/// <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 bool EditAllot(string id, string status, string operater, out string strResult) { strResult = string.Empty; bool result = false; string[] ids = id.Split(','); string strId = ""; MoveBillDetail detail = null; var employee = EmployeeRepository.GetQueryable().FirstOrDefault(e => e.UserName == operater); for (int i = 0; i < ids.Length; i++) { strId = ids[i].ToString(); detail = MoveBillDetailRepository.GetQueryable().AsEnumerable().FirstOrDefault(a => strId == a.ID.ToString()); if (detail != null) { if (detail.Status == "0" && status == "1" || detail.Status == "1" && status == "0" || detail.Status == "1" && status == "2") { try { detail.Status = status; if (operater != "") { detail.Operator = employee.EmployeeName; } else { detail.Operator = ""; } MoveBillDetailRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "原因:" + ex.Message; } } else { strResult = "原因:操作错误!"; } } else { strResult = "原因:未找到该记录!"; } } return(result); }
/// <summary> /// 修改移库细单 /// </summary> /// <param name="moveBillDetail"></param> /// <returns></returns> public bool Save(MoveBillDetail moveBillDetail, out string strResult) { bool result = false; IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); var mbd = moveBillDetailQuery.FirstOrDefault(i => i.ID == moveBillDetail.ID && i.BillNo == moveBillDetail.BillNo); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == moveBillDetail.UnitCode); var outStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.OutStorageCode); var inStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.InStorageCode); var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == mbd.ProductCode); var outCell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.OutCellCode); var inCell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.InCellCode); //判断移出数量是否合理 bool isOutQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity, outStorage.InFrozenQuantity, outStorage.OutFrozenQuantity - mbd.RealQuantity, outCell.MaxQuantity, outStorage.Quantity, "out"); //判断移入数量是否合理 bool isInQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity, inStorage.InFrozenQuantity - mbd.RealQuantity, inStorage.OutFrozenQuantity, inCell.MaxQuantity, inStorage.Quantity, "in"); if (Locker.LockStorage(outStorage, product) != null) { if (Locker.LockStorage(inStorage, product) != null) { if (isOutQuantityRight && isInQuantityRight) { mbd.ProductCode = moveBillDetail.ProductCode; mbd.OutCellCode = moveBillDetail.OutCellCode; mbd.OutStorageCode = moveBillDetail.OutStorageCode; mbd.InCellCode = moveBillDetail.InCellCode; mbd.InStorageCode = moveBillDetail.InStorageCode; mbd.UnitCode = moveBillDetail.UnitCode; mbd.RealQuantity = moveBillDetail.RealQuantity * unit.Count; outStorage.OutFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; inStorage.InFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; mbd.Status = "0"; MoveBillDetailRepository.SaveChanges(); result = true; } } else { resultStr = "加锁移入库存失败,当前库存已有人在操作!"; } } else { resultStr = "加锁移出库存失败,当前库存已有人在操作!"; } strResult = resultStr; return(result); }
public void DeleteMoveBillDetail(MoveBillMaster moveBillMaster) { if (moveBillMaster != null) { var sourceStorages = moveBillMaster.MoveBillDetails.Select(m => m.OutStorage).ToArray(); var targetStorages = moveBillMaster.MoveBillDetails.Select(m => m.InStorage).ToArray(); if (Locker.Lock(sourceStorages) && Locker.Lock(targetStorages)) { moveBillMaster.MoveBillDetails.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("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能删除移库单!"); } } ); Locker.UnLock(sourceStorages); Locker.UnLock(targetStorages); } else { throw new Exception("锁定储位失败,其他人可能正在操作,请稍候重试!"); } MoveBillDetailRepository.Delete(moveBillMaster.MoveBillDetails.ToArray()); //MoveBillDetailRepository.GetObjectSet() // .DeleteEntity(m => m.BillNo == moveBillMaster.BillNo); MoveBillDetailRepository.SaveChanges(); } }
/// <summary> /// 删除移库细单 /// </summary> /// <param name="ID">移库细单ID</param> /// <returns></returns> public bool Delete(string ID, out string strResult) { bool result = false; IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); int intID = Convert.ToInt32(ID); var mbd = moveBillDetailQuery.FirstOrDefault(i => i.ID == intID); var outStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.OutStorageCode); var inStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.InStorageCode); var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == mbd.ProductCode); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == mbd.UnitCode); try { if (Locker.LockStorage(outStorage, product) != null) { if (Locker.LockStorage(inStorage, product) != null) { outStorage.OutFrozenQuantity -= mbd.RealQuantity; inStorage.InFrozenQuantity -= mbd.RealQuantity; MoveBillDetailRepository.Delete(mbd); MoveBillDetailRepository.SaveChanges(); result = true; } else { resultStr = "加锁移入库存失败,当前库存已有人在操作!"; } } else { resultStr = "加锁移出库存失败,当前库存已有人在操作!"; } } catch (Exception ex) { resultStr = ex.ToString(); } strResult = resultStr; return(result); }
/// <summary> /// 修改移库细单 /// </summary> /// <param name="moveBillDetail"></param> /// <returns></returns> public bool Save(MoveBillDetail moveBillDetail, out string strResult) { bool result = false; decimal inFrozenQuantity = 0; decimal outFrozenQuantity = 0; if (moveBillDetail.OutCellCode == moveBillDetail.InCellCode) { strResult = "移入和移出货位不能一样!"; return(false); } IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); var mbd = moveBillDetailQuery.FirstOrDefault(i => i.ID == moveBillDetail.ID && i.BillNo == moveBillDetail.BillNo); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == moveBillDetail.UnitCode); Product product = null; if (mbd.ProductCode == moveBillDetail.ProductCode)//判断用户选择的移库卷烟编码和之前保存的移库卷烟编码是否相等 { product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == mbd.ProductCode); } else { product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == moveBillDetail.ProductCode); } var outCell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.OutCellCode); var inCell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.InCellCode); Storage outStorage = null; Storage oldOutStorage = null; if (mbd.OutStorageCode == moveBillDetail.OutStorageCode)//判断用户选择的移出库存和之前保存的移出库存是否相等 { outStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.OutStorageCode); outFrozenQuantity = outStorage.OutFrozenQuantity - mbd.RealQuantity; } else { oldOutStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.OutStorageCode); outStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == moveBillDetail.OutStorageCode); outFrozenQuantity = outStorage.OutFrozenQuantity; } Storage inStorage = null; Storage oldInStorage = null; if (mbd.InCellCode == moveBillDetail.InCellCode)//判断用户选择的移入货位和之前保存的移入货位是否相等 { inStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.InStorageCode); inFrozenQuantity = inStorage.InFrozenQuantity - mbd.RealQuantity; } else { oldInStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == mbd.InStorageCode); inStorage = Locker.LockStorage(inCell); if (inStorage == null) { strResult = "移入库存加锁失败!"; return(false); } inFrozenQuantity = inStorage.InFrozenQuantity; } if (inCell.IsSingle == "1") { if (inStorage.Product != null && inStorage.Product.ProductCode != moveBillDetail.ProductCode) { strResult = "货位:<" + inCell.CellName + ">是非货位管理货位不能移入不同品牌的卷烟!"; return(false); } } //判断移出数量是否合理 bool isOutQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, outStorage.InFrozenQuantity, outFrozenQuantity, outCell.MaxQuantity * product.Unit.Count, outStorage.Quantity, "out"); if (Locker.LockStorage(outStorage, product) != null) { //if (Locker.LockStorage(inStorage, product) != null) //{ //判断移入数量是否合理 bool isInQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, inFrozenQuantity, inStorage.OutFrozenQuantity, inCell.MaxQuantity * product.Unit.Count, inStorage.Quantity, "in"); if (isOutQuantityRight && isInQuantityRight) { if (mbd.OutStorageCode == moveBillDetail.OutStorageCode) { outStorage.OutFrozenQuantity -= mbd.RealQuantity; outStorage.OutFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; } else { oldOutStorage.OutFrozenQuantity -= mbd.RealQuantity; outStorage.OutFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; } if (mbd.InCellCode == moveBillDetail.InCellCode) { inStorage.InFrozenQuantity -= mbd.RealQuantity; inStorage.InFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; } else { oldInStorage.InFrozenQuantity -= mbd.RealQuantity; inStorage.InFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; } mbd.ProductCode = moveBillDetail.ProductCode; mbd.OutCellCode = moveBillDetail.OutCellCode; mbd.OutStorageCode = moveBillDetail.OutStorageCode; mbd.InCellCode = moveBillDetail.InCellCode; mbd.InStorageCode = inStorage.StorageCode; mbd.UnitCode = moveBillDetail.UnitCode; mbd.RealQuantity = moveBillDetail.RealQuantity * unit.Count; mbd.Status = "0"; outStorage.LockTag = string.Empty; inStorage.LockTag = string.Empty; inStorage.ProductCode = product.ProductCode; MoveBillDetailRepository.SaveChanges(); result = true; } //} //else //{ // resultStr = "加锁移入库存失败,当前库存已有人在操作!"; //} } else { resultStr = "加锁移出库存失败,当前库存已有人在操作!"; } strResult = resultStr; return(result); }
/// <summary> /// 新增移库细单 /// </summary> /// <param name="moveBillDetail"></param> /// <returns></returns> public bool Add(MoveBillDetail moveBillDetail, out string strResult) { bool result = false; try { IQueryable <MoveBillDetail> moveBillDetailQuery = MoveBillDetailRepository.GetQueryable(); var product = ProductRepository.GetQueryable().FirstOrDefault(p => p.ProductCode == moveBillDetail.ProductCode); var unit = UnitRepository.GetQueryable().FirstOrDefault(u => u.UnitCode == moveBillDetail.UnitCode); var storage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == moveBillDetail.InStorageCode); var outStorage = StorageRepository.GetQueryable().FirstOrDefault(s => s.StorageCode == moveBillDetail.OutStorageCode); var outCell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.OutCellCode); var inCell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == moveBillDetail.InCellCode); Storage inStorage = null; if (storage != null) { inStorage = Locker.LockStorage(storage, product); } else { inStorage = Locker.LockStorage(inCell); } //判断移出数量是否合理 bool isOutQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, outStorage.InFrozenQuantity, outStorage.OutFrozenQuantity, outCell.MaxQuantity * product.Unit.Count, outStorage.Quantity, "out"); if (Locker.LockStorage(outStorage, product) != null) { if (inStorage != null) { //判断移入数量是否合理 bool isInQuantityRight = IsQuntityRight(moveBillDetail.RealQuantity * unit.Count, inStorage.InFrozenQuantity, inStorage.OutFrozenQuantity, inCell.MaxQuantity * product.Unit.Count, inStorage.Quantity, "in"); if (isInQuantityRight && isOutQuantityRight) { var mbd = new MoveBillDetail(); mbd.BillNo = moveBillDetail.BillNo; mbd.ProductCode = moveBillDetail.ProductCode; mbd.OutCellCode = moveBillDetail.OutCellCode; mbd.OutStorageCode = moveBillDetail.OutStorageCode; mbd.InCellCode = moveBillDetail.InCellCode; mbd.InStorageCode = inStorage.StorageCode; mbd.UnitCode = moveBillDetail.UnitCode; mbd.RealQuantity = moveBillDetail.RealQuantity * unit.Count; outStorage.OutFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; inStorage.ProductCode = moveBillDetail.ProductCode; inStorage.InFrozenQuantity += moveBillDetail.RealQuantity * unit.Count; mbd.Status = "0"; inStorage.LockTag = string.Empty; outStorage.LockTag = string.Empty; MoveBillDetailRepository.Add(mbd); MoveBillDetailRepository.SaveChanges(); result = true; } else { result = false; } } else { resultStr = "移入库存加锁失败"; } } else { resultStr = "移出库存加锁失败"; } } catch (Exception ex) { resultStr = ex.ToString(); } strResult = resultStr; return(result); }
public void CreateSyncMoveBillDetail(MoveBillMaster moveBillMaster) { Locker.LockKey = moveBillMaster.BillNo; IQueryable <Storage> storageQuery = StorageRepository.GetQueryable(); IQueryable <Cell> cellQuery = CellRepository.GetQueryableIncludeStorages(); var storages = storageQuery.Where(s => s.Cell.WarehouseCode == moveBillMaster.WarehouseCode && s.Cell.IsActive == "1" && s.Quantity - s.OutFrozenQuantity > 0 && s.OutFrozenQuantity > 0); var cells = cellQuery.Where(c => c.WarehouseCode == moveBillMaster.WarehouseCode && c.IsActive == "1"); //1:主库区 1;2:件烟区 2; //3;条烟区 3;4:暂存区 4; //5:备货区 0;6:残烟区 0; //7:罚烟区 0;8:虚拟区 0; //9:其他区 0; //主库区未满盘件烟移到件烟区 string[] areaTypes = new string[] { "1" }; var ss = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType) && ((s.Quantity - s.OutFrozenQuantity) / s.Product.Unit.Count) > 1) .ToArray(); if (Locker.Lock(ss)) { //件烟区 货位是单一存储的空货位; areaTypes = new string[] { "2" }; var cc = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) && c.IsSingle == "1") .ToArray(); ss.AsParallel().ForAll( (Action <Storage>) delegate(Storage s) { MoveToPieceArea(moveBillMaster, s, cc); } ); Locker.UnLock(ss); } else { return; } MoveBillDetailRepository.SaveChanges(); //主库区条烟移到件烟区,没有条烟区 if (AreaRepository.GetQueryable().Where(a => a.AreaType == "3").Select(a => a.IsActive).ToArray()[0] == "0") { areaTypes = new string[] { "1" }; ss = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType) && (s.Quantity - s.OutFrozenQuantity) % s.Product.Unit.Count > 0) .ToArray(); if (Locker.Lock(ss)) { areaTypes = new string[] { "2" }; var cc = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) && c.IsSingle == "1") .ToArray(); ss.AsParallel().ForAll( (Action <Storage>) delegate(Storage s) { MoveToBarArea(moveBillMaster, s, cc); } ); Locker.UnLock(ss); } else { return; } } else { //主库区件烟库区条烟移到条烟区 areaTypes = new string[] { "1", "2" }; ss = storages.Where(s => areaTypes.Any(a => a == s.Cell.Area.AreaType) && (s.Quantity - s.OutFrozenQuantity) % s.Product.Unit.Count > 0) .ToArray(); if (Locker.Lock(ss)) { areaTypes = new string[] { "3" }; var cc = cells.Where(c => areaTypes.Any(a => a == c.Area.AreaType) && c.IsSingle == "1") .ToArray(); ss.AsParallel().ForAll( (Action <Storage>) delegate(Storage s) { MoveToBarArea(moveBillMaster, s, cc); } ); Locker.UnLock(ss); } else { return; } } MoveBillDetailRepository.SaveChanges(); }
private bool FinishMoveBillTask(Task task) { var moveDetail = MoveBillDetailRepository.GetQueryable() .Where(i => i.BillNo == task.OrderID && i.ID == task.AllotID && i.Status == "1") .FirstOrDefault(); if (moveDetail != null && (moveDetail.MoveBillMaster.Status == "2" || moveDetail.MoveBillMaster.Status == "3" )) { if (string.IsNullOrEmpty(moveDetail.InStorage.LockTag) && string.IsNullOrEmpty(moveDetail.OutStorage.LockTag) && moveDetail.InStorage.InFrozenQuantity >= moveDetail.RealQuantity && moveDetail.OutStorage.OutFrozenQuantity >= moveDetail.RealQuantity) { moveDetail.Status = "2"; moveDetail.InStorage.Quantity += moveDetail.RealQuantity; moveDetail.InStorage.InFrozenQuantity -= moveDetail.RealQuantity; moveDetail.InStorage.Rfid = ""; moveDetail.OutStorage.Quantity -= moveDetail.RealQuantity; moveDetail.OutStorage.OutFrozenQuantity -= moveDetail.RealQuantity; moveDetail.OutStorage.Rfid = ""; //判断移入的时间是否小于移出的时间 if (DateTime.Compare(moveDetail.InStorage.StorageTime, moveDetail.OutStorage.StorageTime) == 1) { moveDetail.InStorage.StorageTime = moveDetail.OutStorage.StorageTime; } moveDetail.MoveBillMaster.Status = "3"; moveDetail.FinishTime = DateTime.Now; var sortwork = SortWorkDispatchRepository.GetQueryable() .Where(s => s.MoveBillMaster.BillNo == moveDetail.MoveBillMaster.BillNo && s.DispatchStatus == "2") .FirstOrDefault(); //修改分拣调度作业状态 if (sortwork != null) { sortwork.DispatchStatus = "3"; } if (moveDetail.MoveBillMaster.MoveBillDetails.All(c => c.Status == "2")) { moveDetail.MoveBillMaster.Status = "4"; } MoveBillDetailRepository.SaveChanges(); return(true); } else { //"需确认移库的数据别人在操作或者完成的数量不对,完成出错!"; return(false); } } else { //"需确认移库的数据查询为空或者主单状态不对,完成出错!"; return(false); } }