/// <summary> /// 複製鈕(複製視窗內的) /// </summary> protected void btnSave_Click(object sender, EventArgs e) { #region 輸入檢查 if (SLP_CopyFromDate.Text == "") { ErrorMsgLabel.Text = "舊[門市進貨日]欄位不得空白"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 舊[門市進貨日]欄位不得空白 ');", true); return; } if (txtPickBatchCopyFrom.Text == "") { ErrorMsgLabel.Text = "舊[理貨批次]欄位不得空白"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 舊[理貨批次]欄位不得空白 ');", true); return; } if (SLP_CopyToDate.Text == "") { ErrorMsgLabel.Text = "新[門市進貨日]欄位不得空白"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 新[門市進貨日]欄位不得空白 ');", true); return; } if (Convert.ToDateTime(SLP_CopyToDate.Text) <= DateTime.Now) { ErrorMsgLabel.Text = "新[門市進貨日]欄位不得小於等於系統日"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 新[門市進貨日]欄位不得小於等於系統日 ');", true); return; } if (txtPickBatchCopyTo.Text == "") { ErrorMsgLabel.Text = "新[理貨批次]欄位不得空白"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 新[理貨批次]欄位不得空白 ');", true); return; } #endregion System.IO.TextReader tr; CGDModel.CGDCommon BCOCommon = new CGDModel.CGDCommon(); System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction(); try { CGDModel.MaintainSpecStore BCO = new CGDModel.MaintainSpecStore(ConntionDB); string strWhere = ""; // 檢查新日期是否有資料----------------------------------------------------------------------------------------- #region checking DataTable DtCheckNew; ParameterList.Clear(); //組sql where字串 strWhere = ""; strWhere += " and MA.ST_ACCEPT_DATE = to_date('" + this.SLP_CopyToDate.Text.Trim() + "' , 'yyyy/mm/dd')"; strWhere += " and MA.PICK_BATCH = '" + this.txtPickBatchCopyTo.Text.Trim() + "'"; ParameterList.Add(strWhere); DtCheckNew = BCO.QuerySwitch(CGDModel.CGDCommon.QueryType.QueryStoreData, ParameterList); if (DtCheckNew.Rows.Count > 0) { ErrorMsgLabel.Text = "輸入的新門市進貨日已有資料"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 輸入的新門市進貨日已有資料 ');", true); return; } #endregion // 檢查舊日期是否有資料 , 如有資料則進行複製-------------------------------------------------------------------- #region checking DataTable DtCheckOld; ParameterList.Clear(); //組sql where字串 strWhere = ""; strWhere += " and MA.ST_ACCEPT_DATE = to_date('" + this.SLP_CopyFromDate.Text.Trim() + "' , 'yyyy/mm/dd')"; strWhere += " and MA.PICK_BATCH = '" + this.txtPickBatchCopyFrom.Text.Trim() + "'"; ParameterList.Add(strWhere); DtCheckOld = BCO.QuerySwitch(CGDModel.CGDCommon.QueryType.QueryStoreData, ParameterList); if (DtCheckOld.Rows.Count == 0) { ErrorMsgLabel.Text = "輸入的舊門市進貨日沒有資料可以複製"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 輸入的舊門市進貨日沒有資料可以複製 ');", true); return; } else { for (int i = 0; i <= DtCheckOld.Rows.Count - 1; i++) { ParameterList.Clear(); ParameterListDel.Clear(); ParameterList.Add(System.DateTime.Now); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(System.DateTime.Now); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(DtCheckOld.Rows[i]["STATUS"]); ParameterList.Add(DtCheckOld.Rows[i]["ENABLE"]); ParameterList.Add(Convert.ToDateTime(this.SLP_CopyToDate.Text.Trim())); ParameterList.Add(this.txtPickBatchCopyTo.Text.Trim()); ParameterList.Add(DtCheckOld.Rows[i]["CHAN_NO"]); ParameterList.Add(DtCheckOld.Rows[i]["STORE"]); ParameterList.Add(DtCheckOld.Rows[i]["DELIV_EARLY"]); ParameterList.Add(DtCheckOld.Rows[i]["LABEL_QTY"]); BCO.CreatePICK_SPEC_STORE(ParameterList, DBT); } DBT.Commit();//交易成功 } #endregion ErrorMsgLabel.Text = "複製完畢"; ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 複製完畢 ');", true); } catch (Exception ex) { DBT.Rollback();//交易失敗 ErrorMsgLabel.Text = ex.Message; } btnCloseCopy_Click(null, null); }
/// <summary> /// 儲存鈕 /// </summary> protected void btnSaveAll_Click(object sender, EventArgs e) { string SessionIDName = "CGD021_" + PageTimeStamp.Value; DataTable Dt = null; DataTable DT_Add = null; DataTable DT_Mod = null; DataTable DT_Del = null; if (Session[SessionIDName] != null) { Dt = (DataTable)Session[SessionIDName]; DT_Add = Dt.GetChanges(DataRowState.Added); DT_Mod = Dt.GetChanges(DataRowState.Modified); DT_Del = Dt.GetChanges(DataRowState.Deleted); } else { ErrorMsgLabel.Text = "目前無資料異動"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 目前無資料異動 ');", true); return; } if (DT_Add == null && DT_Mod == null && DT_Del == null) { ErrorMsgLabel.Text = "目前無資料異動"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD011.aspx", "alert(' 目前無資料異動 ');", true); return; } CGDModel.CGDCommon BCOCommon = new CGDModel.CGDCommon(); System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction(); CGDModel.MaintainSpecStore BCO = new CGDModel.MaintainSpecStore(ConntionDB); try { //刪除---------------------------------------------------------------------------------------------------------- if (DT_Del != null) { foreach (DataRow dRow in DT_Del.Rows) { ParameterList.Clear(); ParameterList.Add(dRow["PICK_BATCH", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["ST_ACCEPT_DATE", DataRowVersion.Original].ToString())); ParameterList.Add(dRow["CHAN_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["STORE", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["UPDATEDATE", DataRowVersion.Original])); string MSG = BCO.DeletePICK_SPEC_STORE(ParameterList, DBT); if (MSG == "NODATA") { throw new Exception("DB_NODATA"); } } } //新增---------------------------------------------------------------------------------------------------------- if (DT_Add != null) { foreach (DataRow dRow in DT_Add.Rows) { ParameterList.Clear(); ParameterList.Add(dRow["CREATEDATE"]); ParameterList.Add(dRow["CREATEUID"]); ParameterList.Add(dRow["UPDATEDATE"]); ParameterList.Add(dRow["UPDATEUID"]); ParameterList.Add(dRow["STATUS"]); ParameterList.Add(dRow["ENABLE"]); ParameterList.Add(dRow["ST_ACCEPT_DATE"]); ParameterList.Add(dRow["PICK_BATCH"]); ParameterList.Add(dRow["CHAN_NO"]); ParameterList.Add(dRow["STORE"]); ParameterList.Add(dRow["DELIV_EARLY"]); ParameterList.Add(dRow["LABEL_QTY"]); BCO.CreatePICK_SPEC_STORE(ParameterList, DBT); } } //修改---------------------------------------------------------------------------------------------------------- if (DT_Mod != null) { foreach (DataRow dRow in DT_Mod.Rows) { ParameterList.Clear(); ParameterList.Add(dRow["UPDATEUID", DataRowVersion.Current].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["ST_ACCEPT_DATE", DataRowVersion.Current].ToString())); ParameterList.Add(dRow["PICK_BATCH", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["CHAN_NO", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["STORE", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["DELIV_EARLY", DataRowVersion.Current].ToString()); ParameterList.Add(Convert.ToInt32(dRow["LABEL_QTY", DataRowVersion.Current].ToString())); ParameterList.Add(Convert.ToDateTime(dRow["CREATEDATE", DataRowVersion.Original].ToString())); ParameterList.Add(dRow["CREATEUID", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["UPDATEDATE", DataRowVersion.Original].ToString())); ParameterList.Add(dRow["UPDATEUID", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["STATUS", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["ENABLE", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["ST_ACCEPT_DATE", DataRowVersion.Original].ToString())); ParameterList.Add(dRow["PICK_BATCH", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["CHAN_NO", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["STORE", DataRowVersion.Original].ToString()); ParameterList.Add(dRow["DELIV_EARLY", DataRowVersion.Original].ToString()); ParameterList.Add(Convert.ToInt32(dRow["LABEL_QTY", DataRowVersion.Original].ToString())); string MSG = BCO.UpdatePICK_SPEC_STORE(ParameterList, DBT); if (MSG == "NODATA") { throw new Exception("DB_NODATA"); } } } DBT.Commit();//交易成功 btnQuery_Click(null, null); ErrorMsgLabel.Text = "儲存完畢"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD021.aspx", "alert(' 儲存完畢 ');", true); } catch (Exception ex) { DBT.Rollback();//交易失敗 if (ex.Message.IndexOf("違反必須為唯一的限制條件") > 0) { ErrorMsgLabel.Text = "新增之站所已重複"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 新增之站所已重複 ');", true); return; } if (ex.Message.IndexOf("NODATA") > 0) { ErrorMsgLabel.Text = "原資料已異動過,請重新查詢資料後再作處理"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD281.aspx", "alert(' 原資料已異動過,請重新查詢資料後再作處理 ');", true); return; } ErrorMsgLabel.Text = ex.Message; } finally { } }