/// <summary> /// 通路選取 /// </summary> protected void grdItem_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { DataTable dataTable = new DataTable(); //if (VerifyFormData) //{ grdItem.Enabled = false; chkSelectAll.Visible = true; btnOK.Visible = true; btnCancel.Visible = true; ParameterList.Clear(); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); //ParameterList.Add(((TextBox)((ASP.itm_slp_slp_sku_ascx)grdItem.Rows[e.NewSelectedIndex].FindControl("splItemNO")).FindControl("TextBoxCode")).Text.Trim()); ParameterList.Add(((TextBox)grdItem.Rows[e.NewSelectedIndex].FindControl("splItemNO")).Text.Trim()); ParameterList.Add(((TextBox)grdItem.Rows[e.NewSelectedIndex].FindControl("txtPeriod")).Text.Trim()); CGDModel.ProcessResetBatchAdj BCO = new CGDModel.ProcessResetBatchAdj(ConntionDB); dataTable = BCO.QueryALOChan(ParameterList); grdChain.DataSource = dataTable; grdChain.DataBind(); //從 DataSet 更新使用者所選取的通路 DataSet dataSet = ((DataSet)Session[PAGE_DT_01 + PageTimeStamp.Value.ToString()]); dataTable = dataSet.Tables[0]; int grdItemSelectedRowId = Convert.ToInt32(((Label)grdItem.Rows[e.NewSelectedIndex].FindControl("lblId")).Text); DataRow dataRow = dataTable.Rows.Find(grdItemSelectedRowId); if (dataRow["chain"].ToString() != "") { string chainSelected = dataRow["chain"].ToString(); foreach (GridViewRow gr in grdChain.Rows) { if (chainSelected.IndexOf("^" + gr.Cells[1].Text + "^") != -1) { ((CheckBox)gr.FindControl("chkChain")).Checked = true; } } } grdChain.Visible = true; grdItem.SelectedIndex = e.NewSelectedIndex; //} }
/// <summary> /// 出庫檢查 /// </summary> private bool VerifyALOOutNo() { string slpdStAcceptDateClientId = ""; try { ParameterList.Clear(); ParameterList.Add(SLP_StAcceptDate.Text.Trim()); CGDModel.ProcessResetBatchAdj BCO = new CGDModel.ProcessResetBatchAdj(ConntionDB); if (!BCO.CheckALOOutNO(ParameterList)) { ErrorMsgLabel.Text = "門市進貨日資料已出庫(或無資料),不可作門市進貨單的異動"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD071.aspx", "alert(' 門市進貨日資料已出庫(或無資料),不可作門市進貨單的異動 ');", true); SetClinetFocus(SLP_StAcceptDate.ClientID); return false; } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; return false; } return true; }
/// <summary> /// 期別 的TextChanged事件 /// </summary> protected void txtPeriod_TextChanged(object sender, EventArgs e) { TextBox tmpTxtBox = sender as TextBox; GridViewRow gr = (tmpTxtBox.BindingContainer as GridViewRow); int i = gr.RowIndex; string _splItemNO = ((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim(); string _splItemNO_Gift = ""; TextBox _splItemName = ((TextBox)grdItem.Rows[i].FindControl("splItemName")); string _Period = ((TextBox)grdItem.Rows[i].FindControl("txtPeriod")).Text.Trim(); string itemName = ""; string outQty = ""; string errMsg = ""; if (_splItemNO != "") { //檢查品號/虛擬品號是否重複 for (int j = 0; j <= grdItem.Rows.Count - 1; j++) { if (j != i) { if ((((TextBox)grdItem.Rows[j].FindControl("splItemNO")).Text.Trim() == ((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim()) && (((TextBox)grdItem.Rows[j].FindControl("txtPeriod")).Text.Trim() == ((TextBox)grdItem.Rows[i].FindControl("txtPeriod")).Text.Trim())) { DataSet dataSet = (DataSet)Session[PAGE_DT_01 + PageTimeStamp.Value.ToString()]; DataRow dataRow = dataSet.Tables[0].Rows.Find(Convert.ToInt32(((Label)grdItem.Rows[i].FindControl("lblId")).Text)); dataRow["item_no"] = ""; dataRow["item_name"] = ""; dataRow["period_no"] = ""; dataRow["qty"] = ""; dataRow["chain"] = ""; ((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text = ""; ((TextBox)grdItem.Rows[i].FindControl("splItemName")).Text = ""; ((TextBox)grdItem.Rows[i].FindControl("txtPeriod")).Text = ""; ((Label)grdItem.Rows[i].FindControl("lblQty")).Text = ""; ErrorMsgLabel.Text = "所輸入之[品號/虛擬品號][期別]已重複"; //ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert(' 所輸入之[品號/虛擬品號][期別]已重複 ');", true); return; } } } try { CGDModel.ProcessResetBatchAdj BCO = new CGDModel.ProcessResetBatchAdj(ConntionDB); //如品號/虛擬品號大於6碼 if ((((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim().Length > 6) && (((TextBox)grdItem.Rows[i].FindControl("txtPeriod")).Text.Trim() != "")) { //if (_splItemNO.IndexOf("-") <= 0) //{ // _splItemNO_Gift = _splItemNO.Substring(0, 6) + "-" + _splItemNO.Substring(6); //} //else //{ _splItemNO_Gift = _splItemNO; //} //----先查主品號 //_splItemNO = _splItemNO.Substring(0, 6); //ParameterList.Clear(); //ParameterList.Add(_splItemNO); //itemName = BCO.QueryItemName(ParameterList); //if (itemName == "") //{ // _splItemName.Text = "查無資料"; //} //else //{ // _splItemName.Text = itemName; //} //----查贈品號 ParameterList.Clear(); ParameterList.Add(_splItemNO_Gift); ParameterList.Add(_Period); itemName = BCO.QueryGiftName(ParameterList); if (itemName == "") { _splItemName.Text = "查無資料"; } else { _splItemName.Text = itemName; } } else { if (_splItemNO.Length > 6) { _splItemNO = _splItemNO.Substring(0, 6); } ParameterList.Clear(); ParameterList.Add(_splItemNO); itemName = BCO.QueryItemName(ParameterList); if (itemName == "") { _splItemName.Text = "查無資料"; } else { _splItemName.Text = itemName; } } //查數量 ParameterList.Clear(); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); //if (((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim().Length > 6) //{ // ParameterList.Add(((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim().Substring(0, 6)); //} //else //{ // ParameterList.Add(((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim()); //} ParameterList.Add(((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim()); ParameterList.Add(((TextBox)grdItem.Rows[i].FindControl("txtPeriod")).Text.Trim()); outQty = BCO.QueryItemOutQty(ParameterList); if (outQty == "") { errMsg = "此商品期別不存在門市進貨檔"; ErrorMsgLabel.Text = "此商品期別不存在門市進貨檔"; ((Label)grdItem.Rows[i].FindControl("lblQty")).Text = ""; return; } if (outQty == "0") { switch (optOperation.SelectedIndex) { case 0: errMsg = "此商品期別數量已歸0,不可執行刪單作業"; ErrorMsgLabel.Text = "此商品期別數量已歸0,不可執行刪單作業"; break; } ((Label)grdItem.Rows[i].FindControl("lblQty")).Text = outQty; return; } if (Convert.ToInt16(outQty) > 0) { switch (optOperation.SelectedIndex) { case 1: errMsg = "此商品期別數量未刪單,不可執行恢復作業"; ErrorMsgLabel.Text = "此商品期別數量未刪單,不可執行恢復作業"; break; } ((Label)grdItem.Rows[i].FindControl("lblQty")).Text = outQty; return; } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } finally { } } }
/// <summary> /// 品號 的TextChanged事件 /// </summary> protected void splItemNO_TextChanged(object sender, EventArgs e) { TextBox tmpTxtBox = sender as TextBox; GridViewRow gr = (tmpTxtBox.BindingContainer as GridViewRow); int i = gr.RowIndex; string _splItemNO = ((TextBox)grdItem.Rows[i].FindControl("splItemNO")).Text.Trim(); TextBox _splItemName = ((TextBox)grdItem.Rows[i].FindControl("splItemName")); string _Period = ((TextBox)grdItem.Rows[i].FindControl("txtPeriod")).Text.Trim(); string itemName = ""; try { if (_splItemNO.Length > 6) { _splItemNO = _splItemNO.Substring(0, 6); } CGDModel.ProcessResetBatchAdj BCO = new CGDModel.ProcessResetBatchAdj(ConntionDB); ParameterList.Clear(); ParameterList.Add(_splItemNO); itemName = BCO.QueryItemName(ParameterList); if (itemName == "") { _splItemName.Text = "查無資料"; } else { _splItemName.Text = itemName; } if (_Period != "") txtPeriod_TextChanged(sender, null); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } finally { } }
/// <summary> /// 執行按鈕 /// </summary> protected void btnRun_Click(object sender, EventArgs e) { DataBind(); if (VerifyFormData()) { #region CGDModel.CGDCommon BCOCommon = new CGDModel.CGDCommon(); System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction(); try { DataSet dataSet; CGDModel.ProcessResetBatchAdj BCO = new CGDModel.ProcessResetBatchAdj(ConntionDB); dataSet = ((DataSet)Session[PAGE_DT_01 + PageTimeStamp.Value.ToString()]); if (optOperation.SelectedValue == "1" || optOperation.SelectedValue == "2") { foreach (DataRow dr in dataSet.Tables[0].Rows) { if (dr["item_no"].ToString().Trim() != "") { string[] chainsSelected = dr["chain"].ToString().Split(new Char[] { '^' }); foreach (string chain in chainsSelected) { if (chain.Trim() != "") { ParameterList.Clear(); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); ParameterList.Add(dr["item_no"].ToString().Trim()); ParameterList.Add(dr["period_no"].ToString().Trim()); string outQty = BCO.QueryItemOutQty(ParameterList); if (outQty == "") { DBT.Rollback(); ErrorMsgLabel.Text = "資料不存在於門市進貨檔,執行中止。"; return; } else { ParameterList.Clear(); ParameterList.Add(Convert.ToInt16(optOperation.SelectedValue)); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); ParameterList.Add(dr["item_no"].ToString().Trim()); ParameterList.Add(dr["period_no"].ToString().Trim()); ParameterList.Add(chain.Trim()); ParameterList.Add(Session["UID"].ToString()); BCO.ProcessBatchSelect(ParameterList, DBT); } } } } } } else if (optOperation.SelectedValue == "3" || optOperation.SelectedValue == "4") { foreach (DataRow dr in dataSet.Tables[0].Rows) { if (dr["item_no"].ToString().Trim() != "") { ParameterList.Clear(); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); ParameterList.Add(dr["item_no"].ToString().Trim()); ParameterList.Add(dr["period_no"].ToString().Trim()); string outQty = BCO.QueryItemOutQty(ParameterList); if (outQty == "") { DBT.Rollback(); ErrorMsgLabel.Text = "資料不存在於門市進貨檔,執行中止。"; //ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert(' " + "[門市進貨日] = " + slpdStAcceptDate.Text.Trim() + "\\n" + " [理貨批次] = " + txtPickBatch.Text.Trim() + "\\n" + " [品號/虛擬品號] = " + dr["item_no"].ToString().Trim() + "\\n" + " [期別] = " + dr["period_no"].ToString().Trim() + "\\n" + "\\n" + "之資料不存在於門市進貨檔,執行中止。 ');", true); return; } else if ((Convert.ToInt16(outQty) > 0) && (optOperation.SelectedValue == "4")) { DBT.Rollback(); ErrorMsgLabel.Text = "此商品期別數量未刪單,不可執行恢復作業,執行中止。"; //ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert(' " + "[門市進貨日] = " + slpdStAcceptDate.Text.Trim() + "\\n" + " [理貨批次] = " + txtPickBatch.Text.Trim() + "\\n" + " [品號/虛擬品號] = " + dr["item_no"].ToString().Trim() + "\\n" + " [期別] = " + dr["period_no"].ToString().Trim() + "\\n" + "\\n" + "此商品期別數量未刪單,不可執行恢復作業,執行中止。 ');", true); return; } else if ((Convert.ToInt16(outQty) == 0) && (optOperation.SelectedValue == "3")) { DBT.Rollback(); ErrorMsgLabel.Text = "此商品期別數量已歸0,不可執行刪單作業,執行中止。"; //ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert(' " + "[門市進貨日] = " + slpdStAcceptDate.Text.Trim() + "\\n" + " [理貨批次] = " + txtPickBatch.Text.Trim() + "\\n" + " [品號/虛擬品號] = " + dr["item_no"].ToString().Trim() + "\\n" + " [期別] = " + dr["period_no"].ToString().Trim() + "\\n" + "\\n" + "此商品期別數量已歸0,不可執行刪單作業,執行中止。 ');", true); return; } else { ParameterList.Clear(); ParameterList.Add(Convert.ToInt16(optOperation.SelectedValue)); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); ParameterList.Add(dr["item_no"].ToString().Trim()); ParameterList.Add(dr["period_no"].ToString().Trim()); ParameterList.Add(Session["UID"].ToString()); BCO.ProcessBatchAdj(ParameterList, DBT); } } } } else if (optOperation.SelectedValue == "5") { foreach (DataRow dr in dataSet.Tables[0].Rows) { if (dr["item_no"].ToString().Trim() != "") { string[] chainsSelected = dr["chain"].ToString().Split(new Char[] { '^' }); foreach (string chain in chainsSelected) { if (chain.Trim() != "") { ParameterList.Clear(); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); ParameterList.Add(dr["item_no"].ToString().Trim()); ParameterList.Add(dr["period_no"].ToString().Trim()); string outQty = BCO.QueryItemOutQty(ParameterList); if (outQty == "") { DBT.Rollback(); ErrorMsgLabel.Text = "資料不存在於門市進貨檔,執行中止。"; //ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "A", "alert(' " + "[門市進貨日] = " + slpdStAcceptDate.Text.Trim() + "\\n" + " [理貨批次] = " + txtPickBatch.Text.Trim() + "\\n" + " [品號/虛擬品號] = " + dr["item_no"].ToString().Trim() + "\\n" + " [期別] = " + dr["period_no"].ToString().Trim() + "\\n" + "\\n" + "之資料不存在於門市進貨檔,執行中止。 ');", true); return; } else { ParameterList.Clear(); ParameterList.Add(slpdStAcceptDate.Text.Trim()); ParameterList.Add(txtPickBatch.Text.Trim()); ParameterList.Add(txtModifiedPickBatch.Text); ParameterList.Add(dr["item_no"].ToString().Trim()); ParameterList.Add(dr["period_no"].ToString().Trim()); ParameterList.Add(chain.Trim()); ParameterList.Add(Session["UID"].ToString()); BCO.ProcessPickBatch(ParameterList, DBT); } } } } } } DBT.Commit(); } catch (Exception ex) { DBT.Rollback();//交易失敗 ErrorMsgLabel.Text = ex.Message; } finally { } #endregion ErrorMsgLabel.Text = "執行完畢"; } }
/// <summary> /// 將變更後的內部變量this.CallBackValue返回給前台JavaScript方法ReceiveServerData(string Value)。 /// </summary> /// <returns></returns> string ICallbackEventHandler.GetCallbackResult() { string outQty = ""; string errMsg = ""; if (CallBackValue != string.Empty) { string[] s_Client_String = System.Text.RegularExpressions.Regex.Split(CallBackValue, ";", System.Text.RegularExpressions.RegexOptions.IgnoreCase); ParameterList.Clear(); ParameterList.Add(s_Client_String[1]); ParameterList.Add(s_Client_String[2]); ParameterList.Add(s_Client_String[3]); ParameterList.Add(s_Client_String[4]); CGDModel.ProcessResetBatchAdj BCO = new CGDModel.ProcessResetBatchAdj(ConntionDB); outQty = BCO.QueryItemOutQty(ParameterList); if (outQty == "0") { switch (optOperation.SelectedIndex) { case 0: errMsg = "此商品期別數量已歸0,不可執行刪單作業"; break; case 1: errMsg = "此商品期別數量未刪單,不可執行恢復作業"; break; default: errMsg = "此商品期別不存在門市進貨檔"; break; } } else { DataSet ds = (DataSet)Session[PAGE_DT_01 + PageTimeStamp.Value.ToString()]; for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { if (ds.Tables[0].Rows[i]["id"].ToString() == s_Client_String[6].ToString()) { ds.Tables[0].Rows[i]["qty"] = outQty; } } Session[PAGE_DT_01 + PageTimeStamp.Value.ToString()] = ds; //grdItem.DataSource = ds; //grdItem.DataBind(); } CallBackValue = s_Client_String[0] + ";" + s_Client_String[5] + ";" + outQty + ";" + errMsg; } return CallBackValue; }
/// <summary> /// 畫面欄位檢查 /// </summary> private bool VerifyFormData() { string slpdStAcceptDateClientId = ""; slpdStAcceptDateClientId = ((TextBox)((ASP.wui_slp_slp_slpdate_ascx)slpdStAcceptDate).FindControl("TextBoxCode")).ClientID; if (optOperation.SelectedIndex == -1) { ErrorMsgLabel.Text = "請選擇[作業選項]"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' 請選擇[作業選項] ');", true); return false; } if (slpdStAcceptDate.Text == "") { ErrorMsgLabel.Text = "[門市進貨日]欄位不得空白"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' [門市進貨日]欄位不得空白 ');", true); //SetClinetFocus(slpdStAcceptDateClientId); return false; } //先忽略此條件,以方便UAT測試 //if (DateTime.Compare(Convert.ToDateTime(slpdStAcceptDate.Text), DateTime.Today) < 0) //{ // ErrorMsgLabel.Text = "[門市進貨日]不可小於系統日"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' [門市進貨日]不可小於系統日 ');", true); //SetClinetFocus(slpdStAcceptDateClientId); //return false; //} ParameterList.Clear(); ParameterList.Add(slpdStAcceptDate.Text.Trim()); CGDModel.ProcessResetBatchAdj BCO = new CGDModel.ProcessResetBatchAdj(ConntionDB); if (!BCO.CheckALOOutNO(ParameterList)) { ErrorMsgLabel.Text = "門市進貨日資料已出庫(或無資料),不可作門市進貨單的異動"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' 門市進貨日資料已出庫(或無資料),不可作門市進貨單的異動 ');", true); //SetClinetFocus(slpdStAcceptDateClientId); return false; } if (txtPickBatch.Text.Trim() == "") { ErrorMsgLabel.Text = "[理貨批次]欄位不得空白"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' [理貨批次]欄位不得空白 ');", true); //SetClinetFocus(txtPickBatch.ClientID); return false; } if ((optOperation.SelectedIndex == 4) && (txtModifiedPickBatch.Text.Trim() == "")) { ErrorMsgLabel.Text = "[修改後理貨批次]欄位不得空白"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' [修改後理貨批次]欄位不得空白 ');", true); //SetClinetFocus(txtModifiedPickBatch.ClientID); return false; } //檢查 dataSet 中的資料是否正確 DataSet dataSet; dataSet = (DataSet)Session[PAGE_DT_01 + PageTimeStamp.Value.ToString()]; int InputParameterCount = 0; foreach (DataRow dr in dataSet.Tables[0].Rows) { if ((dr["item_no"].ToString().Trim() != "") && (dr["period_no"].ToString().Trim() == "")) { ErrorMsgLabel.Text = "請輸入[期別]"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' 請輸入[期別] ');", true); return false; } else if ((dr["item_no"].ToString().Trim() != "") && (dr["period_no"].ToString().Trim() != "")) { if ((optOperation.SelectedIndex >= 2) && (optOperation.SelectedIndex <= 4)) { if (dr["chain"].ToString().Trim() == "") { ErrorMsgLabel.Text = "請選擇[通路]"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' 請選擇[通路] ');", true); return false; } } } InputParameterCount = InputParameterCount + 1; } if (InputParameterCount == 0) { ErrorMsgLabel.Text = "請至少輸入一組參數"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD081.aspx", "alert(' 請至少輸入一組參數 ');", true); return false; } return true; }