Exemplo n.º 1
0
        public ResultModel Update(UserModel user, int repoApplyId, List<int> stockIds, string memo, int deptId)
        {
            ResultModel result = new ResultModel();

            //获取质押申请
            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.RepoApplyDetailDAL detailDAL = new RepoApplyDetailDAL();
                NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证质押申请
                    result = repoapplyDAL.Get(user, repoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.RepoApply repoApply = result.ReturnValue as Model.RepoApply;
                    if (repoApply == null || repoApply.RepoApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "质押申请获取失败";
                        return result;
                    }

                    //获取主申请
                    result = applyDAL.Get(user, repoApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请获取失败";
                        return result;
                    }

                    //更新主申请
                    NFMT.User.Model.Department dept = NFMT.User.UserProvider.Departments.FirstOrDefault(temp => temp.DeptId == deptId);
                    if (dept == null || dept.DeptId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请部门不存在";
                        return result;
                    }

                    apply.ApplyDesc = memo;
                    apply.ApplyDept = dept.DeptId;
                    //apply.ApplyDeptName = dept.DeptName;
                    result = applyDAL.Update(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    //获了质押申请明细
                    result = detailDAL.Load(user, repoApply.RepoApplyId);
                    if (result.ResultStatus != 0)
                        return result;
                    List<Model.RepoApplyDetail> details = result.ReturnValue as List<Model.RepoApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "明细获取失败";
                        return result;
                    }

                    //作废明细
                    foreach (Model.RepoApplyDetail detail in details)
                    {
                        if (detail.DetailStatus == StatusEnum.已生效)
                            detail.DetailStatus = StatusEnum.已录入;
                        result = detailDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //获取库存
                    foreach (int stockId in stockIds)
                    {
                        result = stockDAL.Get(user, stockId);
                        if (result.ResultStatus != 0)
                            return result;

                        Model.Stock stock = result.ReturnValue as Model.Stock;
                        if (stock == null || stock.StockId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存获取失败";
                            return result;
                        }

                        if (stock.StockStatus != StockStatusEnum.质押库存)
                        {
                            result.ResultStatus = -1;
                            result.Message = "库存非质押状态,不能进行回购操作";
                            return result;
                        }

                        //添加明细
                        Model.RepoApplyDetail detail = new RepoApplyDetail();
                        detail.DetailStatus = StatusEnum.已生效;
                        detail.RepoApplyId = repoApply.RepoApplyId;
                        detail.StockId = stock.StockId;
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Exemplo n.º 2
0
        public ResultModel RepoApplyInvalid(UserModel user, int repoApplyId)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //获取回购申请
                    NFMT.WareHouse.DAL.RepoApplyDAL repoApplyDAL = new RepoApplyDAL();
                    result = repoApplyDAL.Get(user, repoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.Model.RepoApply repoApply = result.ReturnValue as NFMT.WareHouse.Model.RepoApply;

                    //获取申请主表
                    NFMT.Operate.BLL.ApplyBLL applyBLL = new Operate.BLL.ApplyBLL();
                    result = applyBLL.Get(user, repoApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply apply = result.ReturnValue as NFMT.Operate.Model.Apply;

                    //作废申请主表
                    result = applyBLL.Invalid(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废回购申请明细
                    NFMT.WareHouse.DAL.RepoApplyDetailDAL repoApplyDetailDAL = new RepoApplyDetailDAL();
                    result = repoApplyDetailDAL.Invalid(user, repoApplyId, string.Empty);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.DAL.StockExclusiveDAL stockExclusiveDAL = new StockExclusiveDAL();
                    result = stockExclusiveDAL.Invalid(user, apply.ApplyId, repoApplyId, string.Empty);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = string.Format("操作失败,{0}", ex.Message);
                result.ResultStatus = -1;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Exemplo n.º 3
0
        public ResultModel RepoApplyUpdateHandle(UserModel user, NFMT.Operate.Model.Apply apply, int repoApplyId, List<Model.RepoApplyDetail> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
                    result = applyDAL.Get(user, apply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.Operate.Model.Apply applyRes = result.ReturnValue as NFMT.Operate.Model.Apply;
                    if (applyRes == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取申请失败";
                        return result;
                    }

                    applyRes.ApplyTime = apply.ApplyTime;
                    applyRes.EmpId = apply.EmpId;
                    applyRes.ApplyDept = apply.ApplyDept;
                    applyRes.ApplyCorp = apply.ApplyCorp;
                    applyRes.ApplyDesc = apply.ApplyDesc;

                    result = applyDAL.Update(user, applyRes);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.WareHouse.DAL.RepoApplyDetailDAL repoApplyDetailDAL = new RepoApplyDetailDAL();
                    result = repoApplyDetailDAL.InvalidAll(user, repoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    foreach (Model.RepoApplyDetail detail in details)
                    {
                        result = repoApplyDetailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Exemplo n.º 4
0
        public ResultModel Confirm(UserModel user, int repoApplyId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockDAL stockDAL = new StockDAL();
                DAL.RepoApplyDAL repoApplyDAL = new RepoApplyDAL();
                Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
                DAL.RepoApplyDetailDAL detailDAL = new RepoApplyDetailDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证回购申请
                    result = repoApplyDAL.Get(user, repoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.RepoApply repoApply = result.ReturnValue as Model.RepoApply;
                    if (repoApply == null || repoApply.RepoApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "回购申请不存在";
                        return result;
                    }

                    //验证主申请
                    result = applyDAL.Get(user, repoApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //验证是否执行完成
                    result = repoapplyDAL.CheckStockOutCanConfirm(user, repoApply.RepoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Common.StatusEnum status = (Common.StatusEnum)result.ReturnValue;

                    //获取已生效回购申请明细
                    result = detailDAL.Load(user, repoApply.RepoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.RepoApplyDetail> details = result.ReturnValue as List<Model.RepoApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取回购申请明细失败";
                        return result;
                    }

                    //主申请更新状态至已完成
                    if (status == StatusEnum.已完成)
                        result = applyDAL.Confirm(user, apply);
                    else if (status == StatusEnum.部分完成)
                        result = applyDAL.PartiallyConfirm(user, apply);
                    else
                    {
                        result.ResultStatus = -1;
                        result.Message = "更新主申请状态失败";
                        return result;
                    }
                    if (result.ResultStatus != 0)
                        return result;

                    //回购申请明细更新状态至已完成
                    foreach (Model.RepoApplyDetail detail in details)
                    {
                        //回购申请明细更新状态至已完成
                        result = detailDAL.Confirm(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Exemplo n.º 5
0
        public ResultModel RepoApplyCreateHandle(UserModel user, Operate.Model.Apply apply, RepoApply repoApply, List<RepoApplyDetail> details)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //写入申请主表
                    NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
                    result = applyDAL.Insert(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    int applyId = (int)result.ReturnValue;
                    repoApply.ApplyId = applyId;

                    //写入回购申请表
                    NFMT.WareHouse.DAL.RepoApplyDAL repoApplyDAL = new RepoApplyDAL();
                    result = repoApplyDAL.Insert(user, repoApply);
                    if (result.ResultStatus != 0)
                        return result;

                    int repoApplyId = (int)result.ReturnValue;

                    //List<Model.StockExclusive> listStockExclusives = new List<StockExclusive>();

                    //写入回购申请明细表
                    NFMT.WareHouse.DAL.RepoApplyDetailDAL detailDAL = new RepoApplyDetailDAL();
                    foreach (Model.RepoApplyDetail detail in details)
                    {
                        detail.RepoApplyId = repoApplyId;
                        result = detailDAL.Insert(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }
Exemplo n.º 6
0
        public ResultModel Invalid(UserModel user, int repoApplyId)
        {
            ResultModel result = new ResultModel();

            DAL.StockDAL stockDAL = new StockDAL();
            DAL.RepoApplyDAL repoApplyDAL = new RepoApplyDAL();
            Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();
            DAL.RepoApplyDetailDAL detailDAL = new RepoApplyDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证出库申请
                    result = repoApplyDAL.Get(user, repoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.RepoApply repoApply = result.ReturnValue as Model.RepoApply;
                    if (repoApply == null || repoApply.RepoApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "回购申请不存在";
                        return result;
                    }

                    //获取主申请实体
                    result = applyDAL.Get(user, repoApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //获取申请明细
                    result = detailDAL.Load(user, repoApply.RepoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<RepoApplyDetail> details = result.ReturnValue as List<RepoApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "申请明细获取失败";
                        return result;
                    }

                    //作废主申请
                    result = applyDAL.Invalid(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废申请明细
                    foreach (Model.RepoApplyDetail detail in details)
                    {
                        if (detail.DetailStatus == StatusEnum.已生效)
                            detail.DetailStatus = StatusEnum.已录入;
                        result = detailDAL.Invalid(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
                return result;
            }

            return result;
        }
Exemplo n.º 7
0
        public ResultModel ConfirmCancel(UserModel user, int repoApplyId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.RepoApplyDAL repoApplyDAL = new RepoApplyDAL();
                DAL.RepoApplyDetailDAL repoApplyDetailDAL = new RepoApplyDetailDAL();
                Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL();

                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    //验证回购申请
                    result = repoApplyDAL.Get(user, repoApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.RepoApply repoApply = result.ReturnValue as Model.RepoApply;
                    if (repoApply == null || repoApply.RepoApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "回购申请不存在";
                        return result;
                    }

                    //验证主申请
                    result = applyDAL.Get(user, repoApply.ApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply;
                    if (apply == null || apply.ApplyId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主申请不存在";
                        return result;
                    }

                    //主申请状态更新至已生效
                    result = applyDAL.ConfirmCancel(user, apply);
                    if (result.ResultStatus != 0)
                        return result;

                    //回购申请明细,在已完成状态下的更新至已生效
                    //获取已关闭的明细
                    result = repoApplyDetailDAL.Load(user, repoApply.RepoApplyId, Common.StatusEnum.已完成);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.RepoApplyDetail> details = result.ReturnValue as List<Model.RepoApplyDetail>;
                    if (details == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取申请明细失败";
                        return result;
                    }

                    foreach (Model.RepoApplyDetail detail in details)
                    {
                        result = repoApplyDetailDAL.ConfirmCancel(user, detail);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Exemplo n.º 8
0
        public ResultModel RepoUpdateHandle(UserModel user, int repoId, string sids, string memo)
        {
            ResultModel result = new ResultModel();
            DAL.RepoDetailDAL repoDetailDAL = new RepoDetailDAL();
            NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL();
            NFMT.WareHouse.Model.Stock stock = new Stock();
            NFMT.WareHouse.DAL.RepoApplyDetailDAL repoApplyDetailDAL = new RepoApplyDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = repoDAL.Get(user, repoId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Repo repo = result.ReturnValue as Model.Repo;
                    if (repo == null)
                    {
                        result.ResultStatus = -1;
                        return result;
                    }

                    repo.Memo = memo;

                    //更新回购
                    result = repoDAL.Update(user, repo);
                    if (result.ResultStatus != 0)
                        return result;

                    //作废所有该回购下的明细
                    result = repoDetailDAL.InvalidAll(user, repoId);
                    if (result.ResultStatus != 0)
                        return result;

                    string[] splits = sids.Split(',');
                    if (splits != null && splits.Length > 0)
                    {
                        foreach (string str in splits)
                        {
                            //获取库存信息
                            result = stockDAL.Get(user, Convert.ToInt32(str));
                            if (result.ResultStatus != 0)
                                return result;

                            stock = result.ReturnValue as NFMT.WareHouse.Model.Stock;
                            if (stock == null)
                            {
                                result.ResultStatus = -1;
                                return result;
                            }

                            result = repoApplyDetailDAL.GetDetailId(user, repo.RepoApplyId, Convert.ToInt32(str));
                            if (result.ResultStatus != 0)
                                return result;

                            int detailId = (int)result.ReturnValue;

                            //写入质押明细表
                            result = repoDetailDAL.Insert(user, new RepoDetail()
                            {
                                RepoId = repoId,
                                RepoApplyDetailId = detailId,
                                StockId = Convert.ToInt32(str),
                                RepoWeight = stock.GrossAmount,
                                Unit = stock.UintId
                            });
                            if (result.ResultStatus != 0)
                                return result;
                        }
                        scope.Complete();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }