private void InsertDetail() { ErrorMsgLabel.Text = ""; UpdatePanel6.Update(); string SessionIDName = "IVM10_DTL_" + PageTimeStamp.Value; hid_Bill_Ini.Value = "1"; TextBox txtOutNo = (TextBox)this.SLP_Out.FindControl("TextBoxCode"); TextBox txtOutSection = (TextBox)this.SLP_Out.FindControl("TextBoxCode2"); TextBox txtOutSectionName = (TextBox)this.SLP_Out.FindControl("TextBoxName"); TextBox txtInNo = (TextBox)this.SLP_In.FindControl("TextBoxCode"); TextBox txtInSection = (TextBox)this.SLP_In.FindControl("TextBoxCode2"); TextBox txtInSectionName = (TextBox)this.SLP_In.FindControl("TextBoxName"); #region 檢查輸入值 string strErr = ""; string SugLocate = ""; IVMModel.MaintainRemoveDataDetail BCO = new IVMModel.MaintainRemoveDataDetail(ConntionDB); int Qty = 0; if (txtOutNo.Text == string.Empty && txtOutSection.Text == string.Empty) { strErr = "請輸入移出儲位 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } if (txtInNo.Text == string.Empty) { strErr = "請輸入移入儲區 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } if (SLP_Out.Text == SLP_In.Text) { strErr = "移入移出儲位不得相同 "; SLP_In.Text = ""; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } if (chkEnable.Checked == false && txtInSection.Text == string.Empty) { strErr = "請輸入移入儲位或勾選建議儲位 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } if (int.TryParse(this.txtQty.Text, out Qty) == false) { strErr = "請輸入正確數值格式 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } else { if (Qty <= 0) { strErr = "請輸入正整數 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } } if (SLP_Item.Text == string.Empty) { strErr = "請輸入品號 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } if (SLP_Period.Text == string.Empty) { strErr = "請輸入期別 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } if (txtQty.Text == string.Empty) { strErr = "請輸入移轉數量 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } else { int i = 0; bool Result = int.TryParse(txtQty.Text, out i); if (Result = false) { strErr = "請輸入正確數值 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } else { if (int.Parse(txtQty.Text) == 0) { strErr = "請輸入有效移轉數量 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } } } //判斷是否有建議儲格 if (chkEnable.Checked == true && txtInSection.Text == string.Empty) { IVMModel.MaintainRemoveData BCOMain = new IVMModel.MaintainRemoveData(ConntionDB); SugLocate = BCOMain.GetSugLocate(txtOutNo.Text + txtOutSection.Text, SLP_Item.Text, SLP_Period.Text); if (SugLocate == string.Empty) { strErr = "此商品無可建議儲格,請手動輸入移入儲格 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } else { txtInNo.Text = SugLocate.Substring(0, 1); txtInSection.Text = SugLocate.Substring(1, 5); lblSugSec.Text = SugLocate.Substring(1, 5); } } #endregion #region 如果沒有資料取得空DATASET //DataTable Dt = null; //DataSet Ds = new DataSet(); //if (MasterOLDData.InnerHtml != "") //{ // System.IO.StringReader sr = new System.IO.StringReader(MasterOLDData.InnerHtml); // Ds.ReadXml(sr); //} DataTable Dt = (DataTable)Session[SessionIDName]; try { //string SessionIDName = "IVM10_DTL_" + PageTimeStamp.Value; if (Dt == null) { //從DB讀取一空table回來 ParameterList.Clear(); Dt = BCO.QueryRemoveDetlEmpty(); } //else //{ // Dt = Ds.Tables[0]; //} #region 取得庫存數 int NowOnhdQty = 0; if (txtBarCode.Text == "") { ParameterList.Clear(); INVModel.MaintainStockStatement dbo = new INVModel.MaintainStockStatement(ConntionDB); INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "LOCATE_NO", txtOutNo.Text, "=", "and"); INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "LOCATE_SECTION", txtOutNo.Text + txtOutSection.Text, "=", "and"); INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "ITEM", SLP_Item.Text, "=", "and"); INVModel.SQLHelper.SQLWhere(ref ParameterList, DbType.String, "PERIOD", SLP_Period.Text, "=", "and"); DataTable dtResult = dbo.QueryStockStatementByFind_1(ParameterList); if (dtResult.Rows.Count != 1) { if (chkEnable.Checked == true) txtInSection.Text = ""; txtBarCode.Text = ""; //SLP_Item.Text = ""; //SLP_Period.Text = ""; strErr = "移出儲位的庫存數已不足! "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } else { NowOnhdQty = int.Parse(dtResult.Rows[0]["onhd_qty"].ToString()); } } else { NowOnhdQty = int.Parse(this.hid_StockQty.Value); } #endregion tempID = 0; DataView tempDT = new DataView(); tempDT.Table = Dt.Copy(); tempDT.Sort = "ID ASC"; if (Dt.Rows.Count != 0) { tempID = Convert.ToInt32(tempDT[Dt.Rows.Count - 1]["ID"].ToString()); } if (NowOnhdQty - int.Parse(txtQty.Text) < 0) { if (chkEnable.Checked == true) txtInSection.Text = ""; txtBarCode.Text = ""; //SLP_Item.Text = ""; //SLP_Period.Text = ""; strErr = "移出儲位的庫存數已不足 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } //如果出入庫儲位不相同需要取得入庫暫存儲位 //if(txtOutNo.Text != txtInNo.Text) //{ // IVMModel.MaintainRemoveByPick BCOStock = new IVMModel.MaintainRemoveByPick(ConntionDB); // ParameterList.Clear(); // ParameterList.Add(txtInNo.Text); // ParameterList.Add("1"); // string InLocateSec = BCOStock.GetLocateSecByAttr(ParameterList); // txtInNo.Text = InLocateSec.Substring(0, 1); // txtInSection.Text = InLocateSec.Substring(1,5); //} //檢查是否有重複的品項、期別、儲位,重複的數量必須要加總(既有+新輸入的值) bool HaveData = false; for (int i = 0; i <= Dt.Rows.Count - 1; i++) { if ((Dt.Rows[i]["item"].ToString() == SLP_Item.Text) && (Dt.Rows[i]["period"].ToString() == SLP_Period.Text) && (Dt.Rows[i]["out_locate_section"].ToString() == txtOutNo.Text + txtOutSection.Text) && (Dt.Rows[i]["in_locate_section"].ToString() == txtInNo.Text + txtInSection.Text)) { //明細已存在加總 int NewOnhdQty = int.Parse(Dt.Rows[i]["remove_qty"].ToString()) + int.Parse(txtQty.Text); if (NowOnhdQty - NewOnhdQty < 0) { if (chkEnable.Checked == true) txtInSection.Text = ""; txtBarCode.Text = ""; //SLP_Item.Text = ""; //SLP_Period.Text = ""; strErr = "移出儲位的庫存數已不足 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM102", "showErr('" + strErr + "');", true); return; } Dt.Rows[i]["remove_qty"] = NewOnhdQty; HaveData = true; } } if (HaveData == false) { IVMModel.MaintainRemoveDataDetail dboIVM = new IVMModel.MaintainRemoveDataDetail(ConntionDB); DataRow dRow = Dt.NewRow(); //ID和CODE暫自訂, 真正寫入CO時會重取 int v_ID = tempID + 1; int v_CODE = tempID + 1; dRow["item"] = SLP_Item.Text; dRow["period"] = SLP_Period.Text; if (txtBarCode.Text != string.Empty) { string ItemName = dboIVM.GetItemName(SLP_Item.Text); dRow["item_name"] = ItemName; } else { dRow["item_name"] = SLP_Item.Name; } dRow["Out_locate_no"] = SLP_Out.Text1; dRow["Out_locate_section"] = SLP_Out.Text; dRow["Out_Locate_Name"] = SLP_Out.Text + " " + SLP_Out.Name; dRow["In_locate_no"] = SLP_In.Text1; dRow["In_locate_section"] = SLP_In.Text; dRow["In_Locate_Name"] = SLP_In.Text + " " + SLP_In.Name; dRow["onhd_qty"] = NowOnhdQty; dRow["remove_qty"] = int.Parse(txtQty.Text); if (hidCost.Value != "") { dRow["cost"] = hidCost.Value; } else { //手動輸入需要取得成本資料 double Cost = 0; bool haveData = dboIVM.GetItemPeriodCost(SLP_Item.Text, SLP_Period.Text, out Cost); if (haveData == false) { ErrorMsgLabel.Text = "查無該商品成本資料"; UpdatePanel6.Update(); return; } else { hidCost.Value = Cost.ToString(); dRow["cost"] = Cost.ToString(); } } dRow["ID"] = v_ID; Dt.Rows.Add(dRow); } if (this.chkEnable.Checked == true) { txtInSection.Text = ""; this.chkEnable.Checked = true; } else { lblSugSec.Text = ""; this.txtBarCode.Text = ""; this.chkEnable.Checked = false; } this.SLP_Item.Text = ""; this.SLP_Period.Text = ""; this.txtQty.Text = ""; this.hidCost.Value = ""; this.txtBarCode.Text = ""; #region 使用XML放置到前端資料 //MasterOLDData.InnerHtml = Dt.DataSet.GetXml(); #endregion GridView1.DataSource = Dt; GridView1.DataBind(); Session[SessionIDName] = Dt; CalcuTotalRemove(Dt); this.txtQty.Text = "1"; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; UpdatePanel6.Update(); } #endregion }
private void databind_Dtl() { #region try { string SessionIDName = "IVM10_DTL_" + PageTimeStamp.Value; IVMModel.MaintainRemoveDataDetail BCO = new IVMModel.MaintainRemoveDataDetail(ConntionDB); ParameterList.Clear(); if (Request.QueryString["ID"] != null) { ParameterList.Add(Request.QueryString["ID"].ToString()); } else { ParameterList.Add(CraeteMainID); } DataTable Dt = BCO.QueryRemoveDetlByID(ParameterList); #region 使用XML放置到前端資料 //DataSet Ds = Dt.DataSet; //MasterOLDData.InnerHtml = Ds.GetXml(); #endregion iDetlRowsCount = Dt.Rows.Count; CalcuTotalRemove(Dt); Session[SessionIDName] = Dt; GridView1.DataSource = Dt; GridView1.DataSource = Dt; GridView1.PageIndex = 0; GridView1.DataBind(); //設定GRIDVIEW狀態 if (this.hid_Page_Status.Value == "VIEW") { GridView1.Columns[5].Visible = false; GridView1.Columns[8].Visible = false; for (int i = 0; i < GridView1.Rows.Count; i++) { TextBox txtQty = (TextBox)GridView1.Rows[i].FindControl("txtRemove_Qty"); txtQty.ReadOnly = true; txtQty.BorderStyle = BorderStyle.None; txtQty.BackColor = System.Drawing.Color.Transparent; } } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; UpdatePanel6.Update(); } #endregion }
////依button功能將ButtonID放至下面四個String Array中 //string[] ReadControl = { "" }; //string[] EditControl = { "" }; //string[] DeleteControl = { "" }; //string[] InsertControl = { "" }; //protected void AuthorityControls(Control c) //{ // foreach (string s in EditControl) if (c.ID == s) c.Visible = CanUpdate; // foreach (string s in DeleteControl) if (c.ID == s) c.Visible = CanDelete; // foreach (string s in ReadControl) if (c.ID == s) c.Visible = CanRead; // foreach (string s in InsertControl) if (c.ID == s) c.Visible = CanCreate; // foreach (Control child in c.Controls) // AuthorityControls(child); //} #endregion #region PageElement protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { ItemNo = Request.QueryString["Item"].ToString(); Period = Request.QueryString["Period"].ToString(); IVMModel.MaintainRemoveDataDetail dbo = new IVMModel.MaintainRemoveDataDetail(ConntionDB); ItemName = dbo.GetItemName(ItemNo); dataBind(); } }
private void dataBind() { lblItem.Text = ItemNo + " " + ItemName + " 第" + Period + "期"; try { IVMModel.MaintainRemoveDataDetail dbo = new IVMModel.MaintainRemoveDataDetail(ConntionDB); ParameterList.Clear(); ParameterList.Add(ItemNo.Trim()); ParameterList.Add(Period.Trim()); DataTable dtResult = dbo.QueryRemoveDetlStockQty(ParameterList); GridView1.DataSource = dtResult; GridView1.DataBind(); } catch (Exception ex) { this.ErrLog.Text = ex.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { #region ErrorMsgLabel.Text = ""; if (!IsPostBack) { PageTimeStamp.Value = string.Format("{0}{1}{2}{3}{4}{5}", DateTime.Now.Year.ToString(), DateTime.Now.Month.ToString().PadLeft(2, '0'), DateTime.Now.Day.ToString().PadLeft(2, '0'), DateTime.Now.Hour.ToString().PadLeft(2, '0'), DateTime.Now.Minute.ToString().PadLeft(2, '0'), DateTime.Now.Second.ToString().PadLeft(2, '0') ); IVMModel.MaintainRemoveDataDetail dbo = new IVMModel.MaintainRemoveDataDetail(ConnectionDB); ItemName = dbo.GetItemName(Item); pg_id = "IVM161"; if (Session["dtIVMRemoveDetl"] == null) { MakeTempDataTable(); } getPageDefault(); TextBox txtBNo = (TextBox)this.SLP_BSec.FindControl("TextBoxCode"); TextBox txtBSec = (TextBox)this.SLP_BSec.FindControl("TextBoxCode2"); string BSec = txtBNo.Text + txtBSec.Text; this.hid_BSec.Value = BSec; this.hid_BQty.Value = lblBQty.Text; TextBox txtENo = (TextBox)this.SLP_ESec.FindControl("TextBoxCode"); TextBox txtESec = (TextBox)this.SLP_ESec.FindControl("TextBoxCode2"); string ESec = txtENo.Text + txtESec.Text; this.hid_ESec.Value = ESec; this.hid_EQty.Value = lblEQty.Text; this.txtPickQty.Text = PickQty; this.hid_OldPickQty.Value = PickQty; //txtBNo.Attributes["onblur"] += "getTempBSec('" + lblItem.Text + "','" + lblPeriod.Text + "','" //+ txtBNo.ClientID + "','" + txtBSec.ClientID + "','" //+ lblBQty.ClientID + "','" + txtENo.ClientID + "','" //+ txtESec.ClientID + "','" + lblEQty.ClientID + "','" //+ FunNo + "')"; txtBSec.Attributes["onblur"] += "getBStock('" + lblItem.Text + "','" + lblPeriod.Text + "','" + txtBNo.ClientID + "','" + txtBSec.ClientID + "','" + lblBQty.ClientID + "')"; txtENo.Attributes["onblur"] += "getTempESec('" + lblItem.Text + "','" + lblPeriod.Text + "','" + txtBNo.ClientID + "','" + txtBSec.ClientID + "','" + lblBQty.ClientID + "','" + txtENo.ClientID + "','" + txtESec.ClientID + "','" + lblEQty.ClientID + "','" + FunNo + "')"; txtESec.Attributes["onblur"] += "getEStock('" + lblItem.Text + "','" + lblPeriod.Text + "','" + txtENo.ClientID + "','" + txtESec.ClientID + "','" + lblEQty.ClientID + "')"; if (Mode == "0") btnAdd.Text = "新增確定"; else btnAdd.Text = "編輯確定"; } #endregion }//Page_Load
//新增明細 protected void btnAdd_Click(object sender, EventArgs e) { ErrorMsgLabel.Text = ""; string SessionIDName = "VGR01_DTL_" + PageTimeStamp.Value; //宣告殘餘數量 int Remain_Qty = 0; //調整數量 int Adjust_Qty = 0; #region 檢查輸入值 string strErr = ""; string SugLocate = ""; string strTaxType = ""; if (SLP_Item.Text == string.Empty) { strErr = "請輸入品號 "; //this.ErrorMsgLabel.Text = strErr; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true); return; } if (SLP_Period.Text == string.Empty) { strErr = "請輸入期間 "; //this.ErrorMsgLabel.Text = strErr; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true); return; } if (SLP_ReturnQty.Text == string.Empty) { strErr = "請輸入退貨數量 "; //this.ErrorMsgLabel.Text = strErr; //ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + this.SLP_ReturnQty.FindControl("TextBoxCode").ClientID + "').focus();", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true); return; } //else //{ // if (int.Parse(SLP_ReturnQty.Text) < 1) // { // strErr = "[退貨數量]欄必須為正整數 "; // this.ErrorMsgLabel.Text = strErr; // SLP_ReturnQty.Text = ""; // return; // } //} if (txtOnHDQty.Text == "") { txtOnHDQty.Text = "0"; } #endregion #region 判斷新增的資料 DataTable Dt = null; DataSet Ds = new DataSet(); if (MasterOLDData.InnerHtml != "") { System.IO.StringReader sr = new System.IO.StringReader(MasterOLDData.InnerHtml); Ds.ReadXml(sr); } try { IVMModel.MaintainRemoveDataDetail dboIVM = new IVMModel.MaintainRemoveDataDetail(ConntionDB); VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB); //變更DATATABLE 資料內容 for (int i = 0; i < GridView1.Rows.Count; i++) { Label lblItem = (Label)GridView1.Rows[i].FindControl("lblItem"); Label lblPeriod = (Label)GridView1.Rows[i].FindControl("lblPeriod"); Label lblOnhdQty = (Label)GridView1.Rows[i].FindControl("lblOnhdQty"); Label lblRemainQty = (Label)GridView1.Rows[i].FindControl("lblRemainQty"); TextBox txtReturnQty = (TextBox)GridView1.Rows[i].FindControl("txtReturnQty"); for (int x = 0; x < Ds.Tables[0].Rows.Count; x++) { string Item = Ds.Tables[0].Rows[x]["item"].ToString(); string Period = Ds.Tables[0].Rows[x]["period"].ToString(); if (lblItem.Text == Item && lblPeriod.Text == Period) { if (int.Parse(txtReturnQty.Text) + int.Parse(lblOnhdQty.Text) >= 0) { Ds.Tables[0].Rows[x]["return_qty"] = txtReturnQty.Text; Ds.Tables[0].Rows[x]["remain_qty"] = (int.Parse(lblOnhdQty.Text) - int.Parse(txtReturnQty.Text)).ToString(); if(int.Parse(lblOnhdQty.Text) - int.Parse(txtReturnQty.Text) > 0) { Ds.Tables[0].Rows[x]["adjust_qty"] = "0"; } else { Ds.Tables[0].Rows[x]["adjust_qty"] = ((int.Parse(lblOnhdQty.Text) - int.Parse(txtReturnQty.Text)) * -1).ToString(); } break; } else { ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtReturnQty.ClientID + "').focus();", true); return; } } } } if (Ds.Tables.Count == 0) { //從DB讀取一空table回來 ParameterList.Clear(); Dt = BCOVGR.QueryReturnDetlEmpty(); } else { Dt = Ds.Tables[0]; } //如果不是使用BARCODE輸入,取得商品資料 if(txtBarCode.Text == "") { string Vendor = ""; int Onhd_Qty = 0; int Price = 0; Double Cost = 0; string TaxType = ""; VGRModel.MaintainReturnData BCO = new VGRModel.MaintainReturnData(ConntionDB); bool HaveData = BCO.GetItemData(SLP_Item.Text, SLP_Period.Text, hid_LocateSection.Value.ToString(), out Vendor, out Onhd_Qty, out Price, out Cost, out TaxType); hid_Vendor_Temp.Value = Vendor.ToString(); hid_Price.Value = Price.ToString(); hid_Cost.Value = Cost.ToString(); hid_Tax_Type.Value = TaxType.ToString() ; if (HaveData == true) txtOnHDQty.Text = Onhd_Qty.ToString(); else txtOnHDQty.Text = "0"; } //檢查是否有重複的品項、期別、儲位 bool haveData = false; ArrayList TaxList = new ArrayList(); TaxList = TaxTypeList; for (int i = 0; i <= Dt.Rows.Count - 1; i++) { if ((Dt.Rows[i]["item"].ToString() == SLP_Item.Text) && (Dt.Rows[i]["period"].ToString() == SLP_Period.Text)) { Remain_Qty = int.Parse(this.txtOnHDQty.Text) - int.Parse(SLP_ReturnQty.Text); if (Remain_Qty < 0) { Adjust_Qty = Remain_Qty * -1; } else { Adjust_Qty = 0; } haveData = true; Dt.Rows[i]["return_qty"] =int.Parse(SLP_ReturnQty.Text); Dt.Rows[i]["old_return_qty"] = int.Parse(SLP_ReturnQty.Text); Dt.Rows[i]["adjust_qty"] = Adjust_Qty; Dt.Rows[i]["remain_qty"] = Remain_Qty; Dt.Rows[i]["isChange"] = "N"; } } strTaxType = hid_Tax_Type.Value; bool InList = false; //紀錄TaxType類型 for (int j = 0; j < TaxList.Count; j++) { if (strTaxType == TaxList[j].ToString()) { InList = true; } } if (InList == false) { TaxList.Add(strTaxType); } TaxTypeList = TaxList; if(haveData == false) { if ((SLP_Vendor.Text != string.Empty && this.hid_CurrentVendor.Value == "")||(SLP_Vendor.Text == string.Empty && this.hid_CurrentVendor.Value == "") || (this.hid_CurrentVendor.Value == this.hid_Vendor_Temp.Value && this.hid_CurrentVendor.Value == this.SLP_Vendor.Text)) { tempID = 0; DataView tempDT = new DataView(); tempDT.Table = Dt.Copy(); tempDT.Sort = "ID ASC"; if (Dt.Rows.Count != 0) { tempID = Convert.ToInt32(tempDT[Dt.Rows.Count - 1]["ID"].ToString()); } DataRow dRow = Dt.NewRow(); //ID和CODE暫自訂, 真正寫入CO時會重取 int v_ID = tempID + 1; int v_CODE = tempID + 1; Remain_Qty = int.Parse(this.txtOnHDQty.Text) - int.Parse(SLP_ReturnQty.Text); if (Remain_Qty < 0) { Adjust_Qty = Remain_Qty * -1; } else { Adjust_Qty = 0; } dRow["item"] = SLP_Item.Text; dRow["period"] = SLP_Period.Text; if (SLP_Item.Name != "") { dRow["item_name"] = SLP_Item.Name; } else { string ItemName = dboIVM.GetItemName(SLP_Item.Text); dRow["item_name"] = ItemName; } dRow["price"] = hid_Price.Value; dRow["onhd_qty"] = txtOnHDQty.Text; dRow["return_qty"] = SLP_ReturnQty.Text; dRow["old_return_qty"] = SLP_ReturnQty.Text; dRow["remain_qty"] = Remain_Qty; dRow["adjust_qty"] = Adjust_Qty; dRow["cost"] = hid_Cost.Value; dRow["tax_type"] = hid_Tax_Type.Value; dRow["ID"] = v_ID; dRow["isChange"] = "N"; Dt.Rows.Add(dRow); if (this.SLP_Vendor.Text == string.Empty) { SLP_Vendor.Text = hid_Vendor_Temp.Value; } if (this.hid_CurrentVendor.Value == "") { this.hid_CurrentVendor.Value = SLP_Vendor.Text; } } else { strErr = "不為此供應商品項 "; txtBarCode.Text = ""; this.hid_Vendor_Temp.Value = ""; //this.ErrorMsgLabel.Text = strErr; //ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + this.txtBarCode.ClientID + "').focus();", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true); return; } } #region 使用XML放置到前端資料 MasterOLDData.InnerHtml = Dt.DataSet.GetXml(); #endregion Session[SessionIDName] = Dt; GridView1.DataSource = Dt; GridView1.DataBind(); CalcuTotalRemove(Dt); //改由db計算 //CalcuTotalTax(Dt); this.SLP_Item.Text = string.Empty; this.SLP_Period.Text = string.Empty; this.txtOnHDQty.Text = string.Empty; this.SLP_ReturnQty.Text = string.Empty; //this.hid_Tax_Total_Amt.Value = string.Empty; //this.hid_UnTax_Total_Amt.Value = string.Empty; //this.hid_Tax_ReMain_Amt.Value = string.Empty; //this.hid_UnTax_ReMain_Amt.Value = string.Empty; //this.hid_Tax_Amt.Value = string.Empty; for (int i = 0; i < GridView1.Rows.Count; i++) { TextBox txtReturnQty = (TextBox)GridView1.Rows[i].FindControl("txtReturnQty"); Label lblReturnQty = (Label)GridView1.Rows[i].FindControl("lblReturnQty"); txtReturnQty.Visible = true; lblReturnQty.Visible = false; } if (this.hid_Page_Status.Value == "INSERT") { GridView1.Columns[8].Visible = false; GridView1.Columns[9].Visible = false; } else if (this.hid_Page_Status.Value == "UPDATE") { GridView1.Columns[8].Visible = false; GridView1.Columns[9].Visible = false; GridView1.Columns[11].Visible = false; } txtBarCode.Text = ""; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + this.txtBarCode.ClientID + "').focus();", true); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }
protected void btnAdd_Click(object sender, EventArgs e) { #region 檢查輸入值 hid_Bill_Ini.Value = ""; ErrorMsgLabel.Text = ""; string strErr = ""; try { string SessionIDName = "IVM11_DTL_" + PageTimeStamp.Value; IVMModel.MaintainAdjustData BCO = new IVMModel.MaintainAdjustData(ConntionDB); if (SLP_SKU1.Text == string.Empty) { strErr = "請輸入品號 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); TextBox txtItem = (TextBox)this.SLP_SKU1.FindControl("TextBoxCode"); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtItem.ClientID + "').focus();", true); return; } if (SLP_ItemPeriod1.Text == string.Empty) { strErr = "請輸入期間 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); TextBox txtPeriod = (TextBox)this.SLP_ItemPeriod1.FindControl("TextBoxCode"); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtPeriod.ClientID + "').focus();", true); return; } TextBox txtLocate = (TextBox)this.SLP_LocateSec1.FindControl("TextBoxCode"); TextBox txtLocateSec = (TextBox)this.SLP_LocateSec1.FindControl("TextBoxCode2"); if (txtLocate.Text == "") { strErr = "請輸入儲區"; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtLocate.ClientID + "').focus();", true); return; } if (txtLocateSec.Text == "") { strErr = "請輸入儲位"; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtLocateSec.ClientID + "').focus();", true); return; } if (txtAdjQty.Text == string.Empty) { strErr = "請輸入調整數量 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtAdjQty.ClientID + "').focus();", true); return; } else { int i = 0; bool Result = int.TryParse(txtAdjQty.Text, out i); if (Result == false) { strErr = "請輸入正確數值 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtAdjQty.ClientID + "').focus();", true); return; } else { if (int.Parse(txtAdjQty.Text) == 0) { strErr ="請輸入有效調整數量 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtAdjQty.ClientID + "').focus();", true); return; } } } #endregion #region 如果沒有資料取得空DATASET DataTable Dt = (DataTable)Session[SessionIDName]; if (Dt == null) { //從DB讀取一空table回來 ParameterList.Clear(); Dt = BCO.QueryAdjustDataEmpty(); } //檢查是否有重複的品項、期別、儲位 for (int i = 0 ; i <= Dt.Rows.Count - 1; i++) { if ((Dt.Rows[i]["item"].ToString() == SLP_SKU1.Text) && (Dt.Rows[i]["locate_name"].ToString().Split(' ')[0] == SLP_LocateSec1.Text) && (Dt.Rows[i]["period"].ToString() == SLP_ItemPeriod1.Text)) { strErr = "此調整明細已存在! "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); return; } } #region 取得庫存成本 bool Getdata = false; string strItem = string.Empty; string strperiod = string.Empty; double dblCost = 0; string Item_Cost = ""; Getdata = BCO.GetBarCodeData(txtBarCode.Text, out strItem, out strperiod, out dblCost); if (txtBarCode.Text != string.Empty) { Item_Cost = dblCost.ToString(); } else { IVMModel.MaintainRemoveDataDetail dbo = new IVMModel.MaintainRemoveDataDetail(ConntionDB); bool haveData = dbo.GetItemPeriodCost(SLP_SKU1.Text, SLP_ItemPeriod1.Text, out dblCost); if (haveData == false) { ErrorMsgLabel.Text="產品編號" + SLP_SKU1.Text + "期別編號" + SLP_ItemPeriod1.Text + "查無成本資料"; } Item_Cost = dblCost.ToString(); } #endregion tempID = 0; DataView tempDT = new DataView(); tempDT.Table = Dt.Copy(); tempDT.Sort = "ID ASC"; if (Dt.Rows.Count != 0) { tempID = Convert.ToInt32(tempDT[Dt.Rows.Count - 1]["ID"].ToString()); } #region 取得開單庫存 ParameterList.Clear(); ParameterList.Add(SLP_LocateSec1.Text); ParameterList.Add(SLP_SKU1.Text); ParameterList.Add(SLP_ItemPeriod1.Text); DataTable dtQty = BCO.QueryNewOnhdQty(ParameterList); int NowOnhdQty = 0; if (dtQty.Rows.Count > 0) NowOnhdQty = int.Parse(dtQty.Rows[0]["onhd_qty"].ToString()); if (NowOnhdQty + int.Parse(txtAdjQty.Text) < 0) { strErr = "調整後數量<0 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "IVM112", "alert('" + strErr + "');", true); ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "隨便寫", "document.getElementById('" + txtAdjQty.ClientID + "').focus();", true); return; } #endregion DataRow dRow = Dt.NewRow(); //ID和CODE暫自訂, 真正寫入CO時會重取 int v_ID = tempID + 1; int v_CODE = tempID + 1; dRow["ID"] = v_ID; dRow["BarCode"] = this.txtBarCode.Text; dRow["item"] = SLP_SKU1.Text; dRow["locate_no"] = SLP_LocateSec1.Text.Substring(0, 1); dRow["locate_section"] = SLP_LocateSec1.Text; dRow["Locate_name"] = SLP_LocateSec1.Text + " " + SLP_LocateSec1.Name; dRow["period"] = SLP_ItemPeriod1.Text; if (SLP_SKU1.Name == string.Empty) { dRow["item_name"] = hid_ItemName.Value; } else { dRow["item_name"] = SLP_SKU1.Name; } dRow["onhd_qty"] = NowOnhdQty; dRow["adjust_qty"] = txtAdjQty.Text; dRow["cost"] = double.Parse(Item_Cost); Dt.Rows.Add(dRow); //} hid_ItemName.Value = ""; txtBarCode.Text = ""; //SLP_LocateSec1.Text = ""; SLP_SKU1.Text = ""; SLP_ItemPeriod1.Text = string.Empty; txtAdjQty.Text = ""; GridView1.DataSource = Dt; GridView1.DataBind(); Session[SessionIDName] = Dt; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }