Create a Crystal Reports Template with an ADO.NET (XML) Connection to a Dataset and DLL
Note: This activity describes using Visual Studio 2005 with the Crystal Reports application. Activity steps may vary with later versions of these applications. This activity does not explain the installation, configuration or in-depth information for Microsoft Visual Studio, Crystal Reports or Microsoft SQL Server. See your network administrator for installation and configuration information.
Create a Windows Application project
- Either double-click the Microsoft Visual Studio icon on the desktop, or select Start » All Programs » Microsoft Visual Studio 2005 » Microsoft Visual Studio 2005.
The Visual Studio .NET 2005 application opens.
- In Microsoft Visual Studio, select File » New » Project from the main menu.
A new Windows Application project opens.
- Select the Visual C# » Window project type from the project types list.
- Select Windows Application from the templates list.
- Enter the Name.
- Enter the Location.
- Check Create directory for solution.
- Click OK.
The Windows Application form opens.
Create the DataSet XSD file
Note: When setting the data source for a report template in Crystal Reports, a data source type of ADO.NET (XML) must be used. To generate a data source that is compliant with this type, an .XSD (XML Schema) file needs to be created. This can be done manually, for example by using Notepad, or automatically in Visual Studio.NET or in XMLSpy.
- Right click the Windows Application Project and select Add » New Item » DataSet from the menu.
- Click Add.
This step opens a design page to design the dataset.
- Right-click the design page and add the columns required for the report.
- Click Save.
Create the Crystal Reports Template File
- Right click the Windows Application Project and select Add » New Item » Crystal Report from the menu.
- Click Add.
This step creates a Crystal Reports project and opens the Visual Studio 2005 Form Design Screen, displaying the Crystal Reports Gallery form.
- Select As a Blank Report from the Crystal Reports Gallery form.
- Click OK.
This step creates and opens a blank report template, and either opens the blank Crystal Reports template or opens the Data Expert form.
- If the Data Expert form is not opened, right-click Database Fields in the Fields Explorer field group and select Database Expert from the menu.
- Expand the Create New Connection node.
- Expand the ADO.NET (XML) node.
This opens the ADO.NET (XML) form.
- Double-click Make New Connection.
- Click the ellipsis (...) next to the File Path.
- Locate and select the XSD file created in the previous steps.
- Click Open.
- Click Finish.
This step closes the ADO.NET form and returns control to the Database Export form. A new XSDSchema connection with the same name as the .XSD file displays.
- Locate and select the newly added dataset in the Available Data Sources field group.
- Click > to move it to the Selected Tables field group.
- Repeat adding datasets as required for the report.
- Click OK.
When more than one dataset is added to the report template, the Links tab displays.
- Select the Links tab.
- Expand the form if all datasets are not visible, and ensure that no datasets are hiding behind other datasets.
- Enter the links to relate the datasets to each other.
- Click Auto-Arrange to rearrange the datasets and links in a logical order.
- Click OK.
This step closes the Database Expert form and returns control to the Report Template form.
- Expand the Database Fields node in the Field Explorer field group.
- Build the report by dragging fields onto the Report Template form.
- Click Save.
Note: Save the report template to the Report Template folder, ensuring that the name is unique.
- Exit the Crystal Reports application.
Build a Component to Facilitate Data Access
- In Microsoft Visual Studio, select File » New » Project from the main menu.
A new Windows Application project opens.
- Select the Visual C# » Window project type from the project types list.
- Select Class Library from the templates list.
- Enter the Name.
- Enter the Location.
- Check Create directory for solution.
- Click OK.
This step creates a Class Library project and opens the Class Library form. The following code stub displays.
Copyusing System;
using System.Collections.Generic;
using System.Text;
namespace ClassLibrary3
{
public class Class1
{
}
} - Add the BulkTrak.Component.dll and cdal.dll references to the project.
- Update the code stub with the following code.Copy
using System;
using System.Data;
using Mincom.MineMarket.DAL;
using Mincom.MineMarket;
using System.Collections.Generic;
using System.Collections;
namespace ClassLibrary3
{
public class StockpileDemo3Class : Mincom.MineMarket.IBTReportTableHandler
{
public StockpileDemo3Class()
{
}
/// <summary>
/// RunTable populates DataTable which is used to populate report table
/// </summary>
/// <param name="connections"> a list of connections to use for the script</param>
/// <param name="parameterValues"> a list of parameters and values</param>
/// <returns>=DataTable which contains all required data</returns>
public DataTable RunTable(BTReportConnectionList connections, Dictionary<BTReportParameter, object> parameterValues)
{
DataTable table1 = new DataTable("DataTable1");
table1.Columns.Add("Stockpile", typeof(string));
table1.Columns.Add("Location", typeof(string));
table1.Columns.Add("Tonnes", typeof(double));
ArrayList stockpiles = GenericObjectFactory.GetFactory(typeof(BaseStockpile)).GetByCriteria();
foreach (BaseStockpile stockpile in stockpiles)
{
Criteria crit = new Criteria(typeof(BaseStockpileState), "StockpileID", QueryOperator.Equal, stockpile.ID);
ArrayList stockpilestates = GenericObjectFactory.GetFactory(typeof(BaseStockpileState)).GetByCriteria(crit);
for each (BaseStockpileState stockpilestate in stockpilestates)
{
table1.Rows.Add(stockpile.Name, stockpile.Location, stockpilestate.Tonnes);
}
}
return table1;
}
}
} - Save Class1.cs and do a build.
- If using the Microsoft Visual Studio application, exit it.
Copy the RPT, XSD, CS and DLL Files to the MineMarket Report Folder
- Copy the report template RPT file, the dataset XSD file, the Visual C#.NET source CS file, and the built DLL to the folder defined by the ReportTemplatePath setting under the Reports group in the MineMarket Service Config program.