QuickOrderViewModel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using GalaSoft.MvvmLight.Ioc;
  4. using Muchinfo.MTPClient.Data;
  5. using Muchinfo.MTPClient.Data.DTO;
  6. using Muchinfo.MTPClient.Data.Enums;
  7. using Muchinfo.MTPClient.Data.Model;
  8. using Muchinfo.MTPClient.Data.Model.Account;
  9. using Muchinfo.MTPClient.Infrastructure.Cache;
  10. using Muchinfo.MTPClient.Infrastructure.Helpers;
  11. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  12. using Muchinfo.MTPClient.Infrastructure.Utilities;
  13. using Muchinfo.MTPClient.IService;
  14. using Muchinfo.MTPClient.Resources;
  15. using Muchinfo.WPF.Controls.Windows;
  16. using System;
  17. using System.Linq;
  18. //----------------------------------------------------------------
  19. //Module Name: $safeprojectname$
  20. //Purpose:
  21. //CopyRight: Muchinfo
  22. //History:
  23. //----------------------------------------------------------------
  24. //DateTime 2016/2/2 16:45:23
  25. //Author
  26. //Description Create
  27. //----------------------------------------------------------------
  28. using System.Timers;
  29. using System.Windows;
  30. namespace Muchinfo.MTPClient.Trade.ViewModels
  31. {
  32. public class QuickOrderViewModel : ViewModelBase
  33. {
  34. private QuoteGoods _currentGoods;
  35. private IGoodsService _igoodsService;
  36. /// <summary>
  37. /// 当前商品
  38. /// </summary>
  39. public QuoteGoods CurrentGoods
  40. {
  41. get { return _currentGoods; }
  42. set
  43. {
  44. Set(() => CurrentGoods, ref _currentGoods, value);
  45. }
  46. }
  47. public QuickOrderViewModel()
  48. {
  49. ////todo:注册改变当前商品消息
  50. MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.SelectGoodsChange, SelectGoodsChange);
  51. MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.QuickSell, QuickSellCommand);
  52. MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.QuickBuy, QuickBuyCommand);
  53. _igoodsService = SimpleIoc.Default.GetInstance<IGoodsService>();
  54. }
  55. private const decimal c_LotBit = 0.01m; //数量的小数位数
  56. /// <summary>
  57. /// 正在加载中
  58. /// </summary>
  59. private bool _isBusy;
  60. public bool IsBusy
  61. {
  62. get { return _isBusy; }
  63. set
  64. {
  65. Set(() => IsBusy, ref _isBusy, value);
  66. }
  67. }
  68. private bool _canOpenMarket;
  69. public bool CanOpenMarket
  70. {
  71. get
  72. {
  73. return _canOpenMarket;
  74. }
  75. set
  76. {
  77. Set(() => CanOpenMarket, ref _canOpenMarket, value);
  78. }
  79. }
  80. private decimal _lot;
  81. /// <summary>
  82. /// 建仓手数
  83. /// </summary>
  84. public decimal Lot
  85. {
  86. get { return _lot; }
  87. set
  88. {
  89. Set(() => Lot, ref _lot, value);
  90. RaisePropertyChanged(() => ShowMessage);
  91. }
  92. }
  93. public string ShowMessage
  94. {
  95. get
  96. {
  97. var returnString = "";
  98. if (Lot % c_LotBit != 0)
  99. returnString = Client_Resource.Trade_OnlyTwoDecimalPlaces;
  100. if (this._currentGoods != null)
  101. {
  102. var minLots = _igoodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId,
  103. _currentGoods.TradeMode, GoodsTradeConts.MINOPENTRADEQTY);
  104. var maxLots = _igoodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId,
  105. _currentGoods.TradeMode, GoodsTradeConts.MAXOPENTRADEQTY);
  106. if (minLots != null && Lot < minLots.FeeValue)
  107. {
  108. returnString = string.Format(Client_Resource.Lot_Open_UpOfMinOpenLot,
  109. minLots.FeeValue);
  110. }
  111. else if (maxLots != null && Lot > maxLots.FeeValue)
  112. {
  113. returnString = string.Format(Client_Resource.Lot_Open_DownOfMaxOpenLot,
  114. maxLots.FeeValue);
  115. }
  116. else if (minLots != null && minLots.FeeValue != 0 && Lot % minLots.FeeValue != 0)
  117. {
  118. returnString = string.Format(Client_Resource.Trade_LotCountIncorrect, minLots.FeeValue);
  119. }
  120. }
  121. else
  122. {
  123. returnString = Client_Resource.Select_Goods_Error;
  124. }
  125. if (Lot <= 0)
  126. {
  127. returnString = Client_Resource.Lot_Vailed_MustUpOfZero;
  128. }
  129. return returnString;
  130. }
  131. }
  132. private Visibility _market_AllownPubsVisiable = Visibility.Collapsed;
  133. public Visibility Market_AllownPubsVisiable
  134. {
  135. get
  136. {
  137. return _market_AllownPubsVisiable;
  138. }
  139. set
  140. {
  141. Set(() => Market_AllownPubsVisiable, ref _market_AllownPubsVisiable, value);
  142. }
  143. }
  144. private decimal _maxLost;
  145. /// <summary>
  146. /// 单笔建仓最大数量
  147. /// </summary>
  148. public decimal MaxLot
  149. {
  150. get { return _maxLost; }
  151. set { Set(() => MaxLot, ref _maxLost, value); }
  152. }
  153. /// <summary>
  154. /// 市价建买
  155. /// </summary>
  156. public RelayCommand BuyCommand
  157. {
  158. get
  159. {
  160. return new RelayCommand(() =>
  161. {
  162. QuickBuy();
  163. });
  164. }
  165. }
  166. /// <summary>
  167. /// 市价建卖
  168. /// </summary>
  169. public RelayCommand SellCommand
  170. {
  171. get
  172. {
  173. return new RelayCommand(QuickSell);
  174. }
  175. }
  176. /// <summary>
  177. /// 快捷卖单消息
  178. /// </summary>
  179. /// <param name="goods">The goods.</param>
  180. private void QuickSellCommand(QuoteGoodsDTO goods)
  181. {
  182. //改变当前商品
  183. SelectGoodsChange(goods);
  184. //改变数量
  185. Lot = goods.Lot;
  186. //内部卖逻辑
  187. QuickSell();
  188. }
  189. /// <summary>
  190. /// 快捷下买单消息
  191. /// </summary>
  192. /// <param name="goods">The goods.</param>
  193. private void QuickBuyCommand(QuoteGoodsDTO goods)
  194. {
  195. //改变当前商品
  196. SelectGoodsChange(goods);
  197. //改变数量
  198. Lot = goods.Lot;
  199. //内部买逻辑
  200. QuickBuy();
  201. }
  202. /// <summary>
  203. /// 选择商品改变
  204. /// </summary>
  205. /// <param name="goods">The goods.</param>
  206. private void SelectGoodsChange(QuoteGoodsDTO goods)
  207. {
  208. var quoteGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.Symbol == goods.Symbol);
  209. CurrentGoods = quoteGoods;
  210. if (goods != null)
  211. {
  212. //todo:赋值MaxLot
  213. //MaxLot = goods.GoodsParameters.MaxOpenNumber;
  214. Lot = goods.Lot;
  215. }
  216. CanOpenMarket = true;
  217. }
  218. /// <summary>
  219. /// 内部卖逻辑
  220. /// </summary>
  221. private void QuickSell()
  222. {
  223. // OpenCloseMode = OpenCloseMode.BUILDTYPE_CLOSE;
  224. CanOpenMarket = false;
  225. string errorMsg = "";
  226. if (VailedFormData(out errorMsg, Direction.Ask))
  227. {
  228. string preViewMessage = Client_Resource.Warning_Order_confirm + Environment.NewLine + "\r\n";
  229. //if (_currentGoods.GoodsParameters.TradeMode != eTradeMode.TRADEMODE_MARKETMAKE)
  230. //{
  231. // preViewMessage = @"您确认要限价下单吗?" + Environment.NewLine + "\r\n";
  232. //}
  233. preViewMessage += Client_Resource.QuickOrderViewModel_Goods + _currentGoods.GoodsParameters.GoodsName + Environment.NewLine;
  234. preViewMessage += Client_Resource.QuickOrderViewModel_Direction + Client_Resource.Content_SellOut + Environment.NewLine;
  235. if (_currentGoods.TradeMode == eTradeMode.TRADEMODE_MARKETMAKE)
  236. {
  237. preViewMessage += Client_Resource.QuickOrderViewModel_Price + _currentGoods.AskPrice + Environment.NewLine;
  238. }
  239. //else
  240. //{
  241. // var currentPrice = decimal.Zero;
  242. // //竞价、混合=》默认限价下单【取值:最新价OR昨结算价】20160725-Idea from qiang
  243. // if (_currentGoods.CurrentPrice != decimal.Zero)
  244. // {
  245. // currentPrice = _currentGoods.CurrentPrice;
  246. // }
  247. // else
  248. // {
  249. // currentPrice = _currentGoods.LastSettlement;
  250. // }
  251. // preViewMessage += "价 格:" + currentPrice + Environment.NewLine;
  252. //}
  253. preViewMessage += Client_Resource.QuickOrderViewModel_Qty + Lot + Environment.NewLine;
  254. if (MessageBoxHelper.ShowQuestion(preViewMessage, Client_Resource.APP_Tips) == MessageBoxResult.Yes)
  255. //if (MessageBoxHelper.ShowQuestion(Client_Resource.Warning_Order_confirm, Client_Resource.APP_Tips) == MessageBoxResult.Yes)
  256. {
  257. try
  258. {
  259. InitTimer();
  260. PostOrder(Direction.Ask);
  261. CanOpenMarket = true;
  262. }
  263. finally
  264. {
  265. CanOpenMarket = true;
  266. DisposeTimer();
  267. }
  268. }
  269. else
  270. {
  271. CanOpenMarket = true;
  272. }
  273. }
  274. else
  275. {
  276. MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
  277. CanOpenMarket = true;
  278. }
  279. }
  280. /// <summary>
  281. /// 内部买逻辑
  282. /// </summary>
  283. private void QuickBuy()
  284. {
  285. CanOpenMarket = false;
  286. string errorMsg = "";
  287. if (VailedFormData(out errorMsg, Direction.Bid))
  288. {
  289. string preViewMessage = Client_Resource.WarningOpen + Environment.NewLine + "\r\n";
  290. //if (_currentGoods.GoodsParameters.TradeMode != eTradeMode.TRADEMODE_MARKETMAKE)
  291. //{
  292. // preViewMessage = @"您确认要限价{0}建仓吗?" + Environment.NewLine + "\r\n";
  293. //}
  294. preViewMessage += Client_Resource.QuickOrderViewModel_Goods + _currentGoods.GoodsParameters.GoodsName + Environment.NewLine;
  295. preViewMessage += Client_Resource.QuickOrderViewModel_Direction + Client_Resource.Content_Purchase + Environment.NewLine;
  296. if (_currentGoods.TradeMode == eTradeMode.TRADEMODE_MARKETMAKE)
  297. {
  298. preViewMessage += Client_Resource.QuickOrderViewModel_Price + _currentGoods.BidPrice + Environment.NewLine;
  299. }
  300. //else
  301. //{
  302. // var currentPrice = decimal.Zero;
  303. // //竞价、混合=》默认限价下单【取值:最新价OR昨结算价】20160725-Idea from qiang
  304. // if (_currentGoods.CurrentPrice!=decimal.Zero)
  305. // {
  306. // currentPrice = _currentGoods.CurrentPrice;
  307. // }
  308. // else
  309. // {
  310. // currentPrice = _currentGoods.LastSettlement;
  311. // }
  312. // preViewMessage += "价 格:" + currentPrice + Environment.NewLine;
  313. //}
  314. preViewMessage += Client_Resource.QuickOrderViewModel_Qty + Lot + Environment.NewLine;
  315. //if (MessageBoxHelper.ShowQuestion(string.Format(Client_Resource.WarningOpen, Client_Resource.Content_Purchase), Client_Resource.WarningOpenPrompt) == MessageBoxResult.Yes)
  316. if (MessageBoxHelper.ShowQuestion(string.Format(preViewMessage, Client_Resource.Content_Purchase), Client_Resource.WarningOpenPrompt) == MessageBoxResult.Yes)
  317. {
  318. try
  319. {
  320. InitTimer();
  321. PostOrder(Direction.Bid);
  322. }
  323. finally
  324. {
  325. CanOpenMarket = true;
  326. DisposeTimer();
  327. }
  328. }
  329. else
  330. {
  331. CanOpenMarket = true;
  332. }
  333. }
  334. else
  335. {
  336. MessageBoxHelper.ShowInfo(errorMsg, Client_Resource.MessageBox_Error_Title);
  337. CanOpenMarket = true;
  338. }
  339. }
  340. /// <summary>
  341. /// 验证表单数据是否正确
  342. /// </summary>
  343. /// <param name="errorMsg"></param>
  344. /// <returns></returns>
  345. private bool VailedFormData(out string errorMsg, Direction direction)
  346. {
  347. if (CurrentGoods == null ||string.IsNullOrWhiteSpace((_currentGoods.Name)))
  348. {
  349. errorMsg = Client_Resource.Select_Goods_Error; ;
  350. return false;
  351. }
  352. if ((CurrentGoods.ContainsGoodsSrc & (int)GoodsFromScr.Trade) != (int)GoodsFromScr.Trade) ////浏览的商品
  353. {
  354. errorMsg = string.Format(Client_Resource.Goods_WithOutTrade_Power, CurrentGoods.Name);
  355. return false;
  356. }
  357. #region MyRegion
  358. if (Lot % c_LotBit != 0)
  359. {
  360. errorMsg = Client_Resource.Trade_OnlyTwoDecimalPlaces;
  361. return false;
  362. }
  363. if (this._currentGoods != null)
  364. {
  365. var minLots = _igoodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId,
  366. _currentGoods.TradeMode, GoodsTradeConts.MINOPENTRADEQTY);
  367. var maxLots = _igoodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId,
  368. _currentGoods.TradeMode, GoodsTradeConts.MAXOPENTRADEQTY);
  369. if (_currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY && direction == Direction.Ask)
  370. {
  371. #region //全额商品区分买入卖出方向
  372. var holdingOrders = UserManager.GetCacheOrders<HoldingOrder>();
  373. if (holdingOrders == null || !holdingOrders.Any())
  374. {
  375. errorMsg = Client_Resource.Quick_OrderHasNoHolds;
  376. return false;
  377. }
  378. var holds = holdingOrders.Where((item) => item.GoodsId == CurrentGoods.GoodsParameters.GoodsId && item.Direction == Direction.Bid).ToList();
  379. if (holds == null || !holds.Any())
  380. {
  381. errorMsg = Client_Resource.Quick_OrderHasNoHolds;
  382. return false;
  383. }
  384. else
  385. {
  386. //最大数量=持仓汇总-冻结寸头
  387. var tempMaxLot = (int)(holds.Sum((item) => item.Lot-item.LockQty) - holds.FirstOrDefault().PositionFzQty);
  388. //全额商品-下单数量是否大于持仓数量
  389. if (Lot > tempMaxLot)
  390. {
  391. errorMsg =string.Format( Client_Resource.Lot_Close_DownOfMaxOpenLot,tempMaxLot);
  392. return false;
  393. }
  394. }
  395. #endregion
  396. }
  397. else
  398. {
  399. #region //非全额商品 买入卖出都只有建仓模式
  400. if (minLots != null && Lot < minLots.FeeValue)
  401. {
  402. errorMsg = string.Format(Client_Resource.Lot_Open_UpOfMinOpenLot,
  403. minLots.FeeValue);
  404. return false;
  405. }
  406. else if (maxLots != null && Lot > maxLots.FeeValue)
  407. {
  408. errorMsg = string.Format(Client_Resource.Lot_Open_DownOfMaxOpenLot,
  409. maxLots.FeeValue);
  410. return false;
  411. }
  412. #endregion
  413. }
  414. if (minLots != null && minLots.FeeValue != 0 && Lot % minLots.FeeValue != 0)
  415. {
  416. errorMsg = string.Format(Client_Resource.Trade_LotCountIncorrect, minLots.FeeValue);
  417. return false;
  418. }
  419. }
  420. else
  421. {
  422. errorMsg = Client_Resource.Select_Goods_Error;
  423. return false;
  424. }
  425. if (Lot <= 0)
  426. {
  427. errorMsg = Client_Resource.Lot_Vailed_MustUpOfZero;
  428. return false;
  429. }
  430. #endregion
  431. errorMsg = string.Empty;
  432. return true;
  433. }
  434. /// <summary>
  435. /// 发送下单消息
  436. /// </summary>
  437. /// <returns>返回下单错误码</returns>
  438. private void PostOrder(Direction direction)
  439. {
  440. var entrustOrder = new NewEntrustOrder()
  441. {
  442. GoodsId = (uint)this._currentGoods.GoodsParameters.GoodsId,
  443. AccountType = UserManager.CurrentTradeAccount.AccountType,
  444. BuyOrSell = direction,
  445. EntrustQuantity = Lot,
  446. OperaterId = UserManager.CurrentTradeAccount.AccountId,
  447. BuildType = OpenCloseMode.BUILDTYPE_OPEN,
  448. EntrurstTime = ApplicationParameter.ServerTimeNow,
  449. PriceMode = ePriceMode.PRICEMODE_MARKET,
  450. CurrentGoods = this.CurrentGoods,
  451. GoodsCode = this.CurrentGoods.GoodsCode,
  452. MemberAreaId = UserManager.CurrentTradeAccount.MemberAreaId,
  453. ValidType = ExpirationType.Today,
  454. MarketId = this.CurrentGoods.MarketID,
  455. TradeMode = CurrentGoods.TradeMode,
  456. LoginID = UserManager.CurrentTradeAccount.AccountId,
  457. AccountId = UserManager.CurrentTradeAccount.FundsAccountId,
  458. OrderFlag = (uint)OrderMethods.NormalOrder,
  459. OrderFormType = eOrderFormType.Commom,
  460. };
  461. var allowPips = _igoodsService.GetGoodsParamerRule((int)_currentGoods.GoodsId,
  462. _currentGoods.TradeMode, GoodsTradeConts.AllowPips);
  463. if (_currentGoods.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY && direction == Direction.Ask)
  464. {
  465. entrustOrder.BuildType = OpenCloseMode.BUILDTYPE_CLOSE;
  466. }
  467. //Edit by DK 20160725 //竞价、混合=》默认限价下单【取值:最新价OR昨结算价】-Idea from qiang
  468. //if (_currentGoods.GoodsParameters.TradeMode != eTradeMode.TRADEMODE_MARKETMAKE)
  469. //{
  470. // entrustOrder.PriceMode = ePriceMode.PRICEMODE_LIMIT;
  471. // if (_currentGoods.CurrentPrice != decimal.Zero)
  472. // {
  473. // entrustOrder.EntrustPrice = _currentGoods.CurrentPrice;
  474. // }
  475. // else
  476. // {
  477. // entrustOrder.EntrustPrice = _currentGoods.LastSettlement;
  478. // }
  479. //}
  480. //todo:默认点差
  481. entrustOrder.AllowTradeSub = allowPips == null ? 0 : allowPips.FeeValue;//ApplicationParameter.AllowTradeSub; //点差只能设置整数
  482. var orderService = SimpleIoc.Default.GetInstance<IOrderService>();
  483. //if (UserManager.CurrentTradeAccount.FundsAccounts.Any() &&
  484. // UserManager.CurrentTradeAccount.FundsAccounts[0] != null)
  485. //{
  486. // entrustOrder.AccountId = UserManager.CurrentTradeAccount.FundsAccounts[0].AccountId;
  487. //}
  488. //else
  489. //{
  490. // entrustOrder.AccountId = UserManager.CurrentTradeAccount.AccountId;
  491. //}
  492. if (_currentGoods.GoodsParameters == null)
  493. {
  494. MessageBoxHelper.ShowInfo(Client_Resource.APP_Tips, Client_Resource.QuickOrder_ParamersError);
  495. }
  496. else
  497. {
  498. switch (_currentGoods.TradeMode)
  499. {
  500. case eTradeMode.TRADEMODE_MARKETMAKE:
  501. entrustOrder.EntrustPrice = direction == Direction.Bid
  502. ? _currentGoods.BidPrice
  503. : _currentGoods.AskPrice;
  504. entrustOrder.OrderMode = OrderMode.InValid;
  505. entrustOrder.CurtQuotePrice = entrustOrder.EntrustPrice;
  506. orderService.MakeMarketEntrustOrder(entrustOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  507. break;
  508. case eTradeMode.TRADEMODE_BIDDING:
  509. entrustOrder.EntrustPrice = 0;
  510. entrustOrder.OrderMode = OrderMode.STD;
  511. entrustOrder.CurtQuotePrice = entrustOrder.EntrustPrice;
  512. // entrustOrder.TradeCloseMode = TradeCloseMode.IsVailed;
  513. orderService.BidMarketEntrustOrder(entrustOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  514. break;
  515. case eTradeMode.TRADEMODE_BIDDINGMARKETMAKE:
  516. entrustOrder.EntrustPrice = 0;
  517. entrustOrder.OrderMode = OrderMode.InValid;
  518. entrustOrder.CurtQuotePrice = entrustOrder.EntrustPrice;
  519. // entrustOrder.TradeCloseMode = TradeCloseMode.IsVailed;
  520. orderService.MixMarketEntrustOrder(entrustOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  521. break;
  522. case eTradeMode.TRADEMODE_ENTRUST_HEDGE:
  523. entrustOrder.CurtQuotePrice = direction == Direction.Ask ? _currentGoods.BidPrice : _currentGoods.AskPrice;
  524. entrustOrder.ChannelPriceMode = ChannelPriceMode.MarketPrice;
  525. orderService.ChannelEntrustOrder(entrustOrder, EntrurstSuccessCallBack, EntrurstErrorCallBack);
  526. break;
  527. default:
  528. var message = string.Format(Client_Resource.QuickOrder_TradeModeError, _currentGoods.TradeMode);
  529. MessageBoxHelper.ShowInfo(Client_Resource.APP_Tips, message);
  530. break;
  531. }
  532. }
  533. }
  534. /// <summary>
  535. /// 提交成功返回
  536. /// </summary>
  537. /// <param name="order"></param>
  538. private void EntrurstSuccessCallBack(OrderDetail order)
  539. {
  540. //更新相应的单据
  541. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.OrderNoticeToken);
  542. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  543. {
  544. MessageBoxHelper.ShowSuccess(Client_Resource.Order_Success_Result,
  545. Client_Resource.Open_MessageBox_Title);
  546. IsBusy = false;
  547. }));
  548. }
  549. /// <summary>
  550. /// 委托失败返回
  551. /// </summary>
  552. /// <param name="errorEntity"></param>
  553. private void EntrurstErrorCallBack(ErrorEntity errorEntity)
  554. {
  555. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  556. {
  557. ErrorManager.ShowReturnError(errorEntity, Client_Resource.UI2014_Tips, true);
  558. IsBusy = false;
  559. }));
  560. }
  561. #region 设置下单倒数定时器
  562. private string _busyTips;
  563. /// <summary>
  564. /// 服务忙提示
  565. /// </summary>
  566. public string BusyTips
  567. {
  568. get
  569. {
  570. return _busyTips;
  571. }
  572. set
  573. {
  574. Set(() => BusyTips, ref _busyTips, value);
  575. }
  576. }
  577. private Timer _timer; //下单计时
  578. private int _countTime; //倒计时时间
  579. private bool _isOrderVisible = false;
  580. /// <summary>
  581. /// 是否显示快速下单
  582. /// </summary>
  583. public bool IsOrderVisible
  584. {
  585. get { return _isOrderVisible; }
  586. set { Set(() => IsOrderVisible, ref _isOrderVisible, value); }
  587. }
  588. /// <summary>
  589. /// 初始化下单计时时间
  590. /// </summary>
  591. private void InitTimer()
  592. {
  593. _countTime = ApplicationParameter.ServerTimeOut;
  594. this._timer = new Timer(1000);
  595. this._timer.AutoReset = true;
  596. this._timer.Elapsed += _timer_Elapsed;
  597. this._timer.Start();
  598. IsOrderVisible = true;
  599. BusyTips = string.Format(Client_Resource.Busy_Summit_Wait, _countTime);
  600. }
  601. /// <summary>
  602. ///
  603. /// </summary>
  604. /// <param name="sender"></param>
  605. /// <param name="e"></param>
  606. void _timer_Elapsed(object sender, ElapsedEventArgs e)
  607. {
  608. _countTime--;
  609. BusyTips = string.Format(Client_Resource.Busy_Summit_Wait, _countTime);
  610. }
  611. /// <summary>
  612. /// 清除计时器
  613. /// </summary>
  614. private void DisposeTimer()
  615. {
  616. this._timer.Stop();
  617. this._timer.Elapsed -= _timer_Elapsed;
  618. this._timer.Close();
  619. IsOrderVisible = false;
  620. }
  621. #endregion
  622. }
  623. }