Creating a DotNetNuke Private Assembly with Crystal Reports - Part 3
Published: 06 Jan 2006
Unedited - Community Contributed
In this 3rd of a four-part series, Eric shows how to display the Crystal parameters dynamically in a private assembly for DNN.
by Eric Landes
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 22698/ 71


As mentioned in Part 1 of this series, DotNetNuke is a great Open Source Portal tool that many in the ASP.NET world use.  Please refer to Part 1 for more information about DotNetNuke.  In Part 2, we explored the DNN Data Access architecture for our application.  Then, we created our own DAL and BLL based on the DNN architecture.  Finally, we created the administrative interface to allow users to add and edit where reports are located.  The data entered from this interface is used in this part of the series in helping to display a report’s parameters.

In Part 3, we will utilize a helper class (based on a previous article of mine) to display reports that have been stored via the Report Manager app.  Then, the application will display the parameters for a report and display the report.  Part 3 specifically details how to display the parameters of a crystal report. 

System Requirements

I created this project using Visual Studio 2003, DotNetNuke 3.1.1, SQL Server 2000, Crystal Reports 10, and Windows XP SP2.

Displaying a Listing of Stored Reports

Download Source

Non-administrative users first see a listing of the reports available on this portal.  Using a datagrid, users see a link button and the display name of the report.  The display name shows a user friendly name (from the field ReportDispName).  We store the actual file system report name in the field ReportName.

To display this list, we use the objects created earlier in the DAL and BLL layers.  In the project source code under desktopmodules, the folder called CrystalReportManager has our project in it.  The Web User Control ReportsViewer.ascx contains the listing of reports and the viewer.  In the Page_Load event of the control, a datagrid (dg_ReportsList) is instantiated with a listing of all reports for this Portal Id.  See Code Listing 1 for the code used to call the listing of reports.

Code Listing 1

if (!IsPostBack)
    PortalSettings oPortal = new
oReportConroller = new ReportsController();

  catch(Exception ex)
    lblError.Text= ex.Message;

Using DotNetNuke's custom Portal Settings objects, we can get the current Portal ID to pass to the GetReports method.  Then, we bind the data from the BLL oReportController to the datagrid, in this instance named dg_ReportsList.

Report Manager Crystal Custom Objects Architecture

Before detailing the code used to display the parameters for a particular report, let’s go over the architecture of the classes used.  The Crystal assemblies are encapsulated within new assemblies that add functionality.  The new classes do not extend Crystal assemblies using inheritance, but rather by referencing the Crystal objects when needed. 

The reasoning for this includes the fact that some of Crystal contains COM components.  I have found that wrapping these objects into my own assemblies helps with certain problems associated with third party software.  Specifically there have been problems with nUnit and Crystal assemblies that have been solved by using separate assemblies to call Crystal.

For these reasons, our source code now contains a class CRParameterPanel.  This class is a refinement of an earlier article that did some of these same functions.  Instead of doing all the panel building activity within the page, this class inherits a panel from the class System.Web.UI.Webcontrols.  We’ll add the parameter input controls to the panel.  Also, in Part 4, the panel is where the report viewer will display.

Currently for purposes of this article, these classes are contained in the project Lancor.CrystalReportManager.  Best practice dictates that these classes should be in their own project, separated from the UI.  Perhaps this will happen for a future version of this. 

Displaying the Parameters

To display these parameters, we need to instantiate CRParameterPanel and call the method that dynamically creates the controls for each of the parameters.  These controls will hold user input values, then allow the users to view the report based on those parameters.   

The user clicks a select button column on the datagrid with the Text “View.”  This calls the code in Code Listing 2 (from event dg_ReportsList_SelectedIndexChanged) to return the parameters.

Code Listing 2

oPanelClass = new Lancor.CrystalReportManager.CRParameterPanel();

As stated earlier, CRParameterPanel gets instantiated as oPanelClass.  Later, this Panel control gets added to ReportPanel.  This panel control is a container on the user control specifically for displaying the parameters.

The method CreateparamsPanel adds the appropriate controls to the panel for user entry.  This method is based on some code from a previous article, “Automagically Display Crystal Parameters.”  This method assumes that a parameter has Prompting text that is used as a label on the web page. 

This method first checks the Crystal SummaryInfo.Title Property from the Crystal ReportDocument object, and adds that as the title of the report.  We use a label and that label control gets added to the Panel object (oPanelClass).  Once we add the title, then we iterate through the ParameterFields collection in the ReportDocument.DataDefinition.  The object oReport in our code is the instantiation of the ReportDocument.  See Code Listing 3 for a snippet of the code. 

Code Listing 3

crTitle = oReport.SummaryInfo.ReportTitle; 
System.Web.UI.WebControls.Label headingLabel = new
foreach (CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition
oCRParam in oReport.DataDefinition.ParameterFields) 
  System.Web.UI.WebControls.Label lblNew = new
  lblNew.ID="lbl" +
oCRParam.ParameterFieldName.Trim() + System.Convert.ToString(controlNum).Trim();

We create a label control with the Prompt from the parameter.  Then in further code, we determine the data type of the parameter.  Depending on the data type, we then use custom methods to create a server control which is added to the Panel control after the label. 

Once all the parameters have been iterated through, we will set the View report buttons visible property to true.  This button contains a click event to display the report in the panel.  We will cover that part of the application in Part 4, the final part of this series.


This part of the series went through how we dynamically create the parameters for a Crystal report in our DNN module.  I believe there is a lot of potential for an application like this, and hope to extend it even more once the series is over.  I will expound more on how this might get done in the last part of our series.  Hopefully this series helps when you are trying to integrate with DotNetNuke or any other framework.   Happy Coding!


User Comments

Title: Wrong Source code   
Name: Jesse
Date: 2006-02-07 10:41:45 AM
The source code available here contains no more that a buggy DNN module with only a single form to store a list of files, but nothing about displaying the reports. Wrong version/ manipulation?

Product Spotlight
Product Spotlight 

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2021  |  Page Processed at 2021-03-05 9:12:34 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search