Пример #1
0
        internal ResultModel Update(NFMT.Common.UserModel user, Contract.Model.Contract contract, Model.ContractDetail contractDetail, Model.ContractPrice contractPrice, List<Model.ContractCorporationDetail> outCorps, List<Model.ContractCorporationDetail> inCorps, List<Model.ContractDept> depts, List<NFMT.Contract.Model.ContractClause> contractClauses, List<Model.ContractTypeDetail> contractTypes = null)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.ContractDetailDAL detailDAL = new ContractDetailDAL();
                DAL.ContractPriceDAL priceDAL = new ContractPriceDAL();
                DAL.ContractCorporationDetailDAL corpDAL = new ContractCorporationDetailDAL();
                DAL.ContractDeptDAL deptDAL = new ContractDeptDAL();

                if (contract == null)
                {
                    result.Message = "合约不存在";
                    return result;
                }

                result = this.ValidateAuth(user, contract, outCorps, inCorps);
                if (result.ResultStatus != 0)
                    return result;

                result = contractDAL.Get(user, contract.ContractId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.Contract.Model.Contract resultObj = result.ReturnValue as NFMT.Contract.Model.Contract;
                if (resultObj == null)
                {
                    result.Message = "合约不存在";
                    return result;
                }

                //合约更新
                resultObj.ContractDate = contract.ContractDate;
                resultObj.OutContractNo = contract.OutContractNo;
                resultObj.Premium = contract.Premium;
                resultObj.TradeBorder = contract.TradeBorder;
                resultObj.ContractLimit = contract.ContractLimit;
                resultObj.TradeDirection = contract.TradeDirection;
                resultObj.ContractPeriodS = contract.ContractPeriodS;
                resultObj.ContractPeriodE = contract.ContractPeriodE;
                resultObj.InitQP = contract.InitQP;
                resultObj.AssetId = contract.AssetId;
                resultObj.SettleCurrency = contract.SettleCurrency;
                resultObj.SignAmount = contract.SignAmount;
                resultObj.UnitId = contract.UnitId;
                resultObj.PriceMode = contract.PriceMode;
                resultObj.Memo = contract.Memo;
                resultObj.DeliveryStyle = contract.DeliveryStyle;
                resultObj.DeliveryDate = contract.DeliveryDate;

                result = contractDAL.Update(user, resultObj);
                if (result.ResultStatus != 0)
                    return result;

                //明细更新
                result = detailDAL.GetDetailByContractId(user, contract.ContractId);
                if (result.ResultStatus != 0)
                    return result;
                NFMT.Contract.Model.ContractDetail resultDetail = result.ReturnValue as NFMT.Contract.Model.ContractDetail;
                if (resultDetail == null)
                {
                    result.Message = "明细不存在";
                    return result;
                }

                resultDetail.DiscountBase = contractDetail.DiscountBase;
                //resultDetail.DiscountType = contractDetail.DiscountType;
                resultDetail.DiscountRate = contractDetail.DiscountRate / 100;
                resultDetail.DelayType = contractDetail.DelayType;
                resultDetail.DelayRate = contractDetail.DelayRate;
                resultDetail.MoreOrLess = contractDetail.MoreOrLess / 100;

                resultDetail.Status = resultObj.Status;

                result = detailDAL.Update(user, resultDetail);
                if (result.ResultStatus != 0)
                    return result;

                //价格更新
                result = priceDAL.GetPriceByContractId(user, contract.ContractId);
                if (result.ResultStatus != 0)
                    return result;
                NFMT.Contract.Model.ContractPrice resultPrice = result.ReturnValue as NFMT.Contract.Model.ContractPrice;
                if (resultPrice == null)
                {
                    result.Message = "合约价格不存在";
                    return result;
                }
                resultPrice.FixedPrice = contractPrice.FixedPrice;
                resultPrice.FixedPriceMemo = contractPrice.FixedPriceMemo;
                resultPrice.WhoDoPrice = contractPrice.WhoDoPrice;
                resultPrice.DoPriceBeginDate = contractPrice.DoPriceBeginDate;
                resultPrice.DoPriceEndDate = contractPrice.DoPriceEndDate;
                resultPrice.IsQP = contractPrice.IsQP;
                resultPrice.PriceFrom = contractPrice.PriceFrom;
                resultPrice.PriceStyle1 = contractPrice.PriceStyle1;
                resultPrice.PriceStyle2 = contractPrice.PriceStyle2;
                resultPrice.MarginMode = contractPrice.MarginMode;
                resultPrice.MarginAmount = contractPrice.MarginAmount;
                resultPrice.MarginMemo = contractPrice.MarginMemo;
                resultPrice.AlmostPrice = contractPrice.AlmostPrice;

                resultPrice.Status = resultObj.Status;

                result = priceDAL.Update(user, resultPrice);
                if (result.ResultStatus != 0)
                    return result;

                //更新抬头
                //外部公司
                result = corpDAL.LoadCorpListByContractId(user, contract.ContractId, false);
                if (result.ResultStatus != 0)
                    return result;

                List<NFMT.Contract.Model.ContractCorporationDetail> ocs = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                if (ocs == null || ocs.Count == 0)
                {
                    result.Message = "外部公司更新错误";
                    return result;
                }
                foreach (NFMT.Contract.Model.ContractCorporationDetail c in ocs)
                {
                    if (c.DetailStatus == StatusEnum.已生效)
                        c.DetailStatus = StatusEnum.已录入;

                    result = corpDAL.Invalid(user, c);
                    if (result.ResultStatus != 0)
                        return result;
                }

                NFMT.User.Model.Corporation outCorpTemp = null;

                foreach (ContractCorporationDetail corp in outCorps)
                {
                    NFMT.User.Model.Corporation c = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == corp.CorpId);
                    if (c == null || c.CorpId <= 0)
                        return result;

                    if (outCorpTemp == null)
                        outCorpTemp = c;
                    if ((outCorpTemp.ParentId == 0 && outCorps.Count > 1) || (outCorpTemp.ParentId != c.ParentId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "选择的外部公司不属于同一集团";
                        return result;
                    }

                    corp.ContractId = contract.ContractId;
                    corp.CorpName = c.CorpName;
                    corp.IsInnerCorp = false;
                    if (outCorps.IndexOf(corp) == 0)
                        corp.IsDefaultCorp = true;
                    else
                        corp.IsDefaultCorp = false;
                    corp.DetailStatus = StatusEnum.已生效;

                    result = corpDAL.Insert(user, corp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //内部公司
                result = corpDAL.LoadCorpListByContractId(user, contract.ContractId, true);
                if (result.ResultStatus != 0)
                    return result;

                ocs = result.ReturnValue as List<NFMT.Contract.Model.ContractCorporationDetail>;
                if (ocs == null || ocs.Count == 0)
                {
                    result.Message = "内部公司更新错误";
                    return result;
                }
                foreach (NFMT.Contract.Model.ContractCorporationDetail c in ocs)
                {
                    if (c.DetailStatus == StatusEnum.已生效)
                        c.DetailStatus = StatusEnum.已录入;

                    result = corpDAL.Invalid(user, c);
                    if (result.ResultStatus != 0)
                        return result;
                }

                foreach (ContractCorporationDetail corp in inCorps)
                {
                    NFMT.User.Model.Corporation c = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == corp.CorpId);

                    if (c == null || c.CorpId <= 0)
                        return result;
                    corp.CorpName = c.CorpName;
                    corp.ContractId = contract.ContractId;
                    corp.IsInnerCorp = true;
                    if (inCorps.IndexOf(corp) == 0)
                        corp.IsDefaultCorp = true;
                    else
                        corp.IsDefaultCorp = false;
                    corp.DetailStatus = StatusEnum.已生效;

                    result = corpDAL.Insert(user, corp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //更新执行部门
                result = deptDAL.LoadDeptByContractId(user, contract.ContractId);
                if (result.ResultStatus != 0)
                    return result;
                List<NFMT.Contract.Model.ContractDept> ds = result.ReturnValue as List<NFMT.Contract.Model.ContractDept>;
                foreach (NFMT.Contract.Model.ContractDept d in ds)
                {
                    if (d.DetailStatus == StatusEnum.已生效)
                        d.DetailStatus = StatusEnum.已录入;

                    result = deptDAL.Invalid(user, d);
                    if (result.ResultStatus != 0)
                        return result;
                }

                foreach (Model.ContractDept dept in depts)
                {
                    dept.ContractId = contract.ContractId;
                    dept.DetailStatus = Common.StatusEnum.已生效;
                    result = deptDAL.Insert(user, dept);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //更新合约类型
                DAL.ContractTypeDetailDAL contractTypeDAL = new ContractTypeDetailDAL();
                result = contractTypeDAL.LoadContractTypesById(user,resultObj.ContractId);
                if(result.ResultStatus!=0)
                    return result;
                List<Model.ContractTypeDetail> resultContractTypes = result.ReturnValue as List<Model.ContractTypeDetail>;
                if(resultContractTypes == null)
                {
                    result.Message="获取合约类型失败";
                    result.ResultStatus=-1;
                    return result;
                }

                //作废原有合约类型
                foreach(Model.ContractTypeDetail contractType in resultContractTypes)
                {
                    contractType.DetailStatus = StatusEnum.已录入;
                    result = contractTypeDAL.Invalid(user,contractType);
                    if(result.ResultStatus!=0)
                        return result;
                }

                //新增新的合约类型
                foreach (Model.ContractTypeDetail contractType in contractTypes)
                {
                    contractType.ContractId = resultObj.ContractId;
                    contractType.DetailStatus = StatusEnum.已生效;
                    result = contractTypeDAL.Insert(user, contractType);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //作废所有关联合约条款
                DAL.ContractClauseDAL contractClauseDAL = new ContractClauseDAL();
                result = contractClauseDAL.InvalidAll(user, contract.ContractId);
                if (result.ResultStatus != 0)
                    return result;

                if (contractClauses != null && contractClauses.Any())
                {
                    foreach (Model.ContractClause contractClause in contractClauses)
                    {
                        contractClause.ContractId = contract.ContractId;
                        contractClause.RefStatus = StatusEnum.已生效;
                        result = contractClauseDAL.Insert(user, contractClause);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #2
0
        internal ResultModel Update(NFMT.Common.UserModel user, NFMT.Contract.Model.ContractSub sub, NFMT.Contract.Model.SubDetail detail, NFMT.Contract.Model.SubPrice price, List<Model.SubCorporationDetail> outCorps, List<Model.SubCorporationDetail> inCorps,List<Model.SubTypeDetail> subTypes = null)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.ContractDAL contractDAL = new ContractDAL();
                DAL.SubDetailDAL detailDAL = new SubDetailDAL();
                DAL.SubPriceDAL priceDAL = new SubPriceDAL();
                DAL.ContractCorporationDetailDAL conCropDAL = new ContractCorporationDetailDAL();
                DAL.SubCorporationDetailDAL subCorpDAL = new SubCorporationDetailDAL();

                //加载子合约
                result = contractsubDAL.Get(user, sub.SubId);
                if (result.ResultStatus != 0)
                    return result;
                NFMT.Contract.Model.ContractSub resultSub = result.ReturnValue as NFMT.Contract.Model.ContractSub;
                if (resultSub == null || resultSub.SubId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "更新子合约失败";
                    return result;
                }

                //验证主合约是否存在
                result = contractDAL.Get(user, resultSub.ContractId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract;
                if (contract == null || contract.ContractId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "主合约不存在";
                    return result;
                }

                resultSub.AssetId = sub.AssetId;
                resultSub.ContractDate = sub.ContractDate;
                resultSub.ContractLimit = sub.ContractLimit;
                resultSub.ContractSide = sub.ContractSide;
                resultSub.DeliveryDate = sub.DeliveryDate;
                resultSub.DeliveryStyle = sub.DeliveryStyle;
                resultSub.InitQP = sub.InitQP;
                resultSub.Memo = sub.Memo;
                resultSub.OutContractNo = sub.OutContractNo;
                resultSub.Premium = sub.Premium;
                resultSub.PriceMode = sub.PriceMode;
                resultSub.SettleCurrency = sub.SettleCurrency;
                resultSub.TradeBorder = sub.TradeBorder;
                resultSub.TradeDirection = sub.TradeDirection;
                resultSub.UnitId = sub.UnitId;

                resultSub.ShipTime = sub.ShipTime;
                resultSub.ArriveTime = sub.ArriveTime;
                resultSub.ContractPeriodS = sub.ContractPeriodS;
                resultSub.ContractPeriodE = sub.ContractPeriodE;
                resultSub.SignAmount = sub.SignAmount;

                //更新子合约主表
                result = contractsubDAL.Update(user, resultSub);
                if (result.ResultStatus != 0)
                    return result;

                //加载子合约明细表
                result = detailDAL.GetDetailBySubId(user, sub.SubId);
                if (result.ResultStatus != 0)
                    return result;
                NFMT.Contract.Model.SubDetail resultDetail = result.ReturnValue as NFMT.Contract.Model.SubDetail;
                if (resultDetail == null || resultDetail.SubDetailId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约明细数据不存在";
                    return result;
                }

                resultDetail.DiscountBase = detail.DiscountBase;
                resultDetail.DiscountType = detail.DiscountType;
                resultDetail.DiscountRate = detail.DiscountRate;
                resultDetail.DelayType = detail.DelayType;
                resultDetail.DelayRate = detail.DelayRate;
                resultDetail.MoreOrLess = detail.MoreOrLess;

                resultDetail.Status = resultSub.Status;

                //更新子合约明细表
                result = detailDAL.Update(user, resultDetail);
                if (result.ResultStatus != 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约明细更新失败";
                    return result;
                }

                //加载子合约价格表
                result = priceDAL.GetPriceBySubId(user, sub.SubId);
                if (result.ResultStatus != 0)
                    return result;
                NFMT.Contract.Model.SubPrice resultPrice = result.ReturnValue as NFMT.Contract.Model.SubPrice;
                if (resultPrice == null || resultPrice.SubPriceId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约价格数据不存在";
                    return result;
                }

                resultPrice.FixedPrice = price.FixedPrice;
                resultPrice.FixedPriceMemo = price.FixedPriceMemo;
                resultPrice.WhoDoPrice = price.WhoDoPrice;
                resultPrice.DoPriceBeginDate = price.DoPriceBeginDate;
                resultPrice.DoPriceEndDate = price.DoPriceEndDate;
                resultPrice.IsQP = price.IsQP;
                resultPrice.PriceFrom = price.PriceFrom;
                resultPrice.PriceStyle1 = price.PriceStyle1;
                resultPrice.PriceStyle2 = price.PriceStyle2;
                resultPrice.MarginMode = price.MarginMode;
                resultPrice.MarginAmount = price.MarginAmount;
                resultPrice.MarginMemo = price.MarginMemo;
                resultPrice.AlmostPrice = price.AlmostPrice;

                resultPrice.Status = resultSub.Status;

                result = priceDAL.Update(user, resultPrice);
                if (result.ResultStatus != 0)
                    return result;

                #region 子合约抬头
                //校验抬头是否存在主合约中
                //新增抬头到子合约抬头明细表

                //作废现有子合约抬头
                result = subCorpDAL.Load(user, resultSub.SubId, false);
                if (result.ResultStatus != 0)
                    return result;

                List<Model.SubCorporationDetail> resultOutCorps = result.ReturnValue as List<Model.SubCorporationDetail>;
                if (resultOutCorps == null || resultOutCorps.Count == 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约对方抬头加载失败";
                    return result;
                }

                foreach (Model.SubCorporationDetail corp in resultOutCorps)
                {
                    result = subCorpDAL.Invalid(user, corp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                result = subCorpDAL.Load(user, resultSub.SubId, true);
                if (result.ResultStatus != 0)
                    return result;

                List<Model.SubCorporationDetail> resultInCorps = result.ReturnValue as List<Model.SubCorporationDetail>;
                if (resultInCorps == null || resultInCorps.Count == 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约我方抬头加载失败";
                    return result;
                }

                foreach (Model.SubCorporationDetail corp in resultInCorps)
                {
                    result = subCorpDAL.Invalid(user, corp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //获取主合约抬头
                result = conCropDAL.LoadCorpListByContractId(user, contract.ContractId, false);
                if (result.ResultStatus != 0)
                    return result;

                List<Model.ContractCorporationDetail> conOutCorps = result.ReturnValue as List<Model.ContractCorporationDetail>;
                if (conOutCorps == null)
                {
                    result.ResultStatus = -1;
                    result.Message = "主合约对方抬头获取失败";
                    return result;
                }

                result = conCropDAL.LoadCorpListByContractId(user, contract.ContractId, true);
                if (result.ResultStatus != 0)
                    return result;

                List<Model.ContractCorporationDetail> conInCorps = result.ReturnValue as List<Model.ContractCorporationDetail>;
                if (conInCorps == null)
                {
                    result.ResultStatus = -1;
                    result.Message = "主合约我方抬头获取失败";
                    return result;
                }

                foreach (Model.SubCorporationDetail outCorp in outCorps)
                {
                    //验证抬头是否在主合约中
                    if (!conOutCorps.Exists(temp => temp.CorpId == outCorp.CorpId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "主合约对方抬头不存在选中公司,新增失败";
                        return result;
                    }

                    NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == outCorp.CorpId);
                    if (corp == null || corp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约对方抬头不存在";
                        return result;
                    }

                    outCorp.ContractId = contract.ContractId;
                    outCorp.CorpName = corp.CorpName;
                    outCorp.SubId = resultSub.SubId;
                    outCorp.IsInnerCorp = false;
                    if (outCorps.IndexOf(outCorp) == 0)
                        outCorp.IsDefaultCorp = true;
                    else
                        outCorp.IsDefaultCorp = false;
                    outCorp.DetailStatus = StatusEnum.已生效;

                    result = subCorpDAL.Insert(user, outCorp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                foreach (Model.SubCorporationDetail inCorp in inCorps)
                {
                    //验证抬头是否在主合约中
                    if (!conInCorps.Exists(temp => temp.CorpId == inCorp.CorpId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "主合约我方抬头不存在选中公司,新增失败";
                        return result;
                    }

                    NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == inCorp.CorpId);
                    if (corp == null || corp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约我方抬头不存在";
                        return result;
                    }

                    inCorp.ContractId = contract.ContractId;
                    inCorp.SubId = resultSub.SubId;
                    inCorp.CorpName = corp.CorpName;
                    inCorp.IsInnerCorp = true;
                    if (inCorps.IndexOf(inCorp) == 0)
                        inCorp.IsDefaultCorp = true;
                    else
                        inCorp.IsDefaultCorp = false;
                    inCorp.DetailStatus = StatusEnum.已生效;

                    result = subCorpDAL.Insert(user, inCorp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                #endregion

                if (subTypes != null)
                {
                    DAL.SubTypeDetailDAL subTypeDAL = new SubTypeDetailDAL();
                    result = subTypeDAL.LoadSubTypesById(user, resultSub.SubId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.SubTypeDetail> resultSubTypes = result.ReturnValue as List<Model.SubTypeDetail>;
                    if (resultSubTypes == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取子合约类型失败";
                        return result;
                    }

                    //作废原有子合约类型
                    foreach (Model.SubTypeDetail subType in resultSubTypes)
                    {
                        subType.DetailStatus = StatusEnum.已录入;
                        result = subTypeDAL.Invalid(user, subType);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    //新增新子合约类型
                    foreach (Model.SubTypeDetail subType in subTypes)
                    {
                        subType.ContractId = resultSub.ContractId;
                        subType.DetailStatus = StatusEnum.已生效;
                        subType.SubId = resultSub.SubId;

                        result = subTypeDAL.Insert(user, subType);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #3
0
        internal ResultModel Create(NFMT.Common.UserModel user, Contract.Model.Contract contract, Model.ContractDetail contractDetail, Model.ContractPrice contractPrice, List<Model.ContractCorporationDetail> outCorps, List<Model.ContractCorporationDetail> inCorps, List<Model.ContractDept> depts, List<NFMT.Contract.Model.ContractClause> contractClauses,List<Model.ContractTypeDetail> contractTypes = null)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.ContractDetailDAL detailDAL = new ContractDetailDAL();
                DAL.ContractPriceDAL priceDAL = new ContractPriceDAL();
                DAL.ContractCorporationDetailDAL corpDAL = new ContractCorporationDetailDAL();
                DAL.ContractDeptDAL deptDAL = new ContractDeptDAL();
                NFMT.User.DAL.CorporationDAL dal = new User.DAL.CorporationDAL();

                result = this.ValidateAuth(user, contract, outCorps, inCorps);
                if (result.ResultStatus != 0)
                    return result;

                contract.ContractStatus = StatusEnum.已录入;
                result = contractDAL.Insert(user, contract);
                if (result.ResultStatus != 0)
                    return result;
                //获取合约序号
                int contractId = (int)result.ReturnValue;

                contractDetail.ContractId = contractId;
                contractDetail.MoreOrLess = contractDetail.MoreOrLess / 100;
                contractDetail.DiscountRate = contractDetail.DiscountRate / 100;
                result = detailDAL.Insert(user, contractDetail);
                if (result.ResultStatus != 0)
                    return result;

                contractPrice.ContractId = contractId;
                result = priceDAL.Insert(user, contractPrice);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.User.Model.Corporation outCorpTemp = null;
                //新增合约对方抬头明细
                foreach (ContractCorporationDetail corp in outCorps)
                {
                    NFMT.User.Model.Corporation c = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == corp.CorpId);
                    if (c == null || c.CorpId <= 0)
                        return result;

                    if (outCorpTemp == null)
                        outCorpTemp = c;
                    if ((outCorpTemp.ParentId == 0 && outCorps.Count > 1) || (outCorpTemp.ParentId != c.ParentId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "选择的外部公司不属于同一集团";
                        return result;
                    }

                    corp.ContractId = contractId;
                    corp.CorpName = c.CorpName;
                    corp.IsInnerCorp = false;
                    if (outCorps.IndexOf(corp) == 0)
                        corp.IsDefaultCorp = true;
                    else
                        corp.IsDefaultCorp = false;
                    corp.DetailStatus = StatusEnum.已生效;

                    result = corpDAL.Insert(user, corp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //新增己方合约抬头明细
                foreach (ContractCorporationDetail corp in inCorps)
                {
                    result = dal.Get(user, corp.CorpId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.User.Model.Corporation c = result.ReturnValue as NFMT.User.Model.Corporation;
                    if (c == null)
                        return result;
                    corp.CorpName = c.CorpName;
                    corp.ContractId = contractId;
                    corp.IsInnerCorp = true;
                    if (inCorps.IndexOf(corp) == 0)
                        corp.IsDefaultCorp = true;
                    else
                        corp.IsDefaultCorp = false;
                    corp.DetailStatus = StatusEnum.已生效;

                    result = corpDAL.Insert(user, corp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //新增执行部门
                foreach (Model.ContractDept dept in depts)
                {
                    dept.ContractId = contractId;
                    dept.DetailStatus = Common.StatusEnum.已生效;
                    result = deptDAL.Insert(user, dept);
                    if (result.ResultStatus != 0)
                        return result;
                }

                //新增合约类型明细
                if (contractTypes != null)
                {
                    DAL.ContractTypeDetailDAL contractTypeDAL = new ContractTypeDetailDAL();
                    foreach (Model.ContractTypeDetail contractType in contractTypes)
                    {
                        contractType.ContractId = contractId;
                        contractType.DetailStatus = StatusEnum.已生效;
                        result = contractTypeDAL.Insert(user, contractType);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }

                //新增合约条款
                if (contractClauses != null && contractClauses.Any())
                {
                    DAL.ContractClauseDAL contractClauseDAL = new ContractClauseDAL();
                    foreach (Model.ContractClause contractClause in contractClauses)
                    {
                        contractClause.ContractId = contractId;
                        result = contractClauseDAL.Insert(user, contractClause);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }

                if (result.ResultStatus == 0)
                {
                    contract.ContractId = contractId;
                    result.ReturnValue = contract;
                }

                //附件使用
                //创建方法最后返回业务数据Id
                if (result.ResultStatus == 0)
                {
                    contract.ContractId = contractId;
                    result.ReturnValue = contract;
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Пример #4
0
        internal ResultModel Create(NFMT.Common.UserModel user, NFMT.Contract.Model.ContractSub sub, NFMT.Contract.Model.SubDetail detail, NFMT.Contract.Model.SubPrice price, List<Model.SubCorporationDetail> outCorps, List<Model.SubCorporationDetail> inCorps, List<Model.SubTypeDetail> subTypes = null)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.ContractDAL contractDAL = new ContractDAL();
                DAL.SubDetailDAL detailDAL = new SubDetailDAL();
                DAL.SubPriceDAL priceDAL = new SubPriceDAL();

                DAL.ContractCorporationDetailDAL conCropDAL = new ContractCorporationDetailDAL();
                DAL.SubCorporationDetailDAL subCorpDAL = new SubCorporationDetailDAL();

                result = contractDAL.Get(user, sub.ContractId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract;
                if (contract == null || contract.ContractId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "主合约不存在,不能新增子合约";
                    return result;
                }

                //验证子合约签订数量是否在主合约范围内
                if (sub.SignAmount > contract.SignAmount)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约签订数量不能大于主合约签订数量";
                    return result;
                }

                result = contractsubDAL.Load(user, contract.ContractId, NFMT.Common.StatusEnum.已录入);
                if (result.ResultStatus != 0)
                    return result;

                List<Model.ContractSub> subs = result.ReturnValue as List<Model.ContractSub>;
                if (subs == null)
                {
                    result.ResultStatus = -1;
                    result.Message = "获取合约失败";
                    return result;
                }

                decimal sumSignAmount = subs.Sum(temp => temp.SignAmount);
                if (sub.SignAmount > contract.SignAmount - sumSignAmount)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约签订数量不能超过主合约下可签数量";
                    return result;
                }

                sub.SubStatus = StatusEnum.已录入;
                result = contractsubDAL.Insert(user, sub);
                if (result.ResultStatus != 0)
                    return result;

                //获取合约序号
                int subId = (int)result.ReturnValue;
                if (subId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "子合约新增失败";
                    return result;
                }

                detail.SubId = subId;
                detail.MoreOrLess = detail.MoreOrLess / 100;
                detail.DiscountRate = detail.DiscountRate / 100;

                result = detailDAL.Insert(user, detail);
                if (result.ResultStatus != 0)
                    return result;

                price.SubId = subId;
                result = priceDAL.Insert(user, price);
                if (result.ResultStatus != 0)
                    return result;

                if (result.ResultStatus == 0)
                {
                    sub.SubId = subId;
                    result.ReturnValue = sub;
                }

                #region 子合约抬头
                //校验抬头是否存在主合约中
                //新增抬头到子合约抬头明细表

                //获取主合约抬头
                result = conCropDAL.LoadCorpListByContractId(user, contract.ContractId, false);
                if (result.ResultStatus != 0)
                    return result;

                List<Model.ContractCorporationDetail> conOutCorps = result.ReturnValue as List<Model.ContractCorporationDetail>;
                if (conOutCorps == null)
                {
                    result.ResultStatus = -1;
                    result.Message = "主合约对方抬头获取失败";
                    return result;
                }

                result = conCropDAL.LoadCorpListByContractId(user, contract.ContractId, true);
                if (result.ResultStatus != 0)
                    return result;

                List<Model.ContractCorporationDetail> conInCorps = result.ReturnValue as List<Model.ContractCorporationDetail>;
                if (conInCorps == null)
                {
                    result.ResultStatus = -1;
                    result.Message = "主合约我方抬头获取失败";
                    return result;
                }

                foreach (Model.SubCorporationDetail outCorp in outCorps)
                {
                    //验证抬头是否在主合约中
                    if (!conOutCorps.Exists(temp => temp.CorpId == outCorp.CorpId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "主合约对方抬头不存在选中公司,新增失败";
                        return result;
                    }

                    NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == outCorp.CorpId);
                    if (corp == null || corp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约对方抬头不存在";
                        return result;
                    }

                    outCorp.ContractId = contract.ContractId;
                    outCorp.CorpName = corp.CorpName;
                    outCorp.SubId = subId;
                    outCorp.IsInnerCorp = false;
                    if (outCorps.IndexOf(outCorp) == 0)
                        outCorp.IsDefaultCorp = true;
                    else
                        outCorp.IsDefaultCorp = false;
                    outCorp.DetailStatus = StatusEnum.已生效;

                    result = subCorpDAL.Insert(user, outCorp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                foreach (Model.SubCorporationDetail inCorp in inCorps)
                {
                    //验证抬头是否在主合约中
                    if (!conInCorps.Exists(temp => temp.CorpId == inCorp.CorpId))
                    {
                        result.ResultStatus = -1;
                        result.Message = "主合约我方抬头不存在选中公司,新增失败";
                        return result;
                    }

                    NFMT.User.Model.Corporation corp = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == inCorp.CorpId);
                    if (corp == null || corp.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约我方抬头不存在";
                        return result;
                    }

                    inCorp.ContractId = contract.ContractId;
                    inCorp.SubId = subId;
                    inCorp.CorpName = corp.CorpName;
                    inCorp.IsInnerCorp = true;
                    if (inCorps.IndexOf(inCorp) == 0)
                        inCorp.IsDefaultCorp = true;
                    else
                        inCorp.IsDefaultCorp = false;
                    inCorp.DetailStatus = StatusEnum.已生效;

                    result = subCorpDAL.Insert(user, inCorp);
                    if (result.ResultStatus != 0)
                        return result;
                }

                #endregion

                //子合约类型明细
                DAL.SubTypeDetailDAL subTypeDAL = new SubTypeDetailDAL();
                if (subTypes != null)
                {
                    foreach (Model.SubTypeDetail subType in subTypes)
                    {
                        subType.ContractId = sub.ContractId;
                        subType.DetailStatus = StatusEnum.已生效;
                        subType.SubId = subId;
                        result = subTypeDAL.Insert(user, subType);
                        if (result.ResultStatus != 0)
                            return result;
                    }
                }

                if (result.ResultStatus == 0)
                {
                    sub.SubId = subId;
                    result.ReturnValue = sub;
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }