/// <summary> /// ITM041, 按下BUTTON[確定匯入],將TempTable的資料寫入正式Table /// </summary> /// <param name="RootDBT"></param> /// <param name="ParameterList"></param> /// <returns></returns> public DataTable TmpToDB(DbTransaction RootDBT, ArrayList ParameterList) { bool IsRootTranscation = false; DataTable dt_Return = new DataTable(); 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 #region 設定變數 ITM_PreItemDBO dbo = new ITM_PreItemDBO(ref USEDB); #endregion #region 將TempTable的資料寫入正式Table dt_Return = dbo.TmpToDB(DBT, ParameterList); #endregion #region 將文字檔資料,由"UpdTmp"資料夾移動至"UpdBak"資料夾 string s_SourcePath = string.Empty; string s_DestinationPath = string.Empty; DataRow[] dr_Row = dt_Return.Select("STATUS = 'FILE_NAME'"); if (dr_Row.Length == 1) { s_SourcePath = ParameterList[2].ToString() + dr_Row[0]["count"].ToString(); s_DestinationPath = ParameterList[3].ToString() + dr_Row[0]["count"].ToString(); } else { throw new Exception("移動檔案至正式資料夾發生錯誤"); } System.IO.File.Move(s_SourcePath, s_DestinationPath); #endregion #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); } #endregion return dt_Return; } catch (Exception ex) { #region 交易失敗 if (IsRootTranscation) { if (DBT != null) //獨立呼叫Transcation失敗 DBT.Rollback(); } #endregion throw ex; } finally { #region 判斷是否關閉交易連線 if (IsRootTranscation) { //獨立呼叫Transcation,關閉連線 if (Conn.State == ConnectionState.Connecting) { Conn.Close(); } } #endregion } }