Exemplo n.º 1
0
        /// <summary>
        /// 依照揀貨單號建立移轉單
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="RemoveDate"></param>
        /// <param name="RemoveReason"></param>
        /// <param name="PickNo"></param>
        /// <param name="RootDBT"></param>
        /// <param name="RemoveNo"></param>
        /// <param name="ErrorList"></param>
        /// <returns></returns>
        public bool CreateRemoveByPick(string UserID, string RemoveDate, string RemoveReason, string FunNo, string PickNo,string UpdateTime, DbTransaction RootDBT, out string RemoveNo, out ArrayList ErrorList)
        {
            RemoveNo = string.Empty;

            string MainID = string.Empty;

            bool IsOK = false;

            bool IsRootTranscation = false;

            ArrayList ParameterList = new ArrayList();

            ArrayList ItemQtyList = 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_IVM16_DBO BCOIVM = new DBO.VDS_IVM16_DBO(ref USEDB);

                ParameterList.Clear();
                ParameterList.Add(PickNo);
                DataTable dtCreate = BCOIVM.GetRemoveDataByPick(ParameterList);

                DBO.MaintainRemoveData BCO = new DBO.MaintainRemoveData(strConn);

                ParameterList.Clear();
                ParameterList.Add(UserID);
                ParameterList.Add(RemoveDate);
                ParameterList.Add(RemoveReason);

                if (FunNo == "8" || FunNo == "6")
                {
                    //拆開之前判斷有沒有空間
                    //建立新的DATATABLE儲存SUMMARY的移出儲位及儲位數量
                    DataTable dtSpace = new DataTable();
                    dtSpace.Columns.Add("OutLocateSection");
                    dtSpace.Columns.Add("InLocateSection"); //充數欄位
                    dtSpace.Columns.Add("Item");
                    dtSpace.Columns.Add("Period");
                    dtSpace.Columns.Add("Remove_Qty");

                    //計算移出欄位數量,並加總

                    for (int i = 0; i < dtCreate.Rows.Count; i++)
                    {
                        string OutLocateSection = dtCreate.Rows[i][0].ToString();
                        string InLocateSection = "";
                        string Item = dtCreate.Rows[i][2].ToString();
                        string Period = dtCreate.Rows[i][3].ToString();
                        string RemoveQty = dtCreate.Rows[i][4].ToString();

                        bool HaveSec = false;
                        int U = -1;

                        for (int x = 0; x < dtSpace.Rows.Count; x++)
                        {
                            if (OutLocateSection == dtSpace.Rows[x]["OutLocateSection"].ToString() &&
                               Item == dtSpace.Rows[x]["Item"].ToString() &&
                               Period == dtSpace.Rows[x]["Period"].ToString())
                            {
                                HaveSec = true;
                                U = x;
                            }
                        }

                        if (HaveSec == true)
                        {
                            dtSpace.Rows[U]["Remove_Qty"] = int.Parse(dtSpace.Rows[U]["Remove_Qty"].ToString()) + int.Parse(RemoveQty);
                        }
                        else
                        {
                            DataRow drSpace = dtSpace.NewRow();
                            drSpace["OutLocateSection"] = OutLocateSection;
                            drSpace["InLocateSection"] = InLocateSection;
                            drSpace["Item"] = Item;
                            drSpace["Period"] = Period;
                            drSpace["Remove_Qty"] = RemoveQty;
                            dtSpace.Rows.Add(drSpace);
                        }
                    }

                    bool HaveSpace = BCO.CheckSpace(dtSpace, out ErrorList, out ItemQtyList);

                    if (HaveSpace == true)
                    {
                        ParameterList.Add("Y");
                        DataTable dtResult = SplitSectionSecData(dtCreate);
                        IsOK = BCO.CreateRemoveData(ParameterList, dtResult, DBT, out MainID, out RemoveNo, out ErrorList);
                    }
                    else
                    {
                        IsOK = false;
                    }
                }
                else
                {
                    IsOK = BCO.CreateRemoveData(ParameterList, dtCreate, DBT, out MainID, out RemoveNo, out ErrorList);
                }

                if (IsOK == false)
                {
                    return false;
                }

                ParameterList.Clear();
                ParameterList.Add(UserID);
                ParameterList.Add(PickNo);
                ParameterList.Add(RemoveNo);
                ParameterList.Add(RemoveDate);
                ParameterList.Add(UpdateTime);
                BCOIVM.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
            }
        }
Exemplo n.º 2
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
            }

        }