New file |
| | |
| | | using HH.WCS.Mobox3.FJJT.models.other; |
| | | using HH.WCS.Mobox3.FJJT.util; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using static HH.WCS.Mobox3.FJJT.dispatch.NDC; |
| | | using static HH.WCS.Mobox3.FJJT.util.ExcetionHelper; |
| | | |
| | | namespace HH.WCS.Mobox3.FJJT.wms { |
| | | /// <summary> |
| | | /// 容器帮助类 |
| | | /// </summary> |
| | | internal class ContainerHelper { |
| | | internal static string GenerateCntrNo() { |
| | | var id = SYSHelper.GetSerialNumber("托盘号", "TP"); |
| | | var date = DateTime.Now.ToString("yyMMdd"); |
| | | return $"TP{date}{id.ToString().PadLeft(4, '0')}"; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// TN_ContainerHelper.test("4L天然水箱装6入", 50, "335ml东方树叶15入", 30); |
| | | /// </summary> |
| | | /// <param name="item1"></param> |
| | | /// <param name="qty1"></param> |
| | | /// <param name="item2"></param> |
| | | /// <param name="qty2"></param> |
| | | //internal static void test(string item1, int qty1, string item2, int qty2) { |
| | | // var db = new SqlHelper<object>().GetInstance(); |
| | | // var cntr = db.Queryable<TN_Container>().Includes(a => a.CntrItemRelList). |
| | | // Where(a => a.CntrItemRelList.Count(b => b.S_ITEM_CODE == item1 && int.Parse(b.F_QTY) > qty1) > 0 |
| | | // && a.CntrItemRelList.Count(b => b.S_ITEM_CODE == item2 && int.Parse(b.F_QTY) > qty2) > 0).First(); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 判断容器是否有物料信息 |
| | | /// </summary> |
| | | /// <param name="cntr"></param> |
| | | /// <returns></returns> |
| | | internal static bool CheckEmpty(string cntr) { |
| | | //1.0 查货位容器表 |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | return db.Queryable<LocCntrRel>().Count(a => a.S_LOC_CODE.Trim() == cntr) == 0; |
| | | |
| | | } |
| | | |
| | | /*internal static bool AddCntr(string cntrCode, string itemCode) { |
| | | var res = false; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var TN_Container = new Container { S_CODE = cntrCode }; |
| | | var cntrItemRel = new CntrItemRel { S_CNTR_CODE = cntrCode, S_ITEM_CODE = itemCode }; |
| | | try { |
| | | db.BeginTran(); |
| | | |
| | | db.Insertable<Container>(TN_Container).ExecuteCommand(); |
| | | db.Insertable<CntrItemRel>(cntrItemRel).ExecuteCommand(); |
| | | |
| | | db.CommitTran(); |
| | | res = true; |
| | | } |
| | | catch (Exception ex) { |
| | | db.RollbackTran(); |
| | | |
| | | } |
| | | return res; |
| | | }*/ |
| | | |
| | | internal static bool AddCntr(string cntrCode ,int detallCount = 0) |
| | | { |
| | | var res = false; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var TN_Container = new Container { S_CODE = cntrCode ,N_DETAIL_COUNT = detallCount }; |
| | | try |
| | | { |
| | | var container = db.Queryable<Container>().Where(a => a.S_CODE.Trim() == cntrCode).First(); |
| | | if (container == null) |
| | | { |
| | | res = db.Insertable<Container>(TN_Container).ExecuteCommand() > 0; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | WMSHelper.addAlarmRecord("系统错误", "高", $"添加容器错误,错误原因:{ex.Message}"); |
| | | throw new BusinessException($"添加容器错误,错误原因:{ex.Message}"); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | internal static bool AddContainer(string cntrCode,int cntrType ,int detallCount = 0) |
| | | { |
| | | var res = false; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var TN_Container = new Container { S_CODE = cntrCode, N_TYPE = cntrType,S_TYPE = Container.GetCntrType(cntrType),N_DETAIL_COUNT = detallCount }; |
| | | try |
| | | { |
| | | db.BeginTran(); |
| | | var container = db.Queryable<Container>().Where(a => a.S_CODE.Trim() == cntrCode).First(); |
| | | if (container == null) |
| | | { |
| | | db.Insertable<Container>(TN_Container).ExecuteCommand(); |
| | | } |
| | | else |
| | | { |
| | | container.N_DETAIL_COUNT = detallCount; |
| | | container.N_E_STATE = 0; |
| | | db.Updateable<Container>(container).ExecuteCommand(); |
| | | } |
| | | db.CommitTran(); |
| | | res = true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | db.RollbackTran(); |
| | | WMSHelper.addAlarmRecord("系统错误", "高", $"添加容器错误,错误原因:{ex.Message}"); |
| | | throw new BusinessException($"添加容器错误,错误原因:{ex.Message}"); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据容器号获取容器信息 |
| | | /// </summary> |
| | | /// <param name="cntr"></param> |
| | | /// <param name="create"></param> |
| | | /// <returns></returns> |
| | | internal static Container GetCntr(string cntr, bool create = false) { |
| | | //1.0 查货位容器表 |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var old = db.Queryable<Container>().Where(a => a.S_CODE.Trim() == cntr).First(); |
| | | if (old == null && create) { |
| | | var model = new Container { S_CODE = cntr }; |
| | | if (db.Insertable(model).ExecuteCommand() > 0) { |
| | | old = model; |
| | | } |
| | | } |
| | | return old; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 根据容器获取物料信息 |
| | | /// </summary> |
| | | /// <param name="cntr"></param> |
| | | /// <returns></returns> |
| | | internal static List<CntrItemRel> GetCntrItemRel(string cntr) { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var list = db.Queryable<CntrItemRel>().Where(a => a.S_CNTR_CODE == cntr).ToList(); |
| | | return list; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新容器物料信息 |
| | | /// </summary> |
| | | /// <param name="cntrItem"></param> |
| | | /// <returns></returns> |
| | | internal static bool updateCntrItemRel(CntrItemRel cntrItem) |
| | | { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | return db.Updateable(cntrItem).ExecuteCommand()>0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 物料信息绑定到满容器上 |
| | | /// </summary> |
| | | /// <param name="cntrCode"></param> |
| | | /// <param name="itemCode"></param> |
| | | /// <param name="batchNo"></param> |
| | | /// <param name="qty"></param> |
| | | /// <returns></returns> |
| | | internal static bool BindCntrItem(Container cntr, string itemCode, string batchNo, float qty) { |
| | | var res = false; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | try { |
| | | db.BeginTran(); |
| | | //1.查看是否有相同物料批次的信息,如果有要累加,不同批次的可以分开 |
| | | var cir = db.Queryable<CntrItemRel>().Where(a => a.S_CNTR_CODE == cntr.S_CODE && a.S_ITEM_CODE == itemCode && a.S_BATCH_NO == batchNo).First(); |
| | | if (cir != null) { |
| | | cir.F_QTY += qty; |
| | | db.Updateable(cir).UpdateColumns(it => new { it.F_QTY }).ExecuteCommand(); |
| | | } |
| | | else { |
| | | //2.插入新的容器物料信息(容器号不变) |
| | | cir = new CntrItemRel { S_CNTR_CODE = cntr.S_CODE.Trim(), S_BATCH_NO = batchNo, F_QTY = qty, S_ITEM_CODE = itemCode }; |
| | | db.Insertable<CntrItemRel>(cir).ExecuteCommand(); |
| | | } |
| | | var count = db.Queryable<CntrItemRel>().Count(a => a.S_CNTR_CODE == cntr.S_CODE); |
| | | cntr.N_DETAIL_COUNT = count; |
| | | cntr.C_ENABLE = "N";//码盘后将托盘设置为不可用状态,入库后变成可用 |
| | | db.Updateable(cntr).UpdateColumns(it => new { it.N_DETAIL_COUNT, it.C_ENABLE}).ExecuteCommand(); |
| | | |
| | | db.CommitTran(); |
| | | res = true; |
| | | } |
| | | catch (Exception ex) { |
| | | db.RollbackTran(); |
| | | Console.WriteLine(ex.Message); |
| | | } |
| | | |
| | | return res; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | internal static bool UpdateCntr(Container container) |
| | | { |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | return db.Updateable(container).ExecuteCommand()>0; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="cntrCode"></param> |
| | | /// <param name="state">托盘异常状态 0.正常 1.异常</param> |
| | | /// <returns></returns> |
| | | internal static bool UpdateCntrState(string cntrCode, int state) { |
| | | var res = false; |
| | | var db = new SqlHelper<object>().GetInstance(); |
| | | var models = db.Queryable<Container>().Where(a => a.S_CODE.Trim() == cntrCode).ToList(); |
| | | if (models.Count > 0) { |
| | | models.ForEach(a => { |
| | | a.N_E_STATE = state; |
| | | db.Updateable(a).UpdateColumns(it => new { it.N_E_STATE }).ExecuteCommand(); |
| | | }); |
| | | res = true; |
| | | } |
| | | return res; |
| | | } |
| | | } |
| | | } |