日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

MVC使用RDL报表

發布時間:2023/12/13 综合教程 27 生活家
生活随笔 收集整理的這篇文章主要介紹了 MVC使用RDL报表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MVC使用RDL報表

這次我們來演示MVC3怎么顯示RDL報表,坑爹的微軟把MVC升級到5都木有良好的支持報表,讓MVC在某些領域趨于短板

我們只能通過一些方式來使用rdl報表。

Razor視圖不支持asp.net服務器控件,但是aspx可以,所以用戶其實可以通過aspx視圖模版來顯示rdl報表或者水晶報表。

我是有強迫癥的人,我不喜歡在眾多razor視圖中,讓aspx視圖鶴立雞群,所以這節主要是演示rdl在MVC中其中一種用法。

報表都有相似性 數據源-數據集-圖表-表組成

在MVC項目中新建一個數據源,這個數據源最后將由數據表、TableAdapter、查詢、關系組成,新建后可以點擊右鍵查看。

這里我們用到TableAdapter來演示,首先新建一張表

SysSample

并錄入一些測試數據

Test Data

一、創建數據源

二、選擇您的數據鏈接,如果你有鏈接數據庫的直接選擇即可

三、新建一個鏈接,最后它會在web.config生成一個節點

<add name="AppDBConnectionString" connectionString="Data Source=.;Initial Catalog=AppDB;User ID=sa;Password=zhaoyun123!@#;MultipleActiveResultSets=True;Application Name=EntityFramework"
providerName="System.Data.SqlClient" />

四、配置向導

有多種方式供用戶選擇。我這里方便的使用了sql語句

輸入select * from SysSample一條查詢語句,接下來全勾上,每個勾都寫得很清楚

數據集已經創建完畢

五、創建RDL

新建一個文件夾。專門來存放rdl -----> Reports

在Reports下創建SysSampleReport.rdlc文件

六、為報表創建數據集,數據源選擇我們剛剛創建的AppDBDataSet數據源

七、隨便添加一個圖標常用的餅圖和列表(老實說過如果不懂先右鍵)

上面說的都是創建報表的基礎。我們早在asp.net頁面已經熟悉了,回到Controller

添加以下方法(type = PDF,Excel,Word )

public ActionResult Reporting(string type = "PDF", string queryStr = "", int rows = 0, int page = 1)
        {
            //選擇了導出全部
            if (rows == 0 && page == 0)
            {
                rows = 9999999;
                page = 1;
            }
            GridPager pager = new GridPager()
            {
                rows = rows,
                page = page,
                sort="Id",
                order="desc"
            };
            List<SysSampleModel> ds = m_BLL.GetList(ref pager, queryStr);
            LocalReport localReport = new LocalReport();
            localReport.ReportPath = Server.MapPath("~/Reports/SysSampleReport.rdlc");
            ReportDataSource reportDataSource = new ReportDataSource("DataSet1", ds);
            localReport.DataSources.Add(reportDataSource);
            string reportType = type;
            string mimeType;
            string encoding;
            string fileNameExtension;

            string deviceInfo =
                "<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,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings
                );
            return File(renderedBytes, mimeType);
        }

所以呢。沒有傳說的那么神秘,靠輸出來制作報表

List<SysSampleModel> ds把讀取到的列表賦予給ds
localReport.ReportPath指定報表的路徑
ReportDataSource reportDataSource = new ReportDataSource("DataSet1", ds);指定數據集 DataSet1

填充好數據集,最后的前端就是調用 Reporting這個方法

在谷歌瀏覽器輸出PDF可以直接在網頁預覽,如果是其他格式將獲得保存對話框彈出

右鍵選擇打印可以接本地打印機

總結

以上是生活随笔為你收集整理的MVC使用RDL报表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。