using System; using CoreSavingLibrary; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DataLibrary; namespace Saving.Criteria { public partial class u_cri_npl_sortyear : PageWebSheet, WebSheet { protected String app; protected String gid; protected String rid; protected String pdf; protected String runProcess; protected String JsPostRangeType; public String outputProcess = ""; //private DwThDate tdw_criteria; #region WebSheet Members public void InitJsPostBack() { HdOpenIFrame.Value = "False"; runProcess = WebUtil.JsPostBack(this, "runProcess"); JsPostRangeType = WebUtil.JsPostBack(this, "JsPostRangeType"); } public void WebSheetLoadBegin() { if (IsPostBack) { this.RestoreContextDw(dw_criteria); } else { dw_criteria.InsertRow(0); dw_criteria.SetItemDecimal(1, "year_th", state.SsWorkDate.Year + 543); for (int i = 0; i <= 7; i++) { dw_criteria.SetItemDecimal(1, "lawtype_" + i, 0); } for (int i = 1; i <= 4; i++) { dw_criteria.SetItemDecimal(1, "lawtype_" + i, 1); } } //--- Page Arguments try { app = Request["app"].ToString(); } catch { } if (app == null || app == "") { app = state.SsApplication; } try { gid = Request["gid"].ToString(); } catch { } try { rid = Request["rid"].ToString(); } catch { } //Report Name. try { Sta ta = new Sta(state.SsConnectionString); String sql = ""; sql = @"SELECT REPORT_NAME FROM WEBREPORTDETAIL WHERE ( GROUP_ID = '" + gid + @"' ) AND ( REPORT_ID = '" + rid + @"' )"; Sdt dt = ta.Query(sql); ReportName.Text = dt.Rows[0]["REPORT_NAME"].ToString(); ta.Close(); } catch { ReportName.Text = "[" + rid + "]"; } //Link back to the report menu. LinkBack.PostBackUrl = String.Format("~/ReportDefault.aspx?app={0}&gid={1}", app, gid); } public void CheckJsPostBack(string eventArg) { if (eventArg == "runProcess") { RunProcess(); } else if (eventArg == "JsPostRangeType") { decimal range_type = dw_criteria.GetItemDecimal(1, "range_type"); if (range_type == 1) { dw_criteria.SetItemDecimal(1, "range_type", 2); } else if (range_type == 2) { dw_criteria.SetItemDecimal(1, "range_type", 1); } } } public void SaveWebSheet() { } public void WebSheetLoadEnd() { dw_criteria.SaveDataCache(); } #endregion private void RunProcess() { //อ่านค่าจากหน้าจอใส่ตัวแปรรอไว้ก่อน. decimal year_th = 0; string array = ""; try { year_th = dw_criteria.GetItemDecimal(1, "year_th"); } catch { } for (int i = 0; i <= 7; i++) { if (dw_criteria.GetItemDecimal(1, "lawtype_" + i) == 1) { array += "," + i; } } if (array.Length > 1) { array = array.Substring(1); } //แปลง Criteria ให้อยู่ในรูปแบบมาตรฐาน. ReportHelper lnv_helper = new ReportHelper(); lnv_helper.AddArgument(state.SsCoopControl, ArgumentType.String); lnv_helper.AddArgument(year_th.ToString(), ArgumentType.Number); lnv_helper.AddArgument(array, ArgumentType.StringArray); //ชื่อไฟล์ PDF = YYYYMMDDHHMMSS__.PDF String pdfFileName = DateTime.Now.ToString("yyyyMMddHHmmss", WebUtil.EN); pdfFileName += "_" + gid + "_" + rid + ".pdf"; pdfFileName = pdfFileName.Trim(); //ส่งให้ ReportService สร้าง PDF ให้ {โดยปกติจะอยู่ใน C:\GCOOP\Saving\PDF\}. try { //CoreSavingLibrary.WcfReport.ReportClient lws_report = wcf.Report; String criteriaXML = lnv_helper.PopArgumentsXML(); //this.pdf = lws_report.GetPDFURL(state.SsWsPass) + pdfFileName; string printer = dw_criteria.GetItemString(1, "printer"); outputProcess = WebUtil.runProcessingReport(state, app, gid, rid, criteriaXML, pdfFileName, printer); //String li_return = lws_report.RunWithID(state.SsWsPass, app, gid, rid, state.SsUsername, criteriaXML, pdfFileName); //if (li_return == "true") //{ // HdOpenIFrame.Value = "True"; //} } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); return; } } public void PopupReport() { //เด้ง Popup ออกรายงานเป็น PDF. String pop = "Gcoop.OpenPopup('" + pdf + "')"; ClientScript.RegisterClientScriptBlock(this.GetType(), "DsReport", pop, true); } } }