1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Kỹ thuật lập trình >

C# Crystal Reports - sub reports

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.18 MB, 71 trang )


In this section we are going to generate a sub-report under the main row details.

That is for each row there is a subreoprt for the details.



Here we are going create an order report based on three tables in the database

and show a subreoprt for each row field of Product Name. Here we are using

our earlier program C# Crystal Reports from multiple tables to show the main

Crystal Reports Data , so refer C# Crystal Reports from multiple tables , before

start this section .

Create a Crystal Reports using three tables and select customername , date ,

product and qty . It will explain in detail the previous section C# Crystal

Reports from multiple tables.

Next step is to create a sub report inside the main report. Here we are showing

the Product details in each row of the specified product in the main row.

After create the main report , right click on Crystal Reports designer window

and select Insert-Subreport.



Then you will get the subreport object , drag the object in the designer window

at the down part of the details tab , just below the fields in the details tab. When

you release the mouse you will get a dialogue box asking report name . Enter a

report name , and click the Report Wizard Button .

The wizard shows the table selection screen and select the table . Here in this

case we have to select the Product Table from the list and click next .

Next screen is showing the table , from there select the fields you want to show

the data and click finish. The you will get the sub report main screen again and

select Link tab .

The link tab is making relation with your main Report and subreport . Here we

are linking the productname from main report to the subreport. For that select

Product.Product_name from Available fields.



Accept the other settings as it is in the screen and click ok. Now you can see the

sub report object in the screen , if you want to re-arrange subreport design ,

double click on subreport object then you can design subreport.



Now the designing part is over and the next step is to call the Crystal Reports in

C# and view it in Crystal Reports Viewer control .

Select the default form (Form1.cs) you created in C# and drag a button and a

CrystalReportViewer control to your form .

You have to include CrystalDecisions.CrystalReports.Engine in your C#

Source Code.

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

Copy and paste the following source code and run your C# project

using

using

using

using



System;

System.Windows.Forms;

CrystalDecisions.CrystalReports.Engine;

CrystalDecisions.Shared;



namespace WindowsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

ReportDocument cryRpt = new ReportDocument();

cryRpt.Load(PUT CRYSTAL REPORT PATH

HERE\\CrystalReport1.rpt");

crystalReportViewer1.ReportSource = cryRpt;

crystalReportViewer1.Refresh();

}

}

}



17. C# Crystal Reports - on demand sub reports

The following program shows how to create a Crystal Report On Demand

Subreport in C#.



All C# Crystal Reports Tutorial in this website is based on the following

database - crystaldb. So before you begin this section , please take a look at the

database structure of crystaldb - Click Here C# crystaldb

If you are new to Crystal Reports and do not know how to create Crystal

Reports from C# , please take a look at the section step by step tutorial for

creating a Crystal Reports from C#.

In the previous section of C# Crystal Reports sub-reports is described how to

insert a subreport in Crystal Reports . In the previous section the sub report is

displayed directly under each row details of main report .

The following section explains how to display subreport when the user click in

a hyper link in the main Crystal Report . In this case the sub report has only a

link to the main Report . That is when the user click the link , then only the

subreport display , it is called On Demand Report .



This section is the continuation of the previous section C# Crystal Reports subreports. Here we are creating a Sub report in Crystal Report and make a link in

the main Crystal Reports for on-demand subreport.

Select the subreport object in the Crystal Reports and right click , then select

Format Object .



Xem Thêm
Tải bản đầy đủ (.pdf) (71 trang)

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×