随笔 - 432  文章 - 0  评论 - 15  阅读 - 63万

DevExpress XtraReport - 动态加载报表布局模板

XtraReport的报表模板文件是.repx,下面的代码演示动态加载报表布局模板。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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");//绑定总计(所有单据的总金额)

  

posted on   狼来了  阅读(3347)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
阅读排行:
· 10亿数据,如何做迁移?
· 推荐几款开源且免费的 .NET MAUI 组件库
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 易语言 —— 开山篇
· Trae初体验
历史上的今天:
2014-09-13 一个基于jQuery的简单树形菜单
2014-09-13 使用C#的HttpWebRequest模拟登陆网站
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8

点击右上角即可分享
微信分享提示