Writing Database Reports using Crystal Reports

10 249 0
Writing Database Reports using Crystal Reports

Đang tải... (xem toàn văn)

Thông tin tài liệu

1 Writing Database Reports using Crystal Reports D.McAmis - Professional Crystal Reports for Visual Studio .N 1 Contents 1. Crystal Report overview 2. Steps to create and display a simple report 3. Customizing the appearance and behavior of the report 4. Customizing the appearance and behavior of the CrystalReportViewer 5. Reports with group 6. Reports with parameter Slide 2 Crystal Report overview ► Crystal Reports is a report design tool that allows you to create reports : retrieving data from a database or other data source. ► Crystal Reports has its own formula language for: ►creating calculations ►creating presentation-quality reports, with graphs, charts, … Slide 3 Contents 1. Crystal Report overview 2. Steps to create and display a simple report 3. Customizing the appearance and behavior of the report 4. Customizing the appearance and behavior of the CrystalReportViewer 5. Reports with group 6. Reports with parameter Slide 4 Steps to create and display a simple report 1. Add a Report Designer and design the report template. 2. Add a CrystalReportViewer control to a form and connect it to the report template. YOU ARE HERE Slide 5 Adding a Report Designer ► Select Add New Item from the Project menu ► Choose the Crystal Report icon ► The .rpt extension is added by default Slide 6 2 Adding a Report Designer ► Using the Report Expert  Creating a report through step-by-step (p.31) ► As a Blank Report ► From an Existing Report  Import your existing report Slide 7 The Report Designer The Report Header appears once at the beginning of the report. The Page Header appears at the top of each page. The Details section holds data for the report body. The Page Footer displays page numbers at the bottom of each page. The Report Footer shows report totals (if existing). Slide 8 The Report Designer (cont.) Use the Field Explorer window to add new fields to your report. Use items in the toolbox to add elements such as lines, boxes, unbound text to the report. Select View/Other Windows/ Document Outline to view the Field Explorer (Ctrl-Alt-T) Slide 9 Add data source ► Select data source (2 ways):  right-click your report and select DatabaseDatabase Expert…  right-click on Database Field node in FieldExplorer, select Database Expert Slide 10 Add data source (cont.) Slide 11 Design report Slide 12 3 Design report Slide 13 Preview report Slide 14 Steps to create and display a simple report 1. Add a Report Designer and design the report template. 2. Add a CrystalReportViewer control to a form and connect it to the report template. YOU ARE HERE Slide 15 Display Crystal report in C#  Using the CrystalReportViewer component in Toolbox  To bind a report to the CrystalReportViewer control, using ReportSource property of CrystalReportViewer  Four ways to use ReportSource property  Binding by Report Name  Binding by Report Object  By binding to an untyped report  By binding to strongly typed report Slide 16 1. Binding by Report Name ► Setting the ReportSource property to specify the report file name and path, as shown here: CrystalReportViewer1.ReportSource = “D:\\Demo\\myReport.rpt”; or: CrystalReportViewer1.ReportSource = Application.StartupPath + "\\myReport.rpt"; Slide 17 2. Binding by Report Object ► If the report you are using has actually been added to your project, we could use the report file as a class ► Example: myReport report = new myReport(); CrystalReportViewer1.ReportSource = report; Using this way Slide 18 4 3. Binding to an Untyped Report ► Use reports as components  add a report component to the form: ReportDocument  choose Untyped ReportDocument (named ReportDocument1)  load a report into this component ► Example: ReportDocument ReportDocument1 = new ReportDocument(); ReportDocument1.Load (“D:\\Demo\\myReport.rpt”); CrystalReportViewer1.ReportSource = ReportDocument1; Slide 19 4. Binding to a Strongly Typed Report ► Use reports as components ► A strongly typed report can be any report that has been added to your project. ► Example: CrystalReportViewer1.ReportSource = reportSV1; Slide 20 Problem: Moving a Crystal Reports project 1. Change the ReportSource property of the CrystalReportViewer control on the form • Add report to project and using relative path 2. Change the data source for the report template • Verify database • Passing Database Logon Info Slide 21 Passing Database Logon Info  Most data sources that Crystal Reports can use are secure, requiring a username, password, and other credentials.  When working with the Crystal Report Viewer, we can pass this information through the use of the TableLogonInfo collection (CrystalDecisions.Shared namespace)  In order to set the database credentials for your report, you will need to loop through all of the tables and set the ConnectionInfo properties within TableLogonInfo for each. The properties in the ConnectionInfo class (CrystalDecisions.Shared namespace) are: Slide 22 Passing Database Logon Info Slide 23 Passing Database Logon Info  Example: using CrystalDecisions.Shared; using CrystalDecisions.CrystalReports.Engine; reportSV rpt = new reportSV(); ConnectionInfo conInfo = new ConnectionInfo(); conInfo.ServerName = Application.StartupPath + "\\QLSV.accdb"; // conInfo.UserID = "MyUser"; // conInfo.Password = "Password"; foreach (Table tbCurrent in rpt.Database.Tables) { TableLogOnInfo crTableLogOnInfo = tbCurrent.LogOnInfo; crTableLogOnInfo.ConnectionInfo = conInfo; tbCurrent.ApplyLogOnInfo (crTableLogOnInfo); } crvSV.ReportSource = rpt; Slide 24 5 Contents 1. Crystal Report overview 2. Steps to create and display a simple report 3. Customizing the appearance and behavior of the report 4. Customizing the appearance and behavior of the CrystalReportViewer 5. Reports with group 6. Reports with parameter Slide 25 Verify Database ► As database structures change, such as field names, types, … reports you have created may no longer work, you can use this function to update those changes Slide 26 Format Object Slide 27 Adding custom text to report ► Used in a report for typing text that will appear in that report, such as the column headings and comments. Slide 28 Adding special text to report: Special Fields ► Special Fields is predefined fields that serve a specific function within your Report Designer, such as page numbers, print dates, data dates,… Slide 29 Using Formula Fields ► To add complex calculations to reports ► Appear in curly braces and are prefixed by the @ symbol ► Created by using the integrated Formula Editor ► Right-click Formula Fields in the Field Explorer, select New, enter a name, and then click OK Slide 30 6 Using Formula Fields Slide 31 Using Formula Fields Slide 32 Add data source from multi-tables ► Single table ► Multiple table  a new tab will appear for joined together ► Command  Using Add Command (right click and choose Add Command to Report) ► Views Slide 33 Contents 1. Crystal Report overview 2. Steps to create and display a simple report 3. Customizing the appearance and behavior of the report 4. Customizing the appearance and behavior of the CrystalReportViewer 5. Reports with group 6. Reports with parameter Slide 34 Customizing the appearance and behavior of the CrystalReportViewer Toolbar Group Tree Slide 35 The Toolbar and the GroupTree Slide 36 7 The Toolbar and the GroupTree (cont.)  For the icons within the toolbar, you can also set some properties to True/False to show or hide a particular icon, as shown here:  ShowCloseButton  ShowExportButton  ShowGotoPageButton  ShowGroupTreeButton  ShowPageNavigateButtons  ShowRefreshButton  ShowTextSearchButton  ShowZoomButton  ShowPrintButton Slide 37 Customizing the CrystalReportViewer Slide 38 Methods of CrystalReportViewer  Printing a Report: CrystalReportViewer1.PrintReport()  Refreshing the Data in a Report: CrystalReportViewer1RefreshReport  Exporting a Report to .pdf, xls, doc, rtf: CrystalReportViewer1.ExportReport() ► Page Navigation and Zoom: ShowFirstPage, ShowLastPage, ShowNextPage, ShowPreviousPage, CrystalReportViewer1.Zoom (int per)  Searching Within a Report: CrystalReportViewer1.SearchForText (string ser) Slide 39 Events of CrystalReportViewer ► Navigate Events ► ReportRefresh Events ► Search Events ► ViewZoom events Slide 40 Contents 1. Crystal Report overview 2. Steps to create and display a simple report 3. Customizing the appearance and behavior of the report 4. Customizing the appearance and behavior of the CrystalReportViewer 5. Reports with group 6. Reports with parameter Slide 41 Reports with group ► Make the report more readable ► Make the report easier to find information quickly ► Create summaries such as the sum, average, maximum, and minimum Slide 42 8 Group Name Fields ► is used to display the name of each group ► right-click on report and select Insert → Group or ► right-click Group Name Fields in the Field Explorer, select Insert Group ► to delete a group from your report, right- click Group Name Fields in the Field Explorer, select Group Expert Slide 43 Reports with group: How to create? ► Select database Slide 44 Reports with group: How to create? ► Inserting a New Group: using Field Explorer ► Choose field to group Slide 45 Reports with group: How to create? Slide 46 Reports with group: How to modify group? Slide 47 Reports with group: How to modify group? Slide 48 9 Reports with group: How to inserting a Summary Field? ► right-click your report and select Insert → Summary… Slide 49 Reports with group Slide 50 Reports with group Slide 51 Contents 1. Crystal Report overview 2. Steps to create and display a simple report 3. Customizing the appearance and behavior of the report 4. Customizing the appearance and behavior of the CrystalReportViewer 5. Reports with group 6. Reports with parameter Slide 52 Parameter Fields ► Using Parameter Fields for:  Display dynamic text (such as reporter)  Filtering the content of a report ► Appear in curly braces and are prefixed by the ? symbol ► Right-click the Parameter Fields section of the Field Explorer and select New,… Slide 53 Parameter Fields (cont.) ► To display dynamic text:  First, create a parameter field  Later, send parameter values to report (in C#) ► To filter the content of a report:  First, create a parameter field  Then, set the record selection to be equal to this parameter field  Last, send parameter values to report (in C#) Slide 54 10 Reports with parameters: How to create? ► Create a parameter field Tên tham số Kiểu tham số Giá trị rời rạc Khoảng giá trị Đặt giá trị mặc định cho tham số Tham số có nhiều giá trị Slide 55 Reports with parameters: How to create? Slide 56 Reports with parameters: How to create? ► Set the record selection to be equal to this parameter field Slide 57 Reports with parameters: How to create? ► Send parameter values to report reportSV_Para rpt = new reportSV_Para(); … rpt.SetParameterValue("MaLop", cboLop.SelectedValue.ToString()); crvSV.ReportSource = rpt; Tên tham số trong report Giá trị truyền cho tham số Slide 58 . the CrystalReportViewer Slide 38 Methods of CrystalReportViewer  Printing a Report: CrystalReportViewer1.PrintReport()  Refreshing the Data in a Report: CrystalReportViewer1RefreshReport. the report 4. Customizing the appearance and behavior of the CrystalReportViewer 5. Reports with group 6. Reports with parameter Slide 2 Crystal Report overview ► Crystal Reports is a report. the report you are using has actually been added to your project, we could use the report file as a class ► Example: myReport report = new myReport(); CrystalReportViewer1.ReportSource = report;

Ngày đăng: 13/05/2014, 12:19

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan