Building Advanced Web Applications

The Simple Web Applications scenario focused on getting reports onto the Web and providing a basic level of customization via parameter fields, record selection formula, and database logon credentials. Whereas that will meet the needs of many, some developers want to build more interactive applications that create reports on-the-fly, modify report layout and structure, and other similar actions. These kind of applications provide a higher level of analysis and ad hoc capabilities. To meet these needs, in addition to the Report Viewers in COM, .NET, and Java, Crystal Reports 9 comes with a powerful Report Application Server SDK.

The Crystal Enterprise Report Application Server is designed for the Web. It is composed of two components: the report processing server and the SDK. The SDK is provided in COM, .NET, and Java platforms. These two components can reside on the same machine, but they can also be separated into two tiers. This means that the overhead of report processing can be offloaded from the Web server to a dedicated reporting server, while still retaining a rich SDK on the Web server. The SDK communicates via open TCP/IP protocols with the Report Application Server. This section focuses on various scenarios with the Report Application Server SDK.

Because the SDK needs to communicate with a Report Application Server, it is designed using a model-view-controller (MVC) pattern. The MVC pattern is an established pattern for software development and is in use in common applications such as Microsoft Word and Excel. An MVC pattern defines a model, a view, and a controller as three independent pieces of an application. The model represents the data in this case, the actual report document. The controller represents the mechanism for modifying the data held in the model in this case, manipulating the report. Finally, the view represents the developer's application, which provides a visual representation of that data usually using one of the report viewers. The naming of the various objects in the Report Application Server SDK indicates their place in the MVC architecture.

graphics/bookpencil_icon.gif

Although the Report Application Server SDK is provided in COM, .NET, and Java, the object model is exactly the same; therefore, the following code examples will be mixed between VBScript (ASP), Java, C#, and VB.NET (.NET).


To start, let's look at a very simple example of using the Report Application Server SDK (see Listing 24.3).

Listing 24.3 Using the RAS SDK via Active Server Pages
 <% Option Explicit ' Open the Report Dim Report Set Report = CreateObject("CrystalClientDoc.ReportClientDocument") Report.Open "C:\Temp\Sorts.rpt" ' Retrieve the customer name field object Dim field, fieldIndex fieldIndex = Report.Database.Tables(0).DataFields.Find("Customer Name", 0) Set field = Report.Database.Tables(0).DataFields(fieldIndex) ' Create a new sort based on the customer name field Dim sort Set sort = CreateObject("CrystalReports.Sort") sort.SortField = field ' Remove the sort previously defined in the Report file Report.DataDefController.SortController.Remove(0) ' Add the new sort Report.DataDefController.SortController.Add 0, sort Dim viewer Set viewer = CreateObject("CrystalReports.CrystalReportViewer") viewer.ReportSource = Report.ReportSource viewer.ProcessHttpRequest Request, Response %> 

This example is quite simple because it only opens the report and changes the field that the report is sorted on. Let's examine the code in a bit more detail to fully understand how the RAS SDK works. You'll notice that the Database object is used to retrieve one of the database fields defined in the report. The Database object and other objects suffixed with Definition, such as DataDefinition and ReportDefinition, represent the model piece of the MVC architecture. If all you needed to do was retrieve the definition of the report such as what database is being used, what fields are where on the report, or other similar things you need only use the Definition objects. However, in most cases, changes are needed to be made. Any necessary data changes need to be made via the controller.

There are several Controller objects in the RAS SDK. In the preceding example, the SortController is being used. First, it is being used to remove the first (and in this case, only) sorting defined in the report. Next, the SortController is being used to add the new sorting. This style of programming is consistent across the RAS SDK.

With the power to modify the report in many ways, you can imagine how your Web-based application can evolve from simply projecting a report onto a Web page to building a highly interactive ad hoc reporting application.



Sams Teach Yourself Crystal Reports 9 in 24 Hours
Sams Teach Yourself Crystal Reports 9 in 24 Hours
ISBN: B003D7JUVW
EAN: N/A
Year: 2005
Pages: 230

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net