From 1e26a7575d9969e728b0aa01466f490409cb173c Mon Sep 17 00:00:00 2001
From: chengsc <Demo@DESKTOP-CPA90BF>
Date: 星期五, 18 十月 2024 18:41:30 +0800
Subject: [PATCH] Merge branch 'master' into csc

---
 Wms/WMS.BLL/BllPdaServer/PdaSoServer.cs |  134 ++++++++++++++++++++++++++++++++++++++------
 1 files changed, 114 insertions(+), 20 deletions(-)

diff --git a/Wms/WMS.BLL/BllPdaServer/PdaSoServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaSoServer.cs
index d8ff5f2..ff2c8d6 100644
--- a/Wms/WMS.BLL/BllPdaServer/PdaSoServer.cs
+++ b/Wms/WMS.BLL/BllPdaServer/PdaSoServer.cs
@@ -520,6 +520,7 @@
                     Db.Updateable(pallet).ExecuteCommand();
                     //淇敼鍑哄簱鍗曟槑缁嗘嫞璐ф暟閲�
                     noticeDetail.CompleteQty += pickQty;
+                    noticeDetail.Status = "2";
                     Db.Updateable(noticeDetail).ExecuteCommand();
 
                     var num = Db.Queryable<BllExportNoticeDetail>()
@@ -527,7 +528,10 @@
                     if (num <= 0)
                     {
                         notice.Status = "4"; //鏇存敼涓烘墽琛屽畬鎴�
+                        noticeDetail.Status = "3";
+                        Db.Updateable(noticeDetail).ExecuteCommand();
                     }
+                    
                     //淇敼鍑哄簱鍗曚俊鎭�
                     Db.Updateable(notice).ExecuteCommand();
                 }
@@ -535,7 +539,7 @@
                 {
                     var biaoShi = "0";//0锛氭暣绠辨嫞璐с��1锛氭暎鏀嫞璐с��2锛氭暟閲忔嫞璐�
                     List<DataBoxInfo> boxInfos;
-                    var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo);
+                    var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo && m.StockDetailId == stockDetail.Id);
                     if (boxInfo.Count() == 0)
                     {
                         throw new Exception("鏈煡璇㈠埌璇ョ鐮佸強杩芥函鐮佺殑淇℃伅");
@@ -649,6 +653,7 @@
 
                         if (biaoShi != "2")
                         {
+                            pickQty += item.Qty;
                             //鍒犻櫎搴撳瓨绠辩爜鏄庣粏
                             Db.Deleteable(item).ExecuteCommand();
                         }
@@ -656,17 +661,20 @@
                         {
                             if (decimal.Parse(pickQty1) == item.Qty)
                             {
+                                pickQty += item.Qty;
                                 //鍒犻櫎搴撳瓨绠辩爜鏄庣粏
                                 Db.Deleteable(item).ExecuteCommand();
+                                
                             }
                             else
                             {
+                                pickQty += decimal.Parse(pickQty1);
                                 item.Qty -= decimal.Parse(pickQty1);
                                 item.BitBoxMark = "1";//闆剁鏍囪瘑
                                 Db.Updateable(item).ExecuteCommand();
                             }
                         }
-                        pickQty += item.Qty;
+                        
                     }
                     //鏀瑰彉搴撳唴绠辩爜鏄惁闆剁淇℃伅
                     if (biaoShi == "1")
@@ -739,6 +747,7 @@
                     }
                     //淇敼鍑哄簱鍗曟槑缁嗘嫞璐ф暟閲�
                     noticeDetail.CompleteQty += pickQty;
+                    noticeDetail.Status = "2"; 
                     Db.Updateable(noticeDetail).ExecuteCommand();
 
                     var num = Db.Queryable<BllExportNoticeDetail>()
@@ -746,6 +755,9 @@
                     if (num <= 0)
                     {
                         notice.Status = "4"; //鏇存敼涓烘墽琛屽畬鎴�
+
+                        noticeDetail.Status = "3";
+                        Db.Updateable(noticeDetail).ExecuteCommand();
                     }
                     //淇敼鍑哄簱鍗曚俊鎭�
                     Db.Updateable(notice).ExecuteCommand();
@@ -940,6 +952,7 @@
 
                 //淇敼鍑哄簱鍗曟槑缁嗘嫞璐ф暟閲�
                 noticeDetail.CompleteQty += int.Parse(PickQty);
+                noticeDetail.Status = "2";
                 Db.Updateable(noticeDetail).ExecuteCommand();
 
                 var num = Db.Queryable<BllExportNoticeDetail>()
@@ -947,6 +960,8 @@
                 if (num <= 0)
                 {
                     notice.Status = "4"; //鏇存敼涓烘墽琛屽畬鎴�
+                    noticeDetail.Status = "3";
+                    Db.Updateable(noticeDetail).ExecuteCommand();
                 }
                 //淇敼鍑哄簱鍗曚俊鎭�
                 Db.Updateable(notice).ExecuteCommand();
@@ -1372,12 +1387,14 @@
                                         #region 娣诲姞绉诲簱浠诲姟淇℃伅
                                         var stkModel = Db.Queryable<DataStockDetail>().First(m => m.LocatNo == slotBefore.LocatNo);
                                         string PalletNo = "LN000000";   // 榛樿婕旂ず鎵樼洏
+                                        string SkuNo = "";
                                         if (stkModel != null)
                                         {
                                             PalletNo = stkModel.PalletNo;
+                                            SkuNo = stkModel.SkuNo;
                                         }
                                         //鑾峰彇绉诲簱鐨勫簱浣�
-                                        var newSlot = MoveAddress(slotBefore.LocatNo, slotBefore.RoadwayNo, stkModel.SkuNo);
+                                        var newSlot = MoveAddress(slotBefore.LocatNo, slotBefore.RoadwayNo, SkuNo, slotBefore.AreaNo);
 
                                         var taskNo = new Common().GetMaxNo("TK");
                                         var exTask = new LogTask    //鍑哄簱浠诲姟
@@ -1387,7 +1404,7 @@
                                             Receiver = "PDA",
                                             IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
 
-                                            StartLocat = stkModel.LocatNo,//璧峰浣嶇疆
+                                            StartLocat = slotBefore.LocatNo,//璧峰浣嶇疆
                                             EndLocat = newSlot,//鐩爣浣嶇疆
                                             PalletNo = PalletNo,//鎵樼洏鐮�
                                             IsSend = 1,//鏄惁鍙啀娆′笅鍙�
@@ -2092,12 +2109,14 @@
                                         #region 娣诲姞绉诲簱浠诲姟淇℃伅
                                         var stkModel = Db.Queryable<DataStockDetail>().First(m=>m.LocatNo == slotBefore.LocatNo);
                                         string PalletNo = "LN000000";   // 榛樿婕旂ず鎵樼洏
+                                        string SkuNo = "";
                                         if (stkModel != null)
                                         {
                                             PalletNo = stkModel.PalletNo;
+                                            SkuNo= stkModel.SkuNo;
                                         }
                                         //鑾峰彇绉诲簱鐨勫簱浣�
-                                        var newSlot = MoveAddress(slotBefore.LocatNo, slotBefore.RoadwayNo, stkModel.SkuNo);
+                                        var newSlot = MoveAddress(slotBefore.LocatNo, slotBefore.RoadwayNo, SkuNo, slotBefore.AreaNo);
 
                                         var taskNo = new Common().GetMaxNo("TK");
                                         var exTask = new LogTask    // 绉诲簱浠诲姟
@@ -2107,7 +2126,7 @@
                                             Receiver = "WCS",
                                             IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
 
