Exemplo n.º 1
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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
        public ResultModel CompleteCancel(UserModel user, int id)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //验证子合约
                    result = this.contractsubDAL.Get(user, id);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.ContractSub resultObj = result.ReturnValue as Model.ContractSub;
                    if (resultObj == null || resultObj.SubId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约不存在";
                        return result;
                    }

                    //验证合约,合约状态不为已生效则不能进行完成撤销
                    DAL.ContractDAL contractDAL = new ContractDAL();
                    result = contractDAL.Get(user, resultObj.ContractId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.Contract contract = result.ReturnValue as Model.Contract;
                    if (contract == null || contract.ContractId <= 0)
                    {
                        result.Message = "子合约未有对应的合约";
                        result.ResultStatus = -1;
                        return result;
                    }

                    if (contract.ContractStatus != StatusEnum.已生效)
                    {
                        result.ResultStatus = -1;
                        result.Message = "主合约非已生效状态,不能进行完成撤销操作。";
                        return result;
                    }

                    result = this.contractsubDAL.CompleteCancel(user, resultObj);
                    if (result.ResultStatus != 0)
                        return result;

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

            return result;
        }