public bool DoUpdate(string MainID, string UserID, string UpdateDate, string UpdateTime, DataTable dtUpdate, DbTransaction RootDBT, out string ErrorLog) { bool IsRootTranscation = false; try { DBO.VDS_IVM15_DBO IVMDBO = new VDS_IVM15_DBO(ref USEDB); //判斷是否有傳入Root Transcation IsRootTranscation = (RootDBT == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDBT; } #endregion //檢查必要條件是否已輸入 ErrorLog = ""; for (int i = 0; i < dtUpdate.Rows.Count; i++) { string FID = dtUpdate.Rows[i]["FatherID"].ToString(); string BLocateSec = dtUpdate.Rows[i]["Blocate_Section"].ToString(); string ELocateSec = dtUpdate.Rows[i]["Elocate_Section"].ToString(); string PickQty = dtUpdate.Rows[i]["real_pick_qty"].ToString(); if (FID == string.Empty || BLocateSec.Length != 6 || ELocateSec.Length != 6 || PickQty == string.Empty) { ErrorLog = "資料輸入不完整"; return false; } } ArrayList ParameterList = new ArrayList(); //更新並比對主檔資料 ParameterList.Clear(); ParameterList.Add(MainID); ParameterList.Add(UserID); ParameterList.Add(UpdateDate); ParameterList.Add(UpdateTime); IVMDBO.UpdatePickMain(ParameterList, DBT); for (int i = 0; i < dtUpdate.Rows.Count; i++) { string IsChange = dtUpdate.Rows[i]["isChange"].ToString(); if (IsChange == "Y") { ErrorLog = "更新資料失敗"; string Item = dtUpdate.Rows[i]["Item"].ToString(); string Period = dtUpdate.Rows[i]["Period"].ToString(); string OnhdQty = dtUpdate.Rows[i]["BOnhd_Qty"].ToString(); string IniPickQty = dtUpdate.Rows[i]["ini_pick_qty"].ToString(); string RealPickQty = dtUpdate.Rows[i]["real_pick_qty"].ToString(); string BLocateNo = dtUpdate.Rows[i]["Blocate_Section"].ToString().Substring(0, 1); string BLocateSec = dtUpdate.Rows[i]["Blocate_Section"].ToString(); string ELocateNo = dtUpdate.Rows[i]["Elocate_Section"].ToString().Substring(0, 1); string ELocateSec = dtUpdate.Rows[i]["Elocate_Section"].ToString(); string OldBSec = dtUpdate.Rows[i]["OLDBSec"].ToString(); string OldESec = dtUpdate.Rows[i]["OLDESec"].ToString(); if (OldESec.Length == 1) OldESec = ""; string ID = dtUpdate.Rows[i]["id"].ToString(); string PID = dtUpdate.Rows[i]["pid"].ToString(); string FatherId = dtUpdate.Rows[i]["FatherId"].ToString(); ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(UserID, "string", false)); ParameterList.Add(GetValueSetParameter(UpdateDate, "string", false)); ParameterList.Add(GetValueSetParameter(PID, "int", false)); ParameterList.Add(GetValueSetParameter(Item, "string", false)); ParameterList.Add(GetValueSetParameter(Period, "string", false)); ParameterList.Add(GetValueSetParameter(OnhdQty, "int", false)); ParameterList.Add(GetValueSetParameter(IniPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(RealPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(BLocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(BLocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(OldBSec, "string", false)); ParameterList.Add(GetValueSetParameter(OldESec, "string", false)); ParameterList.Add(GetValueSetParameter(ID, "int", false)); ParameterList.Add(GetValueSetParameter(FatherId, "int", false)); IVMDBO.UpdatePickDetl(ParameterList, DBT); } } for (int i = 0; i < dtUpdate.Rows.Count; i++) { string IsChange = dtUpdate.Rows[i]["isChange"].ToString(); if (IsChange == "New") { ErrorLog = "新增資料失敗"; string Item = dtUpdate.Rows[i]["Item"].ToString(); string Period = dtUpdate.Rows[i]["Period"].ToString(); string OnhdQty = dtUpdate.Rows[i]["BOnhd_Qty"].ToString(); string IniPickQty = dtUpdate.Rows[i]["ini_pick_qty"].ToString(); string RealPickQty = dtUpdate.Rows[i]["real_pick_qty"].ToString(); string BLocateNo = dtUpdate.Rows[i]["Blocate_Section"].ToString().Substring(0, 1); string BLocateSec = dtUpdate.Rows[i]["Blocate_Section"].ToString(); string ELocateNo = dtUpdate.Rows[i]["Elocate_Section"].ToString().Substring(0, 1); string ELocateSec = dtUpdate.Rows[i]["Elocate_Section"].ToString(); string FatherID = dtUpdate.Rows[i]["FatherID"].ToString(); string PID = dtUpdate.Rows[i]["pid"].ToString(); ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(UserID, "string", false)); ParameterList.Add(GetValueSetParameter(UpdateDate, "string", false)); ParameterList.Add(GetValueSetParameter(PID, "int", false)); ParameterList.Add(GetValueSetParameter(Item, "string", false)); ParameterList.Add(GetValueSetParameter(Period, "string", false)); ParameterList.Add(GetValueSetParameter(OnhdQty, "int", false)); ParameterList.Add(GetValueSetParameter(IniPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(RealPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(BLocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(BLocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(FatherID, "int", false)); IVMDBO.CreatePickDetl(ParameterList, DBT); } } #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); ErrorLog = string.Empty; } return true; #endregion } catch (Exception ex) { #region 交易失敗 if (IsRootTranscation) { //獨立呼叫Transcation失敗 DBT.Rollback(); } #endregion throw ex; } finally { #region 判斷是否關閉交易連線 if (IsRootTranscation) { //獨立呼叫Transcation,關閉連線 if (Conn.State == ConnectionState.Connecting) { Conn.Close(); } } #endregion } }