• 报表的发布


        各种不同的报表工具,其发布方式是不一样的。现在说说一些报表工具的发布方式.笔者对报表了解不多,可能有些认识上的错误,望大家指明.

        DevExpress公司出品的报表工具 XtraReport ,它的报表设计器就是集成在VS.NET集成开发环境中,在我看来,它的报表设计器就是一种比较特殊的窗体设计器.把报表样式当作窗体表单来设计,于是它也就没有什么报表模板的概念,它的设计信息就保存在VB.NET或C#代码中。这种方法也就避免了写复杂的互换式报表设计器界面,VS.NET已经提供了这种设计器界面的支持,XtraReport也能保存报表到独立的模板文件中,只是加载报表模板对象后将对象以SOAP格式序列化到一个XML文件中。

        这种发布方式是生成的详细的源代码的,程序员可以动手修改这些源代码来实现更灵活的功能,因此方便编程,报表代码可以编译到程序中,报表加载和运行速度快,而且减少了应用系统的文件个数,方便部署。但是修改报表需要重新编译,维护不方便,而且可移植性不好。当新旧版本的XtraReport编程接口变化比较大时,则报表难于移植。

        一个最简单的XtraReport报表代码文件可能为,它就是XtraReport格式的报表模板文件

    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Diagnostics;
    using DevExpress.XtraReports.UI;
    namespace WindowsApplication2
    {
        /// <summary>
        /// Summary description for XtraReport1.
        /// </summary>
        public class XtraReport1: DevExpress.XtraReports.UI.XtraReport
        {
            private DevExpress.XtraReports.UI.DetailBand Detail;
            private DevExpress.XtraReports.UI.PageHeaderBand PageHeader;
            private DevExpress.XtraReports.UI.PageFooterBand PageFooter;
            private DevExpress.XtraReports.UI.XRLabel xrLabel1;
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.Container components = null;
            public XtraReport1()
            {
                /// <summary>
                /// Required for Windows.Forms Class Composition Designer support
                /// </summary>
                InitializeComponent();
                //
                // TODO: Add any constructor code after InitializeComponent call
                //
            }
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (components != null)
                    {
                        components.Dispose();
                    }
                }
                base.Dispose(disposing);
            }
            #region Component Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.Detail = new DevExpress.XtraReports.UI.DetailBand();
                this.PageHeader = new DevExpress.XtraReports.UI.PageHeaderBand();
                this.PageFooter = new DevExpress.XtraReports.UI.PageFooterBand();
                this.xrLabel1 = new DevExpress.XtraReports.UI.XRLabel();
                ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
                //
                // Detail
                //
                this.Detail.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[]
                {
                    this.xrLabel1
                }
                );
                this.Detail.Height = 120;
                this.Detail.Name = "Detail";
                //
                // PageHeader
                //
                this.PageHeader.Height = 30;
                this.PageHeader.Name = "PageHeader";
                //
                // PageFooter
                //
                this.PageFooter.Height = 30;
                this.PageFooter.Name = "PageFooter";
                //
                // xrLabel1
                //
                this.xrLabel1.Location = new System.Drawing.Point(108, 17);
                this.xrLabel1.Name = "xrLabel1";
                this.xrLabel1.Size = new System.Drawing.Size(238, 24);
                this.xrLabel1.Text = "报表中显示的文本";
                //
                // XtraReport1
                //
                this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[]
                {
                    this.Detail, this.PageHeader, this.PageFooter
                }
                );
                ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            }
            #endregion
        }
    }

          当然,更多的报表工具是以报表模板文件的形式进行发布。报表设计器生成各种格式生成报表模板文件,有二进制的,有文本的,还有XML格式的。将这些报表模板文件放在合适的地方,而应用程序从指定位置加载报表模板,使用相对应的报表引擎解析报表模板,访问数据源然后输出报表。

       这里拿旧版本的FastReport说说,FastReport是Delphi编写的,只有报表设计器和报表预览控件,没有独立的报表引擎,报表模板文件是二进制格式。在非Win32的B/S应用中,首先使用报表设计器生成一个个报表模板文件,上传到服务器某个目录中,然后HTML页面中嵌入一个报表预览控件,由于是C/S环境,报表预览控件不能连接数据库,因此服务器端编程序要读取数据,根据这些数据拼凑成javascript和vbscript脚本字符串发往客户端。在客户端的浏览器中,这些服务器程序生成的脚本语言调用报表预览控件的接口,让它下载报表模板文件,并填充数据到报表预览控件中,如此完成报表输出。整个发布过程比较艰难,因此做几张报表还是可以完成的,若要做大量报表,这种发布方式是不明智的。

       微软的Reporting Service 算是比较新的重量级的报表工具了,专门做Web报表,不知道它能否方便的用在C/S系统中。它的报表引擎运行在服务器端。它的报表设计器是基于VS.NET集成开发环境,报表模板文件是XML格式。在实际应用中,首先开发者使用VS.NET编制报表模板,然后发布到报表服务器上,然后客户在浏览器中输入报表页面URL就可查看报表了。这种发布方式比较适合WEB应用,部署方便。

       上面的说明,可以知道,通常有两种发布方式,基于源代码的发布方式和基于报表模板文件的发布方式。这两者的差别主要有

    比较项目 报表模板文件发布方式 源代码发布方式
    模板设计器 自己开发互换式设计器,设计器可以独立运行,也可嵌入到VS.NET开发环境。 由VS.NET开发环境提供支持,无需编写设计器。
    自动生成源代码 VS.NET开发环境自动生成。
    保存方式 报表模板文件。 源代码文件。
    发布方式 报表模板文件。 可执行代码,包含在EXE或DLL中。
    可移植性
    灵活性 高,可以深入编程,因此可适应各种情况。
    加载和运行速度 低,需要报表引擎加载和解析报表模板文件,动态的生成报表文档对象。 快,可执行代码加载后就可直接使用。
    动态报表 可以支持,也可以不支持。 必须支持。

       笔者正在开发的报表工具尝试着同时支持这两种报表发布模式,报表工具既可使用报表模板进行发布,又可生成源代码。其实写个报表工具,支持第一种方式或支持第二种方式都是可以想象的,但要这两者结合起来则一时还不可想象,因为这两者相差太大了。

       笔者开发的报表工具的发布是基于报表模板文件的,因此需要进行升级。

        第一步就是支持动态报表。在笔者看来,所谓动态报表就是报表引擎提供非常丰富的编程接口。应用程序可以使用这些接口,使用一个空白报表模板来动态的构造出一个实用的报表模板,其中无需报表模板编制工具。还好,我的报表工具是基于XDesignerLib的,而XDesignerLib就是一个中间件,就是为了让其他程序扩展的,因此编程接口非常丰富,我对报表引擎小修小改,也就完成了对动态报表的支持了。

        第二步就是考虑如何生成源代码。此时报表设计器就客串为代码生成器,笔者的一些设计器由代码生成功能,比如笔者编写的数据库设计器XDBDesigner能根据数据结构自动生成各种代码,那里使用了XML+XSLT来生成代码。但根据报表模板来生成代码情况复杂,XSLT技术不够用,因此不采用XSLT方式。此外还能采用拼凑字符串的方式来生成代码,但生成的代码种类单一。因此采用CodeDom的方式来生成代码,其过程是遍历所有的报表元素,为每一个报表元素生成一小段CodeDom结构,然后将这些结构组合在一起就可以生成一个完整的代码树,然后使用 Microsoft.CSharp.CSharpCodeProvider 或 Microsoft.VisualBasic.VBCodeProvider 来生成C#代码或VB.NET代码,如果找到其他种类的编程语言的CodeProvider则还可以生成其他种类的编程代码。

       比如一个报表设计样式为

    则报表设计器生成的C#和VB.NET代码为

    namespace MyNamespace {
        using System;
        using System.Data;
        using System.Xml;
        using XDesignerDom;
        using XDesignerProperty;
        using XDesignerGUI;
        using XDesignerCommon;
        using XDesigner.Report;
    
        /// <summary>新增文档</summary>
        public class MyClass : DesignReportDocument {
            /// <summary>Initalize document.</summary>
            public MyClass() {
                // Begin of initalize document
                this.Loading = true;
                this.Desc = "新增文档";
                this.Title = "新增文档";
                this.HeadHeight = 72;
                this.Bounds = new System.Drawing.Rectangle(0, 0, 601, 300);
                this.PageLeftMargin = 96;
                this.PageTopMargin = 96;
                this.PageRightMargin = 96;
                this.PageBottomMargin = 96;
                // element reporttable1
                DesignReportTable reporttable1 = this.CreateTableElement();
                this.AppendChild(reporttable1);
                reporttable1.ID = "reporttable1";
                reporttable1.Bounds = new System.Drawing.Rectangle(0, 0, 599, 126);
                reporttable1.PrintDockStyle = XDesigner.Report.PrintDockStyle.Top;
                reporttable1.InnerDataSource = "地区列表";
                // element Col0
                DesignReportTableColumn Col0 = this.CreateTableColumnElement();
                reporttable1.AppendChild(Col0);
                Col0.ID = "Col0";
                Col0.Width = 119;
                // element Col1
                DesignReportTableColumn Col1 = this.CreateTableColumnElement();
                reporttable1.AppendChild(Col1);
                Col1.ID = "Col1";
                Col1.Width = 164;
                // element Col2
                DesignReportTableColumn Col2 = this.CreateTableColumnElement();
                reporttable1.AppendChild(Col2);
                Col2.ID = "Col2";
                Col2.Width = 75;
                // element Col3
                DesignReportTableColumn Col3 = this.CreateTableColumnElement();
                reporttable1.AppendChild(Col3);
                Col3.ID = "Col3";
                Col3.Width = 122;
                // element Col4
                DesignReportTableColumn Col4 = this.CreateTableColumnElement();
                reporttable1.AppendChild(Col4);
                Col4.ID = "Col4";
                Col4.Width = 119;
                // element Row0
                DesignReportTableRow Row0 = this.CreateTableRowElement();
                reporttable1.AppendChild(Row0);
                Row0.ID = "Row0";
                Row0.Height = 41;
                Row0.TableHead = true;
                // element A1
                DesignReportTableCell A1 = this.CreateTableCellElement();
                Row0.AppendChild(A1);
                A1.ID = "A1";
                A1.Bounds = new System.Drawing.Rectangle(0, 0, 599, 41);
                A1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold);
                A1.ColSpan = 5;
                A1.Text = "分组客户列表";
                A1.Align = System.Drawing.StringAlignment.Center;
                // element B1
                DesignReportTableCell B1 = this.CreateTableCellElement();
                Row0.AppendChild(B1);
                B1.ID = "B1";
                B1.Bounds = new System.Drawing.Rectangle(119, 0, 164, 30);
                B1.BorderWidth = 1;
                B1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                B1.Align = System.Drawing.StringAlignment.Center;
                // element C1
                DesignReportTableCell C1 = this.CreateTableCellElement();
                Row0.AppendChild(C1);
                C1.ID = "C1";
                C1.Bounds = new System.Drawing.Rectangle(283, 0, 75, 30);
                C1.BorderWidth = 1;
                C1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                C1.Align = System.Drawing.StringAlignment.Center;
                // element D1
                DesignReportTableCell D1 = this.CreateTableCellElement();
                Row0.AppendChild(D1);
                D1.ID = "D1";
                D1.Bounds = new System.Drawing.Rectangle(358, 0, 122, 30);
                D1.BorderWidth = 1;
                D1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                D1.Align = System.Drawing.StringAlignment.Center;
                // element E1
                DesignReportTableCell E1 = this.CreateTableCellElement();
                Row0.AppendChild(E1);
                E1.ID = "E1";
                E1.Bounds = new System.Drawing.Rectangle(480, 0, 119, 30);
                E1.BorderWidth = 1;
                E1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                E1.Align = System.Drawing.StringAlignment.Center;
                // element Row00
                DesignReportTableRow Row00 = this.CreateTableRowElement();
                reporttable1.AppendChild(Row00);
                Row00.ID = "Row0";
                Row00.Height = 31;
                Row00.TableHead = true;
                // element A10
                DesignReportTableCell A10 = this.CreateTableCellElement();
                Row00.AppendChild(A10);
                A10.ID = "A1";
                A10.Bounds = new System.Drawing.Rectangle(0, 41, 119, 31);
                A10.BorderWidth = 1;
                A10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255);
                A10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                A10.Text = "联系人";
                // element B10
                DesignReportTableCell B10 = this.CreateTableCellElement();
                Row00.AppendChild(B10);
                B10.ID = "B1";
                B10.Bounds = new System.Drawing.Rectangle(119, 41, 164, 31);
                B10.BorderWidth = 1;
                B10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255);
                B10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                B10.Text = "公司名称";
                // element C10
                DesignReportTableCell C10 = this.CreateTableCellElement();
                Row00.AppendChild(C10);
                C10.ID = "C1";
                C10.Bounds = new System.Drawing.Rectangle(283, 41, 75, 31);
                C10.BorderWidth = 1;
                C10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255);
                C10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                C10.Text = "城市";
                // element D10
                DesignReportTableCell D10 = this.CreateTableCellElement();
                Row00.AppendChild(D10);
                D10.ID = "D1";
                D10.Bounds = new System.Drawing.Rectangle(358, 41, 122, 31);
                D10.BorderWidth = 1;
                D10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255);
                D10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                D10.Text = "联系地址";
                // element E10
                DesignReportTableCell E10 = this.CreateTableCellElement();
                Row00.AppendChild(E10);
                E10.ID = "E1";
                E10.Bounds = new System.Drawing.Rectangle(480, 41, 119, 31);
                E10.BorderWidth = 1;
                E10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255);
                E10.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                E10.Text = "联系电话";
                // element Row1
                DesignReportTableRow Row1 = this.CreateTableRowElement();
                reporttable1.AppendChild(Row1);
                Row1.ID = "Row1";
                Row1.Height = 26;
                // element A2
                DesignReportTableCell A2 = this.CreateTableCellElement();
                Row1.AppendChild(A2);
                A2.ID = "A2";
                A2.Bounds = new System.Drawing.Rectangle(0, 72, 599, 26);
                A2.BorderWidth = 1;
                A2.BackColor = System.Drawing.Color.FromArgb(255, 250, 235, 215);
                A2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                A2.ColSpan = 5;
                A2.Text = "[地区名称]地区  共[客户个数]个用户";
                // element B2
                DesignReportTableCell B2 = this.CreateTableCellElement();
                Row1.AppendChild(B2);
                B2.ID = "B2";
                B2.Bounds = new System.Drawing.Rectangle(0, 0, 164, 30);
                B2.BorderWidth = 1;
                B2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                // element C2
                DesignReportTableCell C2 = this.CreateTableCellElement();
                Row1.AppendChild(C2);
                C2.ID = "C2";
                C2.Bounds = new System.Drawing.Rectangle(0, 0, 75, 30);
                C2.BorderWidth = 1;
                C2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                // element D2
                DesignReportTableCell D2 = this.CreateTableCellElement();
                Row1.AppendChild(D2);
                D2.ID = "D2";
                D2.Bounds = new System.Drawing.Rectangle(0, 0, 119, 30);
                D2.BorderWidth = 1;
                D2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                // element E2
                DesignReportTableCell E2 = this.CreateTableCellElement();
                Row1.AppendChild(E2);
                E2.ID = "E2";
                E2.Bounds = new System.Drawing.Rectangle(0, 0, 119, 30);
                E2.BorderWidth = 1;
                E2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                // element Row10
                DesignReportTableRow Row10 = this.CreateTableRowElement();
                reporttable1.AppendChild(Row10);
                Row10.ID = "Row1";
                Row10.DataSource = "客户列表";
                Row10.Height = 28;
                // element A20
                DesignReportTableCell A20 = this.CreateTableCellElement();
                Row10.AppendChild(A20);
                A20.ID = "A2";
                A20.Bounds = new System.Drawing.Rectangle(0, 98, 119, 28);
                A20.BorderWidth = 1;
                A20.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                A20.Text = "[ContactName]";
                // element B20
                DesignReportTableCell B20 = this.CreateTableCellElement();
                Row10.AppendChild(B20);
                B20.ID = "B2";
                B20.Bounds = new System.Drawing.Rectangle(119, 98, 164, 28);
                B20.BorderWidth = 1;
                B20.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                B20.Text = "[CompanyName]";
                // element C20
                DesignReportTableCell C20 = this.CreateTableCellElement();
                Row10.AppendChild(C20);
                C20.ID = "C2";
                C20.Bounds = new System.Drawing.Rectangle(283, 98, 75, 28);
                C20.BorderWidth = 1;
                C20.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                C20.Text = "[City]";
                // element D20
                DesignReportTableCell D20 = this.CreateTableCellElement();
                Row10.AppendChild(D20);
                D20.ID = "D2";
                D20.Bounds = new System.Drawing.Rectangle(358, 98, 122, 28);
                D20.BorderWidth = 1;
                D20.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                D20.Text = "[Address]";
                // element E20
                DesignReportTableCell E20 = this.CreateTableCellElement();
                Row10.AppendChild(E20);
                E20.ID = "E2";
                E20.Bounds = new System.Drawing.Rectangle(480, 98, 119, 28);
                E20.BorderWidth = 1;
                E20.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
                E20.Text = "[Phone]";
                // Add datasource define ***************************
                // initalize variable
                // create 地区列表
                ReportDataSourceElement 地区列表 = this.CreateDataSourceElement();
                this.DataSourceDocument.Add(地区列表);
                地区列表.Name = "地区列表";
                地区列表.SQL = " Select distinct\r\n    Customers.Region\r\n From \r\n    Customers\r\n order by region";
                // create 地区列表_地区名称
                ReportDataSourceElement 地区列表_地区名称 = this.CreateDataSourceElement();
                地区列表.Add(地区列表_地区名称);
                地区列表_地区名称.Name = "地区名称";
                地区列表_地区名称.FieldName = "Customers.Region";
                // create 地区列表_客户个数
                ReportDataSourceElement 地区列表_客户个数 = this.CreateDataSourceElement();
                地区列表.Add(地区列表_客户个数);
                地区列表_客户个数.Name = "客户个数";
                地区列表_客户个数.FieldName = "Customers.Region";
                地区列表_客户个数.SQL = "select count(*) from Customers Where Region = \'[%value%]\'";
                // create 地区列表_客户列表
                ReportDataSourceElement 地区列表_客户列表 = this.CreateDataSourceElement();
                地区列表.Add(地区列表_客户列表);
                地区列表_客户列表.Name = "客户列表";
                地区列表_客户列表.FieldName = "Customers.Region";
                地区列表_客户列表.SQL = " Select \r\n    Customers.ContactName , \r\n    Customers.CompanyName , \r\n    Custome" +
    "rs.ContactTitle , \r\n    Customers.Address , \r\n    Customers.City , \r\n    Custome" +
    "rs.Phone\r\n From \r\n    Customers\r\n    where region =\'[%value%]\'";
                // create 地区列表_客户列表_ContactName
                ReportDataSourceElement 地区列表_客户列表_ContactName = this.CreateDataSourceElement();
                地区列表_客户列表.Add(地区列表_客户列表_ContactName);
                地区列表_客户列表_ContactName.Name = "ContactName";
                地区列表_客户列表_ContactName.FieldName = "Customers.ContactName";
                // create 地区列表_客户列表_CompanyName
                ReportDataSourceElement 地区列表_客户列表_CompanyName = this.CreateDataSourceElement();
                地区列表_客户列表.Add(地区列表_客户列表_CompanyName);
                地区列表_客户列表_CompanyName.Name = "CompanyName";
                地区列表_客户列表_CompanyName.FieldName = "Customers.CompanyName";
                // create 地区列表_客户列表_ContactTitle
                ReportDataSourceElement 地区列表_客户列表_ContactTitle = this.CreateDataSourceElement();
                地区列表_客户列表.Add(地区列表_客户列表_ContactTitle);
                地区列表_客户列表_ContactTitle.Name = "ContactTitle";
                地区列表_客户列表_ContactTitle.FieldName = "Customers.ContactTitle";
                // create 地区列表_客户列表_Address
                ReportDataSourceElement 地区列表_客户列表_Address = this.CreateDataSourceElement();
                地区列表_客户列表.Add(地区列表_客户列表_Address);
                地区列表_客户列表_Address.Name = "Address";
                地区列表_客户列表_Address.FieldName = "Customers.Address";
                // create 地区列表_客户列表_City
                ReportDataSourceElement 地区列表_客户列表_City = this.CreateDataSourceElement();
                地区列表_客户列表.Add(地区列表_客户列表_City);
                地区列表_客户列表_City.Name = "City";
                地区列表_客户列表_City.FieldName = "Customers.City";
                // create 地区列表_客户列表_Phone
                ReportDataSourceElement 地区列表_客户列表_Phone = this.CreateDataSourceElement();
                地区列表_客户列表.Add(地区列表_客户列表_Phone);
                地区列表_客户列表_Phone.Name = "Phone";
                地区列表_客户列表_Phone.FieldName = "Customers.Phone";
                this.Loading = false;
                // End of initalize document
            }
        }
    }
    Option Strict Off
    Option Explicit On
    Imports System
    Imports System.Data
    Imports System.Xml
    Imports XDesigner.Report
    Imports XDesignerCommon
    Imports XDesignerDom
    Imports XDesignerGUI
    Imports XDesignerProperty
    Namespace MyNamespace
    '<summary>新增文档</summary>
    Public Class [MyClass]
        Inherits DesignReportDocument
        '<summary>Initalize document.</summary>
        Public Sub New()
            MyBase.New
            'Begin of initalize document
            Me.Loading = true
            Me.Desc = "新增文档"
            Me.Title = "新增文档"
            Me.HeadHeight = 72
            Me.Bounds = New System.Drawing.Rectangle(0, 0, 601, 300)
            Me.PageLeftMargin = 96
            Me.PageTopMargin = 96
            Me.PageRightMargin = 96
            Me.PageBottomMargin = 96
            'element reporttable1
            Dim reporttable1 As DesignReportTable = Me.CreateTableElement
            Me.AppendChild(reporttable1)
            reporttable1.ID = "reporttable1"
            reporttable1.Bounds = New System.Drawing.Rectangle(0, 0, 599, 126)
            reporttable1.PrintDockStyle = XDesigner.Report.PrintDockStyle.Top
            reporttable1.InnerDataSource = "地区列表"
            'element Col0
            Dim Col0 As DesignReportTableColumn = Me.CreateTableColumnElement
            reporttable1.AppendChild(Col0)
            Col0.ID = "Col0"
            Col0.Width = 119
            'element Col1
            Dim Col1 As DesignReportTableColumn = Me.CreateTableColumnElement
            reporttable1.AppendChild(Col1)
            Col1.ID = "Col1"
            Col1.Width = 164
            'element Col2
            Dim Col2 As DesignReportTableColumn = Me.CreateTableColumnElement
            reporttable1.AppendChild(Col2)
            Col2.ID = "Col2"
            Col2.Width = 75
            'element Col3
            Dim Col3 As DesignReportTableColumn = Me.CreateTableColumnElement
            reporttable1.AppendChild(Col3)
            Col3.ID = "Col3"
            Col3.Width = 122
            'element Col4
            Dim Col4 As DesignReportTableColumn = Me.CreateTableColumnElement
            reporttable1.AppendChild(Col4)
            Col4.ID = "Col4"
            Col4.Width = 119
            'element Row0
            Dim Row0 As DesignReportTableRow = Me.CreateTableRowElement
            reporttable1.AppendChild(Row0)
            Row0.ID = "Row0"
            Row0.Height = 41
            Row0.TableHead = true
            'element A1
            Dim A1 As DesignReportTableCell = Me.CreateTableCellElement
            Row0.AppendChild(A1)
            A1.ID = "A1"
            A1.Bounds = New System.Drawing.Rectangle(0, 0, 599, 41)
            A1.Font = New System.Drawing.Font("宋体", 10.5!, System.Drawing.FontStyle.Bold)
            A1.ColSpan = 5
            A1.Text = "分组客户列表"
            A1.Align = System.Drawing.StringAlignment.Center
            'element B1
            Dim B1 As DesignReportTableCell = Me.CreateTableCellElement
            Row0.AppendChild(B1)
            B1.ID = "B1"
            B1.Bounds = New System.Drawing.Rectangle(119, 0, 164, 30)
            B1.BorderWidth = 1
            B1.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            B1.Align = System.Drawing.StringAlignment.Center
            'element C1
            Dim C1 As DesignReportTableCell = Me.CreateTableCellElement
            Row0.AppendChild(C1)
            C1.ID = "C1"
            C1.Bounds = New System.Drawing.Rectangle(283, 0, 75, 30)
            C1.BorderWidth = 1
            C1.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            C1.Align = System.Drawing.StringAlignment.Center
            'element D1
            Dim D1 As DesignReportTableCell = Me.CreateTableCellElement
            Row0.AppendChild(D1)
            D1.ID = "D1"
            D1.Bounds = New System.Drawing.Rectangle(358, 0, 122, 30)
            D1.BorderWidth = 1
            D1.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            D1.Align = System.Drawing.StringAlignment.Center
            'element E1
            Dim E1 As DesignReportTableCell = Me.CreateTableCellElement
            Row0.AppendChild(E1)
            E1.ID = "E1"
            E1.Bounds = New System.Drawing.Rectangle(480, 0, 119, 30)
            E1.BorderWidth = 1
            E1.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            E1.Align = System.Drawing.StringAlignment.Center
            'element Row00
            Dim Row00 As DesignReportTableRow = Me.CreateTableRowElement
            reporttable1.AppendChild(Row00)
            Row00.ID = "Row0"
            Row00.Height = 31
            Row00.TableHead = true
            'element A10
            Dim A10 As DesignReportTableCell = Me.CreateTableCellElement
            Row00.AppendChild(A10)
            A10.ID = "A1"
            A10.Bounds = New System.Drawing.Rectangle(0, 41, 119, 31)
            A10.BorderWidth = 1
            A10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255)
            A10.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            A10.Text = "联系人"
            'element B10
            Dim B10 As DesignReportTableCell = Me.CreateTableCellElement
            Row00.AppendChild(B10)
            B10.ID = "B1"
            B10.Bounds = New System.Drawing.Rectangle(119, 41, 164, 31)
            B10.BorderWidth = 1
            B10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255)
            B10.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            B10.Text = "公司名称"
            'element C10
            Dim C10 As DesignReportTableCell = Me.CreateTableCellElement
            Row00.AppendChild(C10)
            C10.ID = "C1"
            C10.Bounds = New System.Drawing.Rectangle(283, 41, 75, 31)
            C10.BorderWidth = 1
            C10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255)
            C10.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            C10.Text = "城市"
            'element D10
            Dim D10 As DesignReportTableCell = Me.CreateTableCellElement
            Row00.AppendChild(D10)
            D10.ID = "D1"
            D10.Bounds = New System.Drawing.Rectangle(358, 41, 122, 31)
            D10.BorderWidth = 1
            D10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255)
            D10.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            D10.Text = "联系地址"
            'element E10
            Dim E10 As DesignReportTableCell = Me.CreateTableCellElement
            Row00.AppendChild(E10)
            E10.ID = "E1"
            E10.Bounds = New System.Drawing.Rectangle(480, 41, 119, 31)
            E10.BorderWidth = 1
            E10.BackColor = System.Drawing.Color.FromArgb(255, 166, 210, 255)
            E10.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            E10.Text = "联系电话"
            'element Row1
            Dim Row1 As DesignReportTableRow = Me.CreateTableRowElement
            reporttable1.AppendChild(Row1)
            Row1.ID = "Row1"
            Row1.Height = 26
            'element A2
            Dim A2 As DesignReportTableCell = Me.CreateTableCellElement
            Row1.AppendChild(A2)
            A2.ID = "A2"
            A2.Bounds = New System.Drawing.Rectangle(0, 72, 599, 26)
            A2.BorderWidth = 1
            A2.BackColor = System.Drawing.Color.FromArgb(255, 250, 235, 215)
            A2.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            A2.ColSpan = 5
            A2.Text = "[地区名称]地区  共[客户个数]个用户"
            'element B2
            Dim B2 As DesignReportTableCell = Me.CreateTableCellElement
            Row1.AppendChild(B2)
            B2.ID = "B2"
            B2.Bounds = New System.Drawing.Rectangle(0, 0, 164, 30)
            B2.BorderWidth = 1
            B2.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            'element C2
            Dim C2 As DesignReportTableCell = Me.CreateTableCellElement
            Row1.AppendChild(C2)
            C2.ID = "C2"
            C2.Bounds = New System.Drawing.Rectangle(0, 0, 75, 30)
            C2.BorderWidth = 1
            C2.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            'element D2
            Dim D2 As DesignReportTableCell = Me.CreateTableCellElement
            Row1.AppendChild(D2)
            D2.ID = "D2"
            D2.Bounds = New System.Drawing.Rectangle(0, 0, 119, 30)
            D2.BorderWidth = 1
            D2.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            'element E2
            Dim E2 As DesignReportTableCell = Me.CreateTableCellElement
            Row1.AppendChild(E2)
            E2.ID = "E2"
            E2.Bounds = New System.Drawing.Rectangle(0, 0, 119, 30)
            E2.BorderWidth = 1
            E2.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            'element Row10
            Dim Row10 As DesignReportTableRow = Me.CreateTableRowElement
            reporttable1.AppendChild(Row10)
            Row10.ID = "Row1"
            Row10.DataSource = "客户列表"
            Row10.Height = 28
            'element A20
            Dim A20 As DesignReportTableCell = Me.CreateTableCellElement
            Row10.AppendChild(A20)
            A20.ID = "A2"
            A20.Bounds = New System.Drawing.Rectangle(0, 98, 119, 28)
            A20.BorderWidth = 1
            A20.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            A20.Text = "[ContactName]"
            'element B20
            Dim B20 As DesignReportTableCell = Me.CreateTableCellElement
            Row10.AppendChild(B20)
            B20.ID = "B2"
            B20.Bounds = New System.Drawing.Rectangle(119, 98, 164, 28)
            B20.BorderWidth = 1
            B20.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            B20.Text = "[CompanyName]"
            'element C20
            Dim C20 As DesignReportTableCell = Me.CreateTableCellElement
            Row10.AppendChild(C20)
            C20.ID = "C2"
            C20.Bounds = New System.Drawing.Rectangle(283, 98, 75, 28)
            C20.BorderWidth = 1
            C20.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            C20.Text = "[City]"
            'element D20
            Dim D20 As DesignReportTableCell = Me.CreateTableCellElement
            Row10.AppendChild(D20)
            D20.ID = "D2"
            D20.Bounds = New System.Drawing.Rectangle(358, 98, 122, 28)
            D20.BorderWidth = 1
            D20.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            D20.Text = "[Address]"
            'element E20
            Dim E20 As DesignReportTableCell = Me.CreateTableCellElement
            Row10.AppendChild(E20)
            E20.ID = "E2"
            E20.Bounds = New System.Drawing.Rectangle(480, 98, 119, 28)
            E20.BorderWidth = 1
            E20.Font = New System.Drawing.Font("宋体", 9!, System.Drawing.FontStyle.Regular)
            E20.Text = "[Phone]"
            'Add datasource define ***************************
            'initalize variable
            'create 地区列表
            Dim 地区列表 As ReportDataSourceElement = Me.CreateDataSourceElement
            Me.DataSourceDocument.Add(地区列表)
            地区列表.Name = "地区列表"
            地区列表.SQL = " Select distinct"&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
                  &"    Customers.Region"&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
                  &" From "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&"    Customers" _
                  &Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&" order by region"
            'create 地区列表_地区名称
            Dim 地区列表_地区名称 As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表.Add(地区列表_地区名称)
            地区列表_地区名称.Name = "地区名称"
            地区列表_地区名称.FieldName = "Customers.Region"
            'create 地区列表_客户个数
            Dim 地区列表_客户个数 As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表.Add(地区列表_客户个数)
            地区列表_客户个数.Name = "客户个数"
            地区列表_客户个数.FieldName = "Customers.Region"
            地区列表_客户个数.SQL = "select count(*) from Customers Where Region = '[%value%]'"
            'create 地区列表_客户列表
            Dim 地区列表_客户列表 As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表.Add(地区列表_客户列表)
            地区列表_客户列表.Name = "客户列表"
            地区列表_客户列表.FieldName = "Customers.Region"
            地区列表_客户列表.SQL = " Select "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
              &"    Customers.ContactName , "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
              &"    Customers.CompanyName , "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
              &"    Customers.ContactTitle , "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
              &"    Customers.Address , "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
              &"    Customers.City , "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
              &"    Customers.Phone"&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10) _
              &" From "&Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&"    Customers" _
              &Microsoft.VisualBasic.ChrW(13)&Microsoft.VisualBasic.ChrW(10)&"    where region ='[%value%]'"
            'create 地区列表_客户列表_ContactName
            Dim 地区列表_客户列表_ContactName As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表_客户列表.Add(地区列表_客户列表_ContactName)
            地区列表_客户列表_ContactName.Name = "ContactName"
            地区列表_客户列表_ContactName.FieldName = "Customers.ContactName"
            'create 地区列表_客户列表_CompanyName
            Dim 地区列表_客户列表_CompanyName As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表_客户列表.Add(地区列表_客户列表_CompanyName)
            地区列表_客户列表_CompanyName.Name = "CompanyName"
            地区列表_客户列表_CompanyName.FieldName = "Customers.CompanyName"
            'create 地区列表_客户列表_ContactTitle
            Dim 地区列表_客户列表_ContactTitle As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表_客户列表.Add(地区列表_客户列表_ContactTitle)
            地区列表_客户列表_ContactTitle.Name = "ContactTitle"
            地区列表_客户列表_ContactTitle.FieldName = "Customers.ContactTitle"
            'create 地区列表_客户列表_Address
            Dim 地区列表_客户列表_Address As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表_客户列表.Add(地区列表_客户列表_Address)
            地区列表_客户列表_Address.Name = "Address"
            地区列表_客户列表_Address.FieldName = "Customers.Address"
            'create 地区列表_客户列表_City
            Dim 地区列表_客户列表_City As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表_客户列表.Add(地区列表_客户列表_City)
            地区列表_客户列表_City.Name = "City"
            地区列表_客户列表_City.FieldName = "Customers.City"
            'create 地区列表_客户列表_Phone
            Dim 地区列表_客户列表_Phone As ReportDataSourceElement = Me.CreateDataSourceElement
            地区列表_客户列表.Add(地区列表_客户列表_Phone)
            地区列表_客户列表_Phone.Name = "Phone"
            地区列表_客户列表_Phone.FieldName = "Customers.Phone"
            Me.Loading = false
            'End of initalize document
        End Sub
    End Class
    End Namespace

        一般的,代码生成完毕后就可以进行编译,将报表模板编译到DLL文件中,而这个DLL文件就是标准的.NET程序集文件,可以用于任何.NET程序中。将报表模板编译成DLL可以加快报表的加载和运行速度。

        程序员可以把这些自动生成的代码提取出来放置到应用系统中,并根据需要进行修改,此时报表设计器就是辅助程序员开发动态报表了,人们可以不必从零开始来开发动态报表,减少编程量,加快报表开发速度。笔者的报表工具追求尽量减少报表编程量,报表设计器能自动生成代码就是这种追求的体现。

        当报表设计器同时实现基于报表模板文件和基于源代码的发布方式时,也就同时具备了这两种发布方式的特性,这也大大方便的报表的开发。

  • 相关阅读:
    Go语言核心36讲39
    Go语言核心36讲36
    django路飞项目
    设备原理操作
    arp原理实战.docx
    windows10 amd处理器 vmware16pro安装 macOS High Sierra 10.13 显示客户端禁用cpu
    傅里叶变换
    共情的神经生物基础
    网络安全基础
    记录垃圾MySQL的蛋疼失败(相对于mssqlserver)
  • 原文地址:https://www.cnblogs.com/xdesigner/p/498331.html
Copyright © 2020-2023  润新知