Professional.Crystal.Reports.for.Visual.Studio..NET [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Professional.Crystal.Reports.for.Visual.Studio..NET [Electronic resources] - نسخه متنی

David McAmis

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید



























Using Crystal Reports 8.5 in Visual Studio .NET



As stated above, the most likely scenario is using existing Crystal Reports in new Visual Studio .NET applications. The essential goal here is adding existing .RPT files to a new Visual Basic .NET project, and viewing them using the Crystal Reports Windows Forms Viewer. Initially, this is made complex by the basic constraint of the Crystal Report Viewer in Visual Studio .NET and its poor support of the ODBC and OLEDB methods of data access.

As part of this appendix, we'll add two existing Crystal 8.5 reports to a new Visual Basic .NET Windows Application, using the Crystal Reports Windows Forms Viewer. We'll start by looking at our sample reports, then build our viewer, including the reports, and change the data connection as needed. Finally, we'll consider some advanced topics.


Important

Keep in mind that the biggest change in the use of Crystal 8.5 reports in Visual Studio .NET is the new object model of the .NET Framework.


Our Sample Reports


The first report, Sample 8.5.rpt, is a simple report drawn from the Pubs database in a local SQL Server. The Pubs database is available from the Microsoft site, or you can download the SQL Script as part of the code samples in this appendix.



This report uses the three basic features of any report, grouped data, charts, and text. It is a collation of sales by author, including a pie chart of the Top 5 Authors by Volume. There are a few formulas - mostly text concatenations - included to prove that this functionality works in Visual Studio .NET. More complex algorithms would only confuse matters, as all formulas are executed in the same way.

A More Complex Example


To stir things up a little, we have added Complex Sample 8.5.rpt. This report uses some of the features not supported in Visual Studio .NET, just to see what happens to them. These features include:



Office Connectivity



OLAP



Mapping



Alerts



XML



For this example, we'll include some mapping, offer some XML Export, and take a look at how Visual Studio .NET handles these changes. See the sample files for a copy of this report, which is essentially the same as Sample 8.5.rpt, with a map of sales rather than a chart.






A New Visual Basic .NET Report Viewer


First we need to build a very simple single-form Windows Application that will handle these two reports.

Create a new Visual Basic .NET Windows Application called ReportViewer. Next, add the two report files, Sample 8.5.RPT and Complex Sample 8.5.RPT, to the project. Enlarge the form, and add a CrystalReportViewer, a ComboBox, and a Button control as below. Set the CrystalReportViewer control's visibility to False.


In the Form1_Load event handler, fill ComboBox1 with our two report types:


Private Sub Form1_Load(ByVal sender As System.Object, & _
ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("Simple Report")
ComboBox1.Iterns.Add("Complex Report")
End Sub

In the Button1_Click event handler, we'll check the value of ComboBox1 and fire up the viewer:


Private Sub Button1_Click(ByVal sender As System.Object, & _
ByVal e As System.EventArgs) Handles Button1.Click
Select Case ComboBox1.SelectedItem
Case "Simple Report"
CrystalReportViewer1.ReportSource = "Sample 8.5.rpt"
CrystalReportViewer1.Visible = True
Case "Complex Report"
CrystalReportViewer1.ReportSource = "Complex Sample 8.5.rpt"
CrystalReportViewer1.Visible = True
Case Else
MsgBox("Select a report")
End Select
End Sub

Finally, run the report in debug mode by hitting F5.



Select a report from the drop-down list, and click on the Show Me button to open the selected report. The following dialog will appear:


So what happened here? The dialog doesn't give you much information - just typical of Crystal Reports, isn't it? Even in debug mode, you don't get any good information about what actually happened, so, if you are like me, you'll attempt to Verify Database by loading the report into Visual Studio .NET and right-clicking on the data connections.


We find that Crystal Reports still provides us with a wonderful cryptic error message - Unable to Load Report. So what's up? As it turns out, the problem wasn't the data connection at all, and in fact the use of the data wizard isn't necessary.

What this comes down to is a difference between using a Crystal Reports 8.5 report in a .NET application, and using a Crystal Reports.NET report. Until we did the data fix-up, essentially we still had a Crystal Reports 8.5 report, residing in a .NET application.


Important

Crystal 8.5 reports are still usable in .NET applications and have all of the same data features as if they were in VB6. Only reports changed to .NET format lose the ODBC functionality.

The best lessons are lessons learned the hard way, but we get to re-download the report and try again. We need to begin again with a new report, with a new name, in order to change our attitude.




Changing our Visual Basic .NET Report Viewer


Visual Basic .NET is an object-oriented language, and we need to treat it as so when dealing with Crystal Reports. Let's try a few new steps that may help us with the new paradigm.

Begin by renaming the report files to simple.rpt and complex.rpt. The Visual Studio .NET designer will use the names of our files as report names. Remove the old reports from the designer by right-clicking on them and selecting Remove From Project, and then add the two new files. The Solution Explorer should look something like this:


Build the solution (the shortcut keys are Ctrl+Shift+B). Now change the Button1_Click event handler to something more object oriented, so it looks like this:


Private Sub Button1_Click(ByVal sender As System.Object, & _
ByVal e As System.EventArgs) Handles Button1.Click
Select Case ComboBox1.SelectedItem
Case "Simple Report"
Dim simpleReport As New simple()
CrystalReportViewer1.ReportSource = simpleReport
CrystalReportViewer1.Visible = True
Case "Complex Report"
Dim complexReport As New complex()
CrystalReportViewer1.ReportSource = complexReport
CrystalReportViewer1.Visible = True
Case Else
MsgBox("Select a report")
End Select
End Sub

Next build and run the program. When the application has loaded, select the simple report, and the report loads in the viewer as it should.



Admittedly, using some of the more esoteric data drivers like Btrieve, and perhaps some of the more out of date drivers, such as DB2 drivers, will cause problems. The good word from the nice people at Crystal Decisions is that if it doesn't simply work when this protocol is tried, it may be necessary to fix-up the report, delete the existing data bindings, and replace all of the fields in the reports. Upgrades can be like that - you can only go so far before you have to start over from scratch.



Invalid Features in the Complex Report


So now, we need to implement the same type of functionality in the complex sample. Largely, everything in the two reports is the same, with the exception of two new requirements - namely the map and the XML Export.

The Map Graphic


The map is a simple examination. If we open the complex.rpt file in Visual Studio .NET, we discover that the software simply doesn't recognize it.



We can see that the object is referenced, but it is a kind of crMapObject, and none of the operational parameters that we see in Crystal Reports 8.5 are available. Also, the object isn't viewable in preview mode in the designer, although it will still run in a viewer - so long as we don't convert the report file from the previous file format to a .NET format, as we discussed above.


Important

You will also find that Crystal Dictionaries and Crystal Queries are not supported in .NET, and will not actually run. Reports using these technologies will probably need to be rewritten to use DataSets, as described in Chapter 6 of the book.



The XML Export


The XML Export is constrained by the Property Explorer of the CrystalReportViewer object itself, in our Visual Basic .NET Windows Application -just as it is in VB6. Checking the Property Explorer, we discover that some features, including XML Export - simply aren't there, irrespective of the version of the report contained in the viewer.

The export to XML just isn't an option, and as described by Crystal Decisions, exports only work to:



RTF



DOC (Microsoft Word)



PDF



XLS




RPT



HTML



DHTML



This is still an excellent selection of formats for most uses.




/ 115