Getting Started: Using Business Objects as Data Source

Attachment

Download the sample application: ClientDataSource.zip

Introduction

The purpose of the user manual is to demonstrate main points of using SharpShooter Reports.Silverlight, provide necessary knowledge to get started with the component. You will get step by step recommendations on how to create a web application using SharpShooter Reports.Silverlight. You’ll see how to create and configure a service, design a report using business objects as data source and, at last, how to integrate a report viewer into the application pages.

Product Prerequisite

In order to get the sample working the following software should be installed on your computer:

  • MS Visual Studio 2010
  • .NET Framework 3.5 
  • ASP.NET 2.0 
  • Silverlight 4.0 
  • Microsoft Silverlight 4 Toolkit 
  • Report Sharp-Shooter for Silverlight 4.3.0.0 or higher or SharpShooter Reports.Silverlight 6.0

Creating Sample Application

Step 1

Create a new Silverlight Application project named “ClientDataSource”.

While creation of the project check option “Host the Silverlight application in a new Web site” and set name of the web-project to “ClientDataSource.Web”.

After that VS will create a new solution containing two projects.

Step 2

Set the web application to use static port 5555.

Open ClientDataSource.Web properties (right-click on the “ClientDataSource.Web” node in the solution explorer and choose “Properties”).

Check option “Specific port” and set it to “5555” in the “Web” tab of the ClientDataSource.Web properties.

Step 3

Adding and setting up WCF-service.

In order to make client interact with the server, we need a special service. Before you create this service you need to add reference to PerpetuumSoft.Reporting.Silverlight.Server.dll by right-clicking “Referеnсes” node at ClientDataSource.Web project and choosing “Add Reference” in the popup menu.

Add Report Service Over HTTP named “ReportService.svc” to the ClientDataSource.Web project.

In order to do that, right-click “ClientDataSource.Web” and choose “Add->New Item” in the popup menu.

Add Report Service Over HTTP template to your project.

ReportService class will extend the PerpetuumSoft.Reporting.Silverlight.Server.ReportServiceBase class containing implementation of wcf-service for Silverlight ReportViewer.

Step 4

Creating report template.

Open service in the designer. In order to do that right-click "ReportService.svc.cs" and choose "View Designer" in the popup menu.

Add the ReportManager component (double click on “ReportManager” in ToolBox); this component is responsible for report generation.

To view source code right-click on designer area and click “View Code” item in contextual menu.

Set the ReportManager property of the ReportService service. In order to do that, open ReportService properties in the "Properties" window.

Select reportManager1 from the list:

Create the classes: UserData to store information on a single User and UserDataCollection to store collection of UserData elements.

        public class UserData 
        {
            public UserData() { }
            public string Login { get; set; }
            public string UserName { get; set; }
        }

        public class UserDataCollection : List<UserData>
        { }

Overriding OnLoadData method of the ReportService class:

  1. Initialize the collection for data storage.
  2. Add data to the collection.
  3. Add data to the DataSources collection of the ReportManager as UserDataSource.

Now you should create the report.

Run Report Manager Editor by right-clicking “reportManager1” and choosing “Run Editor”

In the “Reports” tab add a new object – “InlineReportSlot” by clicking the “Add” button.

Set the ReportName property value to UserData. Afterwards you will get the required document from the Report Manager exactly by that name. Then press the “Run Designer” button to launch report designer.

Select the "File->New" menu item, and the form shown on the screen below will appear.

Select “Blank Report” in the list under the “New” tab and press “OK”.

Create report template.

Set DataBand.DataSource property to “UserDataSource”.

Set bindings textBox1.Value to “GetData("UserDataSource.Login")” and textBox2.Value to “GetData("UserDataSource.UserName")”.

Report template should look like this:

Now you should save template and close designer.

Step 5

Adding and setting up Silverlight ReportViewer component.

It’s necessary to add report viewer component to the Silverlight application for the report display. In order to do that, you should add a reference to the PerpetuumSoft.Reporting.Silverlight.Client assembly, containing ReportViewer (right-click “References” of the “ClientDataSource” in Solution Explorer and choose “Add Reference” item in the popup menu).

You should also add a reference to the System.Windows.Controls.Toolkit.dll assembly.

Open MainPage.xaml in the designer and add “rss” xml namespace for the PerpetuumSoft.Reporting.Silverlight.Client assembly.

Then add ReportViewer element to the Grid Section.

        <rss:ReportViewer x:Name="ReportViewer1"
             ServiceUrl="http://localhost:5555/ReportService.svc"
             ReportName="UserData"/>

After you made changes the UserControl section should look like this:

<UserControl x:Class="SilverlightApplication.MainPage"
    xmlns=
    "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc=
    "http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:rss=
    "clr-namespace:PerpetuumSoft.Reporting.Silverlight.Client;
    assembly=PerpetuumSoft.Reporting.Silverlight.Client"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    
    <Grid x:Name="LayoutRoot" Background="White">
    <rss:ReportViewer x:Name="ReportViewer1" ReportName="UserData" 
     ServiceUrl="http://localhost:5555/ReportService.svc"/>
    </Grid>
</UserControl>

Open MainPage source code and change/add the lines for code to look like this:

    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            ReportViewer1.RenderDocument();
        }
    }

Note: RenderDocument() invocation leads to the rendering of the current report on the server and its displaying in the Report Viewer.

Step 6

Launching application.

Set the ClientDataSource.Web application as a StartUp. In order to do that, right-click “ClientDataSource.Web” and choose “Set as StartUp Project” in the popup menu.

Launch application by clicking the “Start Debugging” button on the main Visual Studio toolbar.

For more information on using business objects please refer to the following article or to the orignal SharpShooter Reports Documentation.

Add Feedback