Exemplo n.º 1
0
        public ResultModel Update(UserModel user, NFMT.DoPrice.Model.StopLoss stopLoss, List<NFMT.DoPrice.Model.StopLossDetail> details)
        {
            ResultModel result = new ResultModel();
            DAL.StopLossApplyDAL stopLossApplyDAL = new StopLossApplyDAL();
            DAL.StopLossDetailDAL stopLossDetailDAL = new StopLossDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = stoplossDAL.Get(user, stopLoss.StopLossId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.DoPrice.Model.StopLoss stopLossResult = result.ReturnValue as NFMT.DoPrice.Model.StopLoss;
                    if (stopLossResult == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取止损信息错误";
                        return result;
                    }

                    result = stopLossApplyDAL.Get(user, stopLoss.StopLossApplyId);
                    if (result.ResultStatus != 0)
                        return result;

                    NFMT.DoPrice.Model.StopLossApply stopLossApply = result.ReturnValue as NFMT.DoPrice.Model.StopLossApply;
                    if (stopLossApply == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "获取止损申请信息错误";
                        return result;
                    }
                    result = stoplossDAL.IsWeightCanStopLoss(user, stopLoss.StopLossApplyId, stopLoss.FuturesCodeId, stopLossApply.StopLossWeight, stopLoss.StopLossWeight, true, stopLossResult.StopLossWeight);
                    if (result.ResultStatus != 0)
                        return result;

                    stopLossResult.StopLossWeight = stopLoss.StopLossWeight;
                    stopLossResult.ExchangeId = stopLoss.ExchangeId;
                    stopLossResult.FuturesCodeId = stopLoss.FuturesCodeId;
                    stopLossResult.AvgPrice = stopLoss.AvgPrice;
                    stopLossResult.PricingTime = DateTime.Now;
                    stopLossResult.StopLosser = user.EmpId;

                    //写入止损信息
                    result = stoplossDAL.Update(user, stopLossResult);
                    if (result.ResultStatus != 0)
                        return result;

                    if (details != null && details.Any())
                    {
                        //作废明细
                        result = stopLossDetailDAL.InvalidAll(user, stopLoss.StopLossId);
                        if (result.ResultStatus != 0)
                            return result;

                        //写入明细信息
                        foreach (Model.StopLossDetail detail in details)
                        {
                            result = stopLossDetailDAL.Insert(user, detail);
                            if (result.ResultStatus != 0)
                                return result;
                        }
                    }
                    scope.Complete();
                }
            }
            catch (Exception e)
            {
                result.ResultStatus = -1;
                result.Message = e.Message;
            }

            return result;
        }
Exemplo n.º 2
0
        public ResultModel Invalid(UserModel user, int stopLossId)
        {
            ResultModel result = new ResultModel();
            DAL.StopLossDetailDAL stopLossDetailDAL = new StopLossDetailDAL();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    result = stoplossDAL.Get(user, stopLossId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StopLoss stopLoss = result.ReturnValue as Model.StopLoss;
                    if (stopLoss == null)
                    {
                        result.Message = "不存在止损信息";
                        result.ResultStatus = -1;
                        return result;
                    }

                    result = stoplossDAL.Invalid(user, stopLoss);
                    if (result.ResultStatus != 0)
                        return result;

                    result = stopLossDetailDAL.Load(user, stopLossId);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StopLossDetail> details = result.ReturnValue as List<Model.StopLossDetail>;
                    if (details != null && details.Any())
                    {
                        result = stopLossDetailDAL.InvalidAll(user, stopLossId);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (result.ResultStatus != 0)
                    log.ErrorFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
                else if (log.IsInfoEnabled)
                    log.InfoFormat("{0} {1},类型序号:{2}", user.EmpName, result.Message, result.ReturnValue);
            }

            return result;
        }