public bool InsertRow(DataRow dRow, string PageTimeStamp, DbTransaction RootDB) { try { VDS_IVM10_IMPORT_DBO dbo = new VDS_IVM10_IMPORT_DBO(ref USEDB); bool IsRootTranscation = false; //判斷是否有傳入Root Transcation IsRootTranscation = (RootDB == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDB; } #endregion ArrayList ParameterList = new ArrayList(); ParameterList.Clear(); ParameterList.Add(dRow[0].ToString().Trim()); ParameterList.Add(dRow[1].ToString().Trim()); ParameterList.Add(dRow[3].ToString().Trim()); ParameterList.Add(dRow[4].ToString().Trim()); ParameterList.Add(int.Parse(dRow[5].ToString().Trim())); ParameterList.Add(PageTimeStamp); dbo.InsertOneTempRow(ParameterList, DBT); return true; } catch (Exception ex) { string strErr = ex.ToString(); return false; } }
public DataTable GetErrorDataSheet(ArrayList ParameterList) { try { VDS_IVM10_IMPORT_DBO dbo = new VDS_IVM10_IMPORT_DBO(ref USEDB); return dbo.QueryErrorData(ParameterList); } catch (Exception ex) { throw ex; } }
public void FileToTmp(string PageTimeStamp, string CreateDate, string LoginID, string strFilePath, string RemoveReason, DbTransaction RootDB, out ArrayList ErrorRowList, out string V_OK, out int RemoveID, out int ErrCnt, out string V_Msg) { V_OK = ""; RemoveID = -1; V_Msg = ""; ErrCnt = 0; ArrayList ParameterList = new ArrayList(); bool IsRootTranscation = false; ArrayList ErrorRows = new ArrayList(); string strErrMsgDataFormat = ""; try { //判斷是否有傳入Root Transcation IsRootTranscation = (RootDB == null) ? true : false; #region 啟動交易或指定RootTranscation if (IsRootTranscation) { //獨立呼叫啟動Transcation Conn = USEDB.CreateConnection(); Conn.Open(); DBT = Conn.BeginTransaction(); } else { DBT = RootDB; } #endregion ParameterList.Clear(); VDS_IVM10_IMPORT_DBO BCO = new VDS_IVM10_IMPORT_DBO(ref USEDB); #region 刪除同一個PAGEIMESTAMP的資料 ParameterList.Add(PageTimeStamp); BCO.DeleteDataByPageTimeStamp(ParameterList, DBT); #endregion DataSet ds_Excel = ReadDataFromExcel(strFilePath); for (int i = 0; i < ds_Excel.Tables[0].Rows.Count; i++) { DataRow dRow = ds_Excel.Tables[0].Rows[i]; if (!CheckRequiredField(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查必填欄位 { #region 檢查資料格式正確性 ErrorRows.Add((i + 1).ToString()); } else if (!CheckOverFlow(dRow, iAryOverflowColumnsCheck, out strErrMsgDataFormat))//檢查是否為溢位 { ErrorRows.Add((i + 1).ToString()); } else if (!CheckInputValueIsInt32(dRow, iAryRequiredColumnsCheck, out strErrMsgDataFormat))//檢查是否為數值 { ErrorRows.Add((i + 1).ToString()); #endregion } else { #region 將資料寫入 TEMP TABLE bool isOK = InsertRow(dRow, PageTimeStamp, DBT); if (isOK == false) { ErrorRows.Add((i + 1).ToString()); } #endregion } } #region ErrorRowList = ErrorRows; if (ErrorRows.Count > 0) { if (IsRootTranscation) { //獨立呼叫Transcation失敗 DBT.Rollback(); return; } } #endregion #region 由TEMPTABLE資料建立移轉單 ParameterList.Clear(); ParameterList.Add(PageTimeStamp); ParameterList.Add(LoginID); ParameterList.Add(CreateDate); ParameterList.Add(RemoveReason); BCO.CreateRemoveNoFromTemp(ParameterList, DBT, out V_OK, out RemoveID, out ErrCnt, out V_Msg); if (V_Msg != "0") { if (IsRootTranscation) { //獨立呼叫Transcation失敗 DBT.Rollback(); return; } } #endregion #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); } #endregion } catch (Exception ex) { #region 交易失敗 if (IsRootTranscation) { //獨立呼叫Transcation失敗 DBT.Rollback(); } #endregion throw ex; } }