using System; using CoreSavingLibrary; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml.Linq; using CoreSavingLibrary.WcfCommon; using CoreSavingLibrary.WcfKeeping; using CoreSavingLibrary.WcfCommon; using CoreSavingLibrary.WcfPrint; namespace Saving.Applications.keeping { public partial class w_sheet_kp_mrc_receive_cutting : PageWebSheet, WebSheet { protected String app; protected String gid; protected String rid; protected String pdf; public string pbl = "kp_mrc_receive_cutting.pbl"; protected String postProcStatus; protected String getXml; protected String postProcType; protected String postInitReport; //===================== private KeepingClient kpService; private CommonClient commonService; protected String chgProcDate; #region WebSheet Members public void InitJsPostBack() { postInitReport = WebUtil.JsPostBack(this, "postInitReport"); postProcStatus = WebUtil.JsPostBack(this, "postProcStatus"); getXml = WebUtil.JsPostBack(this, "getXml"); chgProcDate = WebUtil.JsPostBack(this, "chgProcDate"); postProcType = WebUtil.JsPostBack(this, "postProcType"); } public void WebSheetLoadBegin() { kpService = wcf.Keeping; commonService = wcf.Common; HdRunProcess.Value = "false"; HdOpenIFrame.Value = "false"; this.ConnectSQLCA(); Dw_Report.SetTransaction(sqlca); //--- Page Arguments try { app = "keeping"; } catch { } try { gid = "KEEPING_CHECK"; } catch { } try { rid = "KEEPING_CHECK03"; } catch { } if (!IsPostBack) { if (DwMain.RowCount < 1) { B_Print.Visible = false; DwMain.InsertRow(0); DwMain.SetItemString(1, "coop_id", state.SsCoopId); DwMain.SetItemString(1, "entry_id", state.SsUsername); DateTime last = commonService.LastDayOfmonth(state.SsWsPass,state.SsWorkDate); DwMain.SetItemDecimal(1, "receive_year", last.Year + 543); DwMain.SetItemDecimal(1, "receive_month", last.Month); } } else { this.RestoreContextDw(DwMain); this.RestoreContextDw(Dw_Report); } } public void CheckJsPostBack(string eventArg) { if (eventArg == "postProcStatus") { } else if(eventArg == "postProcType") { DwMain.SetItemString(1, "memb_text", ""); DwMain.SetItemString(1, "group_text", ""); DwMain.SetItemString(1, "mem_text", ""); } else if (eventArg == "getXml") { String xml_tmp = DwMain.Describe("DataWindow.Data.Xml"); //เรียกเว็บเซอร์วิสประมวลผลตัดยอด CallWSRunPostProcess(xml_tmp); } else if (eventArg == "postInitReport") { JspostInitReport(); } } public void SaveWebSheet() { } public void WebSheetLoadEnd() { DwMain.SaveDataCache(); Dw_Report.SaveDataCache(); } #endregion private void CallWSRunPostProcess(string xml) { try { kpService.RunPostProcess(state.SsWsPass, xml,state.SsApplication, state.CurrentPage ); HdRunProcess.Value = "true"; } catch(Exception e) { LtServerMessage.Text = WebUtil.ErrorMessage(e); } } protected void cb_post_Click(object sender, EventArgs e) { String xml_tmp = DwMain.Describe("DataWindow.Data.Xml"); //เรียกเว็บเซอร์วิสประมวลผลและจัดเก็บ CallWSRunPostProcess(xml_tmp); } private void JspostInitReport() { try { String xml_tmp = DwMain.Describe("DataWindow.Data.Xml"); str_keep_proc astr_keep_proc = new str_keep_proc(); astr_keep_proc.xml_option = xml_tmp; int result = kpService.of_init_rcv_post(state.SsWsPass, ref astr_keep_proc); if (result == 1) { Dw_Report.Reset(); Dw_Report.SetSqlSelect(astr_keep_proc.sqlrpt_desc); Dw_Report.Retrieve(); B_Print.Visible = true; } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); } } protected void B_Print_Click(object sender, EventArgs e) { if (Dw_Report.RowCount > 0) { RunProcess(); } } private void RunProcess() { //=========================================================== //String xmlpdf = dw_rpt.Describe("Datawindow.data.XML"); ////ชื่อไฟล์ PDF = YYYYMMDDHHMMSS__.PDF //String pdfFileName = DateTime.Now.ToString("yyyyMMddHHmmss", WebUtil.EN); //pdfFileName += "_Triblane.pdf"; //pdfFileName = pdfFileName.Trim(); //PrintClient wsPrint = wcf.Print; //int inV = wsPrint.PrintPDF(state.SsWsPass, xmlpdf, pdfFileName); //if (inV < 0) //{ // LtServerMessage.Text = WebUtil.ErrorMessage("เกิดข้อผิดพลาด " + xmlpdf); // return; //} //String pdfURL = wsPrint.GetPDFURL(state.SsWsPass) + pdfFileName; //String pop = "Gcoop.OpenPopup('" + pdfURL + "')"; //ClientScript.RegisterClientScriptBlock(this.GetType(), "Triblane", pop, true); //แปลง Criteria ให้อยู่ในรูปแบบมาตรฐาน. decimal year = DwMain.GetItemDecimal(1, "receive_year"); decimal month = DwMain.GetItemDecimal(1, "receive_month"); string ls_month = month.ToString(); if(ls_month.Length !=2) { ls_month = "0"+ls_month; } string recv_period = year.ToString() + ls_month; ReportHelper lnv_helper = new ReportHelper(); lnv_helper.AddArgument(recv_period, ArgumentType.String); //---------------------------------------------------------------- //ชื่อไฟล์ 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 li_return = lws_report.Run(state.SsWsPass, app, gid, rid, 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); } } }