/// <summary> /// 儲存鈕 /// </summary> protected void btnSave_Click(object sender, EventArgs e) { string SessionIDName = "CGD041_" + 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(), "CGD041.aspx", "alert(' 目前無資料異動 ');", true); return; } if (DT_Add == null && DT_Mod == null && DT_Del == null) { ErrorMsgLabel.Text = "目前無資料異動"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD041.aspx", "alert(' 目前無資料異動 ');", true); return; } CGDModel.CGDCommon BCOCommon = new CGDModel.CGDCommon(); System.Data.Common.DbTransaction DBT = BCOCommon.OpenAndGetConnection(ConnectionDB).BeginTransaction(); CGDModel.MaintainCheckQualityStore BCO = new CGDModel.MaintainCheckQualityStore(ConntionDB); try { //新增---------------------------------------------------------------------------------------------------------- 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["ENABLE"]); ParameterList.Add(dRow["PICK_BATCH"]); ParameterList.Add(dRow["CHAN_NO"]); ParameterList.Add(dRow["STORE"]); ParameterList.Add(dRow["START_DATE"]); ParameterList.Add(dRow["END_DATE"]); BCO.CreatePICK_CK_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(dRow["PICK_BATCH", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["CHAN_NO", DataRowVersion.Current].ToString()); ParameterList.Add(dRow["STORE", DataRowVersion.Current].ToString()); ParameterList.Add(Convert.ToDateTime(dRow["START_DATE", DataRowVersion.Current].ToString())); ParameterList.Add(Convert.ToDateTime(dRow["END_DATE", 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["ENABLE", 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(Convert.ToDateTime(dRow["START_DATE", DataRowVersion.Original].ToString())); ParameterList.Add(Convert.ToDateTime(dRow["END_DATE", DataRowVersion.Original].ToString())); string MSG = BCO.UpdatePICK_CK_STORE(ParameterList, DBT); if (MSG == "NODATA") { throw new Exception("DB_NODATA"); } } } DBT.Commit();//交易成功 btnQuery_Click(null, null); ErrorMsgLabel.Text = "儲存完畢"; //ScriptManager.RegisterStartupScript(Page, this.GetType(), "CGD041.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; } txtChanNo.Text = ""; txtChanNo_Add.Text = ""; txtStore.Text = ""; txtStore_Add.Text = ""; SLP_StartDate_Add.Text = ""; SLP_EndDate_Add.Text = ""; Panel1.Visible = false; }