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 }
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 }