DevExpress报表打印设计

这个章节内容详细说明DevExpress开发教程之报表打印设计实现篇中的关键代码部分、简单的设计和打印应用。

 1、DevExpress中 可以通过report.RunDesignerDialog或者report.RunDesigner来设计报表,这里没有使用这两个方法来实现报表设计 功能,而是使用第一章中的自定义的DesignReportForm来实现(实际上相同,但自定义可以控制其他如根据权限显示等内容)。

 2、DesignReportForm非常简单,就是把DesignReportControl,DesignToolBar和 DesignFormattingToolBar拼凑在一起,它们共同关联designReportControl1.DesignPanel。

 3、现在设计一个简单的DataSet,内容如下:

DataSet ds = new DataSet("DeliveryDataSet");
            DataTable dtDelivery= new DataTable("Delivery");
            {
                dtDelivery.Columns.Add("BillId", typeof(string));
                dtDelivery.Columns.Add("ManualId", typeof(string));
                dtDelivery.Columns.Add("BillDate", typeof(DateTime));
                dtDelivery.Columns.Add("CustomerId", typeof(string));
                dtDelivery.Columns.Add("WarehouseId", typeof(string));
                dtDelivery.Columns.Add("Maker", typeof(string));
                dtDelivery.Columns.Add("Remark", typeof(string));
                {
                    DataRow row = dtDelivery.NewRow();
                    row["BillId"] = "IGZ0000002";
                    row["ManualId"] = "Kingmond.Demo";
                    row["BillDate"] = DateTime.Today;
                    row["CustomerId"] = "Regent";
                    row["WarehouseId"] = "MyStore";
                    row["Maker"] = "kevin";
                    row["Remark"] = "Demo a report.";
                    dtDelivery.Rows.Add(row);
                }
            }

            DataTable dtDeliveryGoods = new DataTable("DeliveryGoods");
            {
                dtDeliveryGoods.Columns.Add("BillId", typeof(string));
                dtDeliveryGoods.Columns.Add("BillGoodsId", typeof(string));
                dtDeliveryGoods.Columns.Add("GoodsId", typeof(string));
                dtDeliveryGoods.Columns.Add("Quantity", typeof(int));
                {
                    DataRow row = dtDeliveryGoods.NewRow();
                    row["BillId"] = "IGZ0000002";
                    row["BillGoodsId"] = "IGZ0000002001";
                    row["GoodsId"] = "R001";
                    row["Quantity"] = 23;
                    dtDeliveryGoods.Rows.Add(row);
                }
                {
                    DataRow row = dtDeliveryGoods.NewRow();
                    row["BillId"] = "IGZ0000002";
                    row["BillGoodsId"] = "IGZ0000002002";
                    row["GoodsId"] = "R002";
                    row["Quantity"] = 36;
                    dtDeliveryGoods.Rows.Add(row);
                }
            }
            DataTable dtDeliveryDetail = new DataTable("DeliveryDetail");
            {
                dtDeliveryDetail.Columns.Add("AutoId", typeof(int));
                dtDeliveryDetail.Columns.Add("BillGoodsId", typeof(string));
                dtDeliveryDetail.Columns.Add("ColorId", typeof(string));
                dtDeliveryDetail.Columns.Add("GoodsLong", typeof(string));
                dtDeliveryDetail.Columns.Add("S1", typeof(int));
                dtDeliveryDetail.Columns.Add("S2", typeof(int));
                dtDeliveryDetail.Columns.Add("S3", typeof(int));
                {
                    DataRow row = dtDeliveryDetail.NewRow();
                    row["AutoId"] = 1;
                    row["BillGoodsId"] = "IGZ0000002001";
                    row["ColorId"] = "RED";
                    row["GoodsLong"] = "0";
                    row["S1"] = 7;
                    row["S3"] = 11;
                    dtDeliveryDetail.Rows.Add(row);
                }
                {
                    DataRow row = dtDeliveryDetail.NewRow();
                    row["AutoId"] = 2;
                    row["BillGoodsId"] = "IGZ0000002001";
                    row["ColorId"] = "WHT";
                    row["GoodsLong"] = "0";
                    row["S1"] = 2;
                    row["S2"] = 3;
                    dtDeliveryDetail.Rows.Add(row);
                }

                {
                    DataRow row = dtDeliveryDetail.NewRow();
                    row["AutoId"] = 3;
                    row["BillGoodsId"] = "IGZ0000002002";
                    row["ColorId"] = "RED";
                    row["GoodsLong"] = "0";
                    row["S1"] = 1;
                    row["S2"] = 7;
                    dtDeliveryDetail.Rows.Add(row);
                }
                {
                    DataRow row = dtDeliveryDetail.NewRow();
                    row["AutoId"] = 4;
                    row["BillGoodsId"] = "IGZ0000002002";
                    row["ColorId"] = "BLK";
                    row["GoodsLong"] = "0";
                    row["S1"] = 20;
                    row["S2"] = 8;
                    dtDeliveryDetail.Rows.Add(row);
                }
            }
            ds.Tables.Add(dtDelivery);
            ds.Tables.Add(dtDeliveryGoods);
            ds.Tables.Add(dtDeliveryDetail);
            //设置表之间的关系
            ds.Relations.Add("Delivery_DeliveryGoods", dtDelivery.Columns["BillId"], dtDeliveryGoods.Columns["BillId"]);            
            ds.Relations.Add("DeliveryGoods_DeliveryDetail", dtDeliveryGoods.Columns["BillGoodsId"], dtDeliveryDetail.Columns["BillGoodsId"]);

4、DataSet通过方法WriteXmlSchema(@"c:\temp\delivery.xml");可以很容易得到DataSet的Schema文件。

5、 设计delivery 报表格式,通过

ReportUtil.DesignReport (@"c:\temp\delivery.repx",@"c:\temp\delivery.xml")可以设计已经存在的格式文件.

6、设计结果参考图片:

DevExpress开发教程之报表打印设计应用篇

7、预览结果参考图片:

DevExpress开发教程之报表打印设计应用篇

你可能感兴趣的:(DevExpress)