//******************************************************************************************************
// SelectMeasurementUserControl.xaml.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.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using GSF.TimeSeries.Transport.UI.ViewModels;
using GSF.TimeSeries.UI;
using DataModelMeasurement = GSF.TimeSeries.UI.DataModels.Measurement;
namespace GSF.TimeSeries.Transport.UI.UserControls
{
///
/// Interaction logic for SelectMeasurementUserControl.xaml
///
public partial class SelectMeasurementUserControl : UserControl
{
#region [ Members ]
// Delegates
///
/// Method signature for function used to handle SourceCollectionChanged event.
///
/// Source of the event.
/// Event arguments.
public delegate void OnSourceCollectionChanged(object sender, RoutedEventArgs e);
// Events
///
/// Event to notify subcribers when collection changes.
///
public event OnSourceCollectionChanged SourceCollectionChanged;
// Fields
private SelectMeasurements m_dataContext;
private ObservableCollection m_itemsSource;
private int m_currentDeviceID;
#endregion
#region [ Properties ]
// Dependency Properties
///
/// to determine number of measurements per page.
///
public static readonly DependencyProperty ItemsPerPageProperty = DependencyProperty.Register("ItemsPerPage", typeof(int),
typeof(SelectMeasurementUserControl), new UIPropertyMetadata(0));
///
/// to determine if only records with Internal flag set to true are displayed.
///
public static readonly DependencyProperty FilterByInternalProperty = DependencyProperty.Register("FilterByInternal", typeof(bool),
typeof(SelectMeasurementUserControl), new UIPropertyMetadata(false));
///
/// Gets or sets number of measurements to display on a page.
///
public int ItemsPerPage
{
get
{
return (int)GetValue(ItemsPerPageProperty);
}
set
{
SetValue(ItemsPerPageProperty, value);
}
}
///
/// Gets or set falg to determine if only measurements with Internal flag set true are returned.
///
public bool FilterByInternal
{
get
{
return (bool)GetValue(FilterByInternalProperty);
}
set
{
SetValue(FilterByInternalProperty, value);
}
}
///
/// Gets updated measurement list.
///
public ObservableCollection UpdatedMeasurements
{
get
{
return m_dataContext.ItemsSource;
}
}
///
/// Gets or sets current device selected on the parent screen for filtering purpose.
///
public int CurrentDeviceID
{
get
{
return m_currentDeviceID;
}
set
{
m_currentDeviceID = value;
}
}
#endregion
#region [ Constructors ]
///
/// Creates an instance of class.
///
public SelectMeasurementUserControl()
{
InitializeComponent();
this.Loaded += SelectMeasurementUserControl_Loaded;
}
#endregion
#region [ Methods ]
///
/// Handles loaded event for select measurement user control.
///
///
///
private void SelectMeasurementUserControl_Loaded(object sender, RoutedEventArgs e)
{
if (IsolatedStorageManager.ReadFromIsolatedStorage("DisplayInternal") == null)
IsolatedStorageManager.WriteToIsolatedStorage("DisplayInternal", false);
if (FilterByInternal)
{
CheckboxDisplayInternal.Visibility = Visibility.Visible;
CheckboxDisplayInternal.IsChecked = IsolatedStorageManager.ReadFromIsolatedStorage("DisplayInternal").ToString().ParseBoolean();
}
else
{
CheckboxDisplayInternal.Visibility = Visibility.Collapsed;
}
if (!DesignerProperties.GetIsInDesignMode(this))
Refresh();
}
///
/// Handles property changed event for select measurement user control.
///
/// Source of the event.
/// Event arguments.
private void measurement_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (SourceCollectionChanged != null)
SourceCollectionChanged(this, null);
}
///
/// Hanldes checked event on the select all check box.
///
/// Source of the event.
/// Event arguments.
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
foreach (DataModelMeasurement measurement in m_itemsSource)
{
measurement.Selected = true;
}
}
///
/// Handles unchecked event on the select all check box.
///
/// Source of the event.
/// Event arguments.
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
foreach (DataModelMeasurement measurement in m_itemsSource)
{
measurement.Selected = false;
}
}
///
/// Method to uncheck check boxes checked by user.
///
public void UncheckSelection()
{
foreach (DataModelMeasurement measurement in m_itemsSource)
{
measurement.Selected = false;
}
}
///
/// Refreshes data bound to grid.
///
/// ID of the device to filter data.
public void Refresh(int deviceID = 0)
{
m_dataContext = new SelectMeasurements(ItemsPerPage, true, FilterByInternal, deviceID, (bool)CheckboxDisplayInternal.IsChecked);
m_itemsSource = m_dataContext.ItemsSource;
foreach (DataModelMeasurement measurement in m_itemsSource)
{
measurement.PropertyChanged += measurement_PropertyChanged;
}
this.DataContext = m_dataContext;
}
private void DataGrid_Sorting(object sender, DataGridSortingEventArgs e)
{
m_dataContext.SortData(e.Column.SortMemberPath);
}
private void CheckboxDisplayInternal_Checked(object sender, RoutedEventArgs e)
{
Refresh(m_currentDeviceID);
IsolatedStorageManager.WriteToIsolatedStorage("DisplayInternal", true);
}
private void CheckboxDisplayInternal_Unchecked(object sender, RoutedEventArgs e)
{
Refresh(m_currentDeviceID);
IsolatedStorageManager.WriteToIsolatedStorage("DisplayInternal", false);
}
#endregion
}
}