HomeViewModel.cs 75 KB

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