I. Preface Recently, the project requires the document batch printing function. rdlc is preferred. After the development of several Visual Studio versions, the rdlc has become more mature and the operation methods have become concise. Compared with the vs2005 version, the rdlc has a qualitative improvement, but there are still some shortcomings: 1. built-in functions do not support C # And only support Visual Basic. 2. Asp.net MVC is not supported, and webform and winform are supported. 3. When developing webform in vs2008 and earlier versions, rdlc is not recommended because the report style is not compatible with chrome. If there will be plenty of time in the future, I will share a series of rdlc application instances. Let's talk less and get down to the truth. Ii. Test Data
-- Order table Create Table fcworder ( Id int identity (1, 1 ), Ordercode varchar (50), -- Order Number Ordername varchar (50), -- order name Opername varchar (50),-handled Comname varchar (50), -- CUSTOMER NAME Createtime datetime, -- order date Barcode image -- barcode, reserved field. ) -- Order details Create Table fcworderdetails ( Id int identity (1, 1 ), Ordercode varchar (50), -- Order Number Procode varchar (50), -- product no. Proname varchar (50), -- product name Promodel varchar (50), -- Product Model Pronum int -- order quantity ) -- Test Data Insert into fcworder (ordercode, ordername, opername, comname, createtime) values ('order001', 'order 1', 'zhang suni', 'customer 1 ', '2017-07-01 ') Insert into fcworder (ordercode, ordername, opername, comname, createtime) values ('order002', 'order 2', 'zhang san2', 'customer 2 ', '2017-07-02 ') Insert into fcworder (ordercode, ordername, opername, comname, createtime) values ('order003 ', 'order 3', 'zhang 33', 'customer 3 ', '2017-07-03 ')
Insert into fcworderdetails (ordercode, procode, proname, promodel, pronum) values ('order001', 'pro0011', 'product one by one ', 'length 1 wide 1', 11) Insert into fcworderdetails (ordercode, procode, proname, promodel, pronum) values ('order001', 'pro0012', 'product 12', 'length 1-width 2 ', 12) Insert into fcworderdetails (ordercode, procode, proname, promodel, pronum) values ('order002', 'pro0021', 'product two uni', 'length 2 wide 1', 21) Insert into fcworderdetails (ordercode, procode, proname, promodel, pronum) values ('order002', 'pro0022', 'product 2', 'length 2-width 2 ', 22) Insert into fcworderdetails (ordercode, procode, proname, promodel, pronum) values ('order003 ', 'pro0031', 'product suni', 'length 3-width 1', 31) Insert into fcworderdetails (ordercode, procode, proname, promodel, pronum) values ('order003 ', 'pro0032', 'product three two', 'length 3 width 2', 32) Insert into fcworderdetails (ordercode, procode, proname, promodel, pronum) values ('order003 ', 'pro0033', 'product 3rd', 'length 3-width 3 ', 33) -- Unified order details Select O. ID as orderid, O. ordercode, O. opername, O. ordername, O. comname, O. createtime, O. barcode, D. id as detailid, D. ordercode detailordercode, D. procode, D. proname, D. promodel, D. pronum Fcfrom worder o Fcjoin worderdetails D on D. ordercode = O. ordercode
Iii. coding implementation
Tip: This case belongs to the winform program. In principle, some background codes of rdlc can also be used in the webform Development Environment: Visual Studio 2012 and SQL Server 2012.
|
3. [configure dataset] drag the tableadapter in the toolbox to the Dataset Designer, configure the database connection, and load the following statements into the table: Select O. ID as orderid, O. ordercode, O. opername, O. ordername, O. comname, O. createtime, O. barcode, D. id as detailid, D. ordercode detailordercode, D. procode, D. proname, D. promodel, D. pronum Fcfrom worder o Fcjoin worderdetails D on D. ordercode = O. ordercode Right-click the generated tableadapter, select properties, and change the name to order
|
7 [winform Code]. winform is dragged to ListBox, button, reportviewer, and other steps. Set selectmode of ListBox to multisimple, Set the rdlc file for reportview Important code: Private void form1_load (Object sender, eventargs E) { // Bind list_order Datatable dtorder = sqlhelper. getdatatable (@ "select O. ID as orderid, O. ordercode, O. opername, O. ordername, O. comname, O. createtime, O. barcode from fcworder o "); List_order.datasource = dtorder; List_order.displaymember = "ordercode "; List_order.valuemember = "ordername "; } Private void button#click (Object sender, eventargs E) { Stringbuilder sb = new stringbuilder (); // Construct the multiple-choice order list Foreach (Object OBJ in list_order.selecteditems) { Datarowview DRV = (datarowview) OBJ; If (DRV! = NULL) { SB. append ("'" + DRV. Row ["ordercode"]. tostring () + "',"); } } // Bind the report data source If (sb. tostring (). length> 2) { String orderwhere = sb. tostring (). substring (0, SB. tostring (). Length-1 ); String strsql = @ "select O. ID as orderid, O. ordercode, O. opername, O. ordername, O. comname, O. createtime, O. barcode, D. id as detailid, D. ordercode detailordercode, D. procode, D. proname, D. promodel, D. pronum Fcfrom worder o Fcjoin worderdetails D on D. ordercode = O. ordercode where O. ordercode in ("+ orderwhere + ")"; Datatable dtorder2 = sqlhelper. getdatatable (strsql ); Reportviewer1.localreport. CES. Clear (); Reportviewer1.localreport. enableexternalimages = true; Reportviewer1.localreport. CES. Add (New reportdatasource ("order", dtorder2 )); Reportviewer1.localreport. setparameters (New reportparameter ("para_total", dtorder2.rows. Count. tostring ())); Reportviewer1.refreshreport (); } } |