示例#1
0
        public ResultModel UpdateMain(UserModel user, Model.ReceivableAllot rec, ref List<Model.RecAllotDetail> details)
        {
            ResultModel result = new ResultModel();

            //获取分配
            result = this.receivableallotDAL.Get(user, rec.ReceivableAllotId);
            if (result.ResultStatus != 0)
                return result;

            Model.ReceivableAllot resultObj = result.ReturnValue as Model.ReceivableAllot;
            if (resultObj == null || resultObj.ReceivableAllotId <= 0)
            {
                result.ResultStatus = -1;
                result.Message = "分配不存在";
                return result;
            }

            //更新分配
            decimal sumBala = details.Sum(temp => temp.AllotBala);
            resultObj.AllotBala = sumBala;
            resultObj.AllotDesc = rec.AllotDesc;
            result = this.receivableallotDAL.Update(user, resultObj);
            if (result.ResultStatus != 0)
                return result;

            DAL.RecAllotDetailDAL detailDAL = new RecAllotDetailDAL();
            //获取当前分配下所有有效明细
            result = detailDAL.Load(user, resultObj.ReceivableAllotId);
            if (result.ResultStatus != 0)
                return result;

            List<Model.RecAllotDetail> resultDetails = result.ReturnValue as List<Model.RecAllotDetail>;
            if (resultDetails == null)
            {
                result.ResultStatus = -1;
                result.Message = "获取明细失败";
                return result;
            }
            //作废所有有效明细
            foreach (Model.RecAllotDetail d in resultDetails)
            {
                if (d.DetailStatus == StatusEnum.已生效)
                    d.DetailStatus = StatusEnum.已录入;
                result = detailDAL.Invalid(user, d);
                if (result.ResultStatus != 0)
                    return result;
            }

            foreach (Model.RecAllotDetail detail in details)
            {
                int detailId = 0;

                detail.DetailStatus = StatusEnum.已生效;
                detail.AllotId = resultObj.ReceivableAllotId;
                result = detailDAL.Insert(user, detail);
                if (result.ResultStatus != 0)
                    return result;

                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailId))
                {
                    result.ResultStatus = -1;
                    result.Message = "收款分配明细更新失败";
                    return result;
                }

                detail.DetailId = detailId;
            }

            return result;
        }
示例#2
0
        /// <summary>
        ///  有用,创建分配主表和明细表
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rec"></param>
        /// <param name="details"></param>
        /// <returns></returns>
        public ResultModel CreateMain(UserModel user,Model.ReceivableAllot rec,ref List<Model.RecAllotDetail> details)
        {
            ResultModel result = new ResultModel();

            decimal sumBala = details.Sum(temp=>temp.AllotBala);

            rec.AllotBala = sumBala;
            rec.AllotStatus = StatusEnum.已录入;
            result = this.receivableallotDAL.Insert(user,rec);
            if (result.ResultStatus != 0)
                return result;

            int allotId = 0;
            if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out allotId))
            {
                result.ResultStatus = -1;
                result.Message = "收款分配失败";
                return result;
            }

            DAL.RecAllotDetailDAL detailDAL = new RecAllotDetailDAL();
            foreach (Model.RecAllotDetail detail in details)
            {
                int detailId = 0;

                detail.DetailStatus = StatusEnum.已生效;
                detail.AllotId = allotId;
                result = detailDAL.Insert(user, detail);
                if (result.ResultStatus != 0)
                    return result;

                if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailId))
                {
                    result.ResultStatus = -1;
                    result.Message = "收款分配明细新增失败";
                    return result;
                }

                detail.DetailId = detailId;
            }

            return result;
        }