Building a backend management system for ASP. mvc4+ef5+easyui+unity2.x injection-MVC using RDL reports

Source: Internet
Author: User

Original: Building a backend management system for ASP. mvc4+ef5+easyui+unity2.x injection-MVC using RDL reports

This time we're going to show MVC3 how to display the RDL report, the pit Dad's Microsoft has upgraded MVC to 5-wood has a good support report, so that MVC in some areas tend to short board

We can only use RDL reports in some way.

The razor view does not support ASP. NET server controls, but ASPX can, so users can actually display RDL reports or Crystal Reports through the ASPX view template.

I'm a compulsive man, I don't like it. In many razor views, the ASPX view stands out from the crowd, so this section mainly demonstrates one of the uses of RDL in MVC.

Reports have similarity data sources-datasets-charts-Table composition

Create a new data source in the MVC project, which will eventually consist of a data table, a TableAdapter, a query, a relationship, and then right-click to view the new data source.

Here we use the TableAdapter to demonstrate, first create a new table

CREATE TABLE [dbo]. [Syssample] (    [Id] [varchar] () not null,    [Name] [varchar] () NULL, [age    ] [  int] null,    [Bir] [datetime] NULL,    [Photo] [varchar] () NULL,    [Note] [text] NULL,    [Createtime] [DateTime] NULL, CONSTRAINT [pk__syssampl__3214ec075aee82b9] PRIMARY KEY CLUSTERED (    [Id] ASC) with (pad_index  = Off, statistics_norecompute  = off, Ignore_dup_key = off, allow_row_locks  = on, allow_page_locks  =  On [PRIMARY]) on [PRIMARY] textimage_on [Primary]go
Syssample

and input some test data

INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES ('1','Zhang San', -,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES (' One','Zhang San', -,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES ('2','John Doe', +,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES (' A','John Doe', +,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES ('3','Harry', -,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES (' -','Harry', -,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES ('4','Liu Liu', -,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES (' -','Liu Liu', -,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES ('5','x VII', $,'1 1991 12:00AM', Null,null,'1 12:00AM'INSERT into [Syssample] ([id],[name],[age],[bir],[photo],[note],[createtime]) VALUES (' -','x VII', $,'1 1991 12:00AM', Null,null,'1 12:00AM')
Test Data

First, create a data source

Second, choose your data link, if you have a direct selection of linked databases can

Third, create a new link, and finally it will generate a node in Web. config

<name= "appdbconnectionstring"  connectionString= "Data source=.;i Nitial catalog=appdb; User Id=sa; [Email protected]#; Multipleactiveresultsets=true; Application Name=entityframework "providerName=" System.Data.SqlClient "/>

Iv. Configuration Wizard

There are many ways for users to choose. I use the SQL statement conveniently here

Enter SELECT * FROM syssample a query statement, followed by a full hook, each tick is clearly written

Data set has been created

V. Creation of RDL

Create a new folder. Dedicated to storing RDL-----> Reports

Create a SYSSAMPLEREPORT.RDLC file under reports

Vi. creating datasets for reports, data sources Select the Appdbdataset data source we just created

Seven, casually add an icon commonly used pie chart and list (honestly said if not understand first right)

All that is said is the basis for creating reports. We were already familiar with the ASP, back to controller

Add the following method (type = Pdf,excel,word)

 PublicActionResult Reporting (stringType ="PDF",stringQuerystr ="",introws =0,intpage =1)        {            //Export All selected            if(Rows = =0&& page = =0) {rows=9999999; Page=1; } Gridpager Pager=NewGridpager () {Rows=rows, page=page, sort="Id", Order="desc"            }; List<SysSampleModel> ds = M_bll. GetList (refPager, QUERYSTR); LocalReport LocalReport=NewLocalReport (); Localreport.reportpath= Server.MapPath ("~/REPORTS/SYSSAMPLEREPORT.RDLC"); ReportDataSource ReportDataSource=NewReportDataSource ("DataSet1", DS);            LOCALREPORT.DATASOURCES.ADD (ReportDataSource); stringReporttype =type; stringMimeType; stringencoding; stringfilenameextension; stringDeviceInfo ="<DeviceInfo>"+"<OutPutFormat>"+ Type +"</OutPutFormat>"+"<PageWidth>11in</PageWidth>"+"<PageHeight>11in</PageHeight>"+"<MarginTop>0.5in</MarginTop>"+"<MarginLeft>1in</MarginLeft>"+"<MarginRight>1in</MarginRight>"+"<MarginBottom>0.5in</MarginBottom>"+"</DeviceInfo>";            Warning[] warnings; string[] streams; byte[] renderedbytes; Renderedbytes=Localreport.render (reporttype, DeviceInfo, outMimeType, outencoding, outFilenameextension, outstreams, outwarnings); returnFile (renderedbytes, MimeType); }

So. It's not as mysterious as the legend, it's output to make reports.

    • List <SysSampleModel> ds assign the read to DS
    • Localreport.reportpath specifying the path to a report
    • ReportDataSource ReportDataSource = new ReportDataSource ("DataSet1", DS); specify DataSet DataSet1

Populating the data set, the last front end is calling the reporting method

In Google Chrome output PDF can be directly in the page preview, if it is other format will get Save dialog pop-up

Right-click to select Print to connect to local printer

Related Article

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.