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 System.Data.OracleClient; //เพิ่มเข้ามา using Sybase.DataWindow;//เพิ่มเข้ามา using System.Globalization; //เพิ่มเข้ามา using DataLibrary; //เพิ่มเข้ามา using System.Web.Services.Protocols; //เรียกใช้ service using System.Threading; namespace Saving.Applications.account { public partial class w_acc_sheet_goods_balance : PageWebSheet, WebSheet { //ประกาศ JavaScript Postback protected String postProcess; protected String postGoodsCode; protected String postSectionId; string pbl = "cm_constant_config.pbl"; //** int InsertRow = 0; //จำนวนแถวที่เพิ่ม //** int DataRow = 0; //จำนวนข้อมูลที่มีอยู่เดิม //** //JS-Event #region WebSheet Members public void InitJsPostBack() { //ตั้งค่า JsPostBack postGoodsCode = WebUtil.JsPostBack(this, "postGoodsCode"); postSectionId = WebUtil.JsPostBack(this, "postSectionId"); postProcess = WebUtil.JsPostBack(this, "postProcess"); } public void WebSheetLoadBegin() { //this.ConnectSQLCA(); ////accService = wcf.NAccount;//ประกาศ new //th = new CultureInfo("th-TH"); //Dw_criteria.SetTransaction(sqlca); //Dw_list.SetTransaction(sqlca); //Dw_main.SetTransaction(sqlca); //Dw_detail.SetTransaction(sqlca); //Dw_find.SetTransaction(sqlca); //Dw_footer.SetTransaction(sqlca); if (!IsPostBack) { //JspostNewClear(); Dw_criteria.InsertRow(0); //Dw_main.InsertRow(0); //Dw_list.InsertRow(0); //Dw_detail.InsertRow(0); //DwUtil.RetrieveDataWindow(Dw_main, "cm_constant_config.pbl", null, state.SsCoopControl); //DwUtil.RetrieveDataWindow(Dw_list, "cm_constant_config.pbl", null, null); //Dw_find.InsertRow(0); //HdBranchId.Value = state.SsCoopId; //Panel1.Visible = false; } else { //this.RestoreContextDw(Dw_date); this.RestoreContextDw(Dw_criteria); this.RestoreContextDw(Dw_list); this.RestoreContextDw(Dw_main); this.RestoreContextDw(Dw_detail); //this.RestoreContextDw(Dw_find); //this.RestoreContextDw(Dw_footer); } } public void CheckJsPostBack(string eventArg) { if (eventArg == "postProcess") { JsPostProcess(); } else if (eventArg == "postSectionId") { JspostSectionId(); } else if (eventArg == "postGoodsCode") { JspostGoodsCode(); } } public void SaveWebSheet() { bool flag = true; string erroe_code = ""; Decimal seq_no = 0; Decimal begin_dr = 0; Decimal begin_cr = 0; Decimal movement_dr = 0; Decimal movement_cr = 0; Decimal forward_dr = 0; Decimal forward_cr = 0; Decimal goodsnorm_balamt = 0; Decimal goodsdegenerate_balamt = 0; Decimal rawmaterial_balamt = 0; Decimal manufact_product_balamt = 0; //DwUtil.RetrieveDataWindow(Dw_main, "cm_constant_config.pbl", null, state.SsCoopControl); //DwUtil.RetrieveDataWindow(Dw_list, "cm_constant_config.pbl", null, null); //String section_id = Dw_main.GetItemString(1, "section_id"); //String goods_code = Dw_list.GetItemString(1, "goods_code"); //String section_id = "03"; // HdSectionId.Value; String section_id = HdSectionId.Value; String goods_code = HdGoodsCode.Value; int year = int.Parse(Dw_criteria.GetItemString(1, "year")) - 543; int period = int.Parse(Dw_criteria.GetItemString(1, "period")); InsertRow = Dw_detail.RowCount; string sqlcount = @"SELECT * FROM accgoodsbalance where year_period = '" + year + "' and month_period = '" + period + "' and section_id = '" + section_id + "' and goods_code = '" + goods_code + "' and coop_id = '" + state.SsCoopControl + "'"; Sdt count = WebUtil.QuerySdt(sqlcount); DataRow = count.GetRowCount(); try { for (int j = 1; j <= DataRow; j++) { DwUtil.UpdateDataWindow(Dw_detail, "cm_constant_config.pbl", "ACCGOODSBALANCE"); } for (int i = DataRow + 1; i <= InsertRow; i++) { try { seq_no = i; //goods_code = Dw_detail.GetItemString(i, "goods_code").Trim(); //section_id = Dw_main.GetItemString(i, "section_id").Trim(); ; section_id = HdSectionId.Value; goods_code = HdGoodsCode.Value; try { begin_dr = Dw_detail.GetItemDecimal(i, "begin_dr"); } catch { begin_dr = 0; } try { begin_cr = Dw_detail.GetItemDecimal(i, "begin_cr"); } catch { begin_cr = 0; } try { movement_dr = Dw_detail.GetItemDecimal(i, "movement_dr"); } catch { movement_dr = 0; } try { movement_cr = Dw_detail.GetItemDecimal(i, "movement_cr"); } catch { movement_cr = 0; } try { forward_dr = Dw_detail.GetItemDecimal(i, "forward_dr"); } catch { forward_dr = 0; } try { forward_cr = Dw_detail.GetItemDecimal(i, "forward_cr"); } catch { forward_cr = 0; } try { goodsnorm_balamt = Dw_detail.GetItemDecimal(i, "goodsnorm_balamt"); } catch { goodsnorm_balamt = 0; } try { goodsdegenerate_balamt = Dw_detail.GetItemDecimal(i, "goodsdegenerate_balamt"); } catch { goodsdegenerate_balamt = 0; } try { rawmaterial_balamt = Dw_detail.GetItemDecimal(i, "rawmaterial_balamt"); } catch { rawmaterial_balamt = 0; } try { manufact_product_balamt = Dw_detail.GetItemDecimal(i, "manufact_product_balamt"); } catch { manufact_product_balamt = 0; } string sqlinsert = @"INSERT INTO accgoodsbalance VALUES('" + state.SsCoopId + "','" + goods_code + "','" + year + "','" + period + "','" + begin_dr + "','" + begin_cr + "','" + movement_dr + "','" + movement_cr + "','" + forward_dr + "','" + forward_cr + "','" + section_id + "','" + goodsnorm_balamt + "','" + goodsdegenerate_balamt + "','" + rawmaterial_balamt + "','" + manufact_product_balamt + "','" + goods_code + "')"; Sdt insert = WebUtil.QuerySdt(sqlinsert); } catch { if (!flag) { erroe_code += ", "; } erroe_code += goods_code; flag = false; } } if (flag) { LtServerMessage.Text = WebUtil.CompleteMessage("บันทึกข้อมูลเสร็จเรียบร้อยแล้ว"); //GetList(); } else { Dw_detail.Reset(); Dw_detail.Retrieve(); LtServerMessage.Text = WebUtil.ErrorMessage("รหัสกระทบยอด " + erroe_code + " มีอยู่แล้ว"); } } catch (Exception ex) { LtServerMessage.Text = WebUtil.ErrorMessage(ex.ToString()); } } public void WebSheetLoadEnd() { Dw_criteria.SaveDataCache(); Dw_main.SaveDataCache(); Dw_list.SaveDataCache(); Dw_detail.SaveDataCache(); } private void JsPostProcess() { DwUtil.RetrieveDataWindow(Dw_main, "cm_constant_config.pbl", null, state.SsCoopControl); DwUtil.RetrieveDataWindow(Dw_list, "cm_constant_config.pbl", null, null); String section_id = Dw_main.GetItemString(1, "section_id"); String goods_code = Dw_list.GetItemString(1, "goods_code"); int year = int.Parse(Dw_criteria.GetItemString(1, "year")) - 543; int period = int.Parse(Dw_criteria.GetItemString(1, "period")); DwUtil.RetrieveDataWindow(Dw_detail, "cm_constant_config.pbl", null, state.SsCoopControl, year, period, section_id, goods_code); int Dw_detail_row = Dw_detail.RowCount; int row = 0; bool IsEquals = false; for (int i = 1; i <= Dw_detail_row; i++) { IsEquals = true; break; } if (!IsEquals) { int row_new = Dw_detail.InsertRow(0); Dw_detail.SetItemString(row_new, "goods_code", goods_code); } row++; } private void JspostSectionId() { String section_id = HdSectionId.Value; String goods_code = HdGoodsCode.Value; //String goods_code = Dw_list.GetItemString(1, "goods_code"); int year = int.Parse(Dw_criteria.GetItemString(1, "year")) - 543; int period = int.Parse(Dw_criteria.GetItemString(1, "period")); DwUtil.RetrieveDataWindow(Dw_detail, "cm_constant_config.pbl", null, state.SsCoopControl, year, period, section_id, goods_code); int Dw_detail_row = Dw_detail.RowCount; int row = 0; bool IsEquals = false; for (int i = 1; i <= Dw_detail_row; i++) { IsEquals = true; break; } if (!IsEquals) { int row_new = Dw_detail.InsertRow(0); //Dw_detail.SetItemString(row_new, "cnt_code", cnt_code); } row++; } private void JspostGoodsCode() { JspostSectionId(); String section_id = HdSectionId.Value; String goods_code = HdGoodsCode.Value; int year = int.Parse(Dw_criteria.GetItemString(1, "year")) - 543; int period = int.Parse(Dw_criteria.GetItemString(1, "period")); DwUtil.RetrieveDataWindow(Dw_detail, "cm_constant_config.pbl", null, state.SsCoopControl, year, period, section_id, goods_code); int Dw_detail_row = Dw_detail.RowCount; int row = 0; bool IsEquals = false; for (int i = 1; i <= Dw_detail_row; i++) { IsEquals = true; break; } if (!IsEquals) { int row_new = Dw_detail.InsertRow(0); Dw_detail.SetItemString(row_new, "goods_code", goods_code); } row++; } #endregion } }