Crystal Reports for Visual Studio 2005 in CSharp - Exercise 2: Creating a Custom Stock Market Information (Page 2 of 5 ) Scenario In this exercise, you will create a custom class to hold stock market information. This class will be used to populate an Object Collection. Tasks Detailed Steps Adding a class to your Website.
In Solution Explorer, right-click the web site name that is in bold type and then click Add New Item.
The Add New Item dialog box appears.
In the Visual Studio Installed Templates field, select Class
In the Name field, type Stock, and then click Add.
In the dialog box that appears, click Yes.
In Visual Studio 2005, all classes must be placed inside of an App Code folder if they are to be generally consumable. When you click the Add button, an alert box will ask you if you would like to place your class inside of this App_Code folder.
The Stock class must be set to public scope to be accessed when you create the report. Verify that the class you have created is public. If not, add the public modifier to the class signature to expose the class to the embedded Crystal Report Designer.
public class Stock { public Stock() { } }
Within the class, add three private fields.
private string _symbol; private double _price; private int _volume;
Next, you will add three public read/write properties to encapsulate the three private fields.
Create a new property named Symbol.
public string Symbol { get { return _symbol; } set { _symbol = value; } }
Create a new property named Price.
public double Price { get { return _price; } set { _price = value; } }
Create a new property named Volume.
public int Volume { get { return _volume; } set { _volume = value; } }
Finally, create a new constructor that takes the three public properties as arguments.
public Stock (String symbol, int volume, double price) { _symbol = symbol; _volume = volume; _price = price; }
From the Build menu, click Build Website.
If you have any build errors, fix them now.
You are now ready to access this object from the embedded Crystal Report Designer.
Exercise 3: Creating a Crystal Report Scenario In this exercise, you create a new Crystal report in the embedded Crystal Report Designer and then bind this report to the Stock object. Tasks Detailed Steps Create a Crystal Report.
Right-click the web site name and click Add New Item.
In the Add New Item dialog box, select Crystal Report.
In the Name field, enter StockObjects.rpt, and then click Add.
In the Crystal Reports Gallery dialog box, click OK.
In the Standard Report Creation Wizard dialog box, expand Project Data and the sub node .NET Objects.
A list of classes within the project appears.
Expand the Stock class to view a selectable sub node.
Click the right-arrow > to move the Stock class sub node to the Selected Tables panel.
Click Next.
Expand Stock and click the >> to move all columns to the Fields to Display panel.
Click Next.
Select Symbol and click the right-arrow > to move it into the Group By panel.
Click Finish.
 | Take Microsoft software for a test drive. With MSDN Virtual Labs, you get full access to all available Microsoft products through 90-minute modules, each with its own downloadable manual. Try this lab out now. |
Next: Exercise 4: Bind your Crystal Report to the Crystal Report Viewer >>
More C# Articles More By MSDN Virtual Labs |