Đặc điểmỨng dụng độc lập Thiết kế báo biểu Kết xuất báo biểu thành các tập tin rpt Công cụ tạo báo biểu chuẩn cho Visual Studio .NET 812/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1... Nguồn dữ
Trang 1LẬP BÁO BIỂU
Ngô Chánh Đức
ĐHQG HCM – TRƯỜNG ĐH KHOA HỌC TỰ NHIÊN
KHOA CÔNG NGHỆ THÔNG TIN
2017 - 2018
Trang 2Nhu cầu thực hiện báo biểu
Trình bày lại dữ liệu để xuất bản – in ấn
12/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1 2
Trang 3Các công cụ hỗ trợ tạo báo biểu
Trang 4Cấu trúc của một báo biểu
Report nhiều trang
12/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1 4
Trang 5Ví dụ
Trang 6Crystal Report
12/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1 6
Trang 7Lược sử phát triển
Crystal Services
Inc
1991
Seagate Software - Crystal Decisions
Objects
12/2003 2011 SAP
Trang 8Đặc điểm
Ứng dụng độc lập
Thiết kế báo biểu
Kết xuất báo biểu thành các tập tin rpt
Công cụ tạo báo biểu chuẩn cho Visual Studio NET
812/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 9Cài đặt
VS 2010/2012/2013/2015/2017:
https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal +Reports%2C+Developer+for+Visual+Studio+Do wnloads
http://www.crystalreports.com/crystal-reports-visual-studio/
Tải bản Install Executable
Trang 10Nguồn dữ liệu cho báo biểu
Crytal Reports kết nối với nguồn dữ liệu thông
qua trình điều khiển riêng
Có 2 mô hình kết nối nguồn dữ liệu được hỗ trợ:
▪ Mô hình kéo (Pull)
▪ Mô hình đẩy (Push)
12/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1 10
Trang 11Nguồn dữ liệu cho báo biểu
Mô hình kéo (Pull model)
liệu yêu cầu
Trang 12Nguồn dữ liệu cho báo biểu
Mô hình đẩy (Push model)
RecordSet hoặc DataSet
12/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1 12
Trang 13Các bước tạo Report
Kết nối Crystal Report Viewer với Report
Document Form để hiển thị Crystal Report Viewer
Report Document
Trang 14Report Document
1412/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 15Report Document
Trang 16Report Document
1612/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 17Report Document
Trang 18Report Document
1812/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 19Report Document
KẾT THÚC PHẦN TẠO REPORT DOCUMENT
BẰNG WIZARD
Trang 20Report Document
Quay trở lại thanh Field Explorer
2012/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 21Report Document
Quay trở lại thanh Field Explorer
Trang 22Các bước tạo Report
Kết nối Crystal Report Viewer với Report
Document
Form để hiển thị Crystal Report Viewer
Report Document
2212/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 23Form để hiển thị Crystal Report Viewer
Quay trở lại Solution Explorer
Trang 24Form để hiển thị Crystal Report Viewer
Tạo mới 1 form - BaoCaoSachChoSep
2412/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 25Form để hiển thị Crystal Report Viewer
Vào toolbox, kéo thả CrystalReportViewer vào
form
Trang 26Form để hiển thị Crystal Report Viewer
Sau khi có Crystal Report Viewer
2612/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 27Các bước tạo Report
Kết nối Crystal Report Viewer với Report
Document Form để hiển thị Crystal Report Viewer
Report Document
Trang 282812/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 29Sử dụng theo cơ chế Pull
Cập nhật thông tin kết nối CSDL
CrytalDecisons.Shared.TableLogOnInfo
Thuộc tính:
Trang 30Thay đổi Cơ sở dữ liệu
CSDL thì chỉ cần xác định ConnectionInfo cho bảng đầu tiên
Password Mật khẩu nguồn truy cập
ServerName Tên server
UserID Tên người dùng để truy cập
12/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1 30
Trang 31Ví dụ
ReportDocument cryRpt = new ReportDocument ();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos ();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo ();
ConnectionInfo crConnectionInfo = new ConnectionInfo ();
Tables CrTables ;
cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");
crConnectionInfo.ServerName = "YOUR SERVER NAME";
crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";
crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
crConnectionInfo.Password = "YOUR DATABASE PASSWORD";
crystalReportViewer1.Refresh();
Trang 32Sử dụng theo cơ chế Push
Sử dụng phương thức SetDataSource () trong
của lớp ReportDocument
DataTable dt = new DataTable ();
//Kết nối CSDL và đổ dữ liệu vào dt
ReportLopHoc rpt = new ReportLopHoc ();
rpt.SetDataSource(dt)
12/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1 32
Trang 33Sử dụng theo cơ chế Push kết hợp
Entity Framework
Phương thức ReportDocument.SetDataSource
chỉ nhận DataSet không truyền trực tiếp kết
quả truy vấn bằng LINQ to Entities vào được.
Giải pháp 1:
http://www.codeproject.com/Articles/531776/Entity -Framework-and-Crystal-Reports-Entities-to-D
Giải pháp 2:
http://www.worldbestlearningcenter.com/index_file s/csharp-crystal-report-entity-framework.htm
Trang 34Một số tham số của Report Document
Các đối tượng thông dụng: Text Object, Line,
Picture, Chart, …
Special Fields: Print Date, Print Time, Record
Number, Page Number, …
Parameter Fields.
Formula Fields.
3412/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 35Các đối tượng thông dụng
Trang 36Special Fields
3612/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 37Parameter Fields
Trang 38Parameter Fields
3812/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 39Parameter Fields
Parameter Fields
parameters bằng hàm SetParameterValue.
NameOfParameter là tên của tham số, và Value là giá trị (kiểu phụ thuộc vào kiểu khi ta chọn).
report SetParameterValue (“NameOfParameter", Value);
Trang 40Fomular Fields
4012/12/2017 LẬP TRÌNH ỨNG DỤNG QUẢN LÝ 1
Trang 41Fomular Fields
Trang 43HỎI ĐÁP