git_bsmd/ENI2/EditControls/SelectPortAreaDialog.xaml.cs

87 lines
2.8 KiB
C#

// Copyright (c) 2023- schick Informatik
// Description: Helper search window to
//
using bsmd.database;
using ENI2.Controls;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
namespace ENI2.EditControls
{
/// <summary>
/// Interaction logic for SelectPortAreaDialog.xaml
/// </summary>
public partial class SelectPortAreaDialog : EditWindowBase
{
#region Fields
private readonly string _poc = null;
private List<PortAreaInfo> _portAreas;
private static readonly object filterLock = new object();
#endregion
#region Construction
public SelectPortAreaDialog(string poc)
{
InitializeComponent();
_poc = poc;
}
#endregion
#region Properties
public string SelectedArea { get; private set; }
#endregion
#region event handler
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if(LocalizedLookup.getPortAreaInfos().ContainsKey(this._poc))
_portAreas = LocalizedLookup.getPortAreaInfos()[this._poc];
this.labelLocode.Content = this._poc;
}
private void comboBoxType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
if (this.listBoxAreas.SelectedItem is PortAreaInfo pai)
{
this.textBlockAgency.Text = pai.Agency;
this.textBlockBerth.Text = pai.Berth;
this.textBlockPortArea.Text = pai.PortArea;
this.textBlockShips.Text = pai.Ships;
this.textBlockRemarks.Text = pai.Remark;
this.SelectedArea = pai.PortAreaCode;
}
}
private void textBoxSearchDescription_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
string searchText = this.textBoxSearchDescription.Text.Trim();
if (_portAreas == null) return;
lock (filterLock)
{
IEnumerable<PortAreaInfo> filtered = _portAreas;
if (searchText.Length > 0)
{
filtered = _portAreas.Where(elem => (elem.Remark != null && elem.Remark.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) ||
(elem.Agency != null && elem.Agency.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) ||
(elem.Berth != null && elem.Berth.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) ||
(elem.PortArea != null && elem.PortArea.ToUpperInvariant().Contains(searchText.ToUpperInvariant())));
}
this.listBoxAreas.ItemsSource = filtered;
}
}
#endregion
}
}