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.WcfNShrlon; using CoreSavingLibrary.WcfNCommon; using DataLibrary; using System.Globalization; namespace Saving.Criteria { public partial class u_cri_rdate_procshare : PageWebSheet, WebSheet { protected String app; protected String gid; protected String rid; protected String pdf; protected String runProcess; protected String popupReport; private DwThDate tdw_criteria; public String outputProcess; #region WebSheet Members public void InitJsPostBack() { HdOpenIFrame.Value = "False"; runProcess = WebUtil.JsPostBack(this, "runProcess"); tdw_criteria = new DwThDate(dw_criteria, this); tdw_criteria.Add("start_date", "start_tdate"); tdw_criteria.Add("end_date", "end_tdate"); } //protected void Page_Load(object sender, EventArgs e) public void WebSheetLoadBegin() { InitJsPostBack(); //DwUtil.RetrieveDDDW(dw_criteria, "start_loantype", "criteria.pbl", null); //DwUtil.RetrieveDDDW(dw_criteria, "end_loantype", "criteria.pbl", null); //DwUtil.RetrieveDDDW(dw_criteria, "start_membg", "criteria.pbl", null); //DwUtil.RetrieveDDDW(dw_criteria, "end_membg", "criteria.pbl", null); if (IsPostBack) { dw_criteria.RestoreContext(); } else { //default values. dw_criteria.InsertRow(0); dw_criteria.SetItemDateTime(1, "start_date", state.SsWorkDate); dw_criteria.SetItemDateTime(1, "end_date", state.SsWorkDate); dw_criteria.SetItemString(1, "start_tdate", ""); dw_criteria.SetItemString(1, "end_tdate", ""); DwUtil.RetrieveDDDW(dw_criteria, "select_coop", "criteria.pbl", state.SsCoopControl); DwUtil.RetrieveDDDW(dw_criteria, "printer", "criteria.pbl", null); //string[] minmax = ReportUtil.GetMinMaxLoantype(); //dw_criteria.SetItemString(1, "start_loantype", minmax[0]); //dw_criteria.SetItemString(1, "end_loantype", minmax[1]); //string[] minmax2 = ReportUtil.GetMinMaxMembgroup(); //dw_criteria.SetItemString(1, "start_membg", minmax2[0]); //dw_criteria.SetItemString(1, "end_membg", minmax2[1]); tdw_criteria.Eng2ThaiAllRow(); } //--- 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 == "popupReport") { PopupReport(); } } public void SaveWebSheet() { } public void WebSheetLoadEnd() { } #endregion #region Report Process private void RunProcess() { //อ่านค่าจากหน้าจอใส่ตัวแปรรอไว้ก่อน. //DateTime start_date = dw_criteria.GetItemDateTime(1, "start_date"); //DateTime end_date = dw_criteria.GetItemDateTime(1, "end_date"); String start_date = WebUtil.ConvertDateThaiToEng(dw_criteria, "start_tdate", null); String end_date = WebUtil.ConvertDateThaiToEng(dw_criteria, "end_tdate", null); //String start_loantype = dw_criteria.GetItemString(1, "start_loantype"); //String end_loantype = dw_criteria.GetItemString(1, "end_loantype"); StartProcess(); //แปลง Criteria ให้อยู่ในรูปแบบมาตรฐาน. ReportHelper lnv_helper = new ReportHelper(); //lnv_helper.AddArgument(start_date.ToString("yyyy-MM-dd", WebUtil.EN), ArgumentType.DateTime); //lnv_helper.AddArgument(end_date.ToString("yyyy-MM-dd", WebUtil.EN), ArgumentType.DateTime); lnv_helper.AddArgument(start_date, ArgumentType.DateTime); lnv_helper.AddArgument(end_date, ArgumentType.DateTime); //lnv_helper.AddArgument(start_loantype, ArgumentType.String); //lnv_helper.AddArgument(end_loantype, 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.RunWithID(state.SsWsPass, app, gid, rid, state.SsUsername, criteriaXML, pdfFileName); //if (li_return == "true") //{ // HdOpenIFrame.Value = "True"; //} String criteriaXML = lnv_helper.PopArgumentsXML(); string printer = dw_criteria.GetItemString(1, "printer"); outputProcess = WebUtil.runProcessingReport(state, app, gid, rid, criteriaXML, pdfFileName, printer); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex); return; } } public void StartProcess() { DateTime start_date = dw_criteria.GetItemDate(1, "start_date"); DateTime end_date = dw_criteria.GetItemDate(1, "end_date"); // DateTime start_date = dw_criteria.GetItemDate(1, "start_date"); //String start_membg = dw_criteria.GetItemString(1, "start_membg").Trim(); //String end_membg = dw_criteria.GetItemString(1, "end_membg").Trim(); //String start_loantype = dw_criteria.GetItemString(1, "start_loantype").Trim(); //String end_loantype = dw_criteria.GetItemString(1, "end_loantype").Trim(); CultureInfo th = System.Globalization.CultureInfo.GetCultureInfo("th-TH"); // DateTime ss = dw_periodpay.GetItemDate(row, "expireperiod_date"); String dayss = dw_criteria.GetItemString(1, "start_tdate"); Int16 month = Convert.ToInt16(dayss.Substring(2, 2)); // month = month; DateTime today = DateTime.ParseExact(dayss, "ddmmyyyy", null); DateTime today2 = today.AddMonths(month - 1); // today = new DateTime(today.Year, today.Month, today.Day); today2.AddYears(-543); String dayss3 = dw_criteria.GetItemString(1, "end_tdate"); Int16 month3 = Convert.ToInt16(dayss3.Substring(2, 2)); // month = month; DateTime today3 = DateTime.ParseExact(dayss3, "ddmmyyyy", null); DateTime today23 = today3.AddMonths(month3 - 1); // today = new DateTime(today.Year, today.Month, today.Day); today23.AddYears(-543); wcf.NShrlon.of_procshare_report(today2.AddYears(-543), today23.AddYears(-543), state.SsWsPass); } public void PopupReport() { //เด้ง Popup ออกรายงานเป็น PDF. String pop = "Gcoop.OpenPopup('" + pdf + "')"; ClientScript.RegisterClientScriptBlock(this.GetType(), "DsReport", pop, true); } #endregion } }