integrate reporting services with silver light and ria services

Upload: jsoques

Post on 10-Apr-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    1/17

    First Posted 28 Jul 2010

    Views 5,081

    Bookmarked 27 t imes

    Licence CPOL

    ASP.NET, Windows, Dev, WC F,

    Intermediate, Silverlight,C#4.0

    Web Development Silverlight HowTo

    Integrate Reporting Services w ithSilverlight and RIA ServicesBy Ernesto Herrera | 28 Jul 2010

    Integrate Reporting Services with your Silverlight Line-of-

    Business applications.

    Download source - 801 KB

    Introduction

    One of the most wanted future features in Silverlight is the possibility to create business reports using

    Reporting Services. In this article, I will show how to use the existing Reporting Services technology

    with Silverlight and RIA Services combination.

    Background

    I assume that the reader has some basic to intermediate level knowledge in Silverlight and RIA Service

    and C#, also some knowledge about WCF and the Entity Framework.

    Using the CodeThe first thing to do is create a Silverlight Application in Visual Studio 2010. I used the Silverlight

    Business Application template.

    4.88 / 5, 8 vote

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 1/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    2/17

    In the ASP.NET project, I added an Entity Framework Model.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 2/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    3/17

    In this demo, I'm using the AdventureWorksLT database.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 3/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    4/17

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 4/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    5/17

    These are the entities we will use in this demo:

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 5/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    6/17

    Build the project and add a Domain Service Class:

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 6/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    7/17

    Here are all the entities selected to be added to the domain service:

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 7/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    8/17

    Now we can add a new Report. In this case, we are using Reporting Services in Local mode.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 8/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    9/17

    In the report, when a Tablix component is added, a dataset is requested. In this case, the Choose the

    Dataset Wizard sees the domain context that we added before.

    For this demo, I created a new class that I will use to bind to the report. There are cases in which tha

    is preferable to do because we may need to do some extra processing before the data can be bound t

    the report:

    using System;

    using System.Collections.Generic;

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 9/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    10/17

    using System.Linq;

    using System.Web;

    using System.ComponentModel.DataAnnotations;

    namespace ReportingServicesDemo.Web

    {

    publicclass Orders

    {

    public Orders()

    { }

    [Key]

    publicint OrderDetailsID

    {

    get;

    set;

    }

    publicint OrderID

    {

    get;

    set;

    }

    publicstring Product

    {

    get;

    set;

    }

    publicint Quantity

    { get;

    set;

    }

    publicdecimal UnitPrice

    {

    get;

    set;

    }

    publicdecimal UnitPriceDiscount

    {

    get;

    set;

    }

    publicdecimal LineTotal

    {

    get;

    set;

    }

    }

    }

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 10/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    11/17

    In this class, I made a reference to the System.ComponentModel.DataAnnotations namespace

    that allows me to add a Key attributte to the OrderDetailsID property - that is a requirement for

    the class so the domain service can recognize it as an entity.

    If we dive into the domain service code, we find this:

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;using System.ComponentModel.DataAnnotations;

    using System.Data;

    using System.Linq;

    using System.ServiceModel.DomainServices.EntityFramework;

    using System.ServiceModel.DomainServices.Hosting;

    using System.ServiceModel.DomainServices.Server;

    //// Implements application logic using the AdventureWorksLT2008Entities context.

    //// TODO: Add your application logic to these methods or in additional methods.

    //// TODO: Wire up authentication (Windows/ASP.NET Forms)

    /// and uncomment the following to disable anonymous access

    //// Also consider adding roles to restrict access as appropriate.

    // [RequiresAuthentication]

    [EnableClientAccess()]

    publicclass ADWLTDomainService :

    LinqToEntitiesDomainService

    {

    Now I create a domain operation that exposes the Orders entity I just created in my custom class:

    public IQueryable GetOrderDetails(int OrderID)

    {

    AdventureWorksLT2008Entities adw = new AdventureWorksLT2008Entities();

    var query = from c in adw.SalesOrderDetail.Include("Product")

    where

    c.SalesOrderID == OrderID

    select new Orders { OrderID = OrderID,

    OrderDetailsID = c.SalesOrderDetailID, Product = c.Product.Name,

    Quantity = c.OrderQty, UnitPrice =

    c.UnitPrice, UnitPriceDiscount = c.UnitPriceDiscount,

    LineTotal = c.LineTotal };

    return query;

    }

    Here are some remarks. In this method, I'm using the Entity Framework context instead of the object

    context that the domain service declares, and exposing like the other select methods as IQueryable

    If we build the project again, the "Choose the DataSet Wizard" sees our custom method and all the

    fields exposed by the entity ready for our report.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 11/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    12/17

    Here is the report design together with the dataset available:

    Now we add a WebForm to the web project in order to place the report using theReportViewer

    control:

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 12/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    13/17

    When we add the ReportViewer control, it creates an ObjectDataSource control.

    Looking at the ObjectDataSource's properties, we can see the Select property of our custom

    method.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 13/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    14/17

    Looking at the SelectParameters collection, we see our custom method parameter.

    Now in the Silverlight project, we add a DataGrid bound to the Sales Orders entity.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 14/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    15/17

    Each field in the Sales Order ID column is represented as a button just for this demo in order to pass

    the content value as a parameter on the click event. The idea is to call a popup window using theHtmlPage object, with HtmlPopup options from the System.Windows.Browser namespace.

    HtmlPopupWindowOptions options = new HtmlPopupWindowOptions();options.Left = 0;

    options.Top = 0;

    options.Width = 930;

    options.Height = 800;

    options.Menubar = false;

    options.Toolbar = false;

    options.Directories = false;

    options.Status = false;

    Button btn = sender as Button;

    int OrderID =int.Parse(btn.Content.ToString());

    string address = Application.Current.Host.Source.AbsoluteUri;

    int i = address.IndexOf("/ClientBin/", 1);

    string url = address.Substring(0, i);

    url = url + "/RpDemoWebForm.aspx?OrderID=" + OrderID;

    if (true == HtmlPage.IsPopupWindowAllowed)

    HtmlPage.PopupWindow(new Uri(url), "new", options);

    We can obtain the current web address were the Silverlight XAP application is running, using theApplication.Current.Host.Source.AbsoluteUri property. Later, we can create the URI

    associated with the ReportViewer's Web Form.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 15/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    16/17

    Finally, we can see our Order Details report.

    Points o f Interest

    I hope this article can be helpful while we wait for the next Silverlight releases, and also can explore

    more options in business reporting.

    History

    07-26-2010: Submitted to CodeProject.

    License

    This article, along with any associated source code and files, is licensed under The Code Project Open

    License (CPOL)

    About the Author

    Ernesto Herrera

    Web Developer

    Sigo S.A.

    Venezuela

    Member

    Ernesto Herrera is a Senior Developer, Architect with more than 12 years

    experience, actually working with Silverlight Line-of-Bussiness Applications, h

    holds a MCTS Web Application 2.0 Certification, and have a wide experience

    with sql server since the 6.5 version, on his free time he likes to play tennis

    with his wife,kids and friends, also enjoy playing Wii with his sons, he works a

    Sigo S.A., a retail business located at Margarita Island, Venezuela.

    9/20/2010 Integrate Reporting Services with Silverli

    codeproject.com/KB//SLReporting.asp 16/

  • 8/8/2019 Integrate Reporting Services With Silver Light and RIA Services

    17/17