/// <summary> /// ITM041, 按下BUTTON[載入檔案],AP端資料匯入至TempTable /// </summary> /// <param name="RootDBT"></param> /// <param name="s_LogUser"></param> /// <param name="dt_VDS_CAA_COLL_TMP"></param> /// <returns></returns> public DataTable FileToTmp(DbTransaction RootDBT, string s_LogUser, DataTable dt_Temp) { 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 刪除 VDS_ITM_ITEM_TMP 的資料 dbo.DELETE_VDS_ITM_PRE_ITEM_TMP(DBT, s_LogUser); #endregion #region 新增 VDS_ITM_ITEM_TMP 的資料 foreach (DataRow dr_Temp in dt_Temp.Rows) { dbo.ADD_VDS_ITM_PRE_ITEM_TMP(DBT, dr_Temp); } #endregion #region 檢查文字檔資料是否正確 dbo.CHECK_FILETOTMP(DBT, s_LogUser); #endregion #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); IsRootTranscation = false; } #endregion #region 取得處理結果 dt_Return = dbo.GET_THERESULTS(s_LogUser); #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 } }