예제 #1
0
        /// <summary>
        /// 出库审核
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="userName">登陆用户</param>
        /// <returns></returns>
        public bool Audit(string billNo, string userName, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (outbm != null && outbm.Status == "1")
            {
                if (string.IsNullOrEmpty(outbm.TargetCellCode))//判断出库主单是否有指定货位
                {
                    outbm.Status         = "2";
                    outbm.VerifyDate     = DateTime.Now;
                    outbm.UpdateTime     = DateTime.Now;
                    outbm.VerifyPersonID = employee.ID;
                    OutBillMasterRepository.SaveChanges();
                    result = true;
                }
                else//如果出库主单指定了货位那么就从指定的货位出库
                {
                    result    = OutAllot(outbm, employee.ID);
                    errorInfo = infoStr;
                }
            }
            return(result);
        }
예제 #2
0
        public bool Delete(string BillNo, out string errorInfo)
        {
            errorInfo = string.Empty;
            var ibm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == BillNo && i.Status == "1");

            if (ibm != null)
            {
                try
                {
                    //Del(OutBillDetailRepository, ibm.OutBillAllots);
                    Del(OutBillDetailRepository, ibm.OutBillDetails);
                    OutBillMasterRepository.Delete(ibm);
                    OutBillMasterRepository.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    errorInfo = "删除失败!原因:" + e.Message;
                    return(false);
                }
            }
            else
            {
                errorInfo = "删除失败!未找到当前需要删除的数据!";
                return(false);
            }
        }
예제 #3
0
        public bool DownOutBillMaster(string beginDate, string endDate, out string errorInfo)
        {
            errorInfo = string.Empty;
            bool   result           = false;
            string outBillStr       = "";
            string outBillMasterStr = "";

            try
            {
                var outBillNos = OutBillMasterRepository.GetQueryable().Where(i => i.BillNo == i.BillNo).Select(i => new { i.BillNo }).ToArray();

                for (int i = 0; i < outBillNos.Length; i++)
                {
                    outBillStr += outBillNos[i].BillNo + ",";
                }
                OutBillMaster[] outBillMasterList = OutBillMasterDownService.GetOutBillMaster(outBillStr);
                foreach (var master in outBillMasterList)
                {
                    var outBillMaster = new OutBillMaster();
                    outBillMaster.BillNo        = master.BillNo;
                    outBillMaster.BillDate      = master.BillDate;
                    outBillMaster.BillTypeCode  = master.BillTypeCode;
                    outBillMaster.WarehouseCode = master.WarehouseCode;
                    outBillMaster.Status        = "1";
                    outBillMaster.IsActive      = master.IsActive;
                    outBillMaster.UpdateTime    = DateTime.Now;
                    OutBillMasterRepository.Add(outBillMaster);
                    outBillMasterStr += master.BillNo + ",";
                }
                if (outBillMasterStr != string.Empty)
                {
                    OutBillDetail[] outBillDetailList = OutBillMasterDownService.GetOutBillDetail(outBillMasterStr);
                    foreach (var detail in outBillDetailList)
                    {
                        var outBillDetail = new OutBillDetail();
                        outBillDetail.BillNo        = detail.BillNo;
                        outBillDetail.ProductCode   = detail.ProductCode;
                        outBillDetail.UnitCode      = detail.UnitCode;
                        outBillDetail.Price         = detail.Price;
                        outBillDetail.BillQuantity  = detail.BillQuantity;
                        outBillDetail.AllotQuantity = detail.AllotQuantity;
                        outBillDetail.RealQuantity  = detail.RealQuantity;
                        outBillDetail.Description   = detail.Description;
                        OutBillDetailRepository.Add(outBillDetail);
                    }
                }
                OutBillMasterRepository.SaveChanges();
                result = true;
            }
            catch (Exception e)
            {
                errorInfo = "出错,原因:" + e.Message;
            }
            return(result);
        }
예제 #4
0
        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);
        }
예제 #5
0
        private bool CheckAndLock(OutBillMaster 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;
                    OutBillMasterRepository.SaveChanges();
                    ps.Messages.Add("完成锁定当前订单");
                    NotifyConnection(ps.Clone());
                    return(true);
                }
                catch (Exception)
                {
                    ps.State = StateType.Error;
                    ps.Errors.Add("锁定当前订单失败不可以进行分配!");
                    NotifyConnection(ps.Clone());
                    return(false);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 出库审核
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="userName">登陆用户</param>
        /// <returns></returns>
        public bool Audit(string billNo, string userName, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);
            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (outbm != null && outbm.Status == "1")
            {
                outbm.Status         = "2";
                outbm.VerifyDate     = DateTime.Now;
                outbm.UpdateTime     = DateTime.Now;
                outbm.VerifyPersonID = employee.ID;
                OutBillMasterRepository.SaveChanges();
                result = true;
            }
            return(result);
        }
