示例#1
0
        //IVM153.aspx
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ParameterList">UserID、PickDate、InOutDate、InOutNo、PMA、RootNo、BLocateSec、ELocateSec</param>
        /// <param name="RootDBT">傳入的交易</param>
        /// <param name="OK">回傳參數 0.無資料 1.成功 3.</param>
        /// <param name="PickNo">揀貨單號</param>
        /// <returns>回傳是否成功</returns>
        public bool CreateByBackWard(ArrayList ParameterList, DbTransaction RootDBT, out string OK, out string PickNo)
        {
            OK = string.Empty;
            PickNo = string.Empty;
            ArrayList DBOPara = new ArrayList();
            bool IsRootTranscation = false;
            int PID = -1;

            string UserID = ParameterList[0].ToString();
            string PickDate = ParameterList[1].ToString();
            string InOutDate = ParameterList[2].ToString();
            string InOutNo = ParameterList[3].ToString(); 
            string PMA = ParameterList[4].ToString();
            string RootNo = ParameterList[5].ToString();
            string BLocateSec = ParameterList[6].ToString();
            string BLocateNo = string.Empty;
            if (BLocateSec.Length > 0)
                BLocateNo = BLocateSec.Substring(0, 1);
            string ELocateSec = ParameterList[7].ToString();
            string ELocateNo = string.Empty;
            if (ELocateSec.Length > 0)
                ELocateNo = ELocateSec.Substring(0, 1);

            try
            {

                DBO.VDS_IVM15_DBO IVMDBO = new VDS_IVM15_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

                DBOPara.Clear();
                DBOPara.Add(GetValueSetParameter(InOutDate, "string",false));
                DBOPara.Add(GetValueSetParameter(InOutNo, "string", false));
                DBOPara.Add(GetValueSetParameter(PMA, "string", false));
                DBOPara.Add(GetValueSetParameter(RootNo, "string", false));
                DBOPara.Add(GetValueSetParameter(BLocateSec, "string", false));

                DataTable dtPickData = IVMDBO.GetPickDataByReturn(DBOPara);

                if (dtPickData.Rows.Count == 0)
                {
                    OK = "0";
                    PickNo = "";
                    return false;
                }
                else
                {
                    for (int i = 0; i < dtPickData.Rows.Count; i++)
                    {
                        if (dtPickData.Rows[i]["Pick_No"].ToString() != string.Empty)
                        {
                            OK = "3";
                            PickNo = "";
                            return false;
                        }

                        if (int.Parse(dtPickData.Rows[i]["onhd_qty"].ToString()) < int.Parse(dtPickData.Rows[i]["IniPickQty"].ToString()))
                        {
                            OK = "2";
                        }
                    }
                }

                if (OK != "2")
                {
                    OK = "1";
                }

                #region


                DBOPara.Clear();
                DBOPara.Add(GetValueSetParameter(UserID, "string", false));
                DBOPara.Add(GetValueSetParameter(InOutDate, "string", false));
                DBOPara.Add(GetValueSetParameter("", "string", false));
                DBOPara.Add(GetValueSetParameter(PickDate, "string", false));
                DBOPara.Add(GetValueSetParameter("2", "int", false));
                DBOPara.Add(GetValueSetParameter("", "string", false));

                IVMDBO.CreatePickMain(DBOPara, DBT, out PID, out PickNo);

                for (int i = 0; i < dtPickData.Rows.Count; i++)
                {
                    DBOPara.Clear();
                    DBOPara.Add(GetValueSetParameter(UserID, "string", false));
                    DBOPara.Add(GetValueSetParameter(PickDate, "string", false));
                    DBOPara.Add(GetValueSetParameter(PID.ToString(), "int", false));
                    DBOPara.Add(GetValueSetParameter(dtPickData.Rows[i]["item"].ToString(), "string", false));
                    DBOPara.Add(GetValueSetParameter(dtPickData.Rows[i]["period"].ToString(), "string", false));
                    DBOPara.Add(GetValueSetParameter(dtPickData.Rows[i]["onhd_qty"].ToString(), "int", false));
                    DBOPara.Add(GetValueSetParameter(dtPickData.Rows[i]["IniPickQty"].ToString(), "int", false));
                    DBOPara.Add(GetValueSetParameter(dtPickData.Rows[i]["IniPickQty"].ToString(), "int", false));
                    DBOPara.Add(GetValueSetParameter(BLocateNo, "string", false));
                    DBOPara.Add(GetValueSetParameter(BLocateSec, "string", false));
                    DBOPara.Add(GetValueSetParameter(ELocateNo, "string", false));
                    DBOPara.Add(GetValueSetParameter(ELocateSec, "string", false));
                    DBOPara.Add(GetValueSetParameter("", "int", false));

                    IVMDBO.CreatePickDetl(DBOPara, DBT);
                }

                if (InOutNo != string.Empty)
                {
                    DBOPara.Clear();
                    DBOPara.Add(GetValueSetParameter(UserID, "string", false));
                    DBOPara.Add(GetValueSetParameter(PickDate, "string", false));
                    DBOPara.Add(GetValueSetParameter(PID.ToString(), "int", false));
                    DBOPara.Add(GetValueSetParameter(PickNo, "string", false));
                    DBOPara.Add(GetValueSetParameter(InOutNo, "string", false));
                    DBOPara.Add(GetValueSetParameter("2", "int", false));
                    IVMDBO.CreatePickMapNo(DBOPara, DBT);
                }
                else
                {
                    DBOPara.Clear();
                    DBOPara.Add(GetValueSetParameter(UserID, "string", false));
                    DBOPara.Add(GetValueSetParameter(PickDate, "string", false));
                    DBOPara.Add(GetValueSetParameter(InOutDate, "string", false));
                    DBOPara.Add(GetValueSetParameter(InOutNo, "string", false));
                    DBOPara.Add(GetValueSetParameter(PMA, "string", false));
                    DBOPara.Add(GetValueSetParameter(RootNo, "string", false));
                    DBOPara.Add(GetValueSetParameter(BLocateSec, "string", false));
                    DBOPara.Add(GetValueSetParameter(PickNo, "string", false));
                    DBOPara.Add(GetValueSetParameter(PID.ToString(), "int", false));
                    DBOPara.Add(GetValueSetParameter("2", "int", false));
                    IVMDBO.CreatePickMapNoByReturn(DBOPara, DBT);
                }

                DBOPara.Clear();
                DBOPara.Add(GetValueSetParameter(UserID, "string", false));
                DBOPara.Add(GetValueSetParameter(PickDate, "string", false));
                DBOPara.Add(GetValueSetParameter(InOutDate, "string", false));
                DBOPara.Add(GetValueSetParameter(InOutNo, "string", false));
                DBOPara.Add(GetValueSetParameter(PMA, "string", false));
                DBOPara.Add(GetValueSetParameter(RootNo, "string", false));
                DBOPara.Add(GetValueSetParameter(BLocateSec, "string", false));
                DBOPara.Add(GetValueSetParameter(PickNo, "string", false));
                IVMDBO.UpdateStockInPickNo(DBOPara, DBT);

                #endregion

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