首页 > 代码库 > FastReport实现预览

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实现预览