Ejemplo n.º 1
0
        public override IModel CreateModel(SqlDataReader dr)
        {
            RepoApplyDetail repoapplydetail = new RepoApplyDetail();

            int indexDetailId = dr.GetOrdinal("DetailId");
            repoapplydetail.DetailId = Convert.ToInt32(dr[indexDetailId]);

            int indexRepoApplyId = dr.GetOrdinal("RepoApplyId");
            repoapplydetail.RepoApplyId = Convert.ToInt32(dr[indexRepoApplyId]);

            int indexStockId = dr.GetOrdinal("StockId");
            if (dr["StockId"] != DBNull.Value)
            {
                repoapplydetail.StockId = Convert.ToInt32(dr[indexStockId]);
            }

            int indexDetailStatus = dr.GetOrdinal("DetailStatus");
            if (dr["DetailStatus"] != DBNull.Value)
            {
                repoapplydetail.DetailStatus = (Common.StatusEnum)Convert.ToInt32(dr[indexDetailStatus]);
            }

            return repoapplydetail;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        public ResultModel Load(UserModel user, int repoApplyId, Common.StatusEnum status = StatusEnum.已生效)
        {
            ResultModel result = new ResultModel();
            try
            {
                string cmdText = string.Format("select * from dbo.St_RepoApplyDetail where RepoApplyId={0} and DetailStatus>={1}", repoApplyId, (int)StatusEnum.已生效);
                DataTable dt = SqlHelper.ExecuteDataTable(SqlHelper.ConnectionStringNFMT, cmdText, null, CommandType.Text);

                List<RepoApplyDetail> RepoApplyDetails = new List<RepoApplyDetail>();

                foreach (DataRow dr in dt.Rows)
                {
                    RepoApplyDetail repoapplydetail = new RepoApplyDetail();
                    repoapplydetail.DetailId = Convert.ToInt32(dr["DetailId"]);

                    repoapplydetail.RepoApplyId = Convert.ToInt32(dr["RepoApplyId"]);

                    if (dr["StockId"] != DBNull.Value)
                    {
                        repoapplydetail.StockId = Convert.ToInt32(dr["StockId"]);
                    }
                    if (dr["DetailStatus"] != DBNull.Value)
                    {
                        repoapplydetail.DetailStatus = (Common.StatusEnum)Enum.Parse(typeof(Common.StatusEnum), dr["DetailStatus"].ToString());
                    }
                    RepoApplyDetails.Add(repoapplydetail);
                }
                result.AffectCount = dt.Rows.Count;
                result.Message = "获取列表成功";
                result.ResultStatus = 0;
                result.ReturnValue = RepoApplyDetails;
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }

            return result;
        }