Object-Oriented Report Development using Crystal Reports and ASP.NET 2.0
(Page 1 of 4 )
This is the fourth article in a series focusing on programming with Crystal Reports and ASP.NET 2.0. In this article, we will focus on implementing an object-oriented approach for creating and developing Crystal Reports using ASP.NET 2.0 and Visual Basic 2005.
A
downloadable zip file is available for this article.
If you are new to Crystal report programming, I strongly suggest that you go through the following articles:
Programming Crystal Reports with ASP.NET 2.0
Working with Parameters with Crystal Reports and ASP.NET 2.0
If you are new to OOP-based database applications in Visual Basic 2005, I further suggest that you read the following article:
Implementing OOP to Develop Database-Oriented Applications using VB.NET 2005
The entire solution (source code) for this article is available as a free download (in the form of a zip). The source code in this article has been developed using Microsoft Visual Studio 2005 Professional Edition on Microsoft Windows XP Professional Edition with Microsoft SQL Server 2005 Express Edition. I used the same version of Crystal Reports which comes with Visual Studio 2005 Professional Edition. I didn't really test any of the code in any other tools/IDEs/servers/editions/versions. If you have any problems, please feel free to post in the discussion area.
The approach for mixing business logic-based OOP with Crystal Reports
Almost every .NET application is object oriented. We develop several classes involving different OOPS concepts such as inheritance, polymorphism, and so on to make applications more scalable, readable and easier to maintain. Most of these classes fall into either business logic or data access layers.
Furthermore, we even implement a few types of patterns suggested by experts to solve the most common integration problems. The best example of this is Microsoft Enterprise Library. The pattern-oriented library is divided into several blocks and each block focuses on a particular type of module.
All of the above methodologies are quite familiar during .NET application development. But, coming to Crystal Report development, developers take advantage of different approaches to make it easier to maintain. Most of those approaches directly use databases as data sources.
When we maintain all our data access and business logic in the form of different classes, why can’t we use the same classes for report development as well? This approach would work well when we try to have reports embedded as part of our application, and this may not be suitable (or practical) to deploy with Crystal Servers.
I must also agree that performance would be an issue. Performance tuning a report is not simply related to the report. We may need to tune a database (or data) with different approaches to get the reports out more quickly. Most people use stored procedures, indexed views, and so on to improve the performance of reports.
Considering all of the above issues, I would like to present a simple approach which marries business logic classes with Crystal Reports. In my approach, I would like to introduce the following four classes:
DBHelper
Order
OrderCollection
OrderFactory
"DBHelper" is meant only to interact with databases. "Order" contains detailed information about a particular order from the "Northwind" database. "OrderCollection" simply maintains a set of orders. "OrderFactory" populates the "OrderCollection."
Please note that this approach may not be suitable for every application or report you develop. It totally depends on issues such as requirements, performance, maintenance, administration, scheduling, and so forth.
Let us observe the code of each of those classes before looking at report development.
Next: The DBHelper class for interacting with the database >>
More ASP.NET Articles
More By Jagadish Chaterjee