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
-------------------------------------------------------------------- Directly select the printer to print without previewing -----------------------------------------------------
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 ()
{
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 ("eseshipmentqty "));
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;
}
------------------------------------------------------------------ Association display of the primary and secondary reports ------------------------------------------------------------------
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