| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Controls.Primitives;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Infrastructure.Helpers;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.MTPClient.Sale.ViewModels;
- using Muchinfo.MTPClient.Service.Utilities;
- using Muchinfo.PC.Common.Helpers;
- namespace Muchinfo.MTPClient.Sale.Views
- {
- /// <summary>
- /// DepositPlanView.xaml 的交互逻辑
- /// </summary>
- public partial class DepositPlanView : UserControl
- {
-
- public EventHandler ScrollButtonClicked;
- #region Private Fields
- private const double Const_ScrollWidth = 60d;
- private ScrollViewer _datagridScrollViewer; //当前DataGrid滚动条
- private ISystemService _systemService;
- #endregion
- #region Public Properties
- /// <summary>
- /// Gets or sets the current data grid.
- /// </summary>
- /// <value>The current data grid.</value>
- public WPF.Controls.DataGrid.MuchinfoDataGrid CurrentDataGrid
- {
- get;
- set;
- }
- /// <summary>
- /// 获取当前理财DataGrid的滚动条
- /// </summary>
- public ScrollViewer DataGridScrollViewer
- {
- get
- {
- if (_datagridScrollViewer != null)
- {
- return _datagridScrollViewer;
- }
- _datagridScrollViewer = WPFVisualTreeHelper.FindVisualChild<ScrollViewer>(this.DepositDataGrid);
- return _datagridScrollViewer;
- }
- }
- #endregion
- #region Dependency Properties
- /// <summary>
- /// 是否显示左右滚动条
- /// </summary>
- public Visibility ScrollVisibility
- {
- get { return (Visibility)GetValue(ScrollVisibilityProperty); }
- set { SetValue(ScrollVisibilityProperty, value); }
- }
- // Using a DependencyProperty as the backing store for ScrollVisibility. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty ScrollVisibilityProperty = DependencyProperty.Register("ScrollVisibility", typeof(Visibility), typeof(DepositPlanView), new PropertyMetadata(Visibility.Collapsed));
- #endregion
- #region Public Methods
- /// <summary>
- /// Initializes a new instance of the <see cref=" "/> class.
- /// </summary>
- public DepositPlanView()
- {
- InitializeComponent();
- _systemService = SimpleIoc.Default.GetInstance<ISystemService>();
- this.DataContext = new DepositPlanViewModel();
- BuildDataGridColumns();
- CurrentDataGrid = this.DepositDataGrid;
- RegisterDataGridEvents();
- }
- /// <summary>
- /// 执行与释放或重置非托管资源相关的应用程序定义的任务。
- /// </summary>
- public void Dispose()
- {
-
- MessengerHelper.DefaultUnregister(this);
- var viewModel = this.DataContext as QuerySaleGoodsViewModel;
- if (viewModel != null)
- {
- viewModel.Cleanup();
- if (_datagridScrollViewer != null)
- {
- _datagridScrollViewer.Resources.Clear();
- _datagridScrollViewer = null;
- }
- }
- this.Resources.Clear();
- GC.Collect();
- }
- #endregion
- #region Private Methods
- /// <summary>
- /// Registers the data grid events.
- /// </summary>
- private void RegisterDataGridEvents()
- {
- this.DepositDataGrid.LayoutUpdated += (s, e) =>
- {
- OnScrollButtonClicked(null);
- if (DataGridScrollViewer == null) return;
- var canScroll = DataGridScrollViewer.ScrollableWidth == 0;
- ScrollVisibility = canScroll ? Visibility.Collapsed : Visibility.Visible;
- };
-
-
- this.Unloaded += QuerySaleGoodsView_Unloaded;
- }
- private void BuildDataGridColumns()
- {
- var headerList = _systemService.GetQuoteListHeaders(eTradeMode.Deposit);
- 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;
- ////清除所有列
- DepositDataGrid.Columns.Clear();
- ////添加列
- foreach (var column in columns)
- {
- DepositDataGrid.Columns.Add(column);
- }
- ////添加操作按钮列
- var operationStackPanel = new StackPanel()
- {
- HorizontalAlignment = HorizontalAlignment.Stretch
- };
- operationStackPanel.Children.Add(new TextBlock() { Text = Client_Resource.Content_Operation, HorizontalAlignment = HorizontalAlignment.Center });
- var operationDataTemplate = this.Resources["OperationDataTemplate"] as DataTemplate;
- var operationColumn = new QuoteDataGridTemplateColumn()
- {
- ////QuoteListHeader设为空,不保存此列
- QuoteListHeader = null,
- Header = operationStackPanel,
- Visibility = Visibility.Visible,
- CellTemplate = operationDataTemplate,
- Width = new DataGridLength(1, DataGridLengthUnitType.Auto),
- };
- DepositDataGrid.Columns.Add(operationColumn);
- }
-
- /// <summary>
- /// 滚动按钮滚动时
- /// </summary>
- /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
- private void OnScrollButtonClicked(EventArgs e)
- {
- if (ScrollButtonClicked != null)
- {
- ScrollButtonClicked(null, e);
- }
- }
-
- #region Route Events
- /// <summary>
- /// Handles the Unloaded event of the QuerySaleGoodsView control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
- private void QuerySaleGoodsView_Unloaded(object sender, RoutedEventArgs e)
- {
- // Dispose();
- }
- /// <summary>
- /// Handles the OnKeyDown event of the SaleDataGrid 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 DepositDataGrid_OnKeyDown(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 OnPreviewMouseWheel event of the SaleDataGrid 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 DepositDataGrid_OnPreviewMouseWheel(object sender, MouseWheelEventArgs e)
- {
- if (e.Delta > 0)
- {
- DataGridScrollViewer.PageUp();
- }
- if (e.Delta < 0)
- {
- DataGridScrollViewer.PageDown();
- }
- e.Handled = true;
- }
- /// <summary>
- /// Handles the OnMouseRightButtonDown event of the SaleDataGrid control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="MouseButtonEventArgs"/> instance containing the event data.</param>
- private void DepositDataGrid_OnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- var obj = e.OriginalSource as DependencyObject;
- while (obj != null && !(obj is DataGridColumnHeader))
- {
- obj = VisualTreeHelper.GetParent(obj);
- }
- var header = obj as DataGridColumnHeader;
- if (header != null)
- {
- ////注释掉表头左键菜单,使用统一菜单
- ////header.ContextMenu = _headerContextMenu;
- //var item = QuoteListDataGrid.SelectedItem as QuoteGoodsDTO;
- //if (item == null) return;
- //BuildContextMenu(item);
- }
- else
- {
- var rowContextMenu = new ContextMenu();
- var menuItemStyle = ResourceHelper.GetFromeResource<Style>("ContextCommonMenuItem");
- var row = e.OriginalSource as DependencyObject;
- while (row != null && !(row is DataGridRow))
- {
- row = VisualTreeHelper.GetParent(row);
- }
- var dataRow = row as DataGridRow;
- if (dataRow != null)
- {
- var menuItemApply = new MenuItem()
- {
- Header = Client_Resource.Resources_Service_DepositOrder,
- Tag = ContextMenuCommandType.DepositApply,
- // DataContext = menuItemApply,
- //Margin = new Thickness(0, 3, 0, 3),
- Style = menuItemStyle,
- };
-
- menuItemApply.Click += RefreshGoodsList_Click;
-
- var plane = dataRow.DataContext as DepositPlan;
- if (plane != null)
- {
- menuItemApply.IsEnabled = UserManager.IsAccountLogin && plane.IsDepositApply;
- }
- rowContextMenu.Items.Add(menuItemApply);
- }
-
- var menuItem = new MenuItem()
- {
- Header = ContextMenuNames.RefreshGoodsList,
- Tag = ContextMenuCommandType.RefreshGoodsList,
- //DataContext = item,
- Style = menuItemStyle,
- };
-
- menuItem.Click += RefreshGoodsList_Click;
- menuItem.IsEnabled = UserManager.IsAccountLogin; ////只有账号登录了才有效
- rowContextMenu.Items.Add(menuItem);
- this.DepositDataGrid.ContextMenu = rowContextMenu;
- //}
- //else
- //{
- // ////在DataGrid外点击右键,取消右键菜单
- // this.SaleDataGrid.ContextMenu = null;
- //}
- }
- }
- /// <summary>
- /// Handles the Click event of the RefreshGoodsList control.
- /// </summary>
- /// <param name="sender">The source of the event.</param>
- /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
- private void RefreshGoodsList_Click(object sender, RoutedEventArgs e)
- {
- var menuItem = sender as MenuItem;
- if (menuItem == null) return;
- var commandType = (ContextMenuCommandType)menuItem.Tag;
- var viewModel = this.DataContext as DepositPlanViewModel;
- switch (commandType)
- {
- case ContextMenuCommandType.RefreshGoodsList:
- ////刷新商品列表
- if (viewModel != null)
- {
- viewModel.SelectCommand.Execute(null);
- }
- break;
- case ContextMenuCommandType.DepositApply:
- if (viewModel != null)
- {
- viewModel.DetailCommand.Execute(null);
- }
- break;
- }
- }
- #endregion
- #endregion
- }
- }
|