public void InitReport() { // check if report has a reportpage bool reportPageExists = false; foreach (PageBase page in Report.Pages) { if (page is ReportPage) { reportPageExists = true; } } // if it has not, create the page if (!reportPageExists) { ReportPage reportPage = new ReportPage(); Report.Pages.Add(reportPage); reportPage.CreateUniqueName(); reportPage.SetDefaults(); } InitPages(1); Script = Report.ScriptText; UpdateCaption(); ResetModified(); FPlugins.Unlock(); }
static void Main(string[] args) { Console.WriteLine("Welcome! Press any key to procced..."); Console.ReadKey(); RegisterOwnFunctions(); // create report instance Report report = new Report(); // add report page ReportPage page = new ReportPage(); report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create title band page.ReportTitle = new ReportTitleBand(); // native FastReport unit is screen pixel, use conversion page.ReportTitle.Height = Units.Centimeters * 1; page.ReportTitle.CreateUniqueName(); // create two title text objects TextObject titleText1 = new TextObject(); titleText1.Parent = page.ReportTitle; titleText1.CreateUniqueName(); titleText1.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 1); titleText1.Font = new Font("Arial", 14, FontStyle.Bold); titleText1.HorzAlign = HorzAlign.Center; // !!! use our function titleText1.Text = "[MyUpperCase(\"products\")]"; // !!! // prepare the report report.Prepare(); // save prepared report if (!Directory.Exists(outFolder)) { Directory.CreateDirectory(outFolder); } report.SavePrepared($@"{outFolder}\Prepared Report.fpx"); // export to image ImageExport image = new ImageExport(); image.ImageFormat = ImageExportFormat.Jpeg; report.Export(image, $@"{outFolder}\report.jpg"); // free resources used by report report.Dispose(); Console.WriteLine("\nPrepared report and report exported as image have been saved into the 'out' folder."); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
/// <summary> /// Creates a ReportPage instance in the specified Report. /// </summary> /// <param name="report">The Report instance.</param> /// <returns>The ReportPage instance.</returns> public static ReportPage CreateReportPage(Report report) { ReportPage page = new ReportPage(); report.Pages.Add(page); page.CreateUniqueName(); return(page); }
public void NewReportPage() { ReportPage page = new ReportPage(); Report.Pages.Add(page); page.SetDefaults(); page.CreateUniqueName(); InitPages(Report.Pages.Count); Designer.SetModified(this, "AddPage"); }
public void CreateUniqueNameTest() { report = new Report(); Base page = new ReportPage(); page.Name = "Page1"; report.AddChild(page); page = new ReportPage(); page.CreateUniqueName(); report.AddChild(page); Assert.NotEqual(report.Pages[0].Name, report.Pages[1].Name); }
public void ClearTest() { report = new Report(); Base page = new ReportPage(); page.Name = "Page1"; report.AddChild(page); page = new ReportPage(); page.CreateUniqueName(); report.AddChild(page); report.Clear(); Base foundedPage = report.FindObject("Page1"); Assert.True(foundedPage == null); }
/// <summary> /// 生成默认报表 /// </summary> /// <returns></returns> public FastReport.Report DefaultReport() { FastReport.Report report = new FastReport.Report(); //判断有报表数据,则注册数据 if (dt != null && dt.Rows.Count > 0) { report.RegisterData(dt, styleObject); } else { return(null); } //查询报表设置 DataTable dtReportSet = DBHelper.GetTable("", "tb_report_set", "*", string.Format("set_object='{0}' and set_user='******'", styleObject, GlobalStaticObj.UserID), "", "order by set_num"); if (dtReportSet == null || dtReportSet.Rows.Count == 0) { return(null); } // enable the "Employees" table to use it in the report report.GetDataSource(styleObject).Enabled = true; // add report page ReportPage page = new ReportPage(); if (paperSize != null) { page.PaperWidth = paperSize.Width; page.PaperHeight = paperSize.Height; } report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create title band page.ReportTitle = new ReportTitleBand(); // native FastReport unit is screen pixel, use conversion page.ReportTitle.Height = Units.Centimeters * 1; page.ReportTitle.CreateUniqueName(); // create title text TextObject titleText = new TextObject(); titleText.Parent = page.ReportTitle; titleText.CreateUniqueName(); //titleText.Bounds = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1); titleText.Bounds = new RectangleF(0, 0, Units.Millimeters * page.PaperWidth, Units.Centimeters * 1); titleText.Font = new Font("Arial", 14, FontStyle.Bold); titleText.Text = styleTitle; titleText.HorzAlign = HorzAlign.Center; titleText.VertAlign = VertAlign.Center; //内容行高 float rowHeight = Units.Centimeters * 1F; //标题行高,如果有合并列,怎行高价高 float rowHeaderHeight = rowHeight; if (dicSpanRows != null && dicSpanRows.Count > 0) { rowHeaderHeight = Units.Centimeters * 1.5f; } page.PageHeader = new PageHeaderBand(); page.PageHeader.Height = rowHeaderHeight; page.PageHeader.CreateUniqueName(); #region 生成报表内容 // create data band DataBand dataBand = new DataBand(); page.Bands.Add(dataBand); dataBand.CreateUniqueName(); dataBand.DataSource = report.GetDataSource(styleObject); dataBand.Height = rowHeight; float x = 0F;//x坐标 foreach (DataRow dr in dtReportSet.Rows) { //判断是否要打印 if (CommonCtrl.IsNullToString(dr["is_print"]) != "1") { continue; } //列宽 float columnWidth = Units.Centimeters * 2; //标题 string headerName = string.Empty; //获取设置的列宽和标题 float.TryParse(dr["set_width"].ToString(), out columnWidth); //columnWidth = columnWidth * 0.9f; headerName = dr["set_name"].ToString(); //生成标题 TextObject txtHeader = new TextObject(); txtHeader.Parent = page.PageHeader; txtHeader.CreateUniqueName(); txtHeader.Text = headerName; txtHeader.HorzAlign = HorzAlign.Center; txtHeader.VertAlign = VertAlign.Center; //生成标题竖线 LineObject lineHeaderVer = new LineObject(); lineHeaderVer.Parent = page.PageHeader; //生成标题横线 LineObject lineHeaderHor = new LineObject(); lineHeaderHor.Parent = page.PageHeader; lineHeaderHor.Bounds = new RectangleF(x, 0, columnWidth, 1f); //数据源列名称 string dataName = dr["set_data_name"].ToString(); string spanName = IsContainDataColumn(dataName); //判断列是否是合并列 if (spanName.Length > 0) { #region 合并列标题 txtHeader.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, rowHeaderHeight / 2); lineHeaderVer.Bounds = new RectangleF(x, rowHeaderHeight / 2, 1F, rowHeaderHeight / 2); //生成合并列的短竖线 LineObject lineHeaderHorSpan = new LineObject(); lineHeaderHorSpan.Parent = page.PageHeader; lineHeaderHorSpan.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, 1F); //判断是否包含合并列头 if (dicSpanWidth.ContainsKey(spanName)) { //增加合并列头的列宽 RectangleF rf = dicSpanWidth[spanName]; rf.Width += columnWidth; dicSpanWidth[spanName] = rf; } else { //记录合并列头 RectangleF rf = new RectangleF(); rf.X = x; rf.Y = 0; rf.Width = columnWidth; rf.Height = rowHeaderHeight / 2; dicSpanWidth.Add(spanName, rf); } #endregion } else { lineHeaderVer.Bounds = new RectangleF(x, 0, 1F, rowHeaderHeight); txtHeader.Bounds = new RectangleF(x, 0, columnWidth, rowHeaderHeight); } // create two text objects with employee's name and birth date //生成内容 TextObject empNameText = new TextObject(); empNameText.Parent = dataBand; empNameText.CreateUniqueName(); empNameText.Bounds = new RectangleF(x, 0, columnWidth, rowHeight); DataColumn dc = dt.Columns[dataName]; empNameText.Text = string.Format("[{0}.{1}]", styleObject, dataName); //empNameText.HideZeros = true; if (dc != null && dc.DataType != typeof(string)) { empNameText.HorzAlign = HorzAlign.Right; } else { empNameText.HorzAlign = HorzAlign.Center; } empNameText.VertAlign = VertAlign.Center; //生成内容列的竖线 LineObject lineVertical = new LineObject(); lineVertical.Parent = dataBand; lineVertical.Bounds = new RectangleF(x, 0, 1F, rowHeight); //生成内容列顶部的横线 LineObject lineHorizontal = new LineObject(); lineHorizontal.Parent = dataBand; lineHorizontal.Bounds = new RectangleF(x, 0, columnWidth, 1f); //生成内荣列底部的横线 LineObject lineHorizontalD = new LineObject(); lineHorizontalD.Parent = dataBand; lineHorizontalD.Bounds = new RectangleF(x, rowHeight, columnWidth, 1f); //x坐标增加当前列 x += columnWidth; } //生成标题右边的竖线 LineObject lineHeaderRightVer = new LineObject(); lineHeaderRightVer.Parent = page.PageHeader; lineHeaderRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight); //生成内容右边的竖线 LineObject lineRightVer = new LineObject(); lineRightVer.Parent = dataBand; lineRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight); //生成合并列头 foreach (string span in dicSpanWidth.Keys) { //合并列头 TextObject txtSpan = new TextObject(); txtSpan.Parent = page.PageHeader; txtSpan.CreateUniqueName(); txtSpan.Bounds = dicSpanWidth[span]; txtSpan.Text = span; txtSpan.HorzAlign = HorzAlign.Center; txtSpan.VertAlign = VertAlign.Center; //合并列头的竖线 LineObject lineHeaderVer = new LineObject(); lineHeaderVer.Parent = page.PageHeader; lineHeaderVer.Bounds = new RectangleF(txtSpan.Bounds.X, txtSpan.Bounds.Y, 1f, txtSpan.Bounds.Height); } #endregion return(report); }
private void FastReportForm_Load(object sender, EventArgs e) { var dataSet = new DataSet(DataTable.TableName); dataSet.Tables.Add(DataTable); _report = new Report(); // register all data tables and relations _report.RegisterData(dataSet); // enable the "result" table to use it in the report _report.GetDataSource(DataTable.TableName).Enabled = true; // add report page ReportPage page = new ReportPage(); _report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create title band page.ReportTitle = new ReportTitleBand { Height = Units.Centimeters * 1 }; page.ReportTitle.CreateUniqueName(); // create title text TextObject titleText = new TextObject { Bounds = new System.Drawing.RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1), Font = new System.Drawing.Font("Arial", 14, System.Drawing.FontStyle.Bold), Text = "Report result", HorzAlign = HorzAlign.Center, Parent = page.ReportTitle }; titleText.CreateUniqueName(); // create data band DataBand dataBand = new DataBand(); page.Bands.Add(dataBand); dataBand.CreateUniqueName(); dataBand.DataSource = _report.GetDataSource(DataTable.TableName); dataBand.Height = Units.Centimeters * 0.5f; var width = page.PaperWidth / DataTable.Columns.Count; foreach (DataColumn column in DataTable.Columns) { // create two text objects with employee's name and birth date TextObject empNameText = new TextObject { Bounds = new System.Drawing.RectangleF(0, 0, width * Units.Millimeters, Units.Centimeters * 0.5f), Text = "[" + DataTable.TableName + "." + column.ColumnName + "]", Parent = dataBand, Dock = DockStyle.Left, }; empNameText.CreateUniqueName(); } }
/// <summary> /// 生成默认报表 /// </summary> /// <returns></returns> public FastReport.Report DefaultReport() { FastReport.Report report = new FastReport.Report(); //判断有报表数据,则注册数据 if (dt != null && dt.Rows.Count > 0) { report.RegisterData(dt, styleObject); } else { return null; } //查询报表设置 DataTable dtReportSet = DBHelper.GetTable("", "tb_report_set", "*", string.Format("set_object='{0}' and set_user='******'", styleObject, GlobalStaticObj.UserID), "", "order by set_num"); if (dtReportSet == null || dtReportSet.Rows.Count == 0) { return null; } // enable the "Employees" table to use it in the report report.GetDataSource(styleObject).Enabled = true; // add report page ReportPage page = new ReportPage(); if (paperSize != null) { page.PaperWidth = paperSize.Width; page.PaperHeight = paperSize.Height; } report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create title band page.ReportTitle = new ReportTitleBand(); // native FastReport unit is screen pixel, use conversion page.ReportTitle.Height = Units.Centimeters * 1; page.ReportTitle.CreateUniqueName(); // create title text TextObject titleText = new TextObject(); titleText.Parent = page.ReportTitle; titleText.CreateUniqueName(); //titleText.Bounds = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1); titleText.Bounds = new RectangleF(0, 0, Units.Millimeters * page.PaperWidth, Units.Centimeters * 1); titleText.Font = new Font("Arial", 14, FontStyle.Bold); titleText.Text = styleTitle; titleText.HorzAlign = HorzAlign.Center; titleText.VertAlign = VertAlign.Center; //内容行高 float rowHeight = Units.Centimeters * 1F; //标题行高,如果有合并列,怎行高价高 float rowHeaderHeight = rowHeight; if (dicSpanRows != null && dicSpanRows.Count > 0) { rowHeaderHeight = Units.Centimeters * 1.5f; } page.PageHeader = new PageHeaderBand(); page.PageHeader.Height = rowHeaderHeight; page.PageHeader.CreateUniqueName(); #region 生成报表内容 // create data band DataBand dataBand = new DataBand(); page.Bands.Add(dataBand); dataBand.CreateUniqueName(); dataBand.DataSource = report.GetDataSource(styleObject); dataBand.Height = rowHeight; float x = 0F;//x坐标 foreach (DataRow dr in dtReportSet.Rows) { //判断是否要打印 if (CommonCtrl.IsNullToString(dr["is_print"]) != "1") { continue; } //列宽 float columnWidth = Units.Centimeters * 2; //标题 string headerName = string.Empty; //获取设置的列宽和标题 float.TryParse(dr["set_width"].ToString(), out columnWidth); //columnWidth = columnWidth * 0.9f; headerName = dr["set_name"].ToString(); //生成标题 TextObject txtHeader = new TextObject(); txtHeader.Parent = page.PageHeader; txtHeader.CreateUniqueName(); txtHeader.Text = headerName; txtHeader.HorzAlign = HorzAlign.Center; txtHeader.VertAlign = VertAlign.Center; //生成标题竖线 LineObject lineHeaderVer = new LineObject(); lineHeaderVer.Parent = page.PageHeader; //生成标题横线 LineObject lineHeaderHor = new LineObject(); lineHeaderHor.Parent = page.PageHeader; lineHeaderHor.Bounds = new RectangleF(x, 0, columnWidth, 1f); //数据源列名称 string dataName = dr["set_data_name"].ToString(); string spanName = IsContainDataColumn(dataName); //判断列是否是合并列 if (spanName.Length > 0) { #region 合并列标题 txtHeader.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, rowHeaderHeight / 2); lineHeaderVer.Bounds = new RectangleF(x, rowHeaderHeight / 2, 1F, rowHeaderHeight / 2); //生成合并列的短竖线 LineObject lineHeaderHorSpan = new LineObject(); lineHeaderHorSpan.Parent = page.PageHeader; lineHeaderHorSpan.Bounds = new RectangleF(x, rowHeaderHeight / 2, columnWidth, 1F); //判断是否包含合并列头 if (dicSpanWidth.ContainsKey(spanName)) { //增加合并列头的列宽 RectangleF rf = dicSpanWidth[spanName]; rf.Width += columnWidth; dicSpanWidth[spanName] = rf; } else { //记录合并列头 RectangleF rf = new RectangleF(); rf.X = x; rf.Y = 0; rf.Width = columnWidth; rf.Height = rowHeaderHeight / 2; dicSpanWidth.Add(spanName, rf); } #endregion } else { lineHeaderVer.Bounds = new RectangleF(x, 0, 1F, rowHeaderHeight); txtHeader.Bounds = new RectangleF(x, 0, columnWidth, rowHeaderHeight); } // create two text objects with employee's name and birth date //生成内容 TextObject empNameText = new TextObject(); empNameText.Parent = dataBand; empNameText.CreateUniqueName(); empNameText.Bounds = new RectangleF(x, 0, columnWidth, rowHeight); DataColumn dc = dt.Columns[dataName]; empNameText.Text = string.Format("[{0}.{1}]", styleObject, dataName); //empNameText.HideZeros = true; if (dc != null && dc.DataType != typeof(string)) { empNameText.HorzAlign = HorzAlign.Right; } else { empNameText.HorzAlign = HorzAlign.Center; } empNameText.VertAlign = VertAlign.Center; //生成内容列的竖线 LineObject lineVertical = new LineObject(); lineVertical.Parent = dataBand; lineVertical.Bounds = new RectangleF(x, 0, 1F, rowHeight); //生成内容列顶部的横线 LineObject lineHorizontal = new LineObject(); lineHorizontal.Parent = dataBand; lineHorizontal.Bounds = new RectangleF(x, 0, columnWidth, 1f); //生成内荣列底部的横线 LineObject lineHorizontalD = new LineObject(); lineHorizontalD.Parent = dataBand; lineHorizontalD.Bounds = new RectangleF(x, rowHeight, columnWidth, 1f); //x坐标增加当前列 x += columnWidth; } //生成标题右边的竖线 LineObject lineHeaderRightVer = new LineObject(); lineHeaderRightVer.Parent = page.PageHeader; lineHeaderRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight); //生成内容右边的竖线 LineObject lineRightVer = new LineObject(); lineRightVer.Parent = dataBand; lineRightVer.Bounds = new RectangleF(x, 0, 1f, rowHeight); //生成合并列头 foreach (string span in dicSpanWidth.Keys) { //合并列头 TextObject txtSpan = new TextObject(); txtSpan.Parent = page.PageHeader; txtSpan.CreateUniqueName(); txtSpan.Bounds = dicSpanWidth[span]; txtSpan.Text = span; txtSpan.HorzAlign = HorzAlign.Center; txtSpan.VertAlign = VertAlign.Center; //合并列头的竖线 LineObject lineHeaderVer = new LineObject(); lineHeaderVer.Parent = page.PageHeader; lineHeaderVer.Bounds = new RectangleF(txtSpan.Bounds.X, txtSpan.Bounds.Y, 1f, txtSpan.Bounds.Height); } #endregion #region 生成页脚 page.PageFooter = new PageFooterBand(); page.PageFooter.Height = rowHeaderHeight; page.PageHeader.CreateUniqueName(); TextObject txtPageN = new TextObject(); txtPageN.Parent = page.PageFooter; txtPageN.CreateUniqueName(); txtPageN.Text = "[PageNofM]"; txtPageN.Bounds = new RectangleF(100, 0, 200, rowHeaderHeight); //TextObject txtTotalPages = new TextObject(); //txtTotalPages.Parent = page.PageFooter; //txtTotalPages.CreateUniqueName(); //txtTotalPages.Text = "[TotalPages]"; //txtTotalPages.Bounds = new RectangleF(350, 0, 200, rowHeaderHeight); #endregion return report; }
static Report GetMasterDetailReport() { Report report = new Report(); // load nwind database DataSet dataSet = new DataSet(); dataSet.ReadXml(inFolder + "\\nwind.xml"); // register all data tables and relations report.RegisterData(dataSet); // enable the "Categories" and "Products" tables to use it in the report report.GetDataSource("Categories").Enabled = true; report.GetDataSource("Products").Enabled = true; // enable relation between two tables report.Dictionary.UpdateRelations(); // add report page ReportPage page = new ReportPage(); report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create master data band DataBand masterDataBand = new DataBand(); page.Bands.Add(masterDataBand); masterDataBand.CreateUniqueName(); masterDataBand.DataSource = report.GetDataSource("Categories"); masterDataBand.Height = Units.Centimeters * 0.5f; // create category name text TextObject categoryText = new TextObject(); categoryText.Parent = masterDataBand; categoryText.CreateUniqueName(); categoryText.Bounds = new RectangleF(0, 0, Units.Centimeters * 5, Units.Centimeters * 0.5f); categoryText.Font = new Font("Arial", 10, FontStyle.Bold); categoryText.Text = "[Categories.CategoryName]"; // create detail data band DataBand detailDataBand = new DataBand(); masterDataBand.Bands.Add(detailDataBand); detailDataBand.CreateUniqueName(); detailDataBand.DataSource = report.GetDataSource("Products"); detailDataBand.Height = Units.Centimeters * 0.5f; // set sort by product name detailDataBand.Sort.Add(new Sort("[Products.ProductName]")); // create product name text TextObject productText = new TextObject(); productText.Parent = detailDataBand; productText.CreateUniqueName(); productText.Bounds = new RectangleF(Units.Centimeters * 1, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f); productText.Text = "[Products.ProductName]"; return(report); }
static Report GetSubreportReport() { Report report = new Report(); // load nwind database DataSet dataSet = new DataSet(); dataSet.ReadXml(inFolder + "\\nwind.xml"); // register all data tables and relations report.RegisterData(dataSet); // enable the "Products" and "Suppliers" tables to use it in the report report.GetDataSource("Products").Enabled = true; report.GetDataSource("Suppliers").Enabled = true; // add report page ReportPage page = new ReportPage(); report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create title band page.ReportTitle = new ReportTitleBand(); // native FastReport unit is screen pixel, use conversion page.ReportTitle.Height = Units.Centimeters * 1; page.ReportTitle.CreateUniqueName(); // create two title text objects TextObject titleText1 = new TextObject(); titleText1.Parent = page.ReportTitle; titleText1.CreateUniqueName(); titleText1.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 1); titleText1.Font = new Font("Arial", 14, FontStyle.Bold); titleText1.Text = "Products"; titleText1.HorzAlign = HorzAlign.Center; TextObject titleText2 = new TextObject(); titleText2.Parent = page.ReportTitle; titleText2.CreateUniqueName(); titleText2.Bounds = new RectangleF(Units.Centimeters * 9, 0, Units.Centimeters * 8, Units.Centimeters * 1); titleText2.Font = new Font("Arial", 14, FontStyle.Bold); titleText2.Text = "Suppliers"; titleText2.HorzAlign = HorzAlign.Center; // create report title's child band that will contain subreports ChildBand childBand = new ChildBand(); page.ReportTitle.Child = childBand; childBand.CreateUniqueName(); childBand.Height = Units.Centimeters * 0.5f; // create the first subreport SubreportObject subreport1 = new SubreportObject(); subreport1.Parent = childBand; subreport1.CreateUniqueName(); subreport1.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f); // create subreport's page ReportPage subreportPage1 = new ReportPage(); report.Pages.Add(subreportPage1); // connect subreport to page subreport1.ReportPage = subreportPage1; // create report on the subreport's page DataBand dataBand = new DataBand(); subreportPage1.Bands.Add(dataBand); dataBand.CreateUniqueName(); dataBand.DataSource = report.GetDataSource("Products"); dataBand.Height = Units.Centimeters * 0.5f; TextObject productText = new TextObject(); productText.Parent = dataBand; productText.CreateUniqueName(); productText.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f); productText.Text = "[Products.ProductName]"; // create the second subreport SubreportObject subreport2 = new SubreportObject(); subreport2.Parent = childBand; subreport2.CreateUniqueName(); subreport2.Bounds = new RectangleF(Units.Centimeters * 9, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f); // create subreport's page ReportPage subreportPage2 = new ReportPage(); report.Pages.Add(subreportPage2); // connect subreport to page subreport2.ReportPage = subreportPage2; // create report on the subreport's page DataBand dataBand2 = new DataBand(); subreportPage2.Bands.Add(dataBand2); dataBand2.CreateUniqueName(); dataBand2.DataSource = report.GetDataSource("Suppliers"); dataBand2.Height = Units.Centimeters * 0.5f; // create supplier name text TextObject supplierText = new TextObject(); supplierText.Parent = dataBand2; supplierText.CreateUniqueName(); supplierText.Bounds = new RectangleF(0, 0, Units.Centimeters * 8, Units.Centimeters * 0.5f); supplierText.Text = "[Suppliers.CompanyName]"; return(report); }
static Report GetSimpleListReport() { Report report = new Report(); // load nwind database DataSet dataSet = new DataSet(); dataSet.ReadXml(inFolder + "\\nwind.xml"); // register all data tables and relations report.RegisterData(dataSet); // enable the "Employees" table to use it in the report report.GetDataSource("Employees").Enabled = true; // add report page ReportPage page = new ReportPage(); report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create title band page.ReportTitle = new ReportTitleBand(); // native FastReport unit is screen pixel, use conversion page.ReportTitle.Height = Units.Centimeters * 1; page.ReportTitle.CreateUniqueName(); // create title text TextObject titleText = new TextObject(); titleText.Parent = page.ReportTitle; titleText.CreateUniqueName(); titleText.Bounds = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1); titleText.Font = new Font("Arial", 14, FontStyle.Bold); titleText.Text = "Employees"; titleText.HorzAlign = HorzAlign.Center; // create data band DataBand dataBand = new DataBand(); page.Bands.Add(dataBand); dataBand.CreateUniqueName(); dataBand.DataSource = report.GetDataSource("Employees"); dataBand.Height = Units.Centimeters * 0.5f; // create two text objects with employee's name and birth date TextObject empNameText = new TextObject(); empNameText.Parent = dataBand; empNameText.CreateUniqueName(); empNameText.Bounds = new RectangleF(0, 0, Units.Centimeters * 5, Units.Centimeters * 0.5f); empNameText.Text = "[Employees.FirstName] [Employees.LastName]"; TextObject empBirthDateText = new TextObject(); empBirthDateText.Parent = dataBand; empBirthDateText.CreateUniqueName(); empBirthDateText.Bounds = new RectangleF(Units.Centimeters * 5.5f, 0, Units.Centimeters * 3, Units.Centimeters * 0.5f); empBirthDateText.Text = "[Employees.BirthDate]"; // format value as date DateFormat format = new DateFormat(); format.Format = "MM/dd/yyyy"; empBirthDateText.Format = format; return(report); }
static Report GetNestedGroupsReport() { Report report = new Report(); // load nwind database DataSet dataSet = new DataSet(); dataSet.ReadXml(inFolder + "\\nwind.xml"); // register all data tables and relations report.RegisterData(dataSet); // enable the "Products" table to use it in the report report.GetDataSource("Products").Enabled = true; // add report page ReportPage page = new ReportPage(); report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create group header GroupHeaderBand groupHeaderBand = new GroupHeaderBand(); page.Bands.Add(groupHeaderBand); groupHeaderBand.Height = Units.Centimeters * 1; groupHeaderBand.Condition = "[Products.ProductName].Substring(0,1)"; // create group text TextObject groupText = new TextObject(); groupText.Parent = groupHeaderBand; groupText.CreateUniqueName(); groupText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 1); groupText.Font = new Font("Arial", 14, FontStyle.Bold); groupText.Text = "[[Products.ProductName].Substring(0,1)]"; groupText.VertAlign = VertAlign.Center; groupText.Fill = new LinearGradientFill(Color.OldLace, Color.Moccasin, 90, 0.5f, 1); // create nested group header GroupHeaderBand nestedGroupBand = new GroupHeaderBand(); groupHeaderBand.NestedGroup = nestedGroupBand; nestedGroupBand.Height = Units.Centimeters * 0.5f; nestedGroupBand.Condition = "[Products.ProductName].Substring(0,2)"; // create nested group text TextObject nestedText = new TextObject(); nestedText.Parent = nestedGroupBand; nestedText.CreateUniqueName(); nestedText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f); nestedText.Font = new Font("Arial", 10, FontStyle.Bold); nestedText.Text = "[[Products.ProductName].Substring(0,2)]"; // create data band DataBand dataBand = new DataBand(); // connect it to inner group nestedGroupBand.Data = dataBand; dataBand.CreateUniqueName(); dataBand.DataSource = report.GetDataSource("Products"); dataBand.Height = Units.Centimeters * 0.5f; // set sort by product name dataBand.Sort.Add(new Sort("[Products.ProductName]")); // create product name text TextObject productText = new TextObject(); productText.Parent = dataBand; productText.CreateUniqueName(); productText.Bounds = new RectangleF(Units.Centimeters * 0.5f, 0, Units.Centimeters * 9.5f, Units.Centimeters * 0.5f); productText.Text = "[Products.ProductName]"; // create group footer for outer group groupHeaderBand.GroupFooter = new GroupFooterBand(); groupHeaderBand.GroupFooter.CreateUniqueName(); groupHeaderBand.GroupFooter.Height = Units.Centimeters * 1; // create total Total groupTotal = new Total(); groupTotal.Name = "TotalRows"; groupTotal.TotalType = TotalType.Count; groupTotal.Evaluator = dataBand; groupTotal.PrintOn = groupHeaderBand.GroupFooter; report.Dictionary.Totals.Add(groupTotal); // show total in the group footer TextObject totalText = new TextObject(); totalText.Parent = groupHeaderBand.GroupFooter; totalText.CreateUniqueName(); totalText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f); totalText.Text = "Rows: [TotalRows]"; totalText.HorzAlign = HorzAlign.Right; totalText.Border.Lines = BorderLines.Top; return(report); }
private void btnGroup_Click(object sender, EventArgs e) { Report report = new Report(); // load nwind database DataSet dataSet = new DataSet(); dataSet.ReadXml(GetReportsFolder() + "nwind.xml"); // register all data tables and relations report.RegisterData(dataSet); // enable the "Products" table to use it in the report report.GetDataSource("Products").Enabled = true; // add report page ReportPage page = new ReportPage(); report.Pages.Add(page); // always give names to objects you create. You can use CreateUniqueName method to do this; // call it after the object is added to a report. page.CreateUniqueName(); // create group header GroupHeaderBand groupHeaderBand = new GroupHeaderBand(); page.Bands.Add(groupHeaderBand); groupHeaderBand.Height = Units.Centimeters * 1; groupHeaderBand.Condition = "[Products.ProductName].Substring(0,1)"; groupHeaderBand.SortOrder = FastReport.SortOrder.Ascending; // create group text TextObject groupText = new TextObject(); groupText.Parent = groupHeaderBand; groupText.CreateUniqueName(); groupText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 1); groupText.Font = new Font("Arial", 14, FontStyle.Bold); groupText.Text = "[[Products.ProductName].Substring(0,1)]"; groupText.VertAlign = VertAlign.Center; groupText.Fill = new LinearGradientFill(Color.OldLace, Color.Moccasin, 90, 0.5f, 1); // create data band DataBand dataBand = new DataBand(); groupHeaderBand.Data = dataBand; dataBand.CreateUniqueName(); dataBand.DataSource = report.GetDataSource("Products"); dataBand.Height = Units.Centimeters * 0.5f; // create product name text TextObject productText = new TextObject(); productText.Parent = dataBand; productText.CreateUniqueName(); productText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f); productText.Text = "[Products.ProductName]"; // create group footer groupHeaderBand.GroupFooter = new GroupFooterBand(); groupHeaderBand.GroupFooter.CreateUniqueName(); groupHeaderBand.GroupFooter.Height = Units.Centimeters * 1; // create total Total groupTotal = new Total(); groupTotal.Name = "TotalRows"; groupTotal.TotalType = TotalType.Count; groupTotal.Evaluator = dataBand; groupTotal.PrintOn = groupHeaderBand.GroupFooter; report.Dictionary.Totals.Add(groupTotal); // show total in the group footer TextObject totalText = new TextObject(); totalText.Parent = groupHeaderBand.GroupFooter; totalText.CreateUniqueName(); totalText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f); totalText.Text = "Rows: [TotalRows]"; totalText.HorzAlign = HorzAlign.Right; totalText.Border.Lines = BorderLines.Top; // run report designer report.Design(); }
private bool CreateReport() { bool functionReturnValue = false; // ERROR: Not supported in C#: OnErrorStatement functionReturnValue = false; // create report instance FastReport.Report MainReport = new FastReport.Report(); FastReport.Report StyleReport = default(FastReport.Report); // register the dataset MainReport.RegisterData(this.FDataSet); MainReport.GetDataSource("TableData").Enabled = true; if (StyleRowsEven == null) { if (System.IO.File.Exists(Application.StartupPath + "\\Report\\Pattern.frx")) { StyleReport = new FastReport.Report(); StyleReport.Load(Application.StartupPath + "\\Report\\Pattern.frx"); StyleRowsEven = StyleReport.Styles[0]; if (StyleRowsEven != null) { MainReport.Styles.Add(StyleRowsEven); } } } ReportPage page = new ReportPage(); page.Width = 33 * Units.Centimeters; MainReport.Pages.Add(page); page.CreateUniqueName(); DataBand dataBand = new DataBand(); page.Bands.Add(dataBand); dataBand.CreateUniqueName(); dataBand.DataSource = MainReport.GetDataSource("TableData"); dataBand.Height = (Units.Centimeters * 0.5f); if (StyleRowsEven != null) { MainReport.Styles.Add(StyleRowsEven); if (!ChkWithoutColorTextReport.Checked) { dataBand.EvenStyle = StyleRowsEven.Name; } else { dataBand.EvenStyle = ""; } } page.ReportTitle = new ReportTitleBand(); page.ReportTitle.Height = (Units.Centimeters * 4f); page.ReportTitle.CreateUniqueName(); if (ChkWithoutColorHeader.CheckState == CheckState.Checked) { colorHeader = Color.Transparent; backgroundColor = Color.Transparent; } HeaderAllReport(page, cboLayers.SelectedItem.ToString()); double higthHeader = double.Parse(txtWidthHeader.Text); double higthBody = double.Parse(txtWidthBody.Text); double WidthReport = 19; double widthColumn = (double)19 / columnNames.Count; for (int i = 0; i < columnNames.Count; i++) { WidthReport -= (widthColumn - 0.005); if (WidthReport < 0) { break; } TextObject titleText = new TextObject(); titleText.Parent = page.ReportTitle; titleText.CreateUniqueName(); titleText.Bounds = new RectangleF(Convert.ToSingle((Units.Centimeters * WidthReport)), (Units.Centimeters * 3f), (Units.Centimeters * (float)widthColumn), (Units.Centimeters * (float)higthHeader)); titleText.Font = FontDialog_Topic.Font; titleText.Text = columnNames[i]; titleText.VertAlign = VertAlign.Center; titleText.HorzAlign = HorzAlign.Center; titleText.Fill = new LinearGradientFill(backgroundColor, colorHeader, 90, Convert.ToSingle(higthHeader), 1f); titleText.RightToLeft = true; TextObject ReportText = new TextObject(); ReportText.Parent = dataBand; ReportText.CreateUniqueName(); ReportText.Bounds = new RectangleF(Convert.ToSingle((Units.Centimeters * WidthReport)), 0f, (Units.Centimeters * (float)widthColumn), (Units.Centimeters * (float)higthBody)); ReportText.Text = "[TableData." + FDataSet.Tables[0].Columns[i].ColumnName + "]"; ReportText.Font = FontDialog_TextReport.Font; ReportText.HorzAlign = HorzAlign.Center; ReportText.VertAlign = VertAlign.Center; ReportText.RightToLeft = true; // ReportText.Border.Lines = BorderLines.All; //ReportText.Border.BottomLine.Color = Color.Black; //ReportText.Border.BottomLine.Width = 0.5f; //ReportText.Border.TopLine .Color = Color.Black; //ReportText.Border.TopLine.Width = 0.5f; } if (WidthReport < 19) { TextObject RemaintitleText = new TextObject(); RemaintitleText.Parent = page.ReportTitle; RemaintitleText.CreateUniqueName(); RemaintitleText.Bounds = new RectangleF(0.0f, (Units.Centimeters * 3f), Convert.ToSingle((Units.Centimeters * WidthReport)), (Units.Centimeters * (float)higthHeader)); RemaintitleText.Text = ""; RemaintitleText.VertAlign = VertAlign.Center; RemaintitleText.HorzAlign = HorzAlign.Center; RemaintitleText.Fill = new LinearGradientFill(backgroundColor, colorHeader, 90, Convert.ToSingle(higthHeader), 1f); } MainReport.Save(Application.StartupPath + "\\Report\\Report_TableResult.frx"); MainReport.Dispose(); functionReturnValue = true; return(functionReturnValue); Err: return(functionReturnValue); }
/// <summary> /// Prepare report when finished /// </summary> /// <typeparam name="T"></typeparam> /// <param name="reportBuilder"></param> /// <returns></returns> public static Report Prepare <T>(this ReportBuilder <T> reportBuilder) { var report = new Report(); var name = typeof(T).Name; report.RegisterData(reportBuilder._data, name); report.GetDataSource(name).Enabled = true; ReportPage page = new ReportPage(); report.Pages.Add(page); page.CreateUniqueName(); page.ReportTitle = new ReportTitleBand(); page.ReportTitle.Height = Units.Centimeters * 1; page.ReportTitle.CreateUniqueName(); page.ReportTitle.Visible = reportBuilder._reportTitle.Visible; TextObject titleText = new TextObject(); titleText.Parent = page.ReportTitle; titleText.CreateUniqueName(); titleText.Bounds = new RectangleF(Units.Centimeters * 5, 0, Units.Centimeters * 10, Units.Centimeters * 1); titleText.Font = reportBuilder._reportTitle.Font; titleText.Text = reportBuilder._reportTitle.Text; titleText.TextColor = reportBuilder._reportTitle.TextColor; titleText.FillColor = reportBuilder._reportTitle.FillColor; titleText.HorzAlign = HorzAlign.Center; DataBand dataBand = new DataBand(); dataBand.Parent = page; dataBand.CreateUniqueName(); dataBand.DataSource = report.GetDataSource(name); dataBand.Height = Units.Centimeters * 0.5f; if (reportBuilder._groupHeader.Visible) { GroupHeaderBand groupHeader = new GroupHeaderBand(); groupHeader.CreateUniqueName(); groupHeader.Height = Units.Centimeters * 0.5f; groupHeader.Condition = string.IsNullOrEmpty(reportBuilder._groupHeader.Expression) ? $"[{name}.{reportBuilder._groupHeader.Name}]" : string.Format(reportBuilder._groupHeader.Expression, $"[{name}.{reportBuilder._groupHeader.Name}]"); groupHeader.Data = dataBand; groupHeader.SortOrder = reportBuilder._groupHeader.SortOrder; groupHeader.Parent = page; if (reportBuilder._groupHeader.TextVisible) { TextObject textGroupHeader = new TextObject(); textGroupHeader.CreateUniqueName(); textGroupHeader.Bounds = new RectangleF(0, 0, Units.Centimeters * 2, Units.Centimeters * 0.5f); textGroupHeader.Text = $"[{groupHeader.Condition}]"; textGroupHeader.Font = new Font("Tahoma", 10, FontStyle.Bold); textGroupHeader.Parent = groupHeader; } } var dataHeaderBand = new DataHeaderBand(); if (reportBuilder._dataHeader.Visible) { dataHeaderBand.Parent = dataBand; dataHeaderBand.CreateUniqueName(); dataHeaderBand.Height = Units.Centimeters * 0.5f; } float leftCm = 0.0f; float size = 0.0f; float pageWidth = page.PaperWidth - (page.LeftMargin + page.RightMargin); float cellWidth = pageWidth / 100; var remainColumn = reportBuilder._columns.Count(a => a.Width == 0); float remainSize = 100 - reportBuilder._columns.Sum(a => a.Width); float remainWidth = remainSize / (remainColumn * 10); foreach (var item in reportBuilder._columns) { size = item.Width == 0 ? remainWidth : (float)item.Width / 10; if (reportBuilder._dataHeader.Visible) { TextObject headerText = new TextObject(); headerText.CreateUniqueName(); headerText.Bounds = new RectangleF(leftCm, 0f * Units.Centimeters, cellWidth * Units.Centimeters * size, 0.1f * Units.Centimeters); headerText.VertAlign = reportBuilder._reportTitle.VertAlign ?? reportBuilder._report.VertAlign; headerText.HorzAlign = reportBuilder._reportTitle.HorzAlign ?? reportBuilder._report.HorzAlign; headerText.Font = reportBuilder._dataHeader.Font; headerText.TextColor = reportBuilder._dataHeader.TextColor; headerText.FillColor = reportBuilder._dataHeader.FillColor; headerText.Border.Lines = BorderLines.All; headerText.Text = item.Title; headerText.GrowToBottom = true; headerText.Parent = dataHeaderBand; } TextObject text = new TextObject(); text.Parent = dataBand; text.CreateUniqueName(); text.Bounds = new RectangleF(leftCm, 0, Units.Centimeters * cellWidth * size, Units.Centimeters * 0.5f); text.Text = string.IsNullOrEmpty(item.Expression) ? $"[{name}.{item.Name}]" : string.Format($"[{item.Expression}]", $"[{name}.{item.Name}]"); text.Border.Lines = BorderLines.All; text.TextColor = Color.Black; text.VertAlign = item.VertAlign ?? reportBuilder._report.VertAlign; text.HorzAlign = item.HorzAlign ?? reportBuilder._report.HorzAlign; if (!string.IsNullOrEmpty(item.Format)) { CustomFormat format = new CustomFormat(); format.Format = item.Format; text.Format = format; } leftCm += cellWidth * Units.Centimeters * size; } report.Prepare(); return(report); }