PageRenderTime 1193ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Synchrophasor/Current Version/Source/Libraries/openPDC.UI.WPF/UserControls/OutputStreamDeviceDigitalUserControl.xaml.cs

#
C# | 123 lines | 78 code | 15 blank | 30 comment | 15 complexity | d08540969e1486e2f2b2954807a0edbb MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, EPL-1.0
  1. using System.Windows;
  2. //******************************************************************************************************
  3. // OutputStreamDeviceDigitalUserControl.cs - Gbtc
  4. //
  5. // Copyright © 2010, Grid Protection Alliance. All Rights Reserved.
  6. //
  7. // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
  8. // the NOTICE file distributed with this work for additional information regarding copyright ownership.
  9. // The GPA licenses this file to you under the Eclipse Public License -v 1.0 (the "License"); you may
  10. // not use this file except in compliance with the License. You may obtain a copy of the License at:
  11. //
  12. // http://www.opensource.org/licenses/eclipse-1.0.php
  13. //
  14. // Unless agreed to in writing, the subject software distributed under the License is distributed on an
  15. // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
  16. // License for the specific language governing permissions and limitations.
  17. //
  18. // Code Modification History:
  19. // ----------------------------------------------------------------------------------------------------
  20. // 09/14/2011 - Aniket Salver
  21. // Generated original version of source code.
  22. // 09/15/2012 - Aniket Salver
  23. // Added paging and sorting technique.
  24. //
  25. //******************************************************************************************************
  26. using System.Windows.Controls;
  27. using System.Windows.Input;
  28. using openPDC.UI.ViewModels;
  29. using System.ComponentModel;
  30. using System;
  31. namespace openPDC.UI.UserControls
  32. {
  33. /// <summary>
  34. /// Interaction logic for OutputStreamDeviceDigitalUserControl.xaml
  35. /// </summary>
  36. public partial class OutputStreamDeviceDigitalUserControl : UserControl
  37. {
  38. #region [ Members ]
  39. private OutputStreamDeviceDigitals m_dataContext;
  40. private DataGridColumn m_sortColumn;
  41. private string m_sortMemberPath;
  42. private ListSortDirection m_sortDirection;
  43. #endregion
  44. #region [ Constructor ]
  45. /// <summary>
  46. /// Creates an instance of <see cref="OutputStreamDeviceDigitalUserControl"/>
  47. /// </summary>
  48. public OutputStreamDeviceDigitalUserControl(int outputStreamDeviceID)
  49. {
  50. InitializeComponent();
  51. m_dataContext = new OutputStreamDeviceDigitals(outputStreamDeviceID, 5, true);
  52. this.DataContext = m_dataContext;
  53. m_dataContext.PropertyChanged += new PropertyChangedEventHandler(ViewModel_PropertyChanged);
  54. DataGridList.SelectionChanged += new SelectionChangedEventHandler(DataGridList_SelectionChanged);
  55. }
  56. #endregion
  57. #region [ Methods ]
  58. private void DataGridList_SelectionChanged(object sender, SelectionChangedEventArgs e)
  59. {
  60. TextBoxLabel.ScrollToHome();
  61. }
  62. private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
  63. {
  64. if (e.Key == Key.Delete)
  65. {
  66. DataGrid dataGrid = sender as DataGrid;
  67. if (dataGrid.SelectedItems.Count > 0)
  68. {
  69. if (MessageBox.Show("Are you sure you want to delete " + dataGrid.SelectedItems.Count + " selected item(s)?", "Delete Selected Items", MessageBoxButton.YesNo) == MessageBoxResult.No)
  70. e.Handled = true;
  71. }
  72. }
  73. }
  74. private void DataGrid_Sorting(object sender, DataGridSortingEventArgs e)
  75. {
  76. if (e.Column.SortMemberPath != m_sortMemberPath)
  77. m_sortDirection = ListSortDirection.Ascending;
  78. else if (m_sortDirection == ListSortDirection.Ascending)
  79. m_sortDirection = ListSortDirection.Descending;
  80. else
  81. m_sortDirection = ListSortDirection.Ascending;
  82. m_sortColumn = e.Column;
  83. m_sortMemberPath = e.Column.SortMemberPath;
  84. m_dataContext.SortData(m_sortMemberPath, m_sortDirection);
  85. }
  86. private void ViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
  87. {
  88. if (e.PropertyName == "ItemsSource")
  89. Dispatcher.BeginInvoke(new Action(SortDataGrid));
  90. }
  91. private void SortDataGrid()
  92. {
  93. if ((object)m_sortColumn != null)
  94. {
  95. m_sortColumn.SortDirection = m_sortDirection;
  96. DataGridList.Items.SortDescriptions.Clear();
  97. DataGridList.Items.SortDescriptions.Add(new SortDescription(m_sortMemberPath, m_sortDirection));
  98. DataGridList.Items.Refresh();
  99. }
  100. }
  101. private void GridDetailView_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
  102. {
  103. if (m_dataContext.IsNewRecord)
  104. DataGridList.SelectedIndex = -1;
  105. }
  106. #endregion
  107. }
  108. }