博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DevExpress_Report 主从报表绑定数据,分页打印
阅读量:7093 次
发布时间:2019-06-28

本文共 4639 字,大约阅读时间需要 15 分钟。

首先新建一个XtraReport类。根据需要设计报表页面布局;子报表需要添加DetailReport

布局设计完毕后,写代码绑定数据;

using System;using System.Drawing;using System.Collections;using System.ComponentModel;using DevExpress.XtraReports.UI;using System.Data;using Zeda.AssistantClass;namespace LYWJMIS{    public partial class MainAndChild : DevExpress.XtraReports.UI.XtraReport    {        private DataSet dsSheet;        private DataSet dsDetail;        public MainAndChild()        {            InitializeComponent();            this.AfterPrint += new EventHandler(MainAndChild_AfterPrint);              }        void MainAndChild_AfterPrint(object sender, EventArgs e)        {            //this.InsertPageBreaks(this.xrPageBreak1);        }        public MainAndChild(DataSet dsSheet, DataSet dsDetail)            : this()        {            this.dsDetail = dsDetail;            this.dsSheet = dsSheet;            DataSet dsRep =new DataSet();            DataTable dtSheet = dsSheet.Tables[0].Copy();            dtSheet.TableName="parent";            dsRep.Tables.Add(dtSheet);            DataTable dtDetail = dsDetail.Tables[0].Copy();            dtDetail.TableName = "child";            dsRep.Tables.Add(dtDetail);            GroupField gf = new GroupField("ID", XRColumnSortOrder.Ascending);            GroupHeader1.GroupFields.Add(gf);            //设置主表和从表的父子关系            DataColumn parentColumn = dsRep.Tables["parent"].Columns["ID"];            DataColumn childColumn = dsRep.Tables["child"].Columns["DB0025A"];            DataRelation R1 = new DataRelation("R1", parentColumn, childColumn);            dsRep.Relations.Add(R1);            //绑定主表的数据源            this.DataMember = "parent";            this.DataSource = dsRep;            //绑定明细表的数据源            this.DetailReport.DataMember = "R1";            this.DetailReport.DataSource = dsRep;            //this.DetailReport.dat            BindTableData(dsRep);            BindFormData(dsRep);            //在页脚之后设置分页符            GroupFooter1.PageBreak = PageBreak.AfterBand;        }        ///         /// 绑定采购单明细信息        ///         private void BindTableData(DataSet ds)        {            //为XRTable的每一列绑定数据集及对应的字段            this.xrTableCell1.DataBindings.Add("Text", ds, "R1.DB0137A");//名称 (DB0137A为字段名称)            this.xrTableCell2.DataBindings.Add("Text", ds, "R1.DB0152A");//规格            this.xrTableCell3.DataBindings.Add("Text", ds, "R1.DB0150A");//单位            this.xrTableCell7.DataBindings.Add("Text", ds, "R1.DB0151A");//产地            this.xrTableCell8.DataBindings.Add("Text", ds, "R1.DB0168A");//剂型            this.xrTableCell9.DataBindings.Add("Text", ds, "R1.DB0183A");//计量规格            this.xrTableCell10.DataBindings.Add("Text", ds, "R1.DB0188A", "{0:n2}");//进价            this.xrTableCell11.DataBindings.Add("Text", ds, "R1.DB0354A", "{0:f0}");//数量            //设置本页小计(数量小计),SummaryRunning.Page指定统计范围,只统计本页数量。            this.xrTableCell23.DataBindings.Add("Text", ds, "R1.DB0354A", "{0:f0}");//数量            this.xrTableCell23.Summary = new XRSummary(SummaryRunning.Page, SummaryFunc.Sum, string.Empty);            //绑定本单合计,SummaryRunning.Group 指定统计范围,统计每一组(一个采购单为一组)数量。            this.xrLabel7.DataBindings.Add("Text", ds, "R1.DB0354A","{0:f0}");            this.xrLabel7.Summary = new XRSummary(SummaryRunning.Group,SummaryFunc.Sum,string.Empty);        }        ///         /// 绑定采购单明细信息        ///         private void BindFormData(DataSet ds)        {            //XRLabel绑定数据 方法1:            this.txtDB0336A.DataBindings.Add("Text",ds,"DB0336A");            //XRLabel绑定数据 方法2:            this.txtDB0337A.DataBindings.Add(new XRBinding("Text", ds, "DB0337A", "{0:yyyy-MM-dd}"));            this.txtDB0005A.DataBindings.Add("Text", ds, "DB0005A");            this.txtDB0339A.DataBindings.Add("Text", ds, "DB0339A");            this.txtDB0345A.DataBindings.Add(new XRBinding("Text", ds, "DB0345A", "{0:n2}"));            this.labPrintTime.Text = DateTime.Now.Date.ToString();        }    }}

打印预览代码

private void customButton1_Click(object sender, EventArgs e)        {            DataSet dsDetail=DataService .Instance .GetPurchaseSheetDetailInfoByDate(this.dtpDate .DStartDate,this.dtpDate .DEndDate);            MainAndChild rep = new MainAndChild(dsSearch,dsDetail);            //设置纸张类型为自定义            rep.PaperKind = System.Drawing.Printing.PaperKind.Custom;            //设置纸张大小            double width = 24.1 * 0.3937008 * Dpi.GetDeviceCapsX();            double height = 9.3 * 0.3937008 * Dpi.GetDeviceCapsY();            rep.PageSize = new System.Drawing.Size((int)width, (int)height);            //打印预览            rep.ShowPreview();        }

转载于:https://www.cnblogs.com/Lijq/p/4447178.html

你可能感兴趣的文章
css——简单模版
查看>>
Spring(一)——总体介绍
查看>>
搭建简单的DHCP服务 (照着敲就能搭建好)
查看>>
select count(*)和select count(1)的区别
查看>>
Spring AOP实现对redis统一管理 (注解方式)
查看>>
【MVVM】- Avalon 数组操作
查看>>
【VMCloud云平台】SCSM(八)SCSM创建请求产品
查看>>
我的友情链接
查看>>
虚拟机的时间同步
查看>>
在XenServer 6.0中设置自动启动虚拟机
查看>>
【大数据培训】大数据带你寻找“惊心动魄”
查看>>
TCP三次握手与四次挥手
查看>>
vRealize Operations Manager 6.5的安装与配置
查看>>
centos7修改网卡一致性命名
查看>>
文件管理命令及变量基础
查看>>
find
查看>>
如何理解磁力
查看>>
安卓学习-NDK开发
查看>>
Linux的基础学习
查看>>
MyBatis--01.基础
查看>>