Esempio n. 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;
        }
Esempio n. 2
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;
        }