From ba30538b12f66d8483b925e44f38b9ec486b4999 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 09 十二月 2025 10:46:13 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs |  310 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 288 insertions(+), 22 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
index 4b4b52b..ccbb4de 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
@@ -1,5 +1,7 @@
 锘縰sing AutoMapper;
 using SqlSugar;
+using System.Dynamic;
+using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.OrderEnum;
@@ -19,6 +21,7 @@
 using WIDESEA_IRecordService;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
 
 namespace WIDESEA_InboundService
 {
@@ -35,9 +38,12 @@
         private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository;
         private readonly IRepository<Dt_StockInfoDetail> _stockDetailRepository;
         private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
+        private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
+        private readonly IRepository<Dt_LocationType> _locationTypeRepository;
+        private readonly IRepository<Dt_StockInfo> _stockRepository;
         public IRepository<Dt_InboundOrder> Repository => BaseDal;
 
-        public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService,IRepository<Dt_StockInfoDetail> stockDetailRepository,IRepository<Dt_InboundOrder> inboundOrderRepository) : base(BaseDal)
+        public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_StockInfo> stockRepository, IRepository<Dt_LocationType> locationTypeRepository) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -48,6 +54,9 @@
             _materialUnitService = materialUnitService;
             _stockDetailRepository = stockDetailRepository;
             _inboundOrderRepository = inboundOrderRepository;
+            _warehouseAreaRepository = warehouseAreaRepository;
+            _stockRepository = stockRepository;
+            _locationTypeRepository = locationTypeRepository;
         }
 
         public async Task<WebResponseContent> ReceiveInboundOrder(List<Dt_InboundOrder> models, int operateType)
@@ -56,7 +65,7 @@
             {
                 return operateType switch
                 {
-                    1 =>await AddInboundOrder(models),
+                    1 => await AddInboundOrder(models),
                     2 => await UpdateInboundOrder(models),
                     3 => DeleteInboundOrder(models),
 
@@ -86,11 +95,14 @@
                     foreach (var item in model.Details)
                     {
                         var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
-                        item.Unit= purchaseToStockResult.Unit;  
-                        item.OrderQuantity=purchaseToStockResult.Quantity;  
+                        item.Unit = purchaseToStockResult.Unit;
+                        item.OrderQuantity = purchaseToStockResult.Quantity;
+                    }
+                    if (model.OrderType != InOrderTypeEnum.AllocatInbound.ObjToInt())
+                    {
+                        model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
                     }
 
-                    model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
                     Db.InsertNav(model).Include(x => x.Details).ExecuteCommand();
                 }
                 return WebResponseContent.Instance.OK();
@@ -114,6 +126,10 @@
                     if (inboundOrder.Details == null || inboundOrder.Details.Count == 0)
                     {
                         return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
+                    }
+                    if (inboundOrder.OrderStatus != InOrderStatusEnum.鏈紑濮�.ObjToInt())
+                    {
+                        return WebResponseContent.Instance.Error($"璇ヨ鍗曠姸鎬佷笉鍏佽淇敼");
                     }
                     List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
                     List<Dt_InboundOrderDetail> updateInboundOrderDetails = new List<Dt_InboundOrderDetail>();
@@ -163,7 +179,9 @@
                                 inboundOrderDetail.BarcodeUnit = item.BarcodeUnit;
                                 inboundOrderDetail.BarcodeQty = item.BarcodeQty;
                                 inboundOrderDetail.OrderQuantity = item.OrderQuantity;
-
+                                var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
+                                inboundOrderDetail.Unit = purchaseToStockResult.Unit;
+                                inboundOrderDetail.OrderQuantity = purchaseToStockResult.Quantity;
 
                                 updateInboundOrderDetails.Add(inboundOrderDetail);
                                 detailIds.Add(inboundOrderDetail.Id);
@@ -181,7 +199,8 @@
                     _unitOfWorkManage.BeginTran();
                     foreach (var item in deletePurchaseOrderDetails)
                     {
-                        _inboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎);
+                        _inboundOrderDetailRepository.DeleteData(item);
+                        //_inboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎);
                     }
 
                     _inboundOrderDetailRepository.UpdateData(updateInboundOrderDetails);