-                                            StartLocat = stkModel.LocatNo,//璧峰浣嶇疆
+                                            StartLocat = slotBefore.LocatNo,//璧峰浣嶇疆
                                             EndLocat = newSlot,//鐩爣浣嶇疆
                                             PalletNo = PalletNo,//鎵樼洏鐮�
                                             IsSend = 1,//鏄惁鍙啀娆′笅鍙�
@@ -2371,20 +2390,31 @@
         }
 
 
-        public string MoveAddress(string oldAddress, string roadWay, string skuNo)//01020201  鎺�-鍒�-灞�-娣卞害
+        public string MoveAddress(string oldAddress, string roadWay, string skuNo,string areaNo="")//01020201  鎺�-鍒�-灞�-娣卞害
         {
             string nowAddress = "";
 
-            //鏍规嵁鐗╂枡缂栫爜鑾峰彇瀵瑰簲鍖哄煙
-            var skuCategoryNo = Db.Queryable<SysMaterials>().Where(a => a.IsDel == "0" && a.SkuNo == skuNo).Select(a => a.CategoryNo).First();
-            var category = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.CategoryNo == skuCategoryNo);
+            var category = new SysMaterialCategory();
+            if (!string.IsNullOrEmpty(skuNo))
+            {
+                //鏍规嵁鐗╂枡缂栫爜鑾峰彇瀵瑰簲鍖哄煙
+                var skuCategoryNo = Db.Queryable<SysMaterials>().Where(a => a.IsDel == "0" && a.SkuNo == skuNo).Select(a => a.CategoryNo).First();
+                category = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.CategoryNo == skuCategoryNo);
+
+                areaNo = category.AreaNo;
+            }
+            else
+            {
+                //todo 寰呴獙璇�
+                category = Db.Queryable<SysMaterialCategory>().First(a => a.IsDel == "0" && a.AreaNo == areaNo);
+            }
 
             // 鑾峰彇绉诲簱鐩爣鍌ㄤ綅
             var row = int.Parse(oldAddress.Substring(0, 2));
             var lie = int.Parse(oldAddress.Substring(2, 2));
             var ceng = int.Parse(oldAddress.Substring(4, 2));
 
-            var sqlString = $@"select LocatNo,[Row],[Column],Layer, (ABS(Row-{row}) + ABS([Column]-{lie}) + ABS(Layer-{ceng}))  as distNum from SysStorageLocat where Flag = '0' and Status = '0' and Depth = '02' and RoadwayNo = '{roadWay}' and AreaNo in ('{category.AreaNo}') order by distNum;";
+            var sqlString = $@"select LocatNo,[Row],[Column],Layer, (ABS(Row-{row}) + ABS([Column]-{lie}) + ABS(Layer-{ceng}))  as distNum from SysStorageLocat where Flag = '0' and Status = '0' and Depth = '02' and RoadwayNo = '{roadWay}' and AreaNo in ('{areaNo}') order by distNum;";
 
             var addressModels = Db.Ado.SqlQuery<AddressCls>(sqlString).ToList();
             if (addressModels.Count > 0)   // 鍒ゆ柇鍚屽贩閬撳唴鎺掔┖搴撲綅
@@ -3204,6 +3234,7 @@
 
                         if (biaoShi != "2")
                         {
+                            pickQty += item.Qty;
                             //鍒犻櫎搴撳瓨绠辩爜鏄庣粏
                             Db.Deleteable(item).ExecuteCommand();
                         }
@@ -3211,17 +3242,19 @@
                         {
                             if (decimal.Parse(pickQty1) == item.Qty)
                             {
+                                pickQty += item.Qty;
                                 //鍒犻櫎搴撳瓨绠辩爜鏄庣粏
                                 Db.Deleteable(item).ExecuteCommand();
                             }
                             else
                             {
+                                pickQty += decimal.Parse(pickQty1);
                                 item.Qty -= decimal.Parse(pickQty1);
                                 item.BitBoxMark = "1";//闆剁鏍囪瘑
                                 Db.Updateable(item).ExecuteCommand();
                             }
                         }
