Exemplo n.º 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
            }
        }
Exemplo n.º 2
0
        //IVM152.aspx
        /// <summary>
        /// 
        /// </summary>
        /// <param name="ParameterList">UserID,PickDate,RemoveNo (移轉單號),ELocateNo(上架儲區),ELocateSec (上架儲位,可Null)</param>
        /// <param name="RootDBT"></param>
        /// <param name="OK"></param>
        /// <param name="PickNo"></param>
        /// <returns></returns>
        public bool CreateByTrans(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 PickDataNo = string.Empty;
            string UserID = ParameterList[0].ToString();
            string PickDate = ParameterList[1].ToString();
            string RemoveNo = ParameterList[2].ToString();
            string ELocateNo = ParameterList[3].ToString();
            string ELocateSec = ParameterList[4].ToString();

            string LocateAttr = string.Empty;

            try
            {
                DBO.VDS_IVM15_DBO IVMDBO = new VDS_IVM15_DBO(ref USEDB);
                DBOINV.MaintainStockTmpLocate INVDBO = new DBOINV.MaintainStockTmpLocate(strConn);
                DBOINV.RecordingStockStatement INVDBO2 = new DBOINV.RecordingStockStatement(strConn);

                //判斷是否有傳入Root Transcation 
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region 啟動交易或指定RootTranscation

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

                #endregion

                //取得應揀貨資料
                DataTable dtPickData = IVMDBO.GetRemovePickData(RemoveNo);

                if (dtPickData.Rows.Count == 0)
                {
                    OK = "0";
                    PickNo = "";
                    return false;
                }
                else
                {
                    for (int i = 0; i < dtPickData.Rows.Count; i++)
                    {
                        if (int.Parse(dtPickData.Rows[i]["onhd_qty"].ToString()) < int.Parse(dtPickData.Rows[i]["IniPickQty"].ToString()))
                        {
                            OK = "2";
                        }
                    }
                }

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

                for (int i = 0; i < dtPickData.Rows.Count; i++)
                {
                    if (dtPickData.Rows[i]["BLocateNo"].ToString() != ELocateNo) //上下不同儲區,一定要上到入庫暫存儲位
                    {
                        DBOPara.Clear();
                        DBOPara.Add(ELocateNo);
                        DBOPara.Add("1");
                        string TempELocate = INVDBO.QueryLocateByAttr(DBOPara);
                        dtPickData.Rows[i]["ELocateSec"] = TempELocate;
                        if (TempELocate.Length > 0)
                        {
                            dtPickData.Rows[i]["ELocateNo"] = TempELocate.Substring(0,1);
                        }
                    }
                    else //上下同儲區
                    {
                        //
                        if (ELocateSec != string.Empty && ELocateSec.Length == 5 ) //上下同儲區,而使用者又指定上架儲位的狀況下,依使用者所指定
                        {
                            dtPickData.Rows[i]["ELocateNo"] = ELocateNo;
                            dtPickData.Rows[i]["ELocateSec"] = ELocateNo+ELocateSec;
                        }
                        else //上下同儲區,使用者又未指定儲位
                        {
                            LocateAttr = string.Empty;
                            DBOPara.Clear();
                            DBOPara.Add(dtPickData.Rows[i]["BLocateSec"].ToString());
                            LocateAttr = INVDBO.QueryAttrByLocateSec(DBOPara);
                            if (LocateAttr == string.Empty) //表示下架儲位是一般儲位,所以要上到出庫暫存儲位
                            {
                                DBOPara.Clear();
                                DBOPara.Add(ELocateNo);
                                DBOPara.Add("2");
                                string TempELocate = INVDBO.QueryLocateByAttr(DBOPara);
                                dtPickData.Rows[i]["ELocateSec"] = TempELocate;
                                if (TempELocate != string.Empty)
                                {
                                    dtPickData.Rows[i]["ELocateNo"] = TempELocate.Substring(0, 1);
                                }
                            }
                            else //表示下架儲位是 出/入 庫暫存儲位,要上到一般儲格
                            { 
                                DBOPara.Clear();
                                DBOPara.Add(ELocateNo);
                                DBOPara.Add(dtPickData.Rows[i]["item"].ToString());
                                DBOPara.Add(dtPickData.Rows[i]["period"].ToString());
                                string GeneralELocate = INVDBO2.QueryMinStockSecCode(DBOPara);
                                dtPickData.Rows[i]["ELocateSec"] = GeneralELocate;
                                if (GeneralELocate != string.Empty)
                                {
                                    dtPickData.Rows[i]["ELocateNo"] = GeneralELocate.Substring(0, 1);
                                }
                                else
                                {
                                    dtPickData.Rows[i]["ELocateNo"] = ELocateNo;
                                }
                            }
                        }
                    }
                }

                DataView dv = new DataView(dtPickData);
                dv.Sort="BLOCATENO,ELOCATENO asc";
                DataTable dtInsert = dv.ToTable();

                ArrayList LocateNoList = new ArrayList();

                //取得儲位類型 BLocateNo + ElocateNo不同視為相異
                for (int i = 0; i < dtInsert.Rows.Count;i++ )
                {
                    string BNo = dtInsert.Rows[i]["BLOCATENO"].ToString();
                    string ENo = dtInsert.Rows[i]["ELOCATENO"].ToString();

                    bool InList = false;
                    for (int j = 0; j < LocateNoList.Count; j++)
                    {
                        InList = false;
                        string BNO = LocateNoList[j].ToString().Split(',')[0];
                        string ENO = LocateNoList[j].ToString().Split(',')[1];

                        if (BNo == BNO && ENo == ENO)
                        {
                            InList = true; 
                        }
                    }
                    if (InList == false)
                        LocateNoList.Add(BNo + "," + ENo);
                }

                for (int i = 0; i < LocateNoList.Count; i++)
                {
                    string TempPickNo = string.Empty;
                    int TempMainID = -1;

                    string NewBNo = LocateNoList[i].ToString().Split(',')[0];
                    string NewENO = LocateNoList[i].ToString().Split(',')[1];

                    int TempInsertCount = 0;
                    DBOPara.Clear();
                    DBOPara.Add(GetValueSetParameter(UserID,"string",false));
                    DBOPara.Add(GetValueSetParameter("","string",false));
                    DBOPara.Add(GetValueSetParameter("","string",false));
                    DBOPara.Add(GetValueSetParameter(PickDate,"string",false));
                    DBOPara.Add(GetValueSetParameter("1","int",false));
                    DBOPara.Add(GetValueSetParameter(RemoveNo,"string",false));
                    TempInsertCount = IVMDBO.CreatePickMain(DBOPara, DBT, out TempMainID, out TempPickNo);

                    if (TempInsertCount == 0)
                    {
                        throw new Exception("新增揀貨單主檔失敗");
                    }

                    for (int j = 0; j < dtInsert.Rows.Count; j++)
                    {
                        if (NewBNo == dtInsert.Rows[j]["BLOCATENO"].ToString() && NewENO == dtInsert.Rows[j]["ELOCATENO"].ToString())
                        {
                            string item = dtInsert.Rows[j]["item"].ToString();
                            string period = dtInsert.Rows[j]["period"].ToString();
                            int onhd_qty = int.Parse(dtInsert.Rows[j]["onhd_qty"].ToString());
                            int IniPickQty = int.Parse(dtInsert.Rows[j]["IniPickQty"].ToString());
                            int RealPickQty = int.Parse(dtInsert.Rows[j]["IniPickQty"].ToString());
                            string strBLocateNo = dtInsert.Rows[j]["BLOCATENO"].ToString();
                            string strBLocateSec = dtInsert.Rows[j]["BLOCATESEC"].ToString();
                            string strELocateNo = dtInsert.Rows[j]["ELOCATENO"].ToString();
                            string strELocateSec = dtInsert.Rows[j]["ELOCATESEC"].ToString();

                            DBOPara.Clear();
                            DBOPara.Add(GetValueSetParameter(UserID,"string",false));
                            DBOPara.Add(GetValueSetParameter(PickDate,"string",false));
                            DBOPara.Add(GetValueSetParameter(TempMainID.ToString(),"string",false));
                            DBOPara.Add(GetValueSetParameter(item,"string",false));
                            DBOPara.Add(GetValueSetParameter(period,"string",false));
                            DBOPara.Add(GetValueSetParameter(onhd_qty.ToString(),"int",false));
                            DBOPara.Add(GetValueSetParameter(IniPickQty.ToString(),"int",false));
                            DBOPara.Add(GetValueSetParameter(RealPickQty.ToString(),"int",false));
                            DBOPara.Add(GetValueSetParameter(strBLocateNo,"string",false));
                            DBOPara.Add(GetValueSetParameter(strBLocateSec,"string",false));
                            DBOPara.Add(GetValueSetParameter(strELocateNo,"string",false));
                            DBOPara.Add(GetValueSetParameter(strELocateSec,"string",false));
                            DBOPara.Add(GetValueSetParameter("","int",false));
                            IVMDBO.CreatePickDetl(DBOPara, DBT);
                        }
                    }

                    DBOPara.Clear();
                    DBOPara.Add(GetValueSetParameter(UserID, "string", false));
                    DBOPara.Add(GetValueSetParameter(PickDate, "string", false));
                    DBOPara.Add(GetValueSetParameter(TempMainID.ToString(), "int", false));
                    DBOPara.Add(GetValueSetParameter(TempPickNo, "string", false));
                    DBOPara.Add(GetValueSetParameter(RemoveNo, "string", false));
                    DBOPara.Add(GetValueSetParameter("1", "int", false));
                    IVMDBO.CreatePickMapNo(DBOPara, DBT);

                    PickNo += TempPickNo + ",";
                }

                #region 交易成功

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

                if (PickNo.Length > 0)
                {
                    PickNo = PickNo.Substring(0, PickNo.Length - 1);
                }

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