Click here to Skip to main content
15,884,099 members
Articles / Web Development / ASP.NET

An Open Source RDL Engine

Rate me:
Please Sign up or sign in to vote.
4.77/5 (12 votes)
20 Dec 2010CPOL3 min read 83.6K   3.5K   55  
An Open Source RDL engine for rendering reports to WinForms or ASP.NET
/*-----------------------------------------------------------------------------------
This file is part of the SawikiSoft RDL Engine.
The SawikiSoft RDL Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

The SawikiSoft RDL Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Rdl.Engine;

namespace Rdl.Engine.Table
{
    class Group : TableElement
    {
        private Grouping _grouping = null;
        private List<SortBy> _sortBy = null;
        private Header _header = null;
        private Footer _footer = null;
        private Visibility _visibility = Visibility.Visible;
        private TableElement _details = null;
        private Rdl.Render.FlowContainer _box = null;

        public Group(XmlNode node, ReportElement parent)
            : base(node, parent)
        {
        }

        protected override void ParseAttribute(XmlNode attr)
        {
            switch (attr.Name.ToLower())
            {
                case "grouping":
                    _grouping = new Grouping(attr, this);
                    break;
                case "sorting":
                    _sortBy = new List<SortBy>();
                    foreach(XmlNode child in attr.ChildNodes)
                        _sortBy.Add(new SortBy(child, this));
                    break;
                case "header":
                    _header = new Header(attr, this);
                    break;
                case "footer":
                    _footer = new Footer(attr, this);
                    break;
                case "visibility":
                    _visibility = new Visibility(attr, this);
                    break;
                default:
                    break;
            }
        }

        public TableElement Details
        {
            get { return _details; }
            set { _details = value; }
        }

        internal override void Render(Rdl.Render.Container box, Rdl.Runtime.Context context)
        {
            Rdl.Render.FlowContainer headerBox = null;
            Rdl.Render.FlowContainer detailsBox = null;
            Rdl.Render.FlowContainer footerBox = null;
            Rdl.Render.FlowContainer groupRow = null;

            context = new Rdl.Runtime.Context(
                context,
                null,
                null,
                _grouping,
                _sortBy);

            TextBox tb = Report.FindToggleItem(_visibility);

            if (box != null && !_visibility.IsHidden(context))
            {
                _box = box.AddFlowContainer(this, Style, context, Rdl.Render.FlowContainer.FlowDirectionEnum.TopDown);
                _box.Width = box.Width;
                _box.Name = "TableGroup";

                if (tb != null)
                    tb.LinkedToggles.Add(new Toggle(_box, tb));
            }

            // Render the header
            decimal groupTop = 0;
            while (context.GroupIndex < context.GroupCount)
            {
                if (_box != null)
                {
                    groupRow = _box.AddFlowContainer(this, Style, context, Rdl.Render.FlowContainer.FlowDirectionEnum.TopDown);
                    groupRow.Width = _box.Width;
                    groupRow.Top = groupTop;
                    groupRow.Name = "GroupRrow";
                    groupRow.ContextBase = true;
                    groupRow.PageBreakBefore = _grouping.PageBreakAtStart;
                    // Don't break page on last group item.
                    groupRow.PageBreakAfter = (context.GroupIndex + 1 < context.GroupCount) ? _grouping.PageBreakAtEnd : false;
                }

                if (_header != null)
                {
                    if (_box != null)
                    {
                        headerBox = groupRow.AddFlowContainer(this, _header.Style, context, Rdl.Render.FlowContainer.FlowDirectionEnum.TopDown);
                        headerBox.Top = 0;
                        headerBox.Width = groupRow.Width;
                        headerBox.Name = "GroupHeader";
                    }

                    _header.Render(headerBox, context);
                }

                // Create a box to hold the details and tie that
                // box to any repeat lists referencing these details.
                if (_details != null && groupRow != null)
                {
                    detailsBox = groupRow.AddFlowContainer(this, _details.Style, context, Rdl.Render.FlowContainer.FlowDirectionEnum.TopDown);
                    detailsBox.Top = (headerBox == null) ? 0 : headerBox.Height;
                    detailsBox.Width = groupRow.Width;
                    detailsBox.Name = "GroupDetails";

                    // If the header or footer are repeated, then add them to the repeat list of the details.
                    if (_header != null && _header.RepeatOnNewPage)
                        detailsBox.RepeatList.Add(headerBox);
                    if (_footer != null && _footer.RepeatOnNewPage)
                        detailsBox.RepeatList.Add(footerBox);
                }

                // Render the details.
                if (_details != null)
                    _details.Render(detailsBox, context);

                // Render the footer.
                if (_footer != null)
                {
                    if (groupRow != null)
                    {
                        footerBox = groupRow.AddFlowContainer(this, _footer.Style, context, Rdl.Render.FlowContainer.FlowDirectionEnum.TopDown);
                        footerBox.Name = "GroupFooter";
                        footerBox.Top = ((headerBox == null) ? 0 : headerBox.Height) +
                            ((detailsBox == null) ? 0 : detailsBox.Height);
                        footerBox.Width = _box.Width;
                    }
                    context.RowIndex = 0;
                    _footer.Render(footerBox, context);
                }

                if (groupRow != null)
                    groupTop += groupRow.Height;

                context.LinkToggles();
                context.NextGroup();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Sawiki Software
United States United States
I have been a professional software developer for 25+ years, most of it supporting the business community of Maine. I have been working with MS dotnet since 1.0 beta. I organized Sawiki Software LLC as an outlet for some open source software that I have been working on.

Comments and Discussions