| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- using GalaSoft.MvvmLight.Ioc;
- using GalaSoft.MvvmLight.Messaging;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.PC.Common.Helpers;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model.Account;
- using Muchinfo.MTPClient.Infrastructure.MessengerArgs;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.UI.Utilities;
- using Muchinfo.MTPClient.UI.ViewModels;
- using Muchinfo.WPF.Controls.Windows;
- using System;
- using System.Linq;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace Muchinfo.MTPClient.UI.Views
- {
- /// <summary>
- /// Window1.xaml 的交互逻辑
- /// </summary>
- public partial class Home : Window
- {
- private DispatcherTimer dTimer;
- private const int c_AccountIndex = 8;
- private MenuCommandType _currentLayoutType = MenuCommandType.Horizontal;
- private Style windowMaxImageStyle;
- private Style windowImageStyle;
- private int loginIndex = 0;
- //private WarningMessageView _warningMessageView;
- ///// <summary>
- ///// 预警接口
- ///// </summary>
- //private IWarningService _warningService;
- public Home()
- {
- InitializeComponent();
- new WindowResizer(this,
- new WindowBorder(BorderPosition.TopLeft, TopLeftBorder),
- new WindowBorder(BorderPosition.Top, TopBorder),
- new WindowBorder(BorderPosition.TopRight, TopRightBorder),
- new WindowBorder(BorderPosition.Right, RightBorder),
- new WindowBorder(BorderPosition.BottomRight, BottomRightBorder),
- new WindowBorder(BorderPosition.Bottom, BottomBorder),
- new WindowBorder(BorderPosition.BottomLeft, BottomLeftBorder),
- new WindowBorder(BorderPosition.Left, LeftBorder));
- //避免窗口最大化时遮盖任务栏
- FullScreenManager.RepairWpfWindowFullScreenBehavior(this);
- this.SizeChanged += Home_SizeChanged;
- // MessageRegister.Register(this);
- RegisterLogout();
- this.Loaded += Home_Loaded;
- SetChartTabItem();
- windowMaxImageStyle = ResourceHelper.GetFromeResource<Style>("WindowMaxImageStyle");
- windowImageStyle = ResourceHelper.GetFromeResource<Style>("WindowMaxImageStyle1");
- ////订阅行情
- Messenger.Default.Send(string.Empty, MessengerTokens.QuoteSubscribe);
- }
- void Home_Loaded(object sender, RoutedEventArgs e)
- {
- //todo: uncomment
- //if (ApplicationParameter.IsShowLockSreenTime == 1)
- //{
- // dTimer = new DispatcherTimer();
- // dTimer.Tick += new EventHandler(DispatcherTimer_Tick);
- // int i = 100;
- // if (dTimer.Interval != null)
- // {
- // dTimer.Interval = new TimeSpan(0, 0, i);
- // dTimer.Start();
- // }
- //}
- }
- private void Home_SizeChanged(object sender, SizeChangedEventArgs e)
- {
- MaxImageButton.Style = WindowState == WindowState.Maximized ? windowMaxImageStyle : windowImageStyle;
- }
- #region 窗口操作
- private void Window_MouseDown(object sender, MouseButtonEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- DragMove();
- }
- if (e.ClickCount == 2)
- {
- this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
- }
- }
- private void WinMin_OnClick(object sender, RoutedEventArgs e)
- {
- this.WindowState = WindowState.Minimized;
- }
- private void WinMax_OnClick(object sender, RoutedEventArgs e)
- {
- this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
- }
- private void WinClose_OnClick(object sender, RoutedEventArgs e)
- {
- var messageResult = MessageBoxHelper.ShowQuestion(this, Muchinfo_Resource.UI2014_IsOrNotExit, Muchinfo_Resource.UI2014_Tips);
- if (messageResult == MessageBoxResult.Yes)
- {
- this.Close();
- }
- }
- private void RegisterLogout()
- {
- Messenger.Default.Register<TradeAccount>(this, MessengerTokens.TradeAccountSignOut, (e) =>
- {
- if (this.LayoutGird == null) return;
- UserManager.TradeAccountLogout(e);
- bool flag = UserManager.TradeAccounts.Any();
- if (!flag) //没有已登录的账户
- {
- // this.LayoutGird.InvalidateArrange();
- var loginWindow = new LoginView();
- this.Hide();
- Application.Current.MainWindow = loginWindow;
- this.Close();
- //todo:清理链路等.
- loginWindow.Show();
- }
- else
- {
- UserManager.CurrentTradeAccount = UserManager.TradeAccounts[0];
- }
- });
- }
- #endregion
- /// <summary>
- /// 设置图表项选择
- /// </summary>
- private void SetChartTabItem()
- {
- Messenger.Default.Register<OpenQuoteChartWindowArg>(this, MessengerTokens.OpenQuoteChartWindow, (args) =>
- {
- // this.CandelstickRadioButton.IsChecked = true;
- Messenger.Default.Send<MenuCommandType>(MenuCommandType.CandleChart, MessengerTokens.UpdateCurrentMarketType);
- });
- }
- /// <summary>
- /// 长时间不操作登出保护
- /// </summary>
- public InputTradePassWordView TradePassWordView;
- private void DispatcherTimer_Tick(object sender, EventArgs e)
- {
- var homeViewModel = SimpleIoc.Default.GetInstance<HomeViewModel>();
- //判断鼠标键盘有多少时间不动了
- var lastInputTime = InputHelper.GetLastInputTime();
- if (lastInputTime > ApplicationParameter.LockSreenTime)
- {
- WindowCollection list = Application.Current.Windows;
- foreach (Window w in list)
- {
- if (w.Owner == null)
- {
- homeViewModel.MainPanelVisibility = Visibility.Visible;
- }
- else
- {
- w.WindowState = WindowState.Minimized;
- w.Opacity = 0;
- }
- }
- //判断解锁窗口不能重复打开
- if (TradePassWordView == null || TradePassWordView.IsVisible == false)
- {
- TradePassWordView = new InputTradePassWordView();
- TradePassWordView.Owner = System.Windows.Application.Current.MainWindow;
- TradePassWordView.ShowDialog();
- }
- }
- }
- private void ListButton_OnClick(object sender, RoutedEventArgs e)
- {
- try
- {
- loginIndex = loginIndex + 1;
- if (loginIndex == 1)
- {
- if (ApplicationParameter.ShowListing == 1)
- {
- if (!string.IsNullOrEmpty(ApplicationParameter.ListingUrl))
- {
- //WebKitBrowser wb = new WebKitBrowser();
- //wb.Navigate(ApplicationParameter.ListingUrl + "/?UserName=" +
- // UserManager.CurrentTradeAccount.LoginCode +
- // "&Password=" + UserManager.CurrentTradeAccount.Md5Password);
- //wb.IsWebBrowserContextMenuEnabled = false;
- //ListingContentControl.Child = wb;
- }
- }
- }
- }
- catch (Exception ex)
- {
- //ErrorManager.ShowReturnError(this, ExceptionManager.WebKitNotSupportError, Muchinfo_Resource.APP_Tips);
- MessageBoxHelper.ShowInfo(Muchinfo_Resource.OpenListingError, Muchinfo_Resource.APP_Tips);
- LogHelper.WriteError(typeof(Home), ex.ToString());
- }
- }
- }
- }
|