Crystal Report
1. Based on the structure field of the report, an XSD file is created to hold the data.
2. Create a new report, and note that you want to browse to the XSD file when you create it.
After you've built it, find the property "custom Tool" for the report, putting the original
"CrystalDecisions.VSDesigner.CodeGen.ReportCodeGenerator"
Change to "CrystalDecisions.VSShell.CodeGen.ReportCodeGenerator"
This will result in a Zsmxb.cs file named after your report name, which is actually the following class ZSMXB
At the same time, create a page, put the Crystalreportviewer control on the page,
And to declare the class of the report at the top of the page file,
public class Fr_zsmxb:System.Windows.Forms.Form
{
ZSMXB crreportdocument;
.........
3. Establish a report structure
DataSet dss=new DataSet ();
DataTable dt=new DataTable ("ZSMXB");
Dt. Columns.Add ("Cchbh", System.Type.GetType ("System.String"));
Dt. Columns.Add ("Nglf", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("NCF", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Nqyf", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("NZSF", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Ntcf", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Ngz", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Nzjf", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Nylf", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Nwxf", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Nsy", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("NQTF", System.Type.GetType ("System.Decimal"));
Dt. Columns.Add ("Nxj", System.Type.GetType ("System.Decimal"));
Dss. Tables.add (DT);
Note: Here's the DataTable dt=new DataTable ("Zsmxb"), in which the table name "ZSMXB" is the same as the table name in your XSD file.
Also, DT's field name, type, and XSD file are the same, otherwise the query engine error is generated.
4. Incoming data for this DS
for (int i=0;i<this.ds.tables["ZSMXB"]. rows.count;i++)
{
DataRow Dr=dt. NewRow ();
dr["CCHBH"]=this.ds.tables["ZSMXB"]. rows[i]["CCHBH"];
dr["NGLF"]=this.ds.tables["ZSMXB"]. rows[i]["NGLF"];
dr["NCF"]=this.ds.tables["ZSMXB"]. rows[i]["NCF"];
dr["Nqyf"]=this.ds.tables["ZSMXB"]. rows[i]["NQYF"];
dr["NZSF"]=this.ds.tables["ZSMXB"]. rows[i]["NZSF"];
dr["Ntcf"]=this.ds.tables["ZSMXB"]. rows[i]["Ntcf"];
dr["Ngz"]=this.ds.tables["ZSMXB"]. rows[i]["Ngz"];
dr["NZJF"]=this.ds.tables["ZSMXB"]. rows[i]["NZJF"];
dr["NYLF"]=0;
dr["NWXF"]=0;
dr["Nsy"]=0;
dr["NQTF"]=this.ds.tables["ZSMXB"]. rows[i]["NQTF"];
dr["Nxj"]=system.convert.todecimal (dr["NGLF"). ToString ()) +system.convert.todecimal (dr["NCF"). ToString ();
Dt. Rows.Add (DR);
}
The DS here is the same as the query, just for example.
5. Bind the resulting report data source DSS to the Crystal Report.
Crreportdocument=new ZSMXB ();
Crreportdocument.setdatasource (DSS);
Crystalreportviewer1.reportsource = crreportdocument;