FastReport .NET 上子报表的数量可变

发布于 2024-11-19 11:33:06 字数 167 浏览 3 评论 0原文

我有一份打印销售信息的报告。该报告的数据源是一个 SellReport 对象。

现在我想打印不止一笔销售的信息,但不是固定数量的销售信息。我认为最好的方法是将集合作为数据源传递,并为集合的每个 SellReport 生成一个子报告。

有人知道如何动态创建子报表吗?

谢谢!

I have a report that prints the information a sell. The report's Data Source is a SellReport object.

Now I want to print the information of more than one sell, but not of a fixed number of sells. I think the best way is to pass a Collection as Data Source and for each SellReport of the collection it generates a subreport.

Anyone know how to create subreports dynamically?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捂风挽笑 2024-11-26 11:33:06

这是如何使用代码创建报告的示例

Report report = new Report();



// register the "Products" table

 report.RegisterData(dataSet1.Tables["Products"], "Products");

// enable it to use in a report

 report.GetDataSource("Products").Enabled = true;



// create A4 page with all margins set to 1cm

ReportPage page1 = new ReportPage();

 page1.Name = "Page1";

 report.Pages.Add(page1);



// create ReportTitle band

 page1.ReportTitle = new ReportTitleBand();

 page1.ReportTitle.Name = "ReportTitle1";

// set its height to 1.5cm

 page1.ReportTitle.Height = Units.Centimeters * 1.5f;



// create group header

GroupHeaderBand group1 = new GroupHeaderBand();

 group1.Name = "GroupHeader1";

 group1.Height = Units.Centimeters * 1;

// set group condition

 group1.Condition = "[Products.ProductName].Substring(0, 1)";

// add group to the page.Bands collection

 page1.Bands.Add(group1);



// create group footer

 group1.GroupFooter = new GroupFooterBand();

 group1.GroupFooter.Name = "GroupFooter1";

 group1.GroupFooter.Height = Units.Centimeters * 1;



// create DataBand

DataBand data1 = new DataBand();

 data1.Name = "Data1";

 data1.Height = Units.Centimeters * 0.5f;

// set data source

 data1.DataSource = report.GetDataSource("Products");

// connect databand to a group

 group1.Data = data1;



// create "Text" objects



// report title

TextObject text1 = new TextObject();

 text1.Name = "Text1";

// set bounds

 text1.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 19, Units.Centimeters * 1);

// set text

 text1.Text = "PRODUCTS";

// set appearance

 text1.HorzAlign = HorzAlign.Center;

 text1.Font = new Font("Tahoma", 14, FontStyle.Bold);

// add it to ReportTitle

 page1.ReportTitle.Objects.Add(text1);



// group

TextObject text2 = new TextObject();

 text2.Name = "Text2";

 text2.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 2, Units.Centimeters * 1);

 text2.Text = "[[Products.ProductName].Substring(0, 1)]";

 text2.Font = new Font("Tahoma", 10, FontStyle.Bold);

// add it to GroupHeader

 group1.Objects.Add(text2);



// data band

TextObject text3 = new TextObject();

 text3.Name = "Text3";

 text3.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 10, Units.Centimeters * 0.5f);

 text3.Text = "[Products.ProductName]";

 text3.Font = new Font("Tahoma", 8);

// add it to DataBand

 data1.Objects.Add(text3);



// group footer

TextObject text4 = new TextObject();

 text4.Name = "Text4";

 text4.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 10, Units.Centimeters * 0.5f);

 text4.Text = "Count: [CountOfProducts]";

 text4.Font = new Font("Tahoma", 8, FontStyle.Bold);

// add it to GroupFooter

 group1.GroupFooter.Objects.Add(text4);



// add a total

Total groupTotal = new Total();

 groupTotal.Name = "CountOfProducts";

 groupTotal.TotalType = TotalType.Count;

 groupTotal.Evaluator = data1;

 groupTotal.PrintOn = group1.Footer;

