From 86985a3e211ab4cc1e94a696c15a6f77d21c462a Mon Sep 17 00:00:00 2001
From: chengsc <Demo@DESKTOP-CPA90BF>
Date: 星期二, 15 十月 2024 18:36:51 +0800
Subject: [PATCH] 修改出库单据问题

---
 Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs | 1113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 1,041 insertions(+), 72 deletions(-)

diff --git a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
index f691ddc..faa19db 100644
--- a/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
+++ b/Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -15,6 +15,13 @@
 using WMS.Entity.BllSoEntity;
 using Model.ModelVm.PdaVm;
 using Model.ModelDto.PdaDto;
+using Dm;
+using Model.InterFaceModel;
+using WMS.Entity.BllQualityEntity;
+using Newtonsoft.Json;
+using Utility.Tools;
+using System.Reflection;
+using System.IO;
 
 namespace WMS.BLL.BllPdaServer
 {
@@ -23,14 +30,48 @@
         private static readonly SqlSugarScope Db = DataContext.Db;
 
         // 鑾峰彇鍗曟嵁鍒楄〃
-        public List<ArrivalNoticeDto> GetArrivalNotices(ArrivalNoticeVm model)
+        public List<string> GetArrivalNotices(ArrivalNoticeVm model)
         {
             string sqlString = string.Empty;
             try
             {
                 // 鏈叧鍗曠殑鍗曟嵁
-                sqlString = $"select * from BllArrivalNotice where Type in ({model.Type}) and Status != '3' and Status != '4'  and IsDel='0' order by CreateTime;";
-                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDto>(sqlString);
+                //sqlString = $"select * from BllArrivalNotice where Type in ({model.Type}) and Status != '3' and Status != '4'  and IsDel='0' order by CreateTime;";
+                //var modelList = Db.Ado.SqlQuery<ArrivalNoticeDto>(sqlString);
+
+                //model.Type锛氬崟鎹被鍨� 鍦ㄨ繖閲屼唬琛ㄥ墠绔〉绛剧被鍨嬶細鍗虫爣绛鹃〉绛撅細璐存爣鐗╂枡锛� 鏁伴噺椤电锛氫笉璐磋〃鐗╂枡锛屽師鍥狅細鎳掑緱鍔犲弬鏁�
+                var data = Db.Queryable<BllArrivalNotice>().Where(m => m.IsDel == "0" && m.Status != "3" && m.Status != "4").Select(m=>m.ASNNo).ToList();
+                var list = new List<string>();
+                if (model.Type == "0")//0璐存爣
+                {
+                    list = Db.Queryable<BllArrivalNoticeDetail>().Where(m =>m.IsDel == "0" && data.Contains(m.ASNNo) && !string.IsNullOrWhiteSpace(m.PackagNo)).Select(m => m.ASNNo).Distinct().ToList();
+                }
+                else if(model.Type == "1")//1涓嶈创鏍�
+                {
+                    list = Db.Queryable<BllArrivalNoticeDetail>().Where(m => m.IsDel == "0" && data.Contains(m.ASNNo) && string.IsNullOrWhiteSpace(m.PackagNo)).Select(m=>m.ASNNo).Distinct().ToList();
+                }
+                else
+                {
+                    throw new Exception("椤电绫诲瀷鍙傛暟閿欒");
+                }
+                
+
+                return list;
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        //鏍规嵁鍏ュ簱鍗曞彿鑾峰彇鍏ュ簱鎬诲崟淇℃伅
+        public List<BllArrivalNotice> GetArrivalNotice(ArrivalNoticeVm model)
+        {
+            string sqlString = string.Empty;
+            try
+            {
+                sqlString = $"select * from BllArrivalNotice where ASNNo = '{model.ASNNo}' and isdel='0'  ";
+                var modelList = Db.Ado.SqlQuery<BllArrivalNotice>(sqlString);
 
                 return modelList;
             }
@@ -49,7 +90,17 @@
                 sqlString = $"select * from BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' and isdel='0' order by CreateTime;";
                 var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
 
-                return modelList;
+                List<ArrivalNoticeDetailDto> list = new List<ArrivalNoticeDetailDto>();
+                foreach (var item in modelList)
+                {
+                    string str = BySkuNoGetPackInfo(item.SkuNo);
+                    if (str == "涓嶅瓨鍦�")
+                    {
+                        list.Add(item);
+                    }
+                }
+
+                return list;
             }
             catch (Exception ex)
             {
@@ -157,6 +208,31 @@
                     sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; ";
                 }
                 var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
+
+                return models;
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        // 鏍规嵁鎵樼洏鍙锋垨绠辩爜鑾峰彇鎵樼洏淇℃伅   liudl 
+        public List<PalletBindDto> GetPalletBindInfo(BllPalletBind model)
+        {
+            try
+            {
+                string sqlString = string.Empty;
+                sqlString = "select b.SkuNo,b.SkuName,a.LotNo,a.Qty,a.PalletNo,a.Id from BllPalletBind a left join BllArrivalNoticeDetail b on a.ASNDetailNo = b.Id where a.IsDel = '0' and b.IsDel = '0' ";
+                if (!string.IsNullOrEmpty(model.PalletNo))
+                {
+                    sqlString += $"and PalletNo = '{model.PalletNo}' and a.Status = '0' ";
+                }
+                else
+                {
+                    throw new Exception("鎵樼洏鍙峰紓甯革紒");
+                }
+                var models = Db.Ado.SqlQuery<PalletBindDto>(sqlString);
 
                 return models;
             }
@@ -322,12 +398,12 @@
             {
                 //鑾峰彇浠诲姟淇℃伅
                 var logtask = Db.Queryable<LogTask>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && a.Status == "1");
-                if (logtask == null)
+                if (logtask != null)
                 {
                     strMsg = "璇ユ墭鐩樹换鍔″凡瀹屾垚 鎴栨湭鎴愬姛鍒涘缓浠诲姟 璇锋牳瀹烇紒";
                     return strMsg;
                 }
-                string bindstr = "select * from BllPalletBind Where IsDel = @isdel and PalletNo = @palletno and ASNDetailNo = 0 and ASNNo = ''";
+                string bindstr = "select * from BllPalletBind Where IsDel = @isdel and PalletNo = @palletno and ASNDetailNo = 0 and ASNNo = '' ";
                 //鑾峰彇缁戝畾鎵樼洏琛ㄤ俊鎭�
                 List<PalletBindVm> bindVms = Db.Ado.SqlQuery<PalletBindVm>(bindstr, new
                 {
@@ -343,10 +419,13 @@
                     return strMsg;
                 }
                 //鍒犻櫎缁戝畾鎵樼洏琛ㄤ俊鎭�
-                string delstr = "delete from BllPalletBind Where PalletNo = @palletno";
+                string delstr = "update BllPalletBind set IsDel = 1,UpdateUser = @UpdateUser,UpdateTime = @UpdateTime Where PalletNo = @palletno and Id =@Id ";
                 int i = Db.Ado.ExecuteCommand(delstr, new
                 {
-                    palletno = upBindPalletNo
+                    UpdateUser = createUser,
+                    UpdateTime = DateTime.Now,
+                    palletno = upBindPalletNo,
+                    Id = bindVms[0].Id
                 });
                 //淇敼鎵樼洏鐘舵��
                 Db.BeginTran();
@@ -357,7 +436,7 @@
                     UpbindPalletNo = upBindPalletNo,
                     PalletNo2 = bindVms[0].PalletNo2,
                     PalletNo3 = bindVms[0].PalletNo3,
-                    Qty = (int)bindVms[0].Qty,
+                    Qty = bindVms[0].Qty,
                     LotNo = bindVms[0].LotNo,
                     LotText = bindVms[0].LotText,
                     SupplierLot = bindVms[0].SupplierLot,
@@ -373,12 +452,12 @@
                 box.IsDel = "1";
                 Db.Updateable(box).ExecuteCommand();
 
-                //淇敼浠诲姟鐘舵��
-                logtask.IsDel = "1";
-                logtask.Status = "4"; //3 宸插彇娑�
-                logtask.UpdateUser = createUser; //鍙栨秷浜�
-                logtask.UpdateTime = DateTime.Now; //鍙栨秷鏃堕棿
-                Db.Updateable(logtask).ExecuteCommand();
+                ////淇敼浠诲姟鐘舵��
+                //logtask.IsDel = "1";
+                //logtask.Status = "4"; //3 宸插彇娑�
+                //logtask.UpdateUser = createUser; //鍙栨秷浜�
+                //logtask.UpdateTime = DateTime.Now; //鍙栨秷鏃堕棿
+                //Db.Updateable(logtask).ExecuteCommand();
                 //鏇存敼搴撳瓨鏁伴噺
                 //string str = $"update DataStock set Qty = Qty - {(int)bindVms[0].Qty} Where SkuNo = '100099'";
                 // 鏇存敼鎵樼洏浣跨敤鐘舵��
@@ -485,6 +564,121 @@
             }
         }
 
+        // 鍒犻櫎宸茬粍淇℃伅
+        public string DelPalletBind(BllPalletBind model)
+        {
+            string strMsg = "";
+            string sqlString = string.Empty;
+            try
+            {
+                if (model.Id == 0)
+                {
+                    throw new Exception("-1:鎵樼洏ID涓嶅彲涓�0锛�");
+                }
+
+                //鑾峰彇鎵樼洏缁戝畾淇℃伅
+                var bind = Db.Queryable<BllPalletBind>().First(a => a.IsDel == "0" && a.Status == "0" && a.Id == model.Id);
+                //楠岃瘉鎵樼洏缁戝畾淇℃伅鏄惁涓虹┖
+                if (bind == null)
+                {
+                    throw new Exception("-1:鏈幏鍙栧埌瀵瑰簲鎵樼洏淇℃伅锛岃鏍稿疄锛�");
+                }
+                //鍒ゆ柇鎵樼洏缁戝畾淇℃伅鏄惁涓嶆槸绛夊緟鎵ц
+                if (bind.Status != "0")
+                {
+                    throw new Exception("-1:璇ユ墭鐩樺凡姝e湪鍏ュ簱锛岃鏍稿疄锛�");
+                }
+                //鑾峰彇鏄惁鏈夋寚瀹氬簱浣�
+                SysStorageLocat locat = new SysStorageLocat();
+                int isNullLocat = 0;
+                //鍒ゆ柇鍌ㄤ綅鏄惁涓虹┖
+                if (!string.IsNullOrWhiteSpace(bind.LocatNo))
+                {
+                    isNullLocat = 1;
+                    locat = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.WareHouseNo == bind.WareHouseNo && a.RoadwayNo == bind.RoadwayNo && a.LocatNo == bind.LocatNo);
+                    //鍒ゆ柇鍌ㄤ綅鍦板潃鏄惁涓烘鍦ㄥ叆搴�
+                    if (locat.Status != "2")
+                    {
+                        throw new Exception("-1:褰撳墠鎵樼洏缁戝畾鐨勫偍浣嶅湴鍧�涓嶆槸姝e湪鍏ュ簱锛岃鏍稿疄锛�");
+                    }
+                }
+                //鑾峰彇鎵樼洏淇℃伅
+                var pallet = Db.Queryable<SysPallets>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo);
+                //鍒ゆ柇鎵樼洏淇℃伅鏄惁涓虹┖
+                if (pallet == null)
+                {
+                    throw new Exception("-1:鏈幏鍙栧埌瀵瑰簲鎵樼洏淇℃伅锛岃鏍稿疄锛�");
+                }
+                //鑾峰彇瀵瑰簲鍏ュ簱鍗曟嵁鎬诲崟
+                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == bind.ASNNo);
+                //楠岃瘉鍏ュ簱鍗曟�诲崟淇℃伅
+                if (notice == null)
+                {
+                    throw new Exception("-1:鏈幏鍙栧埌瀵瑰簲鍏ュ簱鍗曟�诲崟淇℃伅锛岃鏍稿疄锛�");
+                }
+                //鑾峰彇瀵瑰簲鍏ュ簱鍗曟嵁鏄庣粏
+                var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.Id == bind.ASNDetailNo);
+                //楠岃瘉鍏ュ簱鍗曞崟鎹槑缁�
+                if (noticeDetail == null)
+                {
+                    throw new Exception("-1:鏈幏鍙栧埌瀵瑰簲鍏ュ簱鍗曞崟鎹槑缁嗕俊鎭紝璇锋牳瀹烇紒");
+                }
+
+
+                Db.BeginTran();
+                //鍑忓皯鍏ュ簱鍗曟槑缁嗘暟閲� 鍒ゆ柇宸茬粍鏁伴噺鏄惁涓�0 鍐嶅垽鏂畬鎴愭暟閲忔槸鍚︿负0
+                noticeDetail.FactQty -= bind.Qty;
+                //鍒ゆ柇宸茬粍鏁伴噺鏄惁涓�0
+                if (noticeDetail.FactQty == 0)
+                {
+                    //鍒ゆ柇鏄惁鏈夊畬鎴愭暟閲�
+                    if (noticeDetail.CompleteQty == 0)
+                    {
+                        noticeDetail.Status = "0"; //鍏ュ簱鍗曟槑缁嗙姸鎬�
+                        notice.Status = "0"; //鍏ュ簱鍗曟�诲崟鐘舵��
+                    }
+                }
+                Db.Updateable(noticeDetail).ExecuteCommand();
+                Db.Updateable(notice).ExecuteCommand();
+
+
+                // 娓呴櫎鎵樼洏缁戝畾涓婁俊鎭�
+                //ASNNo,ASNDetailNo,Qty,FullQty,LotNo,LotText,SupplierLot,IsDel,UpdateTime,UpdateUser
+                bind.ASNNo = ""; //鍏ュ簱鍗曞彿
+                bind.ASNDetailNo = 0; //鍏ュ簱鍗曟槑缁唅d
+                bind.Qty = 0; //鏁伴噺
+                bind.FullQty = 0; //鏁存墭鏁伴噺
+                bind.LotNo = ""; //鎵规
+                bind.LotText = ""; //鎵规鎻忚堪
+                bind.SupplierLot = ""; //渚涜揣鎵规
+                bind.IsDel = "1"; //鏄惁鍒犻櫎
+                bind.UpdateTime = Db.GetDate(); //淇敼鏃堕棿
+                bind.UpdateUser = model.CreateUser; //淇敼浜�
+                if (isNullLocat == 1)
+                {
+                    bind.LocatNo = ""; //鍌ㄤ綅鍦板潃
+                    bind.RoadwayNo = ""; //鎵�灞炲贩閬�
+                    bind.WareHouseNo = ""; //鎵�灞炰粨搴�
+                    //淇敼鍌ㄤ綅淇℃伅鐘舵��
+                    locat.Status = "0"; //鍌ㄤ綅鐘舵�� 0锛氱┖鍌ㄤ綅
+                    Db.Updateable(locat).ExecuteCommand();
+                }
+                Db.Updateable(bind).ExecuteCommand();
+
+                //淇敼鎵樼洏淇℃伅鐘舵��
+                pallet.Status = "0"; //0锛氭湭浣跨敤
+                Db.Updateable(pallet).ExecuteCommand();
+
+                Db.CommitTran();
+                return strMsg;
+            }
+            catch (Exception ex)
+            {
+                Db.RollbackTran();
+                throw ex;
+            }
+        }
+
         // 骞冲簱瀹屾垚鍏ュ簱鎿嶄綔
         public string CompleteInStock(PalletBindVm model)
         {
@@ -534,7 +728,7 @@
                 #endregion
 
                 #region 鍦扮爜淇℃伅(鍌ㄤ綅淇℃伅)
-                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0");
+                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0" && w.WareHouseNo == "W02");
                 if (storageLocat == null)
                 {
                     strMsg = "-1:鍌ㄤ綅淇℃伅涓嶅瓨鍦ㄦ垨闈炵┖闂茬姸鎬侊紝璇锋牳鏌�!";
@@ -628,7 +822,7 @@
                             return strMsg;
                         }
                         #endregion
-                        var pallQty = 0;//鎵樼洏涓婃暟閲�
+                        decimal pallQty = 0;//鎵樼洏涓婃暟閲�
                         var boxinfo2 = boxinfo.Where(w => w.SkuNo == noticeItem.SkuNo && w.LotNo == noticeItem.LotNo && w.PalletNo == model.PalletNo).ToList();
                         if (boxinfo2.Count <= 0)
                         {
@@ -780,6 +974,8 @@
 
                         //淇敼缁勬墭鐘舵��
                         palletbindInfo.Status = "2"; //2 鍏ュ簱瀹屾垚
+                        palletbindInfo.WareHouseNo = "W02";//鎵�灞炰粨搴�
+                        palletbindInfo.LocatNo = model.LocatNo;//鍌ㄤ綅鍦板潃
                         palletbindInfo.UpdateTime = serverTime;
                         palletbindInfo.UpdateUser = model.CreateUser;
                         palletbindInfo.CompleteTime = serverTime; //瀹屾垚鏃堕棿
@@ -946,6 +1142,11 @@
 
                     #endregion
                 }
+                storageLocat.Status = "1";
+                storageLocat.UpdateTime = serverTime; //淇敼鏃堕棿
+                storageLocat.UpdateUser = model.CreateUser; //淇敼浜�
+                //淇敼鍌ㄤ綅鐘舵��                                           
+                Db.Updateable(storageLocat).ExecuteCommand();
 
                 new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "骞冲簱鍏ュ簱", model.PalletNo, "瀹屾垚", $"鍦≒DA涓婂畬鎴愬崟鎹彿涓猴細{model.ASNNo}鐨勬墭鐩樼爜涓猴細{model.PalletNo}鐨勫钩搴撳叆搴撴搷浣�", (int)model.CreateUser);
 
