Click here to Skip to main content
Click here to Skip to main content

Dynamic Crystal Reports Viewing

By , 22 Apr 2004
 

Sample Image

Introduction

The code shows how anyone can make a dynamic Crystal Reports application that can easily be distributed to your users.

Background

So many times at google.com, I have noticed that Crystal Reporting is a problem for many users (especially myself). I finally found a quick and easy recipe to handle any type of reporting requirements. In other words, I think this solution works fine by itself and equally fine when integrated into an existing application.

Using the code

Slap the code into your application and create a rpt subdirectory as part of the setup project (under the application folder), then fill with Crystal Reports that have been created using an ODBC connection (do not click Save Data in the Crystal Report). After this, you are "cooking with gas" (ready to go...).

Set the following properties:

Form Properties
===============
Starting Position = Maximized, Center of Screen

Report Viewer Properties
========================
Anchor (Top,Bottom, Left, Right)
Dock (Bottom)

The key parts of this easy application centers on the following routines:

private void Form1_Load(object sender, System.EventArgs e)
{
    //Populate the Combo Box with the report names
    cBxRptList_Fill();
}

private void cBxRptList_Fill()
{
    //Create a temp table to hold the reports description and path
    DataTable cBxContents = new DataTable ();
    cBxContents.Columns.Add ("Description", System.Type.GetType("System.String"));
    cBxContents.Columns.Add ("Path",System.Type.GetType("System.String"));

    //Create the first row of the temp table to tell users what to do
    string[] FirstRow = {" -- select a report to view --", "-1"};
    cBxContents.Rows.Add (FirstRow);

    //Pickup all the crystal reports in the rpts subdirectory of the program
    string[] fileList =  Directory.GetFiles (Directory.GetCurrentDirectory() 
                                                      + @"\rpts", "*.rpt");
    foreach (string item in fileList)
    {
        //add all the friendly report names into the temp table
        int startPt = item.ToString().LastIndexOf(@"\rpts");
        string[] rowData = {item.Substring(startPt + @"\rpts".Length + 1,
        item.ToString ().Length - (startPt + @"\rpts".Length + 1)),item};
        cBxContents.Rows.Add (rowData);
    }

    //assign the temp table to the combo box
    cBxRptList.DataSource = cBxContents;
    cBxRptList.DisplayMember = "Description";
    cBxRptList.ValueMember = "Path";
}

