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 )
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 .
Then you will get the Format Editor . Select Sub report tab from Format
Editor , you can find there a check box - On-demand Subreport . You have to
select that check box , then the sub report become as a link in your main
Crystal Reports. If you want to change the title , you can change it in subreport
name textbox. Finally click OK button.
Now the designing part is over and the next step is to call the Crystal Reports in
CSharp and view it in Crystal Reports Viewer control .
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 .
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();
}
}
}
18. C# Crystal Reports - Date to Date
The following program describes how to generate a Date to Date report from
Crystal Reports 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 sections explains How to pass C# Crystal Reports Date
Paramater and also explain C# Dynamic logon parameters in Crystal Reports.
So before we start this section take a look at the previous sections because we
are here using sections from these tutorial.
Hope you understand the previous two sections well (1 - C# Crystal Reports
Date Paramater, 2 - C# Dynamic logon parameters in Crystal Reports). Here we
are creating two date parameter and pass it to Crystal Report at run time also
the Crystal Report using dynamic logon parameter to access database.
Createting two date parameters (dateFrom and dateTo).
Date From parameter.
Date To Parameter
Here we have three tables selected for report (ordermaster , orderdetails and
product ) and we are making the formula like , select all records from the tables
whose order date is between fromDate parameter and toDate paramater . For
doing this you have to select from date as Ordermaster.orderdate, to date as
Ordermaster.orderdate , comparison operators , boolean operator (AND) and
date parameters fromdate and todate fields from selection list of Formula Editor
and make the formula.
The following picture shows how to select the fields from formula editor and
make the formula. Double click each field then it will automatically selected .