//新增明細 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 btnReturnPick_Click(object sender, EventArgs e) { if ((bool)Session["btnClose"] != true) { Session["btnClose"] = null; if (Session["dtVGRItemSelected"] != null) { Session["dtVGRItemSelected"] = null; } return; } string SessionIDName = "VGR01_DTL_" + PageTimeStamp.Value; ErrorMsgLabel.Text = ""; string strErr = ""; string strTaxType = ""; DataTable dtPicker; if (Session["dtVGRItemSelected"] != null) { dtPicker = (DataTable)Session["dtVGRItemSelected"]; } else { strErr = "未選擇商品資訊 "; ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(UpdatePanel), "VGR012", "alert('" + strErr + "');", true); return; } #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 { if (Ds.Tables.Count == 0) { //從DB讀取一空table回來 VGRModel.MaintainReturnData BCOVGR = new VGRModel.MaintainReturnData(ConntionDB); ParameterList.Clear(); Dt = BCOVGR.QueryReturnDetlEmpty(); } else { //變更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"); 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; } } } } Dt = Ds.Tables[0]; } for (int RowNum = 0; RowNum < dtPicker.Rows.Count; RowNum++) { //檢查是否有重複的品項、期別、儲位 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() == dtPicker.Rows[RowNum]["item"].ToString() && (Dt.Rows[i]["period"].ToString() == dtPicker.Rows[RowNum]["period"].ToString())) { haveData = true; Dt.Rows[i]["item_name"] = dtPicker.Rows[RowNum]["item_name"].ToString(); Dt.Rows[i]["price"] = int.Parse(dtPicker.Rows[RowNum]["price"].ToString()); Dt.Rows[i]["onhd_qty"] = int.Parse(dtPicker.Rows[RowNum]["onhd_qty"].ToString()); Dt.Rows[i]["return_qty"] = int.Parse(dtPicker.Rows[RowNum]["return_qty"].ToString()); Dt.Rows[i]["old_return_qty"] = int.Parse(dtPicker.Rows[RowNum]["return_qty"].ToString()); Dt.Rows[i]["adjust_qty"] = int.Parse(dtPicker.Rows[RowNum]["adjust_qty"].ToString()); Dt.Rows[i]["remain_qty"] = int.Parse(dtPicker.Rows[RowNum]["remain_qty"].ToString()); Dt.Rows[i]["cost"] = double.Parse(dtPicker.Rows[RowNum]["cost"].ToString()); Dt.Rows[i]["tax_type"] = dtPicker.Rows[RowNum]["tax_type"].ToString(); Dt.Rows[i]["isChange"] = "N"; } } if (haveData != true) { strTaxType = dtPicker.Rows[RowNum]["tax_type"].ToString(); 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; 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; dRow["item"] = dtPicker.Rows[RowNum]["item"].ToString(); dRow["period"] = dtPicker.Rows[RowNum]["period"].ToString(); dRow["item_name"] = dtPicker.Rows[RowNum]["item_name"].ToString(); dRow["price"] = int.Parse(dtPicker.Rows[RowNum]["price"].ToString()); dRow["onhd_qty"] = int.Parse(dtPicker.Rows[RowNum]["onhd_qty"].ToString()); dRow["return_qty"] = int.Parse(dtPicker.Rows[RowNum]["return_qty"].ToString()); dRow["old_return_qty"] = int.Parse(dtPicker.Rows[RowNum]["return_qty"].ToString()); dRow["remain_qty"] = int.Parse(dtPicker.Rows[RowNum]["remain_qty"].ToString()); dRow["adjust_qty"] = int.Parse(dtPicker.Rows[RowNum]["adjust_qty"].ToString()); dRow["cost"] = double.Parse(dtPicker.Rows[RowNum]["cost"].ToString()); dRow["tax_type"] = dtPicker.Rows[RowNum]["tax_type"].ToString(); dRow["isChange"] = "N"; dRow["ID"] = v_ID; Dt.Rows.Add(dRow); } } #region 使用XML放置到前端資料 MasterOLDData.InnerHtml = Dt.DataSet.GetXml(); hid_CurrentVendor.Value = SLP_Vendor.Text; #endregion Session[SessionIDName] = Dt; GridView1.DataSource = Dt; GridView1.DataBind(); GridView1.Columns[8].Visible = false; GridView1.Columns[9].Visible = false; CalcuTotalRemove(Dt); //改由db計算 //CalcuTotalTax(Dt); 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; } Session["dtVGRItemSelected"] = null; } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } #endregion }