private void cBxRptList_SelectedIndexChanged(object sender, System.EventArgs e)
{
    //identify if the first combo box item is not selected
    switch (cBxRptList.SelectedIndex > 0)
    {
        //if another line in the combo box is selected then view the report 
        case true:
            cRVMain.ReportSource = cBxRptList.SelectedValue ;
            cRVMain.Zoom (25);
            break;

        //if the first line in the combo box is selected then clear the report
        case false:
            cRVMain.ReportSource = null;
            break;
    }

The full listing of code includes the IDE generated code that appears after one drops a ComboBox and a Crystal Report Viewer onto a basic form. Note that I renamed my ComboBox -> cBxRptList and the Crystal Report Viewer -> cRVMain. I also created a DataTable to hold the description and the path information for the reports, called cBxContents.

Points of Interest

When one reopens the form in design mode, the viewer seems to be pulled out of position (reset), I am not sure why (seems like a bug to me).

I learned that rather than putting lots of auxiliary stuff (like miscellaneous folders) into the executable, that one should put all the extras into the setup deliverable. For instance, I put the actual reports into the setup file by adding them under the rpts folder (which is under the Application folder).

History

  • 4/21/04 - Changed the routines to use a friendly list of names rather than just assigning the entire path names to the list of reports.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Tommie Carter
Web Developer
United States United States
Member
Hi all,
 
I am a long-time coder. Since 8th grade with Apple and Commodore Pet! Now, I'm a computer consultant and software developer in new york, ny.
 

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to generate dynamic crystal reports - .NETmembertinh cau4 Jan '07 - 17:02 
Help me!
Thank you very much
QuestionHow to create a Dynamic Crystal Report using C# and MSSQLmembertinh cau4 Jan '07 - 17:01 
Help me!
Thank you very much.
AnswerRe: How to create a Dynamic Crystal Report using C# and MSSQLmemberTommie Carter5 Jul '07 - 8:30 
tinh cau wrote:
Help me!
Thank you very much.

 
The project shows a very simple way to create a dynamic report. Would you care to tell me more about what you need help with?
 
Please tell me Crystal Reports Version and MSSQL version?
 
Do you want to use Visual Studio to make the report?
 
Meditate daily on the vast and the empty. Release attachments.

GeneralMake ApplicationmemberAunalisiraj24 May '05 - 20:39 
i am using crystal report since last 3 month i connect report with stored procedure using ODBC now my query is that i want in apllication formate not using any language is there any option in crystal.i only want show previw Phase not design Phase
AnswerRe: Make ApplicationmemberTommie Carter5 Jul '07 - 8:27 
Aunalisiraj wrote:
i am using crystal report since last 3 month i connect report with stored procedure using ODBC now my query is that i want in apllication formate not using any language is there any option in crystal.i only want show previw Phase not design Phase

 
Hi,
 
I will try to answer your question. If you want to attach a data source to the Crystal Report you can do so in a number of ways. One might create a method that returns a dataset or even build out a typed data class to correspond to the data you wish to disply.
 
I am not sure if thatt is the answer you need. Please re-state your question more fully and supply the Crystal Reports version that you are using. Are you needing to have the report display data in a different human language or are you interested in building a report without an specific programming language dependency?
 

 
Meditate daily on the vast and the empty. Release attachments.

GeneralCrystal Report 9/10 and .NET Remotingmembera_dipendra28 Jan '05 - 4:36 
Hi everyone,
 
On a 3 tiered environment, WinApp will call a method from a remote machine (IIS) which loads Crystal Report document object, processes some calculations, loads datasets. Now this method should throw the report document to WinApp side so that the user can view the result on his/her Crystal Report viewer. There are almost 500 users of this Winapp. The company doesn't want to buy per user CAL for crystal reports. They want to buy per processor (for IIS box) license. The nature of the report is quite complex as the client app has to pass parameters into stored procs, stored procs returns some data. Now I need to compare row by row and column by column to find out what values got changed. And dump that result into a new dataset. Use this dataset for the report document object.
 
Now the question is how is this possible. I tried remoting. HOwever, doesn't look like it can handle the Report Document object and send to Win App.
 
Also tried web services but it is slow and will not let me do the row by row and column by column processing, as my report have 18 sub reports. When designing those reports, I am using generic datasets.
 
How to dynamically feed data into crysal report, avoid the expensive licensing issue plus allow the WinApp client to view the reports.
 
Please help. Very critical.
 

AnswerRe: Crystal Report 9/10 and .NET RemotingmemberTommie Carter5 Jul '07 - 8:20 
a_dipendra wrote:
Hi everyone,
 
On a 3 tiered environment, WinApp will call a method from a remote machine (IIS) which loads Crystal Report document object, processes some calculations, loads datasets. Now this method should throw the report document to WinApp side so that the user can view the result on his/her Crystal Report viewer. There are almost 500 users of this Winapp. The company doesn't want to buy per user CAL for crystal reports. They want to buy per processor (for IIS box) license. The nature of the report is quite complex as the client app has to pass parameters into stored procs, stored procs returns some data. Now I need to compare row by row and column by column to find out what values got changed. And dump that result into a new dataset. Use this dataset for the report document object.
 
Now the question is how is this possible. I tried remoting. HOwever, doesn't look like it can handle the Report Document object and send to Win App.
 
Also tried web services but it is slow and will not let me do the row by row and column by column processing, as my report have 18 sub reports. When designing those reports, I am using generic datasets.
 
How to dynamically feed data into crysal report, avoid the expensive licensing issue plus allow the WinApp client to view the reports.
 
Please help. Very critical.

 

 
The best advice that I can offer in this situation is for you to do the data manipulation and comparison on the database using a stored procedure and then to pass the results to Crystal. In general stored procedures are compiled code that can be executed rather quickly. (going on the premise that the simplest approach will work best)
 
Regarding licensing I guess it depends on which version of the software you are using. A built in version of Crystal that comes bundled with Visual Studio.Net can serve any number of users from a website. I do not think that additional fees apply in this case.
 

 
Meditate daily on the vast and the empty. Release attachments.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 23 Apr 2004
Article Copyright 2004 by Tommie Carter
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid