using System.Web; using System.Web.Security; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using FastReport; namespace BLL.Common { public static class FastReportService { /// <summary> /// 重置数据 /// </summary> public static void ResetData() { HttpContext.Current.Session["ReportDataTables"] = null; HttpContext.Current.Session["ReportParameterValues"] = null; } public static void AddFastreportTable(DataTable dataTable) { List<DataTable> dataTables = (List<DataTable>)HttpContext.Current.Session["ReportDataTables"]; if (dataTables == null) { dataTables = new List<DataTable>(); } dataTables.Add(dataTable); HttpContext.Current.Session["ReportDataTables"] = dataTables; } public static void AddFastreportParameter(Dictionary<string, string> Dicparames) { HttpContext.Current.Session["ReportParameterValues"] = Dicparames; } /// <summary> /// 合并报表后打印 /// </summary> /// <param name="fastReportItems">报表实体集</param> /// <param name="path">导出的路径</param> public static void ExportMergeReport(List<Model.FastReportItem> fastReportItems,string path) { Report report = new Report(); report.PrintSettings.ShowDialog = false; //隐藏弹窗 FastReport.EnvironmentSettings settings = new EnvironmentSettings(); settings.ReportSettings.ShowProgress = false; //隐藏进度条 for (int i = 0; i < fastReportItems.Count; i++) { report.Load(Funs.RootPath + fastReportItems[i].ReportPath); //加载报表 List<DataTable> dataTables = fastReportItems[i].DataTables; Dictionary<string, string> ParameterValues = fastReportItems[i].ParameterValues; if (dataTables != null && dataTables.Count > 0) { for (int j = 0; j < dataTables.Count; j++) { report.RegisterData(dataTables[j], dataTables[j].TableName);//绑定数据源 } } if (ParameterValues.Count > 0) { foreach (KeyValuePair<string, string> kvp in ParameterValues) { report.SetParameterValue(kvp.Key, kvp.Value);//绑定参数 } } if (i==0) { report.Prepare(); } else { report.Prepare(true); } } FastReport.Export.Pdf.PDFExport exp = new FastReport.Export.Pdf.PDFExport(); report.Export(exp, path); } } }