예제 #1
0
        /// <summary>
        /// 刪除該使用者存在於 VDS_PUR_PURCHASEORDER_TMP 的舊資料,並將 EXCEL 中新資料匯入 VDS_PUR_PURCHASEORDER_TMP
        /// </summary>
        /// <param name="ParameterList">刪除變數</param>
        /// <param name="RootDBT">是否有主交易,無主交易輸入null</param>
        /// <returns>回傳影響筆數</returns>
        public void DELETE_AND_INSERT_TEMP_TABLE(ArrayList ParameterList, DbTransaction RootDBT, DataTable dt_ALO_IMPORT_TMP)
        {
            bool IsRootTranscation = false;

            try
            {
                PUR_PurchaseOrderDBO dbo = new PUR_PurchaseOrderDBO(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

                dbo.doDelete_PURCHASEORDER_TMP(ParameterList, DBT);

                foreach (DataRow dRow in dt_ALO_IMPORT_TMP.Rows)
                {
                    dbo.doAdd_PURCHASEORDER_TMP(dRow, DBT);
                }

                #region 交易成功
                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation成立
                    DBT.Commit();
                }
                #endregion

                //當資料寫入TMP檔後,做最後檢查
                //1.檢查匯入的贈品有無父層品項
                //2.檢查有無重複的品項/期別/虛擬品號
                //3.檢查主品項與贈品的交貨日期必需一樣,才能匯入
                dbo.doCheckOtherTmp(ParameterList, null);
            }
            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
            }
        }