Ejemplo n.º 1
0
        /// <summary>
        /// 基本表單更新BCO
        /// </summary>
        /// <param name="DetailData">更新變數</param>
        /// <param name="RootDBT">是否有主交易,無主交易輸入null</param>
        /// <returns>回傳成功與否</returns>
        public bool UpdateDetail(DataTable dtForDetailAdded, string strUIDForLog, DataTable dtForDetailDeleted, DbTransaction RootDBT)
        {
            bool IsRootTranscation = false;
            bool bResult = false;
            try
            {
                VDS_ALO_DISCOPY_CHAN_DBO DBO = new VDS_ALO_DISCOPY_CHAN_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();
                ArrayList ParameterList2 = new ArrayList();

                if (dtForDetailDeleted != null)
                {
                    for (Int32 i = 0; i <= dtForDetailDeleted.Rows.Count - 1; i++)
                    {
                        if (dtForDetailDeleted.Rows[i].RowState != DataRowState.Deleted)
                        {
                            #region
                            ParameterList.Clear();
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["ID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["PID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["CREATEDATE"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["CREATEUID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["UPDATEDATE"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["UPDATEUID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["CHAN_NO"]);
                            ParameterList.Add(strUIDForLog);
        
                            DBO.doDelete(ParameterList, DBT);
                            #endregion
                        }
                    }
                }

                if (dtForDetailAdded != null && dtForDetailAdded.Rows.Count > 0)
                {
                    if (dtForDetailDeleted == null)//如果新增dt有變動且刪除dt為null
                    {
                        ParameterList2.Clear();
                        ParameterList2.Add(dtForDetailAdded.Rows[0]["PID"]);
                        DBO.doDeleteWhenUpdate(ParameterList2, DBT);
                    }

                    for (Int32 i = 0; i <= dtForDetailAdded.Rows.Count - 1; i++)
                    {
                        if ((dtForDetailAdded.Rows[i].RowState == DataRowState.Added) || (dtForDetailAdded.Rows[i].RowState == DataRowState.Modified))
                        {
                            #region
                            ParameterList.Clear();
                            ParameterList.Add(dtForDetailAdded.Rows[i]["PID"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["CHAN_NO"]);
                            ParameterList.Add(strUIDForLog);
                            DBO.doCreate(ParameterList, DBT);
                            #endregion
                        }
                    }
                }



                #region 交易成功

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

                #endregion

                bResult = true;

                return bResult;
            }
            catch (Exception ex)
            {
                #region 交易失敗

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation失敗
                    DBT.Rollback();
                }

                #endregion

                throw GetNewException(ex);
            }
            finally
            {
                #region 判斷是否關閉交易連線

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation,關閉連線
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 基本表單新增BCO
        /// </summary>
        /// <param name="DetailData">輸入變數</param>
        /// <param name="RootDBT">是否有主交易,無主交易輸入null</param>
        /// <returns>回傳異動筆數</returns>
        public void CreateDetail(Int32 PID, DataTable DetailData, DbTransaction RootDBT)
        {
            bool IsRootTranscation = false;
            try
            {
                VDS_ALO_DISCOPY_CHAN_DBO DBO = new VDS_ALO_DISCOPY_CHAN_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();

                for (Int32 i = 0; i <= DetailData.Rows.Count - 1; i++)
                {
                    if (DetailData.Rows[i].RowState != DataRowState.Deleted)
                    {
                        ParameterList.Clear();
                        ParameterList.Add(PID);
                        ParameterList.Add(DetailData.Rows[i]["CHAN_NO"]);
                        ParameterList.Add(DetailData.Rows[i]["USERID"]);
                        DBO.doCreate(ParameterList, DBT);

                    }
                }

                #region 交易成功

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

                #endregion

            }
            catch (Exception ex)
            {
                #region 交易失敗

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation失敗
                    DBT.Rollback();
                }

                #endregion

                throw GetNewException(ex);
            }
            finally
            {
                #region 判斷是否關閉交易連線

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation,關閉連線
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }
        }