From f2b3c45b78bb9fc021869c4ae35e6de039b50bbf Mon Sep 17 00:00:00 2001
From: chengsc <Demo@DESKTOP-CPA90BF>
Date: 星期五, 18 十月 2024 18:40:52 +0800
Subject: [PATCH] 修改问题

---
 Wms/WMS.BLL/BllAsnServer/BllBoxInfoServer.cs |  318 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 274 insertions(+), 44 deletions(-)

diff --git a/Wms/WMS.BLL/BllAsnServer/BllBoxInfoServer.cs b/Wms/WMS.BLL/BllAsnServer/BllBoxInfoServer.cs
index 26c7d4e..3448fe9 100644
--- a/Wms/WMS.BLL/BllAsnServer/BllBoxInfoServer.cs
+++ b/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
 {
@@ -529,17 +530,50 @@
         }
 
         //鑾峰彇鏍囩淇℃伅(鐢熸垚鏍囩)
-        public List<BllBoxInfo> AddLabelBox(int imId, string isReset, decimal arriveQty, string productionTime, string expirationTime, string storeTime, int userId)
+        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)
@@ -676,23 +710,24 @@
                         }
                         else
                         {
-                            var labelCount = label.Where(m => m.ASNDetailNo == imId).ToList();
-                            if (labelCount.Count <= 0)
-                            {
-                                throw new Exception("褰撳墠鍗曟嵁鏄庣粏杩樻湭鐢熸垚鏍囩锛岃閫夋嫨閲嶇疆鎵规閫夐」涓衡�樻槸鈥欙紱");
-                            }
-                            maxLotNoStr = label.Max(a => a.LotNo);
-                            maxBoxCode = label.Max(a => a.BoxNo);
-                            if (string.IsNullOrWhiteSpace(maxLotNoStr))
-                            {
-                                maxLotNoStr = toDayTime.Substring(2, 6) + "0001";
-                            }
+                            //var labelCount = label.Where(m => m.ASNDetailNo == imId).ToList();
+                            //if (labelCount.Count <= 0)
+                            //{
+                            //    throw new Exception("褰撳墠鍗曟嵁鏄庣粏杩樻湭鐢熸垚鏍囩锛岃閫夋嫨閲嶇疆鎵规閫夐」涓衡�樻槸鈥欙紱");
+                            //}
+                            //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";
@@ -756,7 +791,7 @@
                             ASNNo = asnList.ASNNo,
                             ASNDetailNo = asnList.Id,
                             BoxNo = maxBoxCode, 
-                            Qty = int.Parse(boxQty.ToString()),
+                            Qty = boxQty,
                             FullQty = bNum,
                             Status = "0",
                             SkuNo = asnList.SkuNo,
@@ -764,20 +799,25 @@
                             LotNo = maxLotNoStr,
                             Standard = asnList.Standard,
                             PackageStandard = packStr,
-                            SupplierLot = asnList.SupplierLot,
+                            SupplierLot = supplierLot,
                             InspectMark = "0",
                             BitBoxMark = bNum > boxQty ? "1":"0",
-                            InspectStatus = "",
+                            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);
                     }
@@ -841,18 +881,20 @@
                         }
                         else
                         {
-                            var labelCount = label.Where(m => m.ASNDetailNo == imId).ToList();
-                            if (labelCount.Count <= 0)
-                            {
-                                throw new Exception("褰撳墠鍗曟嵁鏄庣粏杩樻湭鐢熸垚鏍囩锛岃閫夋嫨閲嶇疆鎵规閫夐」涓衡�樻槸鈥欙紱");
-                            }
-                            maxCodestr2 = label.Max(a => a.LotNo); ;
-                            maxboxcode2 = label.Max(a => a.BoxNo);//绠卞彿;
-                            maxboxcode3 = label.Max(a => a.BoxNo3);//鏀彿;
-                            if (string.IsNullOrWhiteSpace(maxCodestr2))
-                            {
-                                maxCodestr2 = toDayTime2.Substring(2, 6) + "0001";
-                            }
+                            //var labelCount = label.Where(m => m.ASNDetailNo == imId).ToList();
+                            //if (labelCount.Count <= 0)
+                            //{
+                            //    throw new Exception("褰撳墠鍗曟嵁鏄庣粏杩樻湭鐢熸垚鏍囩锛岃閫夋嫨閲嶇疆鎵规閫夐」涓衡�樻槸鈥欙紱");
+                            //}
+                            //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);//鏀彿;
                         }
                         
                     }
@@ -960,8 +1002,8 @@
                                 maxboxcode3 = maxboxcode3.Substring(0, 11) + (int.Parse(maxboxcode3.Substring(11, 4)) + 1).ToString().PadLeft(4, '0'); 
                             }
 
-                            var ssss = d.ToString("0");
-                            var sss = int.Parse(ssss);
+                            //var ssss = d.ToString("0");
+                            //var sss = int.Parse(ssss);
 
                             // 灏嗘潯鐮佷繚瀛樺埌鍘熸枡鏉$爜琛�
                             var labelModel = new BllBoxInfo()
@@ -970,7 +1012,7 @@
                                 ASNDetailNo = asnList.Id,
                                 BoxNo = maxboxcode2,
                                 BoxNo3 = maxboxcode3,
-                                Qty = sss,
+                                Qty = d,
                                 FullQty = bNum,
                                 Status = "0",
                                 SkuNo = asnList.SkuNo,
@@ -978,20 +1020,25 @@
                                 LotNo = maxCodestr2,
                                 Standard = asnList.Standard,
                                 PackageStandard = packStr,
-                                SupplierLot = asnList.SupplierLot,
+                                SupplierLot = supplierLot,
                                 InspectMark = "0",
                                 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);
                         }
@@ -1590,5 +1637,188 @@
                 throw new Exception(e.Message);
             }
         }
+
+        //鏍规嵁鍏ュ簱鍗曞彿杩囧幓鍗曟嵁涓嬫墍鏈夋壒娆″彿
+        public List<string> GetLotNoListByAsn(string asnNo)
+        {
+            try
+            {
+                var data = new List<string>();
+                var asnList = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.IsDel == "0" && m.ASNNo == asnNo).ToList();
+                if (asnList.Count == 0)
+                {
+                    throw new Exception("鏈煡璇㈠埌璇ュ崟鎹彿鐨勪俊鎭�");
+                }
+
+                foreach (var item in asnList)
+                {
+                    if (string.IsNullOrWhiteSpace(item.LotNo))
+                    {
+                        continue;
+                    }
+
+                    var strList = item.LotNo.Split(";");
+                    foreach (var str in strList)
+                    {
+                        if (string.IsNullOrWhiteSpace(str))
+                        {
+                            continue;
+                        }
+                        data.Add(str);
+                    }
+                }
+
+                return data;
+            }
+            catch (Exception e)
+            {
+                throw new Exception(e.Message);
+            }
+        }
+
+        //鍒犻櫎鍗曟嵁涓嬪崟涓垨澶氫釜鎵规鐨勬爣绛�
+        public void DelLabelByAsnNo(string asnNo,string lotNo, int userId)
+        {
+            try
+            {
+                var asnList = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.IsDel == "0" && m.ASNNo == asnNo).ToList();
+                if (asnList.Count == 0)
+                {
+                    throw new Exception("鏈煡璇㈠埌璇ュ崟鎹彿鐨勪俊鎭�");
+                }
+
+                Db.BeginTran();
+
+                //鎵规涓虹┖锛氬綋鍓嶅崟鎹笅鎵�鏈夋壒娆$殑鏍囩鍏ㄩ儴鍒犻櫎锛� 鏈夋壒娆★細浼ゅ褰撳墠鍗曟嵁涓嬪綋鍓嶆壒娆$殑鏍囩
+                if (string.IsNullOrWhiteSpace(lotNo)) //鍒犻櫎鍏ㄩ儴鏍囩
+                {
+                    var labelList = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.ASNNo == asnNo).ToList();
+                    if (labelList.Count(m => m.Status != "0") >= 1)
+                    {
+                        throw new Exception("褰撳墠鍗曟嵁鎵规鐨勬爣绛惧凡鏈夊凡浣跨敤锛屼笉鑳藉垹闄�");
+                    }
+
+                    //foreach (var item in asnList)
+                    //{
+                    //    if (string.IsNullOrWhiteSpace(item.LotNo))
+                    //    {
+                    //        continue;
+                    //    }
+
+                    //    item.LotNo = "";
+                    //    Db.Updateable(item).ExecuteCommand();
+
+                    //}
+                    Db.Deleteable(labelList).ExecuteCommand();
+                }
+                else  //鍒犻櫎鍥哄畾鎵规鏍囩
+                {
+                    var labelList = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.ASNNo == asnNo && m.LotNo == lotNo).ToList();
+                    if (labelList.Count(m=>m.Status != "0") >= 1 )
+                    {
+                        throw new Exception("褰撳墠鍗曟嵁鎵规鐨勬爣绛惧凡鏈夊凡浣跨敤锛屼笉鑳藉垹闄�");
+                    }
+
+                    //foreach (var item in asnList)
+                    //{
+                    //    if (string.IsNullOrWhiteSpace(item.LotNo) || item.LotNo!=lotNo)
+                    //    {
+                    //        continue;
+                    //    }
+
+                    //    var strList = item.LotNo.Split(";");
+                    //    var updateLotNo = "";
+                    //    foreach (var str in strList)
+                    //    {
+                    //        if (string.IsNullOrWhiteSpace(str) || str == lotNo)
+                    //        {
+                    //            continue;
+                    //        }
+
+                    //        if (string.IsNullOrWhiteSpace(updateLotNo))
+                    //        {
+                    //            updateLotNo = str;
+                    //        }
+                    //        else
+                    //        {
+                    //            updateLotNo += ";" + str;
+                    //        }
+                             
+                    //    }
+
+                    //    item.LotNo = updateLotNo;
+                    //    Db.Updateable(item).ExecuteCommand();
+
+                    //}
+                    Db.Deleteable(labelList).ExecuteCommand();
+                }
+
+                Db.CommitTran();
+
+                var msg = $"鍒犻櫎浜嗗崟鎹彿锛歿asnNo}";
+                if (!string.IsNullOrWhiteSpace(lotNo))
+                {
+                    msg += $"銆佹壒娆″彿锛歿lotNo}";
+                }
+                msg += "鐨勬爣绛句俊鎭�";
+
+                new OperationASNServer().AddLogOperationAsn("鍏ュ簱浣滀笟", "鐗╂枡鏍囩", asnNo, "鍒犻櫎", msg, userId);
+            }
+            catch (Exception e)
+            {
+                Db.RollbackTran();
+                throw new Exception(e.Message);
+            }
+        }
+
+
+        //缂栬緫鏍囩鏁伴噺
+        public void EditLabelQty(int id, string qty, int userId)
+        {
+            try
+            {
+                if (string.IsNullOrWhiteSpace(qty))
+                {
+                    throw new Exception("缂栬緫鏁伴噺涓嶅彲涓虹┖");
+                }
+                var qtyData = 0m;
+                var isOk = decimal.TryParse(qty, out qtyData);
+                var boxInfo = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.Id == id);
+                if (boxInfo == null)
+                {
+                    throw new Exception("鏈煡璇㈠埌璇ユ爣绛句俊鎭�");
+                }
+
+                if (isOk)
+                {
+                    if (qtyData <= 0)
+                    {
+                        throw new Exception("鏁伴噺涓嶈兘灏忎簬绛変簬0");
+                    }
+                    boxInfo.Qty = qtyData;
+
+                    Db.Updateable(boxInfo).ExecuteCommand();
+                }
+                else
+                {
+                    throw new Exception("鏁伴噺杞崲澶辫触");
+                }
+
+                var msg = $"缂栬緫浜嗙鍙凤細{boxInfo.BoxNo}";
+                if (!string.IsNullOrWhiteSpace(boxInfo.BoxNo3))
+                {
+                    msg += $"銆佹敮鍙凤細{boxInfo.BoxNo3}";
+                }
+                msg += "鐨勬爣绛炬暟閲忎俊鎭�";
+
+                new OperationASNServer().AddLogOperationAsn("鍏ュ簱浣滀笟", "鐗╂枡鏍囩", boxInfo.BoxNo, "缂栬緫", msg, userId);
+            }
+            catch (Exception e)
+            {
+                throw new Exception(e.Message);
+            }
+        }
+
+
     }
 }

--
Gitblit v1.8.0