@@ -1132,6 +1333,30 @@
             }
         }
 
+        /// <summary>
+        /// 楠岃瘉鍌ㄤ綅鍦板潃(鍦扮爜)鏄惁鍙敤
+        /// </summary>
+        /// <param name="locatNo">鍌ㄤ綅缂栫爜</param>
+        /// <returns></returns>
+        public string CheckLocatNo(string locatNo)
+        {
+            try
+            {
+                string strMsg = "";
+                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == locatNo && w.Status == "0" && w.WareHouseNo == "W02");
+                if (storageLocat == null)
+                {
+                    throw new Exception("-1:鍦扮爜(鍌ㄤ綅淇℃伅)涓嶅瓨鍦ㄦ垨闈炵┖闂茬姸鎬侊紝璇锋牳鏌�!");
+                }
+
+                return strMsg;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception(ex.Message);
+            }
+        }
+
         //鏍规嵁绠辩爜鑾峰彇鐗╂枡銆佹壒娆°�佹暟閲忕瓑淇℃伅
         public PdaPalletNoCheckDto GetBoxInfoByBoxNo(string boxNo)
         {
@@ -1198,7 +1423,7 @@
                 {
                     throw new Exception("-1:绠辩爜淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
                 }
-                var bNum = 0;//鏁伴噺
+                decimal bNum = 0;//鏁伴噺
                 //楠岃瘉绠辩爜鏄惁宸茬粦瀹氭墭鐩�
                 foreach (var item in boxinfo)
                 {
@@ -1481,6 +1706,104 @@
         }
 
         #region 浜у搧缁勬墭
+
+        public void GetBoxInfoByFuMa(string boxNo,string url)
+        {
+            try
+            {
+                var list = new List<BllBoxInfo>();
+
+                var data = new { BoxNo = boxNo };
+                var jsonData = JsonConvert.SerializeObject(data);
+
+                #region 娴嬭瘯鐗堟湰
+
+                //璇诲彇json鏂囦欢锛屾坊鍔犳暟鎹�
+                var ss = AppDomain.CurrentDomain.BaseDirectory;
+                string filePath = Path.Combine(ss, "CreateBoxInfo.json");
+                string json = File.ReadAllText(filePath);
+                var person = JsonConvert.DeserializeObject<List<BllBoxInfo>>(json);
+
+                var comTime = DateTime.Now;
+                //娣诲姞绠辩爜淇℃伅琛ㄤ腑  //鏆傛椂杩欎簺鍐�--娣诲姞鏁版嵁锛屽悗缁渶瑕佸拰璧嬬爜绯荤粺瀵规帴鍚� 鏍规嵁鏄庣‘杩斿洖鐨勬暟鎹牸寮忔洿鏀�
+                foreach (var item in person)
+                {
+                    if (item.BoxNo!= boxNo)
+                    {
+                        continue;
+                    }
+
+                    var sku = Db.Queryable<SysMaterials>().First(m=>m.IsDel =="0" && m.SkuNo == item.SkuNo);
+                    if (sku == null)
+                    {
+                        continue;
+                    }
+                    var boxInfo = new BllBoxInfo()
+                    {
+                        ASNNo = "",
+                        //ASNDetailNo = 0,
+                        OrderCode = "",
+                        //BindNo = 0,
+                        BoxNo = item.BoxNo,
+                        BoxNo2 = item.BoxNo2,
+                        BoxNo3 = item.BoxNo3,
+                        PalletNo = "",
+                        Qty = item.Qty,
+                        FullQty = item.FullQty,
+                        Status = "0",
+                        SkuNo = item.SkuNo,
+                        SkuName = sku.SkuName,
+                        LotNo = item.LotNo,
+                        LotText = item.LotText,
+                        SupplierLot = item.SupplierLot,
+                        ProductionTime = item.ProductionTime,
+                        ExpirationTime = item.ExpirationTime,
+                        //CompleteTime = comTime,
+                        InspectMark = item.InspectMark,
+                        BitBoxMark = item.BitBoxMark,
+                        InspectStatus = item.InspectStatus,
+                        Origin = "璧嬬爜",
+                        Standard = item.Standard,
+                        PackageStandard = item.PackageStandard,
+                        StoreTime = item.StoreTime,
+                        QtyOrd = item.QtyOrd,
+                        QtyCount = item.QtyCount,
+                        CreateUser = 0,
+                        CreateTime = comTime,
+                    };
+                    list.Add(boxInfo);
+                }
+                Db.Insertable(list).ExecuteCommand();
+
+                #endregion
+
+                #region 姝e紡鐗堟湰
+
+
+                ////绋嬪簭姝e紡鍙戝竷鍚庢斁寮�
+                //var time1 = DateTime.Now;//鍙戦�佹椂闂� .ToString("yyyy-MM-dd HH:mm:ss")
+                //var response = HttpHelper.DoPost(url, jsonData, "鑾峰彇绠辩爜淇℃伅", "璧嬬爜");
+                //var time2 = DateTime.Now;//杩斿洖鏃堕棿 .ToString("yyyy-MM-dd HH:mm:ss")
+
+                ////瑙f瀽杩斿洖鏁版嵁 
+                //var fuMaModel = JsonConvert.DeserializeObject<FuMaModel>(response);
+                //if (fuMaModel.Success == 0)
+                //{
+
+                //}
+                //if (fuMaModel.Success == -1)
+                //{
+                //    throw new Exception($"璧嬬爜绯荤粺杩斿洖鐘舵�佸紓甯革細{fuMaModel.Message}");
+                //}
+                #endregion
+
+            }
+            catch (Exception e)
+            {
+                throw new Exception(e.Message);
+            }
+        }
+
         /// <summary>
         /// 鏍规嵁绠辩爜鑾峰彇鏍囩绠辩爜淇℃伅
         /// </summary>
@@ -1493,6 +1816,19 @@
                 if (string.IsNullOrEmpty(model.BoxNo))
                 {
                     throw new Exception("璇锋壂鎻忓绠辨潯鐮�!");
+                }
+                if (!string.IsNullOrWhiteSpace(model.ASNNo))
+                {
+                    var asnData = Db.Queryable<BllArrivalNotice>().First(m => m.IsDel == "0" && m.ASNNo == model.ASNNo);
+                    if (asnData != null && (asnData.Type == "0" || asnData.Type == "3"))
+                    {
+                        var count = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.Status == "0" && m.BoxNo == model.BoxNo);
+                        if (count == 0)
+                        {
+                            GetBoxInfoByFuMa(model.BoxNo, ""); //浠庤祴鐮佺郴缁熻幏鍙栫鐮佷俊鎭�
+                        }
+                    }
+                    
                 }
                 string sqlString = $@"SELECT 
                                         ASNNo,
@@ -1507,7 +1843,7 @@
                                         AND BoxNo = '{model.BoxNo}'
                                       GROUP BY ASNNo,BoxNo,SkuNo,SkuName,LotNo; ";
                 var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString);
