//获取文件报告 public Object GetReportFile() { //生成报告 ResultBody result = new ResultBody();//实例化响应对象 string missionID = Guid.NewGuid().ToString("N"); try { Logger.Info($"[GetReportFile][missionID]:[{missionID}] Paramet:{Newtonsoft.Json.JsonConvert.SerializeObject(HttpContext.Request.Form)}"); Report_param report_Param = new Report_param(HttpContext); string reportPath = GenerateReport.SaveReport(report_Param); result.resultCollection = new ReportResponse(Path.GetFileName(reportPath), reportPath); Logger.Info($"[GetReportFile][missionID]:[{missionID}] Result:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}"); return(result); } catch (Exception ex) { result.Log(404, ex.Message.ToString()); Logger.Error(ex, $"[GetReportFile][missionID]:[{missionID}]"); return(result); } }
//private static BindingFlags s_flag = BindingFlags.Instance | BindingFlags.Public; //private static Document doc = new Document(FileManage.GetReportModelFolderPath()); public static string SaveReport(Report_param report) { try { Document doc = new Document(FileManage.GetReportModelFolderPath()); //使用报告模板 doc.Properties.FormFieldShading = true; //清除表单域阴影 //--------------------------- try { foreach (PropertyInfo p in report.ReportParam.GetType().GetProperties()) { if (p.Name == "targetRects") { List <TargetRect> targets = p.GetValue(report.ReportParam) as List <TargetRect>; foreach (TargetRect item in targets) { RepalceTargetAreaElement(doc, "TopMaxTemperature", item.id, item.TopMaxTemperature); RepalceTargetAreaElement(doc, "BottomMaxTemp", item.id, item.BottomMaxTemp); RepalceTargetAreaElement(doc, "PictureDesc", item.id, item.PictureDesc); RepalceTargetAreaElement(doc, "Reference", item.id, item.Reference); RepalcePicture(doc, item, item.fileName); //插图 } } else { RepalceBaseInfoElement(doc, p.Name, report.ReportParam); // 替换基本信息 } } } catch (Exception ex) { throw ex; } string reprotname = FileManage.GenerateFileName(null) + ReportFormat; string save_path = Path.Combine(FileManage.GetReportSaveFolderPath(), reprotname); doc.SaveToFile(save_path, FileFormat.Doc); return(save_path); } catch (Exception ex) { throw ex; } }
public string Retive_Rep_Data(Report_param <T> condition, string strReportPath, DataSet ds) { var result = string.Empty; var oReport = new cReport(); var rptSource = new ReportDocument(); try { string strReportDirectoryTempPhysicalPath = HttpContext.Current.Server.MapPath(this.ReportDirectoryTemp); Helper.DeleteUnusedFile(strReportDirectoryTempPhysicalPath, ReportAliveTime); string strFilename; string displayCompany = strCompanyName; if (condition.IsLockMajor == "Y") { displayCompany = condition.Person_major_name + " - " + strCompanyName; } strFilename = "report_" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); string strPath = strReportPath; rptSource.Load(HttpContext.Current.Server.MapPath(strPath)); rptSource.SetDataSource(ds.Tables[0]); rptSource.SetParameterValue("UserName", condition.Report_user_print); rptSource.SetParameterValue("CompanyName", displayCompany); rptSource.SetParameterValue("CriteriaDesc", condition.Report_criteria_desc); if (condition.Report_is_pdf) { rptSource.ExportToDisk(ExportFormatType.PortableDocFormat, HttpContext.Current.Server.MapPath("~/temp/") + strFilename + ".pdf"); } if (condition.Report_is_excel) { rptSource.ExportToDisk(ExportFormatType.Excel, HttpContext.Current.Server.MapPath("~/temp/") + strFilename + ".xls"); } result = strFilename; } catch (Exception ex) { throw ex; } finally { oReport.Dispose(); rptSource.Dispose(); } return(result); }
public string Retive_Rep_012(Report_param <T> condition) { var result = string.Empty; var oReport = new cReport(); try { var ds = oReport.SP_REP_012(condition.Report_criteria); string strPath = "~/reports/Rep_012.rpt"; result = Retive_Rep_Data(condition, strPath, ds); } catch (Exception ex) { throw ex; } finally { oReport.Dispose(); } return(result); }
private Report_param <view_Budget_transfer_report> GetCondition() { var result = new Report_param <view_Budget_transfer_report> { Report_condition = new view_Budget_transfer_report(), Report_criteria = string.Empty, Report_criteria_desc = string.Empty, Report_is_excel = chkExcel.Checked, Report_is_pdf = chkPdf.Checked, Report_user_print = base.UserLoginName, IsLockMajor = this.MajorLock, Person_major_name = this.PersonMajorAbbrev }; result.Report_condition.budget_transfer_year = cboYear.SelectedValue; result.Report_condition.budget_transfer_doc = txtbudget_plan_code_from.Text.Replace("'", "''").Trim(); result.Report_condition.degree_code_from = cboDegree_from.SelectedValue; result.Report_condition.budget_plan_code_from = txtbudget_plan_code_from.Text; result.Report_condition.unit_code_from = cboUnit_from.SelectedValue; result.Report_condition.budget_code_from = cboBudget_from.SelectedValue; result.Report_condition.produce_code_from = cboProduce_from.SelectedValue; result.Report_condition.activity_code_from = cboActivity_from.SelectedValue; result.Report_condition.major_code_from = cboMajor_from.SelectedValue; result.Report_condition.degree_code_to = cboDegree_to.SelectedValue; result.Report_condition.budget_plan_code_to = txtbudget_plan_code_to.Text; result.Report_condition.unit_code_to = cboUnit_to.SelectedValue; result.Report_condition.budget_code_to = cboBudget_to.SelectedValue; result.Report_condition.produce_code_to = cboProduce_to.SelectedValue; result.Report_condition.activity_code_to = cboActivity_to.SelectedValue; result.Report_condition.major_code_to = cboMajor_to.SelectedValue; result.Report_condition.budget_transfer_detail_is_impact = rdoImpact.SelectedValue; if (!string.IsNullOrEmpty(result.Report_condition.budget_transfer_year)) { result.Report_criteria = result.Report_criteria + " And (budget_transfer_year = '" + result.Report_condition.budget_transfer_year + "') "; result.Report_criteria_desc += "ปีงบประมาณ : " + result.Report_condition.budget_transfer_year + " "; } if (!string.IsNullOrEmpty(result.Report_condition.budget_transfer_doc)) { result.Report_criteria = result.Report_criteria + " And (budget_transfer_doc ='" + result.Report_condition.budget_transfer_doc + "') "; result.Report_criteria_desc += "เลขที่เอกสาร : " + result.Report_condition.budget_transfer_doc + " "; } if (!string.IsNullOrEmpty(txtdate_begin.Text)) { result.Report_criteria = result.Report_criteria + " And (budget_transfer_date >= '" + cCommon.SeekDate(txtdate_begin.Text) + "') "; result.Report_criteria_desc += "ตั้งแต่วันที่ : " + txtdate_begin.Text + " "; } if (!string.IsNullOrEmpty(txtdate_end.Text)) { result.Report_criteria = result.Report_criteria + " And (budget_transfer_date <= '" + cCommon.SeekDate(txtdate_end.Text) + "') "; result.Report_criteria_desc += "ถึงวันที่ : " + txtdate_end.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.degree_code_from)) { result.Report_criteria = result.Report_criteria + " And (degree_code_from ='" + result.Report_condition.degree_code_from + "') "; result.Report_criteria_desc += "ระดับการศึกษาต้นทาง : " + cboDegree_from.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.budget_plan_code_from)) { result.Report_criteria = result.Report_criteria + " And (budget_plan_code_from ='" + result.Report_condition.budget_plan_code_from + "') "; result.Report_criteria_desc += "รหัสผังงบประมาณต้นทาง : " + txtbudget_plan_code_from.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.unit_code_from)) { result.Report_criteria = result.Report_criteria + " And (unit_code_from ='" + result.Report_condition.unit_code_from + "') "; result.Report_criteria_desc += "หน่วยงานต้นทาง : " + cboUnit_from.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.budget_code_from)) { result.Report_criteria = result.Report_criteria + " And (budget_code_from ='" + result.Report_condition.budget_code_from + "') "; result.Report_criteria_desc += "แผนงบประมาณต้นทาง : " + cboBudget_from.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.produce_code_from)) { result.Report_criteria = result.Report_criteria + " And (produce_code_from ='" + result.Report_condition.produce_code_from + "') "; result.Report_criteria_desc += "ผลผลิตต้นทาง : " + cboProduce_from.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.activity_code_from)) { result.Report_criteria = result.Report_criteria + " And (activity_code_from = '" + result.Report_condition.activity_code_from + "') "; result.Report_criteria_desc += "กิจกรรมต้นทาง : " + cboProduce_from.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.major_code_from)) { result.Report_criteria = result.Report_criteria + " And (major_code_from = '" + result.Report_condition.major_code_from + "') "; result.Report_criteria_desc += "หลักสูตรต้นทาง : " + cboProduce_from.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.degree_code_to)) { result.Report_criteria = result.Report_criteria + " And (degree_code_to ='" + result.Report_condition.degree_code_to + "') "; result.Report_criteria_desc += "ระดับการศึกษาปลายทาง : " + cboDegree_to.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.budget_plan_code_to)) { result.Report_criteria = result.Report_criteria + " And (budget_plan_code_to ='" + result.Report_condition.budget_plan_code_to + "') "; result.Report_criteria_desc += "รหัสผังงบประมาณปลายทาง : " + txtbudget_plan_code_to.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.unit_code_to)) { result.Report_criteria = result.Report_criteria + " And (unit_code_to ='" + result.Report_condition.unit_code_to + "') "; result.Report_criteria_desc += "หน่วยงานปลายทาง : " + cboUnit_to.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.budget_code_to)) { result.Report_criteria = result.Report_criteria + " And (budget_code_to ='" + result.Report_condition.budget_code_to + "') "; result.Report_criteria_desc += "แผนงบประมาณปลายทาง : " + cboBudget_to.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.produce_code_to)) { result.Report_criteria = result.Report_criteria + " And (produce_code_to ='" + result.Report_condition.produce_code_to + "') "; result.Report_criteria_desc += "ผลผลิตปลายทาง : " + cboProduce_to.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.activity_code_to)) { result.Report_criteria = result.Report_criteria + " And (activity_code_to = '" + result.Report_condition.activity_code_to + "') "; result.Report_criteria_desc += "กิจกรรมปลายทาง : " + cboProduce_to.SelectedItem.Text + " "; } if (!string.IsNullOrEmpty(result.Report_condition.major_code_to)) { result.Report_criteria = result.Report_criteria + " And (major_code_to = '" + result.Report_condition.major_code_to + "') "; result.Report_criteria_desc += "หลักสูตรปลายทาง : " + cboProduce_to.SelectedItem.Text + " "; } if (result.Report_condition.budget_transfer_detail_is_impact != "A") { result.Report_criteria = result.Report_criteria + " And (budget_transfer_detail_is_impact = '" + result.Report_condition.budget_transfer_detail_is_impact + "') "; result.Report_criteria_desc += "ผลการโอน : " + rdoImpact.SelectedItem.Text + " "; } if (DirectorLock == "Y") { result.Report_criteria += " and substring(director_code_from,4,2) = substring('" + DirectorCode + "',4,2) "; result.Report_criteria += " and substring(director_code_to,4,2) = substring('" + DirectorCode + "',4,2) "; } if (MajorLock == "Y") { result.Report_criteria += " and major_code_from = '" + PersonMajorCode + "' "; result.Report_criteria += " and major_code_to = '" + PersonMajorCode + "' "; } result.Report_criteria = result.Report_criteria + " and budget_type ='" + this.BudgetType + "' "; return(result); }