Document batch printing for vs2012 reports (rdlc) series applications

Source: Internet
Author: User

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.

1. [Create a project] Open vs2012 and create a new project FCW. rdlc.


2. [Create a dataset] Right-click the project "FCW. rdlc", add a new item, select a dataset, and create the dataset order. XSD.



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





4. Click New Report, right-click FCW. rdlc, select Add new item, and select report. Create order. rdlc

5. Double-click "Configure report data source" to open the order. rdlc designer. On the report data source page, click "new"> "dataset", select an existing data source or a new data source, and change the name to "order ".
6. Design Report: drag the list in the toolbox to the rdlc interface designer and specify the data name order of the list.



6.1 select the list and right-click details in the row Group to add the Group and its parent group. The group is based on ordercode (Order Number), right-click the ordercode group, and select the instances in the group to be displayed on each order page.




6.2 delete the automatically added column ordercode and detailed information group



6.3. Drag tables, text boxes, and images to the report data source to create parameters. Complete the design based on the requirement interface.
Note: The list contains a rectangle by default. You can also manually add a rectangle as needed. A rectangle can be used to typeset the data in a loop. Meet Personalized Requirements.


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 ();


}
}

8. [Final Results]

 
 

 

Iv. Summary

This article starts from the basics to build a basic document batch printing application, involving the use of datasets, the use of list, table, text box, rectangle, parameters, group paging in rldc.

Rdlc tables are used to meet requirements similar to table data, including grouping statistics summary and paging.

The text box is used to display a single field or to process some lines.

Parameters are used to receive fixed values.

Rectangles are used to facilitate layout. When layout is different in other design and final presentation modes, rectangles can be used to enclose the layout disorder.

List, which can be used to process various style la s under a single piece of data in a loop. Implement custom requirements.

Portal: print documents in batches

 

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.