-                if (models == null)
+                if (models.Count == 0)
                 {
                     throw new Exception("绠辩爜淇℃伅涓嶅瓨鍦�!");
                 }
@@ -1518,13 +1854,104 @@
                 throw ex;
             }
         }
+        // 鏍规嵁鍗曟嵁鍙疯幏鍙栧崟鎹槑缁嗗垪琛�
+        public List<ArrivalNoticeDetailDto> GetBindArrivalNoticeDetails(ArrivalNoticeVm model)
+        {
+            string sqlString = string.Empty;
+            try
+            {
+                sqlString = $"select * from BllArrivalNoticeDetail where ASNNo = '{model.ASNNo}' and isdel='0' order by CreateTime;";
+                var modelList = Db.Ado.SqlQuery<ArrivalNoticeDetailDto>(sqlString);
+                List<ArrivalNoticeDetailDto> noticeList = new List<ArrivalNoticeDetailDto>();
+                foreach (var item in modelList)
+                {
+                    if (string.IsNullOrEmpty(item.LotNo))
+                    {
+                        noticeList.Add(item);
+                    }
+                    else
+                    {
+                        string[] LotNoList = item.LotNo.Split(';');
+                        foreach (var item2 in LotNoList)
+                        {
+                            ArrivalNoticeDetailDto entry = new ArrivalNoticeDetailDto()
+                            {
+                                Id = item.Id,
+                                ASNNo = item.ASNNo,
+                                CompleteQty = item.CompleteQty,
+                                CompleteTime = item.CompleteTime,
+                                CreateTime = item.CreateTime,
+                                Qty = item.Qty,
+                                FactQty = item.FactQty,
+                                LotNo = item2,
+                                Money = item.Money,
+                                PackagNo = item.PackagNo,
+                                PackagName = item.PackagName,
+                                Status = item.Status,
+                                SkuNo = item.SkuNo,
+                                SkuName = item.SkuName,
+                            };
 
 
+                            noticeList.Add(entry);
+                        }
+                    }
+                }
+                List<ArrivalNoticeDetailDto> list = new List<ArrivalNoticeDetailDto>();
+                foreach (var item in noticeList)
+                {
+                    string str = BySkuNoGetPackInfo(item.SkuNo);
+                    if (str == "瀛樺湪")
+                    {
+                        list.Add(item);
+                    }
+                }
+
+                return list;
+            }
+            catch (Exception ex)
+            {
+                throw ex;
+            }
+        }
+
+        //鏍规嵁鐗╂枡鑾峰彇鏄惁瀛樺湪鍖呰淇℃伅
+        public string BySkuNoGetPackInfo(string skuNo)
+        {
+            try
+            {
+                //鑾峰彇鐗╂枡淇℃伅
+                var sku = Db.Queryable<SysMaterials>().First(a => a.IsDel == "0" && a.SkuNo == skuNo);
+                //鍒ゆ柇鐗╂枡淇℃伅鏄惁涓虹┖
+                if (!string.IsNullOrWhiteSpace(sku.PackagNo))
+                {
+                    return "瀛樺湪";
+                }
+                else
+                {
+                    return "涓嶅瓨鍦�";
+                }
+            }
+            catch (Exception ex)
+            {
+                return ex.Message;
+            }
+        }
+
+        /// <summary>
+        /// 缁戝畾鎵樼洏
+        /// </summary>
+        /// <param name="model"></param>
+        /// <param name="userId"></param>
+        /// <param name="origin"></param>
         public void BindPallet(PdaPalletBindVm model, int userId, string origin)
         {
             try
             {
                 #region 鍒ゆ柇
+
+                //0锛氭垚鍝佸叆搴� 1锛氶噰璐叆搴� 2锛氫腑闂村搧鍏ュ簱 3锛氶��璐у叆搴� 4锛氳溅闂翠綑鏂欏叆搴� 5锛氬叾瀹冨叆搴� 6锛氫唬鍌ㄥ叆搴� 7锛氬瘎瀛樺叆搴�
+                var TypeLot = "1, 2, 5, 6, 7";
 
                 if (string.IsNullOrEmpty(model.AsnNo))
                 {
@@ -1538,8 +1965,36 @@
                 {
                     throw new Exception("-1:鎵樼洏鍙蜂笉鍙负绌�!");
                 }
+                //鏍规嵁鍗曟嵁鍙疯幏鍙栧叆搴撳崟鎬诲崟
+                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
+                if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
+                {
+                    throw new Exception("-1:璇ュ崟鎹凡鍏冲崟!");
+                }
+                if (string.IsNullOrEmpty(model.LotNo))
+                {
+                    //鍒ゆ柇鏄惁涓轰笉闄愬埗鎵规鍗曟嵁
+                    if (!TypeLot.Contains(notice.Type))
+                    {
+                        throw new Exception("-1:鐗╂枡鎵规涓嶅彲涓虹┖!");
+                    }
+
+                }
+                else
+                {
+                    //浠庣墿鏂欏悕绉�-鎵规涓彇鍑烘壒娆�
+                    int indexOfDash = model.LotNo.IndexOf("-");
+                    if (indexOfDash != -1)
+                    {
+                        model.LotNo = model.LotNo.Substring(indexOfDash + 1);
+                    }
+                    else
+                    {
+                        model.LotNo = "";
+                    }
+                }
                 //鍒ゆ柇鐗╂枡鏁伴噺鏄惁涓�0 涓�0鍒ゆ柇绠辩爜淇℃伅 涓嶄负0缁х画
-                if (model.SkuQty == 0)
+                if (model.TableType == 0)
                 {
                     if (string.IsNullOrEmpty(model.BoxNo))
                     {
@@ -1555,6 +2010,53 @@
 
                     }
                 }
+                int isTextTable = model.TableType;
+                int isDeposit = 0;
+                //鍒ゆ柇鎬诲崟鍗曟嵁鏄惁涓哄瘎瀛樺崟鎹�
+                if (notice.Type == "7")
+                {
+                    isDeposit = 1;
+                }
+                if (isDeposit == 1)
+                {
+                    //鍒ゆ柇鎬诲崟澶囨敞鏄惁涓虹┖
+                    if (!string.IsNullOrWhiteSpace(notice.Demo))
+                    {
+                        //鍒嗗壊鎬诲崟澶囨敞鍙婃墭鐩樺娉�
+                        var noticeDemo = notice.Demo.Split('銆�'); //鎬诲崟澶囨敞
+                        var palletDemo = model.Demo.Split('銆�'); //鎵樼洏澶囨敞
+
+                        //寰幆鎵樼洏澶囨敞
+                        foreach (var itemPallet in palletDemo)
+                        {
+                            int isDemo = 0;
+                            //寰幆鎬诲崟澶囨敞
+                            foreach (var itemNotice in noticeDemo)
+                            {
+                                //鍒ゆ柇鏄惁鏈夌浉鍚屽娉�
+                                if (itemPallet == itemNotice)
+                                {
+                                    isDemo = 1;
+                                    break;
+                                }
+                            }
+                            if (isDemo == 0)
+                            {
+                                throw new Exception("-1:鎬诲崟澶囨敞涓庢墭鐩樺娉ㄤ笉绗︼紝璇锋牳瀹炲悗閲嶆柊缁戝畾!");
+                            }
+                        }
+                    }
+                    else if (string.IsNullOrWhiteSpace(notice.Demo))
+                    {
+                        //鍒ゆ柇鎵樼洏澶囨敞鏄惁涓虹┖
+                        if (!string.IsNullOrWhiteSpace(model.Demo))
+                        {
+                            throw new Exception("-1:璇锋坊鍔犳�诲崟澶囨敞鍚庤緭鍏ユ墭鐩樺娉�!");
+                        }
+                    }
+                }
+
+
                 #endregion
 
                 Db.BeginTran();
@@ -1565,8 +2067,14 @@
                 {
                     throw new Exception("鏈煡璇㈠埌鎵樼洏淇℃伅锛岃鏍稿疄锛�");
                 }
+                //鍒ゆ柇鎵樼洏鏄惁鍦ㄥ簱澶�
+                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
+                if (stockDetail != null)// && !string.IsNullOrEmpty(stockDetail.WareHouseNo)
+                {
+                    throw new Exception("璇ユ墭鐩樺湪搴撳瓨宸叉湁淇℃伅锛岃鏍稿疄锛�");
+                }
                 // 楠岃瘉鍏ュ簱鍗曟槑缁嗘槸鍚﹀瓨鍦�
-                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo);
+                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo));
                 if (detail == null)
                 {
                     throw new Exception("-1:褰撳墠鐗╂枡鍙婃壒娆′笌鍗曟嵁鏃犲叧鑱旓紝璇锋牳瀹�!");
@@ -1575,40 +2083,46 @@
                 var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                 var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                 var pack = package.First(m => m.IsDel == "0" && m.PackagNo == sku.PackagNo);
-                if (pack == null)
-                {
-                    throw new Exception("-1:鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!");
-                }
+
                 var pNum = 0;//鎵樼洏鐗╁搧鏁伴噺 
                 var bNum = 0;//绠辩爜鐗╁搧鏁伴噺 
-                if (pack.L5Num.HasValue)
+
+                //鍒ゆ柇鏄惁涓哄瘎瀛樼墿鏂�
+                if (isDeposit == 0 && isTextTable == 0)
                 {
-                    pNum = (int)pack.L5Num;
-                    bNum = (int)pack.L4Num;
-                }
-                else if (pack.L4Num.HasValue)
-                {
-                    pNum = (int)pack.L4Num;
-                    bNum = (int)pack.L3Num;
-                }
-                else if (pack.L3Num.HasValue)
-                {
-                    pNum = (int)pack.L3Num;
-                    bNum = (int)pack.L2Num;
-                }
-                else if (pack.L2Num.HasValue)
-                {
-                    pNum = (int)pack.L2Num;
-                    bNum = (int)pack.L1Num;
-                }
-                else if (pack.L1Num.HasValue)
-                {
-                    pNum = (int)pack.L1Num;
-                    bNum = (int)pack.L1Num;
-                }
-                if (pNum == 0 || bNum == 0)
-                {
-                    throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒");
+                    if (pack == null)
+                    {
+                        throw new Exception("-1:鑾峰彇鐗╂枡鍖呰澶辫触锛岃鏍稿疄!");
+                    }
+                    if (pack.L5Num.HasValue)
+                    {
+                        pNum = (int)pack.L5Num;
+                        bNum = (int)pack.L4Num;
+                    }
+                    else if (pack.L4Num.HasValue)
+                    {
+                        pNum = (int)pack.L4Num;
+                        bNum = (int)pack.L3Num;
+                    }
+                    else if (pack.L3Num.HasValue)
+                    {
+                        pNum = (int)pack.L3Num;
+                        bNum = (int)pack.L2Num;
+                    }
+                    else if (pack.L2Num.HasValue)
+                    {
+                        pNum = (int)pack.L2Num;
+                        bNum = (int)pack.L1Num;
+                    }
+                    else if (pack.L1Num.HasValue)
+                    {
+                        pNum = (int)pack.L1Num;
+                        bNum = (int)pack.L1Num;
+                    }
+                    if (pNum == 0 || bNum == 0)
+                    {
+                        throw new Exception($"缁戝畾澶辫触锛寋detail.SkuNo}鐗╁搧鍖呰鏈壘鍒帮紒");
+                    }
                 }
                 #endregion
 
@@ -1627,7 +2141,7 @@
                     }
                 }
                 #endregion
