// Copyright (c) 2017- schick Informatik // Description: select a new DG item from a selection of templates // using bsmd.database; using ENI2.Controls; using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; namespace ENI2.EditControls { /// /// Interaction logic for NewDGItemDialog.xaml /// public partial class NewDGItemDialog : EditWindowBase { private List _data = null; private static readonly object filterLock = new object(); public NewDGItemDialog() { InitializeComponent(); } public HAZPosTemplate SelectedTemplate { get { return this.listBoxDescription.SelectedItem as HAZPosTemplate; } } private void EditWindowBase_Loaded(object sender, RoutedEventArgs e) { // load combo boxes _data = LocalizedLookup.LoadHAZTemplates(); this.listBoxDescription.ItemsSource = _data; this.comboBoxType.ItemsSource = Enum.GetValues(typeof(HAZPosTemplate.SublistType)); this.OkVisible = false; this.AddVisible = true; } private void comboBoxType_SelectionChanged(object sender, SelectionChangedEventArgs e) { FilterDescriptions(); } private void listBoxDescription_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.listBoxDescription.SelectedItem is HAZPosTemplate selectedTemplate) { this.textBlockDescription.Text = selectedTemplate.Description; this.textBlockRemarks.Text = selectedTemplate.Comment; } else { this.textBlockDescription.Text = ""; this.textBlockRemarks.Text = ""; } } private void textBoxSearchDescription_TextChanged(object sender, TextChangedEventArgs e) { FilterDescriptions(); } private void FilterDescriptions() { string searchText = this.textBoxSearchDescription.Text.Trim(); lock (filterLock) { IEnumerable filtered = _data; if (searchText.Length > 0) { filtered = _data.Where(elem => elem.Description.ToUpperInvariant().Contains(searchText.ToUpperInvariant())); } if (this.comboBoxType.SelectedItem != null) { HAZPosTemplate.SublistType sType = (HAZPosTemplate.SublistType)this.comboBoxType.SelectedItem; filtered = filtered.Where(elem => elem.TemplateType == sType); } this.listBoxDescription.ItemsSource = filtered; } } } }