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 DataLibrary; namespace Saving.Criteria { public partial class u_cri_acc_compare_year_period : PageWebSheet, WebSheet { protected String app; protected String gid; protected String rid; protected String pdf; protected String runProcess; protected String popupReport; protected String postInitPeriod; private DwThDate tdw_criteria; public String outputProcess = ""; #region WebSheet Members public void InitJsPostBack() { HdOpenIFrame.Value = "False"; runProcess = WebUtil.JsPostBack(this, "runProcess"); postInitPeriod = WebUtil.JsPostBack(this, "postInitPeriod"); tdw_criteria = new DwThDate(dw_criteria, this); } //protected void Page_Load(object sender, EventArgs e) public void WebSheetLoadBegin() { //InitJsPostBack(); if (IsPostBack) { dw_criteria.RestoreContext(); } else { //default values. dw_criteria.InsertRow(0); //dw_criteria.SetItemDecimal(1, "select_year", 2553); } //--- 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(); } else if (eventArg == "postInitPeriod") { PostInitPeriod(); } } public void SaveWebSheet() { } public void WebSheetLoadEnd() { } #endregion #region Report Process private void RunProcess() { //อ่านค่าจากหน้าจอใส่ตัวแปรรอไว้ก่อน. Decimal select_year = dw_criteria.GetItemDecimal(1, "year") - 543; Decimal select_year2 = dw_criteria.GetItemDecimal(1, "year2") - 543; Decimal period1 = dw_criteria.GetItemDecimal(1, "month") ; Decimal period2 = dw_criteria.GetItemDecimal(1, "month2") ; DateTime period_end_date1 = state.SsWorkDate; DateTime period_end_date2 = state.SsWorkDate; //หาวันที่สิ้นสุดงวดบัญชี string sqlcount = @"SELECT period_end_date FROM accperiod where coop_id = '" + state.SsCoopControl + "' and account_year = '" + select_year + "' and period = '"+ period1 +"' "; Sdt count = WebUtil.QuerySdt(sqlcount); while (count.Next()) { period_end_date1 = count.GetDate("period_end_date"); } string sqlcount2 = @"SELECT period_end_date FROM accperiod where coop_id = '" + state.SsCoopControl + "' and account_year = '" + select_year2 + "' and period = '" + period2 + "' "; Sdt count2 = WebUtil.QuerySdt(sqlcount2); while (count.Next()) { period_end_date2 = count2.GetDate("period_end_date"); } //แปลง Criteria ให้อยู่ในรูปแบบมาตรฐาน. ReportHelper lnv_helper = new ReportHelper(); lnv_helper.AddArgument(state.SsCoopId, ArgumentType.String); lnv_helper.AddArgument(select_year.ToString(), ArgumentType.Number); lnv_helper.AddArgument(period1.ToString(), ArgumentType.Number); lnv_helper.AddArgument(select_year2.ToString(), ArgumentType.Number); lnv_helper.AddArgument(period2.ToString(), ArgumentType.Number); lnv_helper.AddArgument(period_end_date1.ToString(), ArgumentType.DateTime); lnv_helper.AddArgument(period_end_date2.ToString(), ArgumentType.DateTime); //ชื่อไฟล์ 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 { 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 PopupReport() { //เด้ง Popup ออกรายงานเป็น PDF. String pop = "Gcoop.OpenPopup('" + pdf + "')"; ClientScript.RegisterClientScriptBlock(this.GetType(), "DsReport", pop, true); } private void PostInitPeriod() { Decimal year1 = 0; Decimal year2 = 0; try { year1 = dw_criteria.GetItemDecimal(1, "year"); } catch { year1 = 0; } try { year2 = dw_criteria.GetItemDecimal(1, "year2"); } catch { year2 = 0; } if (year1 > 0) { year1 = year1 - 543; DwUtil.RetrieveDDDW(dw_criteria, "month", "criteia.pbl", year1); } if (year2 > 0 ) { year2 = year2 - 543; DwUtil.RetrieveDDDW(dw_criteria, "month2", "criteia.pbl", year2); } } #endregion } }