Fun SSRs Article 6-advanced client reports

Source: Internet
Author: User

The previous article introduced the basic development of client reports. This article describes how to customize development data sources for client reports.

In the previous article, we learned that data sources can be added to reports through dataset. This method is relatively simple through UI operations. In addition, we can provide data sources for client reports in other ways to make data organization more flexible. The following describesCodeTo provide data sources for reports.

Review the third SSRs report, whose dataset structure:

First, add a Class Based on the Asp.net project created in the previous article. The structure of this class is the same as that in the preceding report dataset. Right-click the project name and add-> new item...

Select Code on the left and class on the right to add a class to the project.

Open the created class file and replace all the code in it:

UsingSystem;

UsingSystem. Collections. Generic;

UsingSystem. LINQ;

UsingSystem. Web;

 

NamespaceWebapplication3

{

Public Class Reportitem

{

Public StringProductcategory {Get;Set;}

Public StringShipdate {Get;Set;}

Public DoubleProductstandardcost {Get;Set;}

Public DoubleSalesamount {Get;Set;}

Public DoubleTaxamount {Get;Set;}

}

}

We can see that the definition of this class structure is the same as the dataset structure of the previous SSRs report.

Next, add another class named reporttools to the file to expose public methods to provide data for client reports.

Public Class Reporttools

{

Public List<Reportitem> Getreport (StringYear)

{

List<Reportitem> Result =New List<Reportitem> ();

 

SqlconnectionConn =New Sqlconnection(System. configuration.Configurationmanager. Connectionstrings ["Adventureworksdw2012connectionstring"]. Connectionstring );

Conn. open ();

 

StringbuilderSB =New Stringbuilder();

SB. appendline ("Select st. englishproductsubcategoryname as productcategory");

SB. appendline (", Left ([shipdatekey], 6) as [shipdate]");

SB. appendline (", Sum ([productstandardcost]) as [productstandardcost]");

SB. appendline (", Sum ([salesamount]) as salesamount");

SB. appendline (", Sum ([taxamt]) as [taxamt]");

SB. appendline ("From [adventureworksdw2012]. [DBO]. [factinternetsales] F");

SB. appendline ("Left join [DBO]. [dimproduct] P on F. productkey = P. productkey");

SB. appendline ("Left join [DBO]. [dimproductsubcategory] st on p. [productsubcategorykey] = ST. [productsubcategorykey]");

SB. appendline ("Where left ([shipdatekey], 4) ="+ Year );

SB. appendline ("Group by St. englishproductsubcategoryname, left ([shipdatekey], 6 )");

 

SqlcommandComm =New Sqlcommand(Sb. tostring (), Conn );

 

SqldatareaderDr = comm. executereader ();

 

While(Dr. Read ())

{

ReportitemRi =New Reportitem();

Ri. productcategory = Dr [0]. tostring ();

Ri. shipdate = Dr [1]. tostring ();

Ri. productstandardcost =Convert. Todouble (Dr [2]);

Ri. salesamount =Convert. Todouble (Dr [3]);

Ri. taxamount =Convert. Todouble (Dr [4]);

 

Result. Add (RI );

}

 

Dr. Close ();

Conn. Close ();

 

ReturnResult;

}

}

This code mainly refers to the installation of SQL statement results into the list collection class.

After adding a data source to a client report, compile the project so that the client report tool can detect the newly created data structure.

Then, add another client report.

Add a dataset to the report:

On the dataset properties page, select the project name for the data source, and then select reporttools (getreport) in available datasets ).

We can see that the detected data structure is the same as that in SSRS.

Next, refer to the Method Design Report in article 3.

Next, we will create an Asp.net page for this report, add the scriptmanager control and reportviewer control to it, and select this newly created report.

Then, the system automatically generates an objectdatasource Control for it.

Add a dropdownlist control to the page.

Click the right arrow of the dropdownlist control and click Edit items...

Manually add some values to the control.

Click OK to close the listitem editor and return to the design page.

Select the dropdownlist control and modify the autopostback attribute to true in the property list.

After setting the dropdownlist control, click the right arrow of objectdatasource and select configure data source...

On the data source configuration page, click Next.

You can see that the system detects the configuration method in the report and click Next.

Because the method specifies a parameter for the report data source, you need to specify how to pass the parameter to the data source.

Select Control in the parameter source, that is, the value of the specified parameter is passed in through the value of the control. Specify the added dropdownlist control in controlid.

Click Finish to complete the data source control configuration.

Finally, return to the source view on the ASPX page, change the reportpath property of the reportviewer control, and remove the default report property:

Next, set the newly created Asp.net page to the start page, and click F5 to run.

The result is the same as that of the SSRs Server Report.

Based on the introduction of client reports in the last two articles, I believe you have an understanding of client reports. To some extent, client reports are indeed a good solution if you do not want to deploy or maintain a report service separately. In addition, with the help of coding, data generation is relatively more casual, for example, loading data from the analysis service to the client report, you can also refer to my previous article:

Http://www.cnblogs.com/aspnetx/archive/2012/06/20/2556916.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.