public ResultModel Complete(UserModel user, int stopLossId) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = stoplossDAL.Get(user, stopLossId); if (result.ResultStatus != 0) return result; Model.StopLoss resultObj = result.ReturnValue as StopLoss; if (resultObj == null || resultObj.StopLossId <= 0) { result.ResultStatus = -1; result.Message = "该数据不存在,不能进行执行完成操作"; return result; } //执行完成 result = stoplossDAL.Complete(user, resultObj); if (result.ResultStatus != 0) return result; //加载明细 DAL.StopLossDetailDAL stopLossDetailDAL = new StopLossDetailDAL(); result = stopLossDetailDAL.Load(user, resultObj.StopLossId); if (result.ResultStatus != 0) return result; List<Model.StopLossDetail> details = result.ReturnValue as List<Model.StopLossDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取止损明细失败"; return result; } foreach (Model.StopLossDetail detail in details) { result = stopLossDetailDAL.Complete(user, detail); 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; }
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; }
public ResultModel Create(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 = 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.Message = "获取止损申请失败"; result.ResultStatus = -1; return result; } result = stoplossDAL.IsWeightCanStopLoss(user, stopLoss.StopLossApplyId, stopLoss.FuturesCodeId, stopLossApply.StopLossWeight, stopLoss.StopLossWeight, false, 0); if (result.ResultStatus != 0) return result; stopLoss.PricingDirection = stopLossApply.PricingDirection; stopLoss.PricingTime = DateTime.Now; stopLoss.StopLosser = user.EmpId; stopLoss.StopLossStatus = Common.StatusEnum.已录入; //写入止损信息 result = stoplossDAL.Insert(user, stopLoss); if (result.ResultStatus != 0) return result; //写入明细信息 if (details != null && details.Any()) { int StopLossId = (int)result.ReturnValue; foreach (Model.StopLossDetail detail in details) { detail.StopLossId = StopLossId; 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; }
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; }
public ResultModel CompleteCancel(UserModel user, int stopLossId) { ResultModel result = new ResultModel(); try { DAL.StopLossDetailDAL stopLossDetailDAL = new StopLossDetailDAL(); Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证止损 result = stoplossDAL.Get(user, stopLossId); if (result.ResultStatus != 0) return result; Model.StopLoss stopLoss = result.ReturnValue as StopLoss; if (stopLoss == null || stopLoss.StopLossId <= 0) { result.ResultStatus = -1; result.Message = "该数据不存在,不能进行执行完成取消操作"; return result; } //止损完成取消 result = stoplossDAL.CompleteCancel(user, stopLoss); if (result.ResultStatus != 0) return result; //获取已完成止损明细 result = stopLossDetailDAL.Load(user, stopLoss.StopLossId, Common.StatusEnum.已完成); if (result.ResultStatus != 0) return result; List<Model.StopLossDetail> details = result.ReturnValue as List<Model.StopLossDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取止损明细错误"; return result; } //将所有已完成止损明细更新至已生效 foreach (Model.StopLossDetail detail in details) { result = stopLossDetailDAL.CompleteCancel(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }