Home.xaml.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. using GalaSoft.MvvmLight.Ioc;
  2. using GalaSoft.MvvmLight.Messaging;
  3. using Muchinfo.MTPClient.Resources;
  4. using Muchinfo.PC.Common.Helpers;
  5. using Muchinfo.MTPClient.Data.Enums;
  6. using Muchinfo.MTPClient.Data.Model.Account;
  7. using Muchinfo.MTPClient.Infrastructure.MessengerArgs;
  8. using Muchinfo.MTPClient.Infrastructure.Utilities;
  9. using Muchinfo.MTPClient.UI.Utilities;
  10. using Muchinfo.MTPClient.UI.ViewModels;
  11. using Muchinfo.WPF.Controls.Windows;
  12. using System;
  13. using System.Linq;
  14. using System.Windows;
  15. using System.Windows.Input;
  16. using System.Windows.Threading;
  17. namespace Muchinfo.MTPClient.UI.Views
  18. {
  19. /// <summary>
  20. /// Window1.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class Home : Window
  23. {
  24. private DispatcherTimer dTimer;
  25. private const int c_AccountIndex = 8;
  26. private MenuCommandType _currentLayoutType = MenuCommandType.Horizontal;
  27. private Style windowMaxImageStyle;
  28. private Style windowImageStyle;
  29. private int loginIndex = 0;
  30. //private WarningMessageView _warningMessageView;
  31. ///// <summary>
  32. ///// 预警接口
  33. ///// </summary>
  34. //private IWarningService _warningService;
  35. public Home()
  36. {
  37. InitializeComponent();
  38. new WindowResizer(this,
  39. new WindowBorder(BorderPosition.TopLeft, TopLeftBorder),
  40. new WindowBorder(BorderPosition.Top, TopBorder),
  41. new WindowBorder(BorderPosition.TopRight, TopRightBorder),
  42. new WindowBorder(BorderPosition.Right, RightBorder),
  43. new WindowBorder(BorderPosition.BottomRight, BottomRightBorder),
  44. new WindowBorder(BorderPosition.Bottom, BottomBorder),
  45. new WindowBorder(BorderPosition.BottomLeft, BottomLeftBorder),
  46. new WindowBorder(BorderPosition.Left, LeftBorder));
  47. //避免窗口最大化时遮盖任务栏
  48. FullScreenManager.RepairWpfWindowFullScreenBehavior(this);
  49. this.SizeChanged += Home_SizeChanged;
  50. // MessageRegister.Register(this);
  51. RegisterLogout();
  52. this.Loaded += Home_Loaded;
  53. SetChartTabItem();
  54. windowMaxImageStyle = ResourceHelper.GetFromeResource<Style>("WindowMaxImageStyle");
  55. windowImageStyle = ResourceHelper.GetFromeResource<Style>("WindowMaxImageStyle1");
  56. ////订阅行情
  57. Messenger.Default.Send(string.Empty, MessengerTokens.QuoteSubscribe);
  58. }
  59. void Home_Loaded(object sender, RoutedEventArgs e)
  60. {
  61. //todo: uncomment
  62. //if (ApplicationParameter.IsShowLockSreenTime == 1)
  63. //{
  64. // dTimer = new DispatcherTimer();
  65. // dTimer.Tick += new EventHandler(DispatcherTimer_Tick);
  66. // int i = 100;
  67. // if (dTimer.Interval != null)
  68. // {
  69. // dTimer.Interval = new TimeSpan(0, 0, i);
  70. // dTimer.Start();
  71. // }
  72. //}
  73. }
  74. private void Home_SizeChanged(object sender, SizeChangedEventArgs e)
  75. {
  76. MaxImageButton.Style = WindowState == WindowState.Maximized ? windowMaxImageStyle : windowImageStyle;
  77. }
  78. #region 窗口操作
  79. private void Window_MouseDown(object sender, MouseButtonEventArgs e)
  80. {
  81. if (e.LeftButton == MouseButtonState.Pressed)
  82. {
  83. DragMove();
  84. }
  85. if (e.ClickCount == 2)
  86. {
  87. this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  88. }
  89. }
  90. private void WinMin_OnClick(object sender, RoutedEventArgs e)
  91. {
  92. this.WindowState = WindowState.Minimized;
  93. }
  94. private void WinMax_OnClick(object sender, RoutedEventArgs e)
  95. {
  96. this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  97. }
  98. private void WinClose_OnClick(object sender, RoutedEventArgs e)
  99. {
  100. var messageResult = MessageBoxHelper.ShowQuestion(this, Muchinfo_Resource.UI2014_IsOrNotExit, Muchinfo_Resource.UI2014_Tips);
  101. if (messageResult == MessageBoxResult.Yes)
  102. {
  103. this.Close();
  104. }
  105. }
  106. private void RegisterLogout()
  107. {
  108. Messenger.Default.Register<TradeAccount>(this, MessengerTokens.TradeAccountSignOut, (e) =>
  109. {
  110. if (this.LayoutGird == null) return;
  111. UserManager.TradeAccountLogout(e);
  112. bool flag = UserManager.TradeAccounts.Any();
  113. if (!flag) //没有已登录的账户
  114. {
  115. // this.LayoutGird.InvalidateArrange();
  116. var loginWindow = new LoginView();
  117. this.Hide();
  118. Application.Current.MainWindow = loginWindow;
  119. this.Close();
  120. //todo:清理链路等.
  121. loginWindow.Show();
  122. }
  123. else
  124. {
  125. UserManager.CurrentTradeAccount = UserManager.TradeAccounts[0];
  126. }
  127. });
  128. }
  129. #endregion
  130. /// <summary>
  131. /// 设置图表项选择
  132. /// </summary>
  133. private void SetChartTabItem()
  134. {
  135. Messenger.Default.Register<OpenQuoteChartWindowArg>(this, MessengerTokens.OpenQuoteChartWindow, (args) =>
  136. {
  137. // this.CandelstickRadioButton.IsChecked = true;
  138. Messenger.Default.Send<MenuCommandType>(MenuCommandType.CandleChart, MessengerTokens.UpdateCurrentMarketType);
  139. });
  140. }
  141. /// <summary>
  142. /// 长时间不操作登出保护
  143. /// </summary>
  144. public InputTradePassWordView TradePassWordView;
  145. private void DispatcherTimer_Tick(object sender, EventArgs e)
  146. {
  147. var homeViewModel = SimpleIoc.Default.GetInstance<HomeViewModel>();
  148. //判断鼠标键盘有多少时间不动了
  149. var lastInputTime = InputHelper.GetLastInputTime();
  150. if (lastInputTime > ApplicationParameter.LockSreenTime)
  151. {
  152. WindowCollection list = Application.Current.Windows;
  153. foreach (Window w in list)
  154. {
  155. if (w.Owner == null)
  156. {
  157. homeViewModel.MainPanelVisibility = Visibility.Visible;
  158. }
  159. else
  160. {
  161. w.WindowState = WindowState.Minimized;
  162. w.Opacity = 0;
  163. }
  164. }
  165. //判断解锁窗口不能重复打开
  166. if (TradePassWordView == null || TradePassWordView.IsVisible == false)
  167. {
  168. TradePassWordView = new InputTradePassWordView();
  169. TradePassWordView.Owner = System.Windows.Application.Current.MainWindow;
  170. TradePassWordView.ShowDialog();
  171. }
  172. }
  173. }
  174. private void ListButton_OnClick(object sender, RoutedEventArgs e)
  175. {
  176. try
  177. {
  178. loginIndex = loginIndex + 1;
  179. if (loginIndex == 1)
  180. {
  181. if (ApplicationParameter.ShowListing == 1)
  182. {
  183. if (!string.IsNullOrEmpty(ApplicationParameter.ListingUrl))
  184. {
  185. //WebKitBrowser wb = new WebKitBrowser();
  186. //wb.Navigate(ApplicationParameter.ListingUrl + "/?UserName=" +
  187. // UserManager.CurrentTradeAccount.LoginCode +
  188. // "&Password=" + UserManager.CurrentTradeAccount.Md5Password);
  189. //wb.IsWebBrowserContextMenuEnabled = false;
  190. //ListingContentControl.Child = wb;
  191. }
  192. }
  193. }
  194. }
  195. catch (Exception ex)
  196. {
  197. //ErrorManager.ShowReturnError(this, ExceptionManager.WebKitNotSupportError, Muchinfo_Resource.APP_Tips);
  198. MessageBoxHelper.ShowInfo(Muchinfo_Resource.OpenListingError, Muchinfo_Resource.APP_Tips);
  199. LogHelper.WriteError(typeof(Home), ex.ToString());
  200. }
  201. }
  202. }
  203. }