HomeViewModel.cs 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using GalaSoft.MvvmLight.Ioc;
  4. using Muchinfo.MTPClient.Account.ViewModels;
  5. using Muchinfo.MTPClient.Account.ViewModels.AllOrderViewModel;
  6. using Muchinfo.MTPClient.Account.Views;
  7. using Muchinfo.MTPClient.CustomException;
  8. using Muchinfo.MTPClient.Data;
  9. using Muchinfo.MTPClient.Data.DTO;
  10. using Muchinfo.MTPClient.Data.Enums;
  11. using Muchinfo.MTPClient.Data.Model;
  12. using Muchinfo.MTPClient.Data.Model.Account;
  13. using Muchinfo.MTPClient.Data.Model.GoodRules;
  14. using Muchinfo.MTPClient.Data.Model.Message;
  15. using Muchinfo.MTPClient.Infrastructure.Cache;
  16. using Muchinfo.MTPClient.Infrastructure.Helpers;
  17. using Muchinfo.MTPClient.Infrastructure.LinkProxy;
  18. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  19. using Muchinfo.MTPClient.Infrastructure.Users;
  20. using Muchinfo.MTPClient.Infrastructure.Utilities;
  21. using Muchinfo.MTPClient.Infrastructure.Windows;
  22. using Muchinfo.MTPClient.IService;
  23. using Muchinfo.MTPClient.Resources;
  24. using Muchinfo.MTPClient.Service.Utilities;
  25. using Muchinfo.MTPClient.Trade.ViewModels;
  26. using Muchinfo.MTPClient.Trade.Views.ERMCP;
  27. using Muchinfo.MTPClient.UI.Utilities;
  28. using Muchinfo.MTPClient.UI.Views;
  29. using Muchinfo.PC.Common.Extensions;
  30. using System;
  31. using System.Collections;
  32. using System.Collections.Generic;
  33. using System.Collections.ObjectModel;
  34. using System.Diagnostics;
  35. using System.Linq;
  36. using System.Threading;
  37. using System.Threading.Tasks;
  38. using System.Windows;
  39. using System.Windows.Input;
  40. using System.Windows.Threading;
  41. namespace Muchinfo.MTPClient.UI.ViewModels
  42. {
  43. /// <summary>
  44. /// HomePageViewModel类
  45. /// </summary>
  46. public class HomeViewModel : ViewModelBase
  47. {
  48. #region Fields
  49. private bool _isClosePower;//是否有平仓权限
  50. private ObservableCollection<SysMenuItem> _mainMenuItems;
  51. private Visibility _statusBarVisibility;
  52. private Visibility _toolBarVisibility;
  53. private IAnnouncementService _announcementService;
  54. private ILoginService _loginService;
  55. private int _oldTabIndex;
  56. private ISystemService _systemService;
  57. private IDeliveryService _deliveryService;//交割服务-》查询交割关系列表
  58. private Dictionary<ResxVerType, ResxVerInfo> _resxVerInfos; ////服务端资源版本
  59. private IOrderService _orderService;
  60. private ICommonQueryService _commonQueryService;
  61. #endregion Fields
  62. #region Constructors
  63. /// <summary>
  64. /// Initializes a new instance of the <see cref="HomeViewModel" /> class.
  65. /// </summary>
  66. /// <param name="service">系统服务</param>
  67. public HomeViewModel(ISystemService service)
  68. {
  69. //初始化命令
  70. InitializeCommands();
  71. _toolBarVisibility = Visibility.Visible;
  72. _statusBarVisibility = Visibility.Visible;
  73. _announcementService = SimpleIoc.Default.GetInstance<IAnnouncementService>();
  74. _loginService = SimpleIoc.Default.GetInstance<ILoginService>();
  75. SystemName = ApplicationParameter.TradeSystemName;
  76. _deliveryService = SimpleIoc.Default.GetInstance<IDeliveryService>();
  77. _systemService = service;
  78. _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
  79. _commonQueryService = SimpleIoc.Default.GetInstance<ICommonQueryService>();
  80. ApplicationParameter.MakePublishNetIp();
  81. //消息注册
  82. RegisterMessenger();
  83. if (UserManager.IsAccountLogin) ////已交易登录
  84. {
  85. TradeDataInit();
  86. }
  87. else
  88. { ////游客没有交易菜单
  89. CreateLoaclMenu(new List<SysMenuItem>());
  90. }
  91. }
  92. #endregion Constructors
  93. #region Properties
  94. #region Public Properties
  95. private RelayCommand _ftenCommand;
  96. /// <summary>
  97. /// Gets the FtenCommand.
  98. /// </summary>
  99. public RelayCommand FtenCommand
  100. {
  101. get
  102. {
  103. return _ftenCommand
  104. ?? (_ftenCommand = new RelayCommand(
  105. () =>
  106. {
  107. var FtenAddress = ApplicationParameter.FtenAddress;
  108. if (!string.IsNullOrEmpty(FtenAddress))
  109. {
  110. MessengerHelper.DefaultSend<TabContetMode>(TabContetMode.QuoteGoodsInfo, MessengerTokens.ChangeGoodsInfo);
  111. }
  112. }));
  113. }
  114. }
  115. /// <summary>
  116. /// 当前使用的样式
  117. /// </summary>
  118. public Object CurrentStyle
  119. {
  120. get;
  121. set;
  122. }
  123. public string TradeTypeDisplay
  124. {
  125. get
  126. {
  127. return string.Empty;
  128. //var isConfigVersion = ConfigurationManager.AppSettings["IsMockTrade"];
  129. //return isConfigVersion == "0" ? " - 模拟盘" : " - 实盘";
  130. }
  131. }
  132. /// <summary>
  133. /// 系统名称
  134. /// </summary>
  135. public string SystemName { get; set; }
  136. /// <summary>
  137. /// 获取和设置the main menu items
  138. /// </summary>
  139. public ObservableCollection<SysMenuItem> MainMenuItems
  140. {
  141. get
  142. {
  143. return _mainMenuItems;
  144. }
  145. set
  146. {
  147. Set(() => MainMenuItems, ref _mainMenuItems, value);
  148. }
  149. }
  150. /// <summary>
  151. /// 获取和设置the menu command
  152. /// </summary>
  153. public RelayCommand<SysMenuItem> MenuCommand
  154. {
  155. get;
  156. private set;
  157. }
  158. /// <summary>
  159. /// Gets or sets the name of the user.
  160. /// </summary>
  161. public Visibility StatusbarVisibility
  162. {
  163. get { return _statusBarVisibility; }
  164. set
  165. {
  166. Set(() => StatusbarVisibility, ref _statusBarVisibility, value);
  167. }
  168. }
  169. /// <summary>
  170. /// Gets or sets the name of the user.
  171. /// </summary>
  172. public Visibility ToolbarVisibility
  173. {
  174. get { return _toolBarVisibility; }
  175. set
  176. {
  177. Set(() => ToolbarVisibility, ref _toolBarVisibility, value);
  178. }
  179. }
  180. /// <summary>
  181. /// 主窗体是否隐藏
  182. /// </summary>
  183. private Visibility _mainPanelVisibility = Visibility.Collapsed;
  184. public Visibility MainPanelVisibility
  185. {
  186. get { return _mainPanelVisibility; }
  187. set
  188. {
  189. Set(() => MainPanelVisibility, ref _mainPanelVisibility, value);
  190. }
  191. }
  192. #region 快速下单
  193. public RelayCommand<int> OrderTransactionCommand
  194. {
  195. get
  196. {
  197. return new RelayCommand<int>((commandParameter) => Task.Factory.TryStartNew(() =>
  198. {
  199. }));
  200. }
  201. }
  202. #endregion
  203. /// <summary>
  204. /// 是否为已使用交易账号登录
  205. /// </summary>
  206. public bool IsAccountLogin
  207. {
  208. get { return UserManager.IsAccountLogin; }
  209. }
  210. /// <summary>
  211. /// 是否顯示功能樹
  212. /// </summary>
  213. public bool IsTreeVbs
  214. {
  215. get { return UserManager.IsAccountLogin && IsTradeVisible; }
  216. }
  217. private bool _isBusy;
  218. /// <summary>
  219. /// 是否忙
  220. /// </summary>
  221. public bool IsBusy
  222. {
  223. get { return _isBusy; }
  224. set { Set(() => IsBusy, ref _isBusy, value); }
  225. }
  226. #endregion Public Properties
  227. private bool _isTradeVisible = true;
  228. /// <summary>
  229. /// 是否显示交易数据
  230. /// </summary>
  231. public bool IsTradeVisible
  232. {
  233. get { return _isTradeVisible; }
  234. set
  235. {
  236. Set(() => IsTradeVisible, ref _isTradeVisible, value);
  237. var defaultLayout = UserManager.GetCurrentLayoutStyle();
  238. MainLayoutUpdate(defaultLayout);
  239. }
  240. }
  241. /// <summary>
  242. /// 是否保存布局
  243. /// </summary>
  244. public bool IsSaveLayout
  245. {
  246. get;
  247. set;
  248. }
  249. /// <summary>
  250. /// 是否显示期货组件
  251. /// </summary>
  252. private Visibility _quoteVisibility = Visibility.Hidden;
  253. public Visibility QuoteVisibility
  254. {
  255. get { return _quoteVisibility; }
  256. set
  257. {
  258. Set(() => QuoteVisibility, ref _quoteVisibility, value);
  259. }
  260. }
  261. /// <summary>
  262. /// 是否显示WEB浏览器组件
  263. /// </summary>
  264. private Visibility _webBrowerVisibility = Visibility.Visible;
  265. public Visibility WebBrowerVisibility
  266. {
  267. get { return _webBrowerVisibility; }
  268. set
  269. {
  270. Set(() => WebBrowerVisibility, ref _webBrowerVisibility, value);
  271. }
  272. }
  273. #endregion Properties
  274. #region Methods
  275. #region Private Methods
  276. /// <summary>
  277. /// 构建本地菜单
  278. /// </summary>
  279. /// <param name="accessItems">交易菜单</param>
  280. private void CreateLoaclMenu(List<SysMenuItem> accessItems)
  281. {
  282. _systemService = SimpleIoc.Default.GetInstance<ISystemService>();
  283. _orderService = SimpleIoc.Default.GetInstance<IOrderService>();
  284. MainMenuItems = _systemService.GetSysMenuItems(accessItems, MenuCommand);
  285. var toolMenu = _mainMenuItems.FirstOrDefault(z => z.Title == MenuNames.Tools);
  286. if (toolMenu == null || toolMenu.Children == null || !toolMenu.Children.Any()) return;
  287. var toolBarItem = toolMenu.Children.FirstOrDefault(z => z.SysCommandType == MenuCommandType.Toolbar);
  288. if (toolBarItem != null) ToolbarVisibility = toolBarItem.IsChecked ? Visibility.Visible : Visibility.Collapsed;
  289. var statusBarItem = toolMenu.Children.FirstOrDefault(z => z.SysCommandType == MenuCommandType.Statusbar);
  290. if (statusBarItem != null) StatusbarVisibility = statusBarItem.IsChecked ? Visibility.Visible : Visibility.Collapsed;
  291. }
  292. /// <summary>
  293. /// 消息注册
  294. /// </summary>
  295. private void RegisterMessenger()
  296. {
  297. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.MainPanelIsUnlock, MainPanelIsEnableMethod);
  298. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.InitLockTimer, InitLockTimer);
  299. MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.SelectGoodsChange, SelectGoodsChange);
  300. MessengerHelper.DefaultRegister<QuoteGoodsForSelectOrder>(this, MessengerTokens.SelectGoodsOrderChange, SelectGoods);
  301. MessengerHelper.DefaultRegister<QuoteGoodsDTO>(this, MessengerTokens.SelectCommissionGoodsChange, SelectCommissionGoodsChange);
  302. //注册快捷下单消息
  303. MessengerHelper.DefaultRegister<FrameworkElement>(this, MessengerTokens.ShowQueryContet, (view) =>
  304. {
  305. QueryView = view;
  306. });
  307. MessengerHelper.DefaultRegister<string>(this, MessengerTokens.OrderRefresh, OrderViewRefresh);
  308. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.SetHideExpandTradeToken, SetHideTradeMsg);
  309. MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.CancelOrderEnable, (isEnable) =>
  310. {
  311. //var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == UserManager.GetMenuCommandValue(MenuCommandType.Cancel));
  312. var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == MenuCommandType.Cancel.ToString());
  313. if (tradeFunc != null)
  314. {
  315. tradeFunc.IsEnabled = isEnable;
  316. }
  317. });
  318. MessengerHelper.DefaultRegister<TradeOrderViewModel>(this, MessengerTokens.OrderMessage, SetOrderView);
  319. }
  320. /// <summary>
  321. /// 选择某个商品
  322. /// </summary>
  323. /// <param name="goods"></param>
  324. private void SelectGoods(QuoteGoodsForSelectOrder goods)
  325. {
  326. if (goods == null)
  327. {
  328. return;
  329. }
  330. if (goods.IsSelect)
  331. {
  332. if (ApplicationParameter._LockType == LockType.Lock &&
  333. UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
  334. {
  335. return;
  336. }
  337. }
  338. SelectedQuoteGoods = goods.QuoteGoods;
  339. if (IsAccountLogin && (SelectedQuoteGoods.ContainsGoodsSrc & (int)GoodsFromScr.Trade) > 0) //交易商品可下单
  340. {
  341. ////处理点击会卡的问题
  342. Task.Factory.TryStartNew(() =>
  343. {
  344. var viewModel = new TradeOrderViewModel(SelectedQuoteGoods, Direction.Bid);
  345. SetOrderView(viewModel);
  346. });
  347. }
  348. }
  349. /// <summary>
  350. /// 选择商品改变
  351. /// </summary>
  352. /// <param name="goods">The goods.</param>
  353. private void SelectGoodsChange(QuoteGoodsDTO goods)
  354. {
  355. var quoteGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.Symbol == goods.Symbol);
  356. // bool showChart;
  357. if (quoteGoods != null)
  358. {
  359. //todo:
  360. //if (goods.GoodsParameters.TradeMode == TradeModeType.BidGoods)
  361. //{
  362. // showChart = ApplicationParameter.ShowChart == 2; //设置竞价商品才显示图表
  363. //}
  364. QuoteGoodsForSelectOrder orderGoods = new QuoteGoodsForSelectOrder
  365. {
  366. IsSelect = true,
  367. QuoteGoods = quoteGoods
  368. };
  369. SelectGoods(orderGoods);
  370. }
  371. //IsShowChart = ApplicationParameter.ShowChart == 1 || showChart;
  372. }
  373. /// <summary>
  374. /// 选择五档买卖商品改变
  375. /// </summary>
  376. /// <param name="goods">The goods.</param>
  377. private void SelectCommissionGoodsChange(QuoteGoodsDTO goods)
  378. {
  379. var quoteGoods = CacheManager.CacheGoodsBaseInfos.FirstOrDefault((item) => item.Symbol == goods.Symbol);
  380. if (quoteGoods != null)
  381. {
  382. SelectedCommissionQuoteGoods = quoteGoods;
  383. }
  384. }
  385. /// <summary>
  386. /// 设置是否展开交易信息
  387. /// </summary>
  388. /// <param name="result"></param>
  389. private void SetHideTradeMsg(bool result)
  390. {
  391. IsTradeVisible = result;
  392. }
  393. private FrameworkElement _queryView;
  394. /// <summary>
  395. /// 查询面板显示的内容
  396. /// </summary>
  397. public FrameworkElement QueryView
  398. {
  399. get { return _queryView; }
  400. set
  401. {
  402. if (_queryView != null && value.Equals(_queryView))
  403. {
  404. return;
  405. }
  406. else
  407. {
  408. if (_queryView != null)
  409. {
  410. var queryPanel = _queryView.DataContext as QueryPanelModelBase;
  411. if (queryPanel != null)
  412. {
  413. queryPanel.UnRegisterMessage();
  414. }
  415. }
  416. }
  417. Set(() => QueryView, ref _queryView, value);
  418. var newQueryPanel = value.DataContext as QueryPanelModelBase;
  419. if (newQueryPanel != null)
  420. {
  421. newQueryPanel.RegisterMessage();
  422. }
  423. }
  424. }
  425. private FrameworkElement _mainContent;
  426. /// <summary>
  427. /// 布局内容显示
  428. /// </summary>
  429. public FrameworkElement MainContent
  430. {
  431. get { return _mainContent; }
  432. set { Set(() => MainContent, ref _mainContent, value); }
  433. }
  434. /// <summary>
  435. /// 选择的商品
  436. /// </summary>
  437. public QuoteGoods SelectedQuoteGoods { get; set; }
  438. /// <summary>
  439. /// 选择的商品
  440. /// </summary>
  441. public QuoteGoods SelectedCommissionQuoteGoods { get; set; }
  442. /// <summary>
  443. /// 更新单据窗口的内容
  444. /// </summary>
  445. /// <param name="update"></param>
  446. private void OrderViewRefresh(string update)
  447. {
  448. //下方查询界面显示方式修改后此方法无效,要刷新单据须在各自界面注册消息OrderViewRefresh去实现 --dyp
  449. if (QueryView != null && QueryView.DataContext is IOrderRefresh)
  450. {
  451. (QueryView.DataContext as IOrderRefresh).Refresh();
  452. }
  453. ///刷新后-重新查询交割关系列表--pending by dk
  454. // _deliveryService.QueryRelationPAndXGoodsInfoList(QueryAllDeliveryRelationSuccess, null);
  455. }
  456. /// <summary>
  457. /// <summary>
  458. /// 设置撤单是否可用
  459. /// </summary>
  460. /// <param name="isEnable"></param>
  461. private void SetCancelItemEable(bool isEnable)
  462. {
  463. var menuItem = _mainMenuItems.FirstOrDefault((item) => item.Title == MenuNames.Trading);
  464. if (menuItem == null) return;
  465. var canelItem = menuItem.Children.FirstOrDefault((cItem) => cItem.Title == MenuNames.OrderCancel);
  466. if (canelItem == null) return;
  467. //var accountManager = SimpleIoc.Default.GetInstance<AccountManagerViewModel>();
  468. }
  469. /// <summary>
  470. /// Executes the command.
  471. /// </summary>
  472. /// <param name="item">The item.</param>
  473. private void ExecuteCommand(SysMenuItem item)
  474. {
  475. CacheManager.FromType = eOrderFormType.Commom; //顶部买卖按钮与挂牌无关
  476. var goods = this.SelectedQuoteGoods;
  477. switch (item.SysCommandType)
  478. {
  479. #region 系统
  480. case MenuCommandType.Reconnect:
  481. if (MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.UI2014_IsOrNotReconnect,
  482. Muchinfo.MTPClient.Resources.Client_Resource.UI2014_Tips) == MessageBoxResult.Yes)
  483. {
  484. if (UserManager.IsAccountLogin)
  485. {
  486. ////保存布局及列表行情抬头
  487. MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
  488. //手动发送登出消息
  489. var service = SimpleIoc.Default.GetInstance<ILoginService>();
  490. if (service != null) service.TradeAccountLogout(UserManager.CurrentTradeAccount);
  491. }
  492. WindowHelper.RerunApplication();
  493. }
  494. break;
  495. case MenuCommandType.ChangeTradePassword:
  496. //非强制修改密码
  497. MessengerHelper.DefaultSend(true, MessengerTokens.ShowModifyPwd);
  498. break;
  499. case MenuCommandType.Horizontal:
  500. SetInitializeCheck(item);
  501. MainLayoutUpdate(LayoutStyle.Horizontal);
  502. break;
  503. case MenuCommandType.Vertical:
  504. SetInitializeCheck(item);
  505. MainLayoutUpdate(LayoutStyle.Vertical);
  506. break;
  507. case MenuCommandType.Tradition:
  508. SetInitializeCheck(item);
  509. MainLayoutUpdate(LayoutStyle.Tradition);
  510. break;
  511. case MenuCommandType.Logout:
  512. OnClose();
  513. break;
  514. case MenuCommandType.CoolBlack:
  515. SetInitializeCheck(item);
  516. ThemesUpdate(ColorStyle.CoolBlack);
  517. break;
  518. //case MenuCommandType.White:
  519. // break;
  520. //case MenuCommandType.SkyBlue:
  521. // SetInitializeCheck(item);
  522. // ThemesUpdate(ColorStyle.SkyBlue);
  523. // break;
  524. //case MenuCommandType.DarkRed:
  525. // SetInitializeCheck(item);
  526. // ThemesUpdate(ColorStyle.DarkRed);
  527. // break;
  528. case MenuCommandType.DarkBlue:
  529. SetInitializeCheck(item);
  530. ThemesUpdate(ColorStyle.DarkBlue);
  531. break;
  532. case MenuCommandType.BlueWhite:
  533. SetInitializeCheck(item);
  534. ThemesUpdate(ColorStyle.BlueWhite);
  535. break;
  536. case MenuCommandType.LockScreen:
  537. this.IsLockScreen = true;
  538. break;
  539. #endregion
  540. #region 分析
  541. case MenuCommandType.CandleChart:
  542. if (goods == null) return;
  543. // WindowHelper.OpenQuoteChartWindow(new OpenQuoteChartWindowArg(goods, CycleType.Minute));
  544. break;
  545. case MenuCommandType.TimeSharingChart:
  546. if (goods == null) return;
  547. // WindowHelper.OpenQuoteChartWindow(new OpenQuoteChartWindowArg(goods, CycleType.TimeSharing));
  548. break;
  549. case MenuCommandType.TikChart:
  550. if (goods == null) return;
  551. // WindowHelper.OpenQuoteChartWindow(new OpenQuoteChartWindowArg(goods, CycleType.Tik));
  552. break;
  553. case MenuCommandType.TradeDetails:
  554. if (goods == null) return;
  555. //PriceCardHelper.OpenSubPenDetail(goods);
  556. break;
  557. case MenuCommandType.TikDetails:
  558. if (goods == null) return;
  559. //PriceCardHelper.OpenSubPriceDetail(goods);
  560. break;
  561. case MenuCommandType.F10:
  562. //todo:
  563. break;
  564. case MenuCommandType.MA:
  565. //todo:
  566. break;
  567. case MenuCommandType.BOLL:
  568. //todo:
  569. break;
  570. case MenuCommandType.MACD:
  571. //todo:
  572. break;
  573. case MenuCommandType.DMI:
  574. //todo:
  575. break;
  576. case MenuCommandType.OBV:
  577. //todo:
  578. break;
  579. case MenuCommandType.VOL:
  580. //todo:
  581. break;
  582. case MenuCommandType.RSI:
  583. //todo:
  584. break;
  585. case MenuCommandType.KDJ:
  586. //todo:
  587. break;
  588. case MenuCommandType.CCI:
  589. //todo:
  590. break;
  591. case MenuCommandType.BIAS:
  592. //todo:
  593. break;
  594. case MenuCommandType.PSY:
  595. //todo:
  596. break;
  597. case MenuCommandType.MTM:
  598. //todo:
  599. break;
  600. case MenuCommandType.WR:
  601. //todo:
  602. break;
  603. case MenuCommandType.MultiCycles:
  604. //todo:
  605. break;
  606. case MenuCommandType.MultiGoodses:
  607. //todo:
  608. break;
  609. case MenuCommandType.ComparisonGoodes:
  610. //todo:
  611. break;
  612. #endregion
  613. #region 交易
  614. case MenuCommandType.BuyIn:
  615. //建仓
  616. var openOrder = new OrderMessage() { Direction = Direction.Bid, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
  617. MessengerHelper.DefaultSend(openOrder, MessengerTokens.OrderMessageToken);
  618. break;
  619. case MenuCommandType.Sellout:
  620. //平仓
  621. var order = new OrderMessage() { Direction = Direction.Ask, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
  622. MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken);
  623. break;
  624. case MenuCommandType.Cancel:
  625. //撤单
  626. if (ViewModelLocator.MOrderDetails.CanCancelOrderDetial())
  627. {
  628. // ViewModelLocator.MOrderDetails.CancelAllHoldingCammand.Execute(null);
  629. ViewModelLocator.MOrderDetails.CancelHoldingCammand.Execute(null);
  630. }
  631. else
  632. {
  633. MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.UnSupportOrderTypes, Muchinfo.MTPClient.Resources.Client_Resource.Models_CancelBillTips);
  634. }
  635. break;
  636. case MenuCommandType.SaleApply:
  637. var sale = new OrderMessage() { Direction = Direction.Bid, OrderPriceMode = ePriceMode.PRICEMODE_MARKET };
  638. MessengerHelper.DefaultSend(sale, MessengerTokens.OrderMessageToken);
  639. break;
  640. case MenuCommandType.DeliveryApply:
  641. //交收申请
  642. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.DeliveryDeclare);
  643. break;
  644. case MenuCommandType.ReportQuery:
  645. //报表查询
  646. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.AccountReport);
  647. break;
  648. case MenuCommandType.TradeLogin:
  649. var login = new TradeLoginView()
  650. {
  651. Owner = Application.Current.MainWindow,
  652. WindowStartupLocation = WindowStartupLocation.CenterOwner,
  653. ShowInTaskbar = false,
  654. };
  655. if (login.ShowDialog() == true)
  656. {
  657. TradeDataInit(); ////交易账号登录
  658. }
  659. break;
  660. //case MenuCommandType.TradeSettings:
  661. // MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.TraderingParamSet);
  662. // break;
  663. #endregion
  664. #region 帮助
  665. //case MenuCommandType.UserGuide:
  666. // break;
  667. case MenuCommandType.EscapeClause:
  668. var v = new AboutView(1);
  669. v.Owner = Application.Current.MainWindow;
  670. v.WindowStartupLocation = WindowStartupLocation.CenterOwner;
  671. v.ShowDialog();
  672. break;
  673. case MenuCommandType.OfficalWeb:
  674. //if (string.IsNullOrWhiteSpace(ApplicationParameter.WebSite))
  675. //{
  676. // MessageBoxHelper.ShowInfo(Muchinfo.MTPClient.Resources.Client_Resource.UI2014_NoOfficialWebsitePleaseConfigurationFile, Muchinfo.MTPClient.Resources.Client_Resource.UI2014_ConfigurationError);
  677. //}
  678. //else
  679. //{
  680. // var proc = new Process { StartInfo = { FileName = ApplicationParameter.WebSite } };
  681. // proc.Start();
  682. //}
  683. HedgingEntrustWindow hedgingEntrustWindow = new HedgingEntrustWindow()
  684. {
  685. WindowStartupLocation = WindowStartupLocation.CenterScreen
  686. };
  687. _ = hedgingEntrustWindow.ShowDialog();
  688. break;
  689. //case MenuCommandType.OnlineCS:
  690. // break;
  691. case MenuCommandType.AboutUs:
  692. var t = new AboutView(2)
  693. {
  694. Owner = Application.Current.MainWindow,
  695. WindowStartupLocation = WindowStartupLocation.CenterOwner
  696. };
  697. t.ShowDialog();
  698. break;
  699. #endregion
  700. #region 风管云平台
  701. case MenuCommandType.Manage:
  702. // 现货
  703. QuoteVisibility = Visibility.Hidden;
  704. WebBrowerVisibility = Visibility.Visible;
  705. break;
  706. #endregion
  707. case MenuCommandType.MarketQuote:
  708. case MenuCommandType.SelectedGoodses:
  709. MessengerHelper.DefaultSend(item, MessengerTokens.ChangeMarket);
  710. // 期货
  711. QuoteVisibility = Visibility.Visible;
  712. WebBrowerVisibility = Visibility.Hidden;
  713. break;
  714. default:
  715. if (item.Command != null) ////默认实现自带操作的命令
  716. {
  717. item.Command.Execute(null);
  718. }
  719. break;
  720. }
  721. }
  722. /// <summary>
  723. /// Initializes the commands.
  724. /// </summary>
  725. private void InitializeCommands()
  726. {
  727. MenuCommand = new RelayCommand<SysMenuItem>((item) =>
  728. {
  729. if (item == null || (item.Children != null && item.Children.Any())) return;
  730. ExecuteCommand(item);
  731. });
  732. }
  733. #region 快捷键
  734. private RelayCommand<CommandFunc> _keyCommand;
  735. /// <summary>
  736. /// 初始化命令
  737. /// </summary>
  738. public RelayCommand<CommandFunc> KeyCommand
  739. {
  740. get
  741. {
  742. if (_keyCommand != null)
  743. {
  744. return _keyCommand;
  745. }
  746. _keyCommand = new RelayCommand<CommandFunc>((command) =>
  747. {
  748. ExecuteKeyCommand(command);
  749. });
  750. return _keyCommand;
  751. }
  752. }
  753. /// <summary>
  754. /// 执行命令
  755. /// </summary>
  756. /// <param name="command"></param>
  757. private void ExecuteKeyCommand(CommandFunc command)
  758. {
  759. if (this.IsLockScreen) ////锁屏时不执行命令
  760. {
  761. return;
  762. }
  763. var curMode = ViewModelLocator.MainContent.TabContetMode;
  764. switch (command)
  765. {
  766. case CommandFunc.OpenOrder:
  767. if (CanCommandEnable(MenuCommandType.BuyIn) &&
  768. UserManager.QuotationWindowType == TabContetMode.QuoteList)
  769. {
  770. var order = new OrderMessage()
  771. {
  772. Direction = Direction.Bid,
  773. OrderPriceMode = ePriceMode.PRICEMODE_MARKET
  774. };
  775. MessengerHelper.DefaultSend(order, MessengerTokens.OrderMessageToken);
  776. }
  777. break;
  778. case CommandFunc.OpenChart:
  779. MessengerHelper.DefaultSend(TabContetMode.QuoteChart, MessengerTokens.MainContentChange);
  780. break;
  781. case CommandFunc.BrowserBack: ////返回行情列表,在行情列表则提示是否退出
  782. var mode = ViewModelLocator.MainContent.TabContetMode;
  783. if (mode == TabContetMode.QuoteList)
  784. {
  785. OnClose();
  786. }
  787. else
  788. {
  789. MessengerHelper.DefaultSend(TabContetMode.QuoteList, MessengerTokens.MainContentChange);
  790. }
  791. break;
  792. case CommandFunc.QuoteInsert:
  793. if ((curMode == TabContetMode.QuoteList || curMode == TabContetMode.QuoteBoard) &&
  794. SelectedQuoteGoods != null)
  795. {
  796. if (ApplicationParameter.ShowChart == 1 || !UserManager.IsAccountLogin) ////游客登录也可看图表
  797. {
  798. //如果是在内容行上双击, 打开分析图表窗口
  799. //MessengerHelper.DefaultSend(new OpenQuoteChartWindowArg(QuoteListDataGrid.SelectedItem as QuoteGoods, CycleType.Minutes1),
  800. // MessengerTokens.OpenQuoteChartWindow);
  801. MessengerHelper.DefaultSend(TabContetMode.QuoteChart, MessengerTokens.MainContentChange);
  802. }
  803. }
  804. break;
  805. case CommandFunc.QuotePageDown:
  806. case CommandFunc.QuotePageup:
  807. if (curMode == TabContetMode.QuoteList || curMode == TabContetMode.QuoteChart)
  808. {
  809. MessengerHelper.DefaultSend<CommandFunc>(command, MessengerTokens.QuoteGoodsListToken);
  810. }
  811. break;
  812. case CommandFunc.GoodsF10:
  813. var FtenAddress = ApplicationParameter.FtenAddress;
  814. if (!string.IsNullOrEmpty(FtenAddress))
  815. {
  816. MessengerHelper.DefaultSend<TabContetMode>(TabContetMode.QuoteGoodsInfo,
  817. MessengerTokens.ChangeGoodsInfo);
  818. }
  819. break;
  820. case CommandFunc.Tab:
  821. if (UserManager.GetCurrentLayoutStyle() == LayoutStyle.Tradition)
  822. {
  823. MessengerHelper.DefaultSend(true, MessengerTokens.SetOrderFoucsToken);
  824. }
  825. break;
  826. case CommandFunc.Amount:
  827. MessengerHelper.DefaultSend(MenuCommandType.AccountInfo, MessengerTokens.MenuSelectChange);
  828. break;
  829. case CommandFunc.HoldDetail:
  830. MessengerHelper.DefaultSend(MenuCommandType.Position, MessengerTokens.MenuSelectChange);
  831. break;
  832. case CommandFunc.CompleteOrder:
  833. MessengerHelper.DefaultSend(MenuCommandType.TransactionOrder, MessengerTokens.MenuSelectChange);
  834. break;
  835. case CommandFunc.QuoteTik:
  836. if (SelectedQuoteGoods != null &&
  837. (SelectedQuoteGoods.TradeMode == eTradeMode.TRADEMODE_BIDDING ||
  838. SelectedQuoteGoods.TradeMode == eTradeMode.TRADEMODE_MARKETMAKE ||
  839. SelectedQuoteGoods.TradeMode == eTradeMode.TRADEMODE_BIDDINGMARKETMAKE))
  840. {
  841. MessengerHelper.DefaultSend<QuoteGoods>(SelectedQuoteGoods, MessengerTokens.ShowTikDetail);
  842. }
  843. MessengerHelper.DefaultSend(MenuCommandType.AccountInfo, MessengerTokens.MenuSelectChange);
  844. break;
  845. case CommandFunc.Buy:
  846. var tradeView = SimpleIoc.Default.GetInstance<TradeHeaderViewModel>();
  847. if (tradeView.CanCommandEnable(MenuCommandType.BuyIn))
  848. {
  849. tradeView.BuyCommand.Execute(null);
  850. }
  851. break;
  852. case CommandFunc.Sell:
  853. var tradeViewsell = SimpleIoc.Default.GetInstance<TradeHeaderViewModel>();
  854. if (tradeViewsell.CanCommandEnable(MenuCommandType.Sellout))
  855. {
  856. tradeViewsell.SellCommand.Execute(null);
  857. }
  858. break;
  859. case CommandFunc.Cancel:
  860. var orderView = SimpleIoc.Default.GetInstance<MOOrderDetailViewModel>();
  861. orderView.SearchOrderStatus = SearchOrderStatus.OnMarket;
  862. MessengerHelper.DefaultSend(MenuCommandType.EntrustOrder, MessengerTokens.MenuSelectChange);
  863. break;
  864. case CommandFunc.OpenTradeBoard:
  865. IsTradeVisible = !IsTradeVisible;
  866. break;
  867. case CommandFunc.TranFloatOrder:
  868. break;
  869. default:
  870. break;
  871. }
  872. }
  873. /// <summary>
  874. /// 命令类型
  875. /// </summary>
  876. /// <param name="commandType"></param>
  877. /// <returns></returns>
  878. public bool CanCommandEnable(MenuCommandType commandType)
  879. {
  880. if (UserManager.TradeFuncMenus != null && UserManager.TradeFuncMenus.Any())
  881. {
  882. var tradeFunc = UserManager.TradeFuncMenus.FirstOrDefault((item) => item.FuncMenuCode == commandType.ToString());
  883. if (tradeFunc != null)
  884. {
  885. return tradeFunc.IsEnabled;
  886. }
  887. }
  888. return false;
  889. }
  890. /// <summary>
  891. /// 初始化键命令
  892. /// </summary>
  893. /// <returns></returns>
  894. public List<KeyBinding> InitKeysCommand()
  895. {
  896. return _systemService.GetHomeKeyBindings(KeyCommand);
  897. }
  898. #endregion
  899. /// <summary>
  900. /// 将菜单的同级结点选择状态设置为False
  901. /// </summary>
  902. /// <param name="item">设置选择状态的菜单</param>
  903. private void SetInitializeCheck(SysMenuItem item)
  904. {
  905. if (item.ParentItem != null)
  906. {
  907. foreach (var childItem in item.ParentItem.Children)
  908. {
  909. childItem.IsChecked = false;
  910. }
  911. }
  912. item.IsChecked = true;
  913. SaveUserConfig(item); //只有设置布局的方可使用该方法
  914. }
  915. /// <summary>
  916. /// 保存用户主题布局
  917. /// </summary>
  918. /// <param name="item">设置的菜单</param>
  919. private void SaveUserConfig(SysMenuItem item)
  920. {
  921. switch (item.SysCommandType)
  922. {
  923. case MenuCommandType.Vertical:
  924. ////保存配置
  925. UserManager.SaveCurrentLayoutStyle(LayoutStyle.Vertical);
  926. break;
  927. case MenuCommandType.Horizontal:
  928. ////保存配置
  929. UserManager.SaveCurrentLayoutStyle(LayoutStyle.Horizontal);
  930. break;
  931. case MenuCommandType.Tradition:
  932. ////保存配置
  933. UserManager.SaveCurrentLayoutStyle(LayoutStyle.Tradition);
  934. break;
  935. case MenuCommandType.CoolBlack:
  936. ////保存配置
  937. UserManager.SaveCurrentColorStyle(ColorStyle.CoolBlack);
  938. break;
  939. case MenuCommandType.BlueWhite:
  940. ////保存配置
  941. UserManager.SaveCurrentColorStyle(ColorStyle.BlueWhite);
  942. break;
  943. case MenuCommandType.DarkBlue:
  944. ////保存配置
  945. UserManager.SaveCurrentColorStyle(ColorStyle.DarkBlue);
  946. break;
  947. default:
  948. break;
  949. }
  950. }
  951. /// <summary>
  952. /// 设置系统主题
  953. /// </summary>
  954. public void InitializeThemes()
  955. {
  956. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  957. {
  958. var defaultLayout = UserManager.GetCurrentLayoutStyle();
  959. MainLayoutUpdate(defaultLayout);
  960. var defaultColor = UserManager.GetCurrentColorStyle();
  961. ThemesUpdate(defaultColor);
  962. }));
  963. }
  964. /// <summary>
  965. /// 切换主题加载资源
  966. /// </summary>
  967. /// <param name="colorStyle"></param>
  968. private void ThemesUpdate(ColorStyle colorStyle)
  969. {
  970. string themesType;
  971. switch (colorStyle)
  972. {
  973. case ColorStyle.CoolBlack:
  974. themesType = "CoolBlack";
  975. break;
  976. //case ColorStyle.SkyBlue:
  977. // themesType = "SkyBlue";
  978. // break;
  979. //case ColorStyle.DarkRed:
  980. // themesType = "DarkRed";
  981. // break;
  982. case ColorStyle.DarkBlue:
  983. themesType = "DarkBlue";
  984. break;
  985. case ColorStyle.BlueWhite:
  986. themesType = "BlueWhite";
  987. break;
  988. default:
  989. themesType = "DarkBlue";
  990. break;
  991. }
  992. string url = string.Format("/Client.Main;component/Themes/{0}/Style.xaml", themesType);
  993. var resource = (ResourceDictionary)Application.LoadComponent(new Uri(url, UriKind.Relative));
  994. if (CurrentStyle != null && Application.Current.Resources.MergedDictionaries.Contains(CurrentStyle))
  995. {
  996. Application.Current.Resources.MergedDictionaries.Remove(CurrentStyle as ResourceDictionary);
  997. }
  998. else
  999. {
  1000. for (int i = 0; i < Application.Current.Resources.MergedDictionaries.Count; i++)
  1001. {
  1002. var resourceDic = Application.Current.Resources.MergedDictionaries[i];
  1003. if (resourceDic != null)
  1004. {
  1005. resourceDic.Clear();
  1006. }
  1007. }
  1008. // Application.Current.Resources.MergedDictionaries.Clear();
  1009. }
  1010. //if (ApplicationParameter.DataGridColor == "0") //显示纯色
  1011. //{
  1012. // resource.Add("MuchinfoBrush35", System.Windows.Media.Brushes.Transparent);
  1013. // resource.Add("MuchinfoBrush36", System.Windows.Media.Brushes.Transparent);
  1014. //}
  1015. Application.Current.Resources.MergedDictionaries.Add(resource);
  1016. CurrentStyle = resource;
  1017. MessengerHelper.DefaultSend<string>(themesType, MessengerTokens.RegisterResourceChange);
  1018. ////主題变化时强制通知商品颜色改变
  1019. MessengerHelper.DefaultSend(true, MessengerTokens.NotifyQuoteGoodsColorChanged);
  1020. }
  1021. private void MainLayoutUpdate(LayoutStyle layout)
  1022. {
  1023. LogInfoHelper.WriteInfo("Starting MainLayoutUpdate......");
  1024. try
  1025. {
  1026. switch (layout)
  1027. {
  1028. case LayoutStyle.Horizontal:
  1029. MainContent = new HorizontalLayout();
  1030. break;
  1031. case LayoutStyle.Vertical:
  1032. MainContent = new VerticalLayout();
  1033. break;
  1034. case LayoutStyle.Tradition:
  1035. MainContent = new TraditionLayout();
  1036. break;
  1037. default:
  1038. MainContent = new HorizontalLayout();
  1039. break;
  1040. }
  1041. LogInfoHelper.WriteInfo("end MainLayoutUpdate,begin send Message MessengerTokens.UpdateLayoutChange");
  1042. MessengerHelper.DefaultSend(layout, MessengerTokens.UpdateLayoutChange);
  1043. }
  1044. catch (Exception ex)
  1045. {
  1046. LogInfoHelper.WriteInfo("布局异常..." + ex.ToString());
  1047. }
  1048. }
  1049. /// <summary>
  1050. /// Called when [close].
  1051. /// </summary>
  1052. private void OnClose()
  1053. {
  1054. if (MessageBoxHelper.ShowQuestion(Muchinfo.MTPClient.Resources.Client_Resource.UI2014_IsOrNotExit,
  1055. Muchinfo.MTPClient.Resources.Client_Resource.UI2014_Tips) == MessageBoxResult.Yes)
  1056. {
  1057. if (UserManager.IsAccountLogin)
  1058. {
  1059. ////保存布局及列表行情抬头
  1060. MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
  1061. //手动发送登出消息
  1062. var service = SimpleIoc.Default.GetInstance<ILoginService>();
  1063. if (service != null) service.TradeAccountLogout(UserManager.CurrentTradeAccount);
  1064. }
  1065. WindowHelper.RerunApplication(false);
  1066. }
  1067. }
  1068. private void MainPanelIsEnableMethod(bool mainPanelIsUnlock)
  1069. {
  1070. if (mainPanelIsUnlock == true)
  1071. {
  1072. WindowCollection list = Application.Current.Windows;
  1073. foreach (Window w in list)
  1074. {
  1075. if (w.Owner == null)
  1076. {
  1077. MainPanelVisibility = Visibility.Collapsed;
  1078. }
  1079. else
  1080. {
  1081. w.WindowState = WindowState.Normal;
  1082. w.Opacity = 1;
  1083. }
  1084. }
  1085. }
  1086. else
  1087. {
  1088. MainPanelVisibility = Visibility.Visible;
  1089. }
  1090. }
  1091. #endregion Private Methods
  1092. #region 公告处理
  1093. /// <summary>
  1094. /// 查询是否有未读公告
  1095. /// </summary>
  1096. /// <param name="itemList">数据列表</param>
  1097. protected void NoticeCountSuccess(List<NoticeCount> itemList)
  1098. {
  1099. if (itemList != null && itemList.Any())
  1100. {
  1101. var notice = itemList.FirstOrDefault((item) => item.MsgType == MsgTypeEnum.Bulletin && item.MsgCount > 0);
  1102. if (notice != null) //弹出公告
  1103. {
  1104. MessengerHelper.DefaultSend<MsgTypeEnum>(notice.MsgType, MessengerTokens.AnnouncementMessage);
  1105. return; //不用两个都弹出来
  1106. }
  1107. var notify = itemList.FirstOrDefault((item) => item.MsgType == MsgTypeEnum.NTF && item.MsgCount > 0);
  1108. if (notify != null) //弹出消息
  1109. {
  1110. MessengerHelper.DefaultSend<MsgTypeEnum>(notify.MsgType, MessengerTokens.AnnouncementMessage);
  1111. }
  1112. }
  1113. }
  1114. protected void QueryErrorCallback(ErrorEntity errorEntity)
  1115. {
  1116. //IsBusy = false;
  1117. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1118. //{
  1119. // ErrorManager.ShowReturnError(errorEntity, Muchinfo.MTPClient.Resources.Client_Resource.APP_Tips, false);
  1120. //}));
  1121. }
  1122. #endregion
  1123. #region 下单
  1124. /// <summary>
  1125. /// 下单类型
  1126. /// </summary>
  1127. /// <param name="tradeViewModel">下单模型</param>
  1128. private void SetOrderView(TradeOrderViewModel tradeViewModel)
  1129. {
  1130. IsOrderVisible = true;
  1131. TradeViewModel = tradeViewModel;
  1132. }
  1133. //ViewLoadedCommand = new RelayCommand<Home>((MainPage) =>
  1134. //{
  1135. // view.MainPanel.Children.Clear();
  1136. // UserManager.UserManagerCurrentMarketType = MenuCommandType.CustomQuote;
  1137. // UserManager.QuotationWindowType = QuotationWindowType.Board;
  1138. // _oldTabIndex = 9;
  1139. // WindowHelper.OpenDefaultQuoteListView(false);
  1140. //});
  1141. private bool _isOrderVisible;
  1142. /// <summary>
  1143. /// 是否显示下单
  1144. /// </summary>
  1145. public bool IsOrderVisible
  1146. {
  1147. get { return _isOrderVisible; }
  1148. set { Set(() => IsOrderVisible, ref _isOrderVisible, value); }
  1149. }
  1150. private TradeOrderViewModel _tradeViewModel;
  1151. /// <summary>
  1152. /// 下单逻辑
  1153. /// </summary>
  1154. public TradeOrderViewModel TradeViewModel
  1155. {
  1156. get { return _tradeViewModel; }
  1157. set { Set(() => TradeViewModel, ref _tradeViewModel, value); }
  1158. }
  1159. #endregion
  1160. #region 交易登录初始化
  1161. /// <summary>
  1162. /// 交易数据初始化
  1163. /// </summary>
  1164. private void TradeDataInit()
  1165. {
  1166. IsBusy = true;
  1167. ////初始化我的自选
  1168. FavoriteManager.InitializeFavorite(MenuNames.QuotationFavorite);
  1169. //先查询市场信息,再查询商品信息
  1170. ulong lastUpdateTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.MarketsUTime);
  1171. if (MarketResxManager.MarketResx.ResourceHashtable == null || MarketResxManager.MarketResx.Version != lastUpdateTimeUTC)
  1172. {
  1173. _loginService.MarketsQuerySearch(lastUpdateTimeUTC, MarketsInfoCallBack, ErrorEntityCallBack);
  1174. }
  1175. else
  1176. {
  1177. MarketsInfoModel[] marketsArr = Newtonsoft.Json.JsonConvert.DeserializeObject<MarketsInfoModel[]>(Newtonsoft.Json.JsonConvert.SerializeObject(MarketResxManager.MarketResx.ResourceHashtable.Values));
  1178. List<MarketsInfoModel> marketLst = marketsArr.ToList();
  1179. CacheManager.LoadMarketInfoList(marketLst);
  1180. MarketsInfoCallBack(marketLst, 0, false);
  1181. }
  1182. SearchDeliveryGoods();
  1183. }
  1184. /// <summary>
  1185. /// ///查询交割关系列表-成功返回
  1186. /// </summary>
  1187. private void QueryAllDeliveryRelationSuccess(List<Muchinfo.MTPClient.Data.Model.Delivery.RelationPAndXGoodsInfoModel> itemList)
  1188. {
  1189. Muchinfo.MTPClient.Infrastructure.Cache.CacheManager.AllDeliveryRelationList = itemList;
  1190. }
  1191. private void SearchAllGoodsUnitCallBack(List<Muchinfo.MTPClient.Data.Model.DBTableMsg.GoodsUnit> goodUnit)
  1192. {
  1193. Muchinfo.MTPClient.Infrastructure.Cache.CacheManager.TradeGoodsUnit = goodUnit;
  1194. foreach (var quoteGoods in CacheManager.CacheGoodsBaseInfos)
  1195. {
  1196. quoteGoods.AgreeUnitDisplay = quoteGoods.GoodsParameters.AgreeUnit.ToString() + CacheManager.TradeGoodsUnit.Where(x => x.UNITID == quoteGoods.GoodsParameters.AgreeUnitType).Select(x => x.GOODSUNITNAME).FirstOrDefault();
  1197. }
  1198. }
  1199. /// <summary>
  1200. /// 查询失败
  1201. /// </summary>
  1202. /// <param name="error"></param>
  1203. private void ErrorEntityCallBack(ErrorEntity error)
  1204. {
  1205. LogInfoHelper.WriteInfo("MarketsQuerySearch or GoodsQuerySearch or GoodsGroup callback Failed");
  1206. IsBusy = false;
  1207. InitComplete();
  1208. FuncMenusErrorFunc(error);
  1209. }
  1210. private void AccountBaseInfoInitError(ErrorEntity error)
  1211. {
  1212. var format = "查询账号基本信息:" + string.Format(ErrorManager.FormatErrorMsg(error));
  1213. LogInfoHelper.WriteInfo(format);
  1214. ////清除链路
  1215. // LinkManager.Instance.Dispose();
  1216. }
  1217. /// <summary>
  1218. /// 市场成功查询MTP2.0
  1219. /// </summary>
  1220. /// <param name="MarketsInfoList"></param>
  1221. public void MarketsInfoCallBack(List<MarketsInfoModel> MarketsInfoList, ulong marketStamp = 0, bool bUpdate = true)
  1222. {
  1223. //登陆后基本数据查询
  1224. _loginService.LoginQuerySearch(UserManager.CurrentTradeAccount.LoginID, LoginQueryType.All, LoadAccountBaseInfoCallback, AccountBaseInfoInitError);
  1225. if (bUpdate)
  1226. {
  1227. //如果是调用接口更新的系统参数,需要更新对应的本地文件
  1228. var hashtable = new Hashtable();
  1229. foreach (var market in MarketsInfoList)
  1230. {
  1231. hashtable.Add(market.MarketID, market);
  1232. }
  1233. MarketResxManager.SaveMarketResx(hashtable, marketStamp, UserManager.UserDataFolder);
  1234. }
  1235. }
  1236. /// <summary>
  1237. /// 商品成功查询MTP2.0
  1238. /// </summary>
  1239. /// <param name="GoodsInfoList">The goods information list.</param>
  1240. /// <param name="goodsStamp">The goods stamp.</param>
  1241. /// <param name="bUpdate">if set to <c>true</c> [b update].</param>
  1242. /// <param name="midParam">The mid parameter.</param>
  1243. public void GoodsInfoCallBack(List<QuoteGoods> GoodsInfoList, ulong goodsStamp = 0, bool bUpdate = true, List<TradeGoodsFeeRule> midParam = null)
  1244. {
  1245. if (bUpdate)
  1246. {
  1247. //如果是调用接口更新的系统参数,需要更新对应的本地文件
  1248. var hashtable = new Hashtable();
  1249. foreach (var goods in GoodsInfoList)
  1250. {
  1251. hashtable.Add(goods.GoodsCode, goods);
  1252. }
  1253. GoodsResxManager.SaveGoodsResx(hashtable, goodsStamp, UserManager.UserDataFolder);
  1254. }
  1255. ////创建行情链路, 链路成功后订阅商品
  1256. //LinkManager.Instance.CreateQuoteTcpLink();
  1257. //查询交易端配置的菜单--菜单权限从服务端不使用缓存
  1258. ulong menuUTime = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.MenuUTime);
  1259. _loginService.QueryAccountFuncMenu(menuUTime, midParam, FuncMenusSuccess, FuncMenusErrorFunc);
  1260. //改成串行下载数据
  1261. /*
  1262. ////查询商品组信息
  1263. //_loginService.QueryGoodsGroup(null, ErrorEntityCallBack);
  1264. ////外部交易所查询
  1265. //_loginService.QueryExternalExchange(ExternalExchangeCallBack, ErrorEntityCallBack);
  1266. ////查询持仓汇总
  1267. //var queryList = new List<QueryCommonParam>
  1268. //{
  1269. // new QueryCommonParam() {ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.FundsAccountId + string.Empty}
  1270. //};
  1271. //_orderService.QueryHoldingPosistion(QueryStatement.TradePositionDetail, queryList, QuerySuccessCallBack, QueryErrorCallback);
  1272. //_commonQueryService.QueryMarketRun(0, MarketRunQuerySuccessCallBack, QueryErrorCallback);
  1273. */
  1274. }
  1275. /// <summary>
  1276. /// Markets the run query success call back.
  1277. /// </summary>
  1278. /// <param name="models">The models.</param>
  1279. private void MarketRunQuerySuccessCallBack(List<MarketRunModelNew> models)
  1280. {
  1281. // 这里需要把所属母账户也带上 <- 又不用带了……
  1282. var fundsAccountIDs = string.Join(",", UserManager.CurrentTradeAccount.FundsAccountIds);
  1283. //if (UserManager.CurrentTradeAccount.FundsAccounts.Count > 0 && UserManager.CurrentTradeAccount.FundsAccounts[0].ParentAccountID != 0)
  1284. //{
  1285. // fundsAccountIDs += string.Format(",{0}", UserManager.CurrentTradeAccount.FundsAccounts[0].ParentAccountID);
  1286. //}
  1287. // 查询账户汇率模板
  1288. _commonQueryService.QueryTradeRateTmpConfig(fundsAccountIDs, null, QueryErrorCallback);
  1289. // 查询外部汇率模版配置表
  1290. //_commonQueryService.QueryExtenalTradeRateTmpConfig(fundsAccountIDs, DateTime.Now.ToString("yyyyMMdd"), null, QueryErrorCallback);
  1291. // 查询资金账户汇率
  1292. //_commonQueryService.QueryTaAccountExchangeRate(fundsAccountIDs, null, QueryErrorCallback);
  1293. CacheManager.UpdateMarketRun(models);
  1294. }
  1295. /// <summary>
  1296. /// 外部交易所查询成功调用
  1297. /// </summary>
  1298. /// <param name="externalExchages"></param>
  1299. private void ExternalExchangeCallBack(List<ExternalExchangeModel> externalExchages)
  1300. {
  1301. ////查询交易端配置的菜单
  1302. List<Exchange> exchangeLst = new List<Exchange>();
  1303. foreach (var exchange in externalExchages)
  1304. {
  1305. var newExchanage = new Exchange
  1306. {
  1307. ExchangeId = exchange.AutoID,
  1308. ExchangeCode = exchange.ExExchangeCode,
  1309. ExchangeName = exchange.ExExchangeName,
  1310. IsMarketPrice = exchange.IsMarketPrice
  1311. };
  1312. exchangeLst.Add(newExchanage);
  1313. }
  1314. //使用外部交易所做为交易所缓存
  1315. CacheManager.LoadExchangeInfo(exchangeLst);
  1316. //重新构建分类菜单
  1317. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.UpdateQuoteMarket);
  1318. //查询持仓汇总
  1319. var queryList = new List<QueryCommonParam>
  1320. {
  1321. new QueryCommonParam() {ParamKey = "accountId", ParamValue = UserManager.CurrentTradeAccount.FundsAccountId + string.Empty}
  1322. };
  1323. _orderService.QueryHoldingPosistion(QueryStatement.TradePositionDetail, queryList, QuerySuccessCallBack, ErrorEntityCallBack);
  1324. CreateLoaclMenu(UserManager.AccessFuncMenus);
  1325. }
  1326. /// <summary>
  1327. /// Queries the success call back.
  1328. /// </summary>
  1329. /// <param name="orders">The orders.</param>
  1330. private void QuerySuccessCallBack(List<HoldingSummary> orders)
  1331. {
  1332. _commonQueryService.QueryMarketRun(0, MarketRunQuerySuccessCallBack, ErrorEntityCallBack);
  1333. }
  1334. /// <summary>
  1335. /// 构建菜单
  1336. /// </summary>
  1337. /// <param name="funcs"></param>
  1338. private void FuncMenusSuccess(List<SysMenuItem> funcs, ulong menuUTime, List<TradeGoodsFeeRule> GoodsRuleLst, bool update = true)
  1339. {
  1340. UserManager.LocalFuncMenus = eSystemMenuValue.CreateInstance().menu;//实例化本地菜单数据;
  1341. UserManager.FixedFuncMenus = eSystemMenuValue.CreateInstance().fixedMenuList;
  1342. List<SysMenuItem> menus;
  1343. try
  1344. {
  1345. //可使用菜单为 本地固定菜单+服务端获取的且终端已实现的菜单 - dyp
  1346. menus = UserManager.FixedFuncMenus.Union(funcs.Where(z => UserManager.LocalFuncMenus.Select(t => t.Value).Contains(z.FuncMenuCode))).ToList();
  1347. //对菜单进行排序 - dyp
  1348. menus.Sort((x, y) => { return x.SortId > y.SortId ? 1 : (x.SortId == y.SortId ? 0 : -1); });
  1349. }
  1350. catch
  1351. {
  1352. menus = new List<SysMenuItem>();
  1353. }
  1354. //更新交集的菜单
  1355. if (update)
  1356. {
  1357. var hashtable = new Hashtable();
  1358. foreach (var menu in menus)
  1359. {
  1360. hashtable.Add(menu.FuncMenuCode, menu);
  1361. }
  1362. MenuResxManager.SaveMenuResx(hashtable, menuUTime, UserManager.UserDataFolder);
  1363. }
  1364. UserManager.AccessFuncMenus = menus;
  1365. // ////是否可看
  1366. // GetDepositPlan();
  1367. // ////更新市场菜单
  1368. //// MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.UpdateQuoteMarket);
  1369. CreateLoaclMenu(menus);
  1370. if (menus != null && menus.Any())
  1371. {
  1372. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1373. {
  1374. ViewModelLocator.MenuTree.LoadMenus(menus);
  1375. //缓存 -交易商品的费用计算方式,与交易规则
  1376. CacheManager.TradeGoodsFeeRules = GoodsRuleLst.ToArray<TradeGoodsFeeRule>().ToDictionary(key => key.GoodsID, value => value);
  1377. ///todo:保存在缓存中
  1378. IsBusy = false;
  1379. InitComplete();
  1380. }));
  1381. }
  1382. //查询商品组信息
  1383. _loginService.QueryGoodsGroup(null, ErrorEntityCallBack);
  1384. //外部交易所查询
  1385. _loginService.QueryExternalExchange(ExternalExchangeCallBack, ErrorEntityCallBack);
  1386. }
  1387. /// <summary>
  1388. /// 错误处理
  1389. /// </summary>
  1390. /// <param name="error">错误内容</param>
  1391. private void FuncMenusErrorFunc(ErrorEntity error)
  1392. {
  1393. var funcs = new List<SysMenuItem>();
  1394. UserManager.LocalFuncMenus = eSystemMenuValue.CreateInstance().menu;//实例化本地菜单数据;
  1395. UserManager.FixedFuncMenus = eSystemMenuValue.CreateInstance().fixedMenuList;
  1396. funcs.AddRange(UserManager.FixedFuncMenus);
  1397. UserManager.AccessFuncMenus = funcs;
  1398. CreateLoaclMenu(funcs); ////查询不到菜单时显示默认
  1399. if (funcs != null && funcs.Any())
  1400. {
  1401. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1402. {
  1403. ViewModelLocator.MenuTree.LoadMenus(funcs);
  1404. }));
  1405. }
  1406. }
  1407. #endregion
  1408. #region 私有方法
  1409. /// <summary>
  1410. /// 登录后初始化内容
  1411. /// </summary>
  1412. /// <param name="accountInfo">与账号相关基本信息</param>
  1413. private void LoadAccountBaseInfoCallback(AccountBaseInfoModel accountInfo)
  1414. {
  1415. ulong lastUpdateTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.GoodsUTime);
  1416. if (GoodsResxManager.GoodsResx.ResourceHashtable == null || GoodsResxManager.GoodsResx.Version != lastUpdateTimeUTC)
  1417. {
  1418. _loginService.GoodsInfoSearch(lastUpdateTimeUTC, accountInfo.GoodsRuleAndFeeList, GoodsInfoCallBack, ErrorEntityCallBack);
  1419. }
  1420. else
  1421. {
  1422. QuoteGoods[] quoteGoodsArr = Newtonsoft.Json.JsonConvert.DeserializeObject<QuoteGoods[]>(Newtonsoft.Json.JsonConvert.SerializeObject(GoodsResxManager.GoodsResx.ResourceHashtable.Values));
  1423. var goodsLst =quoteGoodsArr == null? new List<QuoteGoods>(): quoteGoodsArr.OrderBy(z=>z.GoodsCode).ToList();
  1424. CacheManager.LoadGoodsInfoList(goodsLst, GoodsFromScr.Trade);
  1425. GoodsInfoCallBack(goodsLst, 0, false, accountInfo.GoodsRuleAndFeeList);
  1426. }
  1427. }
  1428. private void InitComplete()
  1429. {
  1430. //创建行情链路, 链路成功后订阅商品
  1431. // LinkManager.Instance.CreateQuoteTcpLink();
  1432. //进入主界面后再开户断线重连机制
  1433. LinkManager.Instance.StartReconnect();
  1434. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  1435. {
  1436. //设置系统主题
  1437. InitializeThemes();
  1438. InitLockTimer();///启动锁屏
  1439. ////公告查询处理(处理先显示公告时,样式不一致)--pendding dk
  1440. // _announcementService.QueryNoticeCount(UserManager.CurrentTradeAccount.AccountId, NoticeCountSuccess, QueryErrorCallback);
  1441. ////更新市场菜单
  1442. MessengerHelper.DefaultSend(UserManager.CurrentTradeAccount, MessengerTokens.UpdateQuoteMarket);
  1443. MessengerHelper.DefaultSend(true, MessengerTokens.CheckTokenMsg); ///同步时间
  1444. SimpleIoc.Default.GetInstance<MainContentViewModel>().InitMainPanel(); ////主界面内容 更新
  1445. RaisePropertyChanged(() => IsAccountLogin);
  1446. Task.Factory.TryStartNew(() =>
  1447. {
  1448. //var random = new Random();
  1449. //var seconds = random.Next(2000, 10000); ////随机时间再取资源信息
  1450. //var seconds = random.Next(1, 10); ////随机时间再取资源信息
  1451. //Thread.Sleep(seconds);
  1452. //获取资源版本号
  1453. //_systemService.QueryResxVer(ResxVerSuccess, QueryResxVerError);
  1454. if (CacheManager.CacheLastUpdateTimeList != null)
  1455. {
  1456. SearchErrorResxAndConstResx();
  1457. SearchRiskMsgResx();
  1458. }
  1459. });
  1460. }));
  1461. }
  1462. /// <summary>
  1463. /// 查询数据库错误资源和常量资源信息
  1464. /// </summary>
  1465. private void SearchErrorResxAndConstResx()
  1466. {
  1467. ulong errorCodeTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.ErrorcodeUTime);
  1468. if (MuchinfoException.ErrorResx.ResourceHashtable == null || MuchinfoException.ErrorResx.Version != errorCodeTimeUTC)
  1469. {
  1470. //错误码字典查询 MTP2.0
  1471. _loginService.ErrorCodeQuerySearch(errorCodeTimeUTC, ErrorCodeResxCallback, QueryResxVerError);
  1472. }
  1473. ulong constTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.DirctionaryUTime);
  1474. if (ConstResxManager.ConstResx.ResourceHashtable == null || ConstResxManager.ConstResx.Version != constTimeUTC)
  1475. {
  1476. //枚举常量字典查询 MTP2.0
  1477. _loginService.DictionaryQuerySearch(constTimeUTC, ConstCodeResxCallback, QueryResxVerError);
  1478. }
  1479. }
  1480. private void SearchDeliveryGoods()
  1481. {
  1482. ulong DeliveryGoodsUTime = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.DvGoodsUTime);
  1483. if (DeliveryResxManager.DeliveryResx.ResourceHashtable == null || DeliveryResxManager.DeliveryResx.Version != DeliveryGoodsUTime)
  1484. {
  1485. //错误码字典查询 MTP2.0
  1486. _loginService.DeliveryGoodsQuerySearch(DeliveryGoodsUTime, DeliveryGoodsCallback, DeliveryGoodsError);
  1487. }
  1488. else
  1489. {
  1490. DeliveryGoodsInfoModel[] deliveryGoodsArr = Newtonsoft.Json.JsonConvert.DeserializeObject<DeliveryGoodsInfoModel[]>(Newtonsoft.Json.JsonConvert.SerializeObject(DeliveryResxManager.DeliveryResx.ResourceHashtable.Values));
  1491. List<DeliveryGoodsInfoModel> retLst = deliveryGoodsArr.ToList();
  1492. CacheManager.CacheDeliveryGoodsInfo = retLst;
  1493. }
  1494. }
  1495. private void DeliveryGoodsCallback(List<DeliveryGoodsInfoModel> retLst, ulong DeliveryGoodsUTime = 0, bool bUpdate = true)
  1496. {
  1497. if (bUpdate)
  1498. {
  1499. //如果是调用接口更新的系统参数,需要更新对应的本地文件
  1500. var hashtable = new Hashtable();
  1501. foreach (var deliveryGoods in retLst)
  1502. {
  1503. hashtable.Add(deliveryGoods.DeliveryGoodsCode, deliveryGoods);
  1504. }
  1505. DeliveryResxManager.SaveDeliveryResx(hashtable, DeliveryGoodsUTime, UserManager.UserDataFolder);
  1506. }
  1507. CacheManager.CacheDeliveryGoodsInfo = retLst;
  1508. }
  1509. private void DeliveryGoodsError(ErrorEntity errorEntity)
  1510. {
  1511. var format = "交割商品查询" + string.Format(ErrorManager.FormatErrorMsg(errorEntity));
  1512. LogInfoHelper.WriteInfo(format);
  1513. }
  1514. /// <summary>
  1515. /// 错误资源成功回调
  1516. /// </summary>
  1517. /// <param name="descritions"></param>
  1518. private void ErrorCodeResxCallback(List<ErrorCodeInfoModel> descritions, ulong errCodeStamp)
  1519. {
  1520. Task.Factory.TryStartNew(() =>
  1521. {
  1522. var hashtable = new Hashtable();
  1523. foreach (var desc in descritions)
  1524. {
  1525. hashtable.Add(desc.ErrorCode, desc.ErrorMsg);
  1526. }
  1527. MuchinfoException.ErrorResxSaveRep(hashtable, errCodeStamp);
  1528. });
  1529. }
  1530. /// <summary>
  1531. /// 常量资源成功回调
  1532. /// </summary>
  1533. /// <param name="descritions"></param>
  1534. private void ConstCodeResxCallback(List<DictionaryInfoModel> descritions, ulong constStamp)
  1535. {
  1536. Task.Factory.TryStartNew(() =>
  1537. {
  1538. var hashtable = new Hashtable();
  1539. foreach (var desc in descritions)
  1540. {
  1541. hashtable.Add(desc.FieldCode + "_" + desc.Key, desc.Value);
  1542. }
  1543. ConstResxManager.ConstResxSaveRep(hashtable, constStamp, UserManager.UserDataFolder);
  1544. });
  1545. }
  1546. private void ResxVerSuccess(List<ResxVerInfo> resxVer)
  1547. {
  1548. if (resxVer != null && resxVer.Any())
  1549. {
  1550. _resxVerInfos = resxVer.ToDictionary((item) => item.Versiontype);
  1551. if (_resxVerInfos.ContainsKey(ResxVerType.errorCode))
  1552. {
  1553. if (MuchinfoException.ErrorResx == null || MuchinfoException.ErrorResx.Version < _resxVerInfos[ResxVerType.errorCode].Versionno)
  1554. {
  1555. _systemService.QueryResxDescrition(ResxVerType.errorCode, ResxCallback, QueryResxVerError);
  1556. }
  1557. }
  1558. if (_resxVerInfos.ContainsKey(ResxVerType._const))
  1559. {
  1560. if (ConstResxManager.ConstResx == null || ConstResxManager.ConstResx.Version < _resxVerInfos[ResxVerType._const].Versionno)
  1561. {
  1562. _systemService.QueryResxDescrition(ResxVerType._const, ResxCallback, QueryResxVerError);
  1563. }
  1564. }
  1565. }
  1566. }
  1567. /// <summary>
  1568. /// 查询资源回调
  1569. /// </summary>
  1570. /// <param name="descrition"></param>
  1571. private void ResxCallback(List<ResxDescrition> descritions, ResxVerType varType)
  1572. {
  1573. Task.Factory.TryStartNew(() =>
  1574. {
  1575. var hashtable = new Hashtable();
  1576. foreach (var desc in descritions)
  1577. {
  1578. hashtable.Add(desc.ConstKey, desc.Remarks);
  1579. }
  1580. if (varType == ResxVerType._const)
  1581. {
  1582. ConstResxManager.ConstResxSaveRep(hashtable, _resxVerInfos[varType].Versionno, UserManager.UserDataFolder);
  1583. }
  1584. else if (varType == ResxVerType.errorCode)
  1585. {
  1586. MuchinfoException.ErrorResxSaveRep(hashtable, _resxVerInfos[varType].Versionno);
  1587. }
  1588. });
  1589. }
  1590. private void QueryResxVerError(ErrorEntity errorEntity)
  1591. {
  1592. var format = "资源" + string.Format(ErrorManager.FormatErrorMsg(errorEntity));
  1593. LogInfoHelper.WriteInfo(format);
  1594. }
  1595. #region 风险协议书获取
  1596. /// <summary>
  1597. /// 封装获取风险协议书的方法,如有更新就调用接口重新获取
  1598. /// </summary>
  1599. private void SearchRiskMsgResx()
  1600. {
  1601. ulong riskMsgTimeUTC = CacheManager.GetLastUpdateTimeBy(Muchinfo.MTPClient.Data.Enums.LastUpdateTimeType.RiskMsgUTime);
  1602. if (RiskMsgResxManager.RiskMsgResx.ResourceHashtable == null || RiskMsgResxManager.RiskMsgResx.Version != riskMsgTimeUTC)
  1603. {
  1604. //错误码字典查询 MTP2.0
  1605. _loginService.RiskTipQuerySearch(riskMsgTimeUTC, RiskMsgResxCallback, QueryResxVerError);
  1606. }
  1607. }
  1608. private void RiskMsgResxCallback(RiskTipQueryRspModel risktip, ulong risktipStamp = 0)
  1609. {
  1610. Task.Factory.TryStartNew(() =>
  1611. {
  1612. var hashtable = new Hashtable();
  1613. hashtable.Add(risktip.TipTitle, risktip);
  1614. RiskMsgResxManager.SaveRiskMsgResx(hashtable, risktipStamp, UserManager.UserDataFolder);
  1615. });
  1616. }
  1617. #endregion
  1618. #endregion Methods
  1619. #region 锁屏
  1620. private bool _isLockScreen;
  1621. /// <summary>
  1622. /// 是否锁屏
  1623. /// </summary>
  1624. public bool IsLockScreen
  1625. {
  1626. get { return _isLockScreen; }
  1627. set
  1628. {
  1629. Set(() => IsLockScreen, ref _isLockScreen, value);
  1630. }
  1631. }
  1632. /// <summary>
  1633. /// 锁屏方式
  1634. /// </summary>
  1635. public bool LockScreenType
  1636. {
  1637. get
  1638. {
  1639. return ApplicationParameter.IsShowBGLockSreen == 1;
  1640. }
  1641. }
  1642. /// <summary>
  1643. /// 锁屏定时器
  1644. /// </summary>
  1645. private DispatcherTimer _dispatcherTimer;
  1646. private void InitLockTimer(bool result)
  1647. {
  1648. InitLockTimer();
  1649. }
  1650. /// <summary>
  1651. /// 初始化锁屏
  1652. /// </summary>
  1653. private void InitLockTimer()
  1654. {
  1655. var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
  1656. int time = 0;
  1657. if (userInfo.TradeParams == null)
  1658. {
  1659. time = ApplicationParameter.LockSreenTime;
  1660. }
  1661. else
  1662. {
  1663. time = userInfo.TradeParams.LockScreenTime;
  1664. }
  1665. if (_dispatcherTimer != null)
  1666. {
  1667. _dispatcherTimer.Stop();
  1668. }
  1669. // 目前暂时不显示锁屏
  1670. time = 0;
  1671. if (time > 0 && UserManager.IsAccountLogin) ////配置了时间才进行锁屏
  1672. {
  1673. _dispatcherTimer = new DispatcherTimer();
  1674. _dispatcherTimer.Tick += _dispatcherTimer_Tick;
  1675. int i = 100;
  1676. _dispatcherTimer.Interval = new TimeSpan(0, 0, i);
  1677. _dispatcherTimer.Start();
  1678. }
  1679. }
  1680. private string _password;
  1681. /// <summary>
  1682. /// 密码
  1683. /// </summary>
  1684. public string Password
  1685. {
  1686. get { return _password; }
  1687. set { Set(() => Password, ref _password, value); }
  1688. }
  1689. private string _errorMsg;
  1690. /// <summary>
  1691. /// 错误消息
  1692. /// </summary>
  1693. public string ErrorMsg
  1694. {
  1695. get { return _errorMsg; }
  1696. set { Set(() => ErrorMsg, ref _errorMsg, value); }
  1697. }
  1698. private void _dispatcherTimer_Tick(object sender, EventArgs e)
  1699. {
  1700. var userInfo = UserManager.GetCurrentUserInfo(); ////交易菜单设置
  1701. int time = 0;
  1702. if (userInfo.TradeParams == null)
  1703. {
  1704. time = ApplicationParameter.LockSreenTime;
  1705. }
  1706. else
  1707. {
  1708. time = userInfo.TradeParams.LockScreenTime;
  1709. }
  1710. var LastInputTime = GetLastInputInfoHelper.GetLastInputTime();
  1711. if (LastInputTime >= time)
  1712. {
  1713. #if DEBUG
  1714. Console.WriteLine("时间:" + LastInputTime);
  1715. #endif
  1716. WindowCollection list = Application.Current.Windows;
  1717. foreach (Window w in list)
  1718. {
  1719. if (w == Application.Current.MainWindow) ////主窗口
  1720. {
  1721. ////切换到行情列表 , 其他浏览器控件
  1722. MessengerHelper.DefaultSend(TabContetMode.QuoteList, MessengerTokens.MainContentChange);
  1723. }
  1724. else
  1725. {
  1726. w.Close(); ////关其他窗口
  1727. }
  1728. }
  1729. _dispatcherTimer.Stop();
  1730. IsLockScreen = true; ////显示锁屏
  1731. MessengerHelper.DefaultSend(false, MessengerTokens.LockScreenSetHideExpandTradeToken);
  1732. //var lockScreen=new LockScreenWin(){Owner = Application.Current.MainWindow,WindowStartupLocation =WindowStartupLocation.CenterOwner };
  1733. //lockScreen.ShowDialog();
  1734. }
  1735. }
  1736. public RelayCommand UnLockCommand
  1737. {
  1738. get
  1739. {
  1740. return new RelayCommand(() =>
  1741. {
  1742. if (Vailed())
  1743. {
  1744. ErrorMsg = string.Empty;
  1745. var password = EncryptHelper.SHA256(UserManager.CurrentTradeAccount.LoginID.ToString() + Password).ToLower();
  1746. if (password.Equals(UserManager.CurrentTradeAccount.Md5Password))
  1747. {
  1748. IsLockScreen = false;
  1749. Password = string.Empty;
  1750. if (_dispatcherTimer == null)
  1751. {
  1752. if (ApplicationParameter.LockSreenTime > 0 && UserManager.IsAccountLogin) ////配置了时间才进行锁屏
  1753. {
  1754. _dispatcherTimer = new DispatcherTimer();
  1755. _dispatcherTimer.Tick += _dispatcherTimer_Tick;
  1756. int i = 100;
  1757. _dispatcherTimer.Interval = new TimeSpan(0, 0, i);
  1758. _dispatcherTimer.Start();
  1759. }
  1760. }
  1761. else
  1762. {
  1763. _dispatcherTimer.Start();
  1764. }
  1765. MessengerHelper.DefaultSend(true, MessengerTokens.LockScreenSetHideExpandTradeToken);
  1766. }
  1767. else
  1768. {
  1769. //ErrorMsg = Client_Resource.Lock_loginpasswordError;
  1770. MessageBoxHelper.ShowInfo(Client_Resource.Lock_loginpasswordError, Client_Resource.UI2014_Tips, true);
  1771. }
  1772. }
  1773. });
  1774. }
  1775. }
  1776. public RelayCommand LoginOutCommand
  1777. {
  1778. get
  1779. {
  1780. return new RelayCommand(() =>
  1781. {
  1782. this.OnClose();
  1783. });
  1784. }
  1785. }
  1786. private bool Vailed()
  1787. {
  1788. if (string.IsNullOrWhiteSpace(Password) || Password.Length < 6)
  1789. {
  1790. MessageBoxHelper.ShowInfo(Client_Resource.UI2014_AccountNotLessThan6Characters, Client_Resource.UI2014_Tips, true);
  1791. return false;
  1792. }
  1793. return true;
  1794. }
  1795. #endregion
  1796. #endregion
  1797. }
  1798. }