Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member200290
Contributor
0 Kudos

So you want to create a simple application in PowerBuilder .NET to view, export and print Crystal Reports? Well this is the information for you.

This will be a step-by-step guide in how to accomplish just that.

Part One - Setting up the environment

On your development machine that has PowerBuilder .NET installed:

  1. Install the Visual Studio 2010 Shell (Integrated) Redistributable Package. This is a prerequeset for our installer. Note: Just installing the redistributables doesn't seem to work as I was unable to find a way to get PowerBuilder to reference objects from the GAC (WindowsAssembly directory).
  2. Recent Service Packs (CR for VS 2010). When it installs it may ask if you want to install the 64 bit runtime after, select yes. Note: This may throw you off but our install does not present an install complete message box, when the install screens are all gone you can assume the install was finished.

It is as simple as that!

Part Two - Creating a simple viewing form

Start PowerBuilder .NET but do not load any projects or solutions.

  1. Download CR XI Xtreme Report Samples and Database  Note: As CR for VS 2010 doesn't ship with samples and the designer that ships with the product doesn't run without full VS 2010, you will need these samples. To create your own reports you will need our full design
  2. Extract the Reports and Databases directory to a directory of your choice. For my sample I am using c:     est
  3. In PowerBuilder .NET click File->New->Finish.
  4. Give your solution a name and save it, for example I am using the c:     estBasicCrystal directory and file name of BasicCrystal.pbwx.
  5. Click File->New expand Target and select WPF Window Application.
  6. Click Next -> Next and name your Application. I used wpfCrystalApp then click Finish.
  7. Again click File -> New.
  8. Select WPF Window under PB Object.
  9. Click next and give the window title and name. I used Simple Viewer for the title and w_SimpleView for the name.
  10. Click Finish.
  11. DoubleClick wpfCrystalApp to get the Open (string commandline) event add this code: 
    open (w_SimpleView)
  12. Right-click  on References in your Solution Explorer and select Add Reference
  13. From the .NET TAB select CrystalDecisions.CrystalReports.Engine and CrystalDecisions.Shared and every CrystalDecisions.ReportAppServer reference.
  14. Right-Click in your Toolbox and select Choose Items...
  15. From WPF Components select CrystalReportsViewer
  16. Place three buttons horizontally across the top of the form and then the CrystalReportsViewer filling the rest. It will look like the following:
  17. Select the CrystalReportsViewer1 control and in the properties window enable ShowOpenFileButton.

You can now run your project, when your WPF Form displays click the open button in the viewer control and browse to the sample reports we downloaded earlier (or yours if you have some on the system already).

Part Three - Loading a Report and setting a parameter

Here we will load a report globally to be used by the next three sections.

  1.  Double click the first button to take you to code view
  2. Above the code editting box in the first drop down box change from cb_1 to (Declare)
  3. In the second drop down box change Instance Variables to Global Variables.
  4. Add this line of code:
    CrystalDecisions.CrystalReports.Engine.ReportDocument crRptDoc
  5. Select the w_SimpleView:Window [Script]* tab.
  6. Again in the first drop down box change from (Declare) to w_SimpleView.
  7. This should take you to the Open (string commandline)
  8. Add this code to instantiate the report variable, open the report and set a parameter value
    crRptDoc = create CrystalDecisions.CrystalReports.Engine.ReportDocument
    crRptDoc.Load ("C:     estReportsFeature ExamplesAlerting.rpt")
    crRptDoc.SetParameterValue (0,1000)
  9. Now to pretty up the form go back to the w_SimpleView [Layout] tab, select the first button and change its text to "View Report".
  10. Double click the button to go back to its click event and add this code:
    crystalreportsviewer1.ViewerCore.ReportSource = crRptDoc

Part 4 - Exporting the Report

  1. Go back to the w_SimpleView [Layout] tab, select the second button and change its text to "Export Report".
  2. Add the following line of code to export the report to PDF format:
    crRptDoc.ExportToDisk (CrystalDecisions.@Shared.ExportFormatType.PortableDocFormat!,"c:     est     est.pdf")

Part 5 - Printing the Report

  1. Go back to the w_SimpleView [Layout] tab, select the third button and change its text to "Print Report".
  2. Add the following line of code to export the report to PDF format:
    crRptDoc.PrintToPrinter (1,true,1,2)

Conclusion

I hope this bit of a start help you to get started on using the Crystal Reports SDK in PowerBuilder.NET. As time permits I will hopefully play around with PowerBuilder.NET more and get back to you with my results.

Remember to read my first part Developing Crystal Reports applications in PowerBuilder .NET and Crystal Reports and Enterprise .NET developer resources

4 Comments