Exemplo n.º 1
0
        /// <summary>
        /// 根據使用者輸入的揀貨單號建立移轉單
        /// </summary>
        /// <param name="UserID">使用者名稱</param>
        /// <param name="RemoveData">移轉單日期</param>
        /// <param name="RemoveReason">移轉原因</param>
        /// <param name="PickNo">揀貨單號</param>
        /// <param name="UpdateTime">更新時間(辨認是否有兩人以上編輯資料)</param>
        /// <param name="RootDBT">交易</param>
        /// <param name="RemoveNo">回傳1.移轉單號</param>
        /// <param name="ErrorList">回轉2.庫存不足的ITEMList(逗點分隔)</param>
        /// <returns>Boolean True:成功 False:失敗</returns>
        public bool CreateRemoveByPickNo(string UserID, string RemoveDate, string RemoveReason, string PickNo, string UpdateTime, DbTransaction RootDBT, out string RemoveNo, out string ErrorList)
        {
            RemoveNo = string.Empty; //移轉單號
            bool IsOk = false; //是否新增成功
            bool IsRootTranscation = false;
            ErrorList = string.Empty;

            ArrayList ParameterList = new ArrayList();

            try
            {
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region 啟動交易或指定RootTranscation

                if (IsRootTranscation)
                {
                    //獨立呼叫啟動Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }

                #endregion


                DBO.VDS_IVM15_DBO BCOIVM = new DBO.VDS_IVM15_DBO(ref USEDB);
                ParameterList.Clear();
                ParameterList.Add(PickNo);
                ParameterList.Add(RemoveReason);
                ParameterList.Add(UserID);

                int RecCount = BCOIVM.CreateRemoveByPickNo(ParameterList, out RemoveNo, out ErrorList, DBT);

                if (ErrorList.Length != 0)
                {
                    if (IsRootTranscation)
                    {
                        //獨立呼叫Transcation失敗
                        DBT.Rollback();
                        return false;
                    }
                    else
                    {
                        throw new Exception(ErrorList);
                    }
                }

                DBO.VDS_IVM16_DBO BCO = new DBO.VDS_IVM16_DBO(ref USEDB);

                ParameterList.Clear();
                ParameterList.Add(UserID);
                ParameterList.Add(PickNo);
                ParameterList.Add(RemoveNo);
                ParameterList.Add(RemoveDate);
                ParameterList.Add(UpdateTime);
                BCO.UpdateRemoveNoByPickNo(ParameterList, DBT);

                #region 交易成功

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

                return true;

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

        }