Implement dynamic reporting technology in .NET (1)

zhaozj2021-02-16  52

Ø Implement dynamic report technology in .NET (1)

I believe that I will not be too unfamiliar with everyone, it is an excellent third-party report making control. I used it to combine dynamic reports with PB. There is now a .NET project, there is a large number of reports to be implemented, then can the report technologies made by the original Formula ONE can continue to overline in .NET? After a few days of exploration, I finally put the original dynamic report solution using Formula One. Transplantation to .NET.

.NET calls the basic principle of COM components

The code running in Microsoft .NET Universal Language (CLR) is called managed code, and the code that is not in the CLR is called unmanaged code. It can be said that all COM components are non-managed code. The managed code components do not only depend on CLR, and they also require components that interact with it to rely on the CLR. Microsoft's solution is RCW (can be called by calling package) ---- a special type of agent used to call the unmanaged code from the hosting code. The figure below shows if the non-hosting component is called with RCWS. This figure includes a .NET program called NetUI.exe, two COM components called backend.dll and service.dll, as well as linking them.

Use TLBIMP to convert metadata

Not .NET first describes public interfaces using metadata. The COM type library also has metadata that describes the COM component utility interface. In fact, the functionality of RCW is mainly to convert metadata of the COM type into .NET. One tool TLBIMP (Type library importer) is used for this conversion in the .NET Framework Software Development Kit. TLBIMP reads the metadata from the COM type library and creates with the CLR matching part to call COM components.

You can also use the vs.net tool to directly reference the COM components (actually using RCW), the following routines use this method.

Report template management module instance analysis

The following is an example with a specific report template management module, indicating how to use Formula One technology in .NET.

Note: Each defined report has a corresponding template, the template can be used outside the Excel definition. Template management is a module, deleted, and modified modules corresponding to the report.

First, ready to work

1. Confirm that VS.NET2002 or VS.Net2003 is installed

2. Install or register F1

3. Install SQL Server and build the Report_List_Data table, the table structure is as follows:

Create Report_List_Data

(

Num int not null, - primary key

RPT_ID INT NOT NULL, - Report Table ID ID

RPT_NAME VARCHAR (60) Not Null, - Report Name

RPT_Data Image Null, - Report Content

User_name varchar (40) NULL, - Temporary

RPT_DATE DATETIME NULL, - Report Date

ConsTRAINT T_RPT_LIB_PK PRIMARY Key (NUM)

);

Second, interface design

1. Select Toolbox àwindow Form Controls à Add / Shift ... àcom Components, Choose Tidestone Formula One 6.0 Workbook

2. Create a new form to add new to the toolbox's F1 control, and some related controls join the form, and the interface is shown in the following figure:

Third, system design and encoding

1. One Open Module, the module form combo box retrieves the templates in all databases.

Add a ComboftMplateFillValue () function to the TemplateManger class constructor, use to fill the data // to the combo box to join the already saved template name

Private void CombotemplateFillValue ()

{

String strquery = "SELECT RPT_ID, RPT_NAME from Report_List_Data";

SqlDataReader areader = db.query (strquery);

While (areader.read ())

{

Combotemplate.Items.Add (Areader [1] .tostring () "[" areader [0] .tostring () "]");

}

AReader.close ();

}

Note: Where db.Query () is a query method in the custom database operation base class.

2. F1 control can be fully compatible with Excel format documents, we can define templates using Excel familiar with you, and then read into the F1 control. The following script can be added in the "Read Template" button.

Private void btnread_click (Object Sender, System.Eventargs E)

{

IF (OpenFileDialog1.Showdialog () == DialogResult.ok)

{

String TPLNAME = OpenFiledialog1.FileName.toString ();

TPLNAME = TPLNAME.Remove (0, TPLNAME.lastIndexof ("//") 1);

TPLNAME = TPLNAME.SUBSTRING (0, TPLNAME.LENGTH - 4); // Remove the extension

//Messagebox.show(filename);

Combotemplate.text = "Template" TPLNAME "[" Getpkid ("Report_List_Data", "RPT_ID"). TOSTRING () "]";

// Read Excel Files

Axf1book1.readex (OpenFileDialog1.FileName.toString ());

AXF1BOOK1.SHOWEDITBAR = true;

SHOWVSCROLLBAR ();

BTNDEL.ENABLED = FALSE;

}

}

Note: 1. Reading template name naming mode is "Template" "template name" "[template ID]" form

2. The main statement is ax1book1.readex (OpenFileDialog1.FileName.toString ()); the function is to read the template file into the F1 control.

3. The role of the getpkid () function in the script is to obtain the only ID value of the template, showvscrollbar (); mainly to save the F1 control slider has always existed

3. The read module can be modified directly in the control, or call the server server for F1 for modification, and the server server can be called very simple.

Private void btnserver_click (Object Sender, System.Eventargs E)

{

AXF1BOOK1.Allowdesigner = True;

Axf1book1.launchDesigner ();

}

转载请注明原文地址:https://www.9cbs.com/read-26907.html

New Post(0)