ASP.NET
  Home arrow ASP.NET arrow Page 4 - Object-Oriented Report Development using C...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Object-Oriented Report Development using Crystal Reports and ASP.NET 2.0
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2007-08-20

    Table of Contents:
  • Object-Oriented Report Development using Crystal Reports and ASP.NET 2.0
  • The DBHelper class for interacting with the database
  • Developing classes to hold information from the database
  • Adding a Factory class to populate object collection

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Object-Oriented Report Development using Crystal Reports and ASP.NET 2.0 - Adding a Factory class to populate object collection


    (Page 4 of 4 )

    This class mainly interacts with the "DBHelper" class to fetch information from the database and populates the collection objects. This class can also have DML operations like Insert, Update, Delete, and so forth. For the sake of clarity, I removed those methods.

    Add a new class (OrderFactory.vb), which deals with business logic, and copy the following code:

    Imports Microsoft.VisualBasic

    Imports System.Data

     

    Public Class OrderFactory

     

      Public Function GetOrdersListCollection() As OrderCollection

        Dim clnOrders As New OrderCollection

        For Each dr As DataRow In GetOrdersList.Rows

          clnOrders.Add(New Order(dr("OrderID"), dr("CustomerName"), dr
    ("EmployeeName"), dr("OrderDate"), dr("OrderValue")))

        Next

        Return clnOrders

      End Function

     

      Public Function GetOrdersList() As DataTable

        Dim sql As String

        sql = "SELECT     dbo.Orders.OrderID, dbo.Customers.CompanyName AS
    CustomerName, dbo.Employees.LastName AS EmployeeName,
    dbo.Orders.OrderDate, "

        sql &= "          SUM(dbo.[Order Details].UnitPrice * dbo.[Order Details].Quantity)
    AS OrderValue "

        sql &= "FROM      dbo.Orders INNER JOIN "

        sql &= "          dbo.[Order Details] ON dbo.Orders.OrderID = dbo.[Order
    Details].OrderID INNER JOIN "

        sql &= "          dbo.Employees ON dbo.Orders.EmployeeID =
    dbo.Employees.EmployeeID INNER JOIN "

        sql &= "          dbo.Customers ON dbo.Orders.CustomerID =
    dbo.Customers.CustomerID "

        sql &= "GROUP BY dbo.Orders.OrderID, dbo.Customers.CompanyName,
    dbo.Employees.LastName, dbo.Orders.OrderDate"

        Return DBHelper.getDataTable(sql)

      End Function

     

    End Class

    If you would like to work with stored procedures, create a stored procedure at SQL Server and work with "DBHelper.SPgetDataTable("<storedprocedurename>")".  This is another professional approach with the best database performance in mind.

    Designing, developing and binding Crystal Report to the Visual Basic 2005 business logic class

    Once the classes are complete, add a new Crystal Report to the web site (SampleReport01.rpt). With the Standard Report expert, select the "Order" class available under ".NET Objects" and include all the fields. Report Designer gets opened with all the fields and you can format the report according to your requirements.

    Drag a button and CrystalReportViewer control onto the web form.  In the code behind, copy the following code:

    Imports CrystalDecisions.Shared

    Imports CrystalDecisions.CrystalReports.Engine

     

    Partial Class _Default

        Inherits System.Web.UI.Page

     

      Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click

        CrystalReportViewer1_Navigate(Nothing, Nothing)

      End Sub

     

      Protected Sub CrystalReportViewer1_Navigate(ByVal source As Object, ByVal e
    As CrystalDecisions.Web.NavigateEventArgs) Handles
    CrystalReportViewer1.Navigate

        Dim rep As New ReportDocument

        rep.Load(Server.MapPath("SampleReport01.rpt"))

        rep.SetDataSource((New OrderFactory).GetOrdersListCollection)

        Me.CrystalReportViewer1.ReportSource = rep

        Me.CrystalReportViewer1.DataBind()

      End Sub

    End Class

     

    The most important statement to note from the above code is the following:

        rep.SetDataSource((New OrderFactory).GetOrdersListCollection)

    I am creating an instance of "OrderFactory" and executing the "GetOrderListCollection" method. It returns the collection which gets bound to the report.

    Finally, execute the application and hit the button to view the report.

    I hope you enjoyed the article and any suggestions, bugs, errors, enhancements etc. are highly appreciated at http://jagchat.spaces.live.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys,This is my next contribution on the series of "Programming Crystal...
     

    ASP.NET ARTICLES

    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...
    - Completing an ASP.NET AJAX Server-Centric Ba...
    - Information Management for an ASP.NET AJAX S...
    - Comment and Order Management for an ASP.NET ...
    - Back-end Management Tasks for an ASP.NET AJA...
    - User Information Management for an ASP.NET A...
    - Adding Comments and Search to an ASP.NET AJA...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway