天天看点

RDLC报表的开发

         求上上,而得其上;求其上,而得其中;求其中,而得其下;求其下,而得其下下。这句话真的很有道理,当你站在某一个高度,去学习某一个东西时,学到的东西是不尽相同的。努力争取做的更好...... 

          嘿嘿,把前段时间做的报表,写成笔记,方便日后。

         报表的制作在管理系统里应该是很常见。对于常见的东西,应该做的更好。不废话了,下面就是开发报表的流程。

         1.在更目录下新建一个Reports文件夹,如图:

RDLC报表的开发

2.创建DataSet1数据源

RDLC报表的开发

 3.创建DataTable

RDLC报表的开发

 4.添加DataTabl的列

RDLC报表的开发

 5.创建和设计RDLC报表

RDLC报表的开发

 6.创建Control

/// <summary>
        /// 调拨入账凭证打印
        /// </summary>
        /// <param name="mGUID"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        public ActionResult DY(string mGUID,string str)
        {
            try
            {
                LocalReport localReport = new LocalReport();
                localReport.ReportPath = Server.MapPath("~/Reports/DBRZPZDY.rdlc");//报表样式路径
                ReportDataSource reportDataSource = new ReportDataSource("DataSet1", ef.MVC_DBRZPZ_DY(mGUID, str));//报表数据源
                localReport.DataSources.Add(reportDataSource);
                string reportType = "PDF";//类型
                string mimeType;
                string encoding;
                string fileNameExtension;
                //The DeviceInfo settings should be changed based on the reportType             
                //http://msdn2.microsoft.com/en-us/library/ms155397.aspx  
                string deviceInfo =
                    "<DeviceInfo>" +
                    "  <OutputFormat>PDF</OutputFormat>" +
                    "  <PageWidth>8.5in</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);
            }
            catch (Exception ex)
            {
                ViewBag.errorMessage = ex.InnerException.Message;
                return View("Error");
            }
            return View("Index");
        }      

7.设计报表引用

RDLC报表的开发

 8.运行的结果

RDLC报表的开发

继续阅读