C # Crystal Report Summary

Source: Internet
Author: User

1. The data read from the database in the Crystal Report. When the field content is too long, it will affect the appearance. You need to set it to automatic line feed for display.

2. Open the "set object format" attribute of the field and select "extended attributes" under its "public" label. * This setting can make the border adaptive width
3. Open the expert section and select "extend to subsequent sections" in the details. If there are multiple nodes, you can select all the nodes;
4. Select the "extend to the bottom of the section when printing" attribute in "set object format" of the Line Control in the report, so that the line will automatically move down Based on the Data height of each row.

 

1. Create dataset. XSD to add a table and add several columns to the table.

2. Add a crystal report, draw a table, display columns in dataset to the Crystal Report, and add parameters (p1.p2. p3.p4. P5)

3. Use code to convert a able to XML or dataset.

Using crystaldecisions. crystalreports. engine; using dbhelper; using productsys; using system. data; using system. data. oledb; using system. windows. forms; class clsdycrystalreportcore {/// <summary> /// convert all the data required for converting the input able into a report template to string /// </Summary>/ // <Param name = "DT"> source table </param> // The datatable required by the <returns> Report Template </returns> Public datatable dtx (datatable DT) {bigtable. tablemo Dedatatable dtx1 = new bigtable. tablemodedatatable (); object [] OBJ = new object [DT. columns. count]; // note: the number of columns in the selected table must be <= the number of fields in bigtable // enter the protection code for (INT I = 0; I <DT. rows. count; I ++) {dtx1.rows. add (dtx1.newrow (); For (Int J = 0; j <DT. columns. count; j ++) {dtx1.rows [I] [J] = DT. rows [I] [J]. tostring () ;}} return dtx1 ;}/// <summary> /// get reportdocument /// use the obtained object to set reportview /// crystalrep Ortviewer1.reportsource = myreport; // crystalreportviewer1.refreshreport (); ////// </Summary> /// <Param name = "titile"> table title </param> /// <Param name = "dtsource"> data source </param> // <returns> </returns> Public reportdocument getreportsource (string titile, datatable dtsource) {datatable dt1 = dtsource; datatable dtx = new datatable (); // process ds1 clsdycrystalreportcore xcore = new clsdycrystalreportcore (); Dtx = xcore. dtx (dt1); reportdocument myreport = new reportdocument (); string reportpath = system. threading. thread. getdomain (). basedirectory + @ "/resource/timereport. RPT "; myreport. load (reportpath); // bind a dataset. Note that a report uses one dataset. Myreport. setdatasource (dtx); // get the number of columns int Cols = dt1.columns. count; If (Cols> = 9) {// set the parameter, that is, the header for (INT I = 1; I <= Cols; I ++) {if (I <= Cols) // dt1.columns [I-1]. columnname myreport. setparametervalue ("p" + I. tostring (), dt1.columns [I-1]. columnname); else // note that this parameter cannot be saved, and a null value of myreport must be given to unused parameters. setparametervalue ("p" + I. tostring (), "");} myreport. setparametervalue ("titile", titile);} else {for (INT I = 1; I <= 9; I ++) {if (I <= Cols) // dt1.columns [I-1]. columnname myreport. setparametervalue ("p" + I. tostring (), dt1.columns [I-1]. columnname); else // note that this parameter cannot be saved, and a null value of myreport must be given to unused parameters. setparametervalue ("p" + I. tostring (), "");} myreport. setparametervalue ("titile", titile) ;}return myreport ;}}
// Control call method clsdycrystalreportcore CLS = new clsdycrystalreportcore (); reportdocument RD = Cls. getreportsource (reportname, source); crystalreportviewer1.reportsource = RD;

  

The preceding method uses one dataset. XSD to print multiple reports,

 

The following is a method for calling multiple templates through the abstract factory.

// Display the string sqlstr = "select * From userinfo" in crastalreportviewer1 directly through datatable ";
Datatable dt = dbhelper. dbhelpersql. dataquery (sqlstr). Tables [0];
            ReportClass reportClass = ReportFactory.getInstance(reportname);
Reportclass. setdatasource (DT); // set the data source crystalreportviewer1.reportsource = reportclass;

Using crystaldecisions. crystalreports. engine; using system. collections. generic; using system. LINQ; using system. text; namespace productsys. class {// <summary> /// use factory mode to initialize the report /// </Summary> class reportfactory {private reportfactory () {} public static reportclass getinstance (string reportname) {return (reportclass) activator. createinstance (type. getType (reportname ));}}}

  

Push and pull cannot be clearly divided. In any case, an object is displayed through XSD but not through the XSD file ......

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.