コード例 #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_STOREASSIGN_DETL_DBO ALOD = new VDS_ALO_STOREASSIGN_DETL_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();

                if (dtForDetailAdded != null)
                {
                    for (Int32 i = 0; i <= dtForDetailAdded.Rows.Count - 1; i++)
                    {
                        if (dtForDetailAdded.Rows[i].RowState == DataRowState.Added)
                        {
                            #region
                            ParameterList.Clear();
                            ParameterList.Add(dtForDetailAdded.Rows[i]["dPID"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["dCREATEDATE"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["dCREATEUID"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["dUPDATEDATE"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["dUPDATEUID"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["ROOT_NO"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["PMA"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["PATTERN"]);
                            ParameterList.Add(dtForDetailAdded.Rows[i]["ITEM"]);
                            ALOD.doCreate(ParameterList, DBT);
                            #endregion
                        }
                    }
                }

                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]["dID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["dPID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["dCREATEDATE"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["dCREATEUID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["dUPDATEDATE"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["dUPDATEUID"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["ROOT_NO"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["PMA"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["PATTERN"]);
                            ParameterList.Add(dtForDetailDeleted.Rows[i]["ITEM"]);
                            ParameterList.Add(strUIDForLog);
                            ALOD.doDelete(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

            }
        }
コード例 #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_STOREASSIGN_DETL_DBO ALOD = new VDS_ALO_STOREASSIGN_DETL_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();

                if (DetailData != null)
                {
                    for (Int32 i = 0; i <= DetailData.Rows.Count - 1; i++)
                    {
                        ParameterList.Clear();
                        ParameterList.Add(PID);
                        ParameterList.Add(DetailData.Rows[i]["CREATEDATE"]);
                        ParameterList.Add(DetailData.Rows[i]["CREATEUID"]);
                        ParameterList.Add(DetailData.Rows[i]["UPDATEDATE"]);
                        ParameterList.Add(DetailData.Rows[i]["UPDATEUID"]);
                        ParameterList.Add(DetailData.Rows[i]["ROOT_NO"]);
                        ParameterList.Add(DetailData.Rows[i]["PMA"]);
                        ParameterList.Add(DetailData.Rows[i]["PATTERN"]);
                        ParameterList.Add(DetailData.Rows[i]["ITEM"]);
                        ALOD.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

            }
        }