Crystalreportviewer + receivecrystalreport. rpt + dataset. XSD

Source: Internet
Author: User
Crystalreportviewer + receivecrystalreport. rpt + dataset. XSD

Crystalreportviewer + receivecrystalreport. Rpt (report file) + dataset. XSD (Dataset)

1. The reportsource attribute of crystalreportviewer specifies a receivecrystalreport. rpt file
2. Add a dataset. XSD file and add the field information to be displayed in the report (must be consistent with that in the database)
3. Open the receivecrystalreport. rpt file, right-click databasefields in the right window (Database Expert)


Open projectdata> ADO. Net datasets in the left-side window, select a dataset, and add it to the right. Click OK,
Drag the fields to the open report file.

Private void printreceiveorder_load (Object sender, eventargs E)
{
Try
{
Receivecrystalreport RPT = new receivecrystalreport ();
Dataset DS = new dataset ();
String strconn = "Data Source = ITE-03; initial catalog = test; user id = sa; Password = 123456 ";
Sqlconnection conn = new sqlconnection (strconn );
Sqldataadapter da = new sqldataadapter ("select ID, pay_time, type, remark from test", Conn );
Da. Fill (DS, "test ");
Rpt. setdatasource (Ds. Tables ["test"]);
This. crystalreportviewer1.reportsource = RPT;
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
}
}

 

1. fixed number of entries. Adjust the section height or write the formula:
Right-click the detail section and choose format section...
Select New Page after, click the formula button on the right, and enter:
Recordnumber mod 5 = 0
The page is displayed for every five records.

2. line feed display
Right-click a field and select "can grow" from fromat object.

 

3. Set the active/standby table report Association display

 

Select subreport
Right-click Change subreport links

Select an associated field.

4. Paper hitting

Right-click and choose print design.

5. Horizontal and left-side doubles (dual copies on one page)

Set the width to half of the page, preferably less than half of the page

-------------------------------------------------------------------- Do not Preview
Directly select the printer to print -----------------------------------------------------

Printdialog print = new printdialog ();
Print. showdialog (); // select a printer
Printupscrystalreport ups = new printupscrystalreport (); // report Design
Ups. setparametervalue ("code", "ph20120327"); // set parameters
Ups. setparametervalue ("telephone", "123456792 ");
Ups. printoptions. printername = print. printersettings. printername; // print with the selected printer. If not selected, print with the default printer.
Ups. printtoprinter (1, true, 1, 1); // The key sentence. Print it directly without previewing.

Ups. setdatasource (DT); // you can specify a data source.

--------------------------------------------------------------------------- Use an object as report data -----------------------------------------

Public printreceiveorder (receiveshipmentorder orderinfo, list <receiveshipmentorderitem> orderitem)
{
Initializecomponent ();
Bindreport (orderinfo, orderitem );
}
// Bind a report
Private void bindreport (receiveshipmentorder orderinfo, list <receiveshipmentorderitem> orderitem)
{

Parameterfields = loadorderinfo (orderinfo );
Try
{
This. crystalreportviewer1.parameterfieldinfo = parameterfields;
Receivecrystalreport RPT = new receivecrystalreport ();
Rpt. setdatasource (loaddetailinfo (orderitem). Tables ["orderitem"]);
This. crystalreportviewer1.reportsource = RPT;
}
Catch (exception ex)
{

}

}

// Data Source
Private dataset loaddetailinfo (list <receiveshipmentorderitem> orderitem)
{
Dataset DS = createreportdataset ();
If (orderitem! = NULL)
{
Datatable deliveryordertable = Ds. Tables ["orderitem"];
Foreach (exploreshipmentorderitem item in orderitem)
{
Datarow DR = deliveryordertable. newrow ();
Dr ["ID"] = item. purchaseproduct. ID;
Dr ["ordercode"] = item. purchaseproduct. ordercode;
Dr ["eseshipmentqty"] = item. receiveshipmentqty. tostring ();
Dr ["reimbursemark"] = (item. purchaseproduct. reimbursemark? "Yes": "no ");
Dr ["image"] = item. purchaseproduct. image; // binary type
Deliveryordertable. Rows. Add (DR );
}
}
Return Ds;
}

