How the report generator FastReport .Net stores and loads reports

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

In the new version of FastReport .NET 2021.1, we have implemented support for .NET 5. Added a new barcode-Deutsce Post Leitcode. The algorithm for converting RTF into report objects has been significantly improved. And also added a new function for converting numbers.

Store and load reports

You can store reports in the following ways:

Method description:

In web form

The typical scenario we have seen before uses this method. The report is stored in the ReportResourceString property of the WebReport component. This method has the following advantages and disadvantages.

  • This is one of the simplest FastReport.Net working methods.
  • The report template is stored in the ViewState of the web form. It will be transmitted on the client. If the size of the report is large, it may slow down the work speed.
  • This method is not compatible with the "Medium Trust" mode.

The report loading is automatic.

In the .FRX file

This method assumes that the report is stored in a file in a special folder "App_Data". need to be able to do this.
Run the report designer:
create a report and save it to a .FRX file.
In the "Solution Explorer", select the "App_Data" folder, right-click, and select the "Add|Existing Project..." item. Select the report file you just saved.
Select the WebReport component and clear its ReportResourceString property.
Select the "ReportFile" property, call its editor, and select the report from the "App_Data" folder.
This method has the following pros and cons:

  • The report will not be sent to the client machine.
  • This method is not compatible with the "medium trust" mode.

The report loading is automatic.

You can also load the report through the WebReport.StartReport event handler.

Code example in the StartReport event handler
(sender as WebReport).Report.Load(this.Server.MapPath("~/App_Data/report.frx")). As a C#/VB.NET class

In this method, you treat the report as a class. need to be able to do this:

Design your report and save it in a .cs/.vb file. To do this, select "File Type" in the "Save" dialog box. The file type may be .cs or .vb-it depends on the script language in the report (can be changed in the "Report|Options..." menu).
Include this file in your project. It is best to save it in the "App_Code" folder.
Clear the ReportResourceString and ReportFile properties of the WebReport component.
This method has the following advantages and disadvantages:

  • You can use the report as a normal class;
  • You can debug the report in Visual Studio;
  • This is the only way to use reports in "Medium Trust" mode.
  • You cannot edit such reports. To do this, you need the original .FRX file.

To use the report, create the WebReport.StartReport event handler. In this handler, you should do the following:
Create an instance of the report class.
Registration data.
Set the report to the Report property of the WebReport component.
Example of StartReport event handler.
SimpleListReport report = new SimpleListReport();
report.RegisterDataAsp(your_data, "your_data_name");
WebReport1.Report = report; The
prepared report can be displayed through the WebReport.StartReport event handler using the WebReport.ReportDone property. Load and display the sample code of the prepared report in StartReport.
(sender as WebReport).Report.LoadPrepared(this.Server.MapPath("~/App_Data/Prepared.fpx"));
(sender as WebReport).ReportDone = true;

Registration data

If you use the "Smart Label" menu of the WebReport component to select the data source, you do not need to manually register the data. In this case, FastReport.Net stores the name of the data source in the ReportDataSources property of the WebReport component.

If you do not want to use this method to register data, you need to register manually. This can be done by using the StartReport event of the WebReport component. In this event handler, you can call the RegisterData and RegisterDataAsp methods of the report. The report can be accessed through the WebReport.Report property.

webReport1.Report.RegisterData (myDataSet).

Read more about registration data in this section.

Pass a value to the report parameter

To pass a value to a report parameter, use the SetParameterValue method of the Report object. This method is described in detail in the chapter "Working with Windows.Forms".

To use this method in ASP.NET, you need to create an event handler for the StartReport event of the WebReport component. The report can be accessed through WebReport.

Report属性:
webReport1.Report.SetParameterValue("MyParam", 10);

Guess you like

Origin blog.51cto.com/15078157/2660363