| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- using System.Windows.Media.Animation;
- using Muchinfo.MTPClient.Data.DTO;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.Interfaces;
- using Muchinfo.MTPClient.Quotation.ViewModels;
- using Muchinfo.PC.Common.Helpers;
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using Muchinfo.MTPClient.Infrastructure.Cache;
- using System.Linq;
- using Muchinfo.MTPClient.IService;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- namespace Muchinfo.MTPClient.Quotation.Views
- {
- /// <summary>
- /// QuoteBoardView.xaml 的交互逻辑
- /// </summary>
- public partial class QuoteBoardView : UserControl, IDisposable, IQuoteView
- {
- #region Fields
- private const double Const_ScrollWidth = 60d;
- private MenuCommandType _currentType;
- private string _additionalInfo;
- private MarketsInfoModel _goodsGroup;
- private ISystemService _systemService;
- private ScrollViewer _datagridScrollViewer; //当前行情DataGrid滚动条
- #endregion
- #region Properties
- private QuoteBoardViewModel ViewModel
- {
- get
- {
- return this.DataContext as QuoteBoardViewModel;
- }
- }
- public ScrollViewer DataGridScrollViewer
- {
- get
- {
- if (_datagridScrollViewer != null)
- {
- return _datagridScrollViewer;
- }
- _datagridScrollViewer = WPFVisualTreeHelper.FindVisualChild<ScrollViewer>(this.QuoteListBox);
- return _datagridScrollViewer;
- }
- }
- #endregion
- #region Constructors
- public QuoteBoardView(MenuCommandType commandType, MarketsInfoModel additionalInfo)
- {
- InitializeComponent();
- _systemService = SimpleIoc.Default.GetInstance<ISystemService>();
- this.DataContext = new QuoteBoardViewModel();
- RefreshList(commandType, additionalInfo);
- _goodsGroup = additionalInfo;
- this.QuoteListBox.PreviewMouseWheel += QuoteListBox_PreviewMouseWheel;
- this.QuoteListBox.SelectionChanged += QuoteListBox_SelectionChanged;
- this.QuoteListBox.KeyUp += QuoteListBox_KeyUp;
- MessengerHelper.DefaultRegister<QuoteGoods>(this, MessengerTokens.QuoteBoardSelectItemChange, (goods) =>
- {
- if (QuoteListBox == null) return;
- QuoteListBox.SelectedItem = goods;
- });
- MessengerHelper.DefaultRegister<string>(this, MessengerTokens.RefreshGoodsToken, (msg) =>
- {
- Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- RefreshList(_currentType, _goodsGroup);
- }));
- });
- this.Unloaded += QuoteBoardView_Unloaded;
- if (!IsDeliveryVisible)
- {
- this.PAndXGoodsInfoDataGrid.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
-
- }
- }
- /// <summary>
- /// 删除注册内容
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void QuoteBoardView_Unloaded(object sender, RoutedEventArgs e)
- {
- //MessengerHelper.DefaultUnregister(MessengerTokens.RefreshGoodsToken);
- //MessengerHelper.DefaultUnregister(MessengerTokens.RegisterResourceChange);
- //MessengerHelper.DefaultUnregister(MessengerTokens.QuoteBoardSelectItemChange);
- //Dispose();
- }
- #endregion
- #region Event Handlers
- /// <summary>
- /// Handles the KeyUp event of the QuoteListBox control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
- private void QuoteListBox_KeyUp(object sender, KeyEventArgs e)
- {
- if (e.Key == Key.Left)
- {
- if (DataGridScrollViewer == null) return;
- DataGridScrollViewer.ScrollToHorizontalOffset(DataGridScrollViewer.HorizontalOffset - Const_ScrollWidth);
- e.Handled = true;
- }
- else if (e.Key == Key.Right)
- {
- if (DataGridScrollViewer == null) return;
- DataGridScrollViewer.ScrollToHorizontalOffset(DataGridScrollViewer.HorizontalOffset + Const_ScrollWidth);
- e.Handled = true;
- }
- }
- /// <summary>
- /// Handles the SelectionChanged event of the QuoteListBox control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
- private void QuoteListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (e.AddedItems != null && e.AddedItems.Count > 0)
- {
- var quoteGoods = e.AddedItems[0] as QuoteGoodsDTO;
- if (quoteGoods != null)
- {
- MessengerHelper.DefaultSend<QuoteGoodsDTO>(quoteGoods, MessengerTokens.SelectGoodsChange);
- if (ViewModel != null)
- {
- ViewModel.SelectGoodsOfPAndX_ItemSource(quoteGoods);
- if (ViewModel.GoodsOfPandXInfoList != null)
- {
- var fistGoods = ViewModel.GoodsOfPandXInfoList.FirstOrDefault();
- if (fistGoods != null)
- {
- var group = CacheManager.CacheMarketsGroups.FirstOrDefault(
- (item) => item.MarketID == fistGoods.GoodsGroupId);
- BuildDeliveryDataGridColumns(group);
- }
- }
- }
- }
- }
- }
- #region 交割行情列表
- private void BuildDeliveryDataGridColumns(MarketsInfoModel goosGroup)
- {
- var type = GetQuoteListHeaderTypeByeMarket(goosGroup);
- var headerList = _systemService.GetDeliveryQuoteListHeaders(type);
- var quoteListHeaders = (headerList == null) ? null : headerList.ToList();
- if (quoteListHeaders == null || !quoteListHeaders.Any()) return;
- ////根据QuoteListHeader集合创建行情DataGrid列集合
- var columns = QuoteDataGridHelper.CreateQuoteDataGridColumns(quoteListHeaders);
- if (columns == null || !columns.Any()) return;
- ////清除所有列
- PAndXGoodsInfoDataGrid.Columns.Clear();
- ////添加列
- foreach (var column in columns)
- {
- PAndXGoodsInfoDataGrid.Columns.Add(column);
- }
- }
- #endregion
- /// <summary>
- /// 根据市场获取列头
- /// </summary>
- /// <param name="goodsGroup">The goods group.</param>
- /// <returns>MarketType.</returns>
- private eTradeMode GetQuoteListHeaderTypeByeMarket(MarketsInfoModel goodsGroup)
- {
- if (goodsGroup == null)
- {
- return eTradeMode.TRADEMODE_MARKETMAKE;
- }
- return goodsGroup.TradeMode;
- }
- /// <summary>
- /// Handles the PreviewMouseWheel event of the QuoteListBox control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="MouseWheelEventArgs"/> instance containing the event data.</param>
- private void QuoteListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
- {
- if (e.Delta > 0)
- {
- DataGridScrollViewer.PageUp();
- }
- if (e.Delta < 0)
- {
- DataGridScrollViewer.PageDown();
- }
- e.Handled = true;
- }
- #endregion
- #region IDispose
- /// <summary>
- /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
- /// </summary>
- public void Dispose()
- {
- MessengerHelper.DefaultUnregister(this);
- if (ViewModel != null) ViewModel.Cleanup();
- if (QuoteListBox != null)
- {
- this.QuoteListBox.PreviewMouseWheel -= QuoteListBox_PreviewMouseWheel;
- this.QuoteListBox.SelectionChanged -= QuoteListBox_SelectionChanged;
- this.QuoteListBox.KeyUp -= QuoteListBox_KeyUp;
- QuoteListBox.Resources.Clear();
- QuoteListBox = null;
- }
- this.Resources.Clear();
- GC.Collect();
- }
- #endregion
- #region IQuoteView
- /// <summary>
- /// 选中商品
- /// </summary>
- /// <value>The selected item.</value>
- /// <exception cref="System.NotImplementedException">
- /// </exception>
- public QuoteGoods SelectedItem
- {
- get
- {
- return QuoteListBox.SelectedItem as QuoteGoods;
- }
- }
- /// <summary>
- /// 第一个商品
- /// </summary>
- /// <value>The first quote goods.</value>
- /// <exception cref="System.NotImplementedException">
- /// </exception>
- public QuoteGoods FirstQuoteGoods
- {
- get
- {
- if (QuoteListBox.Items.Count == 0) return null;
- return QuoteListBox.Items[0] as QuoteGoods;
- }
- }
- /// <summary>
- /// 更新列表数据
- /// </summary>
- /// <param name="newType">The new type.</param>
- /// <param name="goodsGroup">The goods group.</param>
- public void RefreshList(MenuCommandType newType, MarketsInfoModel goodsGroup)
- {
- _currentType = newType;
- _goodsGroup = goodsGroup;
- if (ViewModel != null)
- {
- ViewModel.RefreshList(_currentType, _goodsGroup);
- }
- QuoteListBox.SelectedIndex = 0;
- }
- #endregion
- private void DecimalUpDown_KeyDown(object sender, KeyEventArgs e)
- {
- //屏蔽非法字符
- if ((e.Key >= Key.NumPad0 && e.Key <= Key.NumPad9) || (e.Key >= Key.D0 && e.Key <= Key.D9))
- {
- e.Handled = false;
- }
- else
- {
- e.Handled = true;
- }
- }
- public bool IsDeliveryVisible
- {
- get
- {
- return ApplicationParameter.IsDeliveryVisible == 1 && UserManager.IsAccountLogin;
- }
- }
- }
- }
|