private dataset createreportdataset ()
{< br> dataset DS = new dataset ();
datatable deliveryordertable = new datatable ("orderitem ");
deliveryordertable. columns. add (New datacolumn ("image", system. type. getType ("system. byte [] ");
deliveryordertable. columns. add (New datacolumn ("ordercode");
deliveryordertable. columns. add (New datacolumn ("receiveshipmentqty");
deliveryordertable. columns. add (New datacolumn ("reimbursemark");
DS. tables. add (deliveryordertable);

Return Ds;
}

// Set header Parameters

Private parameterfields loadorderinfo (receiveshipmentorder orderview)
{
Parameterfields orderinfo = new parameterfields ();
If (orderview! = NULL)
{
Orderinfo. Add (getparameterfield ("suppliername", orderview. Supplier. Name ));
Orderinfo. Add (getparameterfield ("name", orderview. createuser. Name ));
String state = "";
Orderinfo. Add (getparameterfield ("State", State ));
Orderinfo. Add (getparameterfield ("receivecode", orderview. Code ));
}
Return orderinfo;
}

// Set parameter fields
Private parameterfield getparameterfield (string name, string value)
{
Parameterfield field = new parameterfield ();
Parameterdiscretevalue fieldvalue = new parameterdiscretevalue ();
Field. parameterfieldname = Name;
Fieldvalue. value = value;
Field. currentvalues. Add (fieldvalue );
Return field;
}

 

 

 

------------------------------------------------------------------ Primary and secondary reports
Table join display ------------------------------------------------------------------

Private void bindlist (list <waitdeliveryview> deliverylist)
{
Ordercrystalreport RPT = new ordercrystalreport ();
Rpt. setdatasource (loaddetailinfo (deliverylist). Tables ["packageitem"]);
Rpt. subreports ["orderdetailreport. rpt"]. setdatasource (loaddetailinfo (deliverylist). Tables ["productitem"]);
This. crystalreportviewer1.reportsource = RPT;
}

// Data Source
Private dataset loaddetailinfo (list <waitdeliveryview> deliverylist)
{
Dataset DS = createreportdataset ();
If (deliverylist! = NULL)
{
Datatable packagetable = Ds. Tables ["packageitem"];

Datatable producttable = Ds. Tables ["productitem"];

Int Total = 0;
Int I = 0;
Foreach (waitdeliveryview item in deliverylist)
{
Datarow DR = packagetable. newrow ();
Dr ["ID"] = item. Package. ID;
Dr ["ordercode"] = item. Package. Code;
Dr ["customname"] = item. Package. Order. buyer. fullname;
Dr ["deliveryway"] = item. Package. Delivery. Name;
Dr ["Total"] = total;
Packagetable. Rows. Add (DR );

Foreach (orderproduct items in item. Package. orderproducts)
{
Datarow DRS = producttable. newrow ();
Drs ["ID"] = item. Package. ID;
Drs ["no"] = I + 1;
// Display the product number + (SKU)
Drs ["item"] = items. Code + "" + items. SKU;
Drs ["QTY"] = items. productqty;
Total + = items. productqty;
Producttable. Rows. Add (DRS );
}
}
}
Return Ds;
}

Private dataset createreportdataset ()
{
Dataset DS = new dataset ();
Datatable packagetable = new datatable ("packageitem ");
Packagetable. Columns. Add (New datacolumn ("ID "));
Packagetable. Columns. Add (New datacolumn ("ordercode "));
Packagetable. Columns. Add (New datacolumn ("customname "));
Packagetable. Columns. Add (New datacolumn ("deliveryway "));
Packagetable. Columns. Add (New datacolumn ("Total "));
DS. Tables. Add (packagetable );

Datatable producttable = new datatable ("productitem ");
Producttable. Columns. Add (New datacolumn ("ID "));
Producttable. Columns. Add (New datacolumn ("no "));
Producttable. Columns. Add (New datacolumn ("item "));
Producttable. Columns. Add (New datacolumn ("QTY "));
DS. Tables. Add (producttable );
Return Ds;
}

 

Detailed Report Settings

Materials

Document 2

Materials

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.