/// <summary> /// 入库单删除 /// </summary> /// <param name="BillNo">入库单号</param> /// <returns></returns> public bool Delete(string BillNo, out string strResult) { strResult = string.Empty; bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1"); if (ibm != null) { try { Del(InBillDetailRepository, ibm.InBillDetails); InBillMasterRepository.Delete(ibm); InBillMasterRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "删除失败,原因:" + ex.Message; } } else { strResult = "删除失败!未找到当前需要删除的数据!"; } return(result); }
/// <summary> /// 入库单审核 /// </summary> /// <param name="BillNo">入库单号</param> /// <param name="userName">用户名</param> /// <param name="strResult">操作提示信息</param> /// <returns></returns> public bool Audit(string BillNo, string userName, out string strResult) { bool result = false; strResult = string.Empty; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1"); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (ibm != null) { if (string.IsNullOrEmpty(ibm.TargetCellCode))//判断入库主单是否指定货位 { ibm.Status = "2"; ibm.VerifyDate = DateTime.Now; ibm.UpdateTime = DateTime.Now; ibm.VerifyPersonID = employee.ID; InBillMasterRepository.SaveChanges(); result = true; } else//如果入库主单指定了货位那么就进行入库分配 { result = InAllot(ibm, employee.ID); strResult = resultStr; } } return(result); }
/// <summary> /// 入库单反审 /// </summary> /// <param name="BillNo">入库单号</param> /// <returns></returns> public bool AntiTrial(string BillNo, out string strResult) { strResult = string.Empty; bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "2"); if (ibm != null) { try { ibm.Status = "1"; ibm.VerifyDate = null; ibm.UpdateTime = DateTime.Now; ibm.VerifyPersonID = null; InBillMasterRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "反审失败,原因:" + ex.Message; } } else { strResult = "反审失败,未找到该条数据!"; } return(result); }
public bool Add(InBillMaster inBillMaster, string userName) { bool result = false; var ibm = new InBillMaster(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (employee != null) { ibm.BillNo = inBillMaster.BillNo; ibm.BillDate = inBillMaster.BillDate; ibm.BillTypeCode = inBillMaster.BillTypeCode; ibm.WarehouseCode = inBillMaster.WarehouseCode; ibm.OperatePersonID = employee.ID; ibm.Status = "1"; ibm.VerifyPersonID = inBillMaster.VerifyPersonID; ibm.VerifyDate = inBillMaster.VerifyDate; ibm.Description = inBillMaster.Description; //ibm.IsActive = inBillMaster.IsActive; ibm.IsActive = "1"; ibm.UpdateTime = DateTime.Now; InBillMasterRepository.Add(ibm); InBillMasterRepository.SaveChanges(); result = true; } return(result); }
public bool AllotCancelConfirm(string billNo, out string strResult) { bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "4"); if (ibm != null) { if (string.IsNullOrEmpty(ibm.LockTag)) { try { ibm.Status = "3"; ibm.UpdateTime = DateTime.Now; InBillMasterRepository.SaveChanges(); result = true; strResult = "取消成功"; } catch (Exception) { strResult = "当前订单其他人正在操作,请稍候重试!"; } } else { strResult = "当前订单其他人正在操作,请稍候重试!"; } } else { strResult = "当前订单状态不是已确认,或当前订单不存在!"; } 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 ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo); if (ibm != null && ibm.Status == "5") { using (var scope = new TransactionScope()) { try { //修改分配入库冻结量 var inAllot = InBillAllotRepository.GetQueryable() .Where(o => o.BillNo == ibm.BillNo && o.Status != "2") .ToArray(); var storages = inAllot.Select(i => i.Storage).ToArray(); if (!Locker.Lock(storages)) { strResult = "锁定储位失败,储位其他人正在操作,无法结单请稍候重试!"; return(false); } inAllot.AsParallel().ForAll( (Action <InBillAllot>) delegate(InBillAllot i) { if (i.Storage.ProductCode == i.ProductCode && i.Storage.InFrozenQuantity >= i.AllotQuantity) { i.Storage.InFrozenQuantity -= i.AllotQuantity; i.Storage.LockTag = string.Empty; } else { throw new Exception("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能结单!"); } } ); ibm.Status = "6"; ibm.UpdateTime = DateTime.Now; InBillMasterRepository.SaveChanges(); scope.Complete(); result = true; } catch (Exception e) { strResult = "入库单结单出错!原因:" + e.Message; } } } return(result); }
public bool DownInBillMaster(string BeginDate, string EndDate, out string errorInfo) { errorInfo = string.Empty; bool result = false; string inBillStr = ""; string inBillMasterStr = ""; try { var inBillNos = InBillMasterRepository.GetQueryable().Where(i => i.BillNo == i.BillNo).Select(i => new { i.BillNo }).ToArray(); for (int i = 0; i < inBillNos.Length; i++) { inBillStr += inBillNos[i].BillNo + ","; } InBillMaster[] inBillMasterList = InBillMasterDownService.GetInBillMaster(inBillStr); foreach (var master in inBillMasterList) { var inBillMaster = new InBillMaster(); inBillMaster.BillNo = master.BillNo; inBillMaster.BillDate = master.BillDate; inBillMaster.BillTypeCode = master.BillTypeCode; inBillMaster.WarehouseCode = master.WarehouseCode; inBillMaster.Status = "1"; inBillMaster.IsActive = master.IsActive; inBillMaster.UpdateTime = DateTime.Now; InBillMasterRepository.Add(inBillMaster); inBillMasterStr += master.BillNo + ","; } if (inBillMasterStr != string.Empty) { InBillDetail[] inBillDetailList = InBillMasterDownService.GetInBillDetail(inBillMasterStr); foreach (var detail in inBillDetailList) { var inBillDetail = new InBillDetail(); inBillDetail.BillNo = detail.BillNo; inBillDetail.ProductCode = detail.ProductCode; inBillDetail.UnitCode = detail.UnitCode; inBillDetail.Price = detail.Price; inBillDetail.BillQuantity = detail.BillQuantity; inBillDetail.AllotQuantity = detail.AllotQuantity; inBillDetail.RealQuantity = detail.RealQuantity; inBillDetail.Description = detail.Description; InBillDetailRepository.Add(inBillDetail); } } InBillMasterRepository.SaveChanges(); result = true; } catch (Exception e) { errorInfo = "出错,原因:" + e.Message; } return(result); }
public bool Delete(string BillNo) { bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1"); if (ibm != null) { Del(InBillDetailRepository, ibm.InBillDetails); InBillMasterRepository.Delete(ibm); InBillMasterRepository.SaveChanges(); result = true; } return(result); }
public bool AntiTrial(string BillNo) { bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "2"); if (ibm != null) { ibm.Status = "1"; ibm.VerifyDate = null; ibm.UpdateTime = DateTime.Now; ibm.VerifyPersonID = null; InBillMasterRepository.SaveChanges(); result = true; } return(result); }
public bool Audit(string BillNo, string userName) { bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1"); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (ibm != null) { ibm.Status = "2"; ibm.VerifyDate = DateTime.Now; ibm.UpdateTime = DateTime.Now; ibm.VerifyPersonID = employee.ID; InBillMasterRepository.SaveChanges(); result = true; } return(result); }
//检查主表并加锁 private bool CheckAndLock(InBillMaster billMaster, ProgressState ps) { if ((new string[] { "1" }).Any(s => s == billMaster.Status)) { ps.State = StateType.Info; ps.Messages.Add("当前订单未审核,不可以进行分配!"); NotifyConnection(ps.Clone()); return(false); } if ((new string[] { "4", "5", "6" }).Any(s => s == billMaster.Status)) { ps.State = StateType.Info; ps.Messages.Add("分配已确认生效不能再分配!"); NotifyConnection(ps.Clone()); return(false); } if (!string.IsNullOrEmpty(billMaster.LockTag)) { ps.State = StateType.Error; ps.Errors.Add("当前订单被锁定不可以进行分配!"); NotifyConnection(ps.Clone()); return(false); } else { try { billMaster.LockTag = ConnectionId; InBillMasterRepository.SaveChanges(); ps.Messages.Add("锁定当前订单成功!"); NotifyConnection(ps.Clone()); return(true); } catch (Exception) { ps.State = StateType.Error; ps.Errors.Add("锁定当前订单失败不可以进行分配!"); NotifyConnection(ps.Clone()); return(false); } } }
public bool AllotConfirm(string billNo, out string strResult) { bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3"); if (ibm != null) { if (ibm.InBillDetails.All(b => b.BillQuantity == b.AllotQuantity) && ibm.InBillDetails.Sum(b => b.BillQuantity) == ibm.InBillAllots.Sum(a => a.AllotQuantity)) { if (string.IsNullOrEmpty(ibm.LockTag)) { try { ibm.Status = "4"; ibm.UpdateTime = DateTime.Now; InBillMasterRepository.SaveChanges(); result = true; strResult = "确认成功"; } catch (Exception) { strResult = "当前订单其他人正在操作,请稍候重试!"; } } else { strResult = "当前订单其他人正在操作,请稍候重试!"; } } else { strResult = "当前订单分配未完成或分配结果不正确!"; } } else { strResult = "当前订单状态不是已分配,或当前订单不存在!"; } return(result); }
/// <summary> /// 入库单新增 /// </summary> /// <param name="inBillMaster">入库主单</param> /// <param name="userName">用户名</param> /// <returns></returns> public bool Add(InBillMaster inBillMaster, string userName, out string strResult) { strResult = string.Empty; bool result = false; var ibm = new InBillMaster(); var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName); if (employee != null) { try { ibm.BillNo = inBillMaster.BillNo; ibm.BillDate = inBillMaster.BillDate; ibm.BillTypeCode = inBillMaster.BillTypeCode; ibm.WarehouseCode = inBillMaster.WarehouseCode; ibm.OperatePersonID = employee.ID; ibm.Status = "1"; ibm.VerifyPersonID = inBillMaster.VerifyPersonID; ibm.VerifyDate = inBillMaster.VerifyDate; ibm.Description = inBillMaster.Description; //ibm.IsActive = inBillMaster.IsActive; ibm.IsActive = "1"; ibm.UpdateTime = DateTime.Now; ibm.TargetCellCode = inBillMaster.TargetCellCode; InBillMasterRepository.Add(ibm); InBillMasterRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "新增失败,原因:" + ex.Message; } } else { strResult = "找不到当前登陆用户!请重新登陆!"; } return(result); }
/// <summary> /// 入库单修改 /// </summary> /// <param name="inBillMaster">入库主单</param> /// <returns></returns> public bool Save(InBillMaster inBillMaster, out string strResult) { strResult = string.Empty; bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == inBillMaster.BillNo && i.Status == "1"); if (ibm != null) { try { ibm.BillDate = inBillMaster.BillDate; ibm.BillTypeCode = inBillMaster.BillTypeCode; ibm.WarehouseCode = inBillMaster.WarehouseCode; ibm.OperatePersonID = inBillMaster.OperatePersonID; ibm.Status = "1"; ibm.VerifyPersonID = inBillMaster.VerifyPersonID; ibm.VerifyDate = inBillMaster.VerifyDate; ibm.Description = inBillMaster.Description; //ibm.IsActive = inBillMaster.IsActive; ibm.IsActive = "1"; ibm.UpdateTime = DateTime.Now; ibm.TargetCellCode = inBillMaster.TargetCellCode; InBillMasterRepository.SaveChanges(); result = true; } catch (Exception ex) { strResult = "保存失败,原因:" + ex.Message; } } else { strResult = "保存失败,未找到该条数据!"; } return(result); }
public bool Save(InBillMaster inBillMaster) { bool result = false; var ibm = InBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == inBillMaster.BillNo && i.Status == "1"); if (ibm != null) { ibm.BillDate = inBillMaster.BillDate; ibm.BillTypeCode = inBillMaster.BillTypeCode; ibm.WarehouseCode = inBillMaster.WarehouseCode; ibm.OperatePersonID = inBillMaster.OperatePersonID; ibm.Status = "1"; ibm.VerifyPersonID = inBillMaster.VerifyPersonID; ibm.VerifyDate = inBillMaster.VerifyDate; ibm.Description = inBillMaster.Description; //ibm.IsActive = inBillMaster.IsActive; ibm.IsActive = "1"; ibm.UpdateTime = DateTime.Now; InBillMasterRepository.SaveChanges(); result = true; } return(result); }
public bool Add(DateTime datetime, out string strResult) { bool result = false; strResult = string.Empty; var inBillMaster = InBillMasterRepository.GetQueryable().Where(i => i.BillDate <= datetime); var inBillDetail = InBillDetailRepository.GetQueryable().Where(i => i.InBillMaster.BillDate <= datetime); var inBillAllot = InBillAllotRepository.GetQueryable().Where(i => i.InBillMaster.BillDate <= datetime); if (inBillMaster.Any()) { #region 主表移入历史表 try { foreach (var item in inBillMaster.ToArray()) { InBillMasterHistory history = new InBillMasterHistory(); 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.TargetCellCode = item.TargetCellCode; InBillMasterHistoryRepository.Add(history); } result = true; } catch (Exception e) { strResult = "迁移主表时:" + e.InnerException.ToString(); result = false; } #endregion if (inBillDetail.Any()) { #region 细表移入历史表 try { foreach (var item2 in inBillDetail.ToArray()) { InBillDetailHistory history2 = new InBillDetailHistory(); history2.ID = item2.ID; history2.BillNo = item2.BillNo; history2.ProductCode = item2.ProductCode; history2.UnitCode = item2.UnitCode; history2.Price = item2.Price; history2.BillQuantity = item2.BillQuantity; history2.AllotQuantity = item2.AllotQuantity; history2.RealQuantity = item2.RealQuantity; history2.Description = item2.Description; InBillDetailHistoryRepository.Add(history2); } result = true; } catch (Exception e) { strResult = "迁移细表时:" + e.InnerException.ToString(); result = false; } #endregion if (inBillAllot.Any()) { #region 分配表移入历史表 try { foreach (var item3 in inBillAllot.ToArray()) { InBillAllotHistory history3 = new InBillAllotHistory(); history3.BillNo = item3.BillNo; history3.ProductCode = item3.ProductCode; history3.InBillDetailId = item3.InBillDetailId; history3.CellCode = item3.CellCode; history3.StorageCode = item3.StorageCode; history3.UnitCode = item3.UnitCode; history3.AllotQuantity = item3.AllotQuantity; history3.RealQuantity = item3.RealQuantity; history3.OperatePersonID = item3.OperatePersonID; history3.Operator = item3.Operator; history3.StartTime = item3.StartTime; history3.FinishTime = item3.FinishTime; history3.Status = item3.Status; InBillAllotHistoryRepository.Add(history3); } result = true; } catch (Exception e) { strResult = "迁移分配表时:" + e.InnerException.ToString(); result = false; } #endregion } } if (result == true) { #region 除主细分配表 try { foreach (var item in inBillMaster.ToList()) { Del(InBillAllotRepository, item.InBillAllots); Del(InBillDetailRepository, item.InBillDetails); InBillMasterRepository.Delete(item); result = true; } } catch (Exception e) { strResult = "删除操作时:" + e.InnerException.ToString(); result = false; } InBillMasterRepository.SaveChanges(); #endregion } } else { strResult = "数据不存在!"; } return(result); }
/// <summary> /// 入库分配 /// </summary> /// <param name="inBillMaster">入库主单</param> /// <returns></returns> public bool InAllot(InBillMaster inBillMaster, Guid employeeId) { try { var inBillDetails = inBillMaster.InBillDetails.ToArray(); var cell = CellRepository.GetQueryable().FirstOrDefault(c => c.CellCode == inBillMaster.TargetCellCode); //入库单入库 inBillMaster.InBillDetails.AsParallel().ForAll( (Action <InBillDetail>) delegate(InBillDetail i) { if (i.BillQuantity - i.AllotQuantity > 0) { Storage inStorage = null; lock (cell) { inStorage = Locker.LockStorage(cell); if (inStorage == null) { throw new Exception("锁定储位失败,储位其他人正在操作,无法分配请稍候重试!"); } inStorage.LockTag = inBillMaster.BillNo; } if (inStorage.Quantity == 0 && inStorage.InFrozenQuantity == 0) { decimal allotQuantity = i.BillQuantity; i.AllotQuantity += allotQuantity; i.RealQuantity += allotQuantity; inStorage.ProductCode = i.ProductCode; inStorage.Quantity += allotQuantity; inStorage.LockTag = string.Empty; var billAllot = new InBillAllot() { BillNo = inBillMaster.BillNo, InBillDetailId = i.ID, ProductCode = i.ProductCode, CellCode = inStorage.CellCode, StorageCode = inStorage.StorageCode, UnitCode = i.UnitCode, AllotQuantity = allotQuantity, RealQuantity = allotQuantity, Status = "2" }; lock (inBillMaster.InBillAllots) { inBillMaster.InBillAllots.Add(billAllot); } } else { throw new Exception("储位数量不等于0,无法分配请稍候重试!"); } } }); //入库结单 inBillMaster.Status = "6"; inBillMaster.VerifyDate = DateTime.Now; inBillMaster.VerifyPersonID = employeeId; inBillMaster.UpdateTime = DateTime.Now; InBillMasterRepository.SaveChanges(); return(true); } catch (AggregateException ex) { resultStr = "审核失败,详情:" + ex.InnerExceptions.Select(i => i.Message).Aggregate((m, n) => m + n); return(false); } }
public bool AllotCancel(string billNo, out string strResult) { Locker.LockKey = billNo; bool result = false; var ibm = InBillMasterRepository.GetQueryable() .FirstOrDefault(i => i.BillNo == billNo && i.Status == "3"); if (ibm != null) { if (string.IsNullOrEmpty(ibm.LockTag)) { try { using (var scope = new TransactionScope()) { var inAllot = InBillAllotRepository.GetQueryable() .Where(o => o.BillNo == ibm.BillNo) .ToArray(); var storages = inAllot.Select(i => i.Storage).ToArray(); if (!Locker.Lock(storages)) { strResult = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!"; return(false); } inAllot.AsParallel().ForAll( (Action <InBillAllot>) delegate(InBillAllot i) { if (i.Storage.ProductCode == i.ProductCode && i.Storage.InFrozenQuantity >= i.AllotQuantity) { lock (i.InBillDetail) { i.InBillDetail.AllotQuantity -= i.AllotQuantity; } i.Storage.InFrozenQuantity -= i.AllotQuantity; i.Storage.LockTag = string.Empty; } else { throw new Exception("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能取消当前入库分配!"); } } ); InBillAllotRepository.SaveChanges(); InBillAllotRepository.GetObjectSet() .DeleteEntity(i => i.BillNo == ibm.BillNo); //InBillAllotRepository.GetObjectQuery() // .DeleteAll(i => i.BillNo == ibm.BillNo,null); ibm.Status = "2"; ibm.UpdateTime = DateTime.Now; InBillMasterRepository.SaveChanges(); result = true; strResult = "取消分配成功!"; scope.Complete(); } } catch (Exception e) { strResult = "取消分配失败,详情:" + e.Message; } } else { strResult = "当前订单其他人正在操作,请稍候重试!"; } } else { strResult = "当前订单状态不是已分配,或当前订单不存在!"; } return(result); }