public bool SaveData(DataTable dtData, ArrayList ParameterList) { bool bResult = false; try { string strSTOCKTAKE_NO = ParameterList[0].ToString(); string strUID = ParameterList[1].ToString(); string strPID = ParameterList[2].ToString(); Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); DBO.VDS_IVM043_DBO db = new VDS_IVM043_DBO(ref USEDB); ArrayList Para = new ArrayList(); for (int i = 0; i < dtData.Rows.Count; i++) { //V_STOCKTAKE_NO //V_LOCATE_NO //V_LOCATE_SECTION //V_ITEM //V_PERIOD Para.Clear(); Para.Add(strSTOCKTAKE_NO); Para.Add(dtData.Rows[i]["LOCATE_NO"].ToString()); Para.Add(dtData.Rows[i]["LOCATE_SECTION"].ToString()); Para.Add(dtData.Rows[i]["ITEM"].ToString()); Para.Add(dtData.Rows[i]["PERIOD"].ToString()); DataTable dtCheck = db.CheckDETL(Para); if (dtCheck.Rows.Count > 0) { //N_ID number, //N_STOCKTAKE_QTY number, //V_NEW_UPDATEUID varchar2, //D_NEW_UPDATEDATE date, //V_OLD_UPDATEUID varchar2, //D_OLD_UPDATEDATE date, //V_OLD_CREATEUID varchar2, //D_OLD_CREATEDATE date Para.Clear(); Para.Add(int.Parse(dtCheck.Rows[0]["ID"].ToString())); Para.Add(int.Parse(dtData.Rows[i]["STOCKTAKE_QTY"].ToString())); Para.Add(strUID); Para.Add(DateTime.Now); Para.Add(DBNull.Value); Para.Add(DBNull.Value); Para.Add(DBNull.Value); Para.Add(DBNull.Value); db.UpdStockTake(Para, DBT); } else { Para.Clear(); Para.Add(int.Parse(strPID)); Para.Add(dtData.Rows[i]["LOCATE_NO"].ToString() + dtData.Rows[i]["LOCATE_SECTION"].ToString()); Para.Add(dtData.Rows[i]["ITEM"].ToString()); Para.Add(dtData.Rows[i]["PERIOD"].ToString()); Para.Add(int.Parse(dtData.Rows[i]["STOCKTAKE_QTY"].ToString())); Para.Add(decimal.Parse(dtData.Rows[i]["COST"].ToString())); Para.Add(strUID); Para.Add(DateTime.Now); InsertStockTake(Para, DBT); } } DBT.Commit(); bResult = true; } catch (Exception ex) { if (DBT != null) { //獨立呼叫Transcation失敗 DBT.Rollback(); } throw ex; } finally { //獨立呼叫Transcation,關閉連線 if (Conn.State == ConnectionState.Connecting) { Conn.Close(); } } return bResult; }
public int UpdStockTake(ArrayList ParameterList, DbTransaction RootDBT) { int result; bool IsRootTranscation = false; DBO.VDS_IVM043_DBO db = new VDS_IVM043_DBO(ref USEDB); try { //判斷是否有傳入Root Transcation IsRootTranscation = (RootDBT == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDBT; } #endregion result = db.UpdStockTake(ParameterList, RootDBT); #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); } #endregion return result; } 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 } }