Report related: http://www.cnblogs.com/dahuzizyd/archive/2007/04/12/csharp_excel_report_chart_8.html
Http://www.cnblogs.com/xiaotao823/archive/2006/07/06/444339.html
Crystal Report
Production and Use
This article is divided into the following six parts:
I,Crystal report for. netFunctions
II,Crystal ReportOverall Structure
III,Report Data Access Execution Mode
IV,Report Type
V,Crystal ReportDesigner Layout
VI,Crystal ReportSpecific instance
Recently, the project is coming to an end and should be summarized as required.. NetEnvironmentProgramNew personnel help, and a document preparation for new personnel training.
I believe that reports in most applications are a headache for programmers. However. NetThe environment contains powerful reporting tools: Crystal Report. It can interact well with databases and make various beautiful reports and analysis charts..It can solve problems for developers. For example:
Slave1993Year,Crystal ReportYesVisual StudioPart of the suite. Currently
Visual Studio. NETInWindowsLeading in the field of report writing, promotingWebFuture development of reports. LatestVisual Studio. NETTo integrate the development environment(IDE)CompletedCrystal report9.0To enhanceVisual Studio. NETDevelopment functions,Crystal ReportProvide developers with the best possibleAPI.
I,Crystal report for. netFunctions
By addingCrystal ReportThe report processing function is integrated into your own database applications,WindowsApplications andWebDevelopers can save development time to meet user needs.Crystal ReportSupports most popular development languages and allows you to easily add reports to any application.
Specifically,Crystal ReportThe following functions are available:
1Comprehensive database access:
Crystal ReportContains more35Data source driver, you can accessXML, Enterprises, and relational databases.
2Extensive design formats and designs:
PassCrystal ReportYou can convert a database to highly interactive content. From100Select multiple and medium format options, including parameters, ing, cross tabulation, and hyperlink, to enhance the impact of reports.
3Powerful chart design functions:
Crystal ReportYou can include a variety of easy-to-read charts in a report (a wide range of report types are provided, such as bar charts, line charts, area charts, pie charts, Gantt charts, and stock charts ).
4Flexible Application Integration Technology:
Crystal ReportFlexibleJava,ComAnd. Net SDKAnd embeddedReport application server,REPORT AND ENTERPRISEWebApplications are tightly integrated. UseCrystal ReportOf"Zero"The browser control on the client provides rich report interaction, creation, and modification functions for the most terminal support.
5Powerful report export:
Crystal reprortAll reports can be exported in a variety of formats: includingXML,PDF,Html, AndMicrosoft Excel.
II,Crystal ReportOverall Structure
Reports with two-layer structureCrystal ReportRequired:
Interface:
The interface only needs to be usedWinformForm orWebUse the browser in the program.
Background:
1,Crystal Report Engine (crengine. dll)
Merge data and report files, and output data in different formats.Crystal ReportTransfer. AspxSimple and clearHTML.
2,Crystal Report designer (crdesigner. dll)
UseCrystal Report designerYou can create reports, design titles, insert data, formulas, tables, and subreports.
3,The. rpt report file
The first step in applying a report to your application is to useCrystal Report designerCreate a report. But if you already have some ready-made samples, you can use them now.
4,The Data Source
. RptThe method for obtaining data from a file depends on the method you choose. You can choose to makeCrystal ReportTo obtain data without manual writingCode, You can also choose to bind yourDatasetAnd pass it into the report file.
5,Crystal Report Viewer
Crystal Report ViewerIs a container that can insert pages (. NetIs called a control ).
Iii. Report Data Access Execution Mode
1Pull ModelPull Model
In the PULL model, the driver connects to the database and pulls in the data as needed. When using this model, the connection to the database andSQLAll commands are composedCrystal ReportsIt does not require developers to write code. If you do not need to write any special code at runtime, use the PULL model.
2, PUSH modelPush Model
On the contrary, the pushing model requires developers to write code to connect to the database and executeSQLCommand to create a record set or dataset that matches the fields in the report and pass the object to the report. This method allows you to place the connection share in the application andCrystal ReportsFilter the data before receiving the data.
Iv. Report Type
Crystal Report designerIt can be a report independent of the solution, but it can also be loaded into the report contained in the solution.
1,Stronugly-typed report:
When a report is added to the solution, the report becomesStronugly-typed report. In this case, you can directly create a report instance (which can reduce some code) and hide it. Of course you can clickSolution Explorer"Show all filesTo display it.
2,Un-typed report:
Reports that are not included in the solution areUn-typed report. In this case, you must createCrystal Report EngineOf''Report document''And manually load the report.
V,Crystal ReportDesigner Layout
FirstVisual Studio. NETAdd a forwardWindowsOrWebForm to publish dataCrystalReport file:
After the report is successfully added, open the report:
You can see the complete layout of the designer.
1, Field Resource Manager:
List all fields in the report, such as the database fields, parameter fields, and formula fields used. You can modify and delete a Field object here.
2Main Report window:
Displays the Main Report in the report window. For reports that contain subreports, there is a main report window and a subreport for each deepening (by double-clicking) has
Subreport window. You can right-click any blank position in the report window to start the report shortcut menu.
3Main Toolbar of the crystal report:
Including record selection, classification, and Text object formatting icons. You can move or change the size of the entire toolbar.
4, Crystal report insert toolbar:
You can insert icons for summary fields, groups, subreports, charts, and images. You can alsoCrystal ReportClick the mouse in the toolbar to select"Insert".
VI,Crystal ReportSpecific instance
The examples in this section are divided into two parts:WindowsIn the ApplicationCrystal ReportDevelopment;WebIn the ApplicationCrystal ReportDevelop applications. In addition, the PULL model and push model examples are introduced in two environments.
The software environment used in this example:Microsoft Visual maxcompute 2005;Microsoft SQL Server 2005. Data example:Server:Cotton-BDatabase Name:LhomocysteineDatabase Table:Projectstage
Data Table Structure:
Data:
The main function is to count the number of workers in the project phase.
1, How to design a report file template.
1)Add a result setDataset1.xsdAnd add tables.
2)First, add a report file.RPTFile
3)Use report experts"Project Data"Select"Ado.NetDataset", Insert"Projectstage"Table, select the report on the field Selector
4)Select the field basis for grouping
5)Select the displayed chart and topic information
The final result is as follows.
2,WindowsIn the ApplicationCrystal ReportDevelopment
2.1Pull ModelPull ModelOfDemo
In PULL modeSQLThe statement must be used when a condition parameter is added.{? Parameter Name}Method.
For example,"Select projectid, manhours from projectstage where projectid = {? Parm}"ParmIs the parameter name.
Private void form1_load (Object sender, eventargs E)
{
ReportDocument RPT = new reportdocument ();
Rpt. Load (application. startuppath + "crystalreport. rpt ");
// SetdatabaselogonIn PULL mode, you must use this method to set logon information. Parameter 1: User//Name; parameter 2: password; parameter 3: Server; parameter 4: Database Name
Rpt. setdatabaselogon ("sa", "123456", "cotton-B", "lhomocysteine ");
//Transmit parameters to the crystal report. Parameter 1: parameter name; parameter 2: parameter value;
Rpt. setparametervalue ("parm", 1 );
Rpt. setparametervalue ("title ","Pull ModelDemo ");
// Crystalreportviewer1Is the Crystal Report browser. The following shows how to assign an image to the browser.
Crystalreportviewer1.reportsource = RPT;
}
2.2Push ModelPush ModelOfDemo
Programmed and assembled in the push modeDatasetInSQLThe fields in the statement must matchSQLStatement fields are consistent. Simply put, the Crystal Report in the push mode is a template. After setting the report format in the designer, assemble the report.DatasetYou can generate a report.
Private void form1_load (Object sender, eventargs E)
{
Crystalreport1 report = new crystalreport1 ();
String sdbconnetction = "Data Source = cotton-B; initial catalog = lhomocysteine; persist Security info = true; user id = sa; Password = 123456 ";
Dataset1 DS = new dataset1 ();
Sqlconnection conn = new sqlconnection (sdbconnetction );
Sqldataadapter adapterprojectstage = new sqldataadapter
("Select * From projectstage where projectid = 2", Conn );
Adapterprojectstage. Fill (DS, "projectstage ");
Report. setdatasource (DS );
Report. setparametervalue ("title ","Push ModelDemo ");
Crystalreportviewer1.reportsource = report;
}
3,WebIn the ApplicationCrystal ReportDevelopment
3.1Pull ModelPull ModelOfDemo
AndWinformThe pull model of an application is the same as that in the crystal report.SQLThe statement must be used when a condition parameter is added.{? Parameter Name}Method.
For example,"Select projectid, manhours from projectstage where projectid = {? Parm}"ParmIs the parameter name.
Protected void test_pullmodel (Object sender, eventargs E)
{
// Crystalreport. rptIs the name of the crystal report file;Crystalreportsource1Is the image of the crystal report data source added to the page from the toolbox.
Crystalreportsource1.reportdocument. Load (server. mappath ("crystalreport. rpt "));
// SetdatabaselogonIn PULL mode, you must use this method to set logon information. Parameters 1: User Name; Parameters 2: password; Parameters 3: Server; Parameters 4: Database Name
Crystalreportsource1.reportdocument. setdatabaselogon ("sa", "123456", "cotton-B", "lhomocysteine ");
//Transmit parameters to the crystal report. Parameter 1: parameter name; parameter 2: parameter value;
// Crystalreportsource1.reportdocument. setparametervalue ("title ","Model pullingDemo ");
Crystalreportsource1.reportdocument. setparametervalue ("parm", 1 );
//Bind the crystal report data source.
Crystalreportsource1.databind ();
// Crystalreportviewer1Is the Crystal Report browser. The following shows how to assign an image to the browser.
Crystalreportviewer1.reportsource = crystalreportsource1;
Crystalreportviewer1.databind ();
}
3.2Push ModelPush ModelOfDemo
String sdbconnetction = "Data Source = cotton-B; initial catalog = lhomocysteine; persist Security info = true; user id = sa; Password = 123456 ";
Dataset1 DS = new dataset1 ();
Sqlconnection conn = new sqlconnection (sdbconnetction );
Sqldataadapter adapterprojectstage = new sqldataadapter ("select * From projectstage where projectid = 2", Conn );
Adapterprojectstage. Fill (DS, "projectstage ");
Crystalreportsource1.reportdocument. Load (server. mappath ("crystalreport. rpt "));
Crystalreportsource1.reportdocument. setdatasource (Ds. Tables ["projectstage"]);
Crystalreportsource1.databind ();
Crystalreportviewer1.reportsource = crystalreportsource1;
Crystalreportviewer1.databind ();