chengsc
2024-10-13 83b9213dc893bec8f94e04cad121abb6649886dd
Wms/WMS.BLL/BllAsnServer/BllBoxInfoServer.cs
@@ -15,6 +15,7 @@
using WMS.Entity.Context;
using WMS.Entity.SysEntity;
using WMS.IBLL.IBllAsnServer;
using ZXing;
namespace WMS.BLL.BllAsnServer
{
@@ -532,14 +533,47 @@
        public List<BllBoxInfo> AddLabelBox(int imId, string isReset, decimal arriveQty, string productionTime, string expirationTime, string storeTime,string supplierLot, int userId)
        {
            try
            {
            {
                #region 单据、物料、包装、标签信息获取
                if (string.IsNullOrWhiteSpace(productionTime))
                {
                    throw new Exception("生产日期不能为空");
                }
                if (!string.IsNullOrWhiteSpace(expirationTime) && !string.IsNullOrWhiteSpace(storeTime))
                {
                    throw new Exception("有效期和储存期不能同时填写");
                }
                if (isReset != "0")
                {
                    throw new Exception("不可重置批次");
                }
                DateTime proTime;
                DateTime expTime;
                DateTime stoTime;
                var bl1= DateTime.TryParse(productionTime, out proTime);
                var bl2= DateTime.TryParse(expirationTime, out expTime);
                var bl3= DateTime.TryParse(storeTime, out stoTime);
                if (!bl1)
                {
                    throw new Exception("生产日期转换失败");
                }
                if (!bl2 && !string.IsNullOrWhiteSpace(expirationTime))
                {
                    throw new Exception("有效期转换失败");
                }
                if (!bl3 && !string.IsNullOrWhiteSpace(storeTime))
                {
                    throw new Exception("储存期转换失败");
                }
                var asnList = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.Id == imId && m.IsDel == "0");
                if (asnList == null)
                {
                    throw new Exception("未查询到单据明细信息");
                }
                if (asnList.LotNo.Length != 10)
                {
                    throw new Exception("单据进厂编号位数长度错误");
                }
                var asn = Db.Queryable<BllArrivalNotice>().First(m => m.ASNNo == asnList.ASNNo && m.IsDel == "0");
                if (asn == null)
@@ -681,19 +715,19 @@
                            {
                                throw new Exception("当前单据明细还未生成标签,请选择重置批次选项为‘是’;");
                            }
                            maxLotNoStr = labelCount.Max(a => a.LotNo);
                            if (string.IsNullOrWhiteSpace(maxLotNoStr))
                            {
                                maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
                            }
                            maxBoxCode = label.Where(m => m.LotNo == maxLotNoStr).Max(a => a.BoxNo);
                            //maxLotNoStr = labelCount.Max(a => a.LotNo);
                            maxLotNoStr = asnList.LotNo;
                            //if (string.IsNullOrWhiteSpace(maxLotNoStr))
                            //{
                            //    maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
                            //}
                            //maxBoxCode = label.Where(m => m.LotNo == maxLotNoStr).Max(a => a.BoxNo);
                        }
                        
                    }
                    else
                    {
                        var maxCode = Db.Queryable<BllBoxInfo>().Where(m=>m.Origin == "WMS生成").Max(a => a.LotNo);                        // 获取今天最大批次号
                        var maxCode = Db.Queryable<BllBoxInfo>().Where(m=>m.Origin == "WMS生成").Max(a => a.LotNo); // 获取今天最大批次号 20241013
                        if (string.IsNullOrWhiteSpace(maxCode))
                        {
                            maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
@@ -770,15 +804,20 @@
                            BitBoxMark = bNum > boxQty ? "1":"0",
                            InspectStatus = "0",
                            ProductionTime = DateTime.Parse(productionTime),
                            StoreTime = DateTime.Parse(storeTime),
                            ExpirationTime = DateTime.Parse(expirationTime),
                            ProductionTime = proTime,
                            Origin = "WMS生成",
                            CreateUser = userId,
                            CreateTime = DateTime.Now,
                        };
                        if (bl2)
                        {
                            labelModel.ExpirationTime = expTime;
                        }
                        if (bl3)
                        {
                            labelModel.StoreTime = stoTime;
                        }
                        Db.Insertable(labelModel).ExecuteCommand();
                        modelList.Add(labelModel);
                    }
@@ -847,14 +886,15 @@
                            {
                                throw new Exception("当前单据明细还未生成标签,请选择重置批次选项为‘是’;");
                            }
                            maxCodestr2 = labelCount.Max(a => a.LotNo); ;
                            //maxCodestr2 = labelCount.Max(a => a.LotNo); ;
                            maxCodestr2 = asnList.LotNo;
                            
                            if (string.IsNullOrWhiteSpace(maxCodestr2))
                            {
                                maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
                            }
                            maxboxcode2 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo);//箱号;
                            maxboxcode3 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo3);//支号;
                            //if (string.IsNullOrWhiteSpace(maxCodestr2))
                            //{
                            //    maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
                            //}
                            //maxboxcode2 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo);//箱号;
                            //maxboxcode3 = label.Where(m => m.LotNo == maxCodestr2).Max(a => a.BoxNo3);//支号;
                        }
                        
                    }
@@ -985,15 +1025,20 @@
                                BitBoxMark = bNum > boxQty ? "1" : "0",
                                InspectStatus = "0",
                                ProductionTime = DateTime.Parse(productionTime),
                                StoreTime = DateTime.Parse(storeTime),
                                ExpirationTime = DateTime.Parse(expirationTime),
                                ProductionTime = proTime,
                                Origin = "WMS生成",
                                CreateUser = userId,
                                CreateTime = DateTime.Now,
                            };
                            if (bl2)
                            {
                                labelModel.ExpirationTime = expTime;
                            }
                            if (bl3)
                            {
                                labelModel.StoreTime = stoTime;
                            }
                            Db.Insertable(labelModel).ExecuteCommand();
                            modelList.Add(labelModel);
                        }