-                        pickQty += item.Qty;
+                        
                     }
                     //鏀瑰彉搴撳唴绠辩爜鏄惁闆剁淇℃伅
                     if (biaoShi == "1")
@@ -3842,10 +3875,14 @@
                 {
                     throw new Exception("鏈煡璇㈠埌璇ュ嚭搴撳崟鐨勪俊鎭�");
                 }
-                if (notice.Status != "3")
+                if (notice.Type != "1" && notice.Type != "2" && notice.Type != "3")
                 {
-                    throw new Exception("鍑哄簱鍗曠殑鐘舵�佷笉鏄鍦ㄦ墽琛岋紝涓嶈兘鎷h揣");
+                    if (notice.Status != "3")
+                    {
+                        throw new Exception("鍑哄簱鍗曠殑鐘舵�佷笉鏄鍦ㄦ墽琛岋紝涓嶈兘鎷h揣");
+                    }
                 }
+               
                 //鍑哄簱鍗曟槑缁�
                 var noticeDetail = Db.Queryable<BllExportNoticeDetail>()
                     .First(m => m.IsDel == "0" && m.Id == int.Parse(soDetailId));
@@ -3882,7 +3919,7 @@
                 #region 鎷兼墭淇℃伅
                 var sdId = 0;
                 bool isNew = false;
-                var pinStockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == palletNoNew && m.SkuNo == allot.SkuNo && m.LotNo == allot.LotNo);
+                var pinStockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == palletNoNew);
                 if (pinStockDetail != null)
                 {
                     if (palletNo != palletNoNew)//闈炴暣鎵樻嫞璐�
@@ -4053,6 +4090,7 @@
                    
                     //淇敼鍑哄簱鍗曟槑缁嗘嫞璐ф暟閲�
                     noticeDetail.CompleteQty += pickQty;
+                    noticeDetail.Status = "2";
                     Db.Updateable(noticeDetail).ExecuteCommand();
 
                     var num = Db.Queryable<BllExportNoticeDetail>()
@@ -4060,6 +4098,8 @@
                     if (num <= 0)
                     {
                         notice.Status = "4"; //鏇存敼涓烘墽琛屽畬鎴�
+                        noticeDetail.Status = "3";
+                        Db.Updateable(noticeDetail).ExecuteCommand();
                     }
                     //淇敼鍑哄簱鍗曚俊鎭�
                     Db.Updateable(notice).ExecuteCommand();
@@ -4068,7 +4108,7 @@
                 {
                     var biaoShi = "0";//0锛氭暣绠辨嫞璐с��1锛氭暎鏀嫞璐с��2锛氭暟閲忔嫞璐�
                     List<DataBoxInfo> boxInfos;
-                    var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo);
+                    var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo && m.StockDetailId == stockDetail.Id);
                     if (boxInfo.Count() == 0)
                     {
                         throw new Exception("鏈煡璇㈠埌璇ョ鐮佸強杩芥函鐮佺殑淇℃伅");
@@ -4205,6 +4245,8 @@
                         }
                         else//鏁伴噺鎷h揣
                         {
+                            var boxInfo2 = Db.Queryable<DataBoxInfo>().First(m => m.IsDel == "0" && m.BoxNo == boxNo && m.StockDetailId == sdId);
+                            
                             if (decimal.Parse(pickQty1) == item.Qty)
                             {
                                 //淇敼搴撳瓨绠辩爜鏄庣粏
@@ -4216,9 +4258,53 @@
                             }
                             else
                             {
+                                if (boxInfo2 == null)
+                                {
+                                    var dataBoxInfo = new DataBoxInfo()
+                                    {
+                                        StockDetailId = sdId,
+                                        BindNo = item.BindNo,
+                                        BoxNo = item.BoxNo,
+                                        BoxNo2 = item.BoxNo2,
+                                        BoxNo3 = item.BoxNo3,
+                                        PalletNo = item.PalletNo,
+                                        PalletNo2 = item.PalletNo2,
+                                        PalletNo3 = item.PalletNo3,
+                                        Qty = decimal.Parse(pickQty1),
+                                        FullQty = item.FullQty,
+                                        Status = "5",
+                                        LotNo = item.LotNo,
+                                        LotText = item.LotText,
+                                        SkuNo = item.SkuNo,
+                                        SkuName = item.SkuName,
+                                        Standard = item.Standard,
+                                        ProductionTime = item.ProductionTime,
+                                        SupplierLot = item.SupplierLot,
+                                        InspectMark = item.InspectMark,
+                                        BitBoxMark = "1",
+                                        InspectStatus = item.InspectStatus,
+                                        InspectTime = item.InspectTime,
+                                    };
+
+                                    Db.Insertable(dataBoxInfo).ExecuteCommand();
+                                }
+                                else
+                                {
+                                    boxInfo2.Qty += decimal.Parse(pickQty1);
+                                    item.BitBoxMark = boxInfo2.Qty>= boxInfo2.FullQty? "0":"1" ;//闆剁鏍囪瘑
+                                    Db.Updateable(boxInfo2).ExecuteCommand();
+                                }
                                 item.Qty -= decimal.Parse(pickQty1);
                                 item.BitBoxMark = "1";//闆剁鏍囪瘑
-                                Db.Updateable(item).ExecuteCommand();
+                                if (item.Qty<=0)
+                                {
+                                    Db.Deleteable(item).ExecuteCommand();
+                                }
+                                else
+                                {
+                                    Db.Updateable(item).ExecuteCommand();
+                                }
+
                             }
 
                             pickQty += int.Parse(pickQty1);
@@ -4285,6 +4371,7 @@
                     }
                     //淇敼鍑哄簱鍗曟槑缁嗘嫞璐ф暟閲�
                     noticeDetail.CompleteQty += pickQty;
+                    noticeDetail.Status = "2";
                     Db.Updateable(noticeDetail).ExecuteCommand();
 
                     var num = Db.Queryable<BllExportNoticeDetail>()
@@ -4292,17 +4379,21 @@
                     if (num <= 0)
                     {
                         notice.Status = "4"; //鏇存敼涓烘墽琛屽畬鎴�
+                        noticeDetail.Status = "3";
+                        Db.Updateable(noticeDetail).ExecuteCommand();
                     }
+                    
                     //淇敼鍑哄簱鍗曚俊鎭�
                     Db.Updateable(notice).ExecuteCommand();
                 }
 
                 if (isNew)
                 {
-                    sd.Qty = pickQty;
-                    sd.LockQty = pickQty;
+                    var sd2 = Db.Queryable<DataStockDetail>().First(m=>m.Id == sdId);
+                    sd2.Qty = pickQty;
+                    sd2.LockQty = pickQty;
 
-                    Db.Updateable(sd).ExecuteCommand();
+                    Db.Updateable(sd2).ExecuteCommand();
                 }
                 else
                 {
@@ -4618,6 +4709,7 @@
 
                 //淇敼鍑哄簱鍗曟槑缁嗘嫞璐ф暟閲�
                 noticeDetail.CompleteQty += int.Parse(PickQty);
+                noticeDetail.Status = "2";
                 Db.Updateable(noticeDetail).ExecuteCommand();
 
                 var num = Db.Queryable<BllExportNoticeDetail>()
@@ -4625,6 +4717,8 @@
                 if (num <= 0)
                 {
                     notice.Status = "4"; //鏇存敼涓烘墽琛屽畬鎴�
+                    noticeDetail.Status = "3";
+                    Db.Updateable(noticeDetail).ExecuteCommand();
                 }
                 //淇敼鍑哄簱鍗曚俊鎭�
                 Db.Updateable(notice).ExecuteCommand();

--
Gitblit v1.8.0