开发业务单据报表(主从表) - MiniFramework蝇量框架 - Winform框架
开发业务单据报表(主从表) - MiniFramework蝇量框架 - Winform框架
开发模式与CSFrameworkV5.1旗舰版一样。
一、打印预览
点【打印】按钮,弹出打印预览界面:
二、【打印】按钮事件
C# 全选
/// <summary>
/// 打印按钮事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ucOperate_OnPrintData(object sender, UserControls.ButtonEventArgs e)
{
QueryPO input = null;
//打印当前单据
if (gvSummary.FocusedRowHandle >= 0)
{
var row = gvSummary.GetFocusedDataRow();
input = new QueryPO();
input.docNo1 = row[tb_PO.PONO].ToStringEx();
input.docNo2 = row[tb_PO.PONO].ToStringEx();
}
else //打印所有单据
{
input = new QueryPO();
}
new rptPurchaseOrder().ShowReport(input, this);
}
三、rptPurchaseOrder.cs 报表类
C# 全选
/// <summary>
/// 采购订单(PO)报表,主从表报表
/// </summary>
public class rptPurchaseOrder
{
/// <summary>
/// 打印预览
/// </summary>
/// <param name="owner"></param>
/// <param name="input">查询条件</param>
public void ShowReport(QueryPO input, Form owner)
{
var report = InitializeReport(input);
frmPreview.Preview(report, owner);
}
private Report InitializeReport(QueryPO input)
{
//打印主从表数据
string file = Application.StartupPath + @"\Reports\rptPO.frx";
Report rptPO = new Report();
rptPO.Load(file);//加载报表模板文件
//取报表数据
DataSet ds = new bllPO().QueryReport(input);
ds.Tables[0].TableName = "M";//换个短的别名
ds.Tables[1].TableName = "D";//换个短的别名
rptPO.RegisterData(ds.Tables[0], "M"); //注册数据源,主表
rptPO.RegisterData(ds.Tables[1], "D"); //注册数据源,从表
//给DataBand(主表数据)绑定数据源
DataBand masterBand = rptPO.FindObject("Data1") as DataBand;
masterBand.DataSource = rptPO.GetDataSource("M"); //主表
//给DataBand(明细数据)绑定数据源
DataBand detailBand = rptPO.FindObject("Data2") as DataBand;
detailBand.DataSource = rptPO.GetDataSource("D"); //明细表
//重要!!给明细表设置主外键关系!
detailBand.Relation = new Relation();
detailBand.Relation.ParentColumns = new string[] { "PONO" };
detailBand.Relation.ParentDataSource = rptPO.GetDataSource("M"); //主表
detailBand.Relation.ChildColumns = new string[] { "PONO" };
detailBand.Relation.ChildDataSource = rptPO.GetDataSource("D"); //明细表
(rptPO.FindObject("Text52") as RichObject).Text = Loginer.Current.UserId;
return rptPO;
}
}
四、rptPO.frx 报表文件
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
MiniFramework C/S框架网