using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; namespace SiaSun.LMS.Implement { public class ManageIn:ManageBase { /// /// 生成计划或无计划入库任务 /// 生成托盘入库任务 /// 调用界面 MANAGE_PLAN_IN.XAML MANAGE_IN.XAML MANAGE_STOCK_IN.XAML /// /// /// /// /// /// /// /// /// /// /// /// public bool ManageCreate(SiaSun.LMS.Model.MANAGE_MAIN mMANAGE_MAIN, List lsMANAGE_LIST, bool bTrans, bool bCheckStorage, bool bComplete, bool bAutoSendControl, out string sResult) { bool bResult = true; sResult = string.Empty; int MANAGE_ID = 0; try { SiaSun.LMS.Model.MANAGE_TYPE mMANAGE_TYPE = this._P_MANAGE_TYPE.GetModelManageTypeCode(mMANAGE_MAIN.MANAGE_TYPE_CODE); if (mMANAGE_TYPE == null) { bResult = false; sResult = string.Format("未找到任务类型{0}", mMANAGE_MAIN.MANAGE_TYPE_CODE); return bResult; } if (this._S_StorageService.StorageCheck(mMANAGE_MAIN.STOCK_BARCODE, Enum.AREA_TYPE.LiKu.ToString(), out sResult) && bCheckStorage) { sResult = string.Format("托盘{0}已经在立库区", mMANAGE_MAIN.STOCK_BARCODE); return false; } if (!string.IsNullOrWhiteSpace(lsMANAGE_LIST[0].GOODS_PROPERTY1)) { string sGoodsBarcode = lsMANAGE_LIST[0].GOODS_PROPERTY1; string[] asProperty = sGoodsBarcode.Split('-'); if (asProperty.Length > 6) { sGoodsBarcode = $"{asProperty[0]}-{asProperty[1]}-{asProperty[2]}-{asProperty[3]}-{asProperty[4]}-{asProperty[5]}-"; } DataTable dtStorageList = this.GetList(string.Format("select 0 from STORAGE_LIST where GOODS_PROPERTY1 like '{0}%'", sGoodsBarcode)); if (dtStorageList.Rows.Count > 0) { bResult = false; sResult = string.Format("物料条码{0}已经在立库区", lsMANAGE_LIST[0].GOODS_PROPERTY1); return bResult; } DataTable dtManageList = this.GetList(string.Format("select 0 from MANAGE_LIST where GOODS_PROPERTY1 like '{0}%'", sGoodsBarcode)); if (dtManageList.Rows.Count > 0) { bResult = false; sResult = string.Format("物料条码{0}已存在任务", lsMANAGE_LIST[0].GOODS_PROPERTY1); return bResult; } } if (this._S_StorageService.StorageCheck(mMANAGE_MAIN.STOCK_BARCODE, Enum.AREA_TYPE.XuNiKu.ToString(), out sResult) && bCheckStorage) { sResult = string.Format("托盘{0}库存校验失败\n {1} ", mMANAGE_MAIN.STOCK_BARCODE, "已经存在库存"); return false; } if (this._P_MANAGE_MAIN.GetModelStockBarcode(mMANAGE_MAIN.STOCK_BARCODE) != null) { bResult = false; sResult = string.Format("托盘条码{0}已经存在任务", mMANAGE_MAIN.STOCK_BARCODE); return bResult; } SiaSun.LMS.Model.WH_CELL mWH_CELL_START = this._P_WH_CELL.GetModel(mMANAGE_MAIN.START_CELL_ID); SiaSun.LMS.Model.WH_CELL mWH_CELL_END = this._P_WH_CELL.GetModel(mMANAGE_MAIN.END_CELL_ID); SiaSun.LMS.Model.PLAN_MAIN mPLAN_MAIN = this._P_PLAN_MAIN.GetModel(mMANAGE_MAIN.PLAN_ID); this._P_Base_House.BeginTransaction(bTrans); mMANAGE_MAIN.MANAGE_BEGIN_TIME = SiaSun.LMS.Common.StringUtil.GetDateTime(); this._P_MANAGE_MAIN.Add(mMANAGE_MAIN); foreach (SiaSun.LMS.Model.MANAGE_LIST mMANAGE_LIST in lsMANAGE_LIST) { mMANAGE_LIST.MANAGE_ID = mMANAGE_MAIN.MANAGE_ID; if (!string.IsNullOrWhiteSpace(mMANAGE_LIST.GOODS_PROPERTY2) && mMANAGE_LIST.GOODS_PROPERTY2.Contains("-")) { mMANAGE_LIST.GOODS_PROPERTY2 = string.Join("", mMANAGE_LIST.GOODS_PROPERTY2.Split('-')); } if (mPLAN_MAIN != null) { SiaSun.LMS.Model.PLAN_LIST mIO_PLAN_LIST = this._P_PLAN_LIST.GetModel(mMANAGE_LIST.PLAN_LIST_ID); if (null != mIO_PLAN_LIST) { mIO_PLAN_LIST.PLAN_LIST_ORDERED_QUANTITY += mMANAGE_LIST.MANAGE_LIST_QUANTITY; if (mIO_PLAN_LIST.PLAN_LIST_ORDERED_QUANTITY > mIO_PLAN_LIST.PLAN_LIST_QUANTITY) { bResult = false; sResult = string.Format("物料组盘数量超过计划数量!"); this._P_Base_House.RollBackTransaction(bTrans); return bResult; } this._P_PLAN_LIST.Update(mIO_PLAN_LIST); } } this._P_MANAGE_LIST.Add(mMANAGE_LIST); } MANAGE_ID = mMANAGE_MAIN.MANAGE_ID; if (bComplete) { bResult = _S_ManageService.Invoke( mMANAGE_TYPE.MANAGE_TYPE_CLASS, "ManageComplete", new object[] { MANAGE_ID, false }, out sResult ); if (!bResult) { this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } else { if (mWH_CELL_START != null) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.START_CELL_ID, string.Empty, SiaSun.LMS.Enum.RUN_STATUS.Selected.ToString(), out sResult); if (!bResult) { sResult = string.Format("更新开始货位{0}状态错误\n{1}", mWH_CELL_START.CELL_CODE, sResult); this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } if (mWH_CELL_END != null) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.END_CELL_ID, string.Empty, SiaSun.LMS.Enum.RUN_STATUS.Selected.ToString(), out sResult); if (!bResult) { sResult = string.Format("更新结束货位{0}状态错误\n{1}", mWH_CELL_END.CELL_CODE, sResult); this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } } if (bAutoSendControl) { bResult = this.ManageDownLoad(MANAGE_ID, string.Empty, false, out sResult); if (!bResult) { this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } this._P_Base_House.CommitTransaction(bTrans); } catch (Exception ex) { this._P_Base_House.RollBackTransaction(bTrans); bResult = false; sResult = ex.Message; } return bResult; } /// /// 空托盘叠垛自动入库任务 /// 调用界面 MANAGE_PLAN_IN.XAML MANAGE_IN.XAML MANAGE_STOCK_IN.XAML /// public bool ManageCreate_Stock_In_Auto(string StockBarcode, string StartPosition, string Manage_type_code, string CELL_MODEL, int StockQuantity, bool bTrans, bool bCheckStorage, bool bComplete, bool bAutoSendControl, out string sResult) { bool bResult = true; sResult = string.Empty; int MANAGE_ID = 0; try { SiaSun.LMS.Model.MANAGE_TYPE mMANAGE_TYPE = this._P_MANAGE_TYPE.GetModelManageTypeCode(Manage_type_code); if (mMANAGE_TYPE == null) { bResult = false; sResult = string.Format("未找到任务类型{0}", Manage_type_code); return bResult; } SiaSun.LMS.Model.WH_CELL mWH_CELL_START = this._P_WH_CELL.GetModel(StartPosition); SiaSun.LMS.Model.WH_CELL mWH_CELL_END = new Model.WH_CELL(); SiaSun.LMS.Model.MANAGE_MAIN mMANAGE_MAIN = new SiaSun.LMS.Model.MANAGE_MAIN(); mMANAGE_MAIN.PLAN_ID = 0; mMANAGE_MAIN.MANAGE_TYPE_CODE = mMANAGE_TYPE.MANAGE_TYPE_CODE.TrimEnd(); mMANAGE_MAIN.STOCK_BARCODE = StockBarcode; mMANAGE_MAIN.CELL_MODEL = CELL_MODEL; mMANAGE_MAIN.START_CELL_ID = mWH_CELL_START.CELL_ID; mMANAGE_MAIN.END_CELL_ID = 0; mMANAGE_MAIN.MANAGE_OPERATOR = "管理系统"; mMANAGE_MAIN.MANAGE_BEGIN_TIME = SiaSun.LMS.Common.StringUtil.GetDateTime(); mMANAGE_MAIN.MANAGE_STATUS = SiaSun.LMS.Enum.MANAGE_STATUS.WaitingSend.ToString(); mMANAGE_MAIN.MANAGE_LEVEL = string.Empty; mMANAGE_MAIN.MANAGE_REMARK = string.Empty; #region 校验 if (this._S_StorageService.StorageCheck(mMANAGE_MAIN.STOCK_BARCODE, Enum.AREA_TYPE.LiKu.ToString(), out sResult)) { sResult = string.Format("托盘{0}已经在立库区", mMANAGE_MAIN.STOCK_BARCODE); return false; } if (this._S_StorageService.StorageCheck(mMANAGE_MAIN.STOCK_BARCODE, Enum.AREA_TYPE.XuNiKu.ToString(), out sResult) && bCheckStorage) { sResult = string.Format("托盘{0}库存校验失败\n {1} ", mMANAGE_MAIN.STOCK_BARCODE, "已经存在库存"); return false; } if (this._P_MANAGE_MAIN.GetModelStockBarcode(mMANAGE_MAIN.STOCK_BARCODE) != null) { bResult = false; sResult = string.Format("托盘条码{0}已经存在任务", mMANAGE_MAIN.STOCK_BARCODE); return bResult; } #endregion this._P_Base_House.BeginTransaction(bTrans); this._P_MANAGE_MAIN.Add(mMANAGE_MAIN); Model.GOODS_MAIN mGOODS_MAIN = this._P_GOODS_MAIN.GetModel("GTP"); Model.MANAGE_LIST sMANAGE_LIST = new Model.MANAGE_LIST(); sMANAGE_LIST.MANAGE_ID = mMANAGE_MAIN.MANAGE_ID; sMANAGE_LIST.GOODS_ID = mGOODS_MAIN.GOODS_ID; sMANAGE_LIST.MANAGE_LIST_QUANTITY = StockQuantity;//空托盘数量 sMANAGE_LIST.PLAN_LIST_ID = 0; sMANAGE_LIST.GOODS_PROPERTY1 = string.Empty; sMANAGE_LIST.GOODS_PROPERTY2 = string.Empty; sMANAGE_LIST.GOODS_PROPERTY3 = string.Empty; this._P_MANAGE_LIST.Add(sMANAGE_LIST); MANAGE_ID = mMANAGE_MAIN.MANAGE_ID; if (bAutoSendControl) { bResult = this.ManageDownLoad(MANAGE_ID, string.Empty, false, out sResult); if (!bResult) { //this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } if (bComplete) { bResult = _S_ManageService.Invoke(mMANAGE_TYPE.MANAGE_TYPE_CLASS, "ManageComplete", new object[] { MANAGE_ID, false }, out sResult); if (!bResult) { //this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } else { if (mWH_CELL_START != null) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.START_CELL_ID, string.Empty, SiaSun.LMS.Enum.RUN_STATUS.Selected.ToString(), out sResult); if (!bResult) { sResult = string.Format("更新开始货位{0}状态错误\n{1}", mWH_CELL_START.CELL_CODE, sResult); //this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } if (mWH_CELL_END != null) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.END_CELL_ID, string.Empty, SiaSun.LMS.Enum.RUN_STATUS.Selected.ToString(), out sResult); if (!bResult) { sResult = string.Format("更新结束货位{0}状态错误\n{1}", mWH_CELL_END.CELL_CODE, sResult); //this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } } } catch (Exception ex) { //this._P_Base_House.RollBackTransaction(bTrans); bResult = false; sResult = ex.Message; } finally { if (bResult) { this._P_Base_House.CommitTransaction(bTrans); } else { this._P_Base_House.RollBackTransaction(bTrans); } } return bResult; } //自动配盘入库流程 public bool ManageCreateAuto(SiaSun.LMS.Model.MANAGE_MAIN mMANAGE_MAIN, List lsMANAGE_LIST, bool bTrans, bool bAutoSendControl, bool bComplete, out string sResult) { bool bResult = true; sResult = string.Empty; int MANAGE_ID = 0; SiaSun.LMS.Model.WH_CELL mWH_CELL_START = this._P_WH_CELL.GetModel(mMANAGE_MAIN.START_CELL_ID); SiaSun.LMS.Model.WH_CELL mWH_CELL_END = this._P_WH_CELL.GetModel(mMANAGE_MAIN.END_CELL_ID); if (this._S_StorageService.StorageCheck(mMANAGE_MAIN.STOCK_BARCODE, Enum.AREA_TYPE.LiKu.ToString(), out sResult)) { sResult = string.Format("托盘{0}已经在立库区", mMANAGE_MAIN.STOCK_BARCODE); return false; } if (this._P_MANAGE_MAIN.GetModelStockBarcode(mMANAGE_MAIN.STOCK_BARCODE) != null) { bResult = false; sResult = string.Format("托盘条码{0}已经存在任务", mMANAGE_MAIN.STOCK_BARCODE); return bResult; } try { this._P_Base_House.BeginTransaction(bTrans); if (mWH_CELL_START != null) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.START_CELL_ID, string.Empty, SiaSun.LMS.Enum.RUN_STATUS.Selected.ToString(), out sResult); if (!bResult) { sResult = string.Format("更新开始货位{0}状态错误\n{1}", mWH_CELL_START.CELL_CODE, sResult); this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } if (mWH_CELL_END != null) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.END_CELL_ID, string.Empty, SiaSun.LMS.Enum.RUN_STATUS.Selected.ToString(), out sResult); if (!bResult) { sResult = string.Format("更新结束货位{0}状态错误\n{1}", mWH_CELL_END.CELL_CODE, sResult); this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } this._P_MANAGE_MAIN.Add(mMANAGE_MAIN); MANAGE_ID = mMANAGE_MAIN.MANAGE_ID; foreach (SiaSun.LMS.Model.MANAGE_LIST mMANAGE_LIST in lsMANAGE_LIST) { mMANAGE_LIST.MANAGE_ID = mMANAGE_MAIN.MANAGE_ID; this._P_MANAGE_LIST.Add(mMANAGE_LIST); } if (bAutoSendControl) { bResult = this.ManageDownLoad(MANAGE_ID, string.Empty, false, out sResult); if (!bResult) { this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } if (bComplete) { bResult = this.ManageComplete(MANAGE_ID, false, out sResult); if (!bResult) { this._P_Base_House.RollBackTransaction(bTrans); return bResult; } } sResult = string.Format("托盘{0}生成任务成功", mMANAGE_MAIN.STOCK_BARCODE); this._P_Base_House.CommitTransaction(bTrans); } catch (Exception ex) { this._P_Base_House.RollBackTransaction(bTrans); bResult = false; sResult = ex.Message; } return bResult; } /// /// 任务完成 /// /// /// /// /// public new bool ManageComplete(int MANAGE_ID, bool bTrans, out string sResult) { bool bResult = true; sResult = string.Empty; SiaSun.LMS.Model.MANAGE_MAIN mMANAGE_MAIN = this._P_MANAGE_MAIN.GetModel(MANAGE_ID); bResult = null != mMANAGE_MAIN; if (!bResult) { sResult = string.Format("未能找到任务{0}", MANAGE_ID.ToString()); return bResult; } try { SiaSun.LMS.Model.WH_CELL mWH_CELL_START = this._P_WH_CELL.GetModel(mMANAGE_MAIN.START_CELL_ID); SiaSun.LMS.Model.WH_CELL mWH_CELL_END = this._P_WH_CELL.GetModel(mMANAGE_MAIN.END_CELL_ID); this._P_Base_House.BeginTransaction(bTrans); if (mWH_CELL_START != null && (mWH_CELL_START.CELL_TYPE.TrimEnd() == Enum.CELL_TYPE.Cell.ToString() || mWH_CELL_START.CELL_STORAGE_TYPE.TrimEnd() == Enum.CELL_STORAGE_TYPE.Single.ToString())) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.START_CELL_ID, SiaSun.LMS.Enum.CELL_STATUS.Nohave.ToString(), SiaSun.LMS.Enum.RUN_STATUS.Enable.ToString(), out sResult); } if (!bResult) { sResult = string.Format("更新起始位置{0}状态错误\n", mMANAGE_MAIN.START_CELL_ID.ToString()); return bResult; } if (mWH_CELL_END != null && (mWH_CELL_END.CELL_TYPE.TrimEnd() == Enum.CELL_TYPE.Cell.ToString() || mWH_CELL_END.CELL_STORAGE_TYPE.TrimEnd() == Enum.CELL_STORAGE_TYPE.Single.ToString())) { bResult = this._S_CellService.CellUpdateStatus(mMANAGE_MAIN.END_CELL_ID, SiaSun.LMS.Enum.CELL_STATUS.Full.ToString(), SiaSun.LMS.Enum.RUN_STATUS.Enable.ToString(), out sResult); } if (!bResult) { sResult = string.Format("更新终止位置{0}状态错误\n", mMANAGE_MAIN.END_CELL_ID.ToString()); return bResult; } bResult= this.Invoke("StorageBase", "StorageCreate", new object[] { MANAGE_ID }, out sResult); if (!bResult) { sResult = string.Format("库存处理错误-{0}", sResult); return bResult; } bResult = base.ManageComplete(mMANAGE_MAIN, false, out sResult); } catch (Exception ex) { bResult = false; sResult = ex.Message; } finally { if (bResult) { this._P_Base_House.CommitTransaction(bTrans); } else { this._P_Base_House.RollBackTransaction(bTrans); } } return bResult; } } }