| using System; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using System.Runtime.Serialization; | 
| using System.ServiceModel; | 
| using System.Text; | 
| using System.Windows.Forms; | 
| using logtxtWrite; | 
| using wcftest.orm; | 
| using wcftest.EnumDefine; | 
| using Newtonsoft.Json; | 
| using wcftest.sapEntity; | 
| using System.Threading; | 
| using wcftest.sendToSap; | 
| using wcftest.sapEntity; | 
| using wcftest.sql; | 
| using wcftest.BussinessExtension.Handle; | 
| using wcftest.BussinessExtension.Common; | 
| using wcftest.Model; | 
| using wcftest.BussinessExtension; | 
| using wcftest.Model.Sys; | 
| using wcftest.EnumDefine.Sys; | 
| using wcftest.Model.Input; | 
| using wcftest.Model.Output; | 
| using wcftest.orm_test; | 
|   | 
|   | 
| namespace wcftest.wcf | 
| { | 
|     // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的类名“apitest”。 | 
|     public class apitest : Iapitest | 
|     { | 
|         /// <summary>线程锁防止并发 | 
|         /// 线程锁防止并发 | 
|         /// </summary> | 
|         public static System.Threading.Mutex single = new Mutex(); | 
|         //SapWcfService/ | 
|         //sendToSap.SapWcfServiceClient sendSap = new sendToSap.SapWcfServiceClient(); | 
|         wcfApi.ControlCenterWcfServiceClient wcsApi = new wcfApi.ControlCenterWcfServiceClient(); | 
|         // 获取设备信息 | 
|         Form1 form = Program.form1ObjPublic; | 
|         //sendSap.WmsReverser();撤销 | 
|         #region 给WMS接口 | 
|         /// <summary> 呼叫托盘 | 
|         /// 呼叫托盘 | 
|         /// </summary> | 
|         /// <param name="containerTypeId">托盘类型号(1是小托盘,2是大托盘)</param> | 
|         public void callContainer(int containerTypeId) | 
|         { | 
|   | 
|             if (containerTypeId < 1 || containerTypeId > 2) | 
|             { | 
|                 logtxt.txtWrite("类名:taskApi/函数名:callContainer拆盘任务参数超出范围/ 托盘类型:" + containerTypeId.ToString(), 2); | 
|             } | 
|             try | 
|             { | 
|                 //写入任务列表Task_Queue | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     Task_Queue CallContainerTaks = new Task_Queue(); | 
|                     CallContainerTaks.TaskType = ((int)TaskTypeEnum.入库拆盘).ToString();//任务类型 | 
|                     CallContainerTaks.OrderNumber = 0;//任务权重 | 
|                     CallContainerTaks.TaskStatus = "未下发";//任务状态 | 
|                     CallContainerTaks.PlateType = containerTypeId == 1 ? ((int)Sys_containerType.小托盘).ToString() : ((int)Sys_containerType.大托盘).ToString();//托盘类型 | 
|                     CallContainerTaks.CreateDate = DateTime.Now; | 
|                     CallContainerTaks.Creator = "系统"; | 
|                     CallContainerTaks.UserProduct_Id = 1007;//账套id 老谢bug   | 
|                     //垃圾值都赋值0 转到autoTask()里有说明 | 
|                     CallContainerTaks.FromPositionName = "0"; | 
|                     CallContainerTaks.ToPositionName = "0"; | 
|                     CallContainerTaks.DoCount = 0;//库区 | 
|                     CallContainerTaks.Direction = "0";//托盘高度 | 
|                     mod.Task_Queue.Add(CallContainerTaks); | 
|                     mod.SaveChanges(); | 
|   | 
|                     logtxt.txtWrite("类名:taskApi,函数名:callContainer  拆盘任务发送成功 containerType:" + containerTypeId.ToString(), 0); | 
|   | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名:taskApi/函数名:callContainer拆盘任务异常/ 托盘类型:" + containerTypeId.ToString() + logtxt.oneRow(ex.ToString()), 2); | 
|   | 
|             } | 
|         } | 
|   | 
|         /// <summary>分拣确认 | 
|         /// 分拣确认 | 
|         /// </summary> | 
|         /// <param name="PlateCode">托盘编号</param> | 
|         /// <param name="Products">出库物料list</param> | 
|         /// <param name="percentage"></param> | 
|         /// <returns></returns> | 
|         public string sortingConfirm(string PlateCode, string Products, string percentage) | 
|         { | 
|             resultMsg msgs = new resultMsg(); | 
|             //msgs.msg = "分拣失败!"; | 
|             //msgs.result = false; | 
|             //msgs.status = 400; | 
|             //return JsonConvert.SerializeObject(msgs); | 
|             try | 
|             { | 
|                 logtxt.txtWrite("类名:apitest/函数名:sortingConfirm收到分拣数据 托盘号PlateCode:" + PlateCode + ",出库物料列表Products:" + Products + ",百分比percentage:" + percentage | 
|                     , 2); | 
|                 string plateCode = PlateCode; | 
|                 //记录 | 
|                 List<sortingType> products = JsonConvert.DeserializeObject<List<sortingType>>(Products); | 
|   | 
|                 //验证百分比 【EditBy shaocx,2022-10-15】 | 
|                 if (Convert.ToInt32(percentage) <= 0) | 
|                 { | 
|                     msgs.msg = "占用空间不能小于0"; | 
|                     msgs.result = false; | 
|                     msgs.status = 400; | 
|                     return JsonConvert.SerializeObject(msgs); | 
|                 } | 
|   | 
|                 //验证输入的分拣数量 【EditBy shaocx,2022-06-08】 | 
|                 if (products != null && products.Count > 0) | 
|                 { | 
|                     foreach (var item in products) | 
|                     { | 
|                         if (item.finishedQuantity < 0) | 
|                         { | 
|                             msgs.msg = "分拣数量不能小于0"; | 
|                             msgs.result = false; | 
|                             msgs.status = 400; | 
|                             return JsonConvert.SerializeObject(msgs); | 
|                         } | 
|                     } | 
|                 } | 
|                 else | 
|                 { | 
|                     msgs.msg = "没有分拣数据"; | 
|                     msgs.result = false; | 
|                     msgs.status = 400; | 
|                     return JsonConvert.SerializeObject(msgs); | 
|                 } | 
|   | 
|                 var _creator = products[0].creator; | 
|   | 
|                 #region 数据验证 【EditBy shaocx,2022-07-18】 | 
|   | 
|                 /* | 
|                 //判断分拣数据是否有重复的 | 
|                 List<string> validateList = new List<string>(); | 
|                 foreach (var item in products) | 
|                 { | 
|                     var str = item.product_Id.ToString() + "-" + item.finishedQuantity.ToString() + "-" + item.trankNumber; | 
|                     if (validateList.Contains(str)) | 
|                     {//验证不通过 | 
|                         msgs.msg = "分拣数据有重复,重复物料号:" + item.product_Id + ",数量:" + item.finishedQuantity + ",跟踪号:" + item.trankNumber; | 
|                         msgs.result = false; | 
|                         msgs.status = 400; | 
|                         return JsonConvert.SerializeObject(msgs); | 
|                     } | 
|                     else | 
|                     { | 
|                         validateList.Add(str); | 
|                     } | 
|                 } | 
|                 //*/ | 
|   | 
|                 #endregion | 
|   | 
|                 List<MovMaterialEntity> moveMaterials = new List<MovMaterialEntity>();//移库实体集合 | 
|                 List<GIMaterialEntity> resultSap_GIMaterialEntity_List = new List<GIMaterialEntity>();//出库实体集合 | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     List<vvBase_ProductPosition> checkSortion = mod.vvBase_ProductPosition.Where(x => x.PlateCode.Trim() == PlateCode.Trim() && x.ContainerNo == "1").ToList(); | 
|                     if (checkSortion.Count < 1) | 
|                     { | 
|                         logtxt.txtWrite("类名:Form1/函数名:sortingConfirm重复分拣" + Products, 0); | 
|                         msgs.msg = "此托盘没有分拣数据"; | 
|                         msgs.result = false; | 
|                         msgs.status = 400; | 
|                         return JsonConvert.SerializeObject(msgs); | 
|                     } | 
|                     logtxt.txtWrite("类名:Form1/函数名:sortingConfirm分拣收到信息是 " + Products, 0); | 
|                     bool isEmpty = true;//记录库存是否出完变量 | 
|                     Task_Queue backTask = mod.Task_Queue.Where(x => x.PlateCode == plateCode).OrderByDescending(x => x.CreateDate).FirstOrDefault(); | 
|                     //if (backTask==null||Convert.ToInt32( backTask.TaskType)!=1) | 
|                     //{ | 
|                     //    return; | 
|                     //} | 
|                     //查询当前托盘中所有的库存 | 
|                     List<Base_ProductPosition> currentProductPositionList = mod.Base_ProductPosition.Where(x => x.PlateCode == plateCode).ToList(); | 
|                     for (int i = 0; i < products.Count; i++) | 
|                     { | 
|                         int productId = products[i].product_Id; | 
|                         string tracknumber = products[i].trankNumber; | 
|                         //OrignStorage   && x.Product_Id ==(long) )    | 
|                         decimal quantity = (decimal)products[i].finishedQuantity;//分拣数量 | 
|   | 
|   | 
|                         //因为这里是根据托盘号查询的,因此库存一定是在立体库中,不是在收货暂存区中 【EditBy shaocx,2022-03-08】 | 
|                         //Base_ProductPosition ProductPosition = mod.Base_ProductPosition.Where(x => x.PlateCode == plateCode && x.Product_Id == productId | 
|                         //&& x.ProductStorage >= quantity && x.ExtendField04 == tracknumber).FirstOrDefault(); | 
|                         Base_ProductPosition ProductPosition = currentProductPositionList.Where(x => x.PlateCode == plateCode && x.Product_Id == productId | 
|                           && x.ProductStorage >= quantity && x.ExtendField04 == tracknumber).OrderBy(x => x.ProductStorage).FirstOrDefault();//增加对数量的升序排序 【EditBy shaocx,2022-07-18】  | 
|                         if (ProductPosition == null || ProductPosition.ProductPosition_Id == 0) | 
|                         { | 
|                             msgs.msg = "此托盘没有找到库存数据,产品id:" + productId + ",数量:" + quantity + ",跟踪号:" + tracknumber; | 
|                             msgs.result = false; | 
|                             msgs.status = 400; | 
|                             return JsonConvert.SerializeObject(msgs); | 
|                         } | 
|                         //Base_ProductPosition ProductPosition = mod.Base_ProductPosition.Where(x => x.ProductPosition_Id == l_ProductPosition.ProductPosition_Id).FirstOrDefault(); | 
|   | 
|                         //int orderId= (int)  backTask.Bill_Id;//出库单ID | 
|                         // Sale_Order saleOrder=mod.Sale_Order.Find(orderId);//根据id 找到出库单 | 
|                         Sale_Order checkMoveType = mod.Sale_Order.FirstOrDefault(x => x.Order_Id == backTask.Bill_Id); | 
|                         if (checkMoveType == null) | 
|                         { | 
|                             logtxt.txtWrite("类名:Form1/函数名:sortingConfirm分拣异常/托盘号 " + PlateCode + "找不到出库单", 2); | 
|                             msgs.msg = "找不到出库单,是否已删除?"; | 
|                             msgs.result = false; | 
|                             msgs.status = 400; | 
|                             return JsonConvert.SerializeObject(msgs); | 
|                         } | 
|                         #region 写入出库记录 | 
|                         //OutInStockTask addOutTask = new OutInStockTask(); | 
|                         //addOutTask.taskName = "出库任务"; | 
|                         //addOutTask.orderCode = checkMoveType.OrderCode; | 
|                         //addOutTask.trackNumber = tracknumber; | 
|                         //addOutTask.materialNumber = ProductPosition.ProductCode; | 
|                         //addOutTask.materialName = ProductPosition.ProductName; | 
|                         //addOutTask.unit = ProductPosition.ExtendField05; | 
|                         //addOutTask.quantity = -products[i].finishedQuantity;//注意:出库任务记录的数量是负数![EditBy shaocx,2022-03-07] | 
|                         //addOutTask.creatDate = DateTime.Now; | 
|                         ////增加字段 【EditBy shaocx,2022-03-06】 | 
|                         //addOutTask.PositionName = ProductPosition.PositionName; | 
|                         //decimal cghw_ProductStorage = 0; | 
|                         //decimal zcq__ProductStorage = 0; | 
|                         //BussinessExtension.BussinessExtension.GetCurrentProductStorage(mod, addOutTask.materialNumber, out cghw_ProductStorage, out zcq__ProductStorage); | 
|                         //addOutTask.CGHW_ProductStorage = cghw_ProductStorage; | 
|                         //addOutTask.ZCG_ProductStorage = zcq__ProductStorage; | 
|                         //mod.OutInStockTask.Add(addOutTask);//增加出库记录 | 
|                         OutInStockTaskHandler.AddOutInStockTask(ProductPosition.PlateCode, mod, OutInStockTaskName.出库任务, checkMoveType.OrderCode, tracknumber, | 
|                                     ProductPosition.ProductCode, ProductPosition.ProductName, ProductPosition.SmallUnit, | 
|                                     -products[i].finishedQuantity,//注意:出库任务记录的数量是负数![EditBy shaocx,2022-03-07] | 
|                                     ProductPosition.PositionName, "分拣确认,库存出库", products[i].creator); | 
|                         #endregion | 
|                         Sale_OrderList checkMoveTypeList = mod.Sale_OrderList.FirstOrDefault(x => x.Order_Id == checkMoveType.Order_Id && x.ProductCode == ProductPosition.ProductCode); | 
|                         #region Sap出库确认明细 | 
|                         GIMaterialEntity newSap = new GIMaterialEntity(); | 
|                         if (checkMoveTypeList != null) | 
|                         { | 
|                             //如果是手动出库 () 生产订单为空/销售订单为空/移动类型=201 | 
|                             if (checkMoveType.OrderType == "手动出库") | 
|                             { | 
|                                 #region 手动出库 | 
|                                 //判断移动类型不等于空 | 
|                                 if (checkMoveTypeList.ExtendField01 != null) | 
|                                 { | 
|                                     string moveType = ConvertMoveType(checkMoveTypeList.ExtendField01);//移动类型 | 
|                                     string trackNumber = ProductPosition.ExtendField04 == null ? "" : ProductPosition.ExtendField04;//跟踪号 | 
|                                     string materialCode = ProductPosition.ProductCode.Trim();//产品编号 | 
|                                     if (moveType != "311") | 
|                                     { | 
|                                         #region 非311 | 
|   | 
|                                         newSap.WorkOrder = checkMoveTypeList.StoreOrderId + "#0#0";//生产订单   | 
|                                         //如果库存数据没有跟踪号261不加E特殊类型符号 | 
|                                         if (string.IsNullOrEmpty(trackNumber)) | 
|                                         { | 
|                                             newSap.MoveType = moveType;//移动类型 | 
|                                         } | 
|                                         else | 
|                                         { | 
|                                             newSap.MoveType = moveType + "E";//移动类型 | 
|                                         } | 
|   | 
|                                         //如果生产订单为空 | 
|                                         //if (string.IsNullOrEmpty(checkMoveTypeList.StoreOrderId)) | 
|                                         //{ | 
|                                         newSap.SalesOrder = checkMoveTypeList.PackageName;//销售订单 | 
|                                         newSap.SalesOrderItem = checkMoveTypeList.NumberOfGiftBags;// | 
|                                         //} | 
|                                         newSap.Plant = "3TG1"; | 
|                                         newSap.MaterialCode = materialCode; | 
|                                         newSap.StorageLocation = "G021"; | 
|                                         newSap.Quantity = products[i].finishedQuantity; | 
|                                         resultSap_GIMaterialEntity_List.Add(newSap); | 
|                                         #endregion | 
|   | 
|                                     } | 
|                                     else | 
|                                     { | 
|                                         #region 311立库到平库 | 
|                                         #region sap发送数据 | 
|                                         MovMaterialEntity moveMaterial = new MovMaterialEntity(); | 
|   | 
|   | 
|                                         //有跟踪号 移动类型要加E  加E就要天销售单号和销售项号 | 
|                                         if (!string.IsNullOrEmpty(trackNumber))//ProductCode poInfoChild.ExtendField07 = item.SalesOrder;//销售单号 poInfoChild.SpecAlias = item.SalesOrderItem;//销售单项号 | 
|                                         { | 
|                                             moveType += "E"; | 
|   | 
|   | 
|                                             moveMaterial.SalesOrder = checkMoveTypeList.PackageName;//销售订单 | 
|                                             moveMaterial.SalesOrderItem = checkMoveTypeList.NumberOfGiftBags;// | 
|                                         } | 
|                                         logtxt.txtWrite("发送的移动类型是" + moveType + "跟踪号:" + trackNumber, 0);//收到记录一条日志 | 
|                                         moveMaterial.MoveType = moveType; | 
|                                         moveMaterial.Plant = "3TG1"; | 
|                                         moveMaterial.MaterialCode = materialCode; | 
|                                         moveMaterial.FromStorageLocation = "G021"; | 
|                                         moveMaterial.ToStorageLocation = checkMoveType.GiftMessage;//转入仓 | 
|                                         moveMaterial.Quantity = products[i].finishedQuantity; | 
|                                         moveMaterials.Add(moveMaterial); | 
|                                         #endregion | 
|                                     } | 
|   | 
|                                         #endregion | 
|   | 
|                                 } | 
|                                 #endregion | 
|                             } | 
|                             else | 
|                             {//按单出库 | 
|                                 #region 出库任务 | 
|                                 newSap.WorkOrder = backTask.BillCode + "#" + checkMoveType.StoreName + "#" + checkMoveTypeList.ExtendField10; | 
|                                 //判断有没有跟踪号 | 
|                                 if (string.IsNullOrEmpty(ProductPosition.ExtendField04)) | 
|                                 { | 
|                                     newSap.MoveType = ProductPosition.Remark; | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     string trackingNumber = ProductPosition.ExtendField04;//跟踪号 | 
|                                     //通过跟踪号查销售单号 和销售项号 | 
|                                     Purchase_OrderList sale_number = mod.Purchase_OrderList.FirstOrDefault(x => x.ExtendField04 == trackingNumber); | 
|                                     if (sale_number != null) | 
|                                     { | 
|                                         newSap.SalesOrder = sale_number.ExtendField07;//销售订单号 | 
|                                         newSap.SalesOrderItem = sale_number.SpecAlias;//销售项号  | 
|                                     } | 
|                                     else | 
|                                     { | 
|                                         logtxt.txtWrite("类名:Form1/函数名:sortingConfirm分拣确认,通过跟踪号在po里查不到销售单号  跟踪号是:" + trackingNumber + "分拣托盘号:" + PlateCode + 2); | 
|                                     } | 
|                                     newSap.MoveType = ProductPosition.Remark + "E";//移动类型 | 
|   | 
|                                 } | 
|                                 #endregion | 
|                                 newSap.Plant = "3TG1"; | 
|                                 newSap.MaterialCode = ProductPosition.ProductCode.Trim();//产品编号 | 
|                                 newSap.StorageLocation = "G021"; | 
|                                 newSap.Quantity = products[i].finishedQuantity; | 
|                                 resultSap_GIMaterialEntity_List.Add(newSap); | 
|                             } | 
|   | 
|                         } | 
|   | 
|                         #endregion | 
|   | 
|                         #region 库存扣减 | 
|   | 
|                         if (products[i].finishedQuantity == ProductPosition.ProductStorage) | 
|                         { | 
|                             //如果出库数量等于库存就删了这条库存 | 
|                             mod.Base_ProductPosition.Remove(ProductPosition); | 
|                             currentProductPositionList.Remove(ProductPosition);//注意:要清除此数据,不加会导致库存扣减错误!  【EditBy shaocx,2022-07-18】 | 
|                             //前面已经记录了出入库记录了,这里就不需要记录了 【EditBy shaocx,2022-03-07】 | 
|                         } | 
|                         else if (products[i].finishedQuantity < ProductPosition.ProductStorage) | 
|                         { | 
|                             //小于库存就改数量 | 
|                             isEmpty = false; | 
|                             ProductPosition.ProductStorage = ProductPosition.ProductStorage - products[i].finishedQuantity; | 
|                             //前面已经记录了出入库记录了,这里就不需要记录了 【EditBy shaocx,2022-03-07】 | 
|                             ProductPosition.ExtendField02 = "0";//出库数量 | 
|                             ProductPosition.ExtendField03 = "0";//=1是允许分拣 | 
|                             // ProductPosition.ContainerNo = "0";//解除锁定 | 
|                         } | 
|                         else | 
|                         {//增加 重复参数校验 [EditBy shaocx,2022-07-18] | 
|                             logtxt.txtWrite("类名:Form1/函数名:sortingConfirm此托盘本次分拣物料" + products[i].product_Id + ",分拣数量" + products[i].finishedQuantity + "超过实际库存量" + ProductPosition.ProductStorage + ",请重新扫码托盘,重新分拣!", 0); | 
|                             msgs.msg = "此托盘本次分拣物料" + products[i].product_Id + ",分拣数量" + products[i].finishedQuantity + "超过实际库存量" + ProductPosition.ProductStorage + ",请重新扫码托盘,重新分拣!"; | 
|                             msgs.result = false; | 
|                             msgs.status = 400; | 
|                             return JsonConvert.SerializeObject(msgs); | 
|                         } | 
|                         #endregion | 
|                     } | 
|                     //再次复位状态  | 
|                     List<Base_ProductPosition> ProductPositionCheck = mod.Base_ProductPosition.Where(x => x.PlateCode == plateCode).ToList(); | 
|                     if (ProductPositionCheck.Count > 0) | 
|                     { | 
|                         foreach (var ProductItem in ProductPositionCheck) | 
|                         { | 
|                             ProductItem.ExtendField03 = "0";//不需要分拣状态 | 
|                             ProductItem.Remark = "";//移动类型 | 
|                         } | 
|                     } | 
|                     //修复有时候出现托盘上全部分拣,但是wms会创建余料回库的任务,但实际库存都没有的错误 【EditBy shaocx,2022-08-08】 | 
|                     //if (ProductPositionCheck.Count > products.Count) | 
|                     //{ | 
|                     //    isEmpty = false; | 
|                     //} | 
|                     if (currentProductPositionList.Count == 0) | 
|                     { | 
|                         isEmpty = true;//已空盘 | 
|                     } | 
|                     else | 
|                     { | 
|                         isEmpty = false;//未空盘 | 
|                     } | 
|                     #region 判断是否要去叠盘 | 
|                     string position = backTask.DoCount + "-" + backTask.FromPositionName; | 
|                     Base_Position unlock = mod.Base_Position.FirstOrDefault(x => x.PositionName == position); | 
|                     if (isEmpty)//数量出完就去叠盘 | 
|                     { | 
|                         string toPlace = ""; | 
|                         if (backTask.PlateType == "1") | 
|                         { | 
|                             toPlace = "1018"; | 
|                         } | 
|                         else | 
|                         { | 
|                             toPlace = "1017"; | 
|                         } | 
|   | 
|                         //判断是否叠盘机满了,【EditBy shaocx,2022-03-08】 | 
|                         Base_Equipment fpMachine = null; | 
|                         var isFull = Base_EquipmentHandler.FoldingPlateMachine_IsFull(mod, Convert.ToInt32(backTask.PlateType), ref fpMachine); | 
|                         if (isFull) | 
|                         { | 
|                             var errMsg = fpMachine.DeviceName + "目前数量已满,数量为" + Convert.ToInt32(fpMachine.SurplusQuantity) + ",请稍等再操作!"; | 
|                             logtxt.txtWrite("类名:Form1/函数名:sortingConfirm" + errMsg, 0); | 
|                             msgs.msg = errMsg; | 
|                             msgs.result = false; | 
|                             msgs.status = 400; | 
|                             return JsonConvert.SerializeObject(msgs); | 
|                         } | 
|                         if (fpMachine != null) | 
|                         { | 
|                             Base_EquipmentHandler.FoldingPlateMachine_UpdateCurQuantityAddOne(mod, fpMachine);//增加数量1 | 
|                         } | 
|   | 
|   | 
|                         Task_Queue addTask = new Task_Queue(); | 
|                         addTask.BillCode = "回库";//来源单号 | 
|                         addTask.TaskType = ((int)TaskTypeEnum.出库叠盘).ToString(); | 
|                         addTask.PlateType = backTask.PlateType;//器具种类-大托盘小托盘 | 
|                         addTask.PlateCode = plateCode;//母托盘编号 | 
|                         addTask.Bill_Id = 1111;// 单据id | 
|                         addTask.OrderNumber = 0;//任务执行优先级 | 
|                         addTask.TaskStatus = "未下发";//任务状态 | 
|                         addTask.FromPositionName = backTask.ToPositionName;//起始地址 | 
|                         addTask.ToPositionName = toPlace;//目标地址 | 
|                         addTask.Direction = "1";//出库不需要托盘高度 | 
|                         addTask.DoCount = backTask.DoCount;//库区 | 
|                         addTask.CreateDate = DateTime.Now; | 
|                         addTask.Creator = _creator; | 
|                         addTask.UserProduct_Id = 1007;//账套id 老谢bug   | 
|                         // addTask.IsDoing = (int)item.OrderList_Id;//记录出库明细表ID,出库确认用(只有出库用) | 
|                         mod.Task_Queue.Add(addTask); | 
|                         if (unlock != null) | 
|                         { | 
|                             //unlock.IsFreeze = 0; | 
|                             unlock.IsFreeze = (int)IsFreezeEnum.无货; | 
|                             unlock.IsLocked = 0; | 
|                             unlock.Remark = "分拣任务确认-解锁库位!"; | 
|                             unlock.PositionLength = 0; | 
|                         } | 
|                         else | 
|                         { | 
|                             logtxt.txtWrite("类名:Form1/函数名:sortingConfirm分拣叠盘,解锁库位失败,找不到库位: " + position, 2); | 
|                             msgs.msg = "解锁库位失败,找不到库位: " + position; | 
|                             msgs.result = false; | 
|                             msgs.status = 400; | 
|                             return JsonConvert.SerializeObject(msgs); | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         //数量没出完就去回库 | 
|                         Task_Queue addTask = new Task_Queue(); | 
|                         addTask.BillCode = "回库";//来源单号 | 
|                         addTask.TaskType = ((int)TaskTypeEnum.余料回库).ToString(); | 
|                         addTask.PlateType = backTask.PlateType;//器具种类-大托盘小托盘 | 
|                         addTask.PlateCode = plateCode;//母托盘编号 | 
|                         addTask.Bill_Id = 1111;// 单据id | 
|                         addTask.OrderNumber = 0;//任务执行优先级 | 
|                         addTask.TaskStatus = "未下发";//任务状态 | 
|                         addTask.FromPositionName = backTask.ToPositionName;//起始地址 | 
|                         addTask.ToPositionName = backTask.FromPositionName;//目标地址 | 
|                         addTask.DoCount = backTask.DoCount;//库区 | 
|                         int areaNo = (int)backTask.DoCount; | 
|                         string height = ""; | 
|                         if (areaNo == 1) | 
|                         { | 
|                             height = "2"; | 
|                         } | 
|                         else | 
|                         { | 
|                             height = "4"; | 
|                         } | 
|                         addTask.Direction = height;//出库不需要托盘高度 | 
|                         addTask.CreateDate = DateTime.Now; | 
|                         addTask.Creator = _creator; | 
|                         addTask.UserProduct_Id = 1007;//账套id 老谢bug   | 
|                         // addTask.IsDoing = (int)item.OrderList_Id;//记录出库明细表ID,出库确认用(只有出库用) | 
|                         mod.Task_Queue.Add(addTask); | 
|                         if (unlock != null) | 
|                         { | 
|                             unlock.PositionLength = Convert.ToInt32(percentage.Trim()); | 
|                         } | 
|                     } | 
|                     #endregion | 
|                     //注释:由下面的SaveChanges一处执行 【Editby shaocx,2022-03-12】 | 
|                     //int saveok = mod.SaveChanges(); | 
|                     //#region 保存数据判断 | 
|                     //if (saveok < 1) | 
|                     //{ | 
|                     //    saveok = mod.SaveChanges(); | 
|                     //} | 
|                     //if (saveok < 1) | 
|                     //{ | 
|                     //    msgs.msg = "分拣失败-保存数据未成功"; | 
|                     //    msgs.result = false; | 
|                     //    msgs.status = 400; | 
|                     //} | 
|                     //else | 
|                     //{ | 
|                     //    msgs.msg = "分拣成功"; | 
|                     //    msgs.result = true; | 
|                     //    msgs.status = 200; | 
|   | 
|                     //} | 
|                     //#endregion | 
|   | 
|                     if (resultSap_GIMaterialEntity_List.Count > 0)//SAP出库确认 | 
|                     { | 
|                         //注意:这里要改为循环处理,因为如果混合再一起推送,会出问题 【EditBy shaocx,2022-10-11】 | 
|                         foreach (var resultSap_GIMaterialEntity in resultSap_GIMaterialEntity_List) | 
|                         { | 
|                             SapSendInfo sapGi = new SapSendInfo(); | 
|                             //注意!!!:这里的SendSapData还是序列化的这个list | 
|                             List<GIMaterialEntity> newList = new List<GIMaterialEntity>(); | 
|                             newList.Add(resultSap_GIMaterialEntity); | 
|                             sapGi.SendSapData = JsonConvert.SerializeObject(newList);//数据转string 保存 | 
|                             //sapGi.moveType = 1;//出库标志 | 
|                             sapGi.moveType = (int)MoveTypeForSapSend.出库;//出库标志 | 
|                             sapGi.creatTime = DateTime.Now; | 
|                             sapGi.sendCount = 0;//发送次数 | 
|                             sapGi.voucherCode = sapGi.RetMsg = "";//sap凭证 | 
|                             sapGi.isFinish = 0;//是否完成 | 
|                             BussinessExtension.BussinessExtension.SetSapSendInfoByGIMaterialEntity(mod, sapGi, resultSap_GIMaterialEntity);//配置对象 [EditBy shaocx,2022-01-30] | 
|                             mod.SapSendInfo.Add(sapGi); | 
|                         } | 
|                     } | 
|                     if (moveMaterials.Count > 0)//发送311立库到平库 | 
|                     { | 
|                         //替换下面的代码 【EditBy shaocx,2022-09-22】 | 
|                         SapSendInfoHandler.AddSapSendInfoForMove(mod, false, moveMaterials, "", ""); | 
|                         /* | 
|                         SapSendInfo sapGi = new SapSendInfo(); | 
|                         sapGi.SendSapData = JsonConvert.SerializeObject(moveMaterials);//数据转string 保存 | 
|                         //sapGi.moveType = 2;//移库标志 | 
|                         sapGi.moveType = (int)MoveTypeForSapSend.移库;//移库标志 | 
|                         sapGi.creatTime = DateTime.Now; | 
|                         sapGi.sendCount = 0; | 
|                         sapGi.voucherCode = ""; | 
|                         sapGi.isFinish = 0; | 
|                         BussinessExtension.BussinessExtension.SetSapSendInfoByMovMaterialEntity(mod, sapGi, moveMaterials);//配置对象 [EditBy shaocx,2022-01-30] | 
|                         mod.SapSendInfo.Add(sapGi); | 
|                         //*/ | 
|                     } | 
|   | 
|                     int dd = mod.SaveChanges(); | 
|                     if (dd > 0) | 
|                     { | 
|                         logtxt.txtWrite("数据保存成功", 1); | 
|                         msgs.msg = "分拣成功"; | 
|                         msgs.result = true; | 
|                         msgs.status = 200; | 
|                     } | 
|                     else | 
|                     { | 
|                         logtxt.txtWrite("数据保存失败,数目为" + dd, 1); | 
|                         msgs.msg = "分拣失败-保存数据未成功"; | 
|                         msgs.result = false; | 
|                         msgs.status = 400; | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 //logtxt.txtWrite("类名:Form1/函数名:sortingConfirm分拣异常/托盘号 " + PlateCode + "异常信息:" + ex.StackTrace.ToString(), 2); | 
|                 logtxt.txtWrite("类名:Form1/函数名:sortingConfirm分拣异常/托盘号 " + PlateCode + "异常信息:" + JsonConvert.SerializeObject(ex), 2); | 
|                 msgs.msg = "分拣失败-参数异常"; | 
|                 msgs.result = false; | 
|                 msgs.status = 400; | 
|             } | 
|             return JsonConvert.SerializeObject(msgs); | 
|         } | 
|         /// <summary>把前端移动类型描述转换成sap格式, | 
|         /// 把前端移动类型描述转换成sap格式 | 
|         /// </summary> | 
|         /// <param name="stringMove">移动类型描述</param> | 
|         /// <returns>返回SAP格式</returns> | 
|         public string ConvertMoveType(string stringMove) | 
|         { | 
|             switch (stringMove.Trim()) | 
|             { | 
|                 case "发料到成本中心201": return "201"; | 
|                 case "发料到生产订单261": return "261"; | 
|                 case "发料到销售订单231": return "231"; | 
|                 case "暂存区发料到生产订单261": return "261"; | 
|                 case "311立库到平库": return "311"; | 
|                 default: return ""; | 
|             } | 
|         } | 
|         /// <summary>标签打印和码盘上架扣减收货数量 | 
|         /// 标签打印和码盘上架扣减收货数量 | 
|         /// </summary> | 
|         /// <param name="subInfo">扣减list对象</param> | 
|         /// <returns>扣减成功返回"成功",其余返回失败信息</returns> | 
|         public bool subtractQty(string subInfo) | 
|         { | 
|             if (single.WaitOne())//增加线程锁防止并发 | 
|             { | 
|                 try | 
|                 { | 
|                     logtxt.txtWrite("类名:Form1/函数名:subtractQty按单和码盘扣数量/ " + subInfo, 1); | 
|                     List<subStroage> products = JsonConvert.DeserializeObject<List<subStroage>>(subInfo); | 
|                     if (products.Count > 0) | 
|                     { | 
|                         for (int i = 0; i < products.Count; i++) | 
|                         { | 
|                             decimal subNumbeu = products[i].number;//需要扣减的数量 | 
|                             using (dbModel mod = new dbModel()) | 
|                             { | 
|                                 //查询收货物料 | 
|                                 List<Base_ProductPosition> checkStroage = new List<Base_ProductPosition>(); | 
|                                 string pocodu = products[i].poCode; | 
|                                 string productcode = products[i].productCode; | 
|                                 string trackting = ""; | 
|                                 if (products[i].trackting != null) | 
|                                 { | 
|                                     if (products[i].trackting != "") | 
|                                     { | 
|                                         trackting = products[i].trackting; | 
|                                         checkStroage = mod.Base_ProductPosition.Where(x => x.ExtendField04 == trackting && x.ProductCode == productcode | 
|                                            && x.PositionName == SysGlole.PositionName_SHZCQ  //增加收货暂存区的筛选 【Editby shaocx,2022-03-08】 | 
|                                             ).ToList(); | 
|                                     } | 
|   | 
|                                 } | 
|                                 if (checkStroage.Count == 0) | 
|                                 { | 
|                                     if (products[i].saleCode != null) | 
|                                     { | 
|                                         string SaleCode = products[i].saleCode; | 
|                                         checkStroage = mod.Base_ProductPosition.Where(x => x.SaleCode == SaleCode && x.ProductCode == productcode | 
|                                              && x.PositionName == SysGlole.PositionName_SHZCQ  //增加收货暂存区的筛选 【Editby shaocx,2022-03-08】 | 
|                                             ).ToList(); | 
|                                     } | 
|                                 } | 
|                                 if (checkStroage.Count == 0) | 
|                                 { | 
|                                     checkStroage = mod.Base_ProductPosition.Where(x => x.ProductCode == productcode | 
|                                          && x.PositionName == SysGlole.PositionName_SHZCQ  //增加收货暂存区的筛选 【Editby shaocx,2022-03-08】 | 
|                                         ).ToList(); | 
|                                 } | 
|   | 
|                                 #region 检查参数 | 
|                                 if (checkStroage.Count == 0) | 
|                                 { | 
|                                     // result = "没有这个物料"; | 
|                                     continue; | 
|                                 } | 
|                                 decimal sunStroage = (decimal)checkStroage.Sum(x => x.ProductStorage);//库存总数 | 
|                                 //检查要扣的数量比库里数量多的话就返回错误 | 
|                                 if (sunStroage < subNumbeu) | 
|                                 { | 
|                                     //result = "缺料了要修改入库数量!"; | 
|                                     continue; | 
|                                 } | 
|                                 #endregion | 
|                                 #region 找到所有未打印数量大于0的收货记录 | 
|                                 foreach (var item in checkStroage) | 
|                                 { | 
|                                     decimal stroageQty = (decimal)item.ProductStorage; | 
|                                     if (stroageQty >= subNumbeu) | 
|                                     { | 
|                                         decimal? oldQty = item.ProductStorage; | 
|                                         decimal? changeQty = subNumbeu; | 
|                                         item.ProductStorage = stroageQty - subNumbeu; | 
|                                         //增加出入库记录 【EditBy shaocx,2022-03-07】 | 
|                                         OutInStockTaskHandler.AddOutInStockTask(item.Creator, mod, OutInStockTaskName.出库任务, changeQty, item, "1标签打印和码盘上架扣减收货数量,原数量:" + oldQty); | 
|   | 
|   | 
|                                         mod.SaveChanges(); | 
|                                         // result = "成功"; | 
|                                         break; | 
|                                     } | 
|                                     else | 
|                                     { | 
|                                         item.ProductStorage = 0; | 
|                                         subNumbeu -= stroageQty; | 
|   | 
|                                         //增加出入库记录 【EditBy shaocx,2022-03-07】 | 
|                                         OutInStockTaskHandler.AddOutInStockTask(item.Creator, mod, OutInStockTaskName.出库任务, stroageQty, item, "2标签打印和码盘上架扣减收货数量,扣为0,原数量:" + stroageQty); | 
|                                     } | 
|                                     if (subNumbeu == 0) | 
|                                     { | 
|                                         break; | 
|                                     } | 
|                                 } | 
|                                 #endregion | 
|                                 mod.SaveChanges(); | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         return false; | 
|                     } | 
|                 } | 
|                 catch (Exception ex) | 
|                 { | 
|                     //result = "数据异常:";// +logtxt.oneRow(ex.ToString()); | 
|                     logtxt.txtWrite("类名:Form1/函数名:subtractQty按单和码盘扣除异常/ " + subInfo, 2); | 
|                     return false; | 
|                 } | 
|                 finally { single.ReleaseMutex(); }//一轮结束 | 
|             } | 
|             return true; | 
|             //return ; | 
|         } | 
|         /// <summary>获取库存盘点列表 | 
|         /// 获取库存盘点列表 | 
|         /// </summary> | 
|         /// <param name="takes"></param> | 
|         /// <returns></returns> | 
|         public string takeStock(string takes) | 
|         { | 
|             try | 
|             { | 
|                 stockSearchEntity take = JsonConvert.DeserializeObject<stockSearchEntity>(takes); | 
|                 string StockWhere = ""; | 
|   | 
|   | 
|                 //根据货位名称/采购单号/托盘号/物料名称/物料编号模糊查找 | 
|   | 
|   | 
|                 if (!string.IsNullOrEmpty(take.search.materialCode)) | 
|                 { | 
|                     StockWhere = StockWhere + " and MateralCode like '%" + take.search.materialCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(take.search.materialName)) | 
|                 { | 
|                     StockWhere = StockWhere + " and MateralName like '%" + take.search.materialName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(take.search.saleCode)) | 
|                 { | 
|                     StockWhere = StockWhere + " and ProcureCode like '%" + take.search.saleCode.Trim() + "%'"; | 
|                 } | 
|                 string StockWhere_All = StockWhere, StockWhere_OnlySap = StockWhere, StockWhere_OnlyStock = StockWhere; | 
|   | 
|                 if (take.positionTypeValue > 1) | 
|                 { | 
|                     //string isOrAnd = StockWhere == "" ? " or " : " and "; | 
|                     switch (take.positionTypeValue) | 
|                     { | 
|   | 
|                         case 2: | 
|                             StockWhere = StockWhere + "and StockQuantity > 0 and SapQuantity > 0"; | 
|                             break; | 
|                         case 3: | 
|                             StockWhere = StockWhere + "and SapQuantity = 0"; | 
|                             break; | 
|                         case 4: | 
|                             StockWhere = StockWhere + "and StockQuantity = 0 "; | 
|                             break; | 
|   | 
|                     } | 
|                 } | 
|   | 
|   | 
|                 //获取盘点数据 | 
|   | 
|                 msgss<TakeStock> msg = new msgss<TakeStock>(); | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|   | 
|                     //获取盘点数据 | 
|                     var baseSql = "select * from [dbo].[" + "TakeStock" + "] where ID > 1  "; | 
|                     string sql = baseSql + StockWhere; | 
|                     List<TakeStock> takeStockSummary = mod.Database.SqlQuery<TakeStock>("select * from [dbo].[" + "TakeStock" + "] where ID = 1").ToList(); | 
|                     List<TakeStock> takeStock = mod.Database.SqlQuery<TakeStock>(sql).ToList(); | 
|                     List<TakeStock> fenyeRerult = new List<TakeStock>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         var allList = takeStockSummary.Concat(takeStock.ToList()).ToList(); | 
|                         if (take.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = allList; | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             StockWhere_All = StockWhere_All + "and StockQuantity > 0 and SapQuantity > 0"; | 
|                             StockWhere_OnlyStock = StockWhere_OnlyStock + "and SapQuantity = 0"; | 
|                             StockWhere_OnlySap = StockWhere_OnlySap + "and StockQuantity = 0 "; | 
|                             StockWhere_All = baseSql + StockWhere_All; | 
|                             StockWhere_OnlyStock = baseSql + StockWhere_OnlyStock; | 
|                             StockWhere_OnlySap = baseSql + StockWhere_OnlySap; | 
|                             GetSummaryTitle(mod, StockWhere_All, StockWhere_OnlyStock, StockWhere_OnlySap, allList); | 
|                             //构造数据 | 
|                             msg.allDate = new List<TakeStock>(); | 
|                             TakeStock one = new TakeStock(); | 
|                             one.MateralName = allList[0].MateralName; | 
|                             msg.allDate.Add(one); | 
|   | 
|                             msg.status = 200; | 
|                             msg.total = takeStock.Count; | 
|   | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (take.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = take.queryInfo.pagesize; | 
|   | 
|                                 int b = take.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msgss<TakeStock> msg = new msgss<TakeStock>(); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 获取盘点数据的汇总字符串 [EditBy shaocx,2022-01-23] | 
|         /// </summary> | 
|         /// <param name="mod"></param> | 
|         /// <param name="StockWhere_All"></param> | 
|         /// <param name="StockWhere_OnlyStock"></param> | 
|         /// <param name="StockWhere_OnlySap"></param> | 
|         /// <param name="allTakeStock"></param> | 
|         /// <returns></returns> | 
|         private void GetSummaryTitle(dbModel mod, string StockWhere_All, string StockWhere_OnlyStock, string StockWhere_OnlySap, List<TakeStock> allTakeStock) | 
|         { | 
|             var takeStock_All = mod.Database.SqlQuery<TakeStock>(StockWhere_All).ToList(); | 
|             var takeStock_OnlyStock = mod.Database.SqlQuery<TakeStock>(StockWhere_OnlyStock).ToList(); | 
|             var takeStock_OnlySap = mod.Database.SqlQuery<TakeStock>(StockWhere_OnlySap).ToList(); | 
|   | 
|             var msg = string.Format("数量差异数据:{0}条, 仅立库数据:{1}条, 仅SAP数据:{2}条。", | 
|                 takeStock_All == null ? 0 : takeStock_All.Count(), | 
|                 takeStock_OnlyStock == null ? 0 : takeStock_OnlyStock.Count(), | 
|                 takeStock_OnlySap == null ? 0 : takeStock_OnlySap.Count() | 
|                 ); | 
|             allTakeStock[0].MateralName = msg; | 
|         } | 
|         /// <summary>出入库任务列表 | 
|         /// 出入库任务列表 | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string outInTaskList(string pages) | 
|         { | 
|             msgss<OutInStockTask> msg = new msgss<OutInStockTask>(); | 
|             msg.status = 400; | 
|             msg.total = 1; | 
|             msg.date = null; | 
|             try | 
|             { | 
|   | 
|                 stockSearchEntity page = JsonConvert.DeserializeObject<stockSearchEntity>(pages); | 
|                 string StockWhere = " id>0"; | 
|                 //根据日期筛选 | 
|   | 
|   | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + "and creatDate > '" + page.datatime[0].ToString() + "' and  creatDate < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|   | 
|                 //根据货位名称/采购单号/托盘号/物料名称/物料编号模糊查找 | 
|                 if (!string.IsNullOrEmpty(page.search.materialName)) | 
|                 { | 
|                     StockWhere = StockWhere + " and materialName like '%" + page.search.materialName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialCode)) | 
|                 { | 
|                     StockWhere = StockWhere + " and materialNumber like '%" + page.search.materialCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.tranckNnmber)) | 
|                 { | 
|                     StockWhere = StockWhere + " and trackNumber like '%" + page.search.tranckNnmber.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.positionName)) | 
|                 {//库位号 | 
|                     StockWhere = StockWhere + " and positionName='" + page.search.positionName + "' "; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.placeCode)) | 
|                 {//托盘号 [EditBy shaocx,2022-08-09] | 
|                     StockWhere = StockWhere + " and ext1='" + page.search.placeCode + "' "; | 
|                 } | 
|   | 
|   | 
|                 if (page.positionTypeValue != 99) | 
|                 { | 
|                     OutInStockTaskName _OutInStockTaskName = (OutInStockTaskName)Enum.Parse(typeof(OutInStockTaskName), page.positionTypeValue.ToString()); | 
|                     //string taskname = page.positionTypeValue == 1 ? "入库任务" : "出库任务"; | 
|                     StockWhere = StockWhere + " and taskName= '" + _OutInStockTaskName.ToString() + "'"; | 
|                 } | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取盘点数据 | 
|                     string sql = "select * from [dbo].[" + "OutInStockTask" + "] where " + StockWhere + " order by id desc ";//isFreeze    是否有货   先拿这个字段用  | 
|   | 
|                     List<OutInStockTask> takeStock = mod.Database.SqlQuery<OutInStockTask>(sql).ToList(); | 
|   | 
|                     List<OutInStockTask> fenyeRerult = new List<OutInStockTask>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         // msg.date = takeStock; | 
|   | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStock.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|   | 
|             } | 
|             return JsonConvert.SerializeObject(msg); | 
|         } | 
|   | 
|         /// <summary>空库位统计 | 
|         /// 空库位统计 | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string getPositionTotal(string pages) | 
|         { | 
|             msgss<emtypPosition> msg = new msgss<emtypPosition>(); | 
|             try | 
|             { | 
|                 List<emtypPosition> emtyps = new List<emtypPosition>();//汇总数据 | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     #region 一排空库位统计 | 
|   | 
|                     BussinessExtension.BussinessExtension.EmptyPositionTongJiForArea1(mod, ref emtyps); | 
|   | 
|                     #endregion | 
|   | 
|                     #region 二排小库位空库位统计 | 
|   | 
|                     //二排小库位 | 
|                     BussinessExtension.BussinessExtension.EmptyPositionTongJiForArea2_Small(mod, ref emtyps); | 
|   | 
|                     #endregion | 
|   | 
|                     #region 二排大托盘 | 
|   | 
|                     BussinessExtension.BussinessExtension.EmptyPositionTongJiForArea2_Big(mod, ref emtyps); | 
|   | 
|                     #endregion | 
|   | 
|   | 
|   | 
|                     msg.status = 200; | 
|                     msg.date = emtyps; | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类apitest 方法 getPositionTotal" + ex.Message + ex.StackTrace.ToString(), 2); | 
|                 msg.status = 400; | 
|                 return JsonConvert.SerializeObject(msg); ; | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary>库存明细-只查询物料 | 
|         /// 库存明细 | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string productStockInfo(string pages) | 
|         { | 
|             msgss<vvBase_ProductPosition> msg = new msgss<vvBase_ProductPosition>(); | 
|             msg.roleDelete = 0; | 
|             msg.roleModifi = 0; | 
|   | 
|             try | 
|             { | 
|   | 
|                 stockSearchEntity page = JsonConvert.DeserializeObject<stockSearchEntity>(pages); | 
|                 roleMenu ROLEid = JsonConvert.DeserializeObject<roleMenu>(pages); | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|                         StockWhere = "and InStorageDate > '" + page.datatime[0].ToString() + "' and  InStorageDate < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialName))//物料名称 | 
|                 { | 
|                     StockWhere = StockWhere + "and ProductName like '%" + page.search.materialName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialCode))//物料编号 | 
|                 { | 
|                     StockWhere = StockWhere + "and ProductCode like '%" + page.search.materialCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.placeCode))//托盘号 | 
|                 { | 
|                     StockWhere = StockWhere + "and PlateCode like '%" + page.search.placeCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.positionName))//库位名称 | 
|                 { | 
|                     StockWhere = StockWhere + "and PositionName like '%" + page.search.positionName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.purchaseCode))//采购单号 | 
|                 { | 
|                     StockWhere = StockWhere + "and PoCode like '%" + page.search.purchaseCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.tranckNnmber))//跟踪号 | 
|                 { | 
|                     StockWhere = StockWhere + "and ExtendField04 like '%" + page.search.tranckNnmber.Trim() + "%'"; | 
|                 } | 
|                 if (page.positionTypeValue > 0)//货位类型 | 
|                 { | 
|                     StockWhere = StockWhere + " and PositionType=" + page.positionTypeValue.ToString(); | 
|                 } | 
|   | 
|                 //增加查询条件 | 
|                 if (page.search.IsLocked) | 
|                 { | 
|                     StockWhere = StockWhere + " and IsLocked=1 "; | 
|                 } | 
|                 if (page.search.ContainerNo) | 
|                 { | 
|                     StockWhere = StockWhere + " and ContainerNo='1' "; | 
|                 } | 
|                 if (page.search.IsFreeze) | 
|                 { | 
|                     StockWhere = StockWhere + " and IsFreeze=0 "; | 
|                 } | 
|                 if (page.search.OnlyLocked) | 
|                 { | 
|                     StockWhere = StockWhere + " and IsLocked=1  and ContainerNo <> '1' "; | 
|                 } | 
|   | 
|                 #endregion | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //使用权限 | 
|                     string roleSQL = "SELECT * FROM [YrtWMS_Siemens2].[dbo].[Sys_RoleAuth] WITH(NOLOCK) where Menu_Id=385 and Role_Id=" + ROLEid.role_Id; | 
|                     var roleishave = mod.Database.SqlQuery<Sys_RoleAuth>(roleSQL).ToList(); | 
|                     if (roleishave.Count > 0) | 
|                     { | 
|                         if (roleishave[0].AuthValue.Contains("delete=1")) | 
|                         { | 
|                             msg.roleDelete = 1; | 
|                         } | 
|                         if (roleishave[0].AuthValue.Contains("updatePosition=1")) | 
|                         { | 
|                             msg.roleModifi = 1; | 
|                         } | 
|                     } | 
|                     //获取盘点数据 | 
|                     string sql = "select * from [dbo].[" + "vvBase_ProductPosition" + "] WITH(NOLOCK) where ProductStorage>0 " + StockWhere + " order by InStorageDate desc ";//isFreeze    是否有货   先拿这个字段用  | 
|   | 
|                     List<vvBase_ProductPosition> takeStockList = mod.Database.SqlQuery<vvBase_ProductPosition>(sql).ToList(); | 
|                     //增加 显示在库天数 [EditBy shaocx,2022-06-08] | 
|                     takeStockList = BussinessExtension.BussinessExtension.CalcInStoreDays(takeStockList.ToList()); | 
|                     //用在库天数过滤数据  [EditBy shaocx,2022-06-08] | 
|                     var errMsg = ""; | 
|                     takeStockList = BussinessExtension.BussinessExtension.FiltervvBase_ProductPositionByInStoreDays(takeStockList, page, ref errMsg); | 
|                     if (!string.IsNullOrEmpty(errMsg)) | 
|                     { | 
|   | 
|                     } | 
|   | 
|                     List<vvBase_ProductPosition> fenyeRerult = new List<vvBase_ProductPosition>(); | 
|                     if (takeStockList.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStockList.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStockList.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStockList.Count) | 
|                             { | 
|                                 msg.date = takeStockList; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStockList.Count / a); | 
|                                 int d = takeStockList.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStockList[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|   | 
|         /// <summary>修改库存 | 
|         /// 修改库存 | 
|         /// </summary> | 
|         /// <param name="updateInfo">json修改数据</param> | 
|         /// <returns></returns> | 
|         public string updateProductStock(string updateInfo) | 
|         { | 
|             try | 
|             { | 
|                 msgss<string> msg = new msgss<string>(); | 
|                 //msg.status = 400; | 
|                 //msg.total = 1; | 
|                 //msg.date = null; | 
|                 //msg.msg = "参数不能为空"; | 
|                 //return JsonConvert.SerializeObject(msg); | 
|   | 
|                 updateStock updateData = JsonConvert.DeserializeObject<updateStock>(updateInfo); | 
|                 if (updateData == null) | 
|                 { | 
|                     msg.status = 400; | 
|                     msg.total = 1; | 
|                     msg.date = null; | 
|                     msg.msg = "参数不能为空"; | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|                 //验证修改数量 【EditBy shaocx,2022-06-13】 | 
|                 if (updateData.productStorage <= 0) | 
|                 { | 
|                     msg.status = 400; | 
|                     msg.total = 1; | 
|                     msg.date = null; | 
|                     msg.msg = "修改数量不能小于等于0"; | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|                 if (updateData.LimitDate == null) | 
|                 { | 
|                     msg.status = 400; | 
|                     msg.total = 1; | 
|                     msg.date = null; | 
|                     msg.msg = "限用日期不能为空"; | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|                 updateData.saleCode = updateData.saleCode.Trim(); | 
|                 updateData.saleItem = updateData.saleItem.Trim(); | 
|                 updateData.tracknumber = updateData.tracknumber.Trim(); | 
|                 updateData.productCode = updateData.productCode.Trim(); | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //查找库存 | 
|                     VmaterialInfo materialInfo = mod.VmaterialInfo.FirstOrDefault(x => x.ProductCode == updateData.productCode); | 
|   | 
|                     Base_ProductPosition updateStock = mod.Base_ProductPosition.Find(updateData.stockId); | 
|                     Base_ProductPosition old_updateStock = JsonConvert.DeserializeObject<Base_ProductPosition>(JsonConvert.SerializeObject(updateStock));//旧库存 | 
|   | 
|                     VmaterialInfo materialInfoOriginal = mod.VmaterialInfo.FirstOrDefault(x => x.Product_Id == updateStock.Product_Id); | 
|                     if (updateStock != null && materialInfo != null && materialInfoOriginal != null) | 
|                     { | 
|                         #region 修改 | 
|   | 
|                         string operationInfo = ""; | 
|                         if (updateStock.ExtendField04 != updateData.tracknumber) | 
|                         { | 
|                             operationInfo += "跟踪号" + updateStock.ExtendField04 + "改到" + updateData.tracknumber + ","; | 
|                         } | 
|                         if (updateStock.ProductStorage != updateData.productStorage) | 
|                         { | 
|                             operationInfo += "库存量" + updateStock.ProductStorage + "改到" + updateData.productStorage + ","; | 
|                         } | 
|                         if (updateStock.LimitDate != updateData.LimitDate) | 
|                         { | 
|                             operationInfo += "限用日期" + updateStock.LimitDate + "改到" + updateData.LimitDate + ","; | 
|                         } | 
|   | 
|                         updateStock.ExtendField04 = updateData.tracknumber;//跟踪号 | 
|                         updateStock.ExtendField08 = updateData.saleItem;//销售项号 | 
|                         updateStock.SaleCode = updateData.saleCode;//销售单号 | 
|   | 
|                         updateStock.Product_Id = Convert.ToInt32(materialInfo.Product_Id);//产品编号 | 
|   | 
|                         //修改限用日期 [EditBy shaocx,2022-06-14] | 
|                         updateStock.LimitDate = updateData.LimitDate; | 
|   | 
|                         decimal? old_ProductStorage = updateStock.ProductStorage; | 
|                         //decimal? changeQty = old_ProductStorage - updateData.productStorage; | 
|                         updateStock.ProductStorage = updateData.productStorage;//库存量 | 
|                         //增加出入库记录 【EditBy shaocx,2022-03-07】 | 
|                         OutInStockTaskHandler.AddOutInStockTask(updateData.userName, mod, OutInStockTaskName.出库任务, old_updateStock.ProductStorage, old_updateStock, "人为修改库存,操作人:" + updateData.userName + "-出库记录," + operationInfo); | 
|                         OutInStockTaskHandler.AddOutInStockTask(updateData.userName, mod, OutInStockTaskName.入库任务, updateStock.ProductStorage, updateStock, "人为修改库存,操作人:" + updateData.userName + "-入库记录," + operationInfo); | 
|   | 
|   | 
|                         int result = mod.SaveChanges(); | 
|                         if (result == 0) | 
|                         { | 
|                             //失败再保存一次 | 
|                             msg.status = 400; | 
|                             msg.total = 1; | 
|                             msg.date = null; | 
|                         } | 
|   | 
|                         else | 
|                         { | 
|                             //删除成功 | 
|                             msg.status = 200; | 
|                             msg.total = 1; | 
|                             msg.date = null; | 
|                             baseData.addOperation("", "修改库存:" + operationInfo, "修改库存"); | 
|                             logtxt.txtWrite("apitest-" + "updateProductStock-修改库存" + operationInfo, 2); | 
|                         } | 
|   | 
|                         #endregion | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msgss<string> msg = new msgss<string>(); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|   | 
|             } | 
|   | 
|         } | 
|         /// <summary>库存汇总 | 
|         /// 库存汇总 | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string findProductStock(string pages) | 
|         { | 
|             msgss<vvBase_ProductPosition> msg = new msgss<vvBase_ProductPosition>(); | 
|             try | 
|             { | 
|   | 
|                 stockSearchEntity page = JsonConvert.DeserializeObject<stockSearchEntity>(pages); | 
|   | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and InStorageDate > '" + page.datatime[0].ToString() + "' and  InStorageDate < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|   | 
|                 //根据货位名称/采购单号/托盘号/物料名称/物料编号模糊查找 | 
|   | 
|                 if (!string.IsNullOrEmpty(page.search.materialName)) | 
|                 { | 
|                     StockWhere = StockWhere + " and ProductName like '%" + page.search.materialName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialCode)) | 
|                 { | 
|                     StockWhere = StockWhere + " and ProductCode like '%" + page.search.materialCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.tranckNnmber)) | 
|                 { | 
|                     StockWhere = StockWhere + " and ExtendField04 like '%" + page.search.tranckNnmber.Trim() + "%'"; | 
|                 } | 
|                 if (page.positionTypeValue > 0) | 
|                 { | 
|                     if (page.positionTypeValue == 66) | 
|                     { | 
|                         StockWhere = StockWhere + " and PositionType=1 and IsLocked=0 and ContainerNo=0"; | 
|                     } | 
|                     else | 
|                     { | 
|                         StockWhere = StockWhere + " and PositionType=" + page.positionTypeValue.ToString(); | 
|                     } | 
|   | 
|                 } | 
|                 #endregion | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取盘点数据 | 
|                     string sql = "select * from [dbo].[" + "vvBase_ProductPosition" + "] where ProductStorage>0  " + StockWhere + " order by ProductPosition_Id desc ";//isFreeze    是否有货   先拿这个字段用  | 
|   | 
|                     List<vvBase_ProductPosition> takeStock = mod.Database.SqlQuery<vvBase_ProductPosition>(sql).ToList(); | 
|                     List<vvBase_ProductPosition> sunStockShou = new List<vvBase_ProductPosition>();//汇总后加入到集合 | 
|                     var StockGroup = takeStock.GroupBy(x => new { x.ExtendField04, x.ProductCode }).ToList();//x.SaleCode, x.ExtendField08 之前根据销售单号分组,后因为人工新建的料没有 所以改成跟踪号 | 
|                     foreach (var itemSum in StockGroup) | 
|                     { | 
|                         for (int i = 1; i < itemSum.ToList().Count; i++) | 
|                         { | 
|                             itemSum.ToList()[0].ProductStorage = itemSum.ToList()[0].ProductStorage + itemSum.ToList()[i].ProductStorage; | 
|                         } | 
|                         sunStockShou.Add(itemSum.ToList()[0]); | 
|                     } | 
|   | 
|   | 
|                     if (page.alarmValue == 1)//Brand_Id 预警值 | 
|                     { | 
|                         takeStock = sunStockShou.Where(x => x.Brand_Id > 0 && x.ProductStorage <= x.Brand_Id).ToList(); | 
|                         if (string.IsNullOrEmpty(page.search.tranckNnmber)) | 
|                         { | 
|   | 
|                             #region 添加物料里预警值搜索 | 
|   | 
|                             //查找物料里设置了预警值的 | 
|                             //  List<VmaterialInfo> warningValueName = mod.VmaterialInfo.Where(x => x.Brand_Id > 0&&).ToList(); | 
|                             string alarmValueSql = "select * from [dbo].[" + "VmaterialInfo" + "] where Brand_Id>0  "; | 
|                             if (!string.IsNullOrEmpty(page.search.materialName)) | 
|                             { | 
|                                 alarmValueSql = alarmValueSql + " and ProductName like '%" + page.search.materialName.Trim() + "%'"; | 
|                             } | 
|                             if (!string.IsNullOrEmpty(page.search.materialCode)) | 
|                             { | 
|                                 alarmValueSql = alarmValueSql + " and ProductCode like '%" + page.search.materialCode.Trim() + "%'"; | 
|                             } | 
|                             List<VmaterialInfo> warningValueName = mod.Database.SqlQuery<VmaterialInfo>(alarmValueSql).ToList(); | 
|                             List<string> warningValue = warningValueName.Select(x => x.ProductCode).ToList(); | 
|                             //查找库存里所有物料编号 | 
|                             List<string> warningValueStock = sunStockShou.Select(x => x.ProductCode).ToList(); | 
|                             //设置了预警值库存里为零的    var Toplace = rowResultSpl.Where(x => !toPlaceList.Contains(x.PositionName)).ToList(); | 
|                             List<string> zeroStock = warningValue.Where(x => !warningValueStock.Contains(x)).ToList(); | 
|                             foreach (var item in zeroStock) | 
|                             { | 
|                                 VmaterialInfo findZero = warningValueName.FirstOrDefault(x => x.ProductCode == item); | 
|                                 if (page.search.positionName != null && page.search.positionName.Trim() != "") | 
|                                 { | 
|                                     if (findZero.ProductCode.Contains(page.search.positionName.Trim()) || findZero.ProductName.Contains(page.search.positionName.Trim())) | 
|                                     { | 
|                                         vvBase_ProductPosition zeroProduct = new vvBase_ProductPosition(); | 
|                                         zeroProduct.ProductCode = item; | 
|                                         zeroProduct.ProductName = findZero.ProductName; | 
|                                         zeroProduct.ProductStorage = 0; | 
|                                         zeroProduct.SmallUnit = findZero.SmallUnit; | 
|                                         zeroProduct.Brand_Id = findZero.Brand_Id; | 
|                                         takeStock.Add(zeroProduct); | 
|                                     } | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     vvBase_ProductPosition zeroProduct = new vvBase_ProductPosition(); | 
|                                     zeroProduct.ProductCode = item; | 
|                                     zeroProduct.ProductName = findZero.ProductName; | 
|                                     zeroProduct.ProductStorage = 0; | 
|                                     zeroProduct.SmallUnit = findZero.SmallUnit; | 
|                                     zeroProduct.Brand_Id = findZero.Brand_Id; | 
|                                     takeStock.Add(zeroProduct); | 
|                                 } | 
|   | 
|                             } | 
|                             #endregion | 
|   | 
|                         } | 
|   | 
|   | 
|                     } | 
|                     else | 
|                     { | 
|                         takeStock = sunStockShou; | 
|                     } | 
|                     List<vvBase_ProductPosition> fenyeRerult = new List<vvBase_ProductPosition>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStock.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary>查询过期库存预警 【EditBy shaocx,2022-08-06】 | 
|         /// 查询过期库存预警 | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string findOldLibraryEarlyWarning(string pages) | 
|         { | 
|             msgss<vOldLibraryEarlyWarning> msg = new msgss<vOldLibraryEarlyWarning>(); | 
|             msg.roleDelete = 0; | 
|             msg.roleModifi = 0; | 
|   | 
|             try | 
|             { | 
|   | 
|                 stockSearchEntity page = JsonConvert.DeserializeObject<stockSearchEntity>(pages); | 
|                 roleMenu ROLEid = JsonConvert.DeserializeObject<roleMenu>(pages); | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|                         StockWhere = "and InStorageDate > '" + page.datatime[0].ToString() + "' and  InStorageDate < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|                 if (page.datatime_limit != null) | 
|                 { | 
|                     if (page.datatime_limit.Length == 2) | 
|                     { | 
|                         StockWhere = "and limitDate > '" + page.datatime_limit[0].ToString() + "' and  limitDate < '" + page.datatime_limit[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialName))//物料名称 | 
|                 { | 
|                     StockWhere = StockWhere + "and ProductName like '%" + page.search.materialName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialCode))//物料编号 | 
|                 { | 
|                     StockWhere = StockWhere + "and ProductCode like '%" + page.search.materialCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.placeCode))//托盘号 | 
|                 { | 
|                     StockWhere = StockWhere + "and PlateCode like '%" + page.search.placeCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.positionName))//库位名称 | 
|                 { | 
|                     StockWhere = StockWhere + "and PositionName like '%" + page.search.positionName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.purchaseCode))//采购单号 | 
|                 { | 
|                     StockWhere = StockWhere + "and PoCode like '%" + page.search.purchaseCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.tranckNnmber))//跟踪号 | 
|                 { | 
|                     StockWhere = StockWhere + "and ExtendField04 like '%" + page.search.tranckNnmber.Trim() + "%'"; | 
|                 } | 
|   | 
|                 //增加查询条件 | 
|                 if (page.search.IsLocked) | 
|                 { | 
|                     StockWhere = StockWhere + " and IsLocked=1 "; | 
|                 } | 
|                 if (page.search.ContainerNo) | 
|                 { | 
|                     StockWhere = StockWhere + " and ContainerNo='1' "; | 
|                 } | 
|                 if (page.search.IsFreeze) | 
|                 { | 
|                     StockWhere = StockWhere + " and IsFreeze=0 "; | 
|                 } | 
|                 if (page.search.OnlyLocked) | 
|                 { | 
|                     StockWhere = StockWhere + " and IsLocked=1  and ContainerNo <> '1' "; | 
|                 } | 
|   | 
|                 #endregion | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|   | 
|                     //获取盘点数据 | 
|                     //排序,按照 过期天数降序排序 | 
|                     string sql = "select * from [dbo].[" + "vOldLibraryEarlyWarning" + "] where ProductStorage>0 " + StockWhere + " order by LimitDay desc ";//isFreeze    是否有货   先拿这个字段用 InStorageDate | 
|   | 
|                     List<vOldLibraryEarlyWarning> takeStockList = mod.Database.SqlQuery<vOldLibraryEarlyWarning>(sql).ToList(); | 
|                     ////增加 显示在库天数 [EditBy shaocx,2022-06-08] | 
|                     //takeStockList = BussinessExtension.BussinessExtension.CalcInStoreDays(takeStockList.ToList()); | 
|                     ////用在库天数过滤数据  [EditBy shaocx,2022-06-08] | 
|                     //var errMsg = ""; | 
|                     //takeStockList = BussinessExtension.BussinessExtension.FiltervvBase_ProductPositionByInStoreDays(takeStockList, page, ref errMsg); | 
|                     //if (!string.IsNullOrEmpty(errMsg)) | 
|                     //{ | 
|   | 
|                     //} | 
|   | 
|                     List<vOldLibraryEarlyWarning> fenyeRerult = new List<vOldLibraryEarlyWarning>(); | 
|                     if (takeStockList.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStockList.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStockList.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStockList.Count) | 
|                             { | 
|                                 msg.date = takeStockList; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStockList.Count / a); | 
|                                 int d = takeStockList.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStockList[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|   | 
|         } | 
|   | 
|         /// <summary>查询反馈给SAP数据的记录  【EditBy shaocx,2022-02-01】 | 
|         /// 查询反馈给SAP数据的记录 | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string findSendToSapData(string pages) | 
|         { | 
|             msgss<SapSendInfo> msg = new msgss<SapSendInfo>(); | 
|             try | 
|             { | 
|   | 
|                 sendToSapDataSearchEntity page = JsonConvert.DeserializeObject<sendToSapDataSearchEntity>(pages); | 
|   | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and creatTime > '" + page.datatime[0].ToString() + "' and  creatTime < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|   | 
|                 //根据货位名称/采购单号/托盘号/物料名称/物料编号模糊查找 | 
|   | 
|   | 
|                 if (!string.IsNullOrEmpty(page.search.materialCode)) | 
|                 { | 
|                     StockWhere = StockWhere + " and MaterialCode like '%" + page.search.materialCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialName)) | 
|                 { | 
|                     StockWhere = StockWhere + " and MaterialName like '%" + page.search.materialName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.SalesOrder)) | 
|                 { | 
|                     StockWhere = StockWhere + " and SalesOrder like '%" + page.search.SalesOrder.Trim() + "%'"; | 
|                 } | 
|   | 
|                 if (!string.IsNullOrEmpty(page.positionTypeValue)) | 
|                 { | 
|                     StockWhere = StockWhere + " and moveType=" + page.positionTypeValue.ToString(); | 
|                 } | 
|                 #endregion | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取数据 | 
|                     string sql = "select * from [dbo].[" + "SapSendInfo" + "] where 1=1  " + StockWhere + " order by id desc "; | 
|   | 
|                     List<SapSendInfo> takeStock = mod.Database.SqlQuery<SapSendInfo>(sql).ToList(); | 
|   | 
|                     List<SapSendInfo> fenyeRerult = new List<SapSendInfo>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStock.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|   | 
|         /// <summary>查询反馈给SAP数据失败的记录  【EditBy shaocx,2022-03-06】 | 
|         /// 查询反馈给SAP数据失败的记录 | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string findSendToSapFailData(string pages) | 
|         { | 
|             msgss<SapSendFailRecodInfo> msg = new msgss<SapSendFailRecodInfo>(); | 
|             try | 
|             { | 
|   | 
|                 sendToSapDataFailSearchEntity page = JsonConvert.DeserializeObject<sendToSapDataFailSearchEntity>(pages); | 
|   | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and creatTime > '" + page.datatime[0].ToString() + "' and  creatTime < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|   | 
|                 //根据货位名称/采购单号/托盘号/物料名称/物料编号模糊查找 | 
|   | 
|   | 
|                 if (!string.IsNullOrEmpty(page.search.materialCode)) | 
|                 { | 
|                     StockWhere = StockWhere + " and MaterialCode like '%" + page.search.materialCode.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.materialName)) | 
|                 { | 
|                     StockWhere = StockWhere + " and MaterialName like '%" + page.search.materialName.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.SalesOrder)) | 
|                 { | 
|                     StockWhere = StockWhere + " and SalesOrder like '%" + page.search.SalesOrder.Trim() + "%'"; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.search.purchaseCode)) | 
|                 {//采购单号 | 
|                     StockWhere = StockWhere + " and pocode = '" + page.search.purchaseCode.Trim() + "'"; | 
|                 } | 
|   | 
|                 if (!string.IsNullOrEmpty(page.positionTypeValue)) | 
|                 { | 
|                     StockWhere = StockWhere + " and MoveType=" + page.positionTypeValue.ToString(); | 
|                 } | 
|                 #endregion | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取数据 | 
|                     string sql = "select * from [dbo].[" + "SapSendFailRecodInfo" + "] where 1=1  " + StockWhere + " order by id desc "; | 
|   | 
|                     List<SapSendFailRecodInfo> takeStock = mod.Database.SqlQuery<SapSendFailRecodInfo>(sql).ToList(); | 
|   | 
|                     List<SapSendFailRecodInfo> fenyeRerult = new List<SapSendFailRecodInfo>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStock.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|   | 
|   | 
|         /// <summary>手动出库查找库存 | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="pages">jison参数</param> | 
|         /// <returns></returns> | 
|         public string handfindProductStock(string pages) | 
|         { | 
|             msgss<vvBase_ProductPosition> msg = new msgss<vvBase_ProductPosition>(); | 
|             try | 
|             { | 
|   | 
|                 productStockEntity page = JsonConvert.DeserializeObject<productStockEntity>(pages); | 
|   | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and InStorageDate > '" + page.datatime[0].ToString() + "' and  InStorageDate < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|   | 
|                 //根据货位名称/采购单号/托盘号/物料名称/物料编号模糊查找 | 
|                 if (page.positionName.Trim() != "") | 
|                 { | 
|                     string[] paparms = page.positionName.Trim().Split('/'); | 
|   | 
|                     if (paparms[2].Trim() != "") | 
|                     { | 
|                         StockWhere = StockWhere + " and (ProductName like '%" + paparms[2].Trim() + "%' or ProductCode like '%" + paparms[2].Trim() + "%')"; | 
|                     } | 
|                     StockWhere = paparms[1].Trim() == "" ? StockWhere : StockWhere + " and ExtendField04 = '" + paparms[1].Trim() + "'"; | 
|                     StockWhere = paparms[0].Trim() == "" ? StockWhere : StockWhere + " and positionName = '" + paparms[0].Trim() + "'"; | 
|                     // StockWhere = StockWhere + " and (ProductName like '%" + ProductName + "%' or ProductCode like '%" + ProductCode + "%' or ExtendField04='" + trackNumber + "')"; | 
|                 } | 
|   | 
|                 if (page.positionTypeValue > 0) | 
|                 { | 
|                     if (page.positionTypeValue == 66) | 
|                     { | 
|                         StockWhere = StockWhere + " and PositionType=1 and IsLocked=0 and ContainerNo=0"; | 
|                     } | 
|                     else | 
|                     { | 
|                         StockWhere = StockWhere + " and PositionType=" + page.positionTypeValue.ToString(); | 
|                     } | 
|   | 
|                 } | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取盘点数据 | 
|                     string sql = "select * from [dbo].[" + "vvBase_ProductPosition" + "] where ProductStorage>0  " + StockWhere + " order by ProductPosition_Id desc ";//isFreeze    是否有货   先拿这个字段用  | 
|   | 
|                     List<vvBase_ProductPosition> takeStock = mod.Database.SqlQuery<vvBase_ProductPosition>(sql).ToList(); | 
|                     List<vvBase_ProductPosition> sunStockShou = new List<vvBase_ProductPosition>();//汇总后加入到集合 | 
|                     var StockGroup = takeStock.GroupBy(x => new { x.ExtendField04, x.ProductCode }).ToList();//x.SaleCode, x.ExtendField08 之前根据销售单号分组,后因为人工新建的料没有 所以改成跟踪号 | 
|                     foreach (var itemSum in StockGroup) | 
|                     { | 
|                         for (int i = 1; i < itemSum.ToList().Count; i++) | 
|                         { | 
|                             itemSum.ToList()[0].ProductStorage = itemSum.ToList()[0].ProductStorage + itemSum.ToList()[i].ProductStorage; | 
|                         } | 
|                         sunStockShou.Add(itemSum.ToList()[0]); | 
|                     } | 
|   | 
|   | 
|                     if (page.alarmValue == 1)//Brand_Id 预警值 | 
|                     { | 
|                         takeStock = sunStockShou.Where(x => x.Brand_Id > 0 && x.ProductStorage <= x.Brand_Id).ToList(); | 
|                     } | 
|                     else | 
|                     { | 
|                         takeStock = sunStockShou; | 
|                     } | 
|                     List<vvBase_ProductPosition> fenyeRerult = new List<vvBase_ProductPosition>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         // msg.date = takeStock; | 
|   | 
|                         //假如每页数量 大于盘点数据 | 
|                         if (page.queryInfo.pagesize > takeStock.Count) | 
|                         { | 
|                             msg.date = takeStock; | 
|                         } | 
|                         else | 
|                         { | 
|                             #region 分页计算 | 
|                             int a = page.queryInfo.pagesize; | 
|   | 
|                             int b = page.queryInfo.pagenum; | 
|                             int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                             int d = takeStock.Count % a; | 
|                             int e = 0; | 
|                             int f = a * (b - 1); | 
|                             if (d != 0 && b == c) | 
|                             { | 
|                                 e = d + f; | 
|   | 
|                             } | 
|                             else | 
|                             { | 
|                                 e = a + f; | 
|                             } | 
|   | 
|   | 
|   | 
|                             for (int i = f; i < e; i++) | 
|                             { | 
|                                 fenyeRerult.Add(takeStock[i]); | 
|                             } | 
|                             msg.date = fenyeRerult; | 
|                             #endregion | 
|   | 
|                         } | 
|   | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary>删除库存 | 
|         /// 删除库存 | 
|         /// </summary> | 
|         /// <param name="deleteId">库存ID</param> | 
|         /// <returns></returns> | 
|         public string DeleteProductStock(int deleteId, string userName) | 
|         { | 
|             try | 
|             { | 
|   | 
|                 msgss<string> msg = new msgss<string>(); | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     if (deleteId < 1) | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|                     else | 
|                     { | 
|   | 
|                         Base_ProductPosition deleteStock = mod.Base_ProductPosition.Find(deleteId); | 
|                         if (deleteStock != null) | 
|                         { | 
|                             List<Base_ProductPosition> deleteStocks = mod.Base_ProductPosition.Where(x => x.PositionName == deleteStock.PositionName).ToList(); | 
|                             //只有一条库存的时候不可以删,删了托盘就出不来了 | 
|                             #region 删除操作 | 
|                             if (deleteStocks.Count == 1) | 
|                             { | 
|                                 msg.status = 500; | 
|                                 msg.total = 1; | 
|                                 msg.date = null; | 
|                             } | 
|                             else | 
|                             { | 
|                                 mod.Base_ProductPosition.Remove(deleteStock); | 
|                                 //增加出入库记录 【EditBy shaocx,2022-03-07】 | 
|                                 OutInStockTaskHandler.AddOutInStockTask(userName, mod, OutInStockTaskName.清库任务, deleteStock.ProductStorage, deleteStock, "操作人:" + userName + ",删除库存,清空库存"); | 
|                                 int result = mod.SaveChanges(); | 
|                                 if (result == 0) | 
|                                 { | 
|                                     //失败再保存一次 | 
|                                     msg.status = 550; | 
|                                     msg.total = 1; | 
|                                     msg.date = null; | 
|                                 } | 
|   | 
|                                 else | 
|                                 { | 
|                                     //删除成功 | 
|                                     msg.status = 200; | 
|                                     msg.total = 1; | 
|                                     msg.date = null; | 
|                                     baseData.addOperation("", "库存明细-删除库存:" + deleteStock.PositionName + "物料名称:" + deleteStock.ProductCode, "删除库存"); | 
|                                     logtxt.txtWrite("apitest-" + "库存明细-删除库存" + deleteStock.PositionName + "物料名称:" + deleteStock.ProductCode, 2); | 
|                                 } | 
|   | 
|                             } | 
|                             #endregion | 
|                         } | 
|                     } | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msgss<string> msg = new msgss<string>(); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|   | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary>移库 | 
|         /// 移库 | 
|         /// </summary> | 
|         /// <param name="positionName">库位名称</param> | 
|         /// <returns></returns> | 
|         public string moveStock(string positionName, string username) | 
|         { | 
|             //移库直接返回错误 【EditBy shaocx,2022-09-22】 | 
|             msgss<string> msg3 = new msgss<string>(); | 
|             msg3.status = 400; | 
|             msg3.total = 1; | 
|             msg3.date = null; | 
|             return JsonConvert.SerializeObject(msg3); | 
|   | 
|             //try | 
|             //{ | 
|             //    positionName = positionName.Trim(); | 
|             //    msgss<string> msg = new msgss<string>(); | 
|             //    if (string.IsNullOrEmpty(positionName.Trim()))//判断库位是否为空 | 
|             //    { | 
|             //        msg.status = 400; | 
|             //        msg.total = 1; | 
|             //        msg.date = null; | 
|             //        return JsonConvert.SerializeObject(msg); | 
|             //    } | 
|             //    string[] positionname = positionName.Trim().Split('-'); | 
|             //    string sourcePlace = ""; | 
|             //    int areaCode = 0; | 
|             //    if (positionname.Length != 4)//判断是否是库位格式 | 
|             //    { | 
|             //        msg.status = 400; | 
|             //        msg.total = 1; | 
|             //        msg.date = null; | 
|             //        return JsonConvert.SerializeObject(msg); | 
|             //    } | 
|             //    sourcePlace = positionname[1] + "-" + positionname[2] + "-" + positionname[3];//其实地址 | 
|             //    areaCode = Convert.ToInt32(positionname[0]);//库区 | 
|             //    if (areaCode != 1 && areaCode != 2)//重复判断库区格式 | 
|             //    { | 
|             //        msg.status = 400; | 
|             //        msg.total = 1; | 
|             //        msg.date = null; | 
|             //        return JsonConvert.SerializeObject(msg); | 
|             //    } | 
|             //    int layer = Convert.ToInt32(positionname[3]);//当前层 | 
|             //    string toplace = ""; | 
|             //    // Form1 form = new Form1(); | 
|             //    using (dbModel mod = new dbModel()) | 
|             //    { | 
|             //        List<Base_ProductPosition> deleteStocks = mod.Base_ProductPosition.Where(x => x.PositionName == positionName).ToList(); | 
|             //        //锁定状态不允许移库 | 
|             //        Base_Position deleteStockisLock = mod.Base_Position.FirstOrDefault(x => x.PositionName == positionName && x.IsLocked == 0); | 
|             //        if (deleteStockisLock == null) | 
|             //        { | 
|             //            msg.status = 400; | 
|             //            msg.total = 1; | 
|             //            msg.date = null; | 
|             //            return JsonConvert.SerializeObject(msg); | 
|             //        } | 
|             //        int plateType = 0;//托盘类型 | 
|             //        #region 判断操作 | 
|             //        if (deleteStocks.Count < 1)//判断这个库位有没有信息 | 
|             //        { | 
|             //            msg.status = 400; | 
|             //            msg.total = 1; | 
|             //            msg.date = null; | 
|             //            return JsonConvert.SerializeObject(msg); | 
|             //        } | 
|   | 
|             //        bool convertSucceed = Int32.TryParse(deleteStocks[0].PlateType, out plateType); | 
|             //        if (!convertSucceed)//盘点托盘类型转换是否成功 | 
|             //        { | 
|             //            msg.status = 400; | 
|             //            msg.total = 1; | 
|             //            msg.date = null; | 
|             //            return JsonConvert.SerializeObject(msg); | 
|             //        } | 
|             //        #endregion | 
|   | 
|             //        int containterHeight = 0;//托盘高度类型 | 
|   | 
|             //        #region 判断高度类型 | 
|   | 
|             //        //2号库小库位 | 
|             //        //1-11   高度4 | 
|             //        //3,5,7,9,10  高度3 | 
|             //        //2,4,6,8,  高度1 | 
|             //        //2号库大托盘 | 
|             //        //1,13,14  高度4 | 
|             //        //2           高度3 | 
|             //        //6,9,12    高度2 | 
|             //        //4,5,7,8,10,11 高度1 | 
|             //        if (areaCode == 1)//1号库区都是库位 | 
|             //        { | 
|             //            if (layer == 1 || layer == 11) | 
|             //            { | 
|             //                containterHeight = 2; | 
|             //            } | 
|             //            else | 
|             //            { | 
|             //                containterHeight = 1; | 
|             //            } | 
|             //        } | 
|             //        else | 
|             //        { | 
|             //            if (plateType == 1)//2号库区小库位 | 
|             //            { | 
|             //                #region 2号库区小库位 | 
|             //                if (layer == 1 || layer == 11) | 
|             //                { | 
|             //                    containterHeight = 4; | 
|             //                } | 
|             //                else if (layer == 3 || layer == 5 || layer == 7 || layer == 9 || layer == 10) | 
|             //                { | 
|             //                    containterHeight = 3; | 
|             //                } | 
|             //                else | 
|             //                { | 
|             //                    containterHeight = 1; | 
|             //                } | 
|             //                #endregion | 
|   | 
|             //            } | 
|             //            else//2号库区大库位 | 
|             //            { | 
|             //                #region 2号库区大库位 | 
|             //                if (layer == 1 || layer == 13 || layer == 14) | 
|             //                { | 
|             //                    containterHeight = 4; | 
|             //                } | 
|             //                else if (layer == 2) | 
|             //                { | 
|             //                    containterHeight = 3; | 
|             //                } | 
|             //                else if (layer == 6 || layer == 9 || layer == 12) | 
|             //                { | 
|             //                    containterHeight = 2; | 
|             //                } | 
|             //                else | 
|             //                { | 
|             //                    containterHeight = 1; | 
|             //                } | 
|             //                #endregion | 
|   | 
|             //            } | 
|             //        } | 
|             //        #endregion | 
|             //        var findEmptyReason = ""; | 
|             //        bool isInMoreHighPosition = false; | 
|             //        toplace = FindEmptyLocationHandler.findStorage("", true, ref isInMoreHighPosition, ref findEmptyReason, areaCode, Convert.ToInt32(deleteStocks[0].PlateType), containterHeight);//分配库位 | 
|   | 
|             //        #region 写入任务表 | 
|             //        Task_Queue addTask = new Task_Queue(); | 
|             //        addTask.BillCode = "移库";//来源单号 | 
|             //        addTask.TaskType = ((int)TaskTypeEnum.移库).ToString(); | 
|             //        addTask.PlateType = deleteStocks[0].PlateType;//器具种类-大托盘小托盘 | 
|             //        addTask.PlateCode = deleteStocks[0].PlateCode;//母托盘编号 | 
|             //        addTask.Bill_Id = 0;// 单据id | 
|             //        addTask.OrderNumber = 0;//任务执行优先级 | 
|             //        addTask.TaskStatus = "未下发";//任务状态 | 
|             //        addTask.FromPositionName = sourcePlace;//起始地址 | 
|             //        addTask.ToPositionName = toplace;//目标地址给空返回测量高度后重新写入 | 
|             //        addTask.Direction = areaCode == 1 ? "2" : "4";//出库不需要托盘高度 | 
|             //        addTask.DoCount = areaCode;//库区 | 
|             //        addTask.CreateDate = DateTime.Now; | 
|             //        addTask.UserProduct_Id = 1007;//账套id 老谢bug   | 
|             //        mod.Task_Queue.Add(addTask); | 
|   | 
|             //        #endregion | 
|   | 
|             //        //添加日志 | 
|             //        SystemHelper.addOperation(username, "移库:从" + positionName + "到" + toplace, "移库"); | 
|   | 
|             //        int result = mod.SaveChanges(); | 
|             //        #region 失败再保存一次 | 
|             //        if (result == 0)//失败再保存一次 | 
|             //        { | 
|             //            result = mod.SaveChanges(); | 
|             //            if (result == 0) | 
|             //            { | 
|             //                //返回失败 | 
|             //                msg.status = 400; | 
|             //                msg.total = 1; | 
|             //                msg.date = null; | 
|             //            } | 
|             //            else | 
|             //            { | 
|             //                //删除成功 | 
|             //                msg.status = 200; | 
|             //                msg.total = 1; | 
|             //                msg.date = null; | 
|             //            } | 
|             //        } | 
|   | 
|             //        else | 
|             //        { | 
|             //            //删除成功 | 
|             //            msg.status = 200; | 
|             //            msg.total = 1; | 
|             //            msg.date = null; | 
|             //        } | 
|             //        #endregion | 
|   | 
|             //        return JsonConvert.SerializeObject(msg); | 
|             //    } | 
|             //} | 
|             //catch (Exception ex) | 
|             //{ | 
|             //    logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|             //    msgss<string> msg = new msgss<string>(); | 
|             //    msg.status = 400; | 
|             //    msg.total = 1; | 
|             //    msg.date = null; | 
|             //    return JsonConvert.SerializeObject(msg); | 
|   | 
|             //} | 
|   | 
|         } | 
|   | 
|         /// <summary>大屏综合信息 | 
|         /// 大屏综合信息 | 
|         /// </summary> | 
|         /// <param name="startTime"></param> | 
|         /// <param name="endTime"></param> | 
|         /// <returns></returns> | 
|         public string getDeviceInfo(string startTime, string endTime) | 
|         { | 
|             string result = ""; | 
|             try | 
|             { | 
|                 int[] list1 = totalInfo.list11; | 
|                 string[] list2 = totalInfo.list22; | 
|                 List<sendDeviceStatus> data = new List<sendDeviceStatus>(); | 
|                 sendDeviceStatus runStatus = new sendDeviceStatus(); | 
|                 runStatus.name = "设备运行时间"; | 
|                 sendDeviceStatus waitStatus = new sendDeviceStatus(); | 
|                 waitStatus.name = "设备等待时间"; | 
|                 sendDeviceStatus alarmStatus = new sendDeviceStatus(); | 
|                 alarmStatus.name = "设备报警时间"; | 
|                 List<string> xdata = new List<string>(); | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     DateTime _startTime = Convert.ToDateTime(startTime); | 
|                     DateTime _endTime = Convert.ToDateTime(endTime); | 
|                     List<deviceGeneralInfo> fiveDayDeviceInfo = mod.deviceGeneralInfo.Where(x => x.createTime >= _startTime && x.createTime <= _endTime).OrderByDescending(x => x.createTime) | 
|                         //.Take(5) | 
|                         .ToList(); | 
|                     if (fiveDayDeviceInfo.Count > 0) | 
|                     { | 
|   | 
|                         foreach (var item in fiveDayDeviceInfo) | 
|                         { | 
|                             runStatus.xdata.Add(item.deviceRunTime.ToString() == null ? "0" : item.deviceRunTime.ToString()); | 
|                             waitStatus.xdata.Add(item.deviceWaitTime.ToString() == null ? "0" : item.deviceWaitTime.ToString()); | 
|                             alarmStatus.xdata.Add(item.deviceAlarmTime.ToString() == null ? "0" : item.deviceAlarmTime.ToString()); | 
|                             xdata.Add(item.createTime.ToString().Split(' ')[0]); | 
|                         } | 
|   | 
|                     } | 
|   | 
|                 } | 
|                 data.Add(runStatus); | 
|                 data.Add(waitStatus); | 
|                 string[] legend = { "p设备运行时间", "p设备等待时间", "p设备异常时间" }; | 
|                 var workpiece = new | 
|                  { | 
|                      data, | 
|                      legend, | 
|                      xdata | 
|   | 
|                  }; | 
|                 data.Add(alarmStatus); | 
|                 var date = new | 
|                 { | 
|                     list1, | 
|                     list2, | 
|                     workpiece | 
|   | 
|                 }; | 
|                 result = JsonConvert.SerializeObject(date); | 
|                 return result; | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名:Form1/函数名:writeOutTask出库写入任务异常/ " + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 return result; | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary>2d动画获取设备位置 | 
|         /// 2d动画获取设备位置 | 
|         /// </summary> | 
|         /// <returns></returns> | 
|         public int[] getDevicePosition(string param) | 
|         { | 
|   | 
|             try | 
|             { | 
|   | 
|                 //form.textBox3.Text= deviceListInfo.rgv1.position.ToString(); | 
|                 //form.textBox4.Text=deviceListInfo.rgv2.position.ToString(); | 
|                 //form.textBox8.Text= deviceListInfo.srm1.position.ToString(); | 
|                 //form.textBox9.Text=deviceListInfo.srm2.position.ToString(); | 
|   | 
|                 // int rgv1= form.textBox3.Text==""?0:Convert.ToInt32(form.textBox3.Text) | 
|                 int[] datelist =  | 
|                 { | 
|                   deviceListInfo.rgv1.position, | 
|                   deviceListInfo.rgv2.position, | 
|                   deviceListInfo.srm1.position, | 
|                   deviceListInfo.srm2.position, | 
|                   totalInfo.list11[0], | 
|                   totalInfo.list11[1] | 
|                   //form.textBox3.Text==""?0:Convert.ToInt32(form.textBox3.Text), | 
|                   //form.textBox4.Text==""?0:Convert.ToInt32(form.textBox4.Text), | 
|                   //form.textBox8.Text==""?0:Convert.ToInt32(form.textBox8.Text), | 
|                   //form.textBox9.Text==""?0:Convert.ToInt32(form.textBox9.Text), | 
|                   //form.textBox10.Text==""?0:Convert.ToInt32(form.textBox10.Text), | 
|                   //form.textBox11.Text==""?0:Convert.ToInt32(form.textBox11.Text) | 
|                 }; | 
|   | 
|                 return datelist; | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名:Form1/函数名:getDevicePosition动画获取设备位置/ " + ex.Message + "出错行号" + ex.StackTrace.ToString(), 2); | 
|                 int[] datelist = { 0, 0, 0, 0, 0, 0 }; | 
|                 return datelist; | 
|             } | 
|   | 
|         } | 
|         /// <summary>出库看板信息 | 
|         /// 出库看板信息 | 
|         /// </summary> | 
|         /// <returns></returns> | 
|         public string outStockTaskList(string takes) | 
|         { | 
|             outStockList outList3 = new outStockList();//3号出口 | 
|             outList3.title = "3号出口"; | 
|             outStockList outList2 = new outStockList();//2号出口 | 
|             outList2.title = "2号出口"; | 
|             outStockList outList1 = new outStockList();//1号出口 | 
|             outList1.title = "1号出口"; | 
|             DateTime nowTime = DateTime.Now; | 
|             try | 
|             { | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     List<Task_Queue> outStockTask = mod.Task_Queue.Where(x => x.TaskType == "4" && x.TaskStatus == "已下发").OrderBy(x => x.CreateDate).ToList(); | 
|                     var taskOrderBY = outStockTask.GroupBy(x => x.ToPositionName); | 
|                     foreach (var item in taskOrderBY) | 
|                     { | 
|   | 
|                         switch (item.ToList()[0].ToPositionName) | 
|                         { | 
|   | 
|   | 
|                             case "1008": | 
|                                 #region 3号出口 | 
|   | 
|                                 outList3.total = item.ToList().Count(); | 
|                                 foreach (var itemList in item.ToList()) | 
|                                 { | 
|                                     OutDatas outInfo1 = new OutDatas(); | 
|                                     string plateCode = itemList.PlateCode; | 
|                                     outInfo1.userTrueName = itemList.BillCode;//出库单号 | 
|                                     List<Base_ProductPosition> outQyt = mod.Base_ProductPosition.Where(x => x.PlateCode == plateCode && (x.ContainerNo != "0" || x.ContainerNo != "")).ToList(); | 
|                                     var outTime = nowTime - (DateTime)itemList.CreateDate; | 
|                                     int outtime = outTime.Days * 24 * 60 + outTime.Hours * 60 + outTime.Minutes; | 
|                                     outInfo1.roleName = outtime.ToString(); | 
|                                     outInfo1.deptName = outQyt.Count;//一个托盘里出库物料种类数 | 
|                                     outList3.tableData.Add(outInfo1); | 
|                                 } | 
|                                 #endregion | 
|                                 break; | 
|                             case "1003": | 
|                                 #region 2号出口 | 
|   | 
|                                 outList2.total = item.ToList().Count(); | 
|                                 foreach (var itemList in item.ToList()) | 
|                                 { | 
|                                     OutDatas outInfo1 = new OutDatas(); | 
|                                     string plateCode = itemList.PlateCode; | 
|                                     outInfo1.userTrueName = itemList.BillCode;//出库单号 | 
|                                     List<Base_ProductPosition> outQyt = mod.Base_ProductPosition.Where(x => x.PlateCode == plateCode && (x.ContainerNo != "0" || x.ContainerNo != "")).ToList(); | 
|                                     var outTime = nowTime - (DateTime)itemList.CreateDate; | 
|                                     int outtime = outTime.Days * 24 * 60 + outTime.Hours * 60 + outTime.Minutes; | 
|                                     outInfo1.roleName = outtime.ToString(); | 
|                                     outInfo1.deptName = outQyt.Count;//一个托盘里出库物料种类数 | 
|                                     outList2.tableData.Add(outInfo1); | 
|                                 } | 
|                                 #endregion | 
|   | 
|                                 break; | 
|                             case "1001": | 
|                                 #region 1号出口 | 
|   | 
|                                 outList1.total = item.ToList().Count(); | 
|                                 foreach (var itemList in item.ToList()) | 
|                                 { | 
|                                     OutDatas outInfo1 = new OutDatas(); | 
|                                     string plateCode = itemList.PlateCode; | 
|                                     outInfo1.userTrueName = itemList.BillCode;//出库单号 | 
|                                     List<Base_ProductPosition> outQyt = mod.Base_ProductPosition.Where(x => x.PlateCode == plateCode && (x.ContainerNo != "0" || x.ContainerNo != "")).ToList(); | 
|                                     var outTime = nowTime - (DateTime)itemList.CreateDate; | 
|                                     int outtime = outTime.Days * 24 * 60 + outTime.Hours * 60 + outTime.Minutes; | 
|                                     outInfo1.roleName = outtime.ToString(); | 
|                                     outInfo1.deptName = outQyt.Count;//一个托盘里出库物料种类数 | 
|                                     outList1.tableData.Add(outInfo1); | 
|                                 } | 
|                                 #endregion | 
|   | 
|                                 break; | 
|                         } | 
|   | 
|                     } | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|   | 
|             } | 
|             var outList = new | 
|             { | 
|                 outList3, | 
|                 outList2, | 
|                 outList1 | 
|             }; | 
|             return JsonConvert.SerializeObject(outList); | 
|         } | 
|         /// <summary>入库看板信息 | 
|         /// 入库看板信息 | 
|         /// </summary> | 
|         /// <param name="takes"></param> | 
|         /// <returns></returns> | 
|         public string inStockTask(string takes) | 
|         { | 
|             List<OutDatas> inTaskListInfo = new List<OutDatas>(); | 
|             inTaskDatas bigInStock = new inTaskDatas(); | 
|             bigInStock.title = "2号入口-大托盘"; | 
|             inTaskDatas smallInStock = new inTaskDatas(); | 
|             smallInStock.title = "1号入口-小托盘"; | 
|             DateTime nowTime = DateTime.Now; | 
|             try | 
|             { | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     List<Task_Queue> outStockTask = mod.Task_Queue.Where(x => x.TaskType == "1" && (x.TaskStatus == "已下发" || x.TaskStatus == "下发中")).OrderBy(x => x.CreateDate).ToList(); | 
|                     if (outStockTask.Count > 0) | 
|                     { | 
|                         #region 获取大托盘入库明细 | 
|   | 
|                         Task_Queue bigTask = outStockTask.FirstOrDefault(x => x.PlateType == "2"); | 
|   | 
|                         if (bigTask != null) | 
|                         { | 
|                             List<Purchase_ShelveList> inTaskListBig = mod.Purchase_ShelveList.Where(x => x.Shelve_Id == bigTask.Bill_Id).ToList(); | 
|                             if (inTaskListBig.Count > 0) | 
|                             { | 
|                                 foreach (var item in inTaskListBig) | 
|                                 { | 
|                                     inTaskDataList datalist = new inTaskDataList(); | 
|                                     datalist.materialCode = item.ProductCode; | 
|                                     datalist.materialName = item.ProductName; | 
|                                     datalist.quantity = (decimal)item.Quantity; | 
|                                     bigInStock.dataList.Add(datalist); | 
|   | 
|                                 } | 
|   | 
|                             } | 
|   | 
|                         } | 
|   | 
|                         #endregion | 
|                         #region 获取小托盘入库明细 | 
|                         Task_Queue smallTask = outStockTask.FirstOrDefault(x => x.PlateType == "1"); | 
|   | 
|                         if (smallTask != null) | 
|                         { | 
|                             List<Purchase_ShelveList> inTaskListSmall = mod.Purchase_ShelveList.Where(x => x.Shelve_Id == smallTask.Bill_Id).ToList(); | 
|                             if (inTaskListSmall.Count > 0) | 
|                             { | 
|                                 foreach (var item in inTaskListSmall) | 
|                                 { | 
|                                     inTaskDataList datalist = new inTaskDataList(); | 
|                                     datalist.materialCode = item.ProductCode; | 
|                                     datalist.materialName = item.ProductName; | 
|                                     datalist.quantity = (decimal)item.Quantity; | 
|                                     smallInStock.dataList.Add(datalist); | 
|   | 
|                                 } | 
|   | 
|                             } | 
|   | 
|   | 
|                         } | 
|                         #endregion | 
|   | 
|                         #region 获取入库列表 | 
|                         if (outStockTask.Count > 0) | 
|                         { | 
|                             foreach (var item in outStockTask) | 
|                             { | 
|                                 List<Purchase_ShelveList> inTaskList = mod.Purchase_ShelveList.Where(x => x.Shelve_Id == item.Bill_Id).ToList(); | 
|                                 if (inTaskList.Count > 0) | 
|                                 { | 
|   | 
|                                     var EnterTime = nowTime - (DateTime)inTaskList[0].CreateDate; | 
|                                     int enterTime = EnterTime.Days * 24 * 60 + EnterTime.Hours * 60 + EnterTime.Minutes; | 
|                                     OutDatas addData = new OutDatas(); | 
|                                     addData.deptName = inTaskList.Count; | 
|                                     addData.roleName = enterTime.ToString(); | 
|                                     addData.userTrueName = item.BillCode; | 
|                                     inTaskListInfo.Add(addData); | 
|                                 } | 
|                             } | 
|                         } | 
|                         #endregion | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|             } | 
|             var boardlist = new { bigInStock, smallInStock }; | 
|   | 
|             var data = new | 
|             { | 
|                 inTaskListInfo, | 
|                 boardlist | 
|   | 
|             }; | 
|             return JsonConvert.SerializeObject(data); | 
|         } | 
|         /// <summary>创建拼盘出库任务 | 
|         /// 创建拼盘出库任务 | 
|         /// </summary> | 
|         /// <param name="containerCode">托盘高度</param> | 
|         public void madeDish(string containerCode, string creator) | 
|         { | 
|             string[] containerNo = containerCode.Trim().Split('-'); | 
|   | 
|             if (containerNo.Length != 4) | 
|             { | 
|                 return; | 
|             } | 
|             try | 
|             { | 
|                 var _PlateCode = ""; | 
|                 //写入任务列表Task_Queue | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //判断是否有闲时移库任务在执行 [EditBy shaocx,2022-09-22] | 
|                     var isExistRuningTask = FreeTimeMoveLocationTaskHandler.IsExistRuningTask(mod); | 
|                     if (isExistRuningTask) | 
|                     { | 
|                         return; | 
|                     } | 
|   | 
|                     Base_Position Position = mod.Base_Position.FirstOrDefault(x => x.PositionName == containerCode && x.IsLocked == 0); | 
|                     if (Position != null) | 
|                     { | 
|                         List<Base_ProductPosition> productPositionList = mod.Base_ProductPosition.Where(x => x.PositionName == containerCode).ToList(); | 
|                         if (productPositionList.Count < 1) | 
|                         { | 
|                             logtxt.txtWrite("类名:taskApi,函数名:madeDish  Base_ProductPosition组盘出库 找不到库位数据:" + containerCode, 2); | 
|                             return; | 
|                         } | 
|                         _PlateCode = productPositionList.FirstOrDefault().PlateCode; | 
|                         foreach (var itemRemove in productPositionList) | 
|                         { | 
|                             mod.Base_ProductPosition.Remove(itemRemove); | 
|                             //增加出入库记录 【EditBy shaocx,2022-03-07】 | 
|                             OutInStockTaskHandler.AddOutInStockTask(creator, mod, OutInStockTaskName.清库任务, itemRemove.ProductStorage, itemRemove, "拼盘,清空库存"); | 
|                         } | 
|                         //Position.IsFreeze = 0; | 
|                         Position.IsFreeze = (int)IsFreezeEnum.无货; | 
|                         Position.IsLocked = 1; | 
|                         Position.Remark = "拼盘-锁定库位!"; | 
|                         Position.PositionType = 0; | 
|                         Position.PositionLength = 0; | 
|                     } | 
|                     else | 
|                     { | 
|                         logtxt.txtWrite("类名:taskApi,函数名:madeDish  组盘出库 Position找不到库位数据或者被锁定:" + containerCode, 2); | 
|                         return; | 
|                     } | 
|                     string sourcePlace = containerNo[1] + "-" + containerNo[2] + "-" + containerNo[3]; | 
|                     int areaCode = Convert.ToInt32(containerNo[0].Trim()); | 
|                     string toPlace = ""; | 
|                     int PlateType = 0; | 
|                     if (areaCode != 1 && areaCode != 2) | 
|                     { | 
|                         return; | 
|                     } | 
|                     if (areaCode == 1) | 
|                     { | 
|                         toPlace = "1021"; | 
|                         PlateType = 1; | 
|                     } | 
|                     else | 
|                     { | 
|   | 
|                         if (Convert.ToInt32(containerNo[2]) > 1 && Convert.ToInt32(containerNo[2]) < 10) | 
|                         { | 
|                             toPlace = "1021"; | 
|                             PlateType = 1; | 
|                         } | 
|                         else | 
|                         { | 
|                             toPlace = "1026"; | 
|                             PlateType = 2; | 
|                         } | 
|                     } | 
|                     Task_Queue CallContainerTaks = new Task_Queue(); | 
|                     CallContainerTaks.TaskType = ((int)TaskTypeEnum.组盘出库).ToString();//任务类型 | 
|                     CallContainerTaks.OrderNumber = 0;//任务权重 | 
|                     CallContainerTaks.PlateCode = _PlateCode;//托盘号 | 
|                     CallContainerTaks.TaskStatus = "未下发";//任务状态 | 
|                     CallContainerTaks.PlateType = PlateType.ToString();//托盘类型 | 
|                     CallContainerTaks.CreateDate = DateTime.Now; | 
|                     CallContainerTaks.Creator = creator; | 
|                     CallContainerTaks.UserProduct_Id = 1007;//账套id 老谢bug   | 
|                     //垃圾值都赋值0 转到autoTask()里有说明 | 
|                     CallContainerTaks.FromPositionName = sourcePlace; | 
|                     CallContainerTaks.ToPositionName = toPlace; | 
|                     CallContainerTaks.DoCount = areaCode;//库区 | 
|                     CallContainerTaks.Direction = "0";//托盘高度 | 
|                     mod.Task_Queue.Add(CallContainerTaks); | 
|                     mod.SaveChanges(); | 
|                     logtxt.txtWrite("类名:taskApi,函数名:madeDish  组盘出库 库位:" + containerCode, 0); | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名:taskApi/函数名:madeDish组盘出库/ 库位:" + containerCode + logtxt.oneRow(ex.ToString()), 2); | 
|             } | 
|         } | 
|         /// <summary> 按凭证退货 | 
|         /// 按凭证退货 | 
|         /// </summary> | 
|         /// <param name="deviceCode">拆叠盘设备号</param> | 
|         /// <returns></returns> | 
|         public string resetChaiDieDevice(string deviceCode) | 
|         { | 
|             string msg = ""; | 
|             if (deviceCode.Trim() == "") | 
|             { | 
|                 return "参数为空"; | 
|             } | 
|             msg = "复位失败"; | 
|             try | 
|             { | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     ContainerIsFullOrEmpty resetDevice = mod.ContainerIsFullOrEmpty.FirstOrDefault(); | 
|                     if (resetDevice != null) | 
|                     { | 
|                         switch (deviceCode) | 
|                         { | 
|                             case "1": resetDevice.ChaiBig++; | 
|                                 break; | 
|                             case "2": resetDevice.ChaiSmall++; | 
|                                 break; | 
|                             case "3": resetDevice.DieBig++; | 
|                                 break; | 
|                             case "4": resetDevice.DieSmall++; | 
|                                 break; | 
|                         } | 
|                         int res = mod.SaveChanges(); | 
|                         if (res == 1) | 
|                         { | 
|                             msg = "复位成功"; | 
|                         } | 
|   | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "解锁库位失败  出错行号" + (string)ex.StackTrace, 2); | 
|             } | 
|             return msg; | 
|   | 
|         } | 
|   | 
|         /// <summary>删除wcs任务 | 
|         ///  | 
|         /// </summary> | 
|         /// <returns></returns> | 
|         public string deleteTask(string containerCode = "") | 
|         { | 
|             string msg = ""; | 
|             Task_Queue taskDelete; | 
|             try | 
|             { | 
|                 string plateCode = containerCode.Trim(); | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     taskDelete = mod.Task_Queue.FirstOrDefault(x => x.TaskStatus == "已下发" && x.PlateCode == plateCode); | 
|                     if (taskDelete == null) | 
|                     { | 
|                         return msg = "此托盘号任务已完成"; | 
|                     } | 
|                     if (plateCode == "") | 
|                     { | 
|                         return msg = "参数为空"; | 
|                     } | 
|                     bool res = wcsApi.DealAllTask(containerCode.Trim()); | 
|                     if (res) | 
|                     { | 
|                         taskDelete.TaskStatus = "手工处理异常"; | 
|                         if (taskDelete.TaskType == "1") | 
|                         { | 
|                             Purchase_Shelve deleteInTaskCode = mod.Purchase_Shelve.FirstOrDefault(x => x.ShelveCode == taskDelete.BillCode); | 
|                             if (deleteInTaskCode == null) | 
|                             { | 
|                                 logtxt.txtWrite("删除wcs任务产生异常,托盘号:" + containerCode + "  单据编号:" + taskDelete.BillCode, 2); | 
|                             } | 
|                             else | 
|                             { | 
|                                 deleteInTaskCode.OnShelveStatus = "手工处理异常"; | 
|                             } | 
|                         } | 
|                     } | 
|                     int result = mod.SaveChanges(); | 
|                     logtxt.txtWrite("删除wcs任务产生异常,保存结果" + result, 1); | 
|                     msg = res == true ? "删除成功" : "删除失败"; | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("删除wcs产生异常,托盘号:" + containerCode + "    " + ex.ToString(), 2); | 
|                 msg = "参数异常"; | 
|             } | 
|             return msg; | 
|   | 
|         } | 
|   | 
|         /// <summary> 缺料单下载 | 
|         /// 缺料单下载 | 
|         /// </summary> | 
|         /// <param name="orderCode">出库单号</param> | 
|         /// <returns></returns> | 
|         public string lackData(string orderCode) | 
|         { | 
|             string msg = "false"; | 
|             orderCode = orderCode.Trim(); | 
|             if (string.IsNullOrEmpty(orderCode)) | 
|             { | 
|                 return "false"; | 
|             } | 
|             try | 
|             { | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     lackOrder lastOrder = mod.lackOrder.Where(x => x.workCode == orderCode).OrderByDescending(x => x.lackId).FirstOrDefault(); | 
|                     if (lastOrder != null) | 
|                     { | 
|                         List<lackOrderList> lackList = mod.lackOrderList.Where(x => x.lackId == lastOrder.lackId).ToList(); | 
|                         if (lackList.Count > 0) | 
|                         { | 
|   | 
|                             string[] lackOrderName ={ "跟踪号: ",  | 
|                                                         lastOrder.trackCode.ToString() , | 
|                                                         " 出库单号:", | 
|                                                          lastOrder.workCode.ToString(), | 
|                                                           " 已完成总套数:", | 
|                                                           lastOrder.finishCount.ToString(), | 
|                                                            " 本次套数:", | 
|                                                             (lastOrder.finishCount + lastOrder.counting).ToString()}; | 
|                             var data = new | 
|                             { | 
|                                 lackname = lackOrderName, | 
|                                 dataList = lackList | 
|   | 
|                             }; | 
|                             msg = JsonConvert.SerializeObject(data); | 
|                             //导出出库单后 改表的状态 | 
|                             Sale_Order saleorderStatus = mod.Sale_Order.FirstOrDefault(x => x.OrderCode == orderCode); | 
|                             if (saleorderStatus != null) | 
|                             { | 
|                                 //saleorderStatus.StatusText = "部分分配"; | 
|                                 saleorderStatus.StatusText = Sale_Order_StatusEnum.部分分配.ToString(); | 
|                                 saleorderStatus.StatusID = Convert.ToByte(Sale_Order_StatusEnum.部分分配); | 
|                                 List<Sale_OrderList> saleList = mod.Sale_OrderList.Where(x => x.Order_Id == saleorderStatus.Order_Id).ToList(); | 
|                                 if (saleList.Count > 0) | 
|                                 { | 
|                                     foreach (var item in saleList) | 
|                                     { | 
|                                         item.ExtendField03 = "部分分配";//明细分拣状态 | 
|                                         item.ValidQuantity = item.ValidQuantity - item.QuantityOrder;//未出库数量 | 
|                                         item.QuantityOrder = 0;//本次出库数量 | 
|   | 
|                                     } | 
|                                 } | 
|                                 int resultSave = mod.SaveChanges(); | 
|                                 if (resultSave < 1)//保存失败再保存一次 | 
|                                 { | 
|                                     mod.SaveChanges(); | 
|                                 } | 
|   | 
|                             } | 
|   | 
|                         } | 
|                     } | 
|                     else | 
|                     {//无缺料信息 | 
|                         var data = new | 
|                         { | 
|                             lackname = "无缺料", | 
|                             dataList = new List<lackOrderList>() | 
|   | 
|                         }; | 
|                         msg = JsonConvert.SerializeObject(data); | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "解锁库位失败  出错行号" + ex.StackTrace.ToString(), 2); | 
|             } | 
|   | 
|   | 
|             return msg; | 
|   | 
|         } | 
|         ///解锁库位 | 
|         /// </summary> | 
|         /// <param name="positionName">库位名称</param> | 
|         /// <returns></returns> | 
|         public string unlock(int isremove, string positionName, string username) | 
|         { | 
|             string msg = ""; | 
|   | 
|   | 
|             try | 
|             { | 
|                 string PositionName = positionName.Trim(); | 
|                 string[] containerNo = PositionName.Split('-'); | 
|                 username = username == null ? "空" : username.Trim(); | 
|                 if (containerNo.Length != 4) | 
|                 { | 
|                     return "库位格式错误"; | 
|   | 
|                 } | 
|                 //写入任务列表Task_Queue | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|   | 
|                     List<Base_ProductPosition> ProductPosition = mod.Base_ProductPosition.Where(x => x.PositionName == PositionName).ToList(); | 
|                     if (ProductPosition.Count > 0) | 
|                     { | 
|   | 
|                         foreach (var itemRemovePosition in ProductPosition) | 
|                         { | 
|                             if (isremove == 1) | 
|                             { | 
|   | 
|                                 //清除库存 | 
|                                 mod.Base_ProductPosition.Remove(itemRemovePosition); | 
|                                 //增加出入库记录 【EditBy shaocx,2022-03-07】 | 
|                                 OutInStockTaskHandler.AddOutInStockTask(username, mod, OutInStockTaskName.清库任务, itemRemovePosition.ProductStorage, itemRemovePosition, "解锁库位,清空库存"); | 
|                                 baseData.addOperation(username, "清空库存:库位:" + itemRemovePosition.PositionName + "物料名称:" + itemRemovePosition.ProductCode, "清除库存"); | 
|                                 logtxt.txtWrite("apitest-" + "unlock-解锁/删除库存" + itemRemovePosition.PositionName + "物料名称:" + itemRemovePosition.ProductCode, 2); | 
|   | 
|                             } | 
|                             else | 
|                             { | 
|                                 //复位库位 | 
|                                 //ExtendField02 出库数量  ContainerNo=1 锁定(正在出库)  ExtendField03=1允许分拣 Remark 移动类型 | 
|                                 itemRemovePosition.ExtendField02 = "0"; | 
|                                 itemRemovePosition.ContainerNo = "0"; | 
|                                 //增加物料锁定和解锁的时间和备注记录  [EditBy shaocx,2023-07-26] | 
|                                 itemRemovePosition.DoContainerNoTime = DateTime.Now; | 
|                                 itemRemovePosition.OpRemark = "界面解锁库位操作,解绑物料锁定"; | 
|   | 
|                                 itemRemovePosition.ExtendField03 = "0"; | 
|                                 // baseData.addOperation(username, "复位库位:" + itemRemovePosition.PositionName, "复位库位"); | 
|                                 logtxt.txtWrite("apitest-" + "unlock-解锁/删除库存" + itemRemovePosition.PositionName + "物料名称:" + itemRemovePosition.ProductCode, 2); | 
|                             } | 
|                         } | 
|                     } | 
|   | 
|                     //复位库位状态 | 
|                     Base_Position Position = mod.Base_Position.FirstOrDefault(x => x.PositionName == PositionName); | 
|   | 
|                     if (Position != null) | 
|                     { | 
|                         //判断是否有任务占用 | 
|                         string[] positions = Position.PositionName.Split('-'); | 
|                         var position = positions[1] + "-" + positions[2] + "-" + positions[3];//格式: 01-03-01 | 
|                         var doingTaskList = BussinessExtension.BussinessExtension.GetDoingTaskList(mod, Convert.ToInt32(positions[0]), position); | 
|                         if (doingTaskList != null && doingTaskList.Count > 0) | 
|                         { | 
|                             msg = "有未结束的任务占用库位'" + Position.PositionName + "',任务ID为:" + doingTaskList[0].Task_Id; | 
|                             return msg; | 
|                         } | 
|   | 
|                         if (isremove == 1) | 
|                         {//移除库存 | 
|                             //Position.IsFreeze = 0; | 
|                             Position.IsFreeze = (int)IsFreezeEnum.无货; | 
|                             Position.IsLocked = 0; | 
|                             Position.Remark = "人工[" + username + "]解锁库位操作-移除库存!"; | 
|                             Position.PositionLength = 0; | 
|                         } | 
|                         else | 
|                         { | 
|                             //Position.IsFreeze = 1; | 
|                             //Position.IsFreeze = (int)IsFreezeEnum.有货;//库位解锁就一定有货吗,扯犊子 【EditBy shaocx,2022-09-22】 | 
|                             Position.IsLocked = 0; | 
|                             Position.Remark = "人工[" + username + "]解锁库位操作!"; | 
|                         } | 
|   | 
|                     } | 
|                     int result = mod.SaveChanges(); | 
|                     if (result > 0) | 
|                     { | 
|                         if (isremove == 1) | 
|                         { | 
|                             SystemHelper.addOperation(username, "清除库存: " + positionName, "清除库存"); | 
|                         } | 
|                         else | 
|                         { | 
|                             SystemHelper.addOperation(username, "解锁库位: " + positionName, "解锁库位"); | 
|                         } | 
|                         msg = "操作成功"; | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "解锁库位失败  出错行号" + ex.StackTrace.ToString(), 2); | 
|                 msg = ex.Message; | 
|             } | 
|   | 
|             return msg; | 
|   | 
|         } | 
|         /// <summary>按单 收货和退货操作 | 
|         /// 按单 收货和退货操作 | 
|         /// </summary> | 
|         /// <param name="receipt"></param> | 
|         /// <returns></returns> | 
|         public string receiptConvert(string receipt) | 
|         { | 
|             string msg = ""; | 
|             bool saveSueeccd = false; | 
|             int numInfo = 0; | 
|             List<GRMaterialEntity> grEntitys = new List<GRMaterialEntity>(); | 
|             receipiEntity results = JsonConvert.DeserializeObject<receipiEntity>(receipt); | 
|   | 
|             var _qrCode_Guid = results.qrCode_guid; | 
|             if (!string.IsNullOrEmpty(results.qrCode_guid)) | 
|             {//表示有 收货二维码 | 
|                 if (results.dataList.Count > 1) | 
|                 { | 
|                     var data23 = new | 
|                     { | 
|                         result = saveSueeccd, | 
|                         msg = "使用二维码收货,只能收货一个项号的物料" | 
|                     }; | 
|                     msg = JsonConvert.SerializeObject(data23); | 
|                     return msg; | 
|                 } | 
|             } | 
|   | 
|             ////模拟写死,还得改回来 哦  | 
|             //var data22 = new | 
|             //{ | 
|             //    result = saveSueeccd, | 
|             //    msg = "我错了" | 
|             //}; | 
|             //msg = JsonConvert.SerializeObject(data22); | 
|             //return msg; | 
|   | 
|             try | 
|             { | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //需要校验下 该库存是否存在 【Editby shaocx,2023-11-5】 | 
|                     if (!string.IsNullOrEmpty(results.qrCode_guid)) | 
|                     {//表示有 收货二维码 | 
|                         var isExistObj = mod.Base_ProductPosition.Where(x => x.qrCode_guid == results.qrCode_guid).FirstOrDefault(); | 
|                         if (isExistObj != null) | 
|                         { | 
|                             var data99 = new | 
|                             { | 
|                                 result = saveSueeccd, | 
|                                 msg = "该二维码已经收货了" | 
|                             }; | 
|                             msg = JsonConvert.SerializeObject(data99); | 
|                             return msg; | 
|                         } | 
|                     } | 
|   | 
|                     if (results.dataList.Count > 0) | 
|                     { | 
|                         string poCode = results.poCode.Trim(); | 
|                         string moveType = results.moveType.Trim();//具体详看枚举 MoveTypeForReceiptConvertEnum | 
|                         Purchase_Order purchaseOrder = mod.Purchase_Order.FirstOrDefault(x => x.PoCode == poCode); | 
|                         List<Purchase_OrderList> PurchaseList = mod.Purchase_OrderList.Where(x => x.ExtendField10 == poCode).ToList(); | 
|                         if (PurchaseList.Count > 0 && purchaseOrder != null) | 
|                         { | 
|                             int isFinish = 0; | 
|                             foreach (var item in results.dataList) | 
|                             { | 
|                                 if (item.quantity <= 0) | 
|                                 {//增加验证 【EditBy shaocx,2022-10-11】 | 
|                                     saveSueeccd = false; | 
|                                     msg = "数量不能小于等于0"; | 
|                                     var data2 = new | 
|                                     { | 
|                                         result = saveSueeccd, | 
|                                         msg | 
|                                     }; | 
|                                     msg = JsonConvert.SerializeObject(data2); | 
|                                     return msg; | 
|                                 } | 
|   | 
|                                 Purchase_OrderList purchase_OrderList = PurchaseList.FirstOrDefault(x => x.OrderList_Id == item.orderList_Id); | 
|   | 
|                                 if (purchase_OrderList == null) | 
|                                 { | 
|                                     continue; | 
|                                 } | 
|                                 GRMaterialEntity grEntity = new GRMaterialEntity(); | 
|                                 #region 发送sap | 
|                                 grEntity.Plant = "3TG1"; | 
|                                 grEntity.StorageLocation = item.productBarCode;//存储位置 | 
|                                 grEntity.PoNumber = purchase_OrderList.ExtendField10;//采购单号 | 
|                                 grEntity.PoItem = purchase_OrderList.ItemNumber;//采购项号 | 
|                                 grEntity.MaterialCode = purchase_OrderList.ProductCode; | 
|                                 grEntity.MoveType = results.moveType; | 
|                                 grEntity.Quantity = item.quantity;// *item.unitConvert / item.unEnterQuantity;//未打印数量 | 
|                                 #endregion | 
|   | 
|   | 
|                                 //if (moveType == "101") | 
|                                 if (moveType == ((int)MoveTypeForReceiptConvertEnum.收货).ToString()) | 
|                                 {//101是指 收货,具体详看枚举 MoveTypeForReceiptConvertEnum | 
|   | 
|                                     decimal totalQty = (decimal)purchase_OrderList.BigQty * (1 + (decimal)purchase_OrderList.Overcharges / 100);//采购数量乘以容差 | 
|                                     decimal receivedQty = purchase_OrderList.BigEnterQuantity == null ? 0 : (decimal)purchase_OrderList.BigEnterQuantity;//已收数量 | 
|   | 
|                                     decimal nowQty = receivedQty + (decimal)item.quantity;//已收数量加上本次收的数量 | 
|                                     if (totalQty >= nowQty)//验证有没有超收 | 
|                                     { | 
|   | 
|                                         if (nowQty >= (decimal)purchase_OrderList.BigQty) | 
|                                         { | 
|                                             isFinish++; | 
|   | 
|                                         } | 
|   | 
|                                         numInfo++; | 
|                                         #region 收货 | 
|                                         purchase_OrderList.BigEnterQuantity = receivedQty + item.quantity; | 
|                                         Base_ProductPosition productPosition = new Base_ProductPosition(); | 
|                                         //where PositionName = '收货暂存区' and ProductStorage > 0 and PartStatus ='1' | 
|                                         //ProductPosition.PositionName = "收货暂存区"; | 
|                                         productPosition.PositionName = SysGlole.PositionName_SHZCQ; | 
|                                         productPosition.CreateDate = DateTime.Now; | 
|                                         productPosition.ModifyDate = DateTime.Now; | 
|   | 
|                                         //注意:这里处理支持二维码的方式 【Editby shaocx,2023-11-5】 | 
|                                         productPosition.qrCode_guid = _qrCode_Guid; | 
|   | 
|                                         productPosition.ProductStorage = item.quantity * item.unitConvert / item.unEnterQuantity;//未打印数量 | 
|                                         //修改可维护自动打印的参数 【Editby shaocx,2022-06-13】 | 
|                                         //ProductPosition.PartStatus = "1";//0表示不需要自动打印,1表示需要自动打印 | 
|                                         //// 0不打印 1:入库口打印机 2:出库口打印机 | 
|                                         //ProductPosition.PartStatus = results.isAutoPrint ? "1" : "0";//0表示不需要自动打印,1表示需要自动打印 | 
|                                         productPosition.PartStatus = results.printFlag.ToString();//0表示不需要自动打印,1表示需要自动打印 | 
|                                         if (!string.IsNullOrEmpty(results.qrCode_guid)) | 
|                                         {//表示有 收货二维码 | 
|                                             productPosition.PartStatus = "1";//写死为 入库口打印机 | 
|                                         } | 
|   | 
|                                         productPosition.Product_Id = Convert.ToInt32(purchase_OrderList.Product_Id); | 
|                                         productPosition.ProductCode = purchase_OrderList.ProductCode; | 
|                                         productPosition.ProductName = purchase_OrderList.ProductName; | 
|                                         productPosition.InStorageDate = DateTime.Now; | 
|                                         productPosition.PoCode = purchase_OrderList.ExtendField10;//采购单号 | 
|                                         productPosition.ItemNumber = purchase_OrderList.ItemNumber;//采购项号 | 
|                                         productPosition.ExtendField04 = purchase_OrderList.ExtendField04;//跟踪号 | 
|                                         productPosition.SaleCode = purchase_OrderList.ExtendField07;//销售单号 | 
|                                         productPosition.ExtendField08 = purchase_OrderList.SpecAlias;//销售项号 | 
|                                         productPosition.OrignStorage = item.quantity * item.unitConvert / item.unEnterQuantity;//收货数量 ProductStorage | 
|                                         productPosition.OriginPlace = "1";//打印次数 | 
|                                         productPosition.LimitDate = item.limitDate;//限用日期 purchaseOrder  providerShortName providerShortName | 
|                                         productPosition.ProviderShortName = purchaseOrder.ProviderShortName;//供应商名称 | 
|                                         productPosition.PlatUser_Id = 1;//必填垃圾信息 | 
|                                         productPosition.UserProduct_Id = 1007;//必填垃圾信息 | 
|                                         productPosition.ClassName = "采购入库"; | 
|                                         productPosition.Class_Id = 0; | 
|                                         productPosition.MainID = 0; | 
|                                         productPosition.DetailID = 0; | 
|                                         productPosition.Storage_Id = 87; | 
|                                         productPosition.StorageName = "立体库"; | 
|                                         productPosition.ProductModel = purchase_OrderList.ProductName; | 
|                                         productPosition.ProductModel = "0"; | 
|                                         productPosition.ConsignorCode = "GX30"; | 
|                                         productPosition.ConsignorName = "广州西门子"; | 
|                                         productPosition.Consignor_Id = 30; | 
|                                         productPosition.ExtendField10 = purchase_OrderList.OrderList_Id.ToString();//这里记录 表purchase_orderlist的主键OrderList_Id值 【EditBy shaocx,2022-10-14】 | 
|   | 
|                                         mod.Base_ProductPosition.Add(productPosition); | 
|                                         //增加出入库记录 【EditBy shaocx,2022-03-07】 | 
|                                         OutInStockTaskHandler.AddOutInStockTask(results.creator, mod, OutInStockTaskName.收货任务, productPosition.ProductStorage, productPosition, "按单收货-收货,收货暂存区,增加库存"); | 
|                                         //按单收货 | 
|                                         grEntitys.Add(grEntity);//可以收货再发生sap | 
|                                         #endregion | 
|                                     } | 
|                                     else | 
|                                     { | 
|                                         msg = "收货超出数量"; | 
|                                         saveSueeccd = false; | 
|                                     } | 
|                                 } | 
|                                 else | 
|                                 {//退货 | 
|                                     //据我观察,必须是收货后的才能进行退后,未收货的不允许退哦 【EditBy shaocx,2022-10-14】 | 
|                                     if (purchase_OrderList.BigEnterQuantity - item.quantity >= 0) | 
|                                     { | 
|                                         purchase_OrderList.BigEnterQuantity = purchase_OrderList.BigEnterQuantity - item.quantity; | 
|                                         grEntitys.Add(grEntity); | 
|                                         numInfo++; | 
|   | 
|                                         var query_OrderList_Id = purchase_OrderList.OrderList_Id.ToString(); | 
|                                         Base_ProductPosition curStore = mod.Base_ProductPosition.Where(x => x.PositionName == SysGlole.PositionName_SHZCQ | 
|                                          && x.ExtendField10 != null && x.ExtendField10 == query_OrderList_Id).FirstOrDefault(); | 
|                                         if (curStore == null) | 
|                                         { | 
|                                             //报错返回 | 
|                                             saveSueeccd = false; | 
|                                             msg = "明细[采购项号:" + purchase_OrderList.ItemNumber + ",物料:" + purchase_OrderList.ProductName + "]没有被收货,因此不允许被退货"; | 
|                                             var data2 = new | 
|                                             { | 
|                                                 result = saveSueeccd, | 
|                                                 msg | 
|                                             }; | 
|                                             msg = JsonConvert.SerializeObject(data2); | 
|                                             return msg; | 
|                                         } | 
|                                         //扣减暂存区数量 | 
|                                         if (curStore.ProductStorage < item.quantity) | 
|                                         { | 
|                                             //报错返回 | 
|                                             saveSueeccd = false; | 
|                                             msg = "明细[采购项号:" + purchase_OrderList.ItemNumber + ",物料:" + purchase_OrderList.ProductName + "]收货数量" + curStore.ProductStorage + "不能小于退货数量" + item.quantity + ",因此不允许被退货"; | 
|                                             var data2 = new | 
|                                             { | 
|                                                 result = saveSueeccd, | 
|                                                 msg | 
|                                             }; | 
|                                             msg = JsonConvert.SerializeObject(data2); | 
|                                             return msg; | 
|                                         } | 
|                                         curStore.ProductStorage = curStore.ProductStorage - item.quantity; | 
|                                         string remark = ""; | 
|                                         if (curStore.ProductStorage == 0) | 
|                                         { | 
|                                             //表示全部退货了,库存删除 | 
|                                             mod.Base_ProductPosition.Remove(curStore); | 
|                                             remark = "按单退货-退货,收货暂存区,全部退货,清空暂存区库存"; | 
|                                         } | 
|                                         else | 
|                                         { | 
|                                             remark = "按单退货-退货,收货暂存区,减少库存"; | 
|                                         } | 
|                                         //增加出入库记录 【EditBy shaocx,2022-10-14】 | 
|                                         OutInStockTaskHandler.AddOutInStockTask(results.creator, mod, OutInStockTaskName.退货任务, item.quantity, curStore, remark, results.creator); | 
|                                         //*/ | 
|                                     } | 
|                                     else | 
|                                     { | 
|                                         msg = "退货库存不足"; | 
|                                         saveSueeccd = false; | 
|                                     } | 
|   | 
|                                 } | 
|                             } | 
|                             if (isFinish == results.dataList.Count) | 
|                             { | 
|                                 purchaseOrder.StatusText = "完全交货"; | 
|                             } | 
|                             else | 
|                             { | 
|                                 purchaseOrder.StatusText = "部分交货"; | 
|                             } | 
|   | 
|                         } | 
|                         if (grEntitys.Count > 0) | 
|                         { | 
|                             string sendSapGr = JsonConvert.SerializeObject(grEntitys); | 
|                             var resultStr = receiptConfirm(sendSapGr); | 
|                             ResultEntity fe = JsonConvert.DeserializeObject<ResultEntity>(resultStr); | 
|                             if (fe.result == false) | 
|                             { | 
|                                 msg = fe.msg; | 
|                                 saveSueeccd = false; | 
|                             } | 
|                         } | 
|                         if (string.IsNullOrEmpty(msg)) | 
|                         { | 
|                             int result = mod.SaveChanges(); | 
|                             #region 检查是否保存成功 | 
|                             for (int i = 0; i < 10; i++) | 
|                             { | 
|                                 if (result < 1) | 
|                                 { | 
|   | 
|                                     result = mod.SaveChanges(); | 
|                                     if (i == 9 && result < 1) | 
|                                     { | 
|                                         msg = "保存失败"; | 
|                                     } | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     msg = "执行成功,完成" + numInfo + "条信息"; | 
|                                     saveSueeccd = true; | 
|                                     break; | 
|                                 } | 
|   | 
|                             } | 
|                             #endregion | 
|                         } | 
|   | 
|   | 
|                     } | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|   | 
|                 msg = "执行失败"; | 
|             } | 
|             var data = new | 
|             { | 
|                 result = saveSueeccd, | 
|                 msg | 
|             }; | 
|             msg = JsonConvert.SerializeObject(data); | 
|             return msg; | 
|         } | 
|         /// <summary>查找物料信息 | 
|         /// 查找物料信息 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string findMaterial(string param) | 
|         { | 
|             msgss<VmaterialInfo> msg = new msgss<VmaterialInfo>(); | 
|             try | 
|             { | 
|                 searchEntity page = JsonConvert.DeserializeObject<searchEntity>(param); | 
|   | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 if (page.searchParam != null && page.searchParam != "") | 
|                 { | 
|                     StockWhere = StockWhere + " and (ProductCode like '%" + page.searchParam.Trim() + "%' or ProductName like '%" + page.searchParam.Trim() + "%')"; | 
|   | 
|                 } | 
|                 if (page.check == true) | 
|                 { | 
|                     StockWhere = StockWhere + " and Brand_Id>0 "; | 
|                 } | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取盘点数据 | 
|                     string sql = "select * from [dbo].[" + "VmaterialInfo" + "] where Product_Id >0 " + StockWhere + " order by Product_Id desc ";//isFreeze    是否有货   先拿这个字段用  | 
|   | 
|                     List<VmaterialInfo> takeStock = mod.Database.SqlQuery<VmaterialInfo>(sql).ToList(); | 
|                     List<VmaterialInfo> fenyeRerult = new List<VmaterialInfo>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             //msg.allDate = takeStock.Take(20000).ToList(); | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStock.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|         } | 
|         /// <summary>物料增删改 | 
|         /// 物料增删改查 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string MaterialOperation(string param) | 
|         { | 
|   | 
|   | 
|             resultMsg msgs = new resultMsg(); | 
|             try | 
|             { | 
|                 materialResult acceptParam = JsonConvert.DeserializeObject<materialResult>(param); | 
|                 #region 参数验证 | 
|                 if (acceptParam == null) | 
|                 { | 
|                     msgs.status = 400; | 
|                     msgs.result = false; | 
|                     msgs.msg = "参数为空"; | 
|                     return JsonConvert.SerializeObject(msgs); | 
|                 } | 
|                 if (acceptParam.OperationValue != 1 && acceptParam.OperationValue != 2 && acceptParam.OperationValue != 3) | 
|                 { | 
|                     msgs.status = 400; | 
|                     msgs.result = false; | 
|                     msgs.msg = "参数为空"; | 
|                     return JsonConvert.SerializeObject(msgs); | 
|                 } | 
|                 #endregion | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     switch (acceptParam.OperationValue) | 
|                     { | 
|                         case 1://新建物料 Base_ProductInfo | 
|                             #region 新建物料 | 
|                             Base_ProductInfo addmaterial = new Base_ProductInfo(); | 
|                             addmaterial.BigUnit = acceptParam.taskForm.BigUnit; | 
|                             addmaterial.Brand_Id = acceptParam.taskForm.Brand_Id == null ? 0 : acceptParam.taskForm.Brand_Id; | 
|                             addmaterial.CreateDate = DateTime.Now; | 
|                             addmaterial.Creator = acceptParam.taskForm.Creator; | 
|                             addmaterial.ModifyDate = DateTime.Now; | 
|                             addmaterial.ProductCode = acceptParam.taskForm.ProductCode; | 
|                             addmaterial.ProductName = acceptParam.taskForm.ProductName; | 
|                             addmaterial.SmallUnit = acceptParam.taskForm.SmallUnit; | 
|                             addmaterial.ProductModel = acceptParam.taskForm.ProductCode; | 
|                             //非空值 | 
|                             addmaterial.UnitConvert = 1M;//大小单位转换 | 
|                             addmaterial.Provider_Id = 926; | 
|                             addmaterial.ProviderCode = "PV201940371"; | 
|                             addmaterial.Consignor_Id = 30; | 
|                             addmaterial.ConsignorCode = "GX30"; | 
|                             addmaterial.ConsignorName = "广州西门子"; | 
|                             addmaterial.UserProduct_Id = 1007; | 
|                             addmaterial.UserProductCode = "100000001"; | 
|                             mod.Base_ProductInfo.Add(addmaterial); | 
|                             int saveResult = mod.SaveChanges(); | 
|                             if (saveResult < 1) | 
|                             { | 
|                                 saveResult = mod.SaveChanges(); | 
|                             } | 
|                             if (saveResult < 1) | 
|                             { | 
|                                 msgs.status = 400; | 
|                                 msgs.result = false; | 
|                                 msgs.msg = "新建物料失败"; | 
|                             } | 
|                             else | 
|                             { | 
|                                 msgs.status = 200; | 
|                                 msgs.result = true; | 
|                                 msgs.msg = "新建成功"; | 
|                             } | 
|                             break; | 
|                             #endregion | 
|   | 
|                         case 2://修改物料 | 
|                             Base_ProductInfo modify = mod.Base_ProductInfo.Find(acceptParam.taskForm.Product_Id); | 
|                             if (modify != null) | 
|                             { | 
|                                 modify.BigUnit = acceptParam.taskForm.BigUnit; | 
|                                 modify.Brand_Id = acceptParam.taskForm.Brand_Id == null ? 0 : acceptParam.taskForm.Brand_Id; | 
|                                 modify.Creator = acceptParam.taskForm.Creator; | 
|                                 modify.ModifyDate = DateTime.Now; | 
|                                 modify.ProductCode = acceptParam.taskForm.ProductCode; | 
|                                 modify.ProductName = acceptParam.taskForm.ProductName; | 
|                                 modify.SmallUnit = acceptParam.taskForm.SmallUnit; | 
|                                 modify.ProductModel = acceptParam.taskForm.ProductCode; | 
|                                 int updateResult = mod.SaveChanges(); | 
|                                 if (updateResult < 1) | 
|                                 { | 
|                                     updateResult = mod.SaveChanges(); | 
|                                 } | 
|                                 if (updateResult < 1) | 
|                                 { | 
|                                     msgs.status = 400; | 
|                                     msgs.result = false; | 
|                                     msgs.msg = "修改物料失败"; | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     msgs.status = 200; | 
|                                     msgs.result = true; | 
|                                     msgs.msg = "修改成功"; | 
|                                 } | 
|                             } | 
|                             else | 
|                             { | 
|                                 msgs.status = 400; | 
|                                 msgs.result = false; | 
|                                 msgs.msg = "修改物料失败--找不到这个物料"; | 
|                             } | 
|   | 
|                             break; | 
|                         case 3://删除物料 | 
|                             #region 删除物料 | 
|                             Base_ProductInfo deleteMaterial = mod.Base_ProductInfo.Find(acceptParam.taskForm.Product_Id); | 
|                             if (deleteMaterial != null) | 
|                             { | 
|                                 mod.Base_ProductInfo.Remove(deleteMaterial); | 
|                                 int deleteResult = mod.SaveChanges(); | 
|                                 if (deleteResult < 1) | 
|                                 { | 
|                                     deleteResult = mod.SaveChanges(); | 
|                                 } | 
|                                 if (deleteResult < 1) | 
|                                 { | 
|                                     msgs.status = 400; | 
|                                     msgs.result = false; | 
|                                     msgs.msg = "删除物料失败"; | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     msgs.status = 200; | 
|                                     msgs.result = true; | 
|                                     msgs.msg = "删除成功"; | 
|                                 } | 
|                             } | 
|                             else | 
|                             { | 
|                                 msgs.status = 200; | 
|                                 msgs.result = true; | 
|                                 msgs.msg = "删除物料失败,找不到这个物料"; | 
|                             } | 
|                             break; | 
|                             #endregion | 
|   | 
|                         default: | 
|                             break; | 
|                     } | 
|                 } | 
|   | 
|   | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 msgs.status = 400; | 
|                 msgs.result = false; | 
|                 msgs.msg = "参数异常"; | 
|   | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "MaterialOperation 物料增删改产生异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|   | 
|             } | 
|   | 
|             return JsonConvert.SerializeObject(msgs); | 
|         } | 
|         /// <summary>获取设备报警记录 | 
|         /// 获取设备报警记录 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string deviceAlarm(string param) | 
|         { | 
|             msgss<deviceAlarmMsg> msg = new msgss<deviceAlarmMsg>(); | 
|             try | 
|             { | 
|                 productStockEntity page = JsonConvert.DeserializeObject<productStockEntity>(param); | 
|   | 
|                 string StockWhere = ""; | 
|                 //根据下拉框筛选 | 
|                 if (page.positionTypeValue < 5) | 
|                 { | 
|                     StockWhere = "and type = " + page.positionTypeValue; | 
|                 } | 
|                 //根据日期筛选 | 
|                 if (page.datatime != null) | 
|                 { | 
|                     if (page.datatime.Length == 2) | 
|                     { | 
|                         StockWhere = StockWhere + "and createtime > '" + page.datatime[0].ToString() + "' and  createtime < '" + page.datatime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|                 using (deviceOrm mod = new deviceOrm()) | 
|                 { | 
|                     //设备报警信息 | 
|                     string sql = "select * from [dbo].[" + "DevAlert" + "] where id >0 " + StockWhere + " and isfinished=1 order by id desc "; | 
|   | 
|                     List<DevAlert> takeStock = mod.Database.SqlQuery<DevAlert>(sql).ToList(); | 
|   | 
|                     List<deviceAlarmMsg> devicefenyeRerults = new List<deviceAlarmMsg>(); | 
|                     List<DevAlert> fenyeRerult = new List<DevAlert>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             foreach (var item in takeStock) | 
|                             { | 
|                                 deviceAlarmMsg deviceAlarm = new deviceAlarmMsg(); | 
|                                 string[] name = form.alarmName(item.type, Convert.ToInt32(item.alertcode), Convert.ToInt32(item.eqname)); | 
|                                 deviceAlarm.deviceName = name[0]; | 
|                                 deviceAlarm.alarmInfo = name[1]; | 
|                                 deviceAlarm.creatTime = (DateTime)item.createtime; | 
|                                 TimeSpan continuetime = (DateTime)item.finishtime - (DateTime)item.createtime; | 
|                                 deviceAlarm.continueTime = continuetime.Hours + "小时" + continuetime.Minutes + "分钟" + continuetime.Seconds + "秒"; | 
|                                 devicefenyeRerults.Add(deviceAlarm); | 
|                             } | 
|                             msg.allDate = devicefenyeRerults; | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             msg.total = takeStock.Count; | 
|                             //假如每页数量 大于总数量 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 fenyeRerult = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 #endregion | 
|                             } | 
|                             foreach (var item in fenyeRerult) | 
|                             { | 
|                                 deviceAlarmMsg deviceAlarm = new deviceAlarmMsg(); | 
|                                 string[] name = form.alarmName(item.type, Convert.ToInt32(item.alertcode), Convert.ToInt32(item.eqname)); | 
|                                 deviceAlarm.deviceName = name[0]; | 
|                                 deviceAlarm.alarmInfo = name[1]; | 
|                                 deviceAlarm.creatTime = (DateTime)item.createtime; | 
|                                 TimeSpan continuetime = (DateTime)item.finishtime - (DateTime)item.createtime; | 
|                                 deviceAlarm.continueTime = continuetime.Hours + "小时" + continuetime.Minutes + "分钟" + continuetime.Seconds + "秒"; | 
|                                 devicefenyeRerults.Add(deviceAlarm); | 
|                             } | 
|                             msg.date = devicefenyeRerults; | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "deviceAlarm" + "获取报警信息异常" + ex.ToString() + "--" + logtxt.oneRow(ex.ToString()), 2); | 
|             } | 
|             return JsonConvert.SerializeObject(msg); | 
|         } | 
|         /// <summary>获取设备报警记录统计 | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="param">此参数不用</param> | 
|         /// <returns></returns> | 
|         public string deviceAlarms(string param) | 
|         { | 
|             msgss<DeviceAlarms> msg = new msgss<DeviceAlarms>(); | 
|             msg.status = 400; | 
|             try | 
|             { | 
|                 List<DeviceAlarms> deviceTotal = new List<DeviceAlarms>(); | 
|                 DeviceAlarms srm1 = new DeviceAlarms(); | 
|                 DeviceAlarms srm2 = new DeviceAlarms(); | 
|                 DeviceAlarms rgv1 = new DeviceAlarms(); | 
|                 DeviceAlarms rgv2 = new DeviceAlarms(); | 
|                 string month = param == "" ? DateTime.Now.Month.ToString() : DateTime.Parse(param).Month.ToString(); | 
|                 DateTime fristMonth = DateTime.Parse(DateTime.Now.ToString("yyyy-" + month + "-01")); | 
|                 DateTime lastMonth = DateTime.Parse(DateTime.Parse(DateTime.Now.ToString("yyyy-" + month + "-01")).AddMonths(1).AddMinutes(-1).ToString()); | 
|   | 
|                 using (deviceOrm mod = new deviceOrm()) | 
|                 { | 
|                     List<DevAlert> srm1Info = mod.DevAlert.Where(x => x.createtime > fristMonth && x.createtime < lastMonth && x.name == "Srm1").ToList(); | 
|                     #region 堆垛机1 | 
|                     var srm1Type = srm1Info.GroupBy(x => x.alertname).OrderByDescending(x => x.Count()).ToList(); | 
|   | 
|                     TimeSpan srm1Span = new TimeSpan(); | 
|                     if (srm1Info.Count > 0) | 
|                     { | 
|                         foreach (var srm1item in srm1Info) | 
|                         { | 
|                             srm1Span = srm1Span + (TimeSpan)(srm1item.finishtime - srm1item.createtime); | 
|                         } | 
|                     } | 
|                     srm1.AlarmTime = srm1Span.TotalHours.ToString("0.00"); | 
|   | 
|                     srm1.DeviceName = "一号堆垛机"; | 
|                     srm1.AlarmNum = srm1Info.Count.ToString(); | 
|                     if (srm1Type.Count > 0) | 
|                     { | 
|                         srm1.AlarmName1 = srm1Type[0].Key; | 
|                         if (srm1Type.Count > 1) | 
|                         { | 
|                             srm1.AlarmName2 = srm1Type[1].Key; | 
|                             if (srm1Type.Count > 2) | 
|                             { | 
|                                 srm1.AlarmName3 = srm1Type[2].Key; | 
|                             } | 
|                         } | 
|   | 
|                     } | 
|                     #endregion | 
|   | 
|                     List<DevAlert> srm2Info = mod.DevAlert.Where(x => x.createtime > fristMonth && x.createtime < lastMonth && x.name == "Srm2").ToList(); | 
|                     #region 堆垛机2 | 
|                     var srm2Type = srm2Info.GroupBy(x => x.alertname).OrderByDescending(x => x.Count()).ToList(); | 
|   | 
|                     TimeSpan srm2Span = new TimeSpan(); | 
|                     if (srm2Info.Count > 0) | 
|                     { | 
|                         foreach (var srm2item in srm2Info) | 
|                         { | 
|                             srm2Span = srm2Span + (TimeSpan)(srm2item.finishtime - srm2item.createtime); | 
|                         } | 
|                     } | 
|                     srm2.AlarmTime = srm2Span.TotalHours.ToString("0.00"); | 
|   | 
|                     srm2.DeviceName = "二号堆垛机"; | 
|                     srm2.AlarmNum = srm2Info.Count.ToString(); | 
|                     if (srm2Type.Count > 0) | 
|                     { | 
|                         srm2.AlarmName1 = srm2Type[0].Key; | 
|                         if (srm2Type.Count > 1) | 
|                         { | 
|                             srm2.AlarmName2 = srm2Type[1].Key; | 
|                             if (srm2Type.Count > 2) | 
|                             { | 
|                                 srm2.AlarmName3 = srm2Type[2].Key; | 
|                             } | 
|                         } | 
|   | 
|                     } | 
|                     #endregion | 
|                     List<DevAlert> rgv1Info = mod.DevAlert.Where(x => x.createtime > fristMonth && x.createtime < lastMonth && x.name == "Rgv1").ToList(); | 
|                     #region 堆垛机1 | 
|                     var rgv1Type = rgv1Info.GroupBy(x => x.alertname).OrderByDescending(x => x.Count()).ToList(); | 
|   | 
|                     TimeSpan rgv1Span = new TimeSpan(); | 
|                     if (rgv1Info.Count > 0) | 
|                     { | 
|                         foreach (var agv1item in rgv1Info) | 
|                         { | 
|                             rgv1Span = rgv1Span + (TimeSpan)(agv1item.finishtime - agv1item.createtime); | 
|                         } | 
|                     } | 
|                     rgv1.AlarmTime = rgv1Span.TotalHours.ToString("0.00"); | 
|                     rgv1.DeviceName = "一号RGV"; | 
|                     rgv1.AlarmNum = rgv1Info.Count.ToString(); | 
|                     if (rgv1Type.Count > 0) | 
|                     { | 
|                         rgv1.AlarmName1 = rgv1Type[0].Key; | 
|                         if (rgv1Type.Count > 1) | 
|                         { | 
|                             rgv1.AlarmName2 = rgv1Type[1].Key; | 
|                             if (rgv1Type.Count > 2) | 
|                             { | 
|                                 rgv1.AlarmName3 = rgv1Type[2].Key; | 
|                             } | 
|                         } | 
|   | 
|                     } | 
|                     #endregion | 
|                     List<DevAlert> rgv2Info = mod.DevAlert.Where(x => x.createtime > fristMonth && x.createtime < lastMonth && x.name == "Rgv2").ToList(); | 
|                     #region 二号RGV | 
|                     var rgv2Type = rgv2Info.GroupBy(x => x.alertname).OrderByDescending(x => x.Count()).ToList(); | 
|   | 
|                     TimeSpan rgv2Span = new TimeSpan(); | 
|                     if (rgv2Info.Count > 0) | 
|                     { | 
|                         foreach (var rgv2item in rgv2Info) | 
|                         { | 
|                             rgv2Span = rgv2Span + (TimeSpan)(rgv2item.finishtime - rgv2item.createtime); | 
|                         } | 
|                     } | 
|                     rgv2.AlarmTime = rgv2Span.TotalHours.ToString("0.00"); | 
|                     rgv2.DeviceName = "二号RGV"; | 
|                     rgv2.AlarmNum = rgv2Info.Count.ToString(); | 
|                     if (rgv2Type.Count > 0) | 
|                     { | 
|                         rgv2.AlarmName1 = rgv2Type[0].Key; | 
|                         if (rgv2Type.Count > 1) | 
|                         { | 
|                             rgv2.AlarmName2 = rgv2Type[1].Key; | 
|                             if (rgv2Type.Count > 2) | 
|                             { | 
|                                 rgv2.AlarmName3 = rgv2Type[2].Key; | 
|                             } | 
|                         } | 
|   | 
|                     } | 
|                     #endregion | 
|                 } | 
|                 deviceTotal.Add(srm1); | 
|                 deviceTotal.Add(srm2); | 
|                 deviceTotal.Add(rgv1); | 
|                 deviceTotal.Add(rgv2); | 
|                 msg.status = 200; | 
|                 msg.date = deviceTotal; | 
|   | 
|             } | 
|             catch (Exception) | 
|             { | 
|   | 
|                 throw; | 
|             } | 
|   | 
|             return JsonConvert.SerializeObject(msg); | 
|         } | 
|         /// <summary>空托盘出入库 | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string emtypContainerOUtandIN(string param) | 
|         { | 
|             //我认为这个方法不用了 【EditBy shaocx,2022-09-22】 | 
|             resultMsg msgs = new resultMsg(); | 
|             msgs.status = 400; | 
|             msgs.msg = "方法无效"; | 
|             return JsonConvert.SerializeObject(msgs); | 
|             /* | 
|             resultMsg msgs = new resultMsg(); | 
|             msgs.status = 400; | 
|             try | 
|             { | 
|                 emtypContainerOUtandINclass emtypContainer = JsonConvert.DeserializeObject<emtypContainerOUtandINclass>(param); | 
|                 var findEmptyReason = ""; | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     bool isInMoreHighPosition = false; | 
|                     if (emtypContainer.name == null)//没有目标库位说明是入库 | 
|                     { | 
|                         Task_Queue CallContainerTaks = new Task_Queue(); | 
|                         CallContainerTaks.BillCode = "空托盘入库"; | 
|                         string toplace = emtypContainer.type == "1" ? FindEmptyLocationHandler.findStorage("", true, ref isInMoreHighPosition, ref findEmptyReason, 1, 1, 2, 0) : FindEmptyLocationHandler.findStorage("", true, ref isInMoreHighPosition, ref findEmptyReason, 2, 2, 4, 0); | 
|                         CallContainerTaks.TaskType = ((int)TaskTypeEnum.余料回库).ToString();//任务类型 | 
|                         CallContainerTaks.OrderNumber = 0;//任务权重 | 
|                         CallContainerTaks.TaskStatus = "未下发";//任务状态 | 
|                         CallContainerTaks.PlateType = emtypContainer.type;//托盘类型  第二排没有空小托盘 | 
|                         CallContainerTaks.CreateDate = DateTime.Now; | 
|                         CallContainerTaks.UserProduct_Id = 1007;//账套id 老谢bug   | 
|                         //垃圾值都赋值0 转到autoTask()里有说明 | 
|                         CallContainerTaks.FromPositionName = "1001"; | 
|                         CallContainerTaks.Direction = "0";//托盘高度 | 
|                         CallContainerTaks.ToPositionName = toplace; | 
|                         CallContainerTaks.CreateID = 0;//表示空托盘入库 | 
|                         CallContainerTaks.DoCount = emtypContainer.type == "1" ? 1 : 2;//库区 | 
|                         mod.Task_Queue.Add(CallContainerTaks); | 
|                         int res = mod.SaveChanges(); | 
|                         if (res == 1) | 
|                         { | 
|                             msgs.status = 200; | 
|                         } | 
|                         else | 
|                         { | 
|                             res = mod.SaveChanges(); | 
|                             if (res == 1) | 
|                             { | 
|                                 msgs.status = 200; | 
|                             } | 
|                             else | 
|                             { | 
|   | 
|                                 msgs.msg = "生成任务失败"; | 
|                             } | 
|                         } | 
|                     } | 
|   | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 msgs.status = 400; | 
|                 msgs.msg = "生成任务失败ex"; | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "emtypContainerOUtandIN 空托盘出入库产生异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|   | 
|             } | 
|             return JsonConvert.SerializeObject(msgs); | 
|   | 
|             //*/ | 
|         } | 
|   | 
|         #region 闲时移库管理 | 
|   | 
|         /// <summary> | 
|         /// 分页查询 闲时移库 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string QueryPageFreeTimeMoveLocationTask(string param) | 
|         { | 
|             msgss<FreeTimeMoveLocationTaskOutput> msg = new msgss<FreeTimeMoveLocationTaskOutput>(); | 
|             QueryPageFoldingPlateMachineInput page = JsonConvert.DeserializeObject<QueryPageFoldingPlateMachineInput>(param); | 
|             try | 
|             { | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 if (page.StartTime != null) | 
|                 { | 
|                     if (page.StartTime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and StartTime > '" + page.StartTime[0].ToString() + "' and  StartTime < '" + page.StartTime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|                 if (page.EndTime != null) | 
|                 { | 
|                     if (page.EndTime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and EndTime > '" + page.EndTime[0].ToString() + "' and  EndTime < '" + page.EndTime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|                 if (page.CreateTime != null) | 
|                 { | 
|                     if (page.CreateTime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and CreateTime > '" + page.CreateTime[0].ToString() + "' and  CreateTime < '" + page.CreateTime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|   | 
|                 if (!string.IsNullOrEmpty(page.UserName)) | 
|                 { | 
|                     StockWhere = StockWhere + " and Creator like '%" + page.UserName.Trim() + "%'"; | 
|                 } | 
|   | 
|                 if (page.MoveStatus != null) | 
|                 { | 
|                     StockWhere = StockWhere + " and MoveStatus=" + page.MoveStatus.ToString(); | 
|                 } | 
|                 if (page.RunTime != null) | 
|                 { | 
|                     StockWhere = StockWhere + " and RunTime=" + page.RunTime.ToString(); | 
|                 } | 
|                 #endregion | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取数据 | 
|                     string sql = "select * from [dbo].[" + "V_FreeTimeMoveLocationTaskPage" + "] WITH(NOLOCK) where 1=1  " + StockWhere + " order by LastModifyTime desc "; | 
|   | 
|                     List<FreeTimeMoveLocationTaskOutput> takeStock = mod.Database.SqlQuery<FreeTimeMoveLocationTaskOutput>(sql).ToList(); | 
|                     foreach (var item in takeStock) | 
|                     { | 
|                         if (item.MoveStatus == (int)MoveStatusEnum.执行中) | 
|                         { | 
|                             TimeSpan ts = DateTime.Now - Convert.ToDateTime(item.StartTime); | 
|                             item.CurExcuteTime = ts.Minutes;//显示分钟 | 
|                         } | 
|                     } | 
|   | 
|                     List<FreeTimeMoveLocationTaskOutput> fenyeRerult = new List<FreeTimeMoveLocationTaskOutput>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStock.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|   | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 分页查询 闲时移库明细 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string QueryPageFreeTimeMoveLocationTaskDetails(string param) | 
|         { | 
|             msgss<V_FreeTimeMoveLocationTask> msg = new msgss<V_FreeTimeMoveLocationTask>(); | 
|             QueryPageFreeTimeMoveLocationTaskDetailsInput page = JsonConvert.DeserializeObject<QueryPageFreeTimeMoveLocationTaskDetailsInput>(param); | 
|             try | 
|             { | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 StockWhere = StockWhere + " and MainFreeMoveId=" + page.MainFreeMoveId.ToString(); | 
|                 #endregion | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取数据 | 
|                     string sql = "select * from [dbo].[" + "V_FreeTimeMoveLocationTask" + "] WITH(NOLOCK) where 1=1  " + StockWhere + " order by Task_Id desc "; | 
|   | 
|                     List<V_FreeTimeMoveLocationTask> takeStock = mod.Database.SqlQuery<V_FreeTimeMoveLocationTask>(sql).ToList(); | 
|   | 
|                     List<V_FreeTimeMoveLocationTask> fenyeRerult = new List<V_FreeTimeMoveLocationTask>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         //假如每页数量 大于盘点数据 | 
|                         if (page.queryInfo.pagesize > takeStock.Count) | 
|                         { | 
|                             msg.date = takeStock; | 
|                         } | 
|                         else | 
|                         { | 
|                             #region 分页计算 | 
|                             int a = page.queryInfo.pagesize; | 
|   | 
|                             int b = page.queryInfo.pagenum; | 
|                             int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                             int d = takeStock.Count % a; | 
|                             int e = 0; | 
|                             int f = a * (b - 1); | 
|                             if (d != 0 && b == c) | 
|                             { | 
|                                 e = d + f; | 
|   | 
|                             } | 
|                             else | 
|                             { | 
|                                 e = a + f; | 
|                             } | 
|   | 
|   | 
|   | 
|                             for (int i = f; i < e; i++) | 
|                             { | 
|                                 fenyeRerult.Add(takeStock[i]); | 
|                             } | 
|                             msg.date = fenyeRerult; | 
|                             #endregion | 
|   | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|   | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 新增 闲时移库 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string AddFreeTimeMoveLocationTask(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 AddFoldingPlateMachineInput input = JsonConvert.DeserializeObject<AddFoldingPlateMachineInput>(param); | 
|                 return JsonConvert.SerializeObject(FreeTimeMoveLocationTaskHandler.Add(input)); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "AddFreeTimeMoveLocationTask 增加闲时移库管理 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 编辑 闲时移库 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string UpdateFreeTimeMoveLocationTask(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 UpdateFoldingPlateMachineInput input = JsonConvert.DeserializeObject<UpdateFoldingPlateMachineInput>(param); | 
|                 return JsonConvert.SerializeObject(FreeTimeMoveLocationTaskHandler.Update(input)); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "UpdateFreeTimeMoveLocationTask 编辑闲时移库管理 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 执行 闲时移库 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string ExcuteFreeTimeMoveLocationTask(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 ExcuteAndCancelFoldingPlateMachineInput input = JsonConvert.DeserializeObject<ExcuteAndCancelFoldingPlateMachineInput>(param); | 
|                 return JsonConvert.SerializeObject(FreeTimeMoveLocationTaskHandler.Excute(input)); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "ExcuteFreeTimeMoveLocationTask 执行 闲时移库管理 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 取消 闲时移库 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string CancelFreeTimeMoveLocationTask(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 ExcuteAndCancelFoldingPlateMachineInput input = JsonConvert.DeserializeObject<ExcuteAndCancelFoldingPlateMachineInput>(param); | 
|                 return JsonConvert.SerializeObject(FreeTimeMoveLocationTaskHandler.Cancel(input)); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "CancelFreeTimeMoveLocationTask 取消 闲时移库管理 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 人工结束 闲时移库 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string PersonStopFreeTimeMoveLocationTask(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 PersonStopFoldingPlateMachineInput input = JsonConvert.DeserializeObject<PersonStopFoldingPlateMachineInput>(param); | 
|                 return JsonConvert.SerializeObject(FreeTimeMoveLocationTaskHandler.PersonStop(input)); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "PersonStopFreeTimeMoveLocationTask 人工结束 闲时移库管理 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|   | 
|         #endregion | 
|   | 
|         #region 按单出库记录 | 
|   | 
|         /// <summary> | 
|         /// 分页查询 按单出库记录 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string QueryPageSale_Order_History(string param) | 
|         { | 
|             msgss<Sale_Order_History> msg = new msgss<Sale_Order_History>(); | 
|             QueryPageSale_Order_HistoryInput page = JsonConvert.DeserializeObject<QueryPageSale_Order_HistoryInput>(param); | 
|             try | 
|             { | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 if (page.CreateTime != null) | 
|                 { | 
|                     if (page.CreateTime.Length == 2) | 
|                     { | 
|   | 
|                         StockWhere = StockWhere + " and CreateTime > '" + page.CreateTime[0].ToString() + "' and  CreateTime < '" + page.CreateTime[1].ToString() + "'"; | 
|                     } | 
|                 } | 
|   | 
|                 if (!string.IsNullOrEmpty(page.UserName)) | 
|                 { | 
|                     StockWhere = StockWhere + " and Creator like '%" + page.UserName.Trim() + "%'"; | 
|                 } | 
|   | 
|                 if (!string.IsNullOrEmpty(page.OrderCode)) | 
|                 { | 
|                     StockWhere = StockWhere + " and OrderCode='" + page.OrderCode.ToString() + "' "; | 
|                 } | 
|                 if (!string.IsNullOrEmpty(page.TrackingNumber)) | 
|                 { | 
|                     StockWhere = StockWhere + " and TrackingNumber='" + page.TrackingNumber.ToString() + "' "; | 
|                 } | 
|   | 
|                 #endregion | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取数据 | 
|                     string sql = "select * from [dbo].[" + "Sale_Order_History" + "] WITH(NOLOCK) where 1=1  " + StockWhere + " order by LastModifyTime desc "; | 
|   | 
|                     List<Sale_Order_History> takeStock = mod.Database.SqlQuery<Sale_Order_History>(sql).ToList(); | 
|   | 
|   | 
|                     List<Sale_Order_History> fenyeRerult = new List<Sale_Order_History>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         if (page.IsLoadAllData) | 
|                         {//只有确定加载全部数据时才加载全部数据 [EditBy shaocx,2022-03-07] | 
|                             msg.status = 200; | 
|                             msg.allDate = takeStock.ToList(); | 
|                         } | 
|                         else | 
|                         {//不加载全部,就过滤分页信息 | 
|                             //假如每页数量 大于盘点数据 | 
|                             if (page.queryInfo.pagesize > takeStock.Count) | 
|                             { | 
|                                 msg.date = takeStock; | 
|                             } | 
|                             else | 
|                             { | 
|                                 #region 分页计算 | 
|                                 int a = page.queryInfo.pagesize; | 
|   | 
|                                 int b = page.queryInfo.pagenum; | 
|                                 int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                                 int d = takeStock.Count % a; | 
|                                 int e = 0; | 
|                                 int f = a * (b - 1); | 
|                                 if (d != 0 && b == c) | 
|                                 { | 
|                                     e = d + f; | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     e = a + f; | 
|                                 } | 
|   | 
|   | 
|   | 
|                                 for (int i = f; i < e; i++) | 
|                                 { | 
|                                     fenyeRerult.Add(takeStock[i]); | 
|                                 } | 
|                                 msg.date = fenyeRerult; | 
|                                 #endregion | 
|   | 
|                             } | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|   | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 分页查询 按单出库记录明细 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string QueryPageSale_Order_HistoryDetails(string param) | 
|         { | 
|             msgss<Sale_Order_History_Items> msg = new msgss<Sale_Order_History_Items>(); | 
|             QueryPageSale_Order_History_ItemsInput page = JsonConvert.DeserializeObject<QueryPageSale_Order_History_ItemsInput>(param); | 
|             try | 
|             { | 
|                 string StockWhere = ""; | 
|                 //根据日期筛选 | 
|                 #region 搜索条件判断 | 
|                 StockWhere = StockWhere + " and Sale_Order_History_Id=" + page.Sale_Order_History_Id.ToString(); | 
|                 #endregion | 
|   | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|                     //获取数据 | 
|                     string sql = "select * from [dbo].[" + "Sale_Order_History_Items" + "] WITH(NOLOCK) where 1=1  " + StockWhere + " order by ID desc "; | 
|   | 
|                     List<Sale_Order_History_Items> takeStock = mod.Database.SqlQuery<Sale_Order_History_Items>(sql).ToList(); | 
|   | 
|                     List<Sale_Order_History_Items> fenyeRerult = new List<Sale_Order_History_Items>(); | 
|                     if (takeStock.Count > 0) | 
|                     { | 
|                         msg.status = 200; | 
|                         msg.total = takeStock.Count; | 
|                         //假如每页数量 大于盘点数据 | 
|                         if (page.queryInfo.pagesize > takeStock.Count) | 
|                         { | 
|                             msg.date = takeStock; | 
|                         } | 
|                         else | 
|                         { | 
|                             #region 分页计算 | 
|                             int a = page.queryInfo.pagesize; | 
|   | 
|                             int b = page.queryInfo.pagenum; | 
|                             int c = (int)Math.Ceiling((double)takeStock.Count / a); | 
|                             int d = takeStock.Count % a; | 
|                             int e = 0; | 
|                             int f = a * (b - 1); | 
|                             if (d != 0 && b == c) | 
|                             { | 
|                                 e = d + f; | 
|   | 
|                             } | 
|                             else | 
|                             { | 
|                                 e = a + f; | 
|                             } | 
|   | 
|   | 
|   | 
|                             for (int i = f; i < e; i++) | 
|                             { | 
|                                 fenyeRerult.Add(takeStock[i]); | 
|                             } | 
|                             msg.date = fenyeRerult; | 
|                             #endregion | 
|   | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         msg.status = 400; | 
|                         msg.total = 1; | 
|                         msg.date = null; | 
|                     } | 
|   | 
|   | 
|                     return JsonConvert.SerializeObject(msg); | 
|                 } | 
|   | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("出错信息" + ex.Message + "出错行号" + (string)ex.StackTrace, 2); | 
|                 msg.status = 400; | 
|                 msg.total = 1; | 
|                 msg.date = null; | 
|   | 
|                 return JsonConvert.SerializeObject(msg); | 
|             } | 
|   | 
|         } | 
|   | 
|   | 
|         #endregion | 
|   | 
|         #region 权限 | 
|   | 
|         /// <summary> | 
|         /// 查询 某个菜单下的,某个角色的权限,考虑多个角色不?我看了,系统配置一个用户只能是一个角色,因此不需要考虑多个角色的情况 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string QueryButtonAuth(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 QueryButtonPermissionInput input = JsonConvert.DeserializeObject<QueryButtonPermissionInput>(param); | 
|                 if (string.IsNullOrEmpty(input.menu_IdEnum)) | 
|                 { | 
|                     return JsonConvert.SerializeObject(FunRetEntity.Fail("菜单ID不能为空")); | 
|                 } | 
|                 Menu_IdEnum menuIdEnum = (Menu_IdEnum)Enum.Parse(typeof(Menu_IdEnum), input.menu_IdEnum); | 
|                 var buttonAuth = SystemHelper.QueryButtonPermission(input.role_Id, menuIdEnum); | 
|   | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Success("成功", buttonAuth)); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "QueryButtonAuth 查询 某个菜单下的,某个角色的权限 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|         #endregion | 
|   | 
|         #region 打印标签 | 
|   | 
|   | 
|         /// <summary> | 
|         /// 重新打印 标签 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string RePrintBarCode(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 if (string.IsNullOrEmpty(param)) | 
|                 { | 
|                     return JsonConvert.SerializeObject(FunRetEntity.Fail("标签条码不能为空!")); | 
|                 } | 
|                 RePrintBarCodeInput input = JsonConvert.DeserializeObject<RePrintBarCodeInput>(param); | 
|                 if (input.barCode == null || input.barCode.Count == 0) | 
|                 { | 
|                     return JsonConvert.SerializeObject(FunRetEntity.Fail("标签条码不能为空!")); | 
|                 } | 
|                 using (dbModel edm = new dbModel()) | 
|                 { | 
|                     foreach (var item in input.barCode) | 
|                     { | 
|                         var data = edm.Base_PositionPrint.Where(x => x.ExtendField06 == item).FirstOrDefault(); | 
|                         if (data == null) | 
|                         { | 
|                             return JsonConvert.SerializeObject(FunRetEntity.Fail("根据标签条码" + item + "没有找到打印数据!")); | 
|                         } | 
|   | 
|                         if (data.printDevice == null) | 
|                         { | 
|                             return JsonConvert.SerializeObject(FunRetEntity.Fail("根据标签条码" + item + "查到的打印数据没有指定打印机!")); | 
|                         } | 
|   | 
|                         data.isNeedPrint = 1; | 
|                         edm.SaveChanges(); | 
|                     } | 
|                 } | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Success("成功")); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "RePrintBarCode 重新打印 标签 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|   | 
|         #endregion | 
|   | 
|   | 
|         #region 维护库存预警天数 | 
|   | 
|         /// <summary> | 
|         /// 维护库存预警天数 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string UpdateStoreWarningDays(string param) | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 UpdateStoreWarningDaysInput input = JsonConvert.DeserializeObject<UpdateStoreWarningDaysInput>(param); | 
|                 return JsonConvert.SerializeObject(UpdateStoreWarningDaysHandler.Excute(input)); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "UpdateStoreWarningDays 维护库存预警天数 异常参数:" + param + " 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 获取库存预警天数 | 
|         /// </summary> | 
|         /// <param name="param"></param> | 
|         /// <returns></returns> | 
|         public string GetStoreWarningDays() | 
|         { | 
|             FunRetEntity msgs = new FunRetEntity(); | 
|             try | 
|             { | 
|                 return JsonConvert.SerializeObject(UpdateStoreWarningDaysHandler.Get()); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("类名: " + "apitest" + "方法名:" + "GetStoreWarningDays 获取库存预警天数 信息:" + logtxt.oneRow(ex.ToString()), 2); | 
|                 return JsonConvert.SerializeObject(FunRetEntity.Fail("异常:" + ex.Message)); | 
|             } | 
|         } | 
|   | 
|         #endregion | 
|   | 
|         #endregion | 
|   | 
|         #region 给WCS接口 | 
|   | 
|         /// <summary> | 
|         /// 返回给WCS 库区和目标库位 | 
|         /// </summary> | 
|         /// <param name="taskId">PLC任务号</param> | 
|         /// <param name="continerType">托盘类型</param> | 
|         /// <param name="height">高度</param> | 
|         /// <param name="wmsTaskId">WMS的任务ID</param> | 
|         /// <returns>失败返回"",成功返回-例子"2-01-01-01" 2号库位1排1列1层</returns> | 
|         public string getToPlace(int taskId, int continerType, int height, int wmsTaskId) | 
|         { | 
|             string toplace = ""; | 
|             try | 
|             { | 
|                 var findEmptyReason = ""; | 
|                 toplace = FindEmptyLocationHandler.toPlace(taskId, continerType, height, height, ref findEmptyReason, wmsTaskId); | 
|                 logtxt.txtWrite("类名:taskApi,函数名: getToPlace:wcs高度等级是:" + height + " 任务号是:" + taskId + " 托盘类型是:" + continerType + " 返回目标地址是 " + toplace | 
|                     + ",原因findEmptyReason:" + findEmptyReason | 
|                     , 1); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|   | 
|                 logtxt.txtWrite("类名:taskApi,异常函数名: getToPlace:wcs高度等级是:" + height + " 任务号是:" + taskId + " 托盘类型是:" + continerType + " 返回目标地址是 " + toplace + logtxt.oneRow(ex.ToString()), 2); | 
|                 toplace = ""; | 
|             } | 
|             return toplace; | 
|         } | 
|         #endregion | 
|   | 
|         #region 调sap接口 | 
|   | 
|         /// <summary>sap收货确认 | 
|         ///  sap收货确认 | 
|         /// </summary> | 
|         /// <param name="receipt">json字符串</param> | 
|         /// <returns>空表示成功,否则返回失败内容</returns> | 
|         public string receiptConfirm(string receipt) | 
|         { | 
|             // 转入toPlace   转出fromPlace | 
|             #region po单状态 | 
|             //StatusText = "新建"; | 
|             //StatusID = 1; | 
|             //StatusText = "部分完成"; | 
|             //StatusID = 7; | 
|             //StatusText = "完全交货"; | 
|             //StatusID =8 ; | 
|             #endregion | 
|   | 
|             string msg = ""; | 
|             if (receipt == null) | 
|             { | 
|                 var datax = new | 
|                 { | 
|                     result = false, | 
|                     msg = "参数不能为空" | 
|                 }; | 
|                 msg = JsonConvert.SerializeObject(datax); | 
|                 return msg; | 
|             } | 
|   | 
|             logtxt.txtWrite(receipt, 0);//收到记录一条日志 | 
|             try | 
|             { | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|   | 
|                     //转换收料信息 | 
|                     GRMaterialEntity[] results = JsonConvert.DeserializeObject<GRMaterialEntity[]>(receipt); | 
|                     if (results.Length > 0) | 
|                     { | 
|                         //没有PO单就是手动收货 | 
|                         if (string.IsNullOrEmpty(results[0].PoNumber)) | 
|                         { | 
|                             #region 无单收货 | 
|                             //转换成移库实体  [{"MaterialCode":"A7EQD-5130033087","Quantity":1,"MoveType":"262","toPlace":"G021","fromPlace":"G021","trackingNumber":"7615"}] | 
|                             moveStock[] moveResults = JsonConvert.DeserializeObject<moveStock[]>(receipt); | 
|                             //检查是否带跟踪号不带的移动类型 不带E | 
|                             List<MovMaterialEntity> moveMaterials = new List<MovMaterialEntity>();//移库实体 | 
|                             List<GIMaterialEntity> GImaterals = new List<GIMaterialEntity>();//收货实体类 | 
|   | 
|                             foreach (var itemGi in moveResults) | 
|                             { | 
|                                 string moveType = itemGi.MoveType; | 
|                                 string trackingNum = itemGi.trackingNumber; | 
|                                 string materialCode = itemGi.MaterialCode; | 
|                                 //311是移库有转入仓和转出仓 | 
|                                 if (moveType == "311") | 
|                                 { | 
|                                     #region MyRegion | 
|                                     MovMaterialEntity moveMaterial = new MovMaterialEntity(); | 
|                                     //有跟踪号 移动类型要加E  加E就要天销售单号和销售项号 | 
|                                     if (!string.IsNullOrEmpty(trackingNum))//ProductCode poInfoChild.ExtendField07 = item.SalesOrder;//销售单号 poInfoChild.SpecAlias = item.SalesOrderItem;//销售单项号 | 
|                                     { | 
|                                         moveType += "E"; | 
|                                         Purchase_OrderList poList = mod.Purchase_OrderList.FirstOrDefault(x => x.ExtendField04 == trackingNum && x.ProductCode == materialCode); | 
|                                         moveMaterial.SalesOrder = poList.ExtendField07; | 
|                                         moveMaterial.SalesOrderItem = poList.SpecAlias; | 
|                                     } | 
|                                     logtxt.txtWrite("发送的移动类型是" + moveType + "跟踪号:" + trackingNum, 0);//收到记录一条日志 | 
|                                     moveMaterial.MoveType = moveType; | 
|                                     moveMaterial.Plant = "3TG1"; | 
|                                     moveMaterial.MaterialCode = materialCode; | 
|                                     moveMaterial.FromStorageLocation = itemGi.fromPlace; | 
|                                     moveMaterial.ToStorageLocation = itemGi.toPlace; | 
|                                     moveMaterial.Quantity = itemGi.Quantity; | 
|                                     moveMaterials.Add(moveMaterial); | 
|                                     #endregion | 
|   | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     #region MyRegion | 
|                                     GIMaterialEntity GImateral = new GIMaterialEntity(); | 
|                                     if (!string.IsNullOrEmpty(trackingNum))//ProductCode poInfoChild.ExtendField07 = item.SalesOrder;//销售单号 poInfoChild.SpecAlias = item.SalesOrderItem;//销售单项号 | 
|                                     { | 
|                                         moveType += "E"; | 
|                                         Purchase_OrderList poList = mod.Purchase_OrderList.FirstOrDefault(x => x.ExtendField04 == trackingNum && x.ProductCode == materialCode); | 
|                                         if (poList == null)//根据跟踪号查不到数据 就赋值为空 | 
|                                         { | 
|                                             GImateral.SalesOrder = ""; | 
|                                             GImateral.SalesOrderItem = ""; | 
|                                         } | 
|                                         else | 
|                                         { | 
|                                             GImateral.SalesOrder = poList.ExtendField07 == null ? "" : poList.ExtendField07; | 
|                                             GImateral.SalesOrderItem = poList.SpecAlias == null ? "" : poList.SpecAlias; | 
|                                         } | 
|                                     } | 
|                                     GImateral.MoveType = moveType; | 
|                                     GImateral.StorageLocation = "G021"; | 
|                                     GImateral.Plant = "3TG1"; | 
|                                     GImateral.MaterialCode = materialCode; | 
|                                     GImateral.Quantity = itemGi.Quantity; | 
|                                     GImateral.WorkOrder = "#0#0"; | 
|                                     GImaterals.Add(GImateral); | 
|                                     #endregion | 
|   | 
|                                 } | 
|                             } | 
|                             if (moveMaterials.Count > 0)//有数据说明是移库 | 
|                             { | 
|                                 string moveReceipt = JsonConvert.SerializeObject(moveMaterials); | 
|                                 msg = SAPHelper.moveStockConfirm(null, moveReceipt); | 
|                             } | 
|                             if (GImaterals.Count > 0)//有数据说明是退料 | 
|                             { | 
|                                 string GiReceipt = JsonConvert.SerializeObject(GImaterals); | 
|                                 msg = SAPHelper.StockOutConfirm(null, GiReceipt); | 
|                             } | 
|                             return msg; | 
|                             #endregion | 
|   | 
|                         } | 
|                     } | 
|                     else | 
|                     { | 
|                         var data = new | 
|                         { | 
|                             result = false, | 
|                             msg = "无此单号" | 
|                         }; | 
|                         msg = JsonConvert.SerializeObject(data); | 
|                         return msg; | 
|                     } | 
|   | 
|                     //收货信息给SAP | 
|                     var result = SAPHelper.ConfirmGR(results, out msg); | 
|                     //注释以下方法,当收货信息推送给SAP失败后,也要允许他们进行收货打印标记  【EditBy shaocx,2022-09-30】 | 
|                     msg = "";//强制认为收货信息推送给SAP是成功的! 【EditBy shaocx,2022-09-30】 | 
|                     /* | 
|                     if (result == false) | 
|                     { | 
|                         var data = new | 
|                         { | 
|                             result = false, | 
|                             msg = "收货信息给SAP失败:" + msg | 
|                         }; | 
|                         msg = JsonConvert.SerializeObject(data); | 
|                         return msg; | 
|                     } | 
|                     //*/ | 
|                     //注释以下方法,改为调用 SAPHelper方法 【EditBy shaocx,2022-09-23】 | 
|                     /* | 
|                     string info = sendSap.ConfirmGR(results, out msg); | 
|                     form.textBox6.Text = DateTime.Now.ToString("dd-HH-mm-ss") + "收货,退货成功,凭证:" + info + "返回信息" + msg + "\r\n" + form.textBox6.Text; | 
|                     if (msg == "") | 
|                     { | 
|                         logtxt.txtWrite("收货,退货成功,凭证:" + info, 0); | 
|                     } | 
|                     else | 
|                     { | 
|                         //这里是 收货,退货失败? [EditBy shaocx,2022-03-06] | 
|                         logtxt.txtWrite("收货,退货失败,凭证:" + info + ",返回msg:" + msg, 0); | 
|                         SapSendFailRecodInfoHandler.AddForSH(results, info, msg);//记录失败表 | 
|                     } | 
|                     //*/ | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 logtxt.txtWrite("收货,退货执行异常" + ex.Message, 2); | 
|                 var data = new | 
|                 { | 
|                     result = false, | 
|                     msg = "执行异常" | 
|                 }; | 
|                 msg = JsonConvert.SerializeObject(data); | 
|                 return msg; | 
|             } | 
|   | 
|             var data1 = new | 
|             { | 
|                 result = msg == "" ? true : false, | 
|                 msg = msg == "" ? "执行成功" : "执行失败", | 
|             }; | 
|             msg = JsonConvert.SerializeObject(data1); | 
|             return msg; | 
|   | 
|         } | 
|         /// <summary>获取Po单 | 
|         ///  获取Po单 | 
|         /// </summary> | 
|         /// <param name="PoCode">Po单</param> | 
|         /// <returns></returns> | 
|         public string getPoList(string PoCode) | 
|         { | 
|             DateTime timeInfo = DateTime.Now; | 
|             string msg = ""; | 
|             try | 
|             { | 
|                 using (dbModel mod = new dbModel()) | 
|                 { | 
|   | 
|                     Purchase_Order poNumber = mod.Purchase_Order.Where(x => x.PoCode == PoCode).FirstOrDefault(); | 
|                     //PO表里查不到就SAP接口里获取采购信息 | 
|                     if (poNumber == null) | 
|                     {//GetPurchaseOrder | 
|                         #region 如果主表里没有数据就调ASP接口获取采购单 | 
|                         PurchaseOrderEntity resultPo = SAPHelper.GetPurchaseOrder(PoCode, out msg); | 
|                         //PurchaseOrderEntity resultPo = sendSap.GetPurchaseOrder(PoCode, out msg);//改为调用SAPHelper 【Editby shaocx,2022-09-23】 | 
|                         if (msg != "")//获取失败返回空 | 
|                         { | 
|                             var data = new | 
|                             { | 
|                                 result = false, | 
|                                 msg = "找不到这个单号" | 
|                             }; | 
|                             msg = JsonConvert.SerializeObject(data); | 
|                             return msg; | 
|                         } | 
|                         List<string> rstPo = resultPo.Materials.Select(x => x.MaterialCode).ToList(); | 
|   | 
|                         Purchase_Order poInfo = new Purchase_Order(); | 
|                         #region 主表数据 | 
|                         poInfo.PoCode = resultPo.PoNumber;//采购单号 | 
|                         poInfo.StatusText = "新建";//状态 providerShortName | 
|                         poInfo.StatusID = 1; | 
|                         poInfo.AuditRemark = resultPo.PurchaseOrg;//采购部门 VendorName | 
|                         poInfo.ProviderShortName = resultPo.VendorName; | 
|                         poInfo.CreateID = 1; | 
|                         poInfo.Creator = resultPo.CreatedBy; | 
|                         poInfo.CreateDate = DateTime.Now; | 
|                         #region 数据库不可为空垃圾字段 | 
|                         poInfo.Storage_Id = 87; | 
|                         poInfo.StorageName = "立体库"; | 
|                         poInfo.Consignor_Id = 30; | 
|                         poInfo.ConsignorCode = "GX30"; | 
|                         poInfo.ConsignorName = "广州西门子"; | 
|                         poInfo.UserProductCode = "100000001"; | 
|                         poInfo.UserProduct_Id = 1007; | 
|                         #endregion | 
|                         #endregion | 
|   | 
|                         //添加PO单物料明细 | 
|                         List<Purchase_OrderList> poInfoList = new List<Purchase_OrderList>(); | 
|                         int number = 0; | 
|                         //查找物料基础数据  找到po明细物料编号在数据库里有的集合 | 
|                         var checkMateria1s = (from p in mod.Base_ProductInfo where (from f in rstPo select f).Contains(p.ProductCode) select p).ToList(); | 
|   | 
|                         #region 添加PO单物料明细 | 
|                         string lastTracknum = ""; | 
|                         foreach (var item in resultPo.Materials) | 
|                         { | 
|                             if (item.MaterialCode == null) | 
|                             { | 
|                                 logtxt.txtWrite("采购单号:" + item.PoNumber + " 物料项号:" + item.PoItem + "物料编号为空", 2); | 
|                                 continue;//物料编号为空 | 
|                             } | 
|                             string materialCode = item.MaterialCode; | 
|                             long productId = 0; | 
|   | 
|                             #region 检查物料基础信息里是否有这个物料没有就新建 | 
|                             Base_ProductInfo checkMateria = checkMateria1s.FirstOrDefault(x => x.ProductCode == materialCode); | 
|                             Base_ProductInfo newMateria = new Base_ProductInfo(); | 
|                             if (checkMateria == null) | 
|                             { | 
|                                 newMateria.ProductCode = materialCode;//物料编号 | 
|                                 newMateria.ProductName = item.MaterialName;//物料名称 | 
|                                 newMateria.SmallUnit = item.BaseUnit;//库存单位 | 
|                                 newMateria.BigUnit = item.Unit;//采购单位 | 
|                                 newMateria.Enable = 1;//设置为可用  | 
|                                 newMateria.ProviderShortName = resultPo.VendorName;//供应商名称 | 
|                                 newMateria.UnitConvert = 1M;//大小单位转换 | 
|                                 newMateria.Brand_Id = 0;//库存预警量 | 
|                                 /////////////// | 
|                                 newMateria.ProductModel = materialCode; | 
|                                 newMateria.Provider_Id = 926; | 
|                                 newMateria.ProviderCode = "PV201940371"; | 
|   | 
|                                 newMateria.Consignor_Id = 30; | 
|                                 newMateria.ConsignorCode = "GX30"; | 
|                                 newMateria.ConsignorName = "广州西门子"; | 
|                                 newMateria.UserProduct_Id = 1007; | 
|                                 newMateria.UserProductCode = "100000001"; | 
|                                 mod.Base_ProductInfo.Add(newMateria); | 
|                                 mod.SaveChanges(); | 
|                                 //通过新建获取产品ID | 
|                                 productId = newMateria.Product_Id; | 
|                             } | 
|                             else | 
|                             { | 
|                                 //通过查询获取ID | 
|                                 productId = checkMateria.Product_Id; | 
|                             } | 
|                             #endregion | 
|   | 
|   | 
|                             //Base_ProductInfo isNewMateria=mod.Base_ProductInfo | 
|                             string trackingNum = ""; | 
|                             if (!string.IsNullOrEmpty(item.TrackingNo)) | 
|                             { | 
|                                 if (item.TrackingNo.Split('/')[0].Substring(0, 1) == "D") | 
|                                 { | 
|                                     trackingNum = item.TrackingNo.Split('/')[0].Remove(0, 1); | 
|                                 } | 
|                                 else | 
|                                 { | 
|                                     trackingNum = item.TrackingNo.Split('/')[0]; | 
|                                 } | 
|                             } | 
|                             #region 添加出库明细 | 
|                             Purchase_OrderList poInfoChild = new Purchase_OrderList(); | 
|                             poInfoChild.ExtendField10 = item.PoNumber;//采购单号 | 
|                             poInfoChild.ItemNumber = item.PoItem;//采购项号 | 
|                             poInfoChild.Product_Id = productId;//产品id | 
|                             poInfoChild.ProductCode = materialCode;//物料编号 | 
|                             poInfoChild.ProductName = item.MaterialName;//物料名称 | 
|                             poInfoChild.BigQty = item.Quantity;//采购数量 | 
|                             poInfoChild.BigUnit = item.Unit;//采购单位 | 
|                             poInfoChild.ExtendField04 = trackingNum;//跟踪号 | 
|                             poInfoChild.ExtendField07 = item.SalesOrder;//销售单号 | 
|                             poInfoChild.SpecAlias = item.SalesOrderItem;//销售单项号 | 
|                             poInfoChild.ProductBarCode = item.StorageLocation;//库区编号G021 | 
|                             poInfoChild.ExtendField02 = item.Plant;//工厂 | 
|   | 
|                             try//UnEnterQuantity | 
|                             { | 
|                                 poInfoChild.UnEnterQuantity = Convert.ToDecimal(item.ConvertDen2);   //订单单位转换系数 和下面单位转换有关,例如100kg(ConvertDen2)=126米(ConvertNum2) | 
|                                 poInfoChild.UnitConvert = Convert.ToDecimal(item.ConvertNum2);  //单位转换值     | 
|                                 poInfoChild.Overcharges = Convert.ToDecimal(item.OverDelTol);  //容差率上线 | 
|                             } | 
|                             catch (Exception ex) | 
|                             { | 
|                                 logtxt.txtWrite("采购单号:" + item.PoNumber + " 物料项号:" + item.PoItem + "物料编号:" + materialCode + " 单位转换或者容差转换失败", 2); | 
|                                 continue;//单位转换或者容差转换失败 | 
|   | 
|                             } | 
|   | 
|                             //垃圾字段 | 
|                             poInfoChild.ProductModel = materialCode; | 
|                             poInfo.Purchase_OrderList.Add(poInfoChild); | 
|                             // poInfoList.Add(poInfoChild); | 
|                             number++; | 
|                             #endregion | 
|                             #region 反推picklist 里的跟踪号 | 
|                             string saleOrder = item.SalesOrder; | 
|                             string saleItemNumber = item.SalesOrderItem; | 
|                             if (saleOrder != "" && lastTracknum != trackingNum) | 
|                             { | 
|                                 if (trackingNum != "") | 
|                                 { | 
|                                     //明细加跟踪号 | 
|                                     lastTracknum = trackingNum; | 
|                                     List<Sale_OrderList> sendPicklistTrackNumber = mod.Sale_OrderList.Where(x => x.SaleCode == saleOrder && x.ExtendField06 == saleItemNumber && x.TrackingNumber == "").ToList(); | 
|   | 
|                                     if (sendPicklistTrackNumber.Count > 0) | 
|                                     { | 
|                                         var orderTrack = sendPicklistTrackNumber.GroupBy(x => x.Order_Id); | 
|                                         var orders = mod.Sale_Order.ToList();//一次读取不然出库单多的时候会卡死 2021-8-16 修改 | 
|                                         if (orderTrack != null) | 
|                                         { | 
|                                             foreach (var itemOrder in orderTrack) | 
|                                             { | 
|                                                 long orderId = itemOrder.ToList()[0].Order_Id; | 
|                                                 Sale_Order addTrack = orders.FirstOrDefault(x => x.Order_Id == orderId); | 
|                                                 //if (addTrack != null && addTrack.OrderType == "SAP生产订单" && addTrack.StatusText == "新建") | 
|                                                 //if (addTrack != null && addTrack.OrderType == SysGlole.SAP_ORDER_TEXT && addTrack.StatusText == "新建") | 
|                                                 if (addTrack != null && addTrack.OrderType == SysGlole.SAP_ORDER_TEXT && addTrack.StatusText == Sale_Order_StatusEnum.新建.ToString()) | 
|                                                 { | 
|                                                     addTrack.TrackingNumber = trackingNum; | 
|                                                     foreach (var itemList in itemOrder) | 
|                                                     { | 
|                                                         itemList.TrackingNumber = trackingNum; | 
|                                                     } | 
|                                                 } | 
|                                             } | 
|                                         } | 
|                                     } | 
|   | 
|   | 
|                                 } | 
|   | 
|   | 
|                             } | 
|                             #endregion | 
|   | 
|   | 
|                         } | 
|                         #endregion | 
|                         //先保存主表 然后获取主表ID 再写入明细表 | 
|                         mod.Purchase_Order.Add(poInfo); | 
|                         int results = mod.SaveChanges(); | 
|                         for (int h = 0; h < 10; h++) | 
|                         { | 
|                             if (results < 1) | 
|                             { | 
|                                 results = mod.SaveChanges(); | 
|                             } | 
|                             else | 
|                             { | 
|                                 break; | 
|                             } | 
|                         } | 
|                         var data1 = new | 
|                         { | 
|                             result = true, | 
|                             data = resultPo.Materials | 
|                         }; | 
|                         msg = JsonConvert.SerializeObject(data1); | 
|                         //JsonConvert.SerializeObject(str) | 
|                         #endregion | 
|   | 
|                     } | 
|   | 
|                 } | 
|             } | 
|             // DateTime timeInfo = DateTime.Now; | 
|   | 
|   | 
|             catch (Exception ex) | 
|             { | 
|   | 
|                 logtxt.txtWrite("采购单号:" + PoCode + "产生异常" + ex.Message, 2); | 
|                 return "找不到这个单号"; | 
|             } | 
|             var timeInfo1 = DateTime.Now - timeInfo; | 
|             form.textBox6.Text = "po获取用时: " + timeInfo1 + "\r\n" + form.textBox6.Text; | 
|             return msg; | 
|         } | 
|   | 
|   | 
|   | 
|   | 
|         /// <summary>按凭证退货 | 
|         /// 按凭证退货 | 
|         /// </summary> | 
|         /// <param name="res"></param> | 
|         /// <returns></returns> | 
|         public string reverser(string res) | 
|         { | 
|             return SAPHelper.reverser(res); | 
|         } | 
|   | 
|         #endregion | 
|   | 
|     } | 
| } |