Enabled combobox ship search by adding helper container class ShipModel

This commit is contained in:
Daniel Schick 2023-12-26 08:41:54 +01:00
parent 01ab755638
commit d116c06b9e
5 changed files with 45 additions and 35 deletions

View File

@ -23,10 +23,10 @@ namespace BreCalClient
private static readonly List<Berth> _berths = new();
private static List<Berth> _allBerths = new();
private static List<Participant> _participants = new();
private static readonly List<Ship> _ships = new();
private static List<Ship> _allShips = new();
private static readonly List<ShipModel> _ships = new();
private static readonly List<ShipModel> _allShips = new();
private readonly static ConcurrentDictionary<int, Ship> _shipLookupDict = new();
private readonly static ConcurrentDictionary<int, ShipModel> _shipLookupDict = new();
private readonly static ConcurrentDictionary<int, Berth> _berthLookupDict = new();
private readonly static Dictionary<int, Participant> _participantLookupDict = new();
@ -34,7 +34,7 @@ namespace BreCalClient
#region Properties
public static ConcurrentDictionary<int, Ship> ShipLookupDict { get { return _shipLookupDict; } }
public static ConcurrentDictionary<int, ShipModel> ShipLookupDict { get { return _shipLookupDict; } }
public static ConcurrentDictionary<int, Berth> BerthLookupDict { get { return _berthLookupDict; } }
@ -76,19 +76,19 @@ namespace BreCalClient
public static List<Berth> Berths { get { return _berths; } }
/// <summary>
/// All active berths
/// All berths including deleted berths
/// </summary>
public static List<Berth> AllBerths { get { return _allBerths; } }
/// <summary>
/// All active ships
/// </summary>
public static List<Ship> Ships { get { return _ships; } }
public static List<ShipModel> Ships { get { return _ships; } }
/// <summary>
/// All active berths
/// All ships including deleted ships
/// </summary>
public static List<Ship> AllShips { get { return _allShips; } }
public static List<ShipModel> AllShips { get { return _allShips; } }
#endregion
@ -130,11 +130,12 @@ namespace BreCalClient
{
foreach (var ship in ships)
{
_shipLookupDict[ship.Id] = ship;
ShipModel sm = new ShipModel(ship);
_shipLookupDict[ship.Id] = sm;
if (!ship.Deleted)
_ships.Add(ship);
}
_allShips = ships;
_ships.Add(sm);
_allShips.Add(sm);
}
}
#endregion

View File

@ -30,22 +30,7 @@
</Grid.RowDefinitions>
<Label Content="{x:Static p:Resources.textShip}" Grid.Column="0" Grid.Row="0" HorizontalContentAlignment="Right"/>
<ComboBox x:Name="comboBoxShip" Margin="2" Grid.Column="1" Grid.Row="0" SelectionChanged="comboBoxShip_SelectionChanged" SelectedValuePath="Id">
<ComboBox.ItemTemplate>
<DataTemplate>
<!--Border-->
<TextBlock>
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} ({1})">
<Binding Path="Name" />
<Binding Path="Imo" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<!--/Border-->
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ComboBox x:Name="comboBoxShip" Margin="2" Grid.Column="1" Grid.Row="0" SelectionChanged="comboBoxShip_SelectionChanged" SelectedValuePath="Ship.Id" IsEditable="True" IsTextSearchEnabled="True" IsTextSearchCaseSensitive="False" />
<Label Content="IMO" Grid.Column="0" Grid.Row="1" HorizontalContentAlignment="Right"/>
<xctk:IntegerUpDown x:Name="integerUpDownIMO" IsReadOnly="True" Margin="2" Grid.Column="1" Grid.Row="1" />
<Label Content="{x:Static p:Resources.textCallsign}" Grid.Column="0" Grid.Row="2" HorizontalContentAlignment="Right"/>

View File

@ -67,11 +67,11 @@ namespace BreCalClient
{
if (this.comboBoxShip.SelectedItem != null)
{
Ship? ship = this.comboBoxShip.SelectedItem as Ship;
this.integerUpDownIMO.Value = ship?.Imo;
this.textBoxCallsign.Text = ship?.Callsign;
this.doubleUpDownLength.Value = ship?.Length;
this.doubleUpDownWidth.Value = ship?.Width;
ShipModel? ship = this.comboBoxShip.SelectedItem as ShipModel;
this.integerUpDownIMO.Value = ship?.Ship.Imo;
this.textBoxCallsign.Text = ship?.Ship.Callsign;
this.doubleUpDownLength.Value = ship?.Ship.Length;
this.doubleUpDownWidth.Value = ship?.Ship.Width;
}
else
{

View File

@ -428,7 +428,7 @@ namespace BreCalClient
Shipcall shipcall = scm.Shipcall;
if (BreCalLists.ShipLookupDict.ContainsKey(shipcall.ShipId))
scm.Ship = BreCalLists.ShipLookupDict[shipcall.ShipId];
scm.Ship = BreCalLists.ShipLookupDict[shipcall.ShipId].Ship;
if (shipcall.Type == 1)
{
if (BreCalLists.BerthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0))
@ -461,7 +461,7 @@ namespace BreCalClient
if(scm.Shipcall == null) return;
Shipcall shipcall = scm.Shipcall;
if (BreCalLists.ShipLookupDict.ContainsKey(shipcall.ShipId))
scm.Ship = BreCalLists.ShipLookupDict[shipcall.ShipId];
scm.Ship = BreCalLists.ShipLookupDict[shipcall.ShipId].Ship;
if (shipcall.Type == 1)
{
if (BreCalLists.BerthLookupDict.ContainsKey(shipcall.ArrivalBerthId ?? 0))

View File

@ -0,0 +1,24 @@
// Copyright (c) 2023 schick Informatik
// Description: Helper class to display/search ships
//
using BreCalClient.misc.Model;
using System;
namespace BreCalClient
{
public class ShipModel
{
public ShipModel(Ship ship) {
this.Ship = ship;
}
public Ship Ship { get; private set; }
public override string ToString()
{
return String.Format("{0} ({1})", this.Ship.Name, this.Ship.Imo);
}
}
}