-                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
+                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo && m.Status != "2");
                 var bindId = 0;
                 if (bind == null)
                 {
@@ -1642,15 +2156,21 @@
                         FullQty = pNum,
                         Status = "0",
                         Type = "0",
-                        LotNo = detail.LotNo,
+                        LotNo = model.LotNo,
                         LotText = detail.LotText,
-                        SupplierLot = "",
+                        SupplierLot = detail.SupplierLot,
                         InspectMark = "0",
                         BitPalletMark = "1",
                         IsBale = "0",
                         IsBelt = "0",
-                        CreateUser = userId
+                        CreateUser = userId,
+                        Demo = model.Demo,
+
                     };
+                    //if (model.TableType == 0 && isDeposit == 0 && isTextTable == 0)   涓嶅お鐞嗚В杩欐浠g爜鐨勫惈涔�
+                    //{
+                    //    throw new Exception($"缁戝畾澶辫触锛寋model.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒");
+                    //}
                     // 鎻掑叆鎵樼洏缁戝畾琛�
                     bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                 }
@@ -1661,6 +2181,7 @@
                         throw new Exception("-1:褰撳墠鎵樼洏姝e湪鎵ц涓紝缁戝畾澶辫触锛岃鏍稿疄!");
                     }
                     bindId = bind.Id;