// add it to report totals

 report.Dictionary.Totals.Add(groupTotal);

 // run the report

 report.Show();

以及数据源的示例:

  private int[] FArray;
 / create report instance
      Report report = new Report();

      / register the array
      report.RegisterData(FArray, "Array");

您可以使用列表而不是 int[]

并查看示例 \Demos\C#\DataFromBusinessObject

Here is example, how to create a report using code

Report report = new Report();



// register the "Products" table

 report.RegisterData(dataSet1.Tables["Products"], "Products");

// enable it to use in a report

 report.GetDataSource("Products").Enabled = true;



// create A4 page with all margins set to 1cm

ReportPage page1 = new ReportPage();

 page1.Name = "Page1";

 report.Pages.Add(page1);



// create ReportTitle band

 page1.ReportTitle = new ReportTitleBand();

 page1.ReportTitle.Name = "ReportTitle1";

// set its height to 1.5cm

 page1.ReportTitle.Height = Units.Centimeters * 1.5f;



// create group header

GroupHeaderBand group1 = new GroupHeaderBand();

 group1.Name = "GroupHeader1";

 group1.Height = Units.Centimeters * 1;

// set group condition

 group1.Condition = "[Products.ProductName].Substring(0, 1)";

// add group to the page.Bands collection

 page1.Bands.Add(group1);



// create group footer

 group1.GroupFooter = new GroupFooterBand();

 group1.GroupFooter.Name = "GroupFooter1";

 group1.GroupFooter.Height = Units.Centimeters * 1;



// create DataBand

DataBand data1 = new DataBand();

 data1.Name = "Data1";

 data1.Height = Units.Centimeters * 0.5f;

// set data source

 data1.DataSource = report.GetDataSource("Products");

// connect databand to a group

 group1.Data = data1;



// create "Text" objects



// report title

TextObject text1 = new TextObject();

 text1.Name = "Text1";

// set bounds

 text1.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 19, Units.Centimeters * 1);

// set text

 text1.Text = "PRODUCTS";

// set appearance

 text1.HorzAlign = HorzAlign.Center;

 text1.Font = new Font("Tahoma", 14, FontStyle.Bold);

// add it to ReportTitle

 page1.ReportTitle.Objects.Add(text1);



// group

TextObject text2 = new TextObject();

 text2.Name = "Text2";

 text2.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 2, Units.Centimeters * 1);

 text2.Text = "[[Products.ProductName].Substring(0, 1)]";

 text2.Font = new Font("Tahoma", 10, FontStyle.Bold);

// add it to GroupHeader

 group1.Objects.Add(text2);



// data band

TextObject text3 = new TextObject();

 text3.Name = "Text3";

 text3.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 10, Units.Centimeters * 0.5f);

 text3.Text = "[Products.ProductName]";

 text3.Font = new Font("Tahoma", 8);

// add it to DataBand

 data1.Objects.Add(text3);



// group footer

TextObject text4 = new TextObject();

 text4.Name = "Text4";

 text4.Bounds = new RectangleF(0, 0, 

   Units.Centimeters * 10, Units.Centimeters * 0.5f);

 text4.Text = "Count: [CountOfProducts]";

 text4.Font = new Font("Tahoma", 8, FontStyle.Bold);

// add it to GroupFooter

 group1.GroupFooter.Objects.Add(text4);



// add a total

Total groupTotal = new Total();

 groupTotal.Name = "CountOfProducts";

 groupTotal.TotalType = TotalType.Count;

 groupTotal.Evaluator = data1;

 groupTotal.PrintOn = group1.Footer;

// add it to report totals

 report.Dictionary.Totals.Add(groupTotal);

 // run the report

 report.Show();

And example for Data Source:

  private int[] FArray;
 / create report instance
      Report report = new Report();

      / register the array
      report.RegisterData(FArray, "Array");

You can use a list instead of int[]

And look at example \Demos\C#\DataFromBusinessObject

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文