DevExpress XtraReport - 动态加载报表布局模板
XtraReport的报表模板文件是.repx,下面的代码演示动态加载报表布局模板。
XtraReport mReport = new XtraReport(); mReport.LoadLayout(Application.StartupPath @"\Reports\" @"rptSO.repx"); //报表模板文件 //取报表数据 DataSet ds = new bllSO().GetReportData(txtNoFrom.Text, txtNoTo.Text, txtDateFrom.DateTime, txtDateTo.DateTime); //查找组件 GroupHeaderBand GroupHeader1 = mReport.FindControl("GroupHeader1", true) as GroupHeaderBand; DetailReportBand DetailReport = mReport.FindControl("DetailReport", true) as DetailReportBand; DetailBand Detail1 = mReport.FindControl("Detail1", true) as DetailBand; XRLabel xrLabel15 = mReport.FindControl("XRLabel15", true) as XRLabel; XRLabel xrLabel23 = mReport.FindControl("XRLabel23", true) as XRLabel; //重要!!!给组(GroupHeader)绑定主键字段 //本报表是按业务单号分组 GroupField gf = new GroupField("SONO", XRColumnSortOrder.Ascending); GroupHeader1.GroupFields.Add(gf); //给数据集建立主外键关系 DataColumn parentColumn = ds.Tables["tb_SO"].Columns["SONO"]; DataColumn childColumn = ds.Tables["tb_SOs"].Columns["SONO"]; DataRelation R1 = new DataRelation("R1", parentColumn, childColumn); ds.Relations.Add(R1); //绑定主表的数据源 mReport.DataMember = "tb_SO"; mReport.DataSource = ds; //绑定明细表的数据源 DetailReport.DataMember = "R1"; DetailReport.DataSource = ds; //自动绑定明细表XRLabel的数据源 BindingFields(ds, Detail1.Controls); xrLabel15.DataBindings.Add("Text", ds, "R1.Amount");//绑定小计(当前单据的总金额) xrLabel23.DataBindings.Add("Text", ds, "R1.Amount");//绑定总计(所有单据的总金额)