@@ -216,13 +235,19 @@
                     {
                         return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟鏄庣粏淇℃伅");
                     }
+                    if (inboundOrder.OrderStatus != InOrderStatusEnum.鏈紑濮�.ObjToInt())
+                    {
+                        return WebResponseContent.Instance.Error($"璇ヨ鍗曠姸鎬佷笉鍏佽鍒犻櫎");
+                    }
                     //Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand();
                     _unitOfWorkManage.BeginTran();
-                    BaseDal.DeleteAndMoveIntoHty(inboundOrder, OperateTypeEnum.鑷姩鍒犻櫎);
+                    //BaseDal.DeleteAndMoveIntoHty(inboundOrder, OperateTypeEnum.鑷姩鍒犻櫎);
                     foreach (var item in inboundOrder.Details)
                     {
-                        _inboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎);
+                        _inboundOrderDetailRepository.DeleteData(item);
+                        //_inboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.鑷姩鍒犻櫎);
                     }
+                    BaseDal.DeleteData(inboundOrder);
                     _unitOfWorkManage.CommitTran();
                 }
                 return WebResponseContent.Instance.OK();
@@ -317,6 +342,14 @@
                 (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
                 if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
 
+                //  materielGroupDTO.WarehouseCode
+                var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x => x.Code).First();
+                if (string.IsNullOrEmpty(code))
+                {
+                    return content = WebResponseContent.Instance.Error($"浠撳簱涓病鏈夎{materielGroupDTO.WarehouseType}缂栧彿銆�");
+                }
+
+
                 Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
 
                 var dbinboundOrderDetails = _inboundOrderDetailService.GetByBarcode(materielGroupDTO.Barcodes);
@@ -337,10 +370,9 @@
 
                 if (stockInfo == null)
                 {
-                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None };
+                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = materielGroupDTO.locationType.ObjToInt() };
                     stockInfo.Details = new List<Dt_StockInfoDetail>();
                 }
-
 
                 foreach (var item in dbinboundOrderDetails)
                 {
@@ -353,16 +385,20 @@
                         Unit = item.Unit,
                         InboundOrderRowNo = item.lineNo,
                         SupplyCode = item.SupplyCode,
-                        WarehouseCode = item.WarehouseCode,
+                        WarehouseCode = materielGroupDTO.WarehouseType,
                         StockQuantity = item.OrderQuantity,
+                        BarcodeQty = item.BarcodeQty,
+                        BarcodeUnit = item.BarcodeUnit,
+                        FactoryArea = inboundOrder.FactoryArea,
                         Status = 0,
                         OrderNo = inboundOrder.InboundOrderNo,
                         BusinessType = inboundOrder.BusinessType,
-                        ProductionDate=DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss")
+
                     });
 
                     item.ReceiptQuantity = item.BarcodeQty;
                     item.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                    item.WarehouseCode = materielGroupDTO.WarehouseType;
                 }
 
                 if (stockInfo.Id == 0)
@@ -410,6 +446,16 @@
                 (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
                 if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
 
+                bool code = _locationTypeRepository.Db.Queryable<Dt_LocationType>().Where(x => x.LocationType == materielGroupDTO.WarehouseCode).Any();
+                if (!code)
+                {
+                    return content = WebResponseContent.Instance.Error($"鍖哄煙涓病鏈夎{materielGroupDTO.WarehouseCode}缂栧彿銆�");
+                }
+
+                if (_stockRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
+                {
+                    return WebResponseContent.Instance.Error("璇ユ墭鐩樺凡缁忕粍杩囩洏");
+                }
 
                 Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
                 if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
@@ -426,13 +472,14 @@
                 {
                     if (stockInfo == null)
                     {
-                        stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(), PalletCode = materielGroupDTO.PalletCode };
+                        stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(), PalletCode = materielGroupDTO.PalletCode, LocationType = materielGroupDTO.WarehouseCode.ObjToInt() };
                         stockInfo.Details = new List<Dt_StockInfoDetail>();
                     }
                     else
                     {
                         stockInfo.PalletType = PalletTypeEnum.Empty.ObjToInt();
                         stockInfo.StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt();
+                        stockInfo.LocationType = materielGroupDTO.WarehouseCode.ObjToInt();
                     }
 
                     _unitOfWorkManage.BeginTran();
@@ -560,21 +607,21 @@
             {
                 StockSumQuantity = 0,
                 StockCount = 0,
-                UniqueUnit=""
+                UniqueUnit = ""
             };
             WebResponseContent content = new WebResponseContent();
             try
             {
                 if (string.IsNullOrWhiteSpace(orderNo))
                 {
-                  return content.Error("浼犲叆鐨勮鍗曞彿orderNo涓虹┖鎴栫┖鐧�");
+                    return content.Error("浼犲叆鐨勮鍗曞彿orderNo涓虹┖鎴栫┖鐧�");
                 }
                 var orderDetail = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details).Where(s => s.InboundOrderNo == orderNo).First();
                 if (orderDetail == null)
                 {
-                   return content.Error("鏈壘鍒板崟鎹�");
+                    return content.Error("鏈壘鍒板崟鎹�");
                 }
-               var unitGroups = orderDetail.Details.GroupBy(d => d.Unit).ToList();
+                var unitGroups = orderDetail.Details.GroupBy(d => d.Unit).ToList();
                 if (unitGroups.Count == 1)
                 {
                     resultDTO.UniqueUnit = unitGroups.First().Key;
@@ -586,19 +633,238 @@
                 var validDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
                 resultDTO.StockSumQuantity = orderDetail.Details.Sum(d => d.OrderQuantity);
                 resultDTO.StockCount = orderDetail.Details.Count;
-                if(validDetails.Any())
+                if (validDetails.Any())
                 {
-                     resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
+                    resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
                     // 鏄庣粏璁板綍鏁帮細绗﹀悎鏉′欢鐨勬湁鏁堣褰曟潯鏁�
                     resultDTO.StockCount -= validDetails.Count;
                 }
-                return content.OK("",resultDTO);
+                return content.OK("", resultDTO);
             }
             catch (Exception ex)
             {
-              return content.Error("SumQuantity 缁熻搴撳瓨鏁伴噺澶辫触锛岃鍗曞彿锛歿OrderNo}");
+                return content.Error("SumQuantity 缁熻搴撳瓨鏁伴噺澶辫触锛岃鍗曞彿锛歿OrderNo}");
             }
         }
 
+        public WebResponseContent UndoPalletGroup(string palletCode, string barcode = "")
+        {
+            
+            if (string.IsNullOrWhiteSpace(palletCode))
+            {
+                return WebResponseContent.Instance.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+            }
+
+            
+            try
+            {
+                _unitOfWorkManage.BeginTran(); 
+
+                // 2. 鏌ヨ鎵樼洏搴撳瓨涓昏褰曪紙閬垮厤鏃犳暟鎹姏寮傚父锛�
+                var stock = _stockRepository.Db.Queryable<Dt_StockInfo>()
+                    .Includes(o => o.Details)
+                    .First(x => x.PalletCode == palletCode
+                                         && (x.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨
+                                             || x.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()));
+
+                if (stock == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒版墭鐩樺彿{palletCode}瀵瑰簲鐨勫簱瀛樿褰�");
+                }
+
+                // 3. 鍦烘櫙1锛氬垹闄ゆ寚瀹氭潯鐮�
+                if (!string.IsNullOrWhiteSpace(barcode))
+                {
+                    var targetDetail = stock.Details?.FirstOrDefault(x => x.Barcode == barcode);
+                    if (targetDetail == null)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        return WebResponseContent.Instance.Error($"鎵樼洏{palletCode}涓嬫湭鎵惧埌鏉$爜{barcode}鐨勬槑缁嗚褰�");
+                    }
+
+                    ResetInboundOrderStatus(new List<string> { targetDetail.OrderNo},new List<string> { targetDetail.Barcode});
+                    // 鍒犻櫎鎸囧畾鏄庣粏
+                    _stockDetailRepository.DeleteData(targetDetail);
+
+
+                    // 閲嶆柊鏌ヨ鍓╀綑鏄庣粏锛堜繚璇佹暟鎹噯纭�э級
+                    var remainingDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>()
+                        .Where(x => x.StockId == stock.Id)
+                        .ToList();
+
+                    // 鍓╀綑鏄庣粏涓虹┖ 鈫� 鍒犻櫎涓昏〃 + 閲嶇疆鍏ュ簱鍗曞強鏄庣粏鐘舵��
+                    if (!remainingDetails.Any())
+                    {
+                        // 閲嶇疆鍏ュ簱鍗曞強鏄庣粏鐘舵��
+                        ResetInboundOrderStatus(stock.Details.Select(d => d.OrderNo).Distinct().ToList());
+
+                        _stockRepository.DeleteData(stock);
+                        _unitOfWorkManage.CommitTran();
+                        return WebResponseContent.Instance.OK($"鏉$爜{barcode}鎾ら攢鎴愬姛锛屾墭鐩樻棤鍓╀綑鏄庣粏锛屽凡鍒犻櫎鎵樼洏骞堕噸缃叧鑱斿叆搴撳崟鐘舵��");
+                    }
+
+                    _unitOfWorkManage.CommitTran();
+                    return WebResponseContent.Instance.OK($"鏉$爜{barcode}鎾ら攢鎴愬姛锛屾墭鐩樹粛鏈夊墿浣欐槑缁�");
+                }
+
+                // 鍒犻櫎鏁存墭鐩橈紙鏃犳潯鐮佷紶鍏ワ級
+                if (stock.Details == null || !stock.Details.Any())
+                {
+                    _stockRepository.DeleteData(stock);
+                    _unitOfWorkManage.CommitTran();
+                    return WebResponseContent.Instance.OK("鎵樼洏鏃犳槑缁嗚褰曪紝宸茬洿鎺ュ垹闄ゆ墭鐩樹富鏁版嵁");
+                }
+
+                // 鏈夋槑缁� 鈫� 閲嶇疆鍏ュ簱鍗曞強鏄庣粏鐘舵�� + 鍒犻櫎搴撳瓨
+                var relatedOrderNos = stock.Details.Select(d => d.OrderNo).Distinct().ToList();
+                if (!relatedOrderNos.Any())
+                {
+                    _unitOfWorkManage.RollbackTran();
+                    return WebResponseContent.Instance.Error("搴撳瓨鏄庣粏鏈叧鑱斾换浣曞叆搴撳崟鍙凤紝鏃犳硶瀹屾垚鎾ら攢");
+                }
+
+                // 閲嶇疆鍏ュ簱鍗曚富鐘舵�� + 鏄庣粏鐘舵��
+                ResetInboundOrderStatus(relatedOrderNos, stock.Details.Select(d => d.Barcode).ToList());
+
+                // 4.3 鍒犻櫎搴撳瓨鏄庣粏鍜屼富琛�
+                _stockDetailRepository.DeleteData(stock.Details);
+                _stockRepository.DeleteData(stock);
+
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK("鎵樼洏鎾ら攢鎴愬姛锛屽凡閲嶇疆鍏宠仈鍏ュ簱鍗曞強鏄庣粏鐘舵��");
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran(); 
+                return WebResponseContent.Instance.Error($"鎵樼洏鎾ら攢澶辫触锛歿ex.Message}");
+            }
+        }
+
+
+        private void ResetInboundOrderStatus(List<string> orderNos, List<string> barcodes = null)
+        {
+            foreach (var orderNo in orderNos)
+            {
+                var inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>()
+                    .Includes(x => x.Details)
+                    .First(x => x.InboundOrderNo == orderNo);
+
+                if (inboundOrder == null) continue;
+
+                bool isSingleBarcode = barcodes != null && barcodes.Count == 1;
+                if (!isSingleBarcode)
+                {
+                    // 闈炲崟涓潯鐮侊紙鏁村崟/澶氫釜鏉$爜锛夛細閲嶇疆涓昏〃鐘舵�佷负0
+                    inboundOrder.OrderStatus = 0;
+                    _inboundOrderRepository.UpdateData(inboundOrder);
+                }
+
+                // 閲嶇疆鍏ュ簱鍗曟槑缁嗙姸鎬�
+                if (inboundOrder.Details == null || !inboundOrder.Details.Any()) continue;
+
+                var targetDetails = barcodes == null
+                    ? inboundOrder.Details.ToList() // 涓嶄紶鏉$爜鍒欓噸缃暣鍗曟槑缁�
+                    : inboundOrder.Details.Where(d => barcodes.Contains(d.Barcode)).ToList();
+
+                foreach (var detail in targetDetails)
+                {
+                    detail.ReceiptQuantity = 0;
+                    detail.OrderDetailStatus = 0;
+                    _inboundOrderDetailRepository.UpdateData(detail);
+                }
+            }
+        }
+
+        public override PageGridData<Dt_InboundOrder> GetPageData(PageDataOptions options)
+        {
+            string wheres = ValidatePageOptions(options);
+
+            string pattern = @"inboundOrderNo like '[^']+'\s*and\s*";
+            wheres = Regex.Replace(wheres, pattern, "", RegexOptions.IgnoreCase);
+
+            //鑾峰彇鎺掑簭瀛楁
+            Dictionary<string, SqlSugar.OrderByType> orderbyDic = GetPageDataSort(options, TProperties);
+            List<OrderByModel> orderByModels = new List<OrderByModel>();
+            foreach (var item in orderbyDic)
+            {
+                OrderByModel orderByModel = new()
+                {
+                    FieldName = item.Key,
+                    OrderByType = item.Value
+                };
+                orderByModels.Add(orderByModel);
+            }
+            ISugarQueryable<Dt_InboundOrder> sugarQueryable1 = BaseDal.Db.Queryable<Dt_InboundOrder>();
+
+            int totalCount = 0;
+            List<SearchParameters> searchParametersList = new List<SearchParameters>();
+            if (!string.IsNullOrEmpty(options.Wheres))
+            {
+                try
+                {                  
+                    searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+                    if (searchParametersList.Count > 0)
+                    {
+
+                        SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.InboundOrderNo).FirstLetterToLower());
+                        if (searchParameters != null)
+                        {
+                            sugarQueryable1 = sugarQueryable1.Where(x => x.InboundOrderNo.Contains(searchParameters.Value.ToString())
+                            || x.UpperOrderNo.Contains(searchParameters.Value.ToString()) ||
+                            x.Details.Any(d => d.Barcode == searchParameters.Value.ToString()));
+                        }
+                        searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.OrderType).FirstLetterToLower());
+                        if (searchParameters != null)
+                        {
+                            sugarQueryable1 = sugarQueryable1.Where(x => x.OrderType.Equals(searchParameters.Value.ToString()));
+                        }
+                        //var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+                        //return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
+                    }
+                    options.Filter = searchParametersList;
+                }
+                catch { }
+            }
+            var data = sugarQueryable1
+                .WhereIF(!wheres.IsNullOrEmpty(), wheres)
+                .Where(x => x.OrderType == 0)
+                .OrderBy(orderByModels).Includes(x => x.Details)
+                .ToPageList(options.Page, options.Rows, ref totalCount);
+
+            return new PageGridData<Dt_InboundOrder>(totalCount, data);
+        }
+
+        //public override PageGridData<Dt_InboundOrder> GetPageData(PageDataOptions options)
+        //{
+        //    //var  pageGridData = base.GetPageData(options);
+
+        //    ISugarQueryable<Dt_InboundOrder> sugarQueryable1 = BaseDal.Db.Queryable<Dt_InboundOrder>();
+        //    if (!string.IsNullOrEmpty(options.Wheres))
+        //    {
+
+        //        List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+        //        int totalCount = 0;
+        //        if (searchParametersList.Count > 0)
+        //        {
+
+        //            SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.InboundOrderNo).FirstLetterToLower());
+        //            if (searchParameters != null)
+        //            {
+        //                sugarQueryable1 = sugarQueryable1.Where(x => x.InboundOrderNo.Contains(searchParameters.Value.ToString())
+        //                || x.UpperOrderNo.Contains(searchParameters.Value.ToString()) ||
+        //                x.Details.Any(d => d.Barcode == searchParameters.Value.ToString()));
+        //            }
+        //            searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrder.OrderType).FirstLetterToLower());
+        //            if (searchParameters != null)
+        //            {
+        //                sugarQueryable1 = sugarQueryable1.Where(x => x.OrderType.Equals(searchParameters.Value.ToString()));
+        //            }
+        //            var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+        //            return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
+        //        }
+        //    }
+        //    return new PageGridData<Dt_InboundOrder>();
+        //}
+
     }
 }

--
Gitblit v1.9.3