git_bsmd/ENI2/EditControls/SelectPortAreaDialog.xaml.cs
Daniel Schick 90a4915683 Refactoring PortArea:
- Hinzufügen eines Editors im Admin-Bereich
- Entfernen der PortArea Daten aus SQLite und den Zugriffsklassen
- Ersetzen aller Zugriffe durch Daten aus der DB (DBManagerAsync)
2026-02-19 10:42:36 +01:00

98 lines
3.2 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<PortArea> _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<PortArea>();
List<PortArea> 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<PortArea> 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
}
}