/// <summary>
        /// 撤单校验-检查委托单当前状态是否可撤
        /// </summary>
        /// <param name="entrustNumber">委托单号</param>
        /// <param name="tet">委托实体</param>
        /// <param name="strMessage">错误信息</param>
        /// <returns>校验是否通过</returns>
        public override bool CancelOrderValidate(string entrustNumber, out XH_TodayEntrustTableInfo tet,
                                                 ref string strMessage)
        {
            var result = false;

            tet = XHDataAccess.GetTodayEntrustTable(entrustNumber);
            if (tet != null)
            {
                if (tet.OrderStatusId == (int)Types.OrderStateType.DOSUnRequired ||
                    tet.OrderStatusId == (int)Types.OrderStateType.DOSRequiredSoon ||
                    tet.OrderStatusId == (int)Types.OrderStateType.DOSIsRequired ||
                    tet.OrderStatusId == (int)Types.OrderStateType.DOSPartDealed)
                {
                    result = true;
                }
                else
                {
                    strMessage = "GT-2200:[现货撤单校验]该委托状态的委托单不可撤.委托状态=" +
                                 Types.GetOrderStateMsg(tet.OrderStatusId);
                }
            }
            else
            {
                strMessage = "GT-2201:[现货撤单校验]委托单不存在.";
            }

            return(result);
        }
        private void DeleteEntrust(string entrustNumber)
        {
            if (string.IsNullOrEmpty(entrustNumber))
            {
                return;
            }

            //删除前面创建的柜台委托单实例
            bool isSuccess = XHDataAccess.DeleteTodayEntrust(entrustNumber);

            if (!isSuccess)
            {
                RescueManager.Instance.Record_XH_DeleteTodayEntrust(entrustNumber);
            }
        }
        /// <summary>
        /// 内部撤单
        /// </summary>
        /// <param name="tet">委托实体</param>
        /// <param name="strMcErrorMessage">错误信息</param>
        /// <returns>是否成功</returns>
        public override bool InternalCancelOrder(XH_TodayEntrustTableInfo tet, string strMcErrorMessage)
        {
            #region 初始化参数

            //柜台委托单号
            EntrustNumber = tet.EntrustNumber;

            string errInfo = "[委托单号=" + EntrustNumber + ",Message=" + strMcErrorMessage + "]";
            LogHelper.WriteDebug(
                "------xxxxxx------开始进行现货内部撤单(撤单时委托状态为未报或者买卖报盘返回的委托单号无效)XHAcceptLogic.InternalCancelOrder" +
                errInfo);

            Code = tet.SpotCode;

            //资金帐户
            CapitalAccount = tet.CapitalAccount;
            //持仓帐户
            HoldingAccount = tet.StockAccount;

            //GetAccountId(CapitalAccount, HoldingAccount);

            //GetCurrencyType();

            var user = AccountManager.Instance.GetUserByAccount(tet.CapitalAccount);
            if (user != null)
            {
                TradeID = user.UserID;
            }
            //else
            //{
            //    TradeID = counterCacher.GetTraderIdByFundAccount(tet.CapitalAccount);
            //}

            //因为1.1结构修改,内部撤单和外部撤单逻辑已经一致,所以统一使用代码
            //内部撤单也作为一个“特殊”的外部撤单来处理,即柜台自己造一个“撤单回报”
            //发送给ReckonUnit来处理

            //假的撮合委托单号
            string orderNo = Guid.NewGuid().ToString();

            tet.McOrderId = orderNo;

            //假的撮合委托单号也要写入委托信息中,以便后面好删除缓存
            XHDataAccess.UpdateEntrustTable(tet);
            LogHelper.WriteDebug("XHAcceptLogic.InternalCancelOrder添加委托单号映射到ConterCache,OrderNo=" +
                                 orderNo);
            //柜台缓存委托相关信息
            var item = new OrderCacheItem(tet.CapitalAccount, tet.StockAccount,
                                          tet.EntrustNumber,
                                          (
                                              GTA.VTS.Common.CommonObject.Types.TransactionDirection)
                                          Enum.Parse(
                                              typeof(
                                                  GTA.VTS.Common.CommonObject.Types.TransactionDirection),
                                              tet.BuySellTypeId.ToString
                                                  ()));
            item.EntrustAmount = tet.EntrustAmount;
            item.Code          = tet.SpotCode;
            item.TraderId      = TradeID;

            counterCacher.AddOrderMappingInfo(orderNo,
                                              item);

            CancelOrderEntityEx coe = new CancelOrderEntityEx();
            coe.IsInternalCancelOrder = true;
            coe.OrderNo     = orderNo;
            coe.IsSuccess   = true;
            coe.OrderVolume = tet.EntrustAmount - tet.TradeAmount - tet.CancelAmount;
            coe.Id          = Guid.NewGuid().ToString();
            coe.Message     = strMcErrorMessage;

            ReckonCenter.Instace.AcceptCancelXHOrderRpt(coe);

            #endregion

            //内部撤单流程
            //1.资金冻结处理,把资金冻结记录里的金额和费用全部还给资金表,删除冻结记录(实际上清零,不删除,盘后统一删)
            //2.资金处理,把从资金冻结记录还回来的金额和费用加到可用资金,并减去总冻结资金
            //3.持仓冻结处理(买入不处理),把持仓冻结记录中的冻结量还给持仓表,删除冻结记录(实际上清零,不删除,盘后统一删)
            //4.持仓处理(买入不处理),把从持仓冻结记录还回来的持仓量加到可用持仓,并减去总冻结持仓
            //5.委托处理,更新委托状态,成交量,撤单量以及委托消息(OrderMessage)

            #region 已作废

            //实际的处理流程

            /*
             #region 1.资金冻结处理,获取冻结金额和冻结费用,并获取冻结记录的id
             *
             * //冻结金额
             * decimal preFreezeCapital = 0;
             * //冻结费用
             * decimal preFreezeCost = 0;
             *
             * //持仓冻结的id
             * int holdFreezeLogoId = -1;
             * //资金冻结的id
             * int capitalFreezeLogoId = -1;
             *
             * var ca = XHDataAccess.GetCapitalAccountFreeze(EntrustNumber, Types.FreezeType.DelegateFreeze);
             * if (ca == null)
             * {
             *  string msg = "[现货内部撤单]资金冻结记录不存在." + entrustNum;
             *  LogHelper.WriteInfo(msg);
             *  //找不到资金冻结,一样允许撤单,当作冻结的资金全部为0
             *  //CancelOrderFailureProcess(EntrustNumber, 0, 0, 0, strErrorMessage);
             *  //return false;
             * }
             * else
             * {
             *  preFreezeCapital = ca.FreezeCapitalAmount;
             *  preFreezeCost = ca.FreezeCost;
             *  capitalFreezeLogoId = ca.CapitalFreezeLogoId;
             * }
             *
             #endregion
             *
             #region 2.资金处理,把从资金冻结记录还回来的金额和费用加到可用资金,并减去总冻结资金
             * XH_CapitalAccountTable_DeltaInfo capitalDelta = new XH_CapitalAccountTable_DeltaInfo();
             * XH_CapitalAccountTable_DeltaInfo capitalDelta2 = new XH_CapitalAccountTable_DeltaInfo();
             *
             * decimal delta = preFreezeCapital + preFreezeCost;
             *
             * if (delta != 0)
             * {
             *  capitalDelta.AvailableCapitalDelta = delta;
             *  capitalDelta.FreezeCapitalTotalDelta = -delta;
             *
             *  capitalDelta2.AvailableCapitalDelta = -delta;
             *  capitalDelta2.FreezeCapitalTotalDelta = delta;
             *
             *  var capMemory = MemoryDataManager.XHCapitalMemoryList.GetByCapitalAccountLogo(CapitalAccountId);
             *  if (capMemory == null)
             *  {
             *      strErrorMessage = "GT-2206:[现货内部撤单]资金帐户不存在:" + CapitalAccount;
             *      return false;
             *  }
             *
             *  bool isSuccess = capMemory.AddDelta(capitalDelta);
             *
             *
             *  if (!isSuccess)
             *  {
             *
             *      return false;
             *  }
             * }
             *
             *
             #endregion
             *
             * decimal preFreezeHoldAmount = 0m;
             * if (Request.BuySell ==
             *  CommonObject.Types.TransactionDirection.Selling)
             * {
             #region 3.持仓冻结处理(买入不计算),获取持仓冻结记录中的冻结量和冻结id
             *
             *  var hold = XHDataAccess.GetHoldAccountFreeze(EntrustNumber, Types.FreezeType.DelegateFreeze);
             *  if (hold == null)
             *  {
             *      string msg = "[现货内部撤单]持仓冻结不存在";
             *      LogHelper.WriteInfo(msg);
             *      //持仓冻结不存在,一样运行撤单,当作持仓冻结量为0
             *      //CancelOrderFailureProcess(EntrustNumber, -preFreezeCapital, -preFreezeCost, 0, strErrorMessage);
             *      //return false;
             *  }
             *  else
             *  {
             *      preFreezeHoldAmount = hold.PrepareFreezeAmount;
             *      holdFreezeLogoId = hold.HoldFreezeLogoId;
             *  }
             *
             #endregion
             *
             *  //4.持仓处理(买入不计算),把从持仓冻结记录还回来的持仓量加到可用持仓,并减去总冻结持仓
             *  isSuccess = XHCommonLogic.DoXHReckonHoldProcess(preFreezeHoldAmount, ref strErrorMessage,
             *                                                     HoldingAccount, HoldingAccountId);
             *  if (!isSuccess)
             *  {
             *      XHCommonLogic.CancelOrderFailureProcess(EntrustNumber, -preFreezeCapital, -preFreezeCost, 0,
             *                                              strErrorMessage, CapitalAccount, CapitalAccountId,
             *                                              HoldingAccount, HoldingAccountId);
             *      return false;
             *  }
             * }
             *
             *
             * //Clear资金和持仓冻结记录(没有删除),更新委托信息
             * tet = XHDataAccess.GetTodayEntrustTable(EntrustNumber);
             * XHCommonLogic.ProcessCancelOrderStatus(tet);
             *
             * tet.CancelAmount = tet.EntrustAmount - tet.TradeAmount;
             * tet.OrderMessage = strMcErrorMessage;
             *
             * try
             * {
             *  DataManager.ExecuteInTransaction((db, transaction) =>
             *                                       {
             *                                           XHDataAccess.ClearCapitalFreeze(capitalFreezeLogoId, db,
             *                                                                           transaction);
             *                                           XHDataAccess.ClearHoldFreeze(holdFreezeLogoId, db, transaction);
             *
             *                                           XHDataAccess.UpdateEntrustTable(tet, db, transaction);
             *                                       });
             * }
             * catch (Exception ex)
             * {
             *  LogHelper.WriteError(ex.Message, ex);
             *
             *  XHCommonLogic.CancelOrderFailureProcess(EntrustNumber, -preFreezeCapital, -preFreezeCost,
             *                                          -preFreezeHoldAmount,
             *                                          strErrorMessage, CapitalAccount, CapitalAccountId,
             *                                          HoldingAccount, HoldingAccountId);
             *
             *  return false;
             * }
             *
             * ReckonEndObject<XH_TodayEntrustTableInfo, XH_TodayTradeTableInfo> canCleObject =
             *  new ReckonEndObject<XH_TodayEntrustTableInfo, XH_TodayTradeTableInfo>();
             * canCleObject.EntrustTable = tet;
             * canCleObject.TradeID = TradeID;
             * canCleObject.IsSuccess = true;
             * canCleObject.TradeTableList = new List<XH_TodayTradeTableInfo>();
             *
             * OnEndCancelEvent(canCleObject);
             * */

            #endregion

            return(true);
        }
 /// <summary>
 /// 执行删除现货当日委托动作
 /// </summary>
 /// <param name="entrustNumber">委托单号</param>
 /// <returns>是否成功</returns>
 private bool Rescue_XH_DeleteTodayEntrust(string entrustNumber)
 {
     return(XHDataAccess.DeleteTodayEntrust(entrustNumber));
 }