Bài 2: Sử dụng parameter trong crytal report

Bài 2: Sử dụng parameter trong crytal report

Bài trên ta đã tạo report chỉ với 1 bảng là Product, bây giờ sẽ tạo report với nhiều bảng xem sao nhé. Mọi việc cũng giống như trên, đến bước chọn các table thì ta chọn cả 3 table cho nó máu, sau đấy là chọn các fields muốn report :

Bài 2: Sử dụng parameter trong crytal report

Mọi chuyện lại tiếp tục như thế

Sử dụng parameter trong crytal report

Ở bài này tôi sẽ hướng dẫn cách sử dụng String parameter.
Ví dụ,bạn muốn đưa vào 1 tham số là customername,và sẽ hiện ra các đơn đặt hàng của khách hàng đó ở report.
Ở đây, tui sẽ sử dụng tiếp cái report đã tạo ở bài trên.
Chọn Fields Explorer (menu Crytal Reports ->Fields Explorer),chuột phải vào Parameter Fields,rồi new,điền các tham số vào :

Tôi chọn kiểu là string, các kiểu khác làm cũng tương tự
Sau khi tạo xong parameter, ta sẽ tạo biểu thức cho các fields,vào cửa sổ design của crytal reports rồi làm như hình :

Hiện ra 1 editor để bạn thiết kế fomular, muốn sử dụng field nào thì chọn field đó,các bạn cứ làm theo thứ tự tớ oánh số trong hình nhá

Thiết kế form như trong hình :

Bi giờ ta viết code cho sự kiện của nút show

private void button1_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load(@"C:\Documents and Settings\Qu@n Bom\My Documents\Visual Studio 2008\Projects\Example\Example\CrystalReport1.rpt");

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = textBox1.Text;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["Customername"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();

        }
Bạn thấy bài viết này như thế nào?: 
Average: 9.3 (4 votes)
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Hacker Jeremy Hammond - Anonymous từng bị FBI truy bắt

Hacker Jeremy Hammond - Anonymous từng bị FBI truy bắt

Tạp chí Rolling Stone kể về hành trình bắt giữ hacker Jeremy Hammond cuối năm 2012 cũng như mô tả sự hỗn độn của thế giới tin tặc với những con người tài năng, lập dị.

[KDS] Keeping Drupal Simple và Static Prototyping

[KDS] Keeping Drupal Simple và Static Prototyping

The technical debt involved with preprocessing views templates or creating custom panel layouts is hard to justify for projects that have small budgets, tight timelines, or hyper-specific design requirements.

Cài đặt Docker development environment với Vagrant - Phần 3

Cài đặt Docker development environment với Vagrant - Phần 3

Now that I’ve laid the ground work for the approach that I want to take with local environment development with 

Công ty diệt chuột T&C

 

Diet con trung