When is the best way to use a code report and when in frx format

2020-02-29

As you probably know, reports in FastReport.Net can be created not only in a special designer, but also from the code of the user application. At the same time, instead of the usual file with frx extension, you will get a class of report. It can be converted into a library and used in different projects. What is this way of creating such report?

Take a look at this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 //Create instance of class Report
 Report report = new Report();
 
 //load data
 DataSet ds = new DataSet();
 ds.ReadXml(AppFolder + "\\nwind.xml");
 
 //Register data source
 report.RegisterData(ds);
 
 //Enable data table
 report.GetDataSource("Products").Enabled = true;
 
 //Add report page
 ReportPage page = new ReportPage();
 report.Pages.Add(page);
 page.CreateUniqueName();
 
 //Create GroupHeader band
 GroupHeaderBand group = new GroupHeaderBand();
 page.Bands.Add(group);
 group.CreateUniqueName();
 group.Height = Units.Centimeters * 1;
 group.Condition = "[Products.ProductName].Substring(0,1)";
 group.SortOrder = FastReport.SortOrder.Ascending;
 
 // create group text
 TextObject groupTxt = new TextObject();
 groupTxt.Parent = group;
 groupTxt.CreateUniqueName();
 groupTxt.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 1);
 groupTxt.Text = "[[Products.ProductName].Substring(0,1)]";
 groupTxt.Font = new Font("Arial", 14, FontStyle.Bold); 
 groupTxt.VertAlign = VertAlign.Center;
 groupTxt.Fill = new LinearGradientFill(Color.LightGoldenrodYellow, Color.Gold, 90, 0.5f, 1);
 
 // create data band
 DataBand data = new DataBand();
 group.Data = data;
 data.CreateUniqueName();
 data.DataSource = report.GetDataSource("Products");
 data.Height = Units.Centimeters * 0.5f;
 
 // create product name text
 TextObject productText = new TextObject();
 productText.Parent = data;
 productText.CreateUniqueName();
 productText.Bounds = new RectangleF(0, 0, Units.Centimeters * 10, Units.Centimeters * 0.5f);
 productText.Text = "[Products.ProductName]";
 
 // create group footer
 group.GroupFooter = new GroupFooterBand();
 group.GroupFooter.CreateUniqueName();
 group.GroupFooter.Height = Units.Centimeters * 1;
 
 if (PDFCheckBox.Checked)
 {
 report.Prepare();
 FastReport.Export.Pdf.PDFExport export = new FastReport.Export.Pdf.PDFExport();
 export.Export(report);
 }
 else
 report.Show();

 This is an example of creating a report template with groups. As you can see, we are consistently creating report objects, starting with the report and pages to text objects. We put the created objects into the other and configure the properties of their display. This requires a good performance FastReport.Net report template structure. In addition to this, to achieve the desired arrangement of the elements, you'll have plenty of time to run a report for the visual evaluation and to correct the properties of objects, exhibiting the desired width or coordinates. Therefore, this approach should be to report on lists, matrices, tables - where there is no need to adjust the location of the elements relative to each other.

The main advantage of a report generated in the code is the ability to edit reports during execution, adding code depending on conditions or events. This allows you to create reports with complex logic that directly depends on the client application itself.

It is no secret that FastReport.Net report templates are xml-like format, despite the extension frx. These templates are easy to transfer and view on other computers via Viewer program. Mobility and independence from the client application - it is undeniable advantages of the traditional pattern in frx report format, or a version with data filled in fpx format. Therefore, having in your application reports generated from the code, many would like to be able to convert them to normal xml-like format frx. It incredibly simple to do so:

1
2
Report report = new Report();
report.Save("C:\\report.frx");

 That is, you just need to use the “Save” function in the report object. As the parameters are passed to the path to the file name in which to save the report. So we can use a single account that is created from the code, and, if necessary, to convert it into a traditional format frx. The resulting file can be transferred to other developers or users.

Both code-based reports and frx reports have their advantages. The first is that it wins when the report needs to be changed directly "on the go," the second is when a mobile report is required, or the template has many elements with a clearly defined location relative to each other. You need to choose a way to create a report based on these benefits.

12. August 2024

Erstellen und Installieren des Postgres-Plugins in FastReport .NET

In diesem Artikel wird beschrieben, wie Sie mit dem FastReport .NET-Plugin für den Berichtsdesigner aus Visual Studio über den NuGet-Server eine Verbindung zur Datenbank herstellen.
8. August 2024

Installation von FastReport .NET und ihren Komponenten unter Windows

Schritt für Schritt Anleitung zur Online- und manuellen Installation über den Registrierungscode FastReport .NET und seine Komponenten in Windows.
26. Juli 2024

Aktualisierung von HTMLObject als Plugin für FastReport .NET

Ausführliche Anleitung zur Verwendung des neuen HTMLObject-Plugins, das die Aufteilung des HTML-Doms in FastReport-Berichtsobjekte verwendet.
Fast Reports
  • 800-985-8986 (Englisch, die USA)
  • +4930568373928 (Deutsch)
  • +55 19 98147-8148 (Portugiesisch)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314

© 1998-2024 Fast Reports Inc.