private void DoPrint()
{
DataView dv = (DataView)dgv_apply_details.DataSource;
Report report = new Report();
//给report注册数据源
report.RegisterData(dv, "Purchasment");
//设置能在报表中使用
report.GetDataSource("Purchasment").Enabled = true;
ReportPage page1 = new ReportPage();
page1.Name = "Page1";
page1.SetDefaults(); //设置标题
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
page1.ReportTitle.Height = ;//Units.Centimeters * 0.1f;
//给标题赋值
TextObject txtTitle = new TextObject();
txtTitle.Name = "TextTitle";
txtTitle.Bounds = new RectangleF(, , Units.Centimeters * , Units.Centimeters * );
txtTitle.Text = "药品采购汇总单";
txtTitle.HorzAlign = HorzAlign.Center;
txtTitle.VertAlign = VertAlign.Center;
txtTitle.Font = new Font("微软雅黑", , FontStyle.Bold);
page1.ReportTitle.Objects.Add(txtTitle); GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "GroupHeader1";
group1.Height = Units.Centimeters * 2f;
group1.Condition = "[Purchasment.order_id]";//分组条件 DataBand data1 = new DataBand();
data1.Name = "Data1";
data1.Height = Units.Centimeters * 1.5f;//Units.Centimeters * 3f;//调的是data里面数据(即dataHeaderBand)的间距,也是table中row之间的间距
data1.DataSource = report.GetDataSource("Purchasment"); #region 分组表头
//GetDataBand(ref dataBand, ref dataHeaderBand);
//TextObject txt2 = new TextObject();
//txt2.Name = "Text2";
//txt2.Bounds = new RectangleF(0, 0, Units.Centimeters * 20, Units.Centimeters * 3);
//txt2.VertAlign = VertAlign.Center;
//txt2.Font = new Font("宋体", 9, FontStyle.Bold);
//txt2.Text = dataHeaderBand;//"订单号:[Purchasment.order_id]";
//group1.Objects.Add(txt2); //TextObject txt3 = new TextObject();
//txt3.Name = "Text3";
//txt3.Bounds = new RectangleF(Units.Centimeters * 8, 0, Units.Centimeters * 20, Units.Centimeters * 3);
//txt3.VertAlign = VertAlign.Center;
//txt3.Text = "申请药房:[Purchasment.storage_name]";
//group1.Objects.Add(txt3); ////<TextObject Name="Text38" Left="198.45" Top="18.9" Width="75.6" Height="28.35" Text="订单状态:" VertAlign="Center"/>
//TextObject txt4 = new TextObject();
//txt4.Name = "Text4";
////txt4.Bounds = new RectangleF(float.Parse("198.45"), float.Parse("18.9"), float.Parse("75.6"), float.Parse("28.35"));
//txt4.Bounds = new RectangleF(Units.Centimeters * 15, 0, Units.Centimeters * 10, Units.Centimeters * 1);
//txt4.VertAlign = VertAlign.Center;
//txt4.Text = "采购科室:[Purchasment.sourceStorage]";
//group1.Objects.Add(txt4);
#endregion
//DataHeaderBand dataHeader1 = new DataHeaderBand();
//dataHeader1.Name = "DataHeader1";
//dataHeader1.Height = Units.Centimeters * 1;
//data1.Objects.Add(dataHeader1);
//GetDataBand(ref dataBand, ref dataHeaderBand); //TextObject txt6 = new TextObject();
//txt6.Name = "Text6";
//txt6.Bounds = new RectangleF(0, Units.Centimeters * 2, Units.Centimeters * 30, Units.Centimeters * 1);
//txt6.Text = dataHeaderBand;
//txt6.Font = new Font("宋体", 9, FontStyle.Bold);
//dataHeader1.Objects.Add(txt6);
////group1.Objects.Add(txt6); //TextObject txt7 = new TextObject();
//txt7.Name = "Text7";
//txt7.Bounds = new RectangleF(0, Units.Centimeters * 3, Units.Centimeters * 30, Units.Centimeters * 1f);
//txt7.Text = dataBand;
//txt7.Font = new Font("宋体", 9);
//data1.Objects.Add(txt7); #region Table表格
TableObject table1 = new TableObject();
table1.Name = "Table1";
table1.Border.Lines = BorderLines.All;
table1.Height = Units.Centimeters * 1.5f;
//table1.Width = Units.Centimeters * 30; #region TableColumn
//TableColumn column1 = new TableColumn();
//column1.Name = "Column1";
//column1.Width = Units.Centimeters * 3;
//table1.AddChild(column1);//AddChild应为添加子节点,适用于table内部
////table1.ChildObjects.Add(column);//试过这种添加方式,不过这样就不显示表格了 //TableColumn column2 = new TableColumn();
//column2.Name = "Column2";
//column2.Width = Units.Centimeters * 3;
//table1.AddChild(column2); //TableColumn column3 = new TableColumn();
//column3.Name = "Column3";
//column3.Width = Units.Centimeters * 3;
//table1.AddChild(column3); //TableColumn column4 = new TableColumn();
//column4.Name = "Column4";
//column4.Width = Units.Centimeters * 3;
//table1.AddChild(column4); //TableColumn column5 = new TableColumn();
//column5.Name = "Column5";
//column5.Width = Units.Centimeters * 3;
//table1.AddChild(column5); //TableColumn column6 = new TableColumn();
//column6.Name = "Column6";
//column6.Width = Units.Centimeters * 3;
//table1.AddChild(column6);
#endregion TableRow row1 = new TableRow();
row1.Name = "Row1";
row1.Height = Units.Centimeters * 1.5f;
table1.AddChild(row1); #region TableCell cell1
//TableCell cell1 = new TableCell();
//cell1.Name = "Cell1";
//cell1.HorzAlign = HorzAlign.Center;
//cell1.VertAlign = VertAlign.Center;
//cell1.Border.Lines = BorderLines.All;
//cell1.Text = "[Purchasment.drug_name]";
//cell1.Font = new Font("宋体", 9);
//row1.AddChild(cell1); //TableCell cell2 = new TableCell();
//cell2.Name = "Cell2";
//cell2.HorzAlign = HorzAlign.Center;
//cell2.VertAlign = VertAlign.Center;
//cell2.Border.Lines = BorderLines.All;
//cell2.Text = "[Purchasment.package_spec]";
//cell2.Font = new Font("宋体", 9);
//row1.AddChild(cell2); //TableCell cell3 = new TableCell();
//cell3.Name = "Cell3";
//cell3.HorzAlign = HorzAlign.Center;
//cell3.VertAlign = VertAlign.Center;
//cell3.Border.Lines = BorderLines.All;
//cell3.Text = "[Purchasment.sale_price]";
//cell3.Font = new Font("宋体", 9);
//row1.AddChild(cell3); //TableCell cell4 = new TableCell();
//cell4.Name = "Cell4";
//cell4.HorzAlign = HorzAlign.Center;
//cell4.VertAlign = VertAlign.Center;
//cell4.Border.Lines = BorderLines.All;
//cell4.Text = "[Purchasment.manufacture_name]";
//cell4.Font = new Font("宋体", 9);
//row1.AddChild(cell4); //TableCell cell5 = new TableCell();
//cell5.Name = "Cell5";
//cell5.HorzAlign = HorzAlign.Center;
//cell5.VertAlign = VertAlign.Center;
//cell5.Border.Lines = BorderLines.All;
//cell5.Text = "[Purchasment.distributor_name]";
//cell5.Font = new Font("宋体", 9);
//row1.AddChild(cell5); //TableCell cell6 = new TableCell();
//cell6.Name = "Cell6";
//cell6.HorzAlign = HorzAlign.Center;
//cell6.VertAlign = VertAlign.Center;
//cell6.Border.Lines = BorderLines.All;
//cell6.Text = "[Purchasment.amount]";
//cell6.Font = new Font("宋体", 9);
//row1.AddChild(cell6);
#endregion SetDataHeaderAndTable(group1, page1.PaperWidth, table1, row1); data1.Objects.Add(table1); #endregion #region 报表底
page1.PageFooter = new PageFooterBand();
page1.PageFooter.Name = "PageFooter1";
page1.PageFooter.Height = Units.Centimeters * ;//这个高度必须>=PageFooter包含文字的RectangleF里面的y的值 TextObject ftxt1 = new TextObject();
ftxt1.Name = "FText1";
ftxt1.Bounds = new RectangleF(, Units.Centimeters * , Units.Centimeters * , Units.Centimeters * );
ftxt1.Text = "打印时间:[Date]";
ftxt1.Font = new Font("宋体", );
ftxt1.VertAlign = VertAlign.Center;
page1.PageFooter.Objects.Add(ftxt1); TextObject ftxt2 = new TextObject();
ftxt2.Name = "FText2";
ftxt2.Bounds = new RectangleF(Units.Centimeters * , Units.Centimeters * , Units.Centimeters * , Units.Centimeters * );
ftxt2.Text = "页码:[PageN]/[TotalPages#]";
ftxt2.Font = new Font("宋体", );
ftxt2.VertAlign = VertAlign.Center;
page1.PageFooter.Objects.Add(ftxt2); TextObject ftxt3 = new TextObject();
ftxt3.Name = "FText3";
ftxt3.Bounds = new RectangleF(Units.Centimeters * , Units.Centimeters * , Units.Centimeters * , Units.Centimeters * );
ftxt3.Text = "打印人:[operator]";
ftxt3.Font = new Font("宋体", );
ftxt3.VertAlign = VertAlign.Center;
page1.PageFooter.Objects.Add(ftxt3);
report.SetParameterValue("operator", SysConfig.UserCode);
#endregion //group1.Objects.Add(data1);
group1.Data = data1;
page1.Bands.Add(group1);
report.Pages.Add(page1);
report.Show();
}
/// <summary>
/// 根据当前显示的字段,动态添加数据首和表格
/// </summary>
private void SetDataHeaderAndTable(GroupHeaderBand group1, float pageWidth, TableObject table1, TableRow row1)
{
int count = ;//记录显示的列数
int index = ;
DataTable dt = OrderBL.SelectFreecombination(this.Name);
if (dt != null)
{
for (int i = ; i < dgv_apply_details.Columns.Count; i++)
{
if (dgv_apply_details.Columns[i].Visible)
{
count++;
}
}
if (count <= )
{
YxMessageBox.ShowWarning("当前没有可打印的数据!");
return;
}
for (int i = ; i < dt.Rows.Count; i++)
{
if (DbHelper.GetBool(dt.Rows[i], "print_status"))
{
TextObject text = new TextObject();
text.Name = "Text" + index.ToString();
text.Bounds = new RectangleF( + index * ( * pageWidth / count), , * pageWidth / count, Units.Centimeters * );
text.VertAlign = VertAlign.Center;
text.Font = new Font("宋体", , FontStyle.Bold);
text.Text = DbHelper.GetString(dt.Rows[i], "header_text");
group1.Objects.Add(text); TableColumn column1 = new TableColumn();
column1.Name = "Column" + index.ToString(); ;
column1.Width = * pageWidth / count;//Units.Centimeters * 3;
table1.AddChild(column1); TableCell cell1 = new TableCell();
cell1.Name = "Cell" + index.ToString(); ;
cell1.HorzAlign = HorzAlign.Center;
cell1.VertAlign = VertAlign.Center;
cell1.Border.Lines = BorderLines.All;
cell1.Text = "[Purchasment." + DbHelper.GetString(dt.Rows[i], "dataproperty_name") + "] ";
cell1.Font = new Font("宋体", );
row1.AddChild(cell1); index++;
}
}
}
}

