// Copyright (c) 2017-today schick Informatik // Description: Select classes for import // Returns: Array of selected classes as property using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using bsmd.database; namespace ENI2.EditControls { /// /// Interaction logic for SelectImportClassesDialog.xaml /// public partial class SelectImportClassesDialog : ENI2.Controls.EditWindowBase { private List _selectClasses = new List(); private List _selectedClasses = new List(); public SelectImportClassesDialog() { InitializeComponent(); this.Loaded += SelectImportClassesDialog_Loaded; } public List SelectedClasses { get { return _selectedClasses; } } public bool IsTransit { get; set; } private void SelectImportClassesDialog_Loaded(object sender, RoutedEventArgs e) { foreach(bsmd.database.Message.NotificationClass notificationClass in Enum.GetValues(typeof(bsmd.database.Message.NotificationClass))) { if ((notificationClass == Message.NotificationClass.VISIT) || (notificationClass == Message.NotificationClass.ATA) || (notificationClass == Message.NotificationClass.ATD) || (notificationClass == Message.NotificationClass.CREWD) || (notificationClass == Message.NotificationClass.STO) || (notificationClass == Message.NotificationClass.PASD) ) continue; if (IsTransit && ((notificationClass == Message.NotificationClass.BKRD) || (notificationClass == Message.NotificationClass.BPOL) || (notificationClass == Message.NotificationClass.HAZD) || (notificationClass == Message.NotificationClass.INFO) || (notificationClass == Message.NotificationClass.LADG) || (notificationClass == Message.NotificationClass.NAME) || //(notificationClass == Message.NotificationClass.POBD) || (notificationClass == Message.NotificationClass.PRE72H) || (notificationClass == Message.NotificationClass.SERV) || (notificationClass == Message.NotificationClass.TIEFD) || (notificationClass == Message.NotificationClass.TOWD) || (notificationClass == Message.NotificationClass.WAS) )) continue; SelectClass sc = new SelectClass(); sc.Name = Enum.GetName(typeof(bsmd.database.Message.NotificationClass), notificationClass); sc.Class = notificationClass; sc.IsSelected = false; _selectClasses.Add(sc); } _selectClasses.Sort(); this.checkListBoxClasses.ItemsSource = _selectClasses; this.OKClicked += SelectImportClassesDialog_OKClicked; } private void SelectImportClassesDialog_OKClicked() { foreach(SelectClass sc in _selectClasses) { if (sc.IsSelected) _selectedClasses.Add(sc.Class); } } class SelectClass : IComparable, INotifyPropertyChanged { private bool _isSelected; public string Name { get; set; } public bsmd.database.Message.NotificationClass Class { get; set; } public bool IsSelected { get { return _isSelected; } set { _isSelected = value; OnPropertyChanged("IsSelected"); } } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { if(PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public int CompareTo(object obj) { return Name.CompareTo(((SelectClass)obj).Name); } } private void buttonAll_Click(object sender, RoutedEventArgs e) { foreach (SelectClass sc in _selectClasses) sc.IsSelected = true; } private void buttonNone_Click(object sender, RoutedEventArgs e) { foreach (SelectClass sc in _selectClasses) sc.IsSelected = false; } } }