Ejemplo n.º 1
0
        public void CopyNew(DataTable dtNew, string strITEM, string strPERIOD, string strUID, string strUPDATEDATE)
        {
            bool IsRootTranscation = false;

            try
            {
                DBO.ITM07_DBO dbo = new ITM07_DBO(ref USEDB);

                //獨立呼叫啟動Transcation
                Conn = USEDB.CreateConnection();
                Conn.Open();
                DBT = Conn.BeginTransaction();

                ArrayList ParameterList = new ArrayList();
                for (int i = 0; i < dtNew.Rows.Count; i++)
                {
                    ParameterList.Clear();
                    ParameterList.Add(strITEM);
                    ParameterList.Add(strPERIOD);
                    ParameterList.Add(dtNew.Rows[i]["EDIT_NO"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["CHAN_NO"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["ITEM_MAP"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["EFFECTIVE_DATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["CHAN_END_DATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["FREQUENCY_TYPE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["TRUN_OUT"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["STATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["PLAN_RETURN_DATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["NEXT_PLAN_RETURN_DATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["NOTICE_RETURN_DATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["BACKWARD_DATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["CHAN_ISS_DATE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["CHAN_DIS_NO"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["RETURN_TYPE"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["RTN_DDL"].ToString());
                    ParameterList.Add(dtNew.Rows[i]["DISPLAY_DAY"].ToString());
                    ParameterList.Add(strUPDATEDATE);
                    ParameterList.Add(strUID);
                    ParameterList.Add(strUPDATEDATE);
                    ParameterList.Add(strUID);
                    dbo.doInsertOne(ParameterList, DBT);
                }

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

            }
            catch (Exception ex)
            {
                #region 交易失敗
                //獨立呼叫Transcation失敗
                DBT.Rollback();
                #endregion

                throw ex;
            }
            finally
            {
                #region 判斷是否關閉交易連線
                //獨立呼叫Transcation,關閉連線
                if (Conn.State == ConnectionState.Connecting)
                {
                    Conn.Close();
                }
                #endregion
            }

        }
Ejemplo n.º 2
0
        public void InsertOne(DataRow[] drs, string strITEM, string strPERIOD, string strUID, string strUPDATEDATE, DbTransaction RootDBT)
        {
            bool IsRootTranscation = false;

            try
            {
                DBO.ITM07_DBO dbo = new ITM07_DBO(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
                ArrayList ParameterList = new ArrayList();
                foreach (DataRow dr in drs)
                {
                    ParameterList.Clear();
                    ParameterList.Add(strITEM);
                    ParameterList.Add(strPERIOD);
                    ParameterList.Add(dr["EDIT_NO"].ToString());
                    ParameterList.Add(dr["CHAN_NO"].ToString());
                    ParameterList.Add(dr["ITEM_MAP"].ToString());
                    ParameterList.Add(dr["EFFECTIVE_DATE"].ToString());
                    ParameterList.Add(dr["CHAN_END_DATE"].ToString());
                    ParameterList.Add(dr["FREQUENCY_TYPE"].ToString());
                    ParameterList.Add(dr["TRUN_OUT"].ToString());
                    ParameterList.Add(dr["STATE"].ToString());
                    ParameterList.Add(dr["PLAN_RETURN_DATE"].ToString());
                    ParameterList.Add(dr["NEXT_PLAN_RETURN_DATE"].ToString());
                    ParameterList.Add(dr["NOTICE_RETURN_DATE"].ToString());
                    ParameterList.Add(dr["BACKWARD_DATE"].ToString());
                    ParameterList.Add(dr["CHAN_ISS_DATE"].ToString());
                    ParameterList.Add(dr["CHAN_DIS_NO"].ToString());
                    ParameterList.Add(dr["RETURN_TYPE"].ToString());
                    ParameterList.Add(dr["RTN_DDL"].ToString());
                    ParameterList.Add(dr["DISPLAY_DAY"].ToString());
                    ParameterList.Add(strUPDATEDATE);
                    ParameterList.Add(strUID);
                    ParameterList.Add(strUPDATEDATE);
                    ParameterList.Add(strUID);
                    dbo.doInsertOne(ParameterList, DBT);
                }


                #region 交易成功

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation成立
                    DBT.Commit();
                }

                #endregion

            }
            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
            }

        }