1. Trang chủ
  2. » Công Nghệ Thông Tin

Crystal Reports For Visual Studio 2005 phần 5 pot

59 297 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 59
Dung lượng 342,29 KB

Nội dung

Walkthroughs Copyright © 2004 Business Objects Page 237 To set up a new project for the ExportToStream() Method 1. Complete the instructions in Adding Controls to the Web or Windows Form. 2. Create the ExportSetup() method and the ExportSelection() method in Creating Three Methods That Perform the Export. 3. Within the "Select Case" [Visual Basic] or "switch" [C#] statement of the ExportSelection() method, add a case statement for the ExcelRecord and the Text formats. [Visual Basic] Case ExportFormatType.ExcelRecord Case ExportFormatType.Text [end] [C#] case ExportFormatType.ExcelRecord: break; case ExportFormatType.Text: break; [end] 4. Create a conditional block to test the Boolean variable, selectedNoFormat. [Visual Basic] If selectedNoFormat Then Else End If [end] [C#] if (selectedNoFormat) { } else { } [end] 5. Within the If block, set the Text property of the message Label control to the FORMAT_NOT_SUPPORTED constant of the MessageConstants class. Note You have created the MessageConstants class for this tutorial in Additional Setup Requirements of Appendix: Project Setup. [Visual Basic] Walkthroughs Copyright © 2004 Business Objects Page 238 message.Text = MessageConstants.FORMAT_NOT_SUPPORTED [end] [C#] message.Text = MessageConstants.FORMAT_NOT_SUPPORTED; [end] 6. Within the Else block, set the Text property of the message Label control to the SUCCESS constant of the MessageConstants class. [Visual Basic] message.Text = MessageConstants.SUCCESS [end] [C#] message.Text = MessageConstants.SUCCESS; [end] 7. Create a try/catch block with the Exception class that is referenced as a variable named "ex." The try block encloses the "Select Case" [Visual Basic] or "switch" [C#] statement and the conditional block. [Visual Basic] Try Catch ex As Exception End Try [end] [C#] try { } catch (Exception ex) { } [end] 8. Within the catch block, set the Text property of the message Label control to the FAILURE constant of the MessagesConstants class, and then append to it the Message property of the Exception parameter. [Visual Basic] message.Text = MessageConstants.FAILURE & ex.Message [end] [C#] message.Text = MessageConstants.FAILURE + ex.Message; [end] Walkthroughs Copyright © 2004 Business Objects Page 239 9. Outside the try/catch block, set the Visible property of the message Label control to "True." [Visual Basic] message.Visible = True [end] [C#] message.Visible = true; [end] 10. From the View menu, click Designer. 11. Double-click the exportByType Button control. The exportByType_Click() event method is created, and you are taken to the Code view. 12. Within the exportByType_Click() event method, enter calls to the ExportSetup() and ExportSelection() methods. [Visual Basic] ExportSetup() ExportSelection() [end] [C#] ExportSetup(); ExportSelection(); [end] Preparing the Project for the ExportToStream() Method In this section, you learn how to modify a project that is a result of the procedure in Creating Methods for the New Exporting Formats. Now, you must delete certain lines of code that are not needed for the ExportToStream() method. To modify the project to use the ExportToStream() method 1. Open the project. 2. Open the Web or Windows Form. 3. From the View menu, click Code. 4. At the top of the class, delete the following class declarations: [Visual Basic] Private myDiskFileDestinationOptions As DiskFileDestinationOptions Private myExportOptions As ExportOptions [end] [C#] private DiskFileDestinationOptions diskFileDestinationOptions; Walkthroughs Copyright © 2004 Business Objects Page 240 private ExportOptions exportOptions; [end] 5. Within the ExportSetup() method, delete all the lines of code after the conditional block. (The last line of code that calls the FormatOptions property only occurs in a Windows project.) [Visual Basic] myDiskFileDestinationOptions = New DiskFileDestinationOptions() myExportOptions = hierarchicalGroupingReport.ExportOptions myExportOptions.ExportDestinationType = ExportDestinationType.DiskFile myExportOptions.FormatOptions = Nothing [end] [C#] diskFileDestinationOptions = new DiskFileDestinationOptions(); exportOptions = hierarchicalGroupingReport.ExportOptions; exportOptions.ExportDestinationType = ExportDestinationType.DiskFile; exportOptions.FormatOptions = null; [end] 6. Delete the following export configuration methods: ConfigureExportToRpt() ConfigureExportToRtf() ConfigureExportToDoc() ConfigureExportToXls() ConfigureExportToPdf() ConfigureExportToHtml32() ConfigureExportToHtml40() ConfigureExportToXlsRec() ConfigureExportToTxt() 7. Within the Select Case [Visual Basic] or switch [C#] case statements of ExportSelection() , delete the calls to the export configuration methods. 8. Within the ExportCompletion() method, delete the call to the Export() method. 9. Copy and paste all the code from the ExportCompletion() method to the top of the ExportSelection() method. 10. Delete the ExportCompletion() method and delete the call to ExportCompletion() in exportByType button click event. 11. Within the ExportSelection() method, cut and paste the Select Case [Visual Basic] or switch [C#] case statements above the If block within the try block. The try/catch block now looks like the following: [Visual Basic] Try Select Case exportTypesList.SelectedIndex Walkthroughs Copyright © 2004 Business Objects Page 241 Case ExportFormatType.NoFormat selectedNoFormat = True Case ExportFormatType.CrystalReport Case ExportFormatType.RichText Case ExportFormatType.WordForWindows Case ExportFormatType.Excel Case ExportFormatType.PortableDocFormat Case ExportFormatType.HTML32 Case ExportFormatType.HTML40 End Select If selectedNoFormat Then message.Text = MessageConstants.FORMAT_NOT_SUPPORTED Else message.Text = MessageConstants.SUCCESS End If Catch ex As Exception message.Text = MessageConstants.FAILURE & ex.Message End Try [end] [C#] try { switch ((ExportFormatType)exportTypesList.SelectedIndex) { case ExportFormatType.NoFormat: selectedNoFormat = true; break; case ExportFormatType.CrystalReport: Walkthroughs Copyright © 2004 Business Objects Page 242 break; case ExportFormatType.RichText: break; case ExportFormatType.WordForWindows: break; case ExportFormatType.Excel: break; case ExportFormatType.PortableDocFormat: break; case ExportFormatType.HTML32: break; case ExportFormatType.HTML40: break; case ExportFormatType.ExcelRecord: break; case ExportFormatType.Text: break; } if (selectedNoFormat) { message.Text = MessageConstants.FORMAT_NOT_SUPPORTED; } else { message.Text = MessageConstants.SUCCESS; } } catch (Exception ex) { message.Text = MessageConstants.FAILURE + ex.Message; } [end] Walkthroughs Copyright © 2004 Business Objects Page 243 Modifying the Case Statements in the ExportSelection() Method In this section, you learn how to set a file name string for each ExportFormatType case statement. To modify the case statements in the ExportSelection() method 1. Within the ExportSelection() method, declare a string variable and instantiate the variable to an empty string. [Visual Basic] Dim myFileName As String = "" [end] [C#] string fileName = ""; [end] 2. Within the ExportFormatType.CrystalReport case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .rpt file extension. [Visual Basic] myFileName = exportPath & "Report.rpt" [end] [C#] myFileName = exportPath + "Report.rpt"; [end] 3. Within the ExportFormatType.RichText case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .rtf file extension. [Visual Basic] myFileName = exportPath & "RichTextFormat.rtf" [end] [C#] myFileName = exportPath + "RichTextFormat.rtf"; [end] 4. Within the ExportFormatType.WordForWindows case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .doc file extension. [Visual Basic] myFileName = exportPath & "Word.doc" [end] [C#] fileName = exportPath + "Word.doc"; [end] Walkthroughs Copyright © 2004 Business Objects Page 244 5. Within the ExportFormatType.Excel case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .xls file extension. [Visual Basic] myFileName = exportPath & "Excel.xls" [end] [C#] fileName = exportPath + "Excel.xls"; [end] 6. Within the ExportFormatType.PortableDocFormat case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .pdf file extension. [Visual Basic] myFileName = exportPath & "PortableDoc.pdf" [end] [C#] fileName = exportPath + "PortableDoc.pdf"; [end] 7. Within the ExportFormatType.HTML32 case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .html file extension. [Visual Basic] myFileName = exportPath & "HTML32.html" [end] [C#] fileName = exportPath + "HTML32.html"; [end] 8. Within the ExportFormatType.HTML40 case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .html file extension. [Visual Basic] myFileName = exportPath & "HTML40.html" [end] [C#] fileName = exportPath + "HTML40.html"; [end] 9. Within the ExportFormatType.ExcelRecord case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .xls file extension. [Visual Basic] myFileName = exportPath & "ExcelRecord.xls" [end] Walkthroughs Copyright © 2004 Business Objects Page 245 [C#] fileName = exportPath + "ExcelRecord.xls"; [end] 10. Within the ExportFormatType.Text case statement, set the file name string to the exportPath string that is followed by a recognizable document name with a .txt file extension. [Visual Basic] myFileName = exportPath & "Text.txt" [end] [C#] fileName = exportPath + "Text.txt"; [end] Calling the ExportToStream() Method In this section, you learn how to call the ExportToStream() method and to write the exported report data to a file in your specified format. To call the ExportToStream() method in the ExportSelection() method 1. Above the class signature, add an "Imports" [Visual Basic] or "using" [C#] declaration to the top of the class for the System.IO namespace. [Visual Basic] Imports System.IO [end] [C#] using System.IO; [end] 2. Within the Else block of the ExportSelection() method, call the ExportToStream() method of the hierarchicalGroupingReport instance, pass in the selected ExportFormatType from the exportTypesList dropdownlist, and assign the instance to the Stream class. [Visual Basic] Stream myStream = hierarchicalGroupingReport.ExportToHttpResponse(exportTypesList.Selecte dIndex) [end] [C#] Stream stream = hierarchicalGroupingReport.ExportToHttpResponse((ExportFormatType)expor tTypesList.SelectedIndex); [end] 3. Create a new byte array that has the same length as the Stream instance. [Visual Basic] Dim myDataArray As byte() = New byte(myStream.Length) Walkthroughs Copyright © 2004 Business Objects Page 246 [end] [C#] byte[] dataArray = new byte[stream.Length]; [end] 4. Read the data from the Stream instance to the byte array from a zero offset to the length of the Stream instance. [Visual Basic] myStream.Read(myDataArray, 0, Convert.ToInt32(myStream.Length)); [end] [C#] stream.Read(dataArray, 0, Convert.ToInt32(stream.Length)); [end] 5. Create a FileStream instance that creates the file specified by the file name string variable. [Visual Basic] Dim myFileStream As FileStream = New FileStream(myFileName, System.IO.FileMode.Create) [end] [C#] FileStream fileStream = new FileStream(fileName, System.IO.FileMode.Create); [end] 6. Write the data stored in the byte array to the file from a zero offset to the length of the byte array. [Visual Basic] myFileStream.Write(myDataArray, 0, myDataArray.Length) [end] [C#] fileStream.Write(dataArray, 0, dataArray.Length); [end] 7. Close the FileStream instance and the Stream instance. [Visual Basic] myFileStream.Close() myStream.Close() [end] [C#] fileStream.Close(); stream.Close(); [end] 8. Set the Text property of the message Label control to the SUCCESS constant of the MessageConstants class. [...]... CS_Win_RDObjMod_SetPrintOptions Visual Basic Web Site: VB_Web_RDObjMod_SetPrintOptions Visual Basic Windows project: VB_Win_RDObjMod_SetPrintOptions To locate the folders that contain these samples, see Appendix: Tutorials' Sample Code Directory Copyright © 2004 Business Objects Page 263 Walkthroughs Crystal Reports For Visual Studio 20 05 ReportDocument Object Model Tutorial: Filtering Data Using Selection Formulas Copyright... the CrystalReportViewer control You can instantiate and bind the report in two ways: As an embedded report As a non-embedded report Note Visual Studio 20 05 supports only non-embedded reports for Web Sites Choose from one (but not both) of the step procedures below If you use embedded reports, follow the next step procedure to instantiate the report as an embedded report If you use non-embedded reports, ... area on the form The page switches to Code view and generates a Page_Load() event method (for a Web Form) or a Form1_Load() event method (for a Windows Form) 4 If you are developing a Web Site, within the Page_Load() event method, create a Not IsPostBack conditional block [Visual Basic] If Not IsPostBack Then End If [end] [C#] if (!IsPostBack) { } Copyright © 2004 Business Objects Page 254 Walkthroughs... the ConfigureCrystalReports() method, instantiate the report wrapper class Note You created the ConfigureCrystalReports() method in Appendix: Project Setup [Visual Basic] customerBySalesNameReport = New CustomerBySalesName() [end] [C#] customerBySalesNameReport = new CustomerBySalesName(); [end] 5 On the next line beneath the report instantiation, bind the ReportSource property of the CrystalReportViewer... customerBySalesName is assigned to the ReportSource property of the CrystalReportViewer control 9 In this line break, assign the selectionFormula string variable to the ReportDocument instance [Visual Basic] customerBySalesNameReport.DataDefinition.RecordSelectionFormula = selectionFormula [end] [C#] customerBySalesNameReport.DataDefinition.RecordSelectionFormula = selectionFormula; [end] Copyright © 2004... to Visual Studio and click Stop to exit from debug mode In the next section, you create controls on the form that allow you to adjust the selection formula dynamically Adding Controls for Dynamic Filtering In this section, you add controls to use in the selection formula These controls allow you to filter the data dynamically To add controls to use in the selection formula 1 Open the Web or Windows Form... Report 3 In the Name field, enter the name "CustomerBySalesName.rpt" and click Add 4 If you have not registered before, you are asked to register To find out how to register, see Appendix: Crystal Reports Registration and Keycode 5 In the Create New Crystal Report Document panel of the Crystal Reports Gallery dialog box, select Using a Report Wizard 6 In the Choose an Expert panel, select Standard, and... names for each sample code version are as follows: C# Web Site: CS_Web_RDObjMod_Export C# Windows project: CS_Win_RDObjMod_Export Visual Basic Web Site: VB_Web_RDObjMod_Export Visual Basic Windows project: VB_Win_RDObjMod_Export To locate the folders that contain these samples, see Appendix: Tutorials' Sample Code Directory Copyright © 2004 Business Objects Page 247 Walkthroughs Crystal Reports For Visual. .. CURRENT_PRINTER constant and other settings for errors 5 Return to Visual Studio and click Stop to exit from debug mode Conclusion In this tutorial, you learned how to configure print options You placed controls on the form and populated them to display standard print options from printing enumerations in the CrystalDecisions.Shared class, as well as custom paper sources for the currently selected printer Copyright... customerBySalesNameReport) [Visual Basic] myCrystalReportViewer.ReportSource = customerBySalesNameReport [end] [C#] crystalReportViewer.ReportSource = customerBySalesNameReport; [end] You are now ready to build and run your project Skip to the next section below To instantiate the CustomerBySalesName report as a non-embedded report and bind it to the CrystalReportViewer control 1 Open the Web or Windows Form 2 From . Case ExportFormatType.NoFormat selectedNoFormat = True Case ExportFormatType.CrystalReport Case ExportFormatType.RichText Case ExportFormatType.WordForWindows Case ExportFormatType.Excel. ExportFormatType.RichText: break; case ExportFormatType.WordForWindows: break; case ExportFormatType.Excel: break; case ExportFormatType.PortableDocFormat: break; case ExportFormatType.HTML32:. Directory. Walkthroughs Copyright © 2004 Business Objects Page 248 Crystal Reports For Visual Studio 20 05 ReportDocument Object Model Tutorial: Printing and Setting Print Options

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

TỪ KHÓA LIÊN QUAN