C#
  Home arrow C# arrow Page 6 - Creating Graphical Reports With Crystal Re...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
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? 
C#

Creating Graphical Reports With Crystal Reports in .NET
By: Wrox Team
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 156
    2002-11-10

    Table of Contents:
  • Creating Graphical Reports With Crystal Reports in .NET
  • The Database
  • Creating Web Pages
  • The Report
  • Creating Report Parameters
  • Passing Parameters to a Report
  • Conclusion

  • 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


    Creating Graphical Reports With Crystal Reports in .NET - Passing Parameters to a Report


    (Page 6 of 7 )

    If you take a look at the end of the Page_Load function, we have called a method setReportParameters(). This method will actually add/send the parameters to our report. So let us see this final function:

    // this method sets the parameters of the report
    private void setReportParameters()
    {

    // all the parameter fields will be added to this collection
    ParameterFields paramFields = new ParameterFields();

    // the parameter fields to be sent to the report
    ParameterField pfItemId = new ParameterField();
    ParameterField pfStartDate = new ParameterField();
    ParameterField pfEndDate = new ParameterField();

    // setting the name of parameter fields with wich they will be recieved in report
    pfItemId.ParameterFieldName = "ItemId";

    pfStartDate.ParameterFieldName = "StartDate";
    pfEndDate.ParameterFieldName = "EndDate";

    // the above declared parameter fields accept values as discrete objects
    // so declaring discrete objects
    ParameterDiscreteValue dcItemId = new ParameterDiscreteValue();
    ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();
    ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();

    // setting the values of discrete objects
    dcItemId.Value = nItemId;

    dcStartDate.Value = DateTime.Parse(strStartDate);
    dcEndDate.Value = DateTime.Parse(strEndDate);

    // now adding these discrete values to parameters
    pfItemId.CurrentValues.Add(dcItemId);
    pfStartDate.CurrentValues.Add(dcStartDate);
    pfEndDate.CurrentValues.Add(dcEndDate);

    // now adding all these parameter fields to the parameter collection
    paramFields.Add(pfItemId);
    paramFields.Add(pfStartDate);
    paramFields.Add(pfEndDate);

    // finally add the parameter collection to the crystal report viewer
    crViewer.ParameterFieldInfo = paramFields;
    }


    Before dissecting the above code let us study the theory behind it. Our crystal report viewer object crViewer has a property that accepts a collection of ParameterFields type. Through this property, all the parameters are passed to the report. This ParameterFields collection has an Add method, which accepts objects of type ParameterField. So what we do is create three objects of type ParameterField for our three parameters, ItemId, StartDate and EndDate. We then add the values of these parameters to these objects, add them to the collection, and then finally specify this collection as the ParameterFieldInfo property of the crystal report viewer object.

    So, from the top where we declare the collection and the three ParameterField objects:

    // all the parameter fields will be added to this collection
    ParameterFields paramFields = new ParameterFields();

    // the parameter fields to be sent to the report
    ParameterField pfItemId = new ParameterField();
    ParameterField pfStartDate = new ParameterField();
    ParameterField pfEndDate = new ParameterField();


    Then we name the parameter fields. These are the names with which they are referred in the crystal report. Remember, we used these names there. After this we need to provide values to these parameter fields. But we cannot just set the values of these parameter fields directly - they accept object of type ParameterDiscreteValue. So we will declare three objects of the this type, and after specifying their values, will add them to the parameter fields. This code deals with this task:

    // the above declared parameter fields accept values as discrete objects
    // so declaring discrete objects
    ParameterDiscreteValue dcItemId = new ParameterDiscreteValue();
    ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();
    ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();

    // setting the values of discrete objects
    dcItemId.Value = nItemId;

    dcStartDate.Value = DateTime.Parse(strStartDate);
    dcEndDate.Value = DateTime.Parse(strEndDate);

    // now adding these discrete values to parameters
    pfItemId.CurrentValues.Add(dcItemId);
    pfStartDate.CurrentValues.Add(dcStartDate);
    pfEndDate.CurrentValues.Add(dcEndDate);


    Here we first declare these objects, then set their values and add them to the parameter fields. As you can see, we have called the Add method of the CurrentValues object and passed it the discrete parameters. So this way all the parameter fields are ready to be added to the collection. Here is how this is done:

    // now adding all these parameter fields to the parameter collection
    paramFields.Add(pfItemId);
    paramFields.Add(pfStartDate);
    paramFields.Add(pfEndDate);


    And finally, we pass this collection to the ParameterFieldInfo property of our crystal report viewer object.

    // finally add the parameter collection to the crystal report viewer
    crViewer.ParameterFieldInfo = paramFields;


    We are finished. Build your project and run it. If you have previously added some sale entries in your tables then you can call ManagerDefault.aspx directly to create a report; otherwise first add some records.

    You should see the following output in your browser:



    We can change the look of the report by changing the ViewReport.aspx page. By making some slight variations in the report, like changing chart type by clicking on the report and selecting ChartExpert, we can obtain some different charts.

    More C# Articles
    More By Wrox Team


       · Hello i want to download the code for following topic.Creating Graphical Reports...
       · best one to know the technical details
       · good one for starting..
       · How can i download source of this article..
       · best is to start lowr level to higher level;
     

    C# ARTICLES

    - Introduction to Objects and Classes in C#, P...
    - Visual C#.NET, Part 1: Introduction to Progr...
    - C# - An Introduction
    - Hotmail Exposed: Access Hotmail using C#
    - Razor Sharp C#
    - Introduction to Objects and Classes in C#
    - Making Your Code CLS Compliant
    - Programming with MySQL and .NET Technologies
    - Socket Programming in C# - Part II
    - Socket Programming in C# - Part I
    - Creational Patterns in C#
    - Type Conversions
    - Creating Custom Delegates and Events in C#
    - Inheritance and Polymorphism
    - Understanding Properties in C#






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT