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 Sybase.DataWindow; using DataLibrary; using System.IO; using System.Text; namespace Saving.Applications.keeping { public partial class w_sheet_kp_opr_exp_savedisk_pea : PageWebSheet, WebSheet { DataStore DStore; public String pbl = "kp_exp_savedisk.pbl"; protected String postInit; protected String postChangeOption; private DwThDate tDw_main; //============================== public void InitJsPostBack() { postInit = WebUtil.JsPostBack(this, "postInit"); postChangeOption = WebUtil.JsPostBack(this, "postChangeOption"); //================================== tDw_main = new DwThDate(Dw_main, this); tDw_main.Add("operate_date", "operate_tdate"); //=================================== DwUtil.RetrieveDDDW(Dw_choice, "format_text", pbl, state.SsCoopId); } public void WebSheetLoadBegin() { this.ConnectSQLCA(); Dw_detail.SetTransaction(sqlca); try { if (!IsPostBack) { JspostNewClear(); } else { this.RestoreContextDw(Dw_choice); this.RestoreContextDw(Dw_main); this.RestoreContextDw(Dw_detail); } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); } } public void CheckJsPostBack(string eventArg) { if (eventArg == "postInit") { JspostInit(); } else if (eventArg == "postChangeOption") { JspostChangeOption(); } } public void SaveWebSheet() { try { } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); } } public void WebSheetLoadEnd() { Dw_choice.SaveDataCache(); Dw_main.SaveDataCache(); Dw_detail.SaveDataCache(); } private void JspostNewClear() { Dw_choice.Reset(); Dw_choice.InsertRow(0); Dw_main.DataWindowObject = "d_kp_exp_savedisk_option"; Dw_main.Reset(); Dw_main.InsertRow(0); Dw_main.SetItemString(1, "year", Convert.ToString(DateTime.Now.Year + 543)); Dw_main.SetItemString(1, "month", Convert.ToString(DateTime.Now.Month)); Dw_main.SetItemDate(1, "operate_date", state.SsWorkDate); //Dw_main.SetItemString(1, "data_code", "2490"); Dw_detail.Reset(); tDw_main.Eng2ThaiAllRow(); } private void JspostInit() { string year, month, txtImp, recv_period, recv_periodtxt; string salary_id, member_no, keeping_code, item_payment_temp; decimal item_payment; DateTime operate_date; bool fileExists = false; try { year = Dw_main.GetItemString(1, "year"); month = "0" + Dw_main.GetItemString(1, "month"); if (month.Length > 2) { month = month.Substring(1); } recv_period = year + month; recv_periodtxt = month + year.Substring(2); operate_date = Dw_main.GetItemDate(1, "operate_date"); string sql_chkKPIMP = @"select b.salary_id, a.* from kptempreceivedet a, mbmembmaster b where b.member_no = a.member_no order by b.salary_id"; sql_chkKPIMP = WebUtil.SQLFormat(sql_chkKPIMP, recv_period); Sdt dtBN = WebUtil.QuerySdt(sql_chkKPIMP); string txtname = "data" + recv_periodtxt.Substring(0, 4) + ".txt"; string path = @"c:\ImportFileKP\" + txtname; StreamWriter sw; fileExists = File.Exists(path); //เช็คว่ามีการสร้างไฟล์แล้วหรือยัง เอาไว้ก่อนยังไม่ว่างทำ if (fileExists) { sw = File.CreateText(path); } else { sw = File.CreateText(path); } while (dtBN.Next()) { salary_id = dtBN.GetString("salary_id").Trim(); member_no = dtBN.GetString("member_no").Trim(); keeping_code = dtBN.GetString("keeping_code").Trim(); item_payment = dtBN.GetDecimal("item_payment") * 100; item_payment_temp = item_payment.ToString("0000000000"); salary_id = FormatString(salary_id, 6); keeping_code = FormatString(keeping_code, 3); txtImp = salary_id + member_no.Substring(2) + keeping_code + item_payment_temp + recv_period.Substring(2); sw.WriteLine(txtImp); } sw.Close(); } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); } } public string FormatString(string inputtxt, int lenghttxt) { int a, b, c; string y = inputtxt; a = inputtxt.Length; b = lenghttxt; try { if (a < b) { c = b - a; string x = ""; for (int i = 0; i < c; i++ ) { x = x + "0"; } y = x + y; } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); } return y.ToString(); } private void JspostChangeOption() { try { } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); } } private void JspostSetData() { try { } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.Message); } } } }