// 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 { /// /// Interaction logic for SelectPortAreaDialog.xaml /// public partial class SelectPortAreaDialog : EditWindowBase { #region Fields private readonly string _poc = null; private List _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) { _portAreas = new List(); List items = DBManagerAsync.LoadPortAreasAsync().Result; foreach (var item in items) { if (item.Locode == _poc) { _portAreas.Add(item); } } this.labelLocode.Content = this._poc; } private void comboBoxType_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (this.listBoxAreas.SelectedItem is PortArea pai) { this.textBlockAgency.Text = pai.Agency; this.textBlockBerth.Text = pai.Berth; this.textBlockPortArea.Text = pai.Name; this.textBlockShips.Text = pai.Ships; this.textBlockRemarks.Text = pai.Remarks; this.SelectedArea = pai.Code; } } private void textBoxSearchDescription_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { string searchText = this.textBoxSearchDescription.Text.Trim(); if (_portAreas == null) return; lock (filterLock) { IEnumerable filtered = _portAreas; if (searchText.Length > 0) { filtered = _portAreas.Where(elem => (elem.Remarks != null && elem.Remarks.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) || (elem.Agency != null && elem.Agency.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) || (elem.Berth != null && elem.Berth.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) || (elem.Ships != null && elem.Ships.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) || (elem.Name != null && elem.Name.ToUpperInvariant().Contains(searchText.ToUpperInvariant())) || (elem.Code != null && elem.Code.ToUpperInvariant().Contains(searchText.ToUpperInvariant()))); } this.listBoxAreas.ItemsSource = filtered; } } #endregion } }