using System; using System.Collections.Generic; using System.Linq; using System.Text; using DataLibrary; using System.Net; using System.IO; namespace CoreSavingLibrary { public enum ReportType { direct = 9, pdf = 0, xls_data = 1, xls_full = 2, xlsx_data = 3, xlsx_full = 4, csv = 5, rtf = 6 } public class iReportBuider { public static String printerName=""; private PageWeb page; private PageWebReport pageReport; private string labelName; private string processId; private List reportId; private List reportName; private List reportArgs; private List reportType; private List encoding; //private CriteriaIReport.u_cri_rdate_billpayment.u_cri_rdate_billpayment u_cri_rdate_billpayment; private string p; //private WebUtility WebUtil; //private ReportUtility ReportUtil; public bool AutoOpenPDF { get; set; } public string ProcessId { get { return this.processId; } } public iReportBuider(PageWebSheet page, String labelName) { this.page = page; this.labelName = labelName; //this.WebUtil = page; //this.ReportUtil = page; AutoOpenPDF = false; reportId = new List(); reportName = new List(); reportArgs = new List(); reportType = new List(); encoding = new List(); } // Overload function for iReport modify by TU 02082013 public iReportBuider(PageWebReport page, iReportArgument args, String reportname) { this.page = page; this.pageReport = page; this.labelName = page.LabelName; //this.WebUtil = page; //this.ReportUtil = page; AutoOpenPDF = true; reportId = new List(); reportName = new List(); reportArgs = new List(); reportType = new List(); encoding = new List(); this.AddCriteria(reportname, page.ReportName, page.ReportType, args); } // Overload function for iReport modify by TU 02082013 public iReportBuider(PageWebReport page, iReportArgument args) { this.page = page; this.pageReport = page; this.labelName = page.LabelName; //this.WebUtil = page; //this.ReportUtil = page; AutoOpenPDF = true; reportId = new List(); reportName = new List(); reportArgs = new List(); reportType = new List(); encoding = new List(); this.AddCriteria(page.ReportId, page.ReportName, page.ReportType, args); } //public iReportBuider(CriteriaIReport.u_cri_rdate_billpayment.u_cri_rdate_billpayment u_cri_rdate_billpayment, string p) //{ // // TODO: Complete member initialization // this.u_cri_rdate_billpayment = u_cri_rdate_billpayment; // this.p = p; //} public void AddCriteria(string reportObjectName, string reportName, ReportType reportType, iReportArgument args) { string encoding = "utf-8"; if (reportType == ReportType.csv) { encoding = "tis-620"; } this.AddCriteria(reportObjectName, reportName, reportType, args, encoding); } private void AddCriteria(string reportObjectName, string reportName, ReportType reportType, iReportArgument args, String encoding) { this.reportId.Add(reportObjectName); this.reportName.Add(reportName); this.reportArgs.Add(args); this.reportType.Add(reportType.ToString()); this.encoding.Add(encoding); } public String Retrieve() { XmlConfigService xml = new XmlConfigService(WebUtil.GetGcoopPath()); DateTime dtCapture = DateTime.Now; Random rnd = new Random(); processId = dtCapture.ToString("yyyyMMddHHmmssffffff", WebUtil.EN) + rnd.Next(99999999) ; StringBuilder xmlCri = new StringBuilder(""); xmlCri.Append("\n"); StringBuilder strLink = new StringBuilder(); string autoOpenPdf = ""; bool found_auto_embed_iframe_flag = false; String output_report_url = "", emded_script=""; for (int i = 0; i < reportId.Count; i++) { StringBuilder strArgs = new StringBuilder(); iReportArgument args = reportArgs[i]; if (args != null) { if (args.argType[0] == iReportArgumentType.SELECT) { strArgs.Append("SELECT" + ReportUtil.Spliter2 + args.argValue[0].ToString().Replace("'", "''").Replace("<", ReportUtil.LT).Replace(">", ReportUtil.GT)); } else { for (int a = 0; a < args.argName.Count; a++) { if (a > 0) { strArgs.Append(ReportUtil.Spliter2); } strArgs.Append(args.argType[a].ToString() + ReportUtil.Spliter1); strArgs.Append(args.argName[a] + ReportUtil.Spliter1); if (args.argType[a] == iReportArgumentType.Date) { try { strArgs.Append(Convert.ToDateTime(args.argValue[a]).ToString("yyyy-MM-dd HH:mm:ss", WebUtil.EN)); } catch { strArgs.Append(""); } } else { strArgs.Append(args.argValue[a].ToString().Replace("<", ReportUtil.LT).Replace(">", ReportUtil.GT)); } } } } string color = "red"; string target = ""; string extension = reportType[i]; if (reportType[i] == "xls_data" || reportType[i] == "xls_full") { extension = "xls"; color = "green"; } else if (reportType[i] == "xlsx_data" || reportType[i] == "xlsx_full") { extension = "xlsx"; color = "green"; } else if (reportType[i] == "pdf") { target = " target=\"_blank\" "; color = "red"; } else if (reportType[i] == "csv") { color = "#0077DD"; } else if (reportType[i] == "rtf") { color = "#0033FF"; } string outputFileName = processId + "_" + (i.ToString("000")) + "_" + reportId[i] + "." + extension; string domain = xml.iReportOutputDomain; if (domain == "*") { domain = xml.SavDomain; } if (domain == "*") { domain = WebUtil.GetSavingAddress(); } string fullUrl = xml.iReportOutputProtocol + "://" + domain + ":" + xml.iReportOutputPort + "/" + WebUtil.GetVirtualDirectory() + "/" + xml.iReportOutputPathPattern + outputFileName; string savePath = xml.iReportSavePath; if (savePath.IndexOf(":") < 0 && savePath.IndexOf("\\\\") < 0) { savePath = WebUtil.GetGcoopPath() + "" + savePath; } string fullSavePath = savePath + outputFileName; ; string img = ""; string aOpen = ""; string aClose = ""; string aHref = aOpen + reportName[i] + aClose; if (pageReport != null) { strLink.Append(string.Format("
" + aOpen + img + aClose + "" + aHref + "
", 24)); } else { strLink.Append(string.Format("   " + aOpen + img + aClose + " " + aHref + "   ", 20)); } if (extension == "pdf" && AutoOpenPDF) { autoOpenPdf = fullUrl; } if (reportType[i] == "direct") { fullSavePath = iReportBuider.printerName; fullUrl = iReportBuider.printerName; AutoOpenPDF = false; color = "Red"; } if (extension == "pdf") { try { output_report_url = fullUrl; String reportAutoPrintLists = File.ReadAllText(WebUtil.GetGcoopPath() + "\\iReport\\Reports\\AUTO_PRINT_REPORT_ID.txt"); String report_file_jasper = reportId[i] + (Sta.IS_MYSQL_MODE ? "_myl" : "") + ".jasper"; found_auto_embed_iframe_flag = reportAutoPrintLists.IndexOf(report_file_jasper) >= 0; emded_script = found_auto_embed_iframe_flag && AutoOpenPDF == false ? ("") : ""; } catch { } } String report_file_ = WebUtil.GetGcoopPath() + "iReport\\Reports\\" + reportId[i] + (Sta.IS_MYSQL_MODE ? "_myl" : "") + ".jasper"; String report_file = WebUtil.GetGcoopPath() + "iReport\\Reports\\" + reportId[i] + ".jasper"; if (WebUtil.FileExists(report_file_) == false) { report_file = WebUtil.GetGcoopPathCore() + "iReport\\Reports\\" + reportId[i] + ".jasper"; } xmlCri.Append("\n\t"); xmlCri.Append("\n\t\t" + reportName[i] + ""); xmlCri.Append("\n\t\t" + report_file + ""); xmlCri.Append("\n\t\t" + fullSavePath + ""); xmlCri.Append("\n\t\t" + fullUrl + ""); xmlCri.Append("\n\t\t" + strArgs.ToString() + ""); xmlCri.Append("\n\t\t" + reportType[i] + ""); xmlCri.Append("\n\t\t" + encoding[i] + ""); xmlCri.Append("\n\t"); } xmlCri.Append("\n
"); if (Sta.IS_MYSQL_MODE) { xmlCri = xmlCri.Replace("\n", ""); xmlCri = xmlCri.Replace("\t", ""); } string sql = @" insert into cmreportprocessing( PROCESS_ID, COOP_CONTROL, COOP_ID, ENTRY_ID, START_PROCESS, END_PROCESS, RUNTIME_STATUS, RUNTIME_MESSAGE, CRITERIA_XML, LABEL_NAME ) values ( {0}, {1}, {2}, {3}, SYSDATE, NULL, 0, NULL, {4}, {5} )"; sql = WebUtil.SQLFormat(sql, processId, page.state.SsCoopControl, page.state.SsCoopId, page.state.SsUsername, xmlCri.ToString(), labelName); ExecuteDataSource exe = new ExecuteDataSource(page); exe.SQL.Add(sql); exe.Execute(); try { string ireportDoamin = xml.iReportDomain; if (ireportDoamin == "*") { ireportDoamin = xml.SavDomain; } if (ireportDoamin == "*") { ireportDoamin = WebUtil.GetSavingAddress(); } WebClient myWebClient = new WebClient(); byte[] myDataBuffer = myWebClient.DownloadData("http://" + ireportDoamin + ":" + xml.iReportPort + "/?conId=" + page.state.SsConnectionIndex + "&rId=" + processId + "&ttt=10"); String downloads = Encoding.UTF8.GetString(myDataBuffer); } catch { } string fullLinkDownload = "
" + strLink.ToString() + "

" + (pageReport != null ? "



" : ""); page.RegisterClientScriptBlock("iReportScript", emded_script+"\n\n"); return processId; } } }