예제 #7
0
        public bool Add(OutBillMaster outBillMaster, string userName, out string errorInfo)
        {
            errorInfo = string.Empty;
            var outbm    = new OutBillMaster();
            var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

            if (employee != null)
            {
                try
                {
                    outbm.BillNo          = outBillMaster.BillNo;
                    outbm.BillDate        = outBillMaster.BillDate;
                    outbm.BillTypeCode    = outBillMaster.BillTypeCode;
                    outbm.WarehouseCode   = outBillMaster.WarehouseCode;
                    outbm.OperatePersonID = employee.ID;
                    outbm.Status          = "1";
                    outbm.VerifyPersonID  = outBillMaster.VerifyPersonID;
                    outbm.VerifyDate      = outBillMaster.VerifyDate;
                    outbm.Description     = outBillMaster.Description;
                    //outbm.IsActive = outBillMaster.IsActive;
                    outbm.IsActive       = "1";
                    outbm.UpdateTime     = DateTime.Now;
                    outbm.Origin         = "1";
                    outbm.TargetCellCode = outBillMaster.TargetCellCode;

                    OutBillMasterRepository.Add(outbm);
                    OutBillMasterRepository.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    errorInfo = "添加失败!原因:" + e.Message;
                    return(false);
                }
            }
            else
            {
                errorInfo = "找不到当前登陆用户!请重新登陆!";
                return(false);
            }
        }
예제 #8
0
        /// <summary>
        /// 出库反审
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <returns></returns>
        public bool AntiTrial(string billNo, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm = OutBillMasterRepository.GetQueryable().Where(i => billNo.Contains(i.BillNo));

            if (outbm.Count() > 0)
            {
                foreach (var item in outbm.ToArray())
                {
                    if (item.Status == "2")
                    {
                        try
                        {
                            item.Status         = "1";
                            item.VerifyDate     = null;
                            item.UpdateTime     = DateTime.Now;
                            item.VerifyPersonID = null;
                            OutBillMasterRepository.SaveChanges();
                            result = true;
                        }
                        catch (Exception e)
                        {
                            errorInfo = item.BillNo + "其他人员正在操作!无法保存!" + e.Message;
                        }
                    }
                    else
                    {
                        errorInfo = item.BillNo + "这条单据状态不是已审核!";
                    }
                }
            }
            else
            {
                errorInfo = "保存失败!没有找到这些数据!";
            }
            return(result);
        }
예제 #9
0
        public bool Save(OutBillMaster outBillMaster, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == outBillMaster.BillNo && i.Status == "1");

            if (outbm != null)
            {
                try
                {
                    outbm.BillDate        = outBillMaster.BillDate;
                    outbm.BillTypeCode    = outBillMaster.BillTypeCode;
                    outbm.WarehouseCode   = outBillMaster.WarehouseCode;
                    outbm.OperatePersonID = outBillMaster.OperatePersonID;
                    outbm.Status          = "1";
                    outbm.VerifyPersonID  = outBillMaster.VerifyPersonID;
                    outbm.VerifyDate      = outBillMaster.VerifyDate;
                    outbm.Description     = outBillMaster.Description;
                    outbm.IsActive        = "1";
                    outbm.UpdateTime      = DateTime.Now;
                    outbm.Origin          = "1";
                    outbm.TargetCellCode  = outBillMaster.TargetCellCode;

                    OutBillMasterRepository.SaveChanges();
                    result = true;
                }
                catch (Exception e)
                {
                    errorInfo = "删除失败!原因:" + e.Message;
                }
            }
            else
            {
                errorInfo = "保存失败!没有找到这条数据!";
            }
            return(result);
        }
