Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Sample analysis of how FastReport .net copies Bands from one report to another

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

FastReport .net how to copy Bands from one report to another example analysis, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

FastReport .net is a full-featured reporting solution for Windows Forms,ASP.NET,MVC and .NET Core. It can be used in Microsoft Visual Studio 2005-2019. It supports .net Framework 2.0-4.xJ. Net Core 3.0 and above.

In the new version of FastReport .NET 2021.1, we have implemented support for .NET 5. A new bar code-Deutsce Post Leitcode has been added. The algorithm for converting RTF to report objects has been significantly improved. New features for converting numbers have also been added.

Sometimes you need to use a partial report in another report. In simple cases, you can use report inheritance to do this.

For example, in some cases, all reports have common elements (company logo, signature, etc.). You can then move these objects to the parent report and copy them automatically when you create the subreport. Therefore, you do not have to copy them manually every time, greatly simplifying and speeding up the creation of new reports. In addition, if you change something in the parent report, those changes are reflected in all subreports.

However, there are many restrictions on report inheritance. In some cases, there is only one "parent" report for a report, and it is necessary to make a "parent" report a completely different report. It seems possible to change the BaseReport property, but unfortunately, it cannot be solved.

However, this problem can be solved in a wonderful way-by replacing bands in one report code with bands in another report.

Suppose you have a benchmark report (base.frx) and you need to copy its scope to a subreport (child.frx). You need to replace PageHeader,PageFooter and DataBand with the name "Data1". The following code example assumes that both reports are in the root folder of the C drive.

First, you need to download two reports:

Report base = new Report (); base.Load (@ "C:\ base.frx"); Report child = new Report (); child.Load (@ "C:\ child.frx")

The next step is to get the page from the two reports. It is important to know the name of the page. The following example assumes that the page name in both reports is "Page1":

ReportPage basePage = base.FindObject ("Page1") as ReportPage;ReportPage childPage = child.FindObject ("Page1") as ReportPage

If you don't know the page names, you can get them from the index. For example, further, we can visit the first page of the two reports:

ReportPage basePage = baseReport.Pages [0] as ReportPage;ReportPage childPage = childReport.Pages [0] as ReportPage

Both options are appropriate and will lead to the same results.

Now you can replace PageHeader and PageFooter. It's simple:

ChildPage.PageHeader = basePage.PageHeader;childPage.PageFooter = basePage.PageFooter

These lines copy two bands with all the properties and settings. In addition, all objects above them will be copied and the properties will not be lost.

Next, replace DataBand with the name "Data1":

DataBand baseBand = basePage.FindObject ("Data1") as DataBand;DataBand childBand = childPage.FindObject ("Data1") as DataBand;// / Data1 / childPage.Bands.IndexOf / childBand /, / (/) /

Finally, the band with all the attributes and subobjects is copied and the binding to the data source responsible for the DataSource property is transferred. Without this binding, the band will not work properly and no data will be output from the database.

We just need to copy the data source. You can do this using the following code snippet:

For (int I = 0; I < baseReport.Dictionary.DataSources.Count; sources +) {childReport.Dictionary.DataSources.Add (baseReport.Dictionary.DataSources [I]);}

Therefore, all data sources have been replicated. If it is not necessary, you can only clone the desired clone.

That's all. Dozens of lines of code exercise makes it possible to copy bands and objects from one report to another. If there are many objects in the band, copying them with the designer can be long and tedious, and it will take longer to create them from scratch.

Of course, if the baseline report only copied the stripes in this example, you can perform this task more easily by simply copying and pasting the report file. Jokes aside, you can use this method to copy one or more bands from a collection without needing all the bands in the new report. Alternatively, you can get headers from one report, data strips from another report, and footers from a third report.

After reading the above, have you mastered the example analysis of how FastReport. Net copies Bands from one report to another? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report