+                    bind.Qty += model.SkuQty;
                 }
 
                 #region 绠辩爜淇℃伅
@@ -1695,12 +2216,13 @@
 
                 // 鏇存敼绠辨敮鍏崇郴琛�
                 decimal factQty = 0.00m;//鎵樼洏鎬绘暟閲�
-                if (model.SkuQty == 0)
+                //鎴愬搧缁勬墭
+                if (isTextTable == 0)
                 {
                     var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
                     foreach (var g in boxGroup)
                     {
-                        var boxFullQty = 0;//绠卞唴鎬绘暟閲�
+                        decimal boxFullQty = 0;//绠卞唴鎬绘暟閲�
                         foreach (var box in g)
                         {
                             if (box.BindNo != null && box.BindNo != 0)
@@ -1708,7 +2230,7 @@
                                 continue;
                             }
                             //绠卞唴鐗╂枡鎵规涓庡崟鎹槑缁嗕笉绗﹀悎
-                            if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo)
+                            if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
                             {
                                 throw new Exception($"-1:{box.BoxNo}绠卞唴鐗╂枡鍙婃壒娆′笌鍗曟嵁涓嶄竴鑷达紝璇锋牳瀹�!");
                             }
@@ -1725,32 +2247,36 @@
                             factQty += box.Qty;
                             boxFullQty += box.Qty;
                         }
-                        if (boxFullQty > bNum)
-                        {
-                            throw new Exception($"缁戝畾澶辫触锛寋g.Key}绠辩爜缁戝畾鏁伴噺澶т簬璇ョ墿鍝佸寘瑁呮暟閲忥紒");
-                        }
+                        //if (boxFullQty > bNum)
+                        //{
+                        //    throw new Exception($"缁戝畾澶辫触锛寋g.Key}绠辩爜缁戝畾鏁伴噺澶т簬璇ョ墿鍝佸寘瑁呮暟閲忥紒");
+                        //}
                     }
                     Db.Updateable(boxInfoList).ExecuteCommand();
 
                     // 鏇存柊鎵樼洏缁戝畾琛�
                     bind.Qty += factQty;
                 }
-                if (bind.FullQty < bind.Qty)
-                {
-                    throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺");
-                }
+                //if (bind.FullQty < bind.Qty && isDeposit == 0 && isTextTable == 0)
+                //{
+                //    throw new Exception("鎵樼洏缁戝畾鏁伴噺宸茶秴鍑鸿鐗╂枡鍖呰鏁伴噺");
+                //}
 
-                if (bind.FullQty == bind.Qty)
+                if (bind.FullQty <= bind.Qty)
                 {
                     bind.BitPalletMark = "0";
                 }
+                //if (bind.Qty > pNum && isDeposit == 0 && isTextTable == 0)
+                //{
+                //    throw new Exception($"缁戝畾澶辫触锛寋bind.PalletNo}鎵樼洏缁戝畾鏁伴噺澶т簬璇ョ墿鍝佹墭鐩樺寘瑁呮暟閲忥紒");
+                //}
                 Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
 
                 // 鏇存敼鍏ュ簱鍗曟槑缁嗗凡缁勬暟閲�
                 var sqlString = string.Empty;
                 if (factQty == 0)
                 {
-                    sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{bind.Qty}' where id = '{model.AsnDetailId}';";
+                    sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{model.SkuQty}' where id = '{model.AsnDetailId}';";
                 }
                 else
                 {
@@ -1763,8 +2289,15 @@
                 if (detail.Status == "0")
                 {
                     var sqlString2 = string.Empty;
-                    sqlString2 += $"update BllArrivalNotice set Status = '1',CompleteTime= getDate() where ASNNo = '{model.AsnNo}' and Status ='0';";
-                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',CompleteTime= getDate() where id = '{model.AsnDetailId}' and Status ='0';";
+                    sqlString2 += $"update BllArrivalNotice set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='0';";
+                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='0';";
+                    Db.Ado.ExecuteCommand(sqlString2);
+                }
+                else if (detail.Status == "1")
+                {
+                    var sqlString2 = string.Empty;
+                    sqlString2 += $"update BllArrivalNotice set UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='1';";
+                    sqlString2 += $"update BllArrivalNoticeDetail set UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='1';";
                     Db.Ado.ExecuteCommand(sqlString2);
                 }
 
@@ -1773,12 +2306,448 @@
                 //娣诲姞鎵樼洏璁板綍琛ㄦ暟鎹�
                 sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','缁勭洏','0',getDate(),{userId},NULL,NULL);";
                 Db.Ado.ExecuteCommand(sqlStr);
-                new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "浜у搧缁勬墭", model.AsnNo, "娣诲姞", $"娣诲姞浜嗘墭鐩樼爜涓猴細{model.PalletNo}銆亄msgStr}鐨勭粍鐩樹俊鎭�", userId);
+                new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "鎵樼洏缁戝畾", model.AsnNo, "娣诲姞", $"娣诲姞浜嗘墭鐩樼爜涓猴細{model.PalletNo}銆亄msgStr}鐨勭粍鐩樹俊鎭�", userId);
 
                 Db.CommitTran();
             }
             catch (Exception ex)
             {
+                Db.RollbackTran();
+                throw ex;
+            }
+        }
+        #endregion
+
+        #region 骞冲簱鍏ュ簱
+        /// <summary>
+        /// 骞冲簱纭鍏ュ簱
+        /// </summary>
+        /// <param name="model"></param>
+        public void ConfirmInStock(PalletBindVm model)
+        {
+            try
+            {
+                #region 楠岃瘉淇℃伅
+                //if (string.IsNullOrEmpty(model.ASNNo))
+                //{
+                //    throw new Exception("鍏ュ簱鍗曚笉鑳戒负绌�!");
+                //}
+                if (string.IsNullOrEmpty(model.PalletNo))
+                {
+                    throw new Exception("鎵樼洏鏉$爜涓嶈兘涓虹┖!");
+                }
+                if (string.IsNullOrEmpty(model.LocatNo))
+                {
+                    throw new Exception("鍌ㄤ綅鍦板潃涓嶈兘涓虹┖!");
+                }
+                #endregion
+                //鑾峰彇褰撳墠鏃堕棿
+                DateTime serverTime = Db.Ado.GetDateTime("select GETDATE();");
+
+                #region 鏄惁鍥炴祦鍏ュ簱
+                int iscount = 0;
+                //搴撳瓨鏄庣粏淇℃伅
+                var stockDetail = Db.Queryable<DataStockDetail>().Where(a => a.IsDel == "0" && a.PalletNo == model.PalletNo).ToList();
+                //楠岃瘉搴撳瓨鏄惁鎷ユ湁璇ユ墭淇℃伅
+                if (stockDetail != null && stockDetail.Count > 0)
+                {
+                    foreach (var item in stockDetail)
+                    {
+                        if (!string.IsNullOrEmpty(item.WareHouseNo))
+                        {
+                            throw new Exception("璇ユ墭鐩樻湭鍦ㄥ簱澶栵紝璇锋牳鏌�!");
+                        }
+                    }
+                    iscount = 1; //鍥炴祦鍏ュ簱
+                }
+                #endregion
+
+                #region 鎵樼洏缁戝畾淇℃伅
+                var bindInfo = Db.Queryable<BllPalletBind>().First(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.PalletNo == model.PalletNo && w.Status != "2");
+                if (iscount == 0)
+                {
+                    if (bindInfo == null)
+                    {
+                        throw new Exception("鎵樼洏缁戝畾淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                    }
+                    if (!string.IsNullOrEmpty(bindInfo.WareHouseNo))
+                    {
+                        throw new Exception("璇ユ墭鐩樻湭鍦ㄥ簱澶栵紝璇锋牳鏌�!");
+                    }
+                }
+
+                #endregion
+
+                #region 鍦扮爜淇℃伅(鍌ㄤ綅淇℃伅)
+                var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0" && w.WareHouseNo == "W02");
+                if (storageLocat == null)
+                {
+                    throw new Exception("鍌ㄤ綅淇℃伅涓嶅瓨鍦ㄦ垨闈炵┖闂茬姸鎬侊紝璇锋牳鏌�!");
+                }
+                #endregion
+
+                Db.BeginTran();//寮�鍚簨鍔�
+                if (iscount == 0)//姝e父鍏ュ簱
+                {
+                    #region 鍏ュ簱鎬诲崟淇℃伅
+                    var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.Status != "3" && a.ASNNo == model.ASNNo);
+                    //楠岃瘉鍏ュ簱鍗曟�诲崟鏄惁鍏抽棴
+                    if (notice == null)
+                    {
+                        throw new Exception("鍏ュ簱鍗曟�诲崟淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                    }
+                    //鍒ゆ柇鍏ュ簱鍗曟�诲崟鏄惁涓哄凡鍏抽棴
+                    if (notice.Status == "3")
+                    {
+                        throw new Exception("鍏ュ簱鍗曟�诲崟宸插叧闂紝璇锋牳鏌�!");
+                    }
+                    #endregion
+
+                    #region 绠辩爜淇℃伅
+                    var boxInfoList = Db.Queryable<BllBoxInfo>().Where(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.PalletNo == model.PalletNo).ToList();
+                    // type 0:鎴愬搧鍏ュ簱 1:閲囪喘鍏ュ簱 2:涓棿鍝佸叆搴� 3:閫�璐у叆搴� 4:杞﹂棿浣欐枡閫�鍥炲叆搴� 5:鍏跺畠鍏ュ簱 6:浠e偍鍏ュ簱 7:瀵勫瓨鍏ュ簱
+                    if (notice.Type == "2" || notice.Type == "6" || notice.Type == "7")
+                    {
+                        // 涓嶈创鐮佺墿鏂� 鏃犻渶楠岃瘉绠辩爜淇℃伅
+                    }
+                    else
+                    {
+                        //楠岃瘉绠辩爜淇℃伅鏄惁瀛樺湪
+                        if (boxInfoList.Count <= 0)
+                        {
+                            throw new Exception("绠辩爜淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                        }
+                        foreach (var item in boxInfoList)
+                        {
+                            item.Status = "2"; // 鏀瑰彉绠辨敮鍏崇郴琛ㄧ姸鎬侊細宸插叆搴�
+                            item.UpdateTime = serverTime;
+                            item.UpdateUser = model.CreateUser;
+                        }
+                        Db.Updateable(boxInfoList).ExecuteCommand();
+                    }
+                    #endregion
+
+                    bool isFinsh = true;//鏄惁鍏ㄩ儴鍏ュ簱瀹屾垚
+                    #region 鍏ュ簱鍗曟槑缁�
+                    var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.IsDel == "0" && w.ASNNo == model.ASNNo && w.Id == bindInfo.ASNDetailNo);
+                    if (noticeDetail == null)
+                    {
+                        throw new Exception("鍏ュ簱鍗曟槑缁嗕俊鎭笉瀛樺湪锛岃鏍告煡!");
+                    }
+                    noticeDetail.CompleteQty += bindInfo.Qty;//澧炲姞鍏ュ簱鏁伴噺
+                    //鍒ゆ柇鍏ュ簱鏁伴噺澧炲姞鍚庢槸鍚﹀ぇ浜庣瓑浜庡崟鎹暟閲�
+                    if (noticeDetail.CompleteQty >= noticeDetail.Qty)
+                    {
+                        noticeDetail.Status = "2";//鎵ц瀹屾垚
+                        noticeDetail.CompleteTime = serverTime;
+                    }
+                    else
+                    {
+                        noticeDetail.Status = "1";//姝e湪鎵ц
+
+                        isFinsh = false;
+                    }
+                    noticeDetail.UpdateUser = model.CreateUser;
+                    noticeDetail.UpdateTime = serverTime;
+                    Db.Updateable(noticeDetail).ExecuteCommand();
+                    #endregion
+
+                    #region 鐗╂枡淇℃伅
+                    var sku = Db.Queryable<SysMaterials>().First(s => s.SkuNo == noticeDetail.SkuNo && s.IsDel == "0" && s.SkuName == noticeDetail.SkuName);
+                    //鍒ゆ柇鐗╂枡淇℃伅鏄惁涓虹┖
+                    if (sku == null)
+                    {
+                        throw new Exception("鐗╂枡淇℃伅涓嶅瓨鍦紝璇锋牳鏌�!");
+                    }
+                    #endregion
+
+                    #region 搴撳瓨鎬昏〃
+                    // 鍒ゆ柇褰撳墠鐗╂枡搴撳瓨琛ㄦ槸鍚﹀凡瀛樺湪
+                    var stockModel = Db.Queryable<DataStock>().First(w => w.IsDel == "0" && w.SkuNo == noticeDetail.SkuNo && w.LotNo == bindInfo.LotNo && w.Standard == noticeDetail.Standard);
+                    if (stockModel == null || stockModel.Id == 0)
+                    {
+                        stockModel = new DataStock
+                        {
+                            LotNo = bindInfo.LotNo,
+                            LotText = bindInfo.LotText,
+                            SupplierLot = bindInfo.SupplierLot,
+                            SkuNo = noticeDetail.SkuNo,
+                            SkuName = noticeDetail.SkuName,
+                            Qty = bindInfo.Qty,
+                            Standard = noticeDetail.Standard,
+                            CreateUser = (int)model.CreateUser,
+                            CreateTime = serverTime
+                        };
+                        //缁存姢搴撳瓨璐т富淇℃伅
+                        if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱
+                        {
+                            stockModel.OwnerNo = notice.CustomerNo;//璐т富缂栫爜
+                            stockModel.OwnerName = notice.CustomerName;//璐т富鍚嶇О
+                        }
+                        //鏂板搴撳瓨鎬讳俊鎭�
+                        Db.Insertable<DataStock>(stockModel).ExecuteCommand();
+                    }
+                    else
+                    {
+                        stockModel.Qty += bindInfo.Qty;
+                        stockModel.UpdateUser = (int)model.CreateUser;
+                        stockModel.UpdateTime = serverTime;
+                        //淇敼搴撳瓨鎬讳俊鎭�
+                        Db.Updateable(stockModel).ExecuteCommand();
+                    }
+                    #endregion
+
+                    #region 搴撳瓨鏄庣粏琛�
+                    // 鍒ゆ柇褰撳墠鎵樼洏鏄惁宸插瓨鍦紙鎷h揣鍥炲簱鎵樼洏锛�
+                    var detailModel = Db.Queryable<DataStockDetail>().First(it => it.PalletNo == bindInfo.PalletNo && it.LotNo == bindInfo.LotNo && it.SkuNo == noticeDetail.SkuNo
+                        && it.Standard == noticeDetail.Standard && it.IsDel == "0");
+                    var stId = 0;
+                    if (detailModel == null || detailModel.Id == 0)
+                    {
+                        // 娣诲姞搴撳瓨鏄庣粏琛�
+                        detailModel = new DataStockDetail()
+                        {
+                            LotNo = bindInfo.LotNo,
+                            LotText = bindInfo.LotText,
+                            SupplierLot = noticeDetail.SupplierLot,
+                            SkuNo = noticeDetail.SkuNo,
+                            SkuName = noticeDetail.SkuName,
+                            Standard = noticeDetail.Standard,
+                            Qty = bindInfo.Qty,
+                            LockQty = 0,
+                            FrozenQty = 0,
+                            InspectQty = bindInfo.Qty,
+                            ASNNo = noticeDetail.ASNNo,
+                            ASNDetailNo = (int)bindInfo.ASNDetailNo,
+                            WareHouseNo = "W02",
+                            RoadwayNo = "",
+                            AreaNo = storageLocat.AreaNo,
+                            LocatNo = model.LocatNo,
+                            PalletNo = model.PalletNo,
+                            PalletNo2 = bindInfo.PalletNo2,
+                            PalletNo3 = bindInfo.PalletNo3,
+                            CompleteTime = serverTime,
+                            ProductionTime = bindInfo.ProductionTime,
+                            ExpirationTime = bindInfo.ExpirationTime,
+                            Status = "0",
+                            InspectMark = bindInfo.InspectMark,
+                            BitPalletMark = bindInfo.BitPalletMark,
+                            InspectStatus = sku.IsInspect,// 缁勭洏鐨勬椂鍊欏氨瑕侀粯璁よ瀹氬ソ鏄惁鍚堟牸
+                            PackagNo = sku.PackagNo,
+                            IsBale = bindInfo.IsBale,
+                            IsBelt = bindInfo.IsBelt,
+                            Demo = bindInfo.Demo,
+                            CreateUser = (int)model.CreateUser,
+                            CreateTime = serverTime
+                        };
+                        //缁存姢搴撳瓨鏄庣粏璐т富/渚涘簲鍟嗕俊鎭�
+                        if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:鎴愬搧鍏ュ簱锛�2:涓棿鍝佸叆搴�,4:杞﹂棿浣欐枡鍏ュ簱,6:浠e偍鍏ュ簱,7:瀵勫瓨鍏ュ簱
+                        {
+                            detailModel.OwnerNo = notice.CustomerNo;//璐т富缂栫爜
+                            detailModel.OwnerName = notice.CustomerName;//璐т富鍚嶇О
+                        }
+                        else if (notice.Type == "1" || notice.Type == "5")//1:閲囪喘鍏ュ簱,2:鍏跺畠鍏ュ簱
+                        {
+                            detailModel.SupplierNo = notice.CustomerNo;//渚涘簲鍟嗙紪鐮�
+                            detailModel.SupplierName = notice.CustomerName;//渚涘簲鍟嗗悕绉�
+                        }
+                        #region  缁存姢璐ㄦ缁撴灉
+                        //鑾峰彇璇ユ壒娆℃渶缁堣川妫�缁撴灉
+                        var quality = Db.Queryable<BllQualityInspect>().Where(a => a.LotNo == noticeDetail.LotNo && a.IsDel == "0").OrderByDescending(a => a.CreateTime).First();
+                        if (quality != null)
+                        {
+                            //淇敼鍚堟牸涓嶅悎鏍兼暟閲�
+                            if (quality.IsQualified == "1") //鍚堟牸
+                            {
+                                //澧炲姞鍚堟牸鏁伴噺
+                                quality.PassQty += detailModel.Qty;
+                                detailModel.InspectStatus = "1";
+                            }
+                            else if (quality.IsQualified == "0") //涓嶅悎鏍�
+                            {
+                                //澧炲姞涓嶅悎鏍兼暟閲�
+                                quality.FailQty += detailModel.Qty;
+                                detailModel.InspectStatus = "2";
+                            }
+                            Db.Updateable(quality).ExecuteCommand(); //淇敼璐ㄦ淇℃伅
+                        }
+                        #endregion
+                        stId = Db.Insertable<DataStockDetail>(detailModel).ExecuteReturnIdentity();
+                    }
+                    else
+                    {
+                        stId = detailModel.Id;
+                        detailModel.LocatNo = model.LocatNo;
+                        detailModel.AreaNo = storageLocat.AreaNo;
+                        detailModel.UpdateTime = serverTime;
+                        detailModel.UpdateUser = (int)model.CreateUser;
+                        // 鍙樻洿鍌ㄤ綅鍦板潃
+                        Db.Updateable<DataStockDetail>(detailModel).UpdateColumns(it => new { it.LocatNo, it.UpdateTime, it.UpdateUser }).ExecuteCommand();
+                    }
+                    #endregion
+
+                    #region 浠诲姟鍙婄粍鎵樹俊鎭�
+                    //鍒涘缓浠诲姟淇℃伅
+                    var taskNo = new Common().GetMaxNo("TK");
+                    var exTask = new LogTask    //鍏ュ簱浠诲姟
+                    {
+                        TaskNo = taskNo,
+                        Sender = "WMS",
+                        Receiver = "PDA",
+                        IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                        SendDate = serverTime,  //鍙戦�佹椂闂�
+                        BackDate = serverTime,  //杩斿洖鏃堕棿
+                        StartLocat = "",//璧峰浣嶇疆
+                        EndLocat = model.LocatNo,//鐩爣浣嶇疆
+                        PalletNo = bindInfo.PalletNo,//鎵樼洏鐮�
+                        IsSend = 0,//鏄惁鍙啀娆′笅鍙�
+                        IsCancel = 0,//鏄惁鍙彇娑�
+                        IsFinish = 0,//鏄惁鍙畬鎴�
+                        Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
+                        Status = "2",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+                        OrderType = "0",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
+                        Msg = "鍔涜骞冲簱鐨勫叆搴撲换鍔�",
+                    };
+                    Db.Insertable(exTask).ExecuteCommand();
+
+                    //淇敼缁勬墭鐘舵��
+                    bindInfo.Status = "2"; //2 鍏ュ簱瀹屾垚
+                    bindInfo.WareHouseNo = "W02";//鎵�灞炰粨搴�
+                    bindInfo.LocatNo = model.LocatNo;//鍌ㄤ綅鍦板潃
+                    bindInfo.UpdateTime = serverTime;
+                    bindInfo.UpdateUser = model.CreateUser;
+                    bindInfo.CompleteTime = serverTime; //瀹屾垚鏃堕棿
+                    bindInfo.TaskNo = taskNo; //浠诲姟鍙�
+                    Db.Updateable(bindInfo).ExecuteCommand();
+                    #endregion
+
+                    #region 搴撳瓨绠辨敮鏄庣粏琛�
+                    // 鎻掑叆鏂扮粍鐨勭鏀俊鎭�
+                    var comTime = DateTime.Now;
+                    foreach (var item in boxInfoList)
+                    {
+                        var info = new DataBoxInfo()
+                        {
+                            StockDetailId = stId,
+                            BindNo = bindInfo.Id,
+                            BoxNo = item.BoxNo,
+                            BoxNo2 = item.BoxNo2,
+                            BoxNo3 = item.BoxNo3,
+                            PalletNo = item.PalletNo,
+                            PalletNo2 = item.PalletNo2,
+                            PalletNo3 = item.PalletNo3,
+                            Qty = item.Qty,
+                            FullQty = item.FullQty,
+                            Status = "2",
+                            LotNo = item.LotNo,
+                            LotText = item.LotText,
+                            SkuNo = item.SkuNo,
+                            SkuName = item.SkuName,
+                            Standard = sku.Standard,
+                            ProductionTime = item.ProductionTime,
+                            SupplierLot = item.SupplierLot,
+                            InspectMark = item.InspectMark,
+                            BitBoxMark = item.BitBoxMark,
+                            InspectStatus = item.InspectStatus,
+                            //InspectTime = item.,
+
+                            IsDel = "0",
+                            CreateUser = 0,
+                            CreateTime = comTime
+                        };
+                        Db.Insertable(info).ExecuteCommand();
+                    }
+                    #endregion
+
+                    var entryList = Db.Queryable<BllArrivalNoticeDetail>().Where(w => w.IsDel == "0" && w.ASNNo == notice.ASNNo && w.Id != noticeDetail.Id && w.Status != "2").ToList();
+                    if (isFinsh && entryList.Count <= 0)//鍏ュ簱鍗曟槑缁嗗叏閮ㄥ畬鎴�
+                    {
+                        //淇敼鍏ュ簱鍗曟�诲崟淇℃伅
+                        notice.Status = "2";
+                        notice.UpdateUser = model.CreateUser;
+                        notice.UpdateTime = serverTime;
+                        Db.Updateable(notice).ExecuteCommand();
+                    }
+                    else
+                    {
+                        //鍒ゆ柇鎬诲崟鐘舵�佹槸鍚︿负姝e湪鎵ц
+                        if (notice.Status == "0")
+                        {
+                            //淇敼鍏ュ簱鍗曟�诲崟淇℃伅
+                            notice.Status = "1";
+                            notice.UpdateUser = model.CreateUser;
+                            notice.UpdateTime = serverTime;
+                            Db.Updateable(notice).ExecuteCommand();
+                        }
+                    }
+                }
+                else
+                {
+                    //淇敼搴撳瓨鏄庣粏淇℃伅
+                    foreach (var item in stockDetail)
+                    {
+                        item.Status = "0"; //鐘舵�佹洿鏀逛负寰呭垎閰�
+                        item.WareHouseNo = "W02"; //鎵�灞炰粨搴�
+                        item.LocatNo = model.LocatNo;//鍌ㄤ綅鍦板潃
+                        item.UpdateTime = serverTime; //淇敼鏃堕棿
+                        item.UpdateUser = model.CreateUser; //淇敼浜�
+                        //淇敼搴撳瓨鏄庣粏淇℃伅                                           
+                        Db.Updateable(item).ExecuteCommand();
+                    }
+                    //鑾峰彇鎷h揣淇℃伅
+                    var alotr = Db.Queryable<BllExportAllot>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo && a.Status == "4");
+                    if (alotr != null)
+                    {
+                        alotr.Status = "5"; //5 宸插畬鎴�
+                        alotr.UpdateUser = model.CreateUser; //淇敼浜�
+                        alotr.UpdateTime = serverTime; //淇敼鏃堕棿
+                        //淇敼鎷h揣淇℃伅
+                        Db.Updateable(alotr).ExecuteCommand();
+                    }
+                    #region 浠诲姟鍙婄粍鎵樹俊鎭�
+                    //鍒涘缓浠诲姟淇℃伅
+                    var taskNo = new Common().GetMaxNo("TK");
+                    var exTask = new LogTask    //鍏ュ簱浠诲姟
+                    {
+                        TaskNo = taskNo,
+                        Sender = "WMS",
+                        Receiver = "PDA",
+                        IsSuccess = 1, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                        SendDate = DateTime.Now,  //鍙戦�佹椂闂�
+                        BackDate = DateTime.Now,  //杩斿洖鏃堕棿
+                        StartLocat = "",//璧峰浣嶇疆
+                        EndLocat = model.LocatNo,//鐩爣浣嶇疆
+                        PalletNo = model.PalletNo,//鎵樼洏鐮�
+                        IsSend = 0,//鏄惁鍙啀娆′笅鍙�
+                        IsCancel = 0,//鏄惁鍙彇娑�
+                        IsFinish = 0,//鏄惁鍙畬鎴�
+                        Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
+                        Status = "2",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+                        OrderType = "3",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
+                        Msg = "鍔涜骞冲簱鐨勫洖搴撲换鍔�",
+                    };
+                    Db.Insertable(exTask).ExecuteCommand();
+                    #endregion
+                }
+                storageLocat.Status = "1";//鐘舵�佸凡浣跨敤
+                storageLocat.UpdateTime = serverTime; //淇敼鏃堕棿
+                storageLocat.UpdateUser = model.CreateUser; //淇敼浜�
+                //淇敼鍌ㄤ綅淇℃伅                                        
+                Db.Updateable(storageLocat).ExecuteCommand();
+
+                if (iscount == 1)
+                {
+                    new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "骞冲簱鍏ュ簱", model.PalletNo, "瀹屾垚", $"鍦≒DA涓婂畬鎴愭墭鐩樼爜涓猴細{model.PalletNo}鐨勫钩搴撳洖娴佸叆搴撴搷浣�", (int)model.CreateUser);
+                }
+                else
+                {
+                    new OperationASNServer().AddLogOperationAsn("PDA妯″潡", "骞冲簱鍏ュ簱", model.PalletNo, "瀹屾垚", $"鍦≒DA涓婂畬鎴愬崟鎹彿涓猴細{model.ASNNo}鐨勬墭鐩樼爜涓猴細{model.PalletNo}鐨勫钩搴撳叆搴撴搷浣�", (int)model.CreateUser);
+                }
+                Db.CommitTran();
+            }
+            catch (Exception ex)
+            {
+                Db.RollbackTran();
                 throw ex;
             }
         }

--
Gitblit v1.8.0