예제 #10
0
        public bool AllotConfirm(string billNo, string userName, ref string errorInfo)
        {
            try
            {
                var ibm      = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");
                var employee = EmployeeRepository.GetQueryable().FirstOrDefault(i => i.UserName == userName);

                if (employee == null)
                {
                    errorInfo = "当前用户不存在或不可用,未能审核!";
                    return(false);
                }
                if (ibm == null)
                {
                    errorInfo = "当前订单状态不是已分配,或当前订单不存在!";
                    return(false);
                }
                if (!(ibm.OutBillDetails.All(b => b.BillQuantity == b.AllotQuantity) &&
                      ibm.OutBillDetails.Sum(b => b.BillQuantity) == ibm.OutBillAllots.Sum(a => a.AllotQuantity)))
                {
                    errorInfo = "当前订单分配未完成或分配结果不正确!";
                    return(false);
                }
                if (!string.IsNullOrEmpty(ibm.LockTag))
                {
                    errorInfo = "当前订单其他人正在操作,请稍候重试!";
                    return(false);
                }
                using (var scope = new TransactionScope())
                {
                    if (MoveBillCreater.CheckIsNeedSyncMoveBill(ibm.WarehouseCode))
                    {
                        var moveBillMaster = MoveBillCreater.CreateMoveBillMaster(ibm.WarehouseCode, "3001", employee.ID.ToString());
                        MoveBillCreater.CreateSyncMoveBillDetail(moveBillMaster);
                        moveBillMaster.Status         = "2";
                        moveBillMaster.Description    = "出库生成同步移库单!";
                        moveBillMaster.VerifyDate     = DateTime.Now;
                        moveBillMaster.VerifyPersonID = employee.ID;
                        if (MoveBillCreater.CheckIsNeedSyncMoveBill(ibm.WarehouseCode))
                        {
                            errorInfo = "生成同步移库单不完整,请重新确认!";
                            return(false);
                        }
                        else
                        {
                            ibm.MoveBillMasterBillNo = moveBillMaster.BillNo;
                        }
                    }

                    ibm.Status     = "4";
                    ibm.UpdateTime = DateTime.Now;
                    OutBillMasterRepository.SaveChanges();
                    scope.Complete();
                    return(true);
                }
            }
            catch (Exception e)
            {
                errorInfo = "确认分配失败,详情:" + e.Message;
                return(false);
            }
        }
예제 #11
0
        public bool AllotCancel(string billNo, out string strResult)
        {
            bool result = false;
            var  ibm    = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo && i.Status == "3");

            if (ibm != null)
            {
                if (string.IsNullOrEmpty(ibm.LockTag))
                {
                    try
                    {
                        using (var scope = new TransactionScope())
                        {
                            var outAllot = OutBillAllotRepository.GetQueryable()
                                           .Where(o => o.BillNo == ibm.BillNo)
                                           .ToArray();

                            var storages = outAllot.Select(i => i.Storage).ToArray();

                            if (!Locker.Lock(storages))
                            {
                                strResult = "锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!";
                                return(false);
                            }

                            outAllot.AsParallel().ForAll(
                                (Action <OutBillAllot>) delegate(OutBillAllot o)
                            {
                                if (o.Storage.ProductCode == o.ProductCode &&
                                    o.Storage.OutFrozenQuantity >= o.AllotQuantity)
                                {
                                    lock (o.OutBillDetail)
                                    {
                                        o.OutBillDetail.AllotQuantity -= o.AllotQuantity;
                                    }
                                    o.Storage.OutFrozenQuantity -= o.AllotQuantity;
                                    o.Storage.LockTag            = string.Empty;
                                }
                                else
                                {
                                    throw new Exception("储位的卷烟或出库冻结量与当前分配不符,信息可能被异常修改,不能取消当前出库分配!");
                                }
                            }
                                );

                            OutBillAllotRepository.SaveChanges();

                            OutBillAllotRepository.GetObjectSet()
                            .DeleteEntity(i => i.BillNo == ibm.BillNo);

                            ibm.Status     = "2";
                            ibm.UpdateTime = DateTime.Now;
                            OutBillMasterRepository.SaveChanges();
                            result    = true;
                            strResult = "取消成功";

                            scope.Complete();
                        }
                    }
                    catch (Exception e)
                    {
                        strResult = "取消分配失败,详情:" + e.Message;
                    }
                }
                else
                {
                    strResult = "当前订单其他人正在操作,请稍候重试!";
                }
            }
            else
            {
                strResult = "当前订单状态不是已分配,或当前订单不存在!";
            }
            return(result);
        }
