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

 
Facebook mở rộng trung tâm dữ liệu ở Oregon

Facebook mở rộng trung tâm dữ liệu ở Oregon

Facebook đang tiếp tục mở rộng trung tâm dữ liệu của mình tại Prineville, tiểu bang Oregon sớm hơn dự kiến nhờ một sự giúp đỏ nho nhỏ từ các nhà lập pháp và sự nâng cấp năng lượng cần thiết.

Blocking Spam Comments and Users on Your Drupal Site

Hướng dẫn cấu cài đặt Mollom chống spam ở Drupal site

If you site is new, this might not be too much of a problem. However, as your site grows, it will increasingly be seen as a valuable target for spammers. If they succeed in placing links on your site, they may get a couple of benefits:

Giải pháp performance cho việc update lượt xem hiệu quả

Đối với một website có nhiều lượt truy cập hằng ngày, giải pháp nào để việc update lượt xem cho từng bài viết cụ thể để không gây ảnh hưởng đến performance của cả hệ thống.

 

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

 

Diet con trung