Pro SQL Server 2012 Reporting Services

(sharon) #1
CHAPTER 7  USING CUSTOM .NET CODE WITH REPORTS

Select the newly created Class1.cs from the solution explorer, and rename it to something a bit
more descriptive, such as Employee, because you will use this class to calculate the cost of a visit provided
by the employees. Open the Employee.cs file in the Visual Studio 2010 IDE, change the namespace from
Employee to Pro_SSRS, and you will see the code editor, as shown in Figure 7-10


.


Figure 7-10. The Visual Studio 200 code editor


For this example, you’ll add a few using statements to import types defined in other namespaces.
Specifically, you’ll add the System.Data and System.Security.Permissions namespaces so you can
reference the DataSet and SecurityAction methods without typing in the full namespace in the Employee
assembly, as shown in Listing 7-3. You can also drop the reference to System.Linq since we will not be
utilizing that in this class library.


Listing 7-3. The EmploYee AssemblY


using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Permissions;
using System.Data;


namespace Pro_SSRS {
public class Employee {
public Employee() { }


[PermissionSetAttribute(SecurityAction.Assert, Unrestricted = true)]
public static decimal CostPerVisitXML(string employeeID, DateTime visitDate)
{
DataSet empDS = new DataSet();
empDS.ReadXmlSchema(@"C:\Temp\EmployeePay.xsd");
empDS.ReadXml(@"C:\Temp\EmployeePay.xml");
DataRow[] empRows = empDS.Tables["EmployeePay"].Select("EmployeeID = '" +
employeeID + "'");
Decimal empAmt;

Free download pdf