TradeHeaderViewModel.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using GalaSoft.MvvmLight.Ioc;
  4. using GalaSoft.MvvmLight.Messaging;
  5. using GalaSoft.MvvmLight.Threading;
  6. using Muchinfo.MTPClient.Account.ViewModels.OrderViewModel;
  7. using Muchinfo.MTPClient.Account.Views;
  8. using Muchinfo.MTPClient.Data;
  9. using Muchinfo.MTPClient.Data.Enums;
  10. using Muchinfo.MTPClient.Data.Model;
  11. using Muchinfo.MTPClient.Data.Model.Account;
  12. using Muchinfo.MTPClient.Infrastructure.Cache;
  13. using Muchinfo.MTPClient.Infrastructure.Helpers;
  14. using Muchinfo.MTPClient.Infrastructure.Utilities;
  15. using Muchinfo.MTPClient.IService;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Windows;
  19. using System.Linq;
  20. namespace Muchinfo.MTPClient.Account.ViewModels
  21. {
  22. public class TradeHeaderViewModel : ViewModelBase
  23. {
  24. #region 字段
  25. private IOrderService _orderService;
  26. private TradeAccount _currentTradeAccount;
  27. //private ILoginService _loginService;
  28. //private IGoodsService _goodsService;
  29. /// <summary>
  30. /// 当前MenuCommandType
  31. /// </summary>
  32. public MenuCommandType _currentMenuType;
  33. public MenuCommandType CurrentMenuType
  34. {
  35. get { return _currentMenuType; }
  36. set
  37. {
  38. Set(() => CurrentMenuType, ref _currentMenuType, value);
  39. }
  40. }
  41. private bool _isMemberTrade;
  42. /// <summary>
  43. /// 是否是要监控会员 交易员
  44. /// </summary>
  45. public bool IsMemberTrade
  46. {
  47. get { return _isMemberTrade; }
  48. set { Set(() => IsMemberTrade, ref _isMemberTrade, value); }
  49. }
  50. #endregion
  51. #region 属性
  52. /// <summary>
  53. /// 账号列表中的字符串表示
  54. /// </summary>
  55. public List<TradeAccount> AccountsList
  56. {
  57. get
  58. {
  59. var listAccount = new List<TradeAccount>();
  60. if (UserManager.TradeAccounts != null)
  61. {
  62. foreach (var tradeAccount in UserManager.TradeAccounts)
  63. {
  64. listAccount.Add(tradeAccount);
  65. }
  66. }
  67. return listAccount;
  68. }
  69. }
  70. /// <summary>
  71. /// 买入命令
  72. /// </summary>
  73. public RelayCommand BuyCommand
  74. {
  75. get
  76. {
  77. return new RelayCommand(() =>
  78. {
  79. CacheManager.FromType = eOrderFormType.Commom; //顶部买卖按钮与挂牌无关
  80. var order = new OrderMessage() { Direction = Direction.Bid, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
  81. MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken);
  82. },() => CanCommandEnable(MenuCommandType.BuyIn));
  83. }
  84. }
  85. #region 工具栏
  86. /// <summary>
  87. /// 返回
  88. /// </summary>
  89. public RelayCommand BackCommand
  90. {
  91. get
  92. {
  93. return new RelayCommand(() =>
  94. {
  95. // MessengerHelper.DefaultSend(Direction.Bid, MessengerTokens.OpenOrderCmdMessage);
  96. MessengerHelper.DefaultSend(TabContetMode.QuoteList, MessengerTokens.MainContentChange);
  97. } );
  98. }
  99. }
  100. private bool _isShowListing;
  101. /// <summary>
  102. /// 是否显示挂牌
  103. /// </summary>
  104. public bool IsShowListing
  105. {
  106. get
  107. {
  108. return _isShowListing;
  109. }
  110. set
  111. {
  112. Set(() => IsShowListing, ref _isShowListing, value);
  113. }
  114. }
  115. public RelayCommand ListingCommand
  116. {
  117. get
  118. {
  119. return new RelayCommand(() =>
  120. {
  121. MessengerHelper.DefaultSend(Direction.Ask, MessengerTokens.OrderListingToken);
  122. });
  123. }
  124. }
  125. public bool IsBidAskVbs
  126. {
  127. get
  128. {
  129. return !IsShowListing && UserManager.GetCurrentLayoutStyle() != LayoutStyle.Tradition;// 传统模式,就不需要显示了
  130. }
  131. }
  132. /// <summary>
  133. /// 交易设置
  134. /// </summary>
  135. public RelayCommand TradeSetCommand
  136. {
  137. get
  138. {
  139. return new RelayCommand(() =>
  140. {
  141. // MessengerHelper.DefaultSend(Direction.Bid, MessengerTokens.OpenOrderCmdMessage);
  142. var tradeSet = new TradeParamSetView()
  143. {
  144. Owner = System.Windows.Application.Current.MainWindow,
  145. WindowStartupLocation = WindowStartupLocation.CenterOwner
  146. };
  147. tradeSet.ShowDialog();
  148. });
  149. }
  150. }
  151. /// <summary>
  152. /// 是否为已使用交易账号登录
  153. /// </summary>
  154. public bool IsAccountLogin
  155. {
  156. get { return UserManager.IsAccountLogin; }
  157. }
  158. private bool _isTradeVisible = false;
  159. /// <summary>
  160. /// 是否显示交易数据
  161. /// </summary>
  162. public bool IsTradeVisible
  163. {
  164. get { return _isTradeVisible; }
  165. set
  166. {
  167. Set(() => IsTradeVisible, ref _isTradeVisible, value);
  168. MessengerHelper.DefaultSend(value, MessengerTokens.SetHideExpandTradeToken);
  169. }
  170. }
  171. /// <summary>
  172. /// 刷新当前命令
  173. /// </summary>
  174. public RelayCommand RefreshCommand
  175. {
  176. get
  177. {
  178. return new RelayCommand(() =>
  179. {
  180. MessengerHelper.DefaultSend(string.Empty, MessengerTokens.OrderRefresh);
  181. }, () =>
  182. {
  183. //todo:临时处理交易对象不一致问题
  184. if (CurrentTradeAccount != UserManager.CurrentTradeAccount)
  185. {
  186. CurrentTradeAccount = UserManager.CurrentTradeAccount;
  187. }
  188. IsMemberTrade = UserManager.IsMonitorMember();
  189. //RaisePropertyChanged(() => IsHiddenWithoutFullPay);
  190. //RaisePropertyChanged(() => IsHiddenWithoutMagin);
  191. return true;
  192. });
  193. }
  194. }
  195. #endregion
  196. /// <summary>
  197. /// 买出命令
  198. /// </summary>
  199. public RelayCommand SellCommand
  200. {
  201. get
  202. {
  203. return new RelayCommand(() =>
  204. {
  205. CacheManager.FromType = eOrderFormType.Commom;//顶部买卖按钮与挂牌无关
  206. var order = new OrderMessage() { Direction = Direction.Ask, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
  207. MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken);
  208. }, () => CanCommandEnable(MenuCommandType.Sellout));
  209. }
  210. }
  211. public RelayCommand CancelCommand
  212. {
  213. get
  214. {
  215. return new RelayCommand(() =>
  216. {
  217. // MessengerHelper.DefaultSend(TradeTreeMenu.CancelOrder, MessengerTokens.CancalOrder);
  218. var orderDetail = SimpleIoc.Default.GetInstance<MOrderDetailViewModel>();
  219. orderDetail.CancelHoldingCammand.Execute(null);
  220. } );
  221. }
  222. }
  223. /// <summary>
  224. /// 持仓单
  225. /// </summary>
  226. public RelayCommand HoldCommand
  227. {
  228. get
  229. {
  230. return new RelayCommand(() =>
  231. {
  232. MessengerHelper.DefaultSend(MenuCommandType.Position, MessengerTokens.MenuSelectChange);
  233. });
  234. }
  235. }
  236. /// <summary>
  237. /// 命令类型
  238. /// </summary>
  239. /// <param name="commandType"></param>
  240. /// <returns></returns>
  241. public bool CanCommandEnable(MenuCommandType commandType)
  242. {
  243. if (UserManager.TradeFuncMenus != null && UserManager.TradeFuncMenus.Any())
  244. {
  245. var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == commandType.ToString());
  246. if (tradeFunc != null)
  247. {
  248. return tradeFunc.IsEnabled;
  249. }
  250. }
  251. return false;
  252. }
  253. /// <summary>
  254. /// 当前选择的账号
  255. /// </summary>
  256. public TradeAccount CurrentTradeAccount
  257. {
  258. get { return _currentTradeAccount; }
  259. set
  260. {
  261. var flag = _currentTradeAccount == null || value == null || _currentTradeAccount.Equals(value);
  262. _currentTradeAccount = value;
  263. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  264. {
  265. RaisePropertyChanged(() => CurrentTradeAccount);
  266. if (flag) return;
  267. UserManager.CurrentTradeAccount = value;
  268. }));
  269. }
  270. }
  271. private List<QuoteGoods> _quoteGoodses;
  272. /// <summary>
  273. /// 持仓汇总商品
  274. /// </summary>
  275. public List<QuoteGoods> QuoteGoodses
  276. {
  277. get { return _quoteGoodses; }
  278. set { Set(() => QuoteGoodses, ref _quoteGoodses, value); }
  279. }
  280. private bool _isCancelEnable;
  281. /// <summary>
  282. /// 撤单是否可用
  283. /// </summary>
  284. public bool IsCancelEnable
  285. {
  286. get { return _isCancelEnable; }
  287. set
  288. {
  289. Set(() => IsCancelEnable, ref _isCancelEnable, value);
  290. }
  291. }
  292. #region 是否隐藏风险率
  293. private bool isNeedChecked;
  294. private bool _isHiddenWithoutFullPay;
  295. private bool isNeedCheckedGuest;
  296. /// <summary>
  297. /// 所有市场没有保证金模式的商品,则不显示:1) 账号信息行的“风险率” 2)资金信息的“风险率”列
  298. /// </summary>
  299. public bool IsHiddenWithoutFullPay
  300. {
  301. get
  302. {
  303. //if (isNeedChecked)
  304. //{
  305. // return _isHiddenWithoutFullPay;
  306. //}
  307. //if (isNeedCheckedGuest)
  308. //{
  309. // return _isHiddenWithoutFullPay;
  310. //}
  311. if (CacheManager.CacheGoodsBaseInfos == null || !CacheManager.CacheGoodsBaseInfos.Any())
  312. {
  313. return false;
  314. }
  315. _isHiddenWithoutFullPay = CacheManager.CacheGoodsBaseInfos.Any((item) => item.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN);
  316. //isNeedChecked = true;
  317. if (UserManager.IsAccountLogin)
  318. {
  319. isNeedChecked = true;
  320. isNeedCheckedGuest = false;
  321. }
  322. else
  323. {
  324. isNeedChecked = false;
  325. isNeedCheckedGuest = true;
  326. }
  327. return _isHiddenWithoutFullPay;
  328. }
  329. }
  330. private bool isNeedCheckedMagin;
  331. private bool _isHiddenWithoutMagin;
  332. private bool isNeedCheckedMaginGuest;
  333. /// <summary>
  334. /// 所有市场没有全额的商品,则不显示
  335. /// </summary>
  336. public bool IsHiddenWithoutMagin
  337. {
  338. get
  339. {
  340. //if (isNeedCheckedMagin)
  341. //{
  342. // return _isHiddenWithoutMagin;
  343. //}
  344. //if (isNeedCheckedMaginGuest)
  345. //{
  346. // return _isHiddenWithoutMagin;
  347. //}
  348. if (CacheManager.CacheGoodsBaseInfos == null || !CacheManager.CacheGoodsBaseInfos.Any())
  349. {
  350. return false;
  351. }
  352. _isHiddenWithoutMagin = CacheManager.CacheGoodsBaseInfos.Any((item) => item.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_PAY);
  353. //isNeedCheckedMagin = true;
  354. if (UserManager.IsAccountLogin)
  355. {
  356. isNeedCheckedMagin = true;
  357. isNeedCheckedMaginGuest = false;
  358. }
  359. else
  360. {
  361. isNeedCheckedMagin = false;
  362. isNeedCheckedMaginGuest = true;
  363. }
  364. return _isHiddenWithoutMagin;
  365. }
  366. }
  367. #endregion
  368. #endregion
  369. #region 构造函数
  370. public TradeHeaderViewModel()
  371. {
  372. _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
  373. _currentTradeAccount = UserManager.CurrentTradeAccount;
  374. #region 是否隐藏风险率逻辑
  375. //所有市场=》没有保证金模式的商品
  376. // IsHiddenWithoutFullPay = CacheManager.CacheGoodsBaseInfos.Any((item) => item.GoodsParameters.MoneyMode == eMoneyMode.MONEYMODE_MARGIN);
  377. #endregion
  378. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.CancelOrderEnable, (isEnable) =>
  379. IsCancelEnable = isEnable
  380. );
  381. MessengerHelper.DefaultRegister<TradeAccount>(this, MessengerTokens.UpdateTradeAccount, (account) =>
  382. {
  383. ///账号信息对象改变时更新当前对象与缓存的一致
  384. if (_currentTradeAccount!=null&&_currentTradeAccount != UserManager.CurrentTradeAccount)
  385. {
  386. UserManager.CurrentTradeAccount.MemberAccountInfo = _currentTradeAccount.MemberAccountInfo;
  387. }
  388. CurrentTradeAccount = UserManager.CurrentTradeAccount;
  389. IsMemberTrade = UserManager.IsMonitorMember();
  390. });
  391. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.MemberRolesToken, (val) =>
  392. {
  393. IsMemberTrade = val;
  394. });
  395. //锁屏控制是否显示交易数据
  396. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.LockScreenSetHideExpandTradeToken, (val) =>
  397. {
  398. IsTradeVisible = val;
  399. });
  400. // MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.ShowChartMsg, (isShow) => IsShowCycles = isShow); ////显示图表
  401. }
  402. #endregion
  403. #region Method
  404. #endregion
  405. }
  406. }