93 lines
2.9 KiB
C#
93 lines
2.9 KiB
C#
// 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
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for NewDGItemDialog.xaml
|
|
/// </summary>
|
|
public partial class NewDGItemDialog : EditWindowBase
|
|
{
|
|
private List<HAZPosTemplate> _data = null;
|
|
private static 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<HAZPosTemplate> 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;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|