Crystal Reports For Visual Studio 2005 phần 6 pptx

57 374 0
Crystal Reports For Visual Studio 2005 phần 6 pptx

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Walkthroughs Copyright © 2004 Business Objects Page 296 Reduced-Code Windows Project Setup with Crystal Reports Using Smart Tasks In this tutorial, you learn how to follow a reduced-code development model to set up a Windows project, using Smart Tasks. Introduction In this tutorial, you learn how to create a Windows project in Crystal Reports for Visual Studio 2005. You then add a CrystalReportViewer control to the Windows Form. From the Smart Task panel, you open the embedded Crystal Reports Designer and create a new report. The Smart Tasks feature generates code that binds the report to the CrystalReportViewer control. Throughout this tutorial, you can preview the report three ways: In the embedded Crystal Reports Designer, with the new Preview button in Crystal Reports for Visual Studio 2005. In the Windows Form, with dummy data. Note This preview of the Windows Form is a new feature called the Design Time Preview. For more information, see Appendix: Design Time Preview. At runtime, when you build and compile the application. At the end of this tutorial, you switch to code view, to see how the reduced-code development model functions in Crystal Reports for Visual Studio 2005. Creating a Windows Project with a CrystalReportViewer Control Before you create a Windows Project, verify that Crystal Reports for Visual Studio 2005 has been installed on your system. To set up a reduced-code Windows project in Crystal Reports for Visual Studio 2005 1. Launch Visual Studio 2005. 2. From the File menu, select New, and then click Project. 3. In the New Project dialog box, select a language folder for C# or Visual Basic from the Project Types list. 4. From the Templates list, click Windows Application. 5. In the Name field, replace the default project name with the name of your project. 6. Click OK. Your project opens in Solution Explorer and contains a Form1 class. 7. Open the Form1 class. 8. From the Toolbox, open the Crystal Reports node to locate the CrystalReportViewer control. 9. Drag the CrystalReportViewer control onto the Windows Form. 10. From the Properties window, set the Name property: For Visual Basic projects, set the value to "myCrystalReportViewer." Walkthroughs Copyright © 2004 Business Objects Page 297 For C# projects, set the value to "crystalReportViewer." 11. From the File menu, click Save All. Configuring the Report in Smart Tasks Visual Studio 2005 has a new GUI feature for .NET controls, called Smart Tasks. For the CrystalReportViewer control in Windows projects, the Smart Task panel is named "CrystalReportViewer Tasks." The "CrystalReportViewer Tasks" Smart Task panel enables you to configure several features of the CrystalReportViewer control, without having to write code. Any selections that you make in Smart Tasks are generated as code in a Form1 partial class. This hidden partial class is a new feature of Visual Studio 2005 that contains initialization and design code. In this section, you configure a new report with the CrystalReportViewer Tasks Smart Task panel and the embedded Crystal Reports Designer. Later in these reduced-code tutorials, you examine other features of Smart Tasks. Configuring the Report using Smart Tasks 1. On the upper-right corner of the CrystalReportViewer control, click on the small triangular button. The Smart Task panel named "CrystalReportViewer Tasks" opens. 2. Click the Create a New Report link. 3. In the Create a New Crystal Report dialog box, enter the name "XtremeCustomers.rpt," and then click OK. The Crystal Reports Gallery dialog box opens. 4. In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard. 5. In the Choose an Expert panel, select Standard, and then click OK. 6. In the Available Data Sources panel of the Standard Report Creation Wizard window, do the following: a) Expand the Create New Connection folder. b) Expand the ODBC (RDO) folder. 7. In the ODBC (RDO) window, select the correct ODBC DSN entry for your version of Crystal Reports, as explained in Appendix: ODBC DSN Entry for Xtreme Sample Database, and then click Finish. The ODBC (RDO) folder expands and shows the Xtreme Sample Database. 8. Expand the Tables node, and then select the Customer table. 9. Double-click the Customer table to move the table into the Selected Tables panel, and then click Next. 10. CTRL-click Customer Name, Contact Title, Address1, and City. 11. Click the > symbol to move these fields into the Fields to Display panel, and then click Next. 12. In the Available Fields panel, under Report Fields, select Customer.City, click the > symbol to move the field into the Group By panel, and then click Finish. Walkthroughs Copyright © 2004 Business Objects Page 298 The XtremeCustomers report is created and loaded into the main window of Visual Studio. 13. At the bottom of the window, click Main Report Preview. The report is displayed in preview mode and shows data from the Xtreme database. Note The Preview button is a new feature of the embedded Crystal Reports Designer that ships with Crystal Reports for Visual Studio 2005. 14. At the bottom of the window, click Main Report to exit Preview mode. 15. Return to the Form1 class. The report is displayed in Design Time Preview mode, showing the report's graphic layout on the Web Form. Below Form1, the XtremeCustomers report is displayed in the component tray. 16. From the File menu, click Save All. Your report is created and becomes the designated report for the CrystalReportViewer control. At this point, you may want to rename your report variable. To rename the report variable 1. Click XtremeCustomers1 in the component tray to select it. 2. From the Properties window, set the Name field to "xtremeCustomersReport." You are now ready to build and run your project. To test the reduced-code Windows project 1. From the Build menu, select Build Solution. 2. If you have any build errors, go ahead and fix them now. 3. From the Debug menu, click Start. 4. The XtremeCustomers report is displayed in a new Windows application. 5. Return to Visual Studio and click Stop to exit from debug mode. Exploring the Code Generated by Smart Tasks In this section, you explore the code that is generated by Smart Tasks, which enabled you to set up a Windows Project with Crystal Reports without having to write code. To explore the code generated by Smart Tasks 1. Open the Form1 class. 2. From the View menu, click Code. The Form1 class opens in code view and displays an empty class. Note In C#, the empty class displays the class constructor. public Form1() { InitializeComponent(); } Notice that the following code is missing: The declaration of the CrystalReportViewer control instance The instance of the XtremeCustomers report. Walkthroughs Copyright © 2004 Business Objects Page 299 The code that binds the report to the CrystalReportViewer control. The absent code has been hidden in a partial class. Partial classes are a new feature in the .NET Framework 2.0 and Visual Studio 2005. Partial classes allow one class to accept an addendum from another class file, by giving the other class file the same class name and prefixed with the word "partial." The partial class usually contains auto-generated designer code. To view the auto-generated code that does not appear in the Form1 class, you will explore the CrystalReportViewer and report instances in the hidden Form1 partial class. To view the hidden Form1 partial class 1. From Solution Explorer, click the toolbar icon Show All Files. 2. Expand Form1.cs or Form1.vb. The Form1.Designer.cs or .vb is displayed. 3. Right-click Form1.Designer.cs or .vb and select View Code. The Form1 partial class opens and displays the auto-generated code for this class. This includes the declaration of the CrystalReportViewer control instance, the XtremeCustomers report instance, and the code that binds the report to the CrystalReportViewer control instance. Note If you prefer to write the code and place it into the code-behind class, see Appendix: Project Setup. Conclusion In this tutorial, you followed a reduced-code development model to create a Crystal Reports Windows Project. You added a CrystalReportViewer control, and then used Smart Tasks to create a new report and bind it to the CrystalReportViewer control, without having to write code. You then explored the code that was auto-generated in the hidden partial class, based on your selections in Smart Tasks. Sample Code Information Each tutorial comes with Visual Basic and C# sample code that show the completed version of the project. Follow the instructions in this tutorial to create a new project or open the sample code project to work from a completed version. The sample code is stored in folders that are categorized by language and project type. The folder names for each sample code version are as follows: C# Windows project: CS_Win_ReducedCode_ProjectSetup Visual Basic Windows project: VB_Win_ReducedCode_ProjectSetup To locate the folders that contain these samples, see Appendix: Tutorials' Sample Code Directory. Walkthroughs Copyright © 2004 Business Objects Page 300 Crystal Reports For Visual Studio 2005 Reduced-Code Tutorial: Secure Database Logon in a Web Site Walkthroughs Copyright © 2004 Business Objects Page 301 Reduced-Code Secure Database Logon in a Web Site Introduction In this reduced-code Web Site tutorial, you learn how to display a report that contains information from a secure SQL Server database. To provide a secure database logon, you assign the report's DataSources property to the SQLDataSource control, which is part of the new DataSource control framework in Visual Studio 2005. Note A coding development model of this tutorial is also available. See Logging onto a Secure SQL Server Database Using SQL Authentication or Logging onto a Secure SQL Server Database Using Integrated Security. In this tutorial, to display a report that contains information from a secure SQL Server database, you use the new tag-based application development model to connect the key components: Connect a CrystalReportViewer control to a CrystalReportSource control. Connect the CrystalReportSource control to a report. Connect the report's DataSources property to an SqlDataSource control. Note DataSources is viewed as a report property in the Properties window, or as a tag in HTML view (Source view). All of this work is done without having to write code. To begin, you add a CrystalReportViewer control to the Web Form. From Smart Tasks, you create a CrystalReportSource control, and then build a Crystal report with the embedded Crystal Reports Designer. This report logs on to a secure SQL server database. The report is referenced within the CrystalReportSource control. Then you learn how to configure the logon to the secure SQL server database, to return the required tables that are used by the Crystal report. To start, you select the "Enable Database Logon prompt" option in Smart Tasks. When that option is selected, the exception that is thrown during a database logon failure is replaced with a prompt that requests the user to log on manually. To configure a consistent log on to the required database, you add a SqlDataSource control, and then configure it to address the secure SQL server database and return the required tables. Finally, you assign the DataSource property of the report to the SqlDataSource control that you have created. Creating a Web Site with a CrystalReportViewer Control Before you create a Web Site, verify that Crystal Reports for Visual Studio 2005 has been installed on your system. Some database setup is required as a prerequisite to this tutorial. Prerequisite Database Setup 1. SQL Server configuration: Walkthroughs Copyright © 2004 Business Objects Page 302 If you have SQL Server (or the OEM version, MSDE) installed, it must be configured to require SQL Server Authentication. If you do not have SQL Server (or the OEM version, MSDE) installed, you must install MSDE with SQL Server Authentication set to "True." 2. The Northwind database provided with SQL Server must be installed and verified that it requires SQL Server Authentication. 3. A limited access account must be created for use within the Web site. To install MSDE with SQL Server Authentication, or the Northwind database, go to the following sections from Appendix: System Setup in this documentation: Appendix: MSDE Installation with Windows or SQL Server Authentication Appendix: Northwind Database Installation Appendix: Security: Creating a Limited Access Database Account Once you have configured SQL Server and the Northwind database according to the sections above, you are ready to create a Web Site that displays a Crystal report drawing its information securely from a Northwind database. You begin by setting up a reduced-code Web Site. To set up a reduced-code Web Site in Crystal Reports for Visual Studio 2005 1. Launch Visual Studio 2005. 2. From the File menu, select New, and then click Web Site. 3. In the New Web Site dialog box, click ASP.NET Web Site. 4. In the Location dropdown, select File System. 5. In the Language dropdown, select the coding language that you wish to use. 6. In the Location text field enter the directory path "C:\WebSites\", followed by the name of your project. C:\WebSites\MyProjectName 7. Click OK. Your project opens in the Solution Explorer and contains a Default.aspx page. 8. Open the Default.aspx page (the Web Form). 9. From the View menu, click Designer. Note You can also switch to design view by clicking the Design button at the bottom of the form view. 10. From the Toolbox, open the Crystal Reports node to locate the CrystalReportViewer control. 11. Drag the CrystalReportViewer control onto the Web Form. The Smart Task panel named "CrystalReportViewer Tasks" opens. Configuring the CrystalReportSource in Smart Tasks Visual Studio 2005 has a new GUI feature for .NET controls, called Smart Tasks. For the CrystalReportViewer control in Web Sites, the Smart Task panel is named "CrystalReportViewer Tasks." Walkthroughs Copyright © 2004 Business Objects Page 303 The "CrystalReportViewer Tasks" Smart Task panel enables you to configure several features of the CrystalReportViewer control, without having to write code. Any selections that you make in Smart Tasks are generated as tag-based settings within the ASPX page. In this section, you configure the CrystalReportSource control that is available from the "CrystalReportViewer Tasks" Smart Task. Later in these reduced-code tutorials, you examine other features of Smart Tasks. To begin, you learn how to close and re-open Smart Tasks. Configuring the CrystalReportSource using Smart Tasks 1. If the Smart Task panel is currently open, click on the Web Form to close Smart Tasks. 2. On the upper-right corner of the CrystalReportViewer control, click on the small triangular button. The Smart Task panel named "CrystalReportViewer Tasks" re-opens. In the Choose Report Source list, <None> is displayed. 3. Click the Choose Report Source list and select <New report source…>. The Create ReportSource dialog box opens. 4. In the Specify a name for the control textbox, leave the default entry as CrystalReportSource1. 5. Click the Specify a report for the ReportSource control drop- down list and select <New Report>. Your alternative selection is <Browse…>. That option allows you to select an existing Crystal report from the file directory. However, later you will create a new report that is required for this tutorial. 6. In the Create a New Crystal Report dialog box, enter the name "NorthwindCustomers.rpt". 7. Click OK, and then click OK again to close the Create ReportSource dialog box. Creating and Connecting the Report to a Secure Database You now begin the process of creating and connecting the report. To create and connect the report to a secure database 1. If the Registration Wizard dialog box appears, you need to register your copy of Crystal Reports. You have two choices: Click Next to register now. Click Register Later to register later. After registering or choosing to register later, proceed to the next step. 2. In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard. 3. In the Choose an Expert panel, select Standard, and then click OK. 4. In the Available Data Sources panel, expand the Create New Connection folder. Walkthroughs Copyright © 2004 Business Objects Page 304 Note In Visual Studio .NET 2002 or 2003 where Crystal Reports has not been upgraded to Crystal Reports Developer, the Create New Connection folder does not exist; the contents are shown at the top level. 5. From the subfolder that opens, expand the OLE DB (ADO) folder. 6. In the OLE DB (ADO) dialog box, select Microsoft OLE DB Provider for SQL Server, and then click Next. 7. You can now use either SQL Authentication, or Windows Authentication with Integrated Security: If you are using SQL Authentication, enter the values for your database server, user id, and password into the Server, User ID, and Password fields and then from the Database list, select "Northwind." Note For security reasons, it is important that you use a database account with limited access permissions. For more information, see Appendix: Security: Creating a Limited Access Database Account. If you are using Windows Authentication with Integrated Security, enter the value for your database server and check the Integrated Security checkbox, and then from the Database list, select "Northwind." 8. Click Finish. The OLE DB folder expands to show your database server and, within it, the Northwind database. 9. Expand the nodes Northwind, dbo, and Tables, and then select the Customers table. 10. Click the > symbol to move the table into the Selected Tables panel, and then click Next. 11. Hold down CTRL and click CompanyName, ContactName and City. 12. Click the > symbol to move these fields into the Fields to Display panel, and then click Next. 13. In the Available Fields panel, under Report Fields, select Customer.City, click the > symbol to move the field into the Group By panel, and then click Finish. The NorthwindCustomers report is created and loaded into the main window of Visual Studio. 14. At the bottom of the window, click Main Report Preview. The report is displayed in preview mode and shows data from the secure Northwind database. Note The Preview button is a new feature of the embedded Crystal Reports Designer that ships with Crystal Reports for Visual Studio 2005. 15. At the bottom of the window, click Main Report to exit Preview mode. 16. Open the Web Form. 17. From the View menu, click Designer. The report is displayed in Design Time Preview mode and shows the report's graphic layout on the Web Form. 18. From the File menu, click Save All. Walkthroughs Copyright © 2004 Business Objects Page 305 Your report is created and is now the designated report for the CrystalReportSource control. You are now ready to build and run your project. To test the reduced-code Web Site 1. From the Build menu, select Build Solution. 2. If you have any build errors, go ahead and fix them now. 3. From the Debug menu, click Start. Note If you are developing a Web Site in Visual Studio 2005, and this is the first time you have started debugging, a dialog box appears and states that the Web.config file must be modified. Click the OK button to enable debugging. 4. A database logon prompt page appears, asking you to enter the database password. This is the expected result, for two reasons: You have not yet configured the data source. In Smart Tasks for the CrystalReportViewer control, the "Enable database logon prompting" checkbox is selected by default. 5. Enter the password and click Logon. 6. The NorthwindCustomers report is displayed in the Web browser. 7. Return to Visual Studio and click Stop to exit from debug mode. Configuring Database Logon Prompting in the Smart Task In this procedure, you examine the effect of turning off "Enable Database Logon Prompting" in the Smart Task. To configure Database Logon Prompting in the Smart Task 1. Open the Default.aspx page (the Web Form). 2. From the View menu, click Designer. 3. On the upper-right corner of the CrystalReportViewer control, click on the small triangular button. The Smart Task panel "CrystalReportViewer Tasks" opens. 4. Clear the Enable Database Logon Prompting checkbox. 5. Click on the Web Form to close the Smart Task. 6. From the Build menu, select Build Solution. 7. If you have any build errors, go ahead and fix them now. 8. From the Debug menu, click Start. Because database logon prompting is no longer enabled, a Logon Failed exception is thrown in the Web application window. 9. Return to Visual Studio and click Stop to exit from debug mode. 10. Return to the Smart Task panel for the CrystalReportViewer control. 11. Select the Enable Database Logon Prompting checkbox. 12. Close Smart Tasks. 13. From the File menu, click Save All. [...]... the Parameters tag directly in HTML view (source view) Creating a Web Site with a CrystalReportViewer control Before you create a Web Site, verify that Crystal Reports for Visual Studio 2005 has been installed on your system To set up a reduced-code Web Site in Crystal Reports for Visual Studio 2005 1 Start Visual Studio 2005 2 From the File menu, select New, and then click Web Site Copyright © 2004... open the Crystal Reports node to locate the CrystalReportViewer control 11 Drag the CrystalReportViewer control onto the Web Form The "CrystalReportViewer Tasks" Smart Task panel opens Configuring the CrystalReportSource in Smart Tasks Visual Studio 2005 has a new GUI feature for NET controls, called Smart Tasks For the CrystalReportViewer control in Web Sites, the Smart Task panel is named "CrystalReportViewer... access information Remember that the CrystalReportSource control was linked to the CrystalReportViewer control when adding the CrystalReportViewer control to the Web Form However, nothing has occurred to link the CrystalReportSource to the SqlDataSource Therefore, even though the data configuration information exists, at runtime the report would not be able to find this information and would ask for logon... the CrystalReportViewer control to other controls in the Windows project In this tutorial, you learn to expose Crystal report data from the CrystalReportViewer control to a label control in the Windows project To begin, you learn how to create a Windows project in Crystal Reports for Visual Studio 2005 You then add a CrystalReportViewer control to the Windows Form Then you add a label to the Windows Form... Windows project in Crystal Reports for Visual Studio 2005 1 Launch Visual Studio 2005 2 From the File menu, select New, and then click Project 3 In the New Project dialog box, select a language folder for C# or Visual Basic from the Project Types list 4 From the Templates list, click Windows Application 5 In the Name field, replace the default project name with the name of your project 6 Click OK Your... Solution Explorer and contains a Form1 class 7 Open the Form1 class 8 From the Toolbox, open the Crystal Reports node to locate the CrystalReportViewer control 9 Drag the CrystalReportViewer control onto the Windows Form 10 From the Properties window, set the Name property: For Visual Basic projects, set the value to "myCrystalReportViewer." For C# projects, set the value to "crystalReportViewer." 11 From... From Smart Tasks, you create a CrystalReportSource control, and then add a sample report to it You add a drill-down event to the CrystalReportViewer control Finally, you expose the drill-down event's report data to the label control Creating a Windows Project with a CrystalReportViewer Control Before you create a Windows Project, verify that Crystal Reports for Visual Studio 2005 has been installed on... onto the Web Form, to the topmost space 4 Click the Label control to select it 5 From the Properties window, set the ID property to "drillLabel" 6 From the File menu, click Save All Configuring the CrystalReportSource in Smart Tasks Visual Studio 2005 has a new GUI feature for NET controls, called Smart Tasks For the CrystalReportViewer control in Web Sites, the Smart Task panel is named "CrystalReportViewer... the bottom of the window, below the CrystalReportViewer control and the CrystalReportSource control Connecting CrystalReportSource to the SqlDataSource Control On your Web Form, you now have three controls that are related to each other: The CrystalReportViewer control, which links to the CrystalReportSource control to access the report to display it The CrystalReportSource control, which encapsulates... above the CrystalReportViewer control 4 Click the Label control to select it 5 From the Properties window, set the Name property to "drillLabel" 6 From the File menu, click Save All Configuring the CrystalReportSource in Smart Tasks Visual Studio 2005 has a new GUI feature for NET controls, called Smart Tasks For the CrystalReportViewer control in Web Sites, the Smart Task panel is named "CrystalReportViewer . in Crystal Reports for Visual Studio 2005. Creating a Windows Project with a CrystalReportViewer Control Before you create a Windows Project, verify that Crystal Reports for Visual Studio 2005. Before you create a Web Site, verify that Crystal Reports for Visual Studio 2005 has been installed on your system. To set up a reduced-code Web Site in Crystal Reports for Visual Studio 2005. embedded Crystal Reports Designer that ships with Crystal Reports for Visual Studio 2005. 15. At the bottom of the window, click Main Report to exit Preview mode. 16. Open the Web Form. 17.

Ngày đăng: 08/08/2014, 18:22

Từ khóa liên quan

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

  • Đang cập nhật ...

Tài liệu liên quan