public string CreateMoveBillNo() { string billNo = ""; IQueryable <MoveBillMaster> moveBillMasterQuery = MoveBillMasterRepository.GetQueryable(); string sysTime = System.DateTime.Now.ToString("yyMMdd"); var billNos = moveBillMasterQuery.Where(i => i.BillNo.Contains(sysTime)) .AsEnumerable() .OrderBy(i => i.BillNo) .Select(i => i.BillNo); if (billNos.Count() == 0) { billNo = System.DateTime.Now.ToString("yyMMdd") + "0001" + "MO"; } else { string billNoStr = billNos.Last(b => b.Contains(sysTime)); int i = Convert.ToInt32(billNoStr.ToString().Substring(6, 4)); i++; string newcode = i.ToString(); for (int j = 0; j < 4 - i.ToString().Length; j++) { newcode = "0" + newcode; } billNo = System.DateTime.Now.ToString("yyMMdd") + newcode + "MO"; } return(billNo); }
public bool Audit(string BillNo, string userName, out string strResult) { bool result = false; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1"); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (LockBillMaster(BillNo)) { if (mbm != null) { mbm.Status = "2"; mbm.VerifyDate = DateTime.Now; mbm.UpdateTime = DateTime.Now; mbm.VerifyPersonID = employee.ID; mbm.LockTag = string.Empty; MoveBillMasterRepository.SaveChanges(); result = true; } } else { result = false; } strResult = resultStr; return(result); }
public object GenMoveBillNo(string userName) { IQueryable <MoveBillMaster> moveBillMasterQuery = MoveBillMasterRepository.GetQueryable(); string sysTime = System.DateTime.Now.ToString("yyMMdd"); string billNo = ""; var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); var moveBillMaster = moveBillMasterQuery.Where(i => i.BillNo.Contains(sysTime)).ToArray().OrderBy(i => i.BillNo).Select(i => new { i.BillNo }.BillNo); if (moveBillMaster.Count() == 0) { billNo = System.DateTime.Now.ToString("yyMMdd") + "0001" + "MO"; } else { string billNoStr = moveBillMaster.Last(b => b.Contains(sysTime)); int i = Convert.ToInt32(billNoStr.ToString().Substring(6, 4)); i++; string newcode = i.ToString(); for (int j = 0; j < 4 - i.ToString().Length; j++) { newcode = "0" + newcode; } billNo = System.DateTime.Now.ToString("yyMMdd") + newcode + "MO"; } var findBillInfo = new { BillNo = billNo, billNoDate = DateTime.Now.ToString("yyyy-MM-dd"), employeeID = employee == null ? "" : employee.ID.ToString(), employeeCode = employee == null ? "" : employee.EmployeeCode.ToString(), employeeName = employee == null ? "" : employee.EmployeeName.ToString() }; return(findBillInfo); }
public bool Save(MoveBillMaster moveBillMaster, out string strResult) { bool result = false; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == moveBillMaster.BillNo && i.Status == "1"); if (LockBillMaster(moveBillMaster.BillNo)) { if (mbm != null) { mbm.BillDate = moveBillMaster.BillDate; mbm.BillTypeCode = moveBillMaster.BillTypeCode; mbm.WarehouseCode = moveBillMaster.WarehouseCode; mbm.OperatePersonID = moveBillMaster.OperatePersonID; mbm.Status = "1"; mbm.VerifyPersonID = moveBillMaster.VerifyPersonID; mbm.VerifyDate = moveBillMaster.VerifyDate; mbm.Description = moveBillMaster.Description; //mbm.IsActive = moveBillMaster.IsActive; mbm.IsActive = "1"; mbm.Origin = "1"; mbm.UpdateTime = DateTime.Now; mbm.LockTag = string.Empty; MoveBillMasterRepository.SaveChanges(); result = true; } } else { result = false; } strResult = resultStr; return(result); }
/// <summary> /// 对移库单进行加锁 /// </summary> /// <param name="BillNo">移库单号</param> /// <returns></returns> public bool LockBillMaster(string BillNo) { bool result = false; var pbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(p => p.BillNo == BillNo); if (pbm != null) { if (string.IsNullOrEmpty(pbm.LockTag)) { pbm.LockTag = BillNo; MoveBillMasterRepository.SaveChanges(); result = true; } else { resultStr = "当前订单其他人正在操作,请稍候重试!"; result = false; } } else { resultStr = "当前单据的状态不是已录入状态或者该单据已被删除无法编辑,请刷新页面!"; result = false; } return(result); }
public bool Add(MoveBillMaster moveBillMaster, string userName) { bool result = false; var mbm = new MoveBillMaster(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (employee != null) { mbm.BillNo = moveBillMaster.BillNo; mbm.BillDate = moveBillMaster.BillDate; mbm.BillTypeCode = moveBillMaster.BillTypeCode; mbm.WarehouseCode = moveBillMaster.WarehouseCode; mbm.OperatePersonID = employee.ID; mbm.Status = "1"; mbm.VerifyPersonID = moveBillMaster.VerifyPersonID; mbm.VerifyDate = moveBillMaster.VerifyDate; mbm.Description = moveBillMaster.Description; //mbm.IsActive = moveBillMaster.IsActive; mbm.IsActive = "1"; mbm.UpdateTime = DateTime.Now; mbm.Origin = "1"; MoveBillMasterRepository.Add(mbm); MoveBillMasterRepository.SaveChanges(); result = true; } return(result); }
/// <summary> /// 移库结单 /// </summary> /// <param name="BillNo">单据号</param> /// <param name="strResult">提示信息</param> /// <returns></returns> public bool Settle(string BillNo, out string strResult) { bool result = false; strResult = string.Empty; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(m => m.BillNo == BillNo); if (mbm != null && mbm.Status == "3") { using (var scope = new TransactionScope()) { try { //结单移库单,修改冻结量 var moveDetail = MoveBillDetailRepository.GetQueryable() .Where(m => m.BillNo == BillNo && m.Status != "2"); var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray(); var targetStorages = moveDetail.Select(m => m.InStorage).ToArray(); if (!Locker.Lock(sourceStorages) || !Locker.Lock(targetStorages)) { strResult = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!"; return(false); } moveDetail.AsParallel().ForAll( (Action <MoveBillDetail>) delegate(MoveBillDetail m) { if (m.InStorage.ProductCode == m.ProductCode && m.OutStorage.ProductCode == m.ProductCode && m.InStorage.InFrozenQuantity >= m.RealQuantity && m.OutStorage.OutFrozenQuantity >= m.RealQuantity) { m.InStorage.InFrozenQuantity -= m.RealQuantity; m.OutStorage.OutFrozenQuantity -= m.RealQuantity; m.InStorage.LockTag = string.Empty; m.OutStorage.LockTag = string.Empty; } else { throw new Exception("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能结单!"); } } ); MoveBillDetailRepository.SaveChanges(); mbm.Status = "4"; mbm.UpdateTime = DateTime.Now; MoveBillMasterRepository.SaveChanges(); result = true; scope.Complete(); } catch (Exception e) { strResult = "移库单结单出错!原因:" + e.Message; return(false); } } } return(result); }
public object GetMoveBillMaster() { var moveBillMaster = MoveBillMasterRepository.GetQueryable() .Where(i => i.Status == "2" || i.Status == "3") .Select(i => new { BillNo = i.BillNo, BillType = "3" }) .ToArray(); return(moveBillMaster); }
public bool GeneratePalletTag(string billNo, ref string strResult) { bool result = false; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(p => p.BillNo == billNo); if (mbm != null) { if (string.IsNullOrEmpty(mbm.LockTag)) { decimal i = 0; int j = 1; var details = mbm.MoveBillDetails.Where(d => (d.Product.AbcTypeCode == "2" || d.Product.AbcTypeCode == "3") && d.RealQuantity != (d.InCell.MaxQuantity * d.Unit.Count) && d.InCell.Area.AreaType != "3") .OrderBy(d => d.OutCellCode) .ToArray(); foreach (var detail in details) { if (detail.PalletTag == null) { if (detail.RealQuantity + i < 300000) { detail.PalletTag = j; i += detail.RealQuantity; } else { detail.PalletTag = ++j; i = detail.RealQuantity; } } else { strResult = "当前订单已组盘!"; return(true); } } MoveBillMasterRepository.SaveChanges(); result = true; } else { strResult = "当前订单其他人正在操作,请稍候重试!"; result = false; } } else { strResult = "当前单据的状态不是已录入状态或者该单据已被删除无法组盘!"; result = false; } return(result); }
public object GetDetails(int page, int rows, string BillNo, string WareHouseCode, string beginDate, string endDate, string OperatePersonCode, string CheckPersonCode, string Status, string IsActive) { IQueryable <MoveBillMaster> moveBillMasterQuery = MoveBillMasterRepository.GetQueryable(); var moveBillMaster = moveBillMasterQuery.Where(i => i.BillNo.Contains(BillNo) && i.Status != "4" && i.WarehouseCode.Contains(WareHouseCode) && i.OperatePerson.EmployeeCode.Contains(OperatePersonCode) && i.Status.Contains(Status)) .OrderByDescending(t => t.BillDate) .OrderByDescending(t => t.BillNo) .Select(i => i); if (!beginDate.Equals(string.Empty)) { DateTime begin = Convert.ToDateTime(beginDate); moveBillMaster = moveBillMaster.Where(i => i.BillDate >= begin); } if (!endDate.Equals(string.Empty)) { DateTime end = Convert.ToDateTime(endDate).AddDays(1); moveBillMaster = moveBillMaster.Where(i => i.BillDate <= end); } if (!CheckPersonCode.Equals(string.Empty)) { moveBillMaster = moveBillMaster.Where(i => i.VerifyPerson.EmployeeCode == CheckPersonCode); } int total = moveBillMaster.Count(); moveBillMaster = moveBillMaster.Skip((page - 1) * rows).Take(rows); var temp = moveBillMaster.ToArray().AsEnumerable().Select(i => new { i.BillNo, BillDate = i.BillDate.ToString("yyyy-MM-dd HH:mm:ss"), i.OperatePersonID, i.WarehouseCode, i.BillTypeCode, i.BillType.BillTypeName, i.Warehouse.WarehouseName, OperatePersonCode = i.OperatePerson.EmployeeCode, OperatePersonName = i.OperatePerson.EmployeeName, VerifyPersonID = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeCode, VerifyPersonName = i.VerifyPersonID == null ? string.Empty : i.VerifyPerson.EmployeeName, SumQuantity = i.MoveBillDetails.Sum(s => s.RealQuantity / s.Product.Unit.Count), VerifyDate = (i.VerifyDate == null ? "" : ((DateTime)i.VerifyDate).ToString("yyyy-MM-dd HH:mm:ss")), Status = WhatStatus(i.Status), IsActive = i.IsActive == "1" ? "可用" : "不可用", Description = i.Description, UpdateTime = i.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss") }); return(new { total, rows = temp.ToArray() }); }
public bool AllotCancelConfirm(string billNo, out string strResult) { bool result = false; var ibm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "4"); if (ibm != null) { if (string.IsNullOrEmpty(ibm.LockTag)) { try { using (var scope = new TransactionScope()) { if (ibm.MoveBillMaster != null) { try { MoveBillCreater.DeleteMoveBillDetail(ibm.MoveBillMaster); MoveBillMasterRepository.Delete(ibm.MoveBillMaster); MoveBillMasterRepository.SaveChanges(); } catch (Exception) { strResult = "删除同步移库单失败,请重新取消!"; return(false); } } ibm.Status = "3"; ibm.UpdateTime = DateTime.Now; OutBillMasterRepository.SaveChanges(); result = true; strResult = "取消成功"; scope.Complete(); } } catch (Exception) { strResult = "当前订单其他人正在操作,请稍候重试!"; } } else { strResult = "当前订单其他人正在操作,请稍候重试!"; } } else { strResult = "当前订单状态不是已确认,或当前订单不存在!"; } return(result); }
public bool AntiTrial(string id, ref string errorInfo) { try { Guid ID = new Guid(id); var sortWork = SortWorkDispatchRepository.GetQueryable() .FirstOrDefault(s => s.ID == ID); if (sortWork == null) { errorInfo = "当前选择的调度记录不存在,未能反审!"; return(false); } if (sortWork.DispatchStatus != "2") { errorInfo = "当前选择的调度记录不是已审核,未能反审!"; return(false); } if (sortWork.OutBillMaster.Status != "2") { errorInfo = "当前选择的调度记录出库单不是已审核,未能反审!"; return(false); } if (sortWork.MoveBillMaster.Status != "2") { errorInfo = "当前选择的调度记录移库单不是已审核,未能反审!"; return(false); } using (var scope = new TransactionScope()) { //出库反审 var outMaster = OutBillMasterRepository.GetQueryable().FirstOrDefault(o => o.BillNo == sortWork.OutBillNo); outMaster.Status = "1"; outMaster.UpdateTime = DateTime.Now; //移库反审 var moveMater = MoveBillMasterRepository.GetQueryable().FirstOrDefault(m => m.BillNo == sortWork.MoveBillNo); moveMater.Status = "1"; moveMater.UpdateTime = DateTime.Now; //分拣作业反审 sortWork.DispatchStatus = "1"; sortWork.UpdateTime = DateTime.Now; SortWorkDispatchRepository.SaveChanges(); scope.Complete(); return(true); } } catch (Exception e) { errorInfo = "反审失败,详情:" + e.Message; return(false); } }
public bool GeneratePalletTag(string billNo, ref string strResult) { bool result = false; var mbms = MoveBillMasterRepository.GetQueryable().Where(p => billNo.Contains(p.BillNo)); IEnumerable <MoveBillDetail> tempDetails = new MoveBillDetail[] { }; foreach (var mbm in mbms) { tempDetails = tempDetails.Concat(mbm.MoveBillDetails); } decimal i = 0; int j = 1; var details = tempDetails.Where(d => (d.Product.AbcTypeCode == "2" || d.Product.AbcTypeCode == "3") && d.RealQuantity != (d.InCell.MaxQuantity * d.Unit.Count) && d.InCell.Area.AreaType != "3") .OrderBy(d => d.OutCellCode) .ToArray(); foreach (var detail in details) { if (detail.PalletTag == null) { if (detail.RealQuantity + i < 300000) { detail.PalletTag = j; i += detail.RealQuantity; } else { detail.PalletTag = ++j; i = detail.RealQuantity; } } else { strResult = "当前订单已组盘!"; return(true); } } MoveBillMasterRepository.SaveChanges(); result = true; return(result); }
public MoveBillMaster CreateMoveBillMaster(string warehouseCode, string billTypeCode, string operatePersonID) { //添加移库单主单 string billNo = CreateMoveBillNo(); MoveBillMaster moveBillMaster = new MoveBillMaster(); moveBillMaster.BillNo = billNo; moveBillMaster.BillDate = DateTime.Now; moveBillMaster.BillTypeCode = billTypeCode; moveBillMaster.Origin = "1"; moveBillMaster.WarehouseCode = warehouseCode; moveBillMaster.OperatePersonID = Guid.Parse(operatePersonID); moveBillMaster.Status = "1"; moveBillMaster.IsActive = "1"; moveBillMaster.UpdateTime = DateTime.Now; MoveBillMasterRepository.Add(moveBillMaster); return(moveBillMaster); }
public object GetMoveBillMaster() { string str = ""; var moveBillDetail = MoveBillDetailRepository.GetQueryable().Where(i => i.Status != "2").Select(b => b.BillNo).ToArray(); for (int i = 0; i < moveBillDetail.Length; i++) { str += moveBillDetail[i]; } var moveBillMaster = MoveBillMasterRepository.GetQueryable().ToArray().Where(i => str.Contains(i.BillNo) && i.Status != "6") .Distinct() .OrderByDescending(t => t.BillDate) .Select(i => new { BillNo = i.BillNo }); return(moveBillMaster); }
public bool AntiTrial(string BillNo, out string strResult) { bool result = false; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "2"); if (LockBillMaster(BillNo)) { if (mbm != null) { mbm.Status = "1"; mbm.VerifyDate = null; mbm.UpdateTime = DateTime.Now; mbm.VerifyPersonID = null; mbm.LockTag = string.Empty; MoveBillMasterRepository.SaveChanges(); result = true; } } strResult = resultStr; return(result); }
public bool Add(MoveBillMaster moveBillMaster, string userName, out string strResult) { strResult = string.Empty; bool result = false; var mbm = new MoveBillMaster(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (employee != null) { try { mbm.BillNo = moveBillMaster.BillNo; mbm.BillDate = moveBillMaster.BillDate; mbm.BillTypeCode = moveBillMaster.BillTypeCode; mbm.WarehouseCode = moveBillMaster.WarehouseCode; mbm.OperatePersonID = employee.ID; mbm.Status = "1"; mbm.VerifyPersonID = moveBillMaster.VerifyPersonID; mbm.VerifyDate = moveBillMaster.VerifyDate; mbm.Description = moveBillMaster.Description; //mbm.IsActive = moveBillMaster.IsActive; mbm.IsActive = "1"; mbm.UpdateTime = DateTime.Now; mbm.Origin = "1"; MoveBillMasterRepository.Add(mbm); MoveBillMasterRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "新增失败,原因:" + ex.Message; } } else { strResult = "找不到当前登陆用户!请重新登陆!"; } return(result); }
public bool AntiTrial(string BillNo, out string strResult) { strResult = string.Empty; bool result = false; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "2"); if (LockBillMaster(BillNo)) { if (mbm != null) { try { mbm.Status = "1"; mbm.VerifyDate = null; mbm.UpdateTime = DateTime.Now; mbm.VerifyPersonID = null; mbm.LockTag = string.Empty; MoveBillMasterRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "反审失败,原因:" + ex.Message; } } else { strResult = "反审失败,未找到该条数据!"; result = false; } } else { strResult = resultStr; result = false; } return(result); }
public bool Delete(string BillNo, out string strResult) { bool result = false; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1"); if (LockBillMaster(BillNo)) { if (mbm != null) { MoveBillCreater.DeleteMoveBillDetail(mbm); Del(MoveBillDetailRepository, mbm.MoveBillDetails); MoveBillMasterRepository.Delete(mbm); MoveBillMasterRepository.SaveChanges(); result = true; } } else { result = false; } strResult = resultStr; return(result); }
public bool Delete(string BillNo, out string strResult) { strResult = string.Empty; bool result = false; var mbm = MoveBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1"); if (LockBillMaster(BillNo)) { if (mbm != null) { try { MoveBillCreater.DeleteMoveBillDetail(mbm); Del(MoveBillDetailRepository, mbm.MoveBillDetails); MoveBillMasterRepository.Delete(mbm); MoveBillMasterRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "删除失败,原因:" + ex.Message; } } else { strResult = "删除失败!未找到当前需要删除的数据!"; result = false; } } else { strResult = resultStr; result = false; } return(result); }
public void Dispatch(string connectionId, Model.ProgressState ps, CancellationToken cancellationToken, string workDispatchId, string userName) { Locker.LockKey = workDispatchId; ConnectionId = connectionId; ps.State = StateType.Start; NotifyConnection(ps.Clone()); IQueryable <SortOrderDispatch> sortOrderDispatchQuery = SortOrderDispatchRepository.GetQueryable(); IQueryable <SortOrder> sortOrderQuery = SortOrderRepository.GetQueryable(); IQueryable <SortOrderDetail> sortOrderDetailQuery = SortOrderDetailRepository.GetQueryable(); IQueryable <OutBillMaster> outBillMasterQuery = OutBillMasterRepository.GetQueryable(); IQueryable <OutBillDetail> outBillDetailQuery = OutBillDetailRepository.GetQueryable(); IQueryable <MoveBillMaster> moveBillMasterQuery = MoveBillMasterRepository.GetQueryable(); IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); IQueryable <SortingLowerlimit> sortingLowerlimitQuery = SortingLowerlimitRepository.GetQueryable(); IQueryable <SortingLine> sortingLineQuery = SortingLineRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); IQueryable <SortWorkDispatch> sortWorkDispatchQuery = SortWorkDispatchRepository.GetQueryable(); IQueryable <THOK.Authority.DbModel.SystemParameter> systemParQuery = SystemParameterRepository.GetQueryable(); var IsUselowerlimit = systemParQuery.FirstOrDefault(s => s.ParameterName == "IsUselowerlimit"); //查询调度是否使用下限 0 否 1是 var isRoundingTray = systemParQuery.FirstOrDefault(s => s.ParameterName == "isRoundingTray"); //查询立式机总量大于20件的是否取整托盘 0表示不取整托盘。其它任意数字表示大于的总数 workDispatchId = workDispatchId.Substring(0, workDispatchId.Length - 1); int[] work = workDispatchId.Split(',').Select(s => Convert.ToInt32(s)).ToArray(); //调度表未作业的数据 var temp = sortOrderDispatchQuery.Join(sortOrderQuery, dp => new { dp.OrderDate, dp.DeliverLineCode }, om => new { om.OrderDate, om.DeliverLineCode }, (dp, om) => new { dp.ID, dp.WorkStatus, dp.OrderDate, dp.SortingLine, dp.DeliverLineCode, om.OrderID } ).Join(sortOrderDetailQuery, dm => new { dm.OrderID }, od => new { od.OrderID }, (dm, od) => new { dm.ID, dm.WorkStatus, dm.OrderDate, dm.SortingLine, od.Product, od.UnitCode, od.Price, od.RealQuantity } ).WhereIn(s => s.ID, work) .Where(s => s.WorkStatus == "1") .GroupBy(r => new { r.OrderDate, r.SortingLine, r.Product, r.UnitCode, r.Price }) .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, r.Key.Product, r.Key.UnitCode, r.Key.Price, SumQuantity = r.Sum(p => p.RealQuantity * r.Key.Product.UnitList.Unit02.Count) }) .AsParallel() .GroupBy(r => new { r.OrderDate, r.SortingLine }) .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, Products = r }) .OrderBy(s => s.SortingLine.SortingLineCode) //如果取整托盘多余的量是1号线就倒序排序,目前多余的量放入2号线,所以先调度一号线 .ToArray(); var temp1 = sortingLowerlimitQuery.GroupBy(r => new { r.Product, r.SortType }) .Select(s => new { s.Key.Product, s.Key.SortType }).ToArray(); var temp2 = sortOrderDispatchQuery.Join(sortOrderQuery, dp => new { dp.OrderDate, dp.DeliverLineCode }, om => new { om.OrderDate, om.DeliverLineCode }, (dp, om) => new { dp.ID, dp.WorkStatus, dp.OrderDate, om.OrderID } ).Join(sortOrderDetailQuery, dm => new { dm.OrderID }, od => new { od.OrderID }, (dm, od) => new { dm.ID, dm.WorkStatus, od.Product, od.RealQuantity } ).WhereIn(s => s.ID, work) .GroupBy(r => new { r.Product }) .Select(s => new { s.Key.Product, Quantity = s.Sum(p => p.RealQuantity * s.Key.Product.UnitList.Unit02.Count) }) .ToArray(); Dictionary <string, decimal> proQuan = new Dictionary <string, decimal>(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); string operatePersonID = employee != null?employee.ID.ToString() : ""; if (employee == null) { ps.State = StateType.Error; ps.Errors.Add("未找到当前用户,或当前用户不可用!"); NotifyConnection(ps.Clone()); return; } decimal sumAllotQuantity = 0; decimal sumAllotLineQuantity = 0; MoveBillMaster lastMoveBillMaster = null; foreach (var item in temp) { try { if (cancellationToken.IsCancellationRequested) { return; } bool hasError = false; ps.State = StateType.Info; ps.Messages.Add("开始调度" + item.SortingLine.SortingLineName); NotifyConnection(ps.Clone()); //using (var scope = new TransactionScope()) //{ if (item.Products.Count() > 0) { if (cancellationToken.IsCancellationRequested) { return; } if (lastMoveBillMaster != null && lastMoveBillMaster.WarehouseCode != item.SortingLine.Cell.WarehouseCode) { if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode)) { MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster); } } sumAllotLineQuantity = 0; if (cancellationToken.IsCancellationRequested) { return; } MoveBillMaster moveBillMaster = MoveBillCreater.CreateMoveBillMaster(item.SortingLine.Cell.WarehouseCode, item.SortingLine.MoveBillTypeCode, operatePersonID); moveBillMaster.Origin = "2"; moveBillMaster.Description = item.SortingLine.SortingLineCode + " 分拣调度生成!"; lastMoveBillMaster = moveBillMaster; foreach (var product in item.Products.ToArray()) { if (product.SumQuantity > 0) { if (cancellationToken.IsCancellationRequested) { return; } decimal sumBillQuantity = temp.Sum(t => t.Products.Sum(p => p.SumQuantity)); sumAllotQuantity += product.SumQuantity; decimal sumBillProductQuantity = item.Products.Sum(p => p.SumQuantity); sumAllotLineQuantity += product.SumQuantity; ps.State = StateType.Processing; ps.TotalProgressName = "分拣作业调度"; ps.TotalProgressValue = (int)(sumAllotQuantity / sumBillQuantity * 100); ps.CurrentProgressName = "正在调度:" + item.SortingLine.SortingLineName; ps.CurrentProgressValue = (int)(sumAllotLineQuantity / sumBillProductQuantity * 100); NotifyConnection(ps.Clone()); if (cancellationToken.IsCancellationRequested) { return; } //获取分拣线下限数据 var sortingLowerlimitQuantity = sortingLowerlimitQuery.Where(s => s.ProductCode == product.Product.ProductCode && s.SortingLineCode == product.SortingLine.SortingLineCode); decimal lowerlimitQuantity = 0; if (sortingLowerlimitQuantity.Count() > 0) { lowerlimitQuantity = sortingLowerlimitQuantity.Sum(s => s.Quantity); } if (cancellationToken.IsCancellationRequested) { return; } //获取分拣备货区库存 var storageQuantity = storageQuery.Where(s => s.ProductCode == product.Product.ProductCode) .Join(sortingLineQuery, s => s.Cell, l => l.Cell, (s, l) => new { l.SortingLineCode, s.Quantity } ) .Where(r => r.SortingLineCode == product.SortingLine.SortingLineCode); decimal storQuantity = 0; if (storageQuantity.Count() > 0) { storQuantity = storageQuantity.Sum(s => s.Quantity); } //获取当前这个卷烟库存数量 string[] areaTypes = new string[] { "1", "2", "4" }; var areaSumQuantitys = storageQuery.Where(s => areaTypes.Any(t => t == s.Cell.Area.AreaType) && s.ProductCode == product.Product.ProductCode).ToArray(); decimal areaQuantiy = 0; if (areaSumQuantitys.Count() > 0) { areaQuantiy = areaSumQuantitys.Sum(s => s.Quantity - s.OutFrozenQuantity); } //是否使用下限 if (IsUselowerlimit != null && IsUselowerlimit.ParameterValue == "0") { lowerlimitQuantity = 0; } if (cancellationToken.IsCancellationRequested) { return; } //获取移库量(按整件计)出库量加上下限量减去备货区库存量取整 decimal quantity = 0; quantity = Math.Ceiling((product.SumQuantity + lowerlimitQuantity - storQuantity) / product.Product.Unit.Count) * product.Product.Unit.Count; //立式机大于20件的取整托盘 //查询这个卷烟是否是立式机的卷烟 if (isRoundingTray != null && Convert.ToInt32(isRoundingTray.ParameterValue) > 0) { var temp3 = temp1.FirstOrDefault(s => s.Product.ProductCode == product.Product.ProductCode && s.SortType == "1"); if (temp3 != null && temp.Count() >= 2 && quantity > 0) { //查询这个订单在分拣当中是否存在.大于20件取整托盘, var SumlowerlimitQuantity = temp2.FirstOrDefault(s => s.Product.ProductCode == temp3.Product.ProductCode); if (SumlowerlimitQuantity != null && SumlowerlimitQuantity.Quantity > (Convert.ToInt32(isRoundingTray.ParameterValue) * product.Product.Unit.Count)) { decimal WholeCare = 0; //托盘数 decimal SumSortingQuantity = 0; //整托盘的数量 decimal Quantity1 = 0; decimal Quantity2 = 0; //取2条线数量总和取整托盘 WholeCare = Math.Ceiling(SumlowerlimitQuantity.Quantity / (product.Product.CellMaxProductQuantity * product.Product.Unit.Count)); SumSortingQuantity = Convert.ToDecimal(WholeCare * (product.Product.Unit.Count * product.Product.CellMaxProductQuantity)); if (item.SortingLine.SortingLineCode == "1") { //总订单量减去当前分拣线订单量,这里是另一条线的量 Quantity1 = SumlowerlimitQuantity.Quantity - product.SumQuantity; if (Quantity1 > 0) { //整托盘数量减去另一条线的量, Quantity1 = Math.Ceiling(Quantity1 / product.Product.Unit.Count) * product.Product.Unit.Count; Quantity2 = SumSortingQuantity - Quantity1; if (Quantity2 >= quantity) { quantity = Quantity2; proQuan.Add(product.Product.ProductCode, SumSortingQuantity - quantity); } } } else { if (proQuan.Keys.Contains(product.Product.ProductCode)) { if (proQuan[product.Product.ProductCode] >= quantity) { quantity = proQuan[product.Product.ProductCode]; } } } } } } //取整托盘,查询这个卷烟是否是通道机的卷烟 decimal wholeTray = 0; var temp4 = temp1.FirstOrDefault(s => s.Product.ProductCode == product.Product.ProductCode && s.SortType == "2"); if (product.Product.IsRounding == "2" || temp4 != null) { wholeTray = Math.Ceiling(quantity / (product.Product.CellMaxProductQuantity * product.Product.Unit.Count)); quantity = Convert.ToDecimal(wholeTray * (product.Product.Unit.Count * product.Product.CellMaxProductQuantity)); } if (areaQuantiy < quantity) //判断当前这个卷烟库存是否小于移库量 { //出库量减去备货区库存量取整 quantity = Math.Ceiling((product.SumQuantity - storQuantity) / product.Product.Unit.Count) * product.Product.Unit.Count; if (areaQuantiy < quantity) { //出库量减去备货区库存量 quantity = product.SumQuantity - storQuantity; } } //不取整的烟直接出库。 if (product.Product.IsRounding == "1") { quantity = product.SumQuantity - storQuantity; } if (quantity > 0) { if (cancellationToken.IsCancellationRequested) { return; } AlltoMoveBill(moveBillMaster, product.Product, item.SortingLine.Cell, ref quantity, cancellationToken, ps, item.SortingLine.Cell.CellCode); } if (quantity > 0) { //生成移库不完整,可能是库存不足; hasError = true; ps.State = StateType.Error; ps.Errors.Add(item.SortingLine.SortingLineCode + "线," + product.Product.ProductCode + " " + product.Product.ProductName + ",库存不足!当前总量:" + Convert.ToDecimal(product.SumQuantity / product.Product.UnitList.Unit02.Count) + "(条),缺少:" + Convert.ToDecimal(quantity / product.Product.UnitList.Unit02.Count) + "(条)"); NotifyConnection(ps.Clone()); } } } if (!hasError) { if (cancellationToken.IsCancellationRequested) { return; } OutBillMaster outBillMaster = OutBillCreater.CreateOutBillMaster(item.SortingLine.Cell.WarehouseCode, item.SortingLine.OutBillTypeCode, operatePersonID); outBillMaster.Origin = "2"; outBillMaster.Description = item.SortingLine.SortingLineCode + " 分拣调度生成!"; //添加出库单细单 foreach (var product in item.Products.ToArray()) { if (cancellationToken.IsCancellationRequested) { return; } OutBillCreater.AddToOutBillDetail(outBillMaster, product.Product, product.Price, product.SumQuantity); } if (cancellationToken.IsCancellationRequested) { return; } //添加出库、移库主单和作业调度表 SortWorkDispatch sortWorkDisp = AddSortWorkDispMaster(moveBillMaster, outBillMaster, item.SortingLine.SortingLineCode, item.OrderDate); //修改线路调度作业状态和作业ID var sortDispTemp = sortOrderDispatchQuery.WhereIn(s => s.ID, work) .Where(s => s.OrderDate == item.OrderDate && s.SortingLineCode == item.SortingLine.SortingLineCode); foreach (var sortDisp in sortDispTemp.ToArray()) { if (cancellationToken.IsCancellationRequested) { return; } sortDisp.SortWorkDispatchID = sortWorkDisp.ID; sortDisp.WorkStatus = "2"; } if (cancellationToken.IsCancellationRequested) { return; } SortWorkDispatchRepository.SaveChanges(); //scope.Complete(); ps.Messages.Add(item.SortingLine.SortingLineName + " 调度成功!"); } else { ps.State = StateType.Info; ps.Messages.Add(item.SortingLine.SortingLineName + " 调度失败!"); NotifyConnection(ps.Clone()); return; } } //} } catch (Exception e) { ps.State = StateType.Info; ps.Errors.Add(item.SortingLine.SortingLineName + "作业调度失败! 详情:" + e.Message); NotifyConnection(ps.Clone()); return; } } if (cancellationToken.IsCancellationRequested) { return; } if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode)) { MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster); } MoveBillMasterRepository.SaveChanges(); ps.State = StateType.Info; ps.Messages.Add("调度完成!"); NotifyConnection(ps.Clone()); }
public void Dispatch(string connectionId, Model.ProgressState ps, CancellationToken cancellationToken, string workDispatchId, string userName) { Locker.LockKey = workDispatchId; ConnectionId = connectionId; ps.State = StateType.Start; NotifyConnection(ps.Clone()); IQueryable <SortOrderDispatch> sortOrderDispatchQuery = SortOrderDispatchRepository.GetQueryable(); IQueryable <SortOrder> sortOrderQuery = SortOrderRepository.GetQueryable(); IQueryable <SortOrderDetail> sortOrderDetailQuery = SortOrderDetailRepository.GetQueryable(); IQueryable <OutBillMaster> outBillMasterQuery = OutBillMasterRepository.GetQueryable(); IQueryable <OutBillDetail> outBillDetailQuery = OutBillDetailRepository.GetQueryable(); IQueryable <MoveBillMaster> moveBillMasterQuery = MoveBillMasterRepository.GetQueryable(); IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); IQueryable <SortingLowerlimit> sortingLowerlimitQuery = SortingLowerlimitRepository.GetQueryable(); IQueryable <SortingLine> sortingLineQuery = SortingLineRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); IQueryable <SortWorkDispatch> sortWorkDispatchQuery = SortWorkDispatchRepository.GetQueryable(); workDispatchId = workDispatchId.Substring(0, workDispatchId.Length - 1); int[] work = workDispatchId.Split(',').Select(s => Convert.ToInt32(s)).ToArray(); //调度表未作业的数据 var temp = sortOrderDispatchQuery.Where(s => work.Any(w => w == s.ID) && s.WorkStatus == "1") .Join(sortOrderQuery, dp => new { dp.OrderDate, dp.DeliverLineCode }, om => new { om.OrderDate, om.DeliverLineCode }, (dp, om) => new { dp.OrderDate, dp.SortingLine, dp.DeliverLineCode, om.OrderID } ).Join(sortOrderDetailQuery, dm => new { dm.OrderID }, od => new { od.OrderID }, (dm, od) => new { dm.OrderDate, dm.SortingLine, od.Product, od.UnitCode, od.Price, od.RealQuantity } ).GroupBy(r => new { r.OrderDate, r.SortingLine, r.Product, r.UnitCode, r.Price }) .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, r.Key.Product, r.Key.UnitCode, r.Key.Price, SumQuantity = r.Sum(p => p.RealQuantity * r.Key.Product.UnitList.Unit02.Count) }) .GroupBy(r => new { r.OrderDate, r.SortingLine }) .Select(r => new { r.Key.OrderDate, r.Key.SortingLine, Products = r }) .ToArray(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); string operatePersonID = employee != null?employee.ID.ToString() : ""; if (employee == null) { ps.State = StateType.Error; ps.Errors.Add("未找到当前用户,或当前用户不可用!"); NotifyConnection(ps.Clone()); return; } decimal sumAllotQuantity = 0; decimal sumAllotLineQuantity = 0; MoveBillMaster lastMoveBillMaster = null; foreach (var item in temp) { try { if (cancellationToken.IsCancellationRequested) { return; } bool hasError = false; ps.State = StateType.Info; ps.Messages.Add("开始调度" + item.SortingLine.SortingLineName); NotifyConnection(ps.Clone()); using (var scope = new TransactionScope()) { if (item.Products.Count() > 0) { if (cancellationToken.IsCancellationRequested) { return; } if (lastMoveBillMaster != null && lastMoveBillMaster.WarehouseCode != item.SortingLine.Cell.WarehouseCode) { if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode)) { MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster); } } sumAllotLineQuantity = 0; if (cancellationToken.IsCancellationRequested) { return; } MoveBillMaster moveBillMaster = MoveBillCreater.CreateMoveBillMaster(item.SortingLine.Cell.WarehouseCode, item.SortingLine.MoveBillTypeCode, operatePersonID); moveBillMaster.Origin = "2"; moveBillMaster.Description = "分拣调度生成!"; lastMoveBillMaster = moveBillMaster; foreach (var product in item.Products.ToArray()) { if (cancellationToken.IsCancellationRequested) { return; } decimal sumBillQuantity = temp.Sum(t => t.Products.Sum(p => p.SumQuantity)); sumAllotQuantity += product.SumQuantity; decimal sumBillProductQuantity = item.Products.Sum(p => p.SumQuantity); sumAllotLineQuantity += product.SumQuantity; ps.State = StateType.Processing; ps.TotalProgressName = "分拣作业调度"; ps.TotalProgressValue = (int)(sumAllotQuantity / sumBillQuantity * 100); ps.CurrentProgressName = "正在调度:" + item.SortingLine.SortingLineName; ps.CurrentProgressValue = (int)(sumAllotLineQuantity / sumBillProductQuantity * 100); NotifyConnection(ps.Clone()); if (cancellationToken.IsCancellationRequested) { return; } //获取分拣线下限数据 var sortingLowerlimitQuantity = sortingLowerlimitQuery.Where(s => s.ProductCode == product.Product.ProductCode && s.SortingLineCode == product.SortingLine.SortingLineCode); decimal lowerlimitQuantity = 0; if (sortingLowerlimitQuantity.Count() > 0) { lowerlimitQuantity = sortingLowerlimitQuantity.Sum(s => s.Quantity); } if (cancellationToken.IsCancellationRequested) { return; } //获取分拣备货区库存 var storageQuantity = storageQuery.Where(s => s.ProductCode == product.Product.ProductCode) .Join(sortingLineQuery, s => s.Cell, l => l.Cell, (s, l) => new { l.SortingLineCode, s.Quantity } ) .Where(r => r.SortingLineCode == product.SortingLine.SortingLineCode); decimal storQuantity = 0; if (storageQuantity.Count() > 0) { storQuantity = storageQuantity.Sum(s => s.Quantity); } //获取当前这个卷烟库存数量 string[] areaTypes = new string[] { "1", "2", "4" }; var areaSumQuantitys = storageQuery.Where(s => areaTypes.Any(t => t == s.Cell.Area.AreaType) && s.ProductCode == product.Product.ProductCode).ToArray(); decimal areaQuantiy = 0; if (areaSumQuantitys.Count() > 0) { areaQuantiy = areaSumQuantitys.Sum(s => s.Quantity - s.OutFrozenQuantity); } if (cancellationToken.IsCancellationRequested) { return; } //获取移库量(按整件计)出库量加上下限量减去备货区库存量取整 decimal quantity = 0; quantity = Math.Ceiling((product.SumQuantity + lowerlimitQuantity - storQuantity) / product.Product.Unit.Count) * product.Product.Unit.Count; if (areaQuantiy < quantity)//判断当前这个卷烟库存是否小于移库量 { //出库量减去备货区库存量取整 quantity = Math.Ceiling((product.SumQuantity - storQuantity) / product.Product.Unit.Count) * product.Product.Unit.Count; if (areaQuantiy < quantity) { //出库量减去备货区库存量 quantity = product.SumQuantity - storQuantity; } } if (quantity > 0) { if (cancellationToken.IsCancellationRequested) { return; } AlltoMoveBill(moveBillMaster, product.Product, item.SortingLine.Cell, ref quantity, cancellationToken, ps, item.SortingLine.Cell.CellCode); } if (quantity > 0) { //生成移库不完整,可能是库存不足; hasError = true; ps.State = StateType.Error; ps.Errors.Add(product.Product.ProductCode + " " + product.Product.ProductName + " 库存不足!"); NotifyConnection(ps.Clone()); } } if (!hasError) { if (cancellationToken.IsCancellationRequested) { return; } OutBillMaster outBillMaster = OutBillCreater.CreateOutBillMaster(item.SortingLine.Cell.WarehouseCode, item.SortingLine.OutBillTypeCode, operatePersonID); outBillMaster.Origin = "2"; outBillMaster.Description = "分拣调度生成!"; //添加出库单细单 foreach (var product in item.Products.ToArray()) { if (cancellationToken.IsCancellationRequested) { return; } OutBillCreater.AddToOutBillDetail(outBillMaster, product.Product, product.Price, product.SumQuantity); } if (cancellationToken.IsCancellationRequested) { return; } //添加出库、移库主单和作业调度表 SortWorkDispatch sortWorkDisp = AddSortWorkDispMaster(moveBillMaster, outBillMaster, item.SortingLine.SortingLineCode, item.OrderDate); //修改线路调度作业状态和作业ID var sortDispTemp = sortOrderDispatchQuery.Where(s => work.Any(w => w == s.ID) && s.OrderDate == item.OrderDate && s.SortingLineCode == item.SortingLine.SortingLineCode); foreach (var sortDisp in sortDispTemp.ToArray()) { if (cancellationToken.IsCancellationRequested) { return; } sortDisp.SortWorkDispatchID = sortWorkDisp.ID; sortDisp.WorkStatus = "2"; } if (cancellationToken.IsCancellationRequested) { return; } SortWorkDispatchRepository.SaveChanges(); scope.Complete(); ps.Messages.Add(item.SortingLine.SortingLineName + " 调度成功!"); } else { ps.State = StateType.Info; ps.Messages.Add(item.SortingLine.SortingLineName + " 调度失败!"); NotifyConnection(ps.Clone()); return; } } } if (cancellationToken.IsCancellationRequested) { return; } if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode)) { MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster); } MoveBillMasterRepository.SaveChanges(); } catch (Exception e) { ps.State = StateType.Info; ps.Errors.Add(item.SortingLine.SortingLineName + "作业调度失败! 详情:" + e.Message); NotifyConnection(ps.Clone()); return; } } ps.State = StateType.Info; ps.Messages.Add("调度完成!"); NotifyConnection(ps.Clone()); }
public bool LowerLimitMoveLibrary(string userName, bool isEnableStocking, out string errorInfo) { IQueryable <SortingLowerlimit> sortingLowerlimitQuery = SortingLowerlimitRepository.GetQueryable(); IQueryable <SortingLine> sortingLineQuery = SortingLineRepository.GetQueryable(); IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); bool Result = true; errorInfo = string.Empty; var sortLowerlimit = sortingLowerlimitQuery.Where(s => s.Quantity > 0) .GroupBy(s => new { s.SortingLine, s.Product, s.UnitCode }) .Select(l => new { l.Key.SortingLine, l.Key.Product, l.Key.UnitCode, SumQuantity = l.Sum(p => p.Quantity) }) .GroupBy(o => new { o.SortingLine }) .Select(t => new { t.Key.SortingLine, product = t }) .ToArray(); string cellCode = ""; var sortings = sortingLineQuery.Where(s => s.SortingLineCode == s.SortingLineCode).ToArray(); foreach (var sort in sortings) { cellCode += sort.Cell.CellCode; } var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); string operatePersonID = employee != null?employee.ID.ToString() : ""; MoveBillMaster lastMoveBillMaster = null; if (sortLowerlimit.Count() > 0) { foreach (var item in sortLowerlimit) { if (item.product.Count() > 0) { if (lastMoveBillMaster != null && lastMoveBillMaster.WarehouseCode != item.SortingLine.Cell.WarehouseCode) { if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode)) { MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster); } } MoveBillMaster moveBillMaster = MoveBillCreater.CreateMoveBillMaster(item.SortingLine.Cell.WarehouseCode, item.SortingLine.MoveBillTypeCode, operatePersonID); moveBillMaster.Origin = "1"; moveBillMaster.Description = "根据 " + item.SortingLine.SortingLineName + "下限生成移库单!"; bool hasError = false; lastMoveBillMaster = moveBillMaster; foreach (var product in item.product.ToArray()) { //获取分拣备货区库存 var storageQuantity = storageQuery.Where(s => s.ProductCode == product.Product.ProductCode) .Join(sortingLineQuery, s => s.Cell, l => l.Cell, (s, l) => new { l.SortingLineCode, s.Quantity } ) .Where(r => r.SortingLineCode == product.SortingLine.SortingLineCode); decimal storQuantity = 0; if (storageQuantity.Count() > 0) { storQuantity = storageQuantity.Sum(s => s.Quantity); } //获取移库量(按整件计) decimal quantity = 0; if (isEnableStocking) { quantity = Math.Ceiling(product.SumQuantity - storQuantity); } else { quantity = Math.Ceiling(product.SumQuantity); } CancellationToken cancellationToken = new CancellationToken(); ProgressState ps = new ProgressState(); AlltoMoveBill(moveBillMaster, product.Product, item.SortingLine.Cell, ref quantity, cancellationToken, ps, cellCode); if (quantity > 0) { //生成移库不完整,可能是库存不足; hasError = true; errorInfo += item.SortingLine.SortingLineName + " 卷烟:" + product.Product.ProductCode + "(" + product.Product.ProductName + ") 库存不足!"; } } if (!hasError && Result) { MoveBillMasterRepository.SaveChanges(); errorInfo += "分拣线:" + item.SortingLine.SortingLineName + " 根据下限生成移库单成功!"; if (lastMoveBillMaster != null) { if (MoveBillCreater.CheckIsNeedSyncMoveBill(lastMoveBillMaster.WarehouseCode)) { MoveBillCreater.CreateSyncMoveBillDetail(lastMoveBillMaster); } } MoveBillMasterRepository.SaveChanges(); } else { Result = false; } } } } return(Result); }
public bool Delete(string id, ref string errorInfo) { try { Guid ID = new Guid(id); var sortOrderDispatch = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(s => s.ID == ID); if (sortOrderDispatch == null) { errorInfo = "当前选择的调度记录不存在,未能删除!"; return(false); } if (sortOrderDispatch.DispatchStatus != "1") { errorInfo = "当前选择的调度记录不是已调度,未能删除!"; return(false); } if (sortOrderDispatch.OutBillMaster.Status != "1") { errorInfo = "当前选择的调度记录出库单不是已录入,未能删除!"; return(false); } if (sortOrderDispatch.MoveBillMaster.Status != "1") { errorInfo = "当前选择的调度记录移库单不是已录入,未能删除!"; return(false); } using (var scope = new TransactionScope()) { //解锁移库冻结量 var moveDetail = MoveBillDetailRepository.GetQueryable() .Where(m => m.BillNo == sortOrderDispatch.MoveBillNo); var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray(); var targetStorages = moveDetail.Select(m => m.InStorage).ToArray(); if (!Locker.Lock(sourceStorages) || !Locker.Lock(targetStorages)) { errorInfo = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!"; return(false); } moveDetail.AsParallel().ForAll( (Action <MoveBillDetail>) delegate(MoveBillDetail m) { if (m.InStorage.ProductCode == m.ProductCode && m.OutStorage.ProductCode == m.ProductCode && m.InStorage.InFrozenQuantity >= m.RealQuantity && m.OutStorage.OutFrozenQuantity >= m.RealQuantity) { m.InStorage.InFrozenQuantity -= m.RealQuantity; m.OutStorage.OutFrozenQuantity -= m.RealQuantity; m.InStorage.LockTag = string.Empty; m.OutStorage.LockTag = string.Empty; } else { throw new Exception("储位的卷烟或移库冻结量与当前分配不符,信息可能被异常修改,不能删除!"); } } ); Del(MoveBillDetailRepository, sortOrderDispatch.MoveBillMaster.MoveBillDetails); //删除移库细单 MoveBillMasterRepository.Delete(sortOrderDispatch.MoveBillMaster); //删除移库主单 Del(OutBillDetailRepository, sortOrderDispatch.OutBillMaster.OutBillDetails); //删除出库细单 OutBillMasterRepository.Delete(sortOrderDispatch.OutBillMaster); //删除出库主单 //修改线路调度表中作业状态 var sortDisp = SortOrderDispatchRepository.GetQueryable() .Where(s => s.SortWorkDispatchID == sortOrderDispatch.ID); foreach (var item in sortDisp.ToArray()) { item.WorkStatus = "1"; item.SortWorkDispatchID = null; } SortWorkDispatchRepository.Delete(sortOrderDispatch); SortWorkDispatchRepository.SaveChanges(); scope.Complete(); return(true); } } catch (Exception e) { errorInfo = "删除失败,详情:" + e.Message; return(false); } }
public bool Audit(string id, string userName, ref string errorInfo) { try { Guid ID = new Guid(id); var sortWork = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(s => s.ID == ID); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (employee == null) { errorInfo = "当前用户不存在或不可用,未能审核!"; return(false); } if (sortWork == null) { errorInfo = "当前选择的调度记录不存在,未能审核!"; return(false); } if (sortWork.DispatchStatus != "1") { errorInfo = "当前选择的调度记录不是已调度,未能审核!"; return(false); } if (sortWork.OutBillMaster.Status != "1") { errorInfo = "当前选择的调度记录出库单不是已录入,未能审核!"; return(false); } if (sortWork.MoveBillMaster.Status != "1") { errorInfo = "当前选择的调度记录移库单不是已录入,未能审核!"; return(false); } using (var scope = new TransactionScope()) { //出库审核 var outMaster = OutBillMasterRepository.GetQueryable() .FirstOrDefault(o => o.BillNo == sortWork.OutBillNo); outMaster.Status = "2"; outMaster.VerifyPersonID = employee.ID; outMaster.VerifyDate = DateTime.Now; outMaster.UpdateTime = DateTime.Now; //移库审核 var moveMater = MoveBillMasterRepository.GetQueryable() .FirstOrDefault(m => m.BillNo == sortWork.MoveBillNo); moveMater.Status = "2"; moveMater.VerifyPersonID = employee.ID; moveMater.VerifyDate = DateTime.Now; moveMater.UpdateTime = DateTime.Now; //分拣作业审核 sortWork.DispatchStatus = "2"; sortWork.UpdateTime = DateTime.Now; SortWorkDispatchRepository.SaveChanges(); scope.Complete(); return(true); } } catch (Exception e) { errorInfo = "审核失败,详情:" + e.Message; return(false); } }
public bool Settle(string id, ref string errorInfo) { try { Guid ID = new Guid(id); var sortWork = SortWorkDispatchRepository.GetQueryable().FirstOrDefault(s => s.ID == ID); if (sortWork == null) { errorInfo = "当前选择的调度记录不存在,未能结单!"; return(false); } if (sortWork.DispatchStatus == "1") { errorInfo = "当前选择的调度记录不是执行中,未能结单!"; return(false); } if (sortWork.MoveBillMaster.Status == "1") { errorInfo = "当前选择的调度记录移库单不是执行中,未能结单!"; return(false); } using (var scope = new TransactionScope()) { //移库细单解锁冻结量 var moveDetail = MoveBillDetailRepository.GetQueryable() .Where(m => m.BillNo == sortWork.MoveBillNo && m.Status != "2"); if (moveDetail.Any()) { var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray(); var targetStorages = moveDetail.Select(m => m.InStorage).ToArray(); if (!Locker.Lock(sourceStorages) || !Locker.Lock(targetStorages)) { errorInfo = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!"; return(false); } moveDetail.AsParallel().ForAll( (Action <MoveBillDetail>) delegate(MoveBillDetail m) { if (m.InStorage.ProductCode == m.ProductCode && m.OutStorage.ProductCode == m.ProductCode && m.InStorage.InFrozenQuantity >= m.RealQuantity && m.OutStorage.OutFrozenQuantity >= m.RealQuantity) { m.InStorage.InFrozenQuantity -= m.RealQuantity; m.OutStorage.OutFrozenQuantity -= m.RealQuantity; m.InStorage.LockTag = string.Empty; m.OutStorage.LockTag = string.Empty; } else { throw new Exception("储位的卷烟或移库冻结量与当前分配不符,信息可能被异常修改,不能结单!"); } } ); //解锁分拣线路调度的状态,以便重新做作业调度; foreach (var sortDisp in sortWork.SortOrderDispatchs) { sortDisp.SortWorkDispatchID = null; sortDisp.WorkStatus = "1"; } } else { //出库单作自动出库 var storages = StorageRepository.GetQueryable().Where(s => s.CellCode == sortWork.SortingLine.CellCode && s.Quantity - s.OutFrozenQuantity > 0).ToArray(); if (!Locker.Lock(storages)) { errorInfo = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!"; return(false); } var outAllots = sortWork.OutBillMaster.OutBillAllots; var outDetails = OutBillDetailRepository.GetQueryableIncludeProduct() .Where(o => o.BillNo == sortWork.OutBillMaster.BillNo); outDetails.ToArray().AsParallel().ForAll( (Action <OutBillDetail>) delegate(OutBillDetail o) { var ss = storages.Where(s => s.ProductCode == o.ProductCode).ToArray(); foreach (var s in ss) { lock (s) { if (o.BillQuantity - o.AllotQuantity > 0) { decimal allotQuantity = s.Quantity; decimal billQuantity = o.BillQuantity - o.AllotQuantity; allotQuantity = allotQuantity < billQuantity ? allotQuantity : billQuantity; o.AllotQuantity += allotQuantity; o.RealQuantity += allotQuantity; s.Quantity -= allotQuantity; var billAllot = new OutBillAllot() { BillNo = sortWork.OutBillMaster.BillNo, OutBillDetailId = o.ID, ProductCode = o.ProductCode, CellCode = s.CellCode, StorageCode = s.StorageCode, UnitCode = o.UnitCode, AllotQuantity = allotQuantity, RealQuantity = allotQuantity, FinishTime = DateTime.Now, Status = "2" }; lock (sortWork.OutBillMaster.OutBillAllots) { sortWork.OutBillMaster.OutBillAllots.Add(billAllot); } } else { break; } } } if (o.BillQuantity - o.AllotQuantity > 0) { throw new Exception(sortWork.SortingLine.SortingLineName + " " + o.ProductCode + " " + o.Product.ProductName + "分拣备货区库存不足,未能结单!"); } } ); storages.AsParallel().ForAll(s => s.LockTag = string.Empty); } //出库结单 var outMaster = OutBillMasterRepository.GetQueryable() .FirstOrDefault(o => o.BillNo == sortWork.OutBillNo); outMaster.Status = "6"; outMaster.UpdateTime = DateTime.Now; //移库结单 var moveMater = MoveBillMasterRepository.GetQueryable() .FirstOrDefault(m => m.BillNo == sortWork.MoveBillNo); moveMater.Status = "4"; moveMater.UpdateTime = DateTime.Now; //分拣作业结单 sortWork.DispatchStatus = "4"; sortWork.UpdateTime = DateTime.Now; SortWorkDispatchRepository.SaveChanges(); scope.Complete(); return(true); } } catch (AggregateException ex) { errorInfo = "结单失败,详情:" + ex.InnerExceptions.Select(i => i.Message).Aggregate((m, n) => m + n); return(false); } catch (Exception e) { errorInfo = "结单失败,详情:" + e.Message; return(false); } }
public bool Add(DateTime datetime, out string strResult) { bool result = false; strResult = string.Empty; var moveBillMaster = MoveBillMasterRepository.GetQueryable().Where(i => i.BillDate <= datetime); var moveBillDetail = MoveBillDetailRepository.GetQueryable().Where(i => i.MoveBillMaster.BillDate <= datetime); if (moveBillMaster.Any()) { #region 主表移入历史表 try { foreach (var item in moveBillMaster.ToArray()) { MoveBillMasterHistory history = new MoveBillMasterHistory(); history.BillNo = item.BillNo; history.BillDate = item.BillDate; history.BillTypeCode = item.BillTypeCode; history.WarehouseCode = item.WarehouseCode; history.OperatePersonID = item.OperatePersonID; history.Status = item.Status; history.VerifyPersonID = item.VerifyPersonID; history.VerifyDate = item.VerifyDate; history.Description = item.Description; history.IsActive = item.IsActive; history.UpdateTime = item.UpdateTime; history.Origin = item.Origin; MoveBillMasterHistoryRepository.Add(history); } result = true; } catch (Exception e) { strResult = "主库单:" + e.InnerException.ToString(); result = false; } #endregion if (moveBillDetail.Any()) { #region 细表移入历史表 try { foreach (var item in moveBillDetail.ToArray()) { MoveBillDetailHistory history = new MoveBillDetailHistory(); history.BillNo = item.BillNo; history.ProductCode = item.ProductCode; history.OutCellCode = item.OutCellCode; history.OutStorageCode = item.OutStorageCode; history.InCellCode = item.InCellCode; history.InStorageCode = item.InStorageCode; history.UnitCode = item.UnitCode; history.RealQuantity = item.RealQuantity; history.OperatePersonID = item.OperatePersonID; history.StartTime = item.StartTime; history.FinishTime = item.FinishTime; history.Status = item.Status; history.Operator = item.Operator; history.CanRealOperate = item.CanRealOperate; history.PalletTag = item.PalletTag; MoveBillDetailHistoryRepository.Add(history); } result = true; } catch (Exception e) { strResult = "细库单:" + e.InnerException.ToString();; } #endregion } if (result == true) { #region 除主细分配表 try { foreach (var item in moveBillMaster.ToList()) { Del(MoveBillDetailRepository, item.MoveBillDetails); MoveBillMasterRepository.Delete(item); result = true; } } catch (Exception e) { strResult = "删除情况" + e.InnerException.ToString(); } MoveBillMasterHistoryRepository.SaveChanges(); #endregion } } else { strResult = "数据不存在!"; } return(result); }