public bool DoUpdate(string MainID, string UserID, string UpdateDate, string UpdateTime, DataTable dtUpdate, DbTransaction RootDBT, out string ErrorLog) { bool IsRootTranscation = false; 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 //檢查必要條件是否已輸入 ErrorLog = ""; for (int i = 0; i < dtUpdate.Rows.Count; i++) { string FID = dtUpdate.Rows[i]["FatherID"].ToString(); string BLocateSec = dtUpdate.Rows[i]["Blocate_Section"].ToString(); string ELocateSec = dtUpdate.Rows[i]["Elocate_Section"].ToString(); string PickQty = dtUpdate.Rows[i]["real_pick_qty"].ToString(); if (FID == string.Empty || BLocateSec.Length != 6 || ELocateSec.Length != 6 || PickQty == string.Empty) { ErrorLog = "資料輸入不完整"; return false; } } ArrayList ParameterList = new ArrayList(); //更新並比對主檔資料 ParameterList.Clear(); ParameterList.Add(MainID); ParameterList.Add(UserID); ParameterList.Add(UpdateDate); ParameterList.Add(UpdateTime); IVMDBO.UpdatePickMain(ParameterList, DBT); for (int i = 0; i < dtUpdate.Rows.Count; i++) { string IsChange = dtUpdate.Rows[i]["isChange"].ToString(); if (IsChange == "Y") { ErrorLog = "更新資料失敗"; string Item = dtUpdate.Rows[i]["Item"].ToString(); string Period = dtUpdate.Rows[i]["Period"].ToString(); string OnhdQty = dtUpdate.Rows[i]["BOnhd_Qty"].ToString(); string IniPickQty = dtUpdate.Rows[i]["ini_pick_qty"].ToString(); string RealPickQty = dtUpdate.Rows[i]["real_pick_qty"].ToString(); string BLocateNo = dtUpdate.Rows[i]["Blocate_Section"].ToString().Substring(0, 1); string BLocateSec = dtUpdate.Rows[i]["Blocate_Section"].ToString(); string ELocateNo = dtUpdate.Rows[i]["Elocate_Section"].ToString().Substring(0, 1); string ELocateSec = dtUpdate.Rows[i]["Elocate_Section"].ToString(); string OldBSec = dtUpdate.Rows[i]["OLDBSec"].ToString(); string OldESec = dtUpdate.Rows[i]["OLDESec"].ToString(); if (OldESec.Length == 1) OldESec = ""; string ID = dtUpdate.Rows[i]["id"].ToString(); string PID = dtUpdate.Rows[i]["pid"].ToString(); string FatherId = dtUpdate.Rows[i]["FatherId"].ToString(); ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(UserID, "string", false)); ParameterList.Add(GetValueSetParameter(UpdateDate, "string", false)); ParameterList.Add(GetValueSetParameter(PID, "int", false)); ParameterList.Add(GetValueSetParameter(Item, "string", false)); ParameterList.Add(GetValueSetParameter(Period, "string", false)); ParameterList.Add(GetValueSetParameter(OnhdQty, "int", false)); ParameterList.Add(GetValueSetParameter(IniPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(RealPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(BLocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(BLocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(OldBSec, "string", false)); ParameterList.Add(GetValueSetParameter(OldESec, "string", false)); ParameterList.Add(GetValueSetParameter(ID, "int", false)); ParameterList.Add(GetValueSetParameter(FatherId, "int", false)); IVMDBO.UpdatePickDetl(ParameterList, DBT); } } for (int i = 0; i < dtUpdate.Rows.Count; i++) { string IsChange = dtUpdate.Rows[i]["isChange"].ToString(); if (IsChange == "New") { ErrorLog = "新增資料失敗"; string Item = dtUpdate.Rows[i]["Item"].ToString(); string Period = dtUpdate.Rows[i]["Period"].ToString(); string OnhdQty = dtUpdate.Rows[i]["BOnhd_Qty"].ToString(); string IniPickQty = dtUpdate.Rows[i]["ini_pick_qty"].ToString(); string RealPickQty = dtUpdate.Rows[i]["real_pick_qty"].ToString(); string BLocateNo = dtUpdate.Rows[i]["Blocate_Section"].ToString().Substring(0, 1); string BLocateSec = dtUpdate.Rows[i]["Blocate_Section"].ToString(); string ELocateNo = dtUpdate.Rows[i]["Elocate_Section"].ToString().Substring(0, 1); string ELocateSec = dtUpdate.Rows[i]["Elocate_Section"].ToString(); string FatherID = dtUpdate.Rows[i]["FatherID"].ToString(); string PID = dtUpdate.Rows[i]["pid"].ToString(); ParameterList.Clear(); ParameterList.Add(GetValueSetParameter(UserID, "string", false)); ParameterList.Add(GetValueSetParameter(UpdateDate, "string", false)); ParameterList.Add(GetValueSetParameter(PID, "int", false)); ParameterList.Add(GetValueSetParameter(Item, "string", false)); ParameterList.Add(GetValueSetParameter(Period, "string", false)); ParameterList.Add(GetValueSetParameter(OnhdQty, "int", false)); ParameterList.Add(GetValueSetParameter(IniPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(RealPickQty, "int", false)); ParameterList.Add(GetValueSetParameter(BLocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(BLocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateNo, "string", false)); ParameterList.Add(GetValueSetParameter(ELocateSec, "string", false)); ParameterList.Add(GetValueSetParameter(FatherID, "int", false)); IVMDBO.CreatePickDetl(ParameterList, DBT); } } #region 交易成功 if (IsRootTranscation) { //獨立呼叫Transcation成立 DBT.Commit(); ErrorLog = string.Empty; } 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 } }
//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 } }
//IVM154.aspx /// <summary> /// 建立揀貨單(門市進貨剩餘移轉) /// </summary> /// <param name="ParameterList">UserID、PickDate、AcceptDate、BLocateSec、ELocateSec</param> /// <param name="RootDBT">傳入的交易</param> /// <param name="OK">OK Flag</param> /// <param name="PickNo">新增的PickNo</param> /// <returns></returns> public bool CreateByLeftTrans(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 AcceptDate = ParameterList[2].ToString(); string BLocateSec = ParameterList[3].ToString(); string ELocateSec = ParameterList[4].ToString(); string BLocateNo = string.Empty; if (BLocateSec.Length > 0) BLocateNo = BLocateSec.Substring(0, 1); 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(AcceptDate,"string",false)); DBOPara.Add(GetValueSetParameter(BLocateSec,"string",false)); DataTable dtPickData = IVMDBO.GetPickDatabyTrans(DBOPara); if (dtPickData.Rows.Count == 0) { OK = "0"; PickNo = ""; return false; } else { OK = "1"; } DBOPara.Clear(); DBOPara.Add(GetValueSetParameter(UserID, "string", false)); DBOPara.Add(GetValueSetParameter(AcceptDate, "string", false)); DBOPara.Add(GetValueSetParameter("", "string", false)); DBOPara.Add(GetValueSetParameter(PickDate, "string", false)); DBOPara.Add(GetValueSetParameter("3", "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]["RealPickQty"].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); } #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 } }
//IVM158.aspx /// <summary> /// 客服查補 /// </summary> /// <param name="ParameterList">UserID,PickDate,TransDate,AcceptDate</param> /// <param name="RootDBT">傳入的交易</param> /// <param name="OK">OK FLAG</param> /// <param name="PickNo">回傳的揀貨單號</param> /// <returns></returns> public bool CreateByCRMTrans(ArrayList ParameterList, DbTransaction RootDBT, out string OK, out string PickNo) { OK = string.Empty; string SubOK = string.Empty; PickNo = string.Empty; //string PickDataNo = ""; ArrayList DBOPara = new ArrayList(); bool IsRootTranscation = false; //int PID = -1; string UserID = ParameterList[0].ToString(); string PickDate = ParameterList[1].ToString(); string TransDate = ParameterList[2].ToString(); string AcceptDate = ParameterList[3].ToString(); 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(TransDate, "string", false)); DBOPara.Add(GetValueSetParameter(AcceptDate, "string", false)); DataTable dtPickData = IVMDBO.GetPickDataByCRMTrans(DBOPara); DataTable dtSumPickData = IVMDBO.GetSumPickDataByCRMTrans(DBOPara); if (dtSumPickData.Rows.Count == 0) { OK = "0"; PickNo = ""; return false; } else { OK = "1"; } DataTable DtNew = new DataTable(); DtNew.Columns.Add("Item", System.Type.GetType("System.String")); DtNew.Columns.Add("period", System.Type.GetType("System.String")); DtNew.Columns.Add("OnHD_Qty", System.Type.GetType("System.Int32")); DtNew.Columns.Add("IniPickQty", System.Type.GetType("System.Int32")); DtNew.Columns.Add("RealPickQty", System.Type.GetType("System.Int32")); DtNew.Columns.Add("BLocateNo", System.Type.GetType("System.String")); DtNew.Columns.Add("BLocateSection", System.Type.GetType("System.String")); DtNew.Columns.Add("ELocateNo", System.Type.GetType("System.String")); DtNew.Columns.Add("ELocateSection", System.Type.GetType("System.String")); //A.Item, //A.Period, //A.SRC_LOCATE_TYPE, //A.SRC_Locate_No, //A.DST_Locate_No, //A.Pick_Qty, //L.LOCATE_SECTION DST_Locate_Section for (int i = 0; i < dtSumPickData.Rows.Count; i++) { DBOPara.Clear(); DBOPara.Add(dtSumPickData.Rows[i]["SRC_Locate_No"].ToString()); DBOPara.Add(dtSumPickData.Rows[i]["SRC_LOCATE_TYPE"].ToString()); DBOPara.Add(dtSumPickData.Rows[i]["Item"].ToString()); DBOPara.Add(dtSumPickData.Rows[i]["Period"].ToString()); DBOPara.Add(int.Parse(dtSumPickData.Rows[i]["Pick_Qty"].ToString())); //DBOPara.Add(dtPickData.Rows[i]["DST_Locate_Section"].ToString()); //取得庫存資料及揀貨儲位 DataTable dtTemp = GetSugLocateQty(DBOPara, out SubOK); if (SubOK == "2") { OK = "2"; } if (dtTemp.Rows.Count == 0) { for (int x = 0; x < dtPickData.Rows.Count; x++) { if (dtSumPickData.Rows[i]["Item"].ToString() == dtPickData.Rows[x]["Item"].ToString() && dtSumPickData.Rows[i]["Period"].ToString() == dtPickData.Rows[x]["Period"].ToString() && dtSumPickData.Rows[i]["SRC_Locate_No"].ToString() == dtPickData.Rows[x]["SRC_Locate_No"].ToString()) { DataRow dr = DtNew.NewRow(); dr["item"] = dtPickData.Rows[x]["Item"].ToString(); dr["period"] = dtPickData.Rows[x]["Period"].ToString(); dr["OnHD_Qty"] = 0; dr["IniPickQty"] = 0; dr["RealPickQty"] = dtPickData.Rows[x]["Pick_Qty"].ToString(); dr["BLocateNo"] = dtPickData.Rows[x]["SRC_Locate_No"].ToString(); dr["BLocateSection"] = ""; dr["ELocateNo"] = dtPickData.Rows[x]["DST_Locate_Section"].ToString().Substring(0, 1); dr["ELocateSection"] = ""; DtNew.Rows.Add(dr); } } } //根據資料分配儲區、儲位及數量 for (int y = 0; y < dtPickData.Rows.Count;y++ ) { if (dtSumPickData.Rows[i]["Item"].ToString() == dtPickData.Rows[y]["Item"].ToString() && dtSumPickData.Rows[i]["Period"].ToString() == dtPickData.Rows[y]["Period"].ToString() && dtSumPickData.Rows[i]["SRC_Locate_No"].ToString() == dtPickData.Rows[y]["SRC_Locate_No"].ToString()) for (int j = 0; j < dtTemp.Rows.Count; j++) { if (int.Parse(dtTemp.Rows[j]["RealPickQty"].ToString()) > 0) { int RealPickQty = int.Parse(dtTemp.Rows[j]["RealPickQty"].ToString()); //該儲位被分配到的應揀貨量 int OnHD_Qty = int.Parse(dtTemp.Rows[j]["OnHD_Qty"].ToString()); //該儲位的庫存量 int Pick_Qty = int.Parse(dtPickData.Rows[y]["Pick_Qty"].ToString()); //該商品於該儲區的實際應揀貨量 int Pick = 0; //儲位揀貨量 int Pick_OnHD_Qty = 0; int RemainQty = 0; //分配儲位剩餘量 if(Pick_Qty > 0) { if(RealPickQty >= Pick_Qty) //該儲位數量可以滿足一次揀貨 { RemainQty = RealPickQty - Pick_Qty; //剩餘的應揀貨量 int RemainOnHDQty = OnHD_Qty - Pick_Qty; //該儲位剩餘的庫存量 Pick = Pick_Qty; Pick_OnHD_Qty = OnHD_Qty; //Liea加 dtPickData.Rows[y]["Pick_Qty"] = "0"; dtTemp.Rows[j]["RealPickQty"] = RealPickQty - Pick_Qty;//Liea Pick.ToString(); dtTemp.Rows[j]["OnHD_Qty"] = RemainOnHDQty.ToString(); //Liea if(OnHD_Qty > Pick_Qty) //庫存大於揀貨量 { //Pick_OnHD_Qty = RemainOnHDQty; //Liea Pick_OnHD_Qty = RemainQty; dtTemp.Rows[j]["OnHD_Qty"] = RemainOnHDQty.ToString(); } else //庫存等於揀貨量 { //Pick_OnHD_Qty = 0; //Liea Pick_OnHD_Qty = OnHD_Qty; dtTemp.Rows[j]["OnHD_Qty"] = "0"; } //Liea } else //該儲位數量小於一次揀貨 { RemainQty = 0; Pick = RealPickQty; //該儲位數量全部揀光 int TempQty = Pick_Qty - RealPickQty; dtPickData.Rows[y]["Pick_Qty"] = TempQty.ToString(); Pick_OnHD_Qty = OnHD_Qty; dtTemp.Rows[j]["OnHD_Qty"] = "0"; dtTemp.Rows[j]["RealPickQty"] = "0";//Liea } DataRow dr = DtNew.NewRow(); dr["item"] = dtTemp.Rows[j]["Item"].ToString(); dr["period"] = dtTemp.Rows[j]["period"].ToString(); dr["OnHD_Qty"] = Pick_OnHD_Qty.ToString(); dr["IniPickQty"] = Pick.ToString(); // Liea int.Parse(dtTemp.Rows[j]["IniPickQty"].ToString()); dr["RealPickQty"] = Pick.ToString(); dr["BLocateNo"] = dtTemp.Rows[j]["BLocateNo"].ToString(); dr["BLocateSection"] = dtTemp.Rows[j]["BLocateSection"].ToString(); dr["ELocateNo"] = dtPickData.Rows[y]["DST_Locate_Section"].ToString().Substring(0,1); dr["ELocateSection"] = dtPickData.Rows[y]["DST_Locate_Section"].ToString(); DtNew.Rows.Add(dr); } } } } } DataView dv = new DataView(DtNew); dv.Sort="BLOCATENO,ELOCATENO asc"; DataTable dtInsert = dv.ToTable(); ArrayList LocateNoList = new ArrayList(); //取得儲位類型 BLocateSecList + ElocateSecList不同視為相異 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(AcceptDate,"string",false)); DBOPara.Add(GetValueSetParameter("","string",false)); DBOPara.Add(GetValueSetParameter(PickDate,"string",false)); DBOPara.Add(GetValueSetParameter("7","int",false)); DBOPara.Add(GetValueSetParameter("","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]["RealPickQty"].ToString()); string strBLocateNo = dtInsert.Rows[j]["BLocateNo"].ToString(); string strBLocateSec = dtInsert.Rows[j]["BLocateSection"].ToString(); string strELocateNo = dtInsert.Rows[j]["ELocateNo"].ToString(); string strELocateSec = dtInsert.Rows[j]["ELocateSection"].ToString(); DBOPara.Clear(); DBOPara.Add(GetValueSetParameter(UserID,"string",false)); DBOPara.Add(GetValueSetParameter(PickDate,"string",false)); DBOPara.Add(GetValueSetParameter(TempMainID.ToString(),"int",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(UserID); DBOPara.Add(PickDate); DBOPara.Add(TempPickNo); DBOPara.Add(NewBNo); DBOPara.Add(NewENo); DBOPara.Add(TransDate); DBOPara.Add(AcceptDate); IVMDBO.UpdateCRMOrderDetl(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 } }