打印效果如图:

C# winform 动态构建fastreport报表的更多相关文章

  1. 使用FastReport报表工具生成报表PDF文档

    在我们开发某个系统的时候,客户总会提出一些特定的报表需求,固定的报表格式符合他们的业务处理需要,也贴合他们的工作场景,因此我们尽可能做出符合他们实际需要的报表,这样我们的系统会得到更好的认同感.本篇随 ...

  2. FastReport报表设计(仔细看)

    FastReport报表设计 2011-06-16 16:56:19|  分类: 系统开发|举报|字号 订阅     下载LOFTER我的照片书  |     目录 5.1 前言 5.2 基本概念及操 ...

  3. FastReport报表设计

    [转载]FastReport报表设计 (2012-10-24 20:37:26) 转载▼ 标签: 转载   原文地址:FastReport报表设计作者:小黑 FastReport报表设计 目录 5.1 ...

  4. 使用FastReport报表工具生成标签打印文档

    在我们实际开发报表的时候,我们需要按一定的业务规则组织好报表的模板设计,让报表尽可能的贴近实际的需求,在之前的随笔中<使用FastReport报表工具生成报表PDF文档>介绍了FastRe ...

  5. 使用FastReport报表工具生成图片格式文档

    之前我在随笔<使用FastReport报表工具生成报表PDF文档>介绍过使用FastReport.Net来根据报表模板进行生成PDF,以及随笔<使用FastReport报表工具生成标 ...

  6. 使用 SailingEase WinForm 框架构建复合式应用程序(插件式应用程序)

    对于一些较小的项目,具备一定经验的开发人员应该能够设计和构建出便于进行维护和扩展的应用程序.但是,随着功能模块数量(以及开发维护这些部件的人员)的不断增加,对项目实施控制的难度开始呈指数级增长. Sa ...

  7. FastReport报表控件使用技巧总结

    FastReport报表控件使用技巧总结 1.FastReport中如何访问报表中的对象? 可以使用FindObject方法. TfrxMemoView(frxReport1.FindObject(' ...

  8. Winform中在FastReport的PreviewControl预览控件中对report控件模板中控件值进行修改

    场景 FastReport安装包下载.安装.去除使用限制以及工具箱中添加控件: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/10 ...

  9. 使用FastReport报表工具实现信封套打功能

    在较早期的报表套打的时候,我倾向于使用LODOP的ActiveX进行报表的打印或者套打,BS效果还是很不错的.之前利用它在Winform程序里面实现信封套打功能,详细参考<基于信封套打以及批量打 ...

随机推荐

  1. windows10 cortana 不能搜索解决办法

    不太确定是某次系统更新或安装VS软件之后, 发现windows10 cortana 搜索的结果是空白了, 搜索了相关帖子, 试遍所有方法都无效, 最后在联网的情况下, 只用了在powershell中重 ...

  2. python分类预测模型的特点

    python分类预测模型的特点 模型 模型特点 位于 SVM 强大的模型,可以用来回归,预测,分类等,而根据选取不同的和函数,模型可以是线性的/非线性的 sklearn.svm 决策树 基于" ...

  3. MySQL查询上一条记录和下一条记录

    如果ID是主键或者有索引,可以直接查找: 方法一: 查询上一条记录的SQL语句(如果有其他的查询条件记得加上other_conditions以免出现不必要的错误): select * from tab ...

  4. centOS不显示ipv4地址的解决办法

    版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/lx_Frolf/article/deta ...

  5. Mac版-Jdk安装与环境配置

    下载安装 oracle官网下载,地址:https://www.oracle.com/technetwork/java/javase/downloads/index.html 下载好后,点击安装包,一直 ...

  6. T1218:取石子游戏

    [题目描述] 有两堆石子,两个人轮流去取.每次取的时候,只能从较多的那堆石子里取,并且取的数目必须是较少的那堆石子数目的整数倍,最后谁能够把一堆石子取空谁就算赢. 比如初始的时候两堆石子的数目是25和 ...

  7. Redis测试类

    单机&集群安装: https://blog.csdn.net/zxd1435513775/article/details/88901992 安装5.0.4版本OK,5.0.5版本make时报错 ...

  8. Oracle学习笔记<4>

    多表查询 1.什么是多表查询? 一次select语句需要查询的内容来自于不止一张表. 同时从多张表中查询数据. 单表查询: select id,last_name,salary from s_emp ...

  9. picker多级选择器的使用————小程序

    picker多级选择器的使用----小程序 picker是选择器来着,既然选择了,就希望可以获取选择的数据. index.html <view>picker获取数据</view> ...

  10. SQL查询连续年份

    有这样一个问题,给出一个表格记录了夺冠球队的名称和年份,我们要做的就是写出一条SQL语句,查询再次期间连续夺冠的有哪些,起止时间是什么 下边是代码 create table #t(TEAM vaarc ...