开发基础资料报表(单表) - MiniFramework蝇量框架 - Winform框架
开发基础资料报表(单表) - MiniFramework蝇量框架 - Winform框架
开发模式与CSFrameworkV5.1旗舰版一样。
一、打印预览
点【打印】按钮,弹出打印预览界面:
二、【打印】按钮事件
C# 全选
private void ucOperate_OnPrintData(object sender, ButtonEventArgs e)
{
if (gvSummary.RowCount > 0)
{
var dt = gcSummary.DataSource as DataTable;
new rptUser().ShowReport(dt, this);
}
}
三、rptUser.cs 报表类
C# 全选
/// <summary>
/// 系统用户报表,单表报表
/// </summary>
public class rptUser
{
/// <summary>
/// 打印预览
/// </summary>
/// <param name="dt">报表数据源</param>
/// <param name="owner"></param>
public void ShowReport(DataTable dt, Form owner)
{
var report = InitializeReport(dt);
frmPreview.Preview(report, owner);
}
private Report InitializeReport(DataTable dt)
{
//打印单表数据
string file = Application.StartupPath + @"\Reports\rptUser.frx";
Report rptUser = new Report();
rptUser.Load(file);
rptUser.RegisterData(dt, "tb_MyUser"); //注册数据源,单表
//给DataBand(明细数据)绑定数据源
DataBand band = rptUser.FindObject("Data1") as DataBand;
DataSourceBase dataSource = rptUser.GetDataSource("tb_MyUser");
band.DataSource = dataSource;
//自定义处理
band.BeforePrint += new EventHandler(band_BeforePrint);
(rptUser.FindObject("Text16") as RichObject).Text = Loginer.Current.UserId;
return rptUser;
}
void band_BeforePrint(object sender, EventArgs e)
{
//取出当前打印的记录。
DataRow row = (sender as DataBand).DataSource.CurrentRow as DataRow;
//做其它特殊处理:
Report rpt = (sender as DataBand).Report;
int i = (sender as DataBand).DataSource.CurrentRowNo;
(rpt.FindObject("Text8") as TextObject).Text = "DataRow:" + i.ToString();
}
}
四、rptUser.frx 文件
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
MiniFramework C/S框架网