//****************************************************************************************************** // SelectMeasurements.cs - Gbtc // // Copyright © 2010, Grid Protection Alliance. All Rights Reserved. // // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See // the NOTICE file distributed with this work for additional information regarding copyright ownership. // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may // not use this file except in compliance with the License. You may obtain a copy of the License at: // // http://www.opensource.org/licenses/MIT // // Unless agreed to in writing, the subject software distributed under the License is distributed on an // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the // License for the specific language governing permissions and limitations. // // Code Modification History: // ---------------------------------------------------------------------------------------------------- // 05/17/2011 - Mehulbhai P Thakkar // Generated original version of source code. // //****************************************************************************************************** using System; using System.Collections.ObjectModel; using System.Linq; using System.Windows; using System.Windows.Input; using GSF.TimeSeries.Transport.UI.DataModels; using GSF.TimeSeries.UI; using GSF.TimeSeries.UI.Commands; using DataModelMeasurement = GSF.TimeSeries.UI.DataModels.Measurement; namespace GSF.TimeSeries.Transport.UI.ViewModels { /// /// Class to hold bindable collection. /// internal class SelectMeasurements : PagedViewModelBase { #region [ Members ] // Fields private ObservableCollection m_measurements; private RelayCommand m_searchCommand; private RelayCommand m_showAllCommand; private readonly bool m_filterByInternal; private readonly bool m_includeInternal; private readonly int m_deviceID; #endregion #region [ Properties ] /// /// Gets flag that determines if is a new record. /// public override bool IsNewRecord { get { return (CurrentItem.SignalID == null || CurrentItem.SignalID == Guid.Empty); } } /// /// Gets to search within measurements. /// public ICommand SearchCommand { get { if (m_searchCommand == null) m_searchCommand = new RelayCommand(Search, (param) => true); return m_searchCommand; } } /// /// Gets to show all measurements. /// public ICommand ShowAllCommand { get { if (m_showAllCommand == null) m_showAllCommand = new RelayCommand(ShowAll); return m_showAllCommand; } } #endregion #region [ Constructors ] /// /// Creates an instance of class. /// /// Number of items to display on a page. /// Boolean indicator to save data automatically. /// Boolean indicator to determine if only measurements with internal flag set to true needs to be displayed. /// ID of the device to filter data. /// Flag to determine if internal measurements should be included. public SelectMeasurements(int itemsPerPage, bool autosave = true, bool filterByInternal = false, int deviceID = 0, bool includeInternal = false) : base(0, autosave) // Set ItemsPerPage to zero to avoid load() in the base class. { ItemsPerPage = itemsPerPage; m_filterByInternal = filterByInternal; m_includeInternal = includeInternal; m_deviceID = deviceID; Load(); } #endregion #region [ Methods ] /// /// Gets the primary key value of the . /// /// The primary key value of the . public override Guid GetCurrentItemKey() { return CurrentItem.SignalID; } /// /// Gets the string based named identifier of the . /// /// The string based named identifier of the . public override string GetCurrentItemName() { return CurrentItem.PointTag; } /// /// Loads collection of defined in the database. /// public override void Load() { Mouse.OverrideCursor = Cursors.Wait; try { if (m_filterByInternal) m_measurements = DataModelMeasurement.Load(null, m_deviceID, true, m_includeInternal); else m_measurements = MeasurementGroup.GetPossibleMeasurements(null, 0); ItemsSource = m_measurements; } catch (Exception ex) { if (ex.InnerException != null) { Popup(ex.Message + Environment.NewLine + "Inner Exception: " + ex.InnerException.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error); CommonFunctions.LogException(null, "Load " + DataModelName, ex.InnerException); } else { Popup(ex.Message, "Load " + DataModelName + " Exception:", MessageBoxImage.Error); CommonFunctions.LogException(null, "Load " + DataModelName, ex); } } finally { Mouse.OverrideCursor = null; } } /// /// Saves CurrentItem information into database. /// public override void Save() { //Don't do anything here. This view model is used in SelecteMeasurementUserControl and we do not need to save anything from here. } /// /// Hanldes . /// /// string value to search for in measurement collection. public void Search(object paramter) { if (paramter != null && !string.IsNullOrEmpty(paramter.ToString())) { string searchText = paramter.ToString().ToLower(); ItemsSource = new ObservableCollection (m_measurements.Where(m => m.PointTag.ToLower().Contains(searchText) || m.SignalReference.ToLower().Contains(searchText) || m.Description.ToNonNullString().ToLower().Contains(searchText) || m.DeviceAcronym.ToNonNullString().ToLower().Contains(searchText) || m.PhasorLabel.ToNonNullString().ToLower().Contains(searchText) || m.SignalName.ToNonNullString().ToLower().Contains(searchText) || m.SignalAcronym.ToNonNullString().ToLower().Contains(searchText) || m.CompanyName.ToNonNullString().ToLower().Contains(searchText) || m.CompanyAcronym.ToNonNullString().ToLower().Contains(searchText) )); } } /// /// Handles . /// public void ShowAll() { ItemsSource = m_measurements; } #endregion } }