There is currently more Web report tools under the development of B / S structures, but some complicated features are still unreasonable, I am also suffering. Dynamic Binding Data Sets and Dynamic Adding Fields The feature has been talked for a long time, I also talk about my idea of implementing myself under Ming-WebReport tool. The way here should be limited to Ming-WebReport tools, just a realistic idea. Other tools, such as Crystal Report should also be realized, I hope everyone will communicate.
Recently, the company purchased a web report tool called Ming-WebReport. Here is a little experience in using Ming-WebReport, and share it with you.
How Ming-WebReport addresses the "Dynamic Add Field" and "Dynamic Bind Results Set" problem:
1, Ming-WebReport Dynamic Data Binding Implementation Ming-WebReport Report Tools There are three parts: Report Designers, Server Report Engines, and Report Browsers. Dynamic data in the report template has two formats: separate variables and formatted data sets.
<1> You can customize the variable parameters in the report template, and call the report template can be dynamically assigned to the variables of the report. Variable Types support all basic variable types (including arrays); the parameters pass between reports and pages don't talk more, relatively simple. <2> During the design of the report template, the binding query or DataSet is only sample data for report design, the sample data: A. Determine the result set and the corresponding field name; B. Determine the data structure of the result set (Such as multi-level reports, cross-reports, etc.); C. Debug report template
Note: There are a variety of means for obtaining sample data: A. Direct connection database (table / view / SQL statement / stored procedure); B. Import the XML documentation in standard format.
<3> Report Design is deployed to the server side, you need to call the server-side report engine, dynamically bind the report template to prepare the data set for the report. A. Ming-WebReport Report Engines support most popular web development environments, including ASP, ASP.NET, J2EE, and PHP. (Here is asp.net as an example) B. When binding the data set for the report, the field of the data set to the report is provided to include the data field required by the report, and the field name is consistent. a. Direct binding result set script example, at this time, DataSet contains the data set field required by the report: // Newly creates a report engine object MRENGINE ENGINE = myViewer.Engine; / / Set the root path (virtual path) of the report directory. Rootpath = "/ yourapp / reports /";
/ / Dynamically bind DataSet, where the data set here must be a report dataset name setup during the design report. Engine.addDataTable ("ReportDataSetName", MyDataSet.Tables ["Table1"]); Engine.bind ("MyReport"); // Dynamic Binding Report
b. Script of manually build report data set objects Samples because Ming-WebReport's report dataset objects are open, so you can manually create data sets required by the report template, this function is the key to realizing dynamic binding result sets. . // Create a report dataset object mrdataObject dataobj = new mrdataobject (this);
// 1, create a data set field // method: mrdataObject.addfield (String "FieldName", Type FieldType, // int filedsize) // creates a characteristic field Filed1 Dataobj.AddField ("FieldName1", Typeof (String), 20); // Create a set field Field2 DataObj.AddField ("FieldName2", TypeOf (Int); // Tip: The above TYPE can be obtained by FieldValue.gettype ().
// 2, add data to the data set with behavior units, // Add a line each time, method: mrdataObject.addrow (array rowdata); // Parameter is a one-dimensional array of sizes. Dataobj.addrow (new object [] {"stringvalue1", 1}; Dataobj.addrow (new object [] {"stringvalue2", 2}); // can also add multi-line, method: MrDataObject.addrows (Array Rows); // Parameter is an array containing multiple line data arrays. Object [] rows = new object []; rows (0) = new object [] {"stringvalul3", 3}; rows (1) = new object [] {"stringvalul4", 4}; dataobj.addrows (ROWS) ;
// 3, set the data set to the report, bind the report.
// New Report Engine Object MRENGINE ENGINE = myViewer.Engine; // Set the root path (virtual path) of the report directory Engine.RootPath = "/ Yourapp / Reports /"; // Dynamic Bind MRDataObject Engine.AddDataTable ("ReportDataSetName ", DataObj); // Dynamic Binding Report Engine.Bind (" MyReport ");
2 The API can solve this problem by means of variable parameters. <1> First take into account the format issues of the report template, you need to control the maximum number of dynamically add fields, this maximum number is subject to the number of records that can be affected according to the report display format. Then design the report template according to this maximum field.
<2> is then displayed by processing the data of the dynamic field. The report template requires dynamic control elements, such as Label corresponding to each field, value Value, etc., can be dynamically displayed with data set. Data elements in the report can be divided into single line data sets and multi-line data sets, which can define different data sets as needed. Then dynamically display data according to the data set provided by the page. Tip: The single line of data can also be transmitted with variables.
<3> Finally, the format of the dynamic field controls the format of the dynamic field needs to use the template script provided by Ming-WebReport, but it can solve some trouble questions. Control Dynamic fields requires dedicated parameters to indicate those fields to display those fields, then we can use scripts, call the page to pass the parameters of the report to determine the fields, hide those fields. The functionality of this dynamically added fields is implemented, in fact, design reports based on the maximum fields that can withstand in the report format, and this time the fields are temporary, which fields are displayed during operation, which fields are hidden in accordance with page input parameters Using scripts to control. 3. Summary Currently Ming-WebReport has not fully disclosed to dynamically create, modify the function of the report template, so it is not very convenient to handle this dynamic field. I hope I want to be interested in discussing. Related Website: http://www.soft2web.com/webreport/index.htm