FastReport实现预览

Posted DouDouZhang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FastReport实现预览相关的知识,希望对你有一定的参考价值。

1.添加dll
  FastReport.dll,FastReport.Bars.dll,FastReport.Web.dll
2.在web.config-》system.webServer中添加配置

《httpHandlers》
《remove name="FastReportHandler"/>
《add path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>
《/httpHandlers>

3.在包含views的文件夹中webconfig中加入以下信息:引用命名空间

《add namespace="FastReport"/>
《add namespace="FastReport.Web"/>

4.在_Layout.cshtml文件中

加入

@WebReportGlobals.Scripts() 

@WebReportGlobals.Styles()
这个我在做项目时无法识别,或识别时报错,因此未添加
5.用FastReport画好模板,放在指定位置:templatePath
6.控制器
 预览功能:
 public void PreviewReport(DiagnoseParams diagnose)
        {
            string templatePath = Server.MapPath(Server.UrlDecode(Server.UrlDecode(@"/TemplateFiles"))).TrimEnd(‘\\‘) + "\\";
            var diagnoseResult = listAllResult.Where(p => p.Diagnosises.FirstOrDefault().ID == diagnose.DiagnoseId).FirstOrDefault();
            string DiagnosisDoctorName = diagnoseResult.Diagnosises.FirstOrDefault().Doctor.UserName;
            string signPath = Server.MapPath(@"/Images/" + DiagnosisDoctorName + ".jpg");
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
           // dt.TableName = "Table1"; // 一定要设置表名称

            ds.Tables.Add(dt);
            dt.Columns.Add("Name");
            dt.Columns.Add("Sex");
            dt.Columns.Add("Age");
            dt.Columns.Add("HZHNumber");
            dt.Columns.Add("CheckDateTime");
            dt.Columns.Add("MirrorDescription");
            dt.Columns.Add("CheckProject");
            dt.Columns.Add("CheckItems");
            dt.Columns.Add("Department");
            dt.Columns.Add("DiagnosticHospital");
            dt.Columns.Add("DiagnosticDoctor");
            dt.Columns.Add("DiagnosticOpinion");
            dt.Columns.Add("ApplyHospital");
            dt.Columns.Add("PathologyNO");
            dt.Columns.Add("ImageRepresentation");
            dt.Columns.Add("InpatientNumber");
            dt.Columns.Add("ReportDateTime");
            dt.Columns.Add("ESign");
            dt.Columns.Add("Ward");

            // Add DataTable Row
            dt.Rows.Add(diagnoseResult.Patient.Name, diagnoseResult.Patient.Sex.ToString(), diagnoseResult.StudyAge.ToString() + " " + diagnoseResult.StudyAgeUnit, diagnoseResult.ID,
               diagnoseResult.CreateDate.ToString("yyyy-MM-dd HH:mm"), HttpUtility.UrlDecode(diagnose.MirrorDescription), diagnoseResult.StudyPart == null ? "" : diagnoseResult.StudyPart.Name.ToString(),
               diagnoseResult.StudyItem == null ? "" : diagnoseResult.StudyItem.Name.ToString(), diagnoseResult.StudyType == null ? "" : diagnoseResult.StudyType.Name.ToString(), diagnoseResult.Diagnosises.FirstOrDefault().Doctor.Organizations.Count == 0 ? "" : CommonController.GetRootOrganization(diagnoseResult.Diagnosises.FirstOrDefault().Doctor.Organizations.FirstOrDefault()).Name,
               DiagnosisDoctorName, HttpUtility.UrlDecode(diagnose.DiagnoseNote), diagnoseResult.ApplyDoctor == null ? "" : CommonController.GetRootOrganization(diagnoseResult.ApplyDoctor.Organizations.FirstOrDefault()).Name,
               diagnoseResult.PathologyNO, HttpUtility.UrlDecode(diagnose.DiagnoseSuggestion), diagnoseResult.HospitalizationNO, DateTime.Now.ToString("yyyy-MM-dd HH:mm"), "");//Esign need update


            Report report1 = new Report();
            report1.Load(templatePath + "CTMR.frx");
            report1.RegisterData(ds);
            report1.Show();
        }

 


技巧点:fastReport 的Tabel可以导入,View-》Data  Actions-》Open Dictionary

以上是关于FastReport实现预览的主要内容,如果未能解决你的问题,请参考以下文章

fastreport打印预览里的数据怎么和dbgrid中查询出来的数据不一样

求教delphi 中fastreport报表的问题

FastReport教程在报表的预览模式下复制或删除页面

fastreport报表设计

如何让创建fastreport的主从报表

fastreport 动态创建报表的问题