예제 #12
0
        /// <summary>
        /// 出库结单
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="errorInfo">错误信息</param>
        /// <returns></returns>
        public bool Settle(string billNo, out string errorInfo)
        {
            bool result = false;

            errorInfo = string.Empty;
            var outbm = OutBillMasterRepository.GetQueryable().FirstOrDefault(i => i.BillNo == billNo);

            if (outbm != null && outbm.Status == "5")
            {
                using (var scope = new TransactionScope())
                {
                    try
                    {
                        //结单移库单,修改冻结量
                        var moveDetail = MoveBillDetailRepository.GetQueryable()
                                         .Where(m => m.BillNo == outbm.MoveBillMasterBillNo &&
                                                m.Status != "2");
                        //结单出库单,修改冻结量
                        var outAllot = OutBillAllotRepository.GetQueryable()
                                       .Where(o => o.BillNo == outbm.BillNo &&
                                              o.Status != "2");

                        var sourceStorages = moveDetail.Select(m => m.OutStorage).ToArray();
                        var targetStorages = moveDetail.Select(m => m.InStorage).ToArray();
                        var storages       = outAllot.Select(i => i.Storage).ToArray();

                        if (!Locker.Lock(storages) ||
                            !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("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能结单!");
                            }
                        }
                            );
                        MoveBillDetailRepository.SaveChanges();

                        outAllot.AsParallel().ForAll(
                            (Action <OutBillAllot>) delegate(OutBillAllot o)
                        {
                            if (o.Storage.ProductCode == o.ProductCode &&
                                o.Storage.OutFrozenQuantity >= o.AllotQuantity)
                            {
                                o.Storage.OutFrozenQuantity -= o.AllotQuantity;
                                o.Storage.LockTag            = string.Empty;
                            }
                            else
                            {
                                throw new Exception("储位的卷烟或入库冻结量与当前分配不符,信息可能被异常修改,不能结单!");
                            }
                        }
                            );

                        if (outbm.MoveBillMaster != null)
                        {
                            outbm.MoveBillMaster.Status     = "4";
                            outbm.MoveBillMaster.UpdateTime = DateTime.Now;
                        }

                        outbm.Status     = "6";
                        outbm.UpdateTime = DateTime.Now;
                        OutBillMasterRepository.SaveChanges();
                        scope.Complete();
                        result = true;
                    }
                    catch (Exception e)
                    {
                        errorInfo = "出库单结单出错!原因:" + e.Message;
                        return(false);
                    }
                }
            }
            return(result);
        }
예제 #13
0
        /// <summary>
        /// 出库分配
        /// </summary>
        /// <param name="outBillMaster">出库主单</param>
        /// <returns></returns>
        public bool OutAllot(OutBillMaster outBillMaster, Guid employeeId)
        {
            try
            {
                bool result = false;
                //出库单出库
                var storages = StorageRepository.GetQueryable().Where(s => s.CellCode == outBillMaster.TargetCellCode &&
                                                                      s.Quantity - s.OutFrozenQuantity > 0).ToArray();

                if (!Locker.Lock(storages))
                {
                    throw new Exception("锁定储位失败,储位其他人正在操作,无法取消分配请稍候重试!");
                }
                var outDetails = OutBillDetailRepository.GetQueryableIncludeProduct()
                                 .Where(o => o.BillNo == 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          = outBillMaster.BillNo,
                                    OutBillDetailId = o.ID,
                                    ProductCode     = o.ProductCode,
                                    CellCode        = s.CellCode,
                                    StorageCode     = s.StorageCode,
                                    UnitCode        = o.UnitCode,
                                    AllotQuantity   = allotQuantity,
                                    RealQuantity    = allotQuantity,
                                    Status          = "2"
                                };
                                lock (outBillMaster.OutBillAllots)
                                {
                                    outBillMaster.OutBillAllots.Add(billAllot);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (o.BillQuantity - o.AllotQuantity > 0)
                    {
                        throw new Exception(o.ProductCode + " " + o.Product.ProductName + "库存不足,未能结单!");
                    }
                });

                result = true;
                storages.AsParallel().ForAll(s => s.LockTag = string.Empty);
                //出库结单
                outBillMaster.Status         = "6";
                outBillMaster.VerifyDate     = DateTime.Now;
                outBillMaster.VerifyPersonID = employeeId;
                outBillMaster.UpdateTime     = DateTime.Now;
                OutBillMasterRepository.SaveChanges();

                return(result);
            }
            catch (AggregateException ex)
            {
                infoStr = "审核失败,详情:" + ex.InnerExceptions.Select(i => i.Message).Aggregate((m, n) => m + n);
                return(false);
            }
        }