YES-WIN winform开发框架报表打印功能开发
1. 窗体添加打印权限:
C# 全选
/// <summary>
/// 权限定义
/// </summary>
protected override void InitAuthorize()
{
base.InitAuthorize();
// 添加打印预览 权限
this.FormCommonAuthority = this.FormCommonAuthority | FunctionAuthorityCommon.PREVIEW;
// 扩展权限
//this.AddExtensionAuthroze(FunctionAuthority.EX_01, "自定义扩展权限1");
}
2. 打印预览按钮点击事件
C# 全选
protected override void DoPreview(object sender)
{
var current = DataSource.Current as DataListItem;
if (current == null)
{
Msg.Warning("没有选择数据!");
return;
}
DataDetail data = bll.GetDataDetail(new Req_ByID() { Id = current.ID });
var rpt = ReportServer.RptHelper.CreatetMainDetail<DataDetail, DetailStatementReceivable_Details>(this, "StatementReceivable.frx", data, data.DetailStatementReceivable_Details);
rpt.EnableDesign = true;
rpt.EnablePrint = true;
rpt.Priview();
}
---------------------------------------------------------- 历史文档备份 ----------------------------------------------------------
窗体权限设置 FormAuthority
添加报表打印权限,FunctionAuthorityCommon.PREVIEW
C# 全选
protected override int FormAuthority
{
get
{
return base.FormAuthority + FunctionAuthorityCommon.PREVIEW;
}
}
重写功能窗体的 DoPreview方法
C# 全选
/// <summary>
/// 打印预览
/// </summary>
protected override void DoPreview(object sender)
{
if (gvMainData.FocusedRowHandle < 0) return;
string docno = gvMainData.GetFocusedRowCellValue(tb_PO.DocNo) + "";
DataSet ds = bll.DoGetDocData(docno);
bool v = ((int)Models.DocType.提交).Equals(ds.Tables[tb_PO._TableName].Rows[0][tb_PO.DocType]);
if (v == false)
{
Msg.Warning("当前单据未提交,不允许打印!");
return;
}
string filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports\\rpt_PO.frx");
RptCommonMainDetail rptHelper = new RptCommonMainDetail(this, filename, ds.Tables[tb_PO._TableName], ds.Tables[tb_PODetail._TableName]);
rptHelper.BeforePrepare += RptHelper_BeforePrepare;
ReportServer.frmRptPreview.ShowForm(rptHelper);
}
private void RptHelper_BeforePrepare(global::FastReport.Report rpt)
{
var total = (decimal)(rpt.GetDataSource("D").Reference as DataTable).Compute($"SUM({Models.tb_PODetail.Amount})", "1=1");
string str = WinFramework.Common.RMBConverter.toRMB(total);
var PrintUser = rpt.Parameters.FindByName("TotalAmount");
if (PrintUser != null) PrintUser.Value = str;
}
报表模板设计
报表模板文件存放位置:程序目录 \ reports \ ***.frx
功能测试
点击打印预览按钮
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
YESWinform 管理员