fastreport.net cdoe 自己的代码
2016-09-29 09:36
120 查看
//初始 Report report1 = new Report(); report1.Clear(); string ReportFileName = GetReportFileName(Rep); //report1.Load(Environment.CurrentDirectory + "\\Report\\" + ReportFileName); report1.Load(Environment.CurrentDirectory + "\\" + ReportFileName); report1.RegisterData(ds); //report1.RegisterData(dtItem, "item");//report1.RegisterData(ds.Tables[1], "Detail"); report1.GetDataSource("Detail").Enabled = true; report1.GetDataSource("Master").Enabled = true; report1.GetDataSource("Material").Enabled = true; report1.GetDataSource("SUM").Enabled = true; DataBand dataBand1 = report1.FindObject("DataItem") as DataBand; if (dataBand1 == null) { Msg.ShowError("数据区对象不存在,检查(DataItem)是否存在!"); return; } PageHeaderBand PageHeader1 = report1.FindObject("PageHeader1") as PageHeaderBand; if (PageHeader1 == null) { Msg.ShowError("页眉对象不存在,检查(PageHeader1)是否存在!"); return; } dataBand1.DataSource = report1.GetDataSource("Detail"); ////列标题位置参考对象 TextObject TxtObjRow = report1.FindObject("TextData") as TextObject; if (TxtObjRow == null) { Msg.ShowError("参照对象不存在,检查(TxtObjRow)是否存在!"); return; } float iLeft = TxtObjRow.Left; float iTop = TxtObjRow.Top; float iWidth = TxtObjRow.Width; float iHeight = TxtObjRow.Height; //列位置参考对象 TextObject TextHeadRow = report1.FindObject("TextHead") as TextObject; if (TextHeadRow == null) { Msg.ShowError("参照对象不存在,检查(TextHead)是否存在!"); return; } float iLeft2 = TextHeadRow.Left; float iTop2 = TextHeadRow.Top; float iWidth2 = TextHeadRow.Width; float iHeight2 = TextHeadRow.Height; DataSourceBase frxSource = report1.GetDataSource("Detail"); float AutoWith = 0; if (AtuoSize == true) { AutoWith = (float)198 / (frxSource.Columns.Count -9); } else { AutoWith = 10; } //对数据区的列自动生成,加载到报表中 int k = 0; for (int i = 0; i < frxSource.Columns.Count; i = i + 1) { //重新设置数据源列别名,由于传入别名重复。默认情况,dataTable列是caption 自动对应的fastreport数据源列的别名 frxSource.Columns[i].Alias = frxSource.Columns[i].Name; string col = frxSource.Columns[i].Name; string colCaption = col.Replace("_1", ""); if (col == "ID" || col == "MaterialID" || col == "MaterialCode" || col == "MaterialName" || col == "Grade" || col == "LR" || col == "LenType" || col == "Sort" || col == "Com") { continue; } //if (col == "Row") continue; string sName = "[" + frxSource.Alias + "." + col + "]"; //数据区设置 TextObject txtObject = new TextObject(); txtObject.Name = col; txtObject.Border.Lines = BorderLines.All; txtObject.HorzAlign = HorzAlign.Center; txtObject.VertAlign = VertAlign.Center; txtObject.Font = new Font("宋体", 9.0f); txtObject.EvenStyle = "Style1"; //txtObject.CreateUniqueName(); txtObject.Bounds = new RectangleF(k * Units.Millimeters * AutoWith, 0, Units.Millimeters * AutoWith, iHeight); txtObject.Text = sName; txtObject.HideZeros = true;//当为0,设置空 //设置打印内容格式 if (col == "Sph" || col == "row") { } else { NumberFormat fn = new NumberFormat(); fn.UseLocale = false; fn.DecimalDigits = 1; fn.DecimalSeparator ="null" ; txtObject.Format = fn; } dataBand1.Objects.Add(txtObject); //Head列区设置 TextObject txtObject1 = new TextObject(); txtObject1.Name = "txt" + col; //txtObject1.CreateUniqueName(); txtObject1.Border.Lines = BorderLines.All; txtObject1.HorzAlign = HorzAlign.Center; txtObject1.VertAlign = VertAlign.Center; txtObject1.Font = new Font("宋体", 9.0f); txtObject1.Bounds = new RectangleF((k) * Units.Millimeters * AutoWith, iTop2, Units.Millimeters * AutoWith, iHeight2); txtObject1.Text = colCaption; if (col == "Sph" || col == "row") { txtObject1.Text = "球\\柱"; } PageHeader1.Objects.Add(txtObject1); k++; }
相关文章推荐
- 如何 动态编译自己写的代码
- Delphi入门4--自己写代码连接资料库,对数据进行简单操作,还是简单的入门
- 《水晶之约》的完整代码以及一些思想很值得学习---优秀程序的代码固然能更提高自己
- 自己写的.Net(C#)代码自动生成器
- 自己常用的一些javascript代码
- 开发人员要对自己编写代码安全负责
- 常用的一些代码,自己觉得比较好的
- 如何在强类型化DS中加入自己的代码
- 自己OJT时的代码
- 自己写代码实现分页导航
- 凑热闹,Share自己写的另一个小工具--代码统计器。
- 自己修改后求1到1000的完数代码。
- 自己写的第一段AOP代码。
- 刚把过去一些vc共3G多参考的代码恢复到系统中,可惜自己写的有几个无法恢复了
- 俺自己可以写点代码了
- 以前没有研究过脚本的使用,所以昨天那个小问题可是让我费了好一番功夫,贴出代码给自己留个纪念!
- 自己编写的一个代码统计的小工具
- 自己写 localtime 函数(含完整注释,代码)
- 自己OJT时的一本代码
- 今天一个数据结构的代码自己想出来,开心!!