AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=598&pId=-1
Sample App: FFAssist Using Crystal .NET for VS 2005 - Part 2
page
by Eric Landes
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 24322/ 144

Setting Up the Application

[download sample app]

For an overview of this sample application, view Part 1 of this series.  This application assumes November CTP Beta 1 of Visual Studio 2005 has been installed.  It is also assumed that you have SQL Server 2000 on your dev machine, and that you are familiar with Crystal .NET.  This sample application is intended to give you an idea how to use the new version of Crystal .NET.  It is not intended as a production type application.

Set Up

To set up the application, download the source files from the link above.  What you'll have is a zip file that includes source files both ASP.NET, partial classes, and the SQL script files. 

Now, in your VS 2005, create a website called FFAssist.  Unzip the files to that directory.  The solution file in there is assuming a directory called c:\Website\FFAssist.  If your directory structure is different, you may need to modify that file.

In the Data directory underneath FFAssist is the SQL script.  These script creates the data and inputs the data, so create a database on your local SQL Server called FFAssistant.  Then open Query Analyzer, open the file CreateFFAssitant.sql.  Run this file, and all the tables will be created, and the stored procedure in the report will be created as well.

The application also assumes that your windows identity has select, insert, delete, update permissions on the tables on this database.  The Web.config of this web application uses the Windows authentication policy.

Explanation of the Player Statistics Report

[download sample app]

The Player Statistics Report (ffasist2.rpt) is based on the stored procedure p_get_ffStatsWithPlayerTeam.  This stored procedure has one parameter, the Player ID, and will display all the statistics for one player.  Actually, as currently configured, it will display the passing statistics for the player, so I currently only have quarterbacks in the report!

To display the report, I placed a Crystal Viewer control on the default.aspx page.  This page, like all pages in the application, is based on the master page FFMain.master.  If I right click the CrystalViewer1 object and then set the report source, the report renders in Visual Studio.  This new feature gives you a preview of your report on the page.  What a welcome addition!

Also included in the content of this page is a drop-down list with the ID of ddlPlayers.  The drop-down list is bound to a SQL DataSource named sqlDSPlayers.  This data source is based on a straight query of all players in the table.

View of Default.aspx in VS 2005 .NET

The Player Statistics report groups the data by player and year and sorts in game number order.  This report also groups and sums by year.  Summing is extremely easy in the designer right now.  Simply Highlight the field you want to sum in the detail area, right click, select insert the summary.  That dialog box allows you to pick the grouping to insert the summary at.  It also allows the you to pick the type of summary you want.  In this instance, I've inserted averages by the year.

Displaying the Report on a Web Page

[download sample app]

Now that we've designed the report we want to display this on a web page.  Displaying the report is similar to the way we did this in .NET.  However I find binding to the viewer programmatically to be easier in this version.  

In this application, the report displays when a Player is selected.  In this case the drop-down list is named DropDownList1.  The code below is what fires when SelectedIndexChanged fires.

void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
 {
  CrystalDecisions.Shared.ParameterDiscreteValue crDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();
  crDiscreteValue.Value = ddlPlayers.SelectedValue;
  CrystalDecisions.Shared.ParameterField crParam = new CrystalDecisions.Shared.ParameterField();
  CrystalDecisions.Shared.ParameterFields crParams = new CrystalDecisions.Shared.ParameterFields();
  CrystalDecisions.Shared.ParameterValues crDefValues = new CrystalDecisions.Shared.ParameterValues();


  crParam.CurrentValues.Add(crDiscreteValue);


  


  CrystalDecisions.CrystalReports.Engine.ReportDocument crFFAssist = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
  crFFAssist.Load(@"C:\WebSites\FFAssistant\FFAssist2.rpt");
  foreach (CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition crParmField in crFFAssist.DataDefinition.ParameterFields)
  {
   crDefValues.Add(crDiscreteValue);
   crParmField.ApplyCurrentValues(crDefValues);


   //  crFFAssist.ParameterFields.Add(crParmField);
  }
  //crFFAssist.ParameterFields.Add(crParams);


  CrystalReportViewer1.ReportSource = crFFAssist;
  CrystalReportViewer1.DataBind();


 }

First a ParameterDiscreteValue is declared, then a ParameterField, then the collections, ParameterFields, and ParamaterValues.  After loading the file, iterate through the parameter field definition collection in the document.  One way to make the iteration work is to name the obects in your page with the same name as the parameter.  Then you can access that control with that parameter name.  I don't do that here, but that's something I will pursue as I add to this sample application.

Finally, bind the report document crFFAssist to the report viewer.  You still set the report source then bind the data.

Disecting the Administration Pages

[download sample app]

Currently, there are a few admin pages for entering data for this sample application.  The pages include AddEditPlayers.aspx, AddEditPositions.aspx, AddEditStats.aspx, and AddEditTeams.aspx.  Here I will cover the basics of how these all come together.

To start learning the new "gee whizz" features of ASP.NET 2.0, I started out by using the SqlDataSource to see how easily I could generate admin screens.  I found that it can be done quickly.

For instance, on AddEditPositions.aspx, everything but Insert is handled through drag and drop and then setting the appropriate properties.  When I created the SqlDataSource for the Positions table, I specify the fields, and the SqlDataSource automatically generates the insert, update, select, and delete statements.

Data Source Wizard

These appear to encapsulate the adapter found in Visual Studio 2002 and 2003 in a one-step data source.  Also, you can configure this to automatically create and use a connection string from your config file, a handy feature.

Using the Gridview control, click on the smart-tag arrow, and select Configure Data Source.  Follow the wizard, selecting the connection information, then specify the fields to select from the table.  Click on the Advanced Options button to set the wizard to automatically generate the insert, update, and delete statements. 

To insert a new position, there are two text boxes for the position name, description, and an Add button.  Below is a sample of the actual code used to insert the data:

SqlDataSource1.InsertParameters["Position"].DefaultValue = txtPosition.Text;
SqlDataSource1.InsertParameters["Description"].DefaultValue = txtDescription.Text;
SqlDataSource1.Insert();

In this case it takes 3 lines to insert a record.  While I don't think my production applications will use this type of approach for everything, for quick admin pages not used by many, this is a quick way to get the functionality.

Summary

[download sample app]

In this, Part 2 of the series, I showed you how we are displaying the first report on a web page.  We also explored new features including the improved Crystal viewer, adding a summary average, and some other features of interest to Crystal .NET programmers.  We went over just a few of the new features that are available in the new version of Crystal .NET.  Programmatically applying parameters and binding a report document to the viewer are similar to the original Crystal .NET.

In the next installment, I'll add a report that binds to a new ASP.NET 2.0 object.  The sample application that this links to includes one simple report that uses a traditional OLE DB connection to a stored procedure on a SQL Server database.  This is intended as a sample to show what's possible with the Crystal .NET shipping with Visual Studio 2005 Beta 1 Refresh.  Happy reporting!



©Copyright 1998-2018 ASPAlliance.com  |  Page Processed at 2018-10-21 8:19:56 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search