CSFrameworkV6旗舰版 - 送货单报表C#源码参考
Report - 报表代码(送货单)
报表打印窗体 - 送货单
报表打印窗体代码
C# 全选
using CartonERP.Business;
using CartonERP.Library.CommonClass;
using CartonERP.Models;
using CSFrameworkV6.Core.Extensions;
using FastReport;
using FastReport.Data;
using System.Data;
using System.IO;
namespace CartonERP.ReportModule.FastReportForms
{
/// <summary>
/// 送货单报表
/// </summary>
public partial class frmReportDO_Carton : frmBasePrint
{
const string REPORT_DOC_TYPE = "DO_Carton";
/// <summary>
/// 构造器
/// </summary>
public frmReportDO_Carton()
{
InitializeComponent();
_BLLReports = new bllReports();//初始化
DataBinderTools.BoundReport(txtReportTpye.Properties, REPORT_DOC_TYPE);
txtReportTpye.EditValue = (txtReportTpye.Properties.DataSource as List<sys_Reports>).FirstOrDefault().ReportFileName;
}
/// <summary>
/// 打开报表窗体
/// </summary>
/// <param name="DONO"></param>
/// <param name="preview"></param>
public static void Execute(string DONO, bool preview = true)
{
frmReportDO_Carton form = new frmReportDO_Carton();
form.txtNoFrom.Text = DONO;
if (preview)
{
Report rpt = form.InitializeReport();
rpt.PrintSettings.ShowDialog = false;
rpt.Show();
}
else
{
form.ShowDialog();
}
}
/// <summary>
/// 打印机设置
/// </summary>
protected override void DoPrinterSetup()
{
var data = JsonFilePrinterSetup.Current.Get(REPORT_DOC_TYPE);
if (frmBasePrinterSetup.Execute(ref data))
{
JsonFilePrinterSetup.Current.Write(REPORT_DOC_TYPE, data);//保存配置
}
}
/// <summary>
/// 打印报表
/// </summary>
protected override void DoPrint()
{
//报表同步:如果数据库报表的版本>本地文件的修改时间,下载到本地替换报表模版文件
ReportLib.SyncReportFile(REPORT_DOC_TYPE, txtReportTpye.EditValue.ToStringEx());
Report rptDO_CartonTable = this.InitializeReport();
rptDO_CartonTable.Prepare();
rptDO_CartonTable.PrintPrepared();
}
/// <summary>
/// 打印预览
/// </summary>
protected override void DoPreview()
{
//报表同步:如果数据库报表的版本>本地文件的修改时间,下载到本地替换报表模版文件
ReportLib.SyncReportFile(REPORT_DOC_TYPE, txtReportTpye.EditValue.ToStringEx());
Report rptDO_CartonTable = this.InitializeReport();
rptDO_CartonTable.Show(true, this);
}
/// <summary>
/// 设计报表模板
/// </summary>
protected override void DoDesignReport()
{
//string file = this.SetReportUrl(txtReportTpye.EditValue.ToStringEx());
//Report rptDO_Carton = new Report();
//rptDO_Carton.Load(file);//加载报表模板文件
//rptDO_Carton.Design(this);
}
/// <summary>
/// 获取报表文件路径
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
private string GetReportFilePath(string fileName)
{
return Path.Combine(Application.StartupPath, @"Reports\" + fileName);
}
/// <summary>
/// 初始化报表
/// </summary>
/// <param name="docNo">送货单号</param>
/// <returns></returns>
private Report InitializeReport(string docNo = "")
{
#region 方法1:加载本地报表文件写法
string rptFileName = txtReportTpye.EditValue.ToStringEx();//如:rptPO_Paper01.frx
string file = this.GetReportFilePath(rptFileName);//文件路径
Report rptDO_Carton = new Report();
rptDO_Carton.Load(file);//加载报表模板文件
#endregion
var valList = txtNoFrom.EditValue.ToStringEx().Split(',', StringSplitOptions.RemoveEmptyEntries).ToList();
QueryBusiness P = new QueryBusiness
{
DocNoFrom = docNo == null ? txtNoFrom.Text : docNo,
ListDocNo = valList,
};
//取报表数据
var ds = new bll_DO_Carton().QueryReportData(P);
ReportLib.ApplyUserName(ds);//自动添加制单人姓名
ReportLib.ApplyEmptyRows(ds, 0, REPORT_DOC_TYPE, "DONO", rptFileName, false);//自动补空行
//人民币大写
if (ds.Tables[0].Columns["TotalAmountCHN"] == null)
{
ReportLib.AddColumn(ds.Tables[0], "TotalAmountCHN", typeof(String));
//设置金额中文、制单人中文名称(model方式)
foreach (DataRow item in ds.Tables[0].Rows)
{
item["TotalAmountCHN"] = RmbHelper.ToUpper(item["TotalAmount"].ToDecimal());
}
}
//获取客户编码用于设置报表抬头
var CustomerCode = ds.Tables[0].Rows.Count > 0 ? ds.Tables[0].Rows[0]["CustomerCode"].ToStringEx() : "";
//取报表名称
var fileName = txtReportTpye.EditValue.ToStringEx();
var obj = txtReportTpye.Properties.GetDataSourceRowByKeyValue(fileName) as sys_Reports;
//明细表相关字段设置空值
foreach (DataRow item in ds.Tables[1].Rows)
{
if (obj.SortId == 2)//无单价&金额&备注
{
item["Price"] = 0;
item["Amount"] = 0;
}
if (obj.ReportFileName == fileName && obj.SortId == 4)//品名&无单价&金额&重量
{
item["Price"] = 0;
item["Amount"] = 0;
}
if (obj.ReportFileName == fileName && obj.SortId == 5)//无品名单价金额
{
item["ProductName"] = DBNull.Value;
}
if (obj.ReportFileName == fileName && obj.SortId == 6)//无品名无单价金额
{
item["ProductName"] = DBNull.Value;
item["Price"] = 0;
item["Amount"] = 0;
}
if (obj.ReportFileName == fileName && obj.SortId == 7)//无单价金额单重重量
{
item["Price"] = 0;
item["Amount"] = 0;
}
if (obj.ReportFileName == fileName && obj.SortId == 8)//无品名有单价金额单重重量
{
item["ProductName"] = DBNull.Value;
}
}
rptDO_Carton.Tag = ds; //缓存报表数据,(放到FastReport.Report.Tag 对象)
ds.Tables[0].TableName = "M";//换个短的别名
ds.Tables[1].TableName = "D";//换个短的别名
rptDO_Carton.RegisterData(ds.Tables[0], "M"); //注册数据源,主表
rptDO_Carton.RegisterData(ds.Tables[1], "D"); //注册数据源,从表
(rptDO_Carton.GetDataSource("M") as TableDataSource).Enabled = true;
(rptDO_Carton.GetDataSource("D") as TableDataSource).Enabled = true;
//给DataBand(主表数据)绑定数据源
DataBand masterBand = rptDO_Carton.FindObject("Data1") as DataBand;
masterBand.DataSource = rptDO_Carton.GetDataSource("M"); //主表
//给DataBand(明细数据)绑定数据源
DataBand detailBand = rptDO_Carton.FindObject("Data2") as DataBand;
detailBand.DataSource = rptDO_Carton.GetDataSource("D"); //明细表
//重要!!给明细表设置主外键关系!
detailBand.Relation = new Relation();
detailBand.Relation.ParentColumns = new string[] { "DONO" };
detailBand.Relation.ParentDataSource = rptDO_Carton.GetDataSource("M"); //主表
detailBand.Relation.ChildColumns = new string[] { "DONO" };
detailBand.Relation.ChildDataSource = rptDO_Carton.GetDataSource("D"); //明细表
//设置客户报表抬头
ReportLib.SetCustomerReportTitle(rptDO_Carton, CustomerCode);
//设置单价、金额显示格式
ReportLib.SetCustomerPriceAmountPoint(rptDO_Carton, CustomerCode, "[D.Price]", "[D.Amount]");
//应用打印机配置
ReportLib.ApplyPrinterSettings(rptDO_Carton, JsonFilePrinterSetup.Current.Get(REPORT_DOC_TYPE));
QueryBusiness p = new QueryBusiness { ListDocNo = valList };
//更新打印次数
var result = new bll_DO_Carton().UpdatePrintTimes(p);
return rptDO_Carton;
}
}
}
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
CSFrameworkV6 C/S框架网