1 / 29

.Net Crystal Reports Name: Justin John Date: 06-19-2007

.Net Crystal Reports Name: Justin John Date: 06-19-2007. Why Use a Reporting Tool?.

abigail
Download Presentation

.Net Crystal Reports Name: Justin John Date: 06-19-2007

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. .Net Crystal ReportsName: Justin JohnDate: 06-19-2007

  2. Why Use a Reporting Tool? • It isn't difficult to retrieve data. You could write code to loop through record sets and print them in your Windows or Web application. In the .NET Framework, you could go further and bind that data to a control, such as a Repeater, Data List or Data Grid. • But to present this data in a formal report format is far more complex. Writing code for searching , navigating between pages of the report, zooming the report extent , multiple level totals, charting, conditional formatting, and page-based output are difficult and time-consuming to program. • Crystal Reports makes it easy to create and distribute complex reports.

  3. What is Crystal Reports? • Crystal reports is the reporting tool of visual studio, an OEM (Original Equipment Manufacturer) of business objects. • Crystal Reports has been part of Visual Studio since 1993, and is now the standard for reporting in Visual Studio 2005. It ships with every copy of Visual Studio 2005 and is integrated directly into the development environment. • Ability to create interactive, presentation-quality content to the windows environment. • Create complex and professional reports in a GUI-based program. • You can connect your report to almost any database source, as well as to proxy data, such as a result set (for example, an ADO.NET DataSet). With the wizards included in the GUI designer, you can easily set formatting, grouping, charting, and other criteria. • You can host your report in either a Web or Windows application

  4. Your reports can be related to your Visual Studio 2005 project in many ways: Embed your reports directly into the project. Access them externally, from a file directory. Access them as a Report Web Service from a remote server.

  5. features • An embedded Crystal Reports designer, assisted by wizards and experts, builds complex report files easily.. • Data and .NET Dataset connections use the Database Expert to easily interact with a wide variety of database protocols, as well as proxy data in the form of ADO.NET Datasets.. • A Crystal Reports SDK interacts with and modifies reports programmatically. Use one of four different object models, each with increasing levels of complexity and power • An exporting feature exports data from the Crystal Report Viewer control to Word, Excel, PDF, and HTML, and Crystal Reports formats. • The ability to print from the Crystal Report Viewer control enables page-based report printing from any Web or Windows application. • Multilingual client support allows you to configure the CrystalReportViewer control so that other languages can be displayed in the Tool Tips, determined by the client browser, the ASPX page, or the environment settings for the machine. • Report Web Services, from an ASP.NET Web Service project, allow you to create a project, add a Crystal Report, and publish it as a Web service. • Seamless migration is possible from previous versions

  6. Database Connections • Crystal Reports for Visual Studio 2005 can connect reports to a wide variety of data sources. The Crystal Reports Designer uses the Database Expert to connect a report to a particular data source. Data connectivity is available through data connections (to databases using database drivers) and proxy data (to an ADO.NET DataSet).

  7. Crystal Reports for Visual Studio 2005 can access and report off the following data sources: • Any database with an ODBC driver • Any database with an OLEDB Provider • Microsoft Access databases • Microsoft Excel workbooks • ADO.NET datasets • ADO.NET datatables • ADO recordsets • CDO recordsets • IDataReader • Object Collections • DAO recordsets • RDO recordsets • XML Data in SQL Server 2005 • User Defined Types (UDT) in SQL Server 2005

  8. Embedded Crystal Reports Designer  • Crystal Reports for Visual Studio 2005 comes with an embedded version of the Crystal Reports Designer application that you can run from within Visual Studio 2005. The embedded Crystal Reports Designer is a GUI application. Using a collection of wizards and experts, complex report files can be built quickly and easily. • Traditionally, the Crystal Reports Designer is a stand-alone application that you launch from your Start menu under the name "Crystal Reports." But in Crystal Reports for Visual Studio 2005, the Crystal Reports Designer is embedded within the application. Report templates are viewed like an ASPX page or .NET class file, within the central window of Visual Studio 2005. • As a result, the embedded Crystal Reports Designer does not run independently. Instead, it is loaded within Visual Studio 2005 when a report file in Solution Explorer has been double-clicked. • The major difference between the stand-alone application and the embedded Crystal Reports is that the menus and toolbars of the embedded Crystal Reports Designer within Visual Studio 2005 are limited, compared to the menus and toolbars that are available in the stand-alone version.

  9. Exporting CrystalReportViewer control Export button formats • Adobe Acrobat (.pdf) • Crystal Reports (.rpt) • Microsoft Excel (.xls) • Microsoft Rich Text (.rtf) • Microsoft Word (.doc)

  10. Exporting through the API The ReportDocument.Export() method and related exporting methods are provided by the API for programmatic exporting of your report. You can write code to export to any of the export formats listed in the ExportFormatType enum. API export formats • Adobe Acrobat (.pdf) • Crystal Reports (.rpt) • HTML 3.2 and 4.0 (.html) • Microsoft Excel (.xls) • Microsoft Rich Text (.rtf) • Microsoft Word (.doc)

  11. Architecture  • Three features form the core of the architecture : • Embedded Crystal Reports Designer • Report Viewer Controls • Object Models

  12. Embedded Crystal Reports Designer  • The embedded Crystal Reports Designer creates or modifies reports. It consists of a graphical user interface for WYSIWYG report design, and a series of experts to simplify data connectivity, sorting, grouping, and other complex report design issues. Crystal Reports Developer includes an enhanced version of the embedded designer that allows you to build powerful reports and reporting applications.

  13. Report Viewer Controls  There are two provided controls: • The CrystalReportViewer control. • This control displays the report in a page-based layout, with the ability to move between pages. • The CrystalReportPartsViewer control. • The control displays report summary information in a small, portal-like window, with the ability to drill down deeper into the report through a series of linked parts.

  14. Object Models  • CrystalReportViewer, the simplest object model. • ReportDocument, the more extensive object model. • Object models available through upgrade: • ReportClientDocument, the most extensive object model. • InfoObject, a powerful object model for scheduling and configuring reports within the Crystal Reports Server or BusinessObjects Enterprise framework.

  15. CrystalReportViewer • The classes of this object model are contained within the CrystalDecisions.Web namespace for the Web Form version of this control or the CrystalDecisions.Windows.Forms namespace for the Windows Form version of this control

  16. Report Document • The classes of this object model are contained within the CrystalDecisions.CrystalReports.Engine namespace. • This is an extensive set of classes that provide more powerful customization and interaction capability with the report.

  17. ReportClientDocument • The classes of this object model are contained within the CrystalDecisions.ReportAppServer group of namespaces

  18. Info Object • The classes of this object model are contained within the CrystalDecisions.Enterprise group of namespaces.

  19. Displaying a report using the CrystalReportViewer control • The CrystalReportViewer control displays only one report at a time. Which report is displayed by the control is determined by which report you bind to your code. To tell the control which report to display, you bind the ReportSource property of the control to a particular report. At runtime, the control loads the report that is bound to the ReportSource property and displays it. • crystalReportViewer1.ReportSource = C:\\WorldSalesReport.rpt"; • Demonstrate

  20. The ReportDocument Object Model • ReportDocument is a more powerful and more extensive object model than CrystalReportViewer. It ships as part of the Crystal Reports for Visual Studio 2005 SDK and provides extensive ability to manipulate reports in the code.

  21. To bind to an embedded report class that is upcast to ReportDocument • Add two additional sample reports to the project: • Chart.rpt • World Sales Report.rpt • Add an "using" [C#] statement to the top of the class for the using CrystalDecisions.CrystalReports.Engine namespace. • Using CrystalDecisions.CrystalReports.Engine

  22. Create a private helper method for report selection, as shown below • private ReportDocument ChooseReport(int i) { switch(i) { case 1: Chart chartReport = new Chart(); return (ReportDocument) chartReport; case 2: Hierarchical Grouping hierarchicalGroupingReport = new Hierarchical Grouping(); return (ReportDocument) hierarchicalGroupingReport; default: World_Sales_Report worldSalesReport = new World_Sales_Report (); return (ReportDocument) worldSalesReport; }; }

  23. Declare an instance of ReportDocument and populate it by calling the ChooseReport() method, passing in the integer 1 to select the first report, Chart.rpt. ReportDocument reportDocument = ChooseReport(1); • This line of code demonstrates how to upcast to the common base class, CrystalReportViewer control. crystalReportViewer.ReportSource = reportDocument;

  24. Bind to a non-embedded report class using the ReportDocument object model • using CrystalDecisions.CrystalReports.Engine; • Locate the World Sales Report.rpt file • string reportPath = "C:\\Program Files\\Microsoft Visual Studio 8\\" + "Crystal Reports\\Samples\\En\\Reports\\General Business\\" + "World Sales Report.rpt"; • declare an instance of ReportDocument. • ReportDocument reportDocument = new ReportDocument(); • Load the non-embedded report class into ReportDocument. • reportDocument.Load(reportPath); • Assign the ReportDocument instance (which now contains the loaded non-embedded report class) to the ReportSource property of the CrystalReportViewer control. crystalReportViewer.ReportSource = reportDocument;

  25. Manipulating the report using ReportDocument object model Programming the Button Events with Sort Orders  Within the event method, retrieve the SortFields property from the DataDefinition property of the report instance and assign it to an instance of the SortFields indexed class SortFields sortFields = hierarchicalGroupingReport.DataDefinition.SortFields; • Retrieve the first SortField instance from the SortFields indexed class and assign it to a variable named firstSortField. SortField firstSortField = sortFields[0]; Set the SortDirection property of firstSortField to descending order, by use of the Descending Order selection of the SortDirection enum firstSortField.SortDirection = SortDirection.DescendingOrder; Now re-assign this report (with its sort that has been modified in the ReportDocument object model) to the ReportSource property of the CrystalReportViewer control crystalReportViewer.ReportSource = hierarchicalGroupingReport;

  26. Real-Time scenario : Connecting to ADO.NET DataSets: • An ADO.NET Dataset schema provides a template of the data structure in XML. However, a report cannot retrieve data from the Dataset schema alone • The Dataset instance must be filled with data, through use of the Data Adapter classes. • To begin, you create a data connection and build a Dataset schema that is based on that connection. • You then create a helper class with a property that returns a populated instance of the Dataset. • Finally, you write code that binds your Crystal report to the Dataset • For the Crystal report binding code, you write code to do the following: • Instantiate the report. • Set its SetDataSource property to the populated Dataset property from the helper class. • Bind the populated Crystal report to the CrystalReportViewer control.

  27. Writing a Helper Class to Populate the DataSet  • The DataSet schema that you have just created for the Customer table is a data structure. At runtime, code is required to populate the DataSet structure with data from the database. In this section, you create a helper class that populates the DataSet with data. using System.Data; using System.Data.OleDb; private const string CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\Microsoft Visual Studio 8\\Crystal Reports\\Samples\\Database\\xtreme.mdb"; private const string QUERY_STRING = "SELECT * FROM CUSTOMER"; private const string DATATABLE_NAME = "Customer"; private const string DIRECTORY_FILE_PATH = @"C:\WebSites\CS_Web_Data_DataSets\"; Public static DataSet CustomerDataSet { get { CustomerDataSetSchema dataSet = new CustomerDataSetSchema(); DataSet dataSet = new DataSet(); dataSet.ReadXmlSchema(DIRECTORY_FILE_PATH + "XMLSchema.xsd"); OleDbConnection oleDbConnection = new OleDbConnection(CONNECTION_STRING); OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(QUERY_STRING, oleDbConnection); oleDbDataAdapter.Fill(dataSet, DATATABLE_NAME); return dataSet; } }

  28. Creating a Report that Connects to the DataSet Schema  • In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard. • The Customer report is created, with data connectivity to the CustomerDataSetSchema • Binding the Report and Setting the DataSource to the Populated DataSet • In this section, you learn how to instantiate the report that you have created, populate the report's DataSet, and display the report in the CrystalReportViewer control. • You populate the report through the assignment of its SetDataSource property to the populated DataSet, which is returned from the CustomerDataSet property of the DataSetConfiguration class. • Finally, you bind the populated report to the CrystalReportViewer control.

  29. To instantiate and bind an embedded report to the CrystalReportViewer control • using System.Data; private Customer customerReport; • Within the ConfigureCrystalReports() method, instantiate the report wrapper class. • customerReport = new Customer(); • On the next line beneath the report instantiation, declare a DataSet. • DataSet dataSet; • Assign the DataSet instance to the DataSetConfiguration.CustomerDataSet property. • dataSet = DataSetConfiguration.CustomerDataSet; • Call the SetDataSource() method of the CustomerReport instance and pass into it the customerReport.SetDataSource(dataSet); • Bind the ReportSource property of the CrystalReportViewer control to the CustomerReport instance. • crystalReportViewer.ReportSource = customerReport;

More Related