diff --git a/src/BreCalClient/EditShipcallControl.xaml b/src/BreCalClient/EditShipcallControl.xaml
index 101eeac..6ebe2cf 100644
--- a/src/BreCalClient/EditShipcallControl.xaml
+++ b/src/BreCalClient/EditShipcallControl.xaml
@@ -4,13 +4,14 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BreCalClient"
- xmlns:p = "clr-namespace:BreCalClient.Resources"
- xmlns:db="clr-namespace:BreCalClient;assembly=BreCalClient"
+ xmlns:p = "clr-namespace:BreCalClient.Resources"
+ xmlns:api="clr-namespace:BreCalClient.misc.Model"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d" Left="{local:SettingBinding W1Left}" Top="{local:SettingBinding W1Top}"
Title="{x:Static p:Resources.textEditShipcall}" Height="270" Width="800" Loaded="Window_Loaded" ResizeMode="NoResize" Icon="Resources/containership.ico">
+
@@ -45,8 +46,8 @@
-
-
+
+
diff --git a/src/BreCalClient/EditShipcallControl.xaml.cs b/src/BreCalClient/EditShipcallControl.xaml.cs
index 6a29df7..86ce4ef 100644
--- a/src/BreCalClient/EditShipcallControl.xaml.cs
+++ b/src/BreCalClient/EditShipcallControl.xaml.cs
@@ -51,14 +51,14 @@ namespace BreCalClient
this.comboBoxShip.ItemsSource = BreCalLists.Ships;
Array types = Enum.GetValues(typeof(ShipcallType));
- List shipcallTypes = new List();
+ List shipcallTypes = new();
bool first = true;
foreach(ShipcallType shipcallType in types)
{
if (!first) shipcallTypes.Add(shipcallType);
else first = false;
- }
- this.comboBoxCategories.ItemsSource = shipcallTypes;
+ }
+
this.comboBoxArrivalBerth.ItemsSource = BreCalLists.Berths;
this.comboBoxDepartureBerth.ItemsSource = BreCalLists.Berths;
@@ -111,7 +111,7 @@ namespace BreCalClient
private void comboBoxCategories_SelectionChanged(object? sender, SelectionChangedEventArgs? e)
{
- ShipcallType? type = this.comboBoxCategories.SelectedItem as ShipcallType?;
+ ShipcallType? type = GetShipcallTypeFromCombobox();
if (type != null)
{
switch (type)
@@ -162,6 +162,12 @@ namespace BreCalClient
#region private methods
+ ShipcallType? GetShipcallTypeFromCombobox()
+ {
+ EnumToStringConverter enumToStringConverter = new();
+ return (ShipcallType?)enumToStringConverter.ConvertBack(this.comboBoxCategories.SelectedItem, typeof(ShipcallType), new object(), System.Globalization.CultureInfo.CurrentCulture);
+ }
+
void CheckForCompletion()
{
bool isEnabled = true;
@@ -175,7 +181,7 @@ namespace BreCalClient
}
else
{
- ShipcallType callType = (ShipcallType)comboBoxCategories.SelectedItem;
+ ShipcallType callType = GetShipcallTypeFromCombobox() ?? ShipcallType.Undefined;
switch (callType)
{
case ShipcallType.Departure:
@@ -203,7 +209,7 @@ namespace BreCalClient
{
if (this.ShipcallModel.Shipcall != null)
{
- this.ShipcallModel.Shipcall.Type = (ShipcallType) this.comboBoxCategories.SelectedItem;
+ this.ShipcallModel.Shipcall.Type = GetShipcallTypeFromCombobox() ?? ShipcallType.Undefined;
this.ShipcallModel.Shipcall.Eta = this.datePickerETA.Value;
this.ShipcallModel.Shipcall.Etd = this.datePickerETD.Value;
@@ -284,7 +290,7 @@ namespace BreCalClient
if (this.ShipcallModel.Shipcall != null)
{
this.comboBoxTimeRef.SelectedIndex = this.ShipcallModel.Shipcall.TimeRefPoint ?? 0;
- this.comboBoxCategories.SelectedItem = this.ShipcallModel.Shipcall.Type;
+ this.comboBoxCategories.SelectedItem = new EnumToStringConverter().Convert(this.ShipcallModel.Shipcall.Type, typeof(ShipcallType), new object(), System.Globalization.CultureInfo.CurrentCulture);
if (this.ShipcallModel.Shipcall.Eta != DateTime.MinValue)
this.datePickerETA.Value = this.ShipcallModel.Shipcall.Eta;
// this.textBoxVoyage.Text = this.ShipcallModel.Shipcall.Voyage;
diff --git a/src/BreCalClient/EnumHelper.cs b/src/BreCalClient/EnumHelper.cs
new file mode 100644
index 0000000..8639ccf
--- /dev/null
+++ b/src/BreCalClient/EnumHelper.cs
@@ -0,0 +1,71 @@
+// Copyright (c) 2024- schick Informatik
+// Description: Helpers to display localized Enum values in Comboboxes
+// https://stackoverflow.com/questions/29658721/enum-in-wpf-comboxbox-with-localized-names
+//
+
+using System;
+using System.Globalization;
+using System.Windows.Data;
+using System.Windows.Markup;
+
+namespace BreCalClient
+{
+
+ #region class EnumToStringConverter
+
+ public sealed class EnumToStringConverter : IValueConverter
+ {
+ public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value == null)
+ { return null; }
+
+ return Resources.Resources.ResourceManager.GetString(value.ToString() ?? "");
+ }
+
+ public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ string str = (string)value;
+
+ foreach (object enumValue in Enum.GetValues(targetType))
+ {
+ if (str == Resources.Resources.ResourceManager.GetString(enumValue.ToString() ?? ""))
+ { return enumValue; }
+ }
+ return null;
+ }
+ }
+
+ #endregion
+
+ #region class EnumerateExtension
+
+ public sealed class EnumerateExtension : MarkupExtension
+ {
+ public Type Type { get; set; }
+
+ public EnumerateExtension(Type type)
+ {
+ this.Type = type;
+ }
+
+ public override object ProvideValue(IServiceProvider serviceProvider)
+ {
+ string[] names = Enum.GetNames(Type);
+
+ // skip value "0" == "Unknown" (we dont want this selectable in the Combobox)
+ // NOTE: This will only work in the future if the first element is always "undefined" aka unused
+
+ string[] values = new string[names.Length - 1];
+ for (int i = 0; i < names.Length - 1; i++)
+ {
+ values[i] = Resources.Resources.ResourceManager.GetString(names[i + 1]) ?? names[i];
+ }
+
+ return values;
+ }
+ }
+
+ #endregion
+
+}
diff --git a/src/BreCalClient/HistoryDialog.xaml.cs b/src/BreCalClient/HistoryDialog.xaml.cs
index 3b80236..b26325e 100644
--- a/src/BreCalClient/HistoryDialog.xaml.cs
+++ b/src/BreCalClient/HistoryDialog.xaml.cs
@@ -70,6 +70,8 @@ namespace BreCalClient
// sort all entries
allHistories.Sort((x, y) => { return y.Timestamp.CompareTo(x.Timestamp); });
+ EnumToStringConverter enumToStringConverter = new();
+
// create controls for all entries
foreach (History history in allHistories)
{
@@ -84,7 +86,7 @@ namespace BreCalClient
if (_shipcalls[history.ShipcallId].Shipcall != null)
{
ShipcallType? type = _shipcalls[history.ShipcallId].Shipcall?.Type;
- if (type != null) calltype = type.Value.ToString();
+ if (type != null) calltype = (string) (enumToStringConverter.Convert(type ?? ShipcallType.Undefined, typeof(ShipcallType), new(), System.Globalization.CultureInfo.CurrentCulture) ?? "");
}
}
diff --git a/src/BreCalClient/Resources/Resources.Designer.cs b/src/BreCalClient/Resources/Resources.Designer.cs
index 3e306de..812d0fd 100644
--- a/src/BreCalClient/Resources/Resources.Designer.cs
+++ b/src/BreCalClient/Resources/Resources.Designer.cs
@@ -80,6 +80,15 @@ namespace BreCalClient.Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Incoming.
+ ///
+ public static string Arrival {
+ get {
+ return ResourceManager.GetString("Arrival", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized resource of type System.Byte[].
///
@@ -200,6 +209,15 @@ namespace BreCalClient.Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Outgoing.
+ ///
+ public static string Departure {
+ get {
+ return ResourceManager.GetString("Departure", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized resource of type System.Byte[].
///
@@ -250,6 +268,15 @@ namespace BreCalClient.Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Shifting.
+ ///
+ public static string Shifting {
+ get {
+ return ResourceManager.GetString("Shifting", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized resource of type System.Byte[].
///
@@ -999,6 +1026,15 @@ namespace BreCalClient.Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Ships.
+ ///
+ public static string textShips {
+ get {
+ return ResourceManager.GetString("textShips", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Show cancelled calls.
///
@@ -1277,6 +1313,15 @@ namespace BreCalClient.Resources {
}
}
+ ///
+ /// Looks up a localized string similar to Undefined.
+ ///
+ public static string Undefined {
+ get {
+ return ResourceManager.GetString("Undefined", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized resource of type System.Byte[].
///
diff --git a/src/BreCalClient/Resources/Resources.de.resx b/src/BreCalClient/Resources/Resources.de.resx
index 6e43a15..291e704 100644
--- a/src/BreCalClient/Resources/Resources.de.resx
+++ b/src/BreCalClient/Resources/Resources.de.resx
@@ -481,4 +481,19 @@
Manuelle Aktualisierung der Anläufe auslösen
+
+ Einkommend
+
+
+ Ausgehend
+
+
+ Verholung
+
+
+ Unbekannt
+
+
+ Schiffe
+
\ No newline at end of file
diff --git a/src/BreCalClient/Resources/Resources.resx b/src/BreCalClient/Resources/Resources.resx
index 4172e4d..aa64fa9 100644
--- a/src/BreCalClient/Resources/Resources.resx
+++ b/src/BreCalClient/Resources/Resources.resx
@@ -121,6 +121,9 @@
add.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Incoming
+
arrow_down_green.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -157,6 +160,9 @@
delete2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Outgoing
+
edit.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -172,6 +178,9 @@
nav_refresh_green.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Shifting
+
ship2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
@@ -421,6 +430,9 @@
Ship length
+
+ Ships
+
Show cancelled calls
@@ -511,6 +523,9 @@
umbrella_open.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ Undefined
+
worker2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
diff --git a/src/BreCalClient/SearchFilterControl.xaml b/src/BreCalClient/SearchFilterControl.xaml
index 951695a..d0e304f 100644
--- a/src/BreCalClient/SearchFilterControl.xaml
+++ b/src/BreCalClient/SearchFilterControl.xaml
@@ -5,9 +5,13 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:p = "clr-namespace:BreCalClient.Resources"
xmlns:local="clr-namespace:BreCalClient"
+ xmlns:api="clr-namespace:BreCalClient.misc.Model"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
d:DesignHeight="56" d:DesignWidth="800" Loaded="UserControl_Loaded">
+
+
+
@@ -63,7 +67,7 @@
-
+
diff --git a/src/BreCalClient/SearchFilterControl.xaml.cs b/src/BreCalClient/SearchFilterControl.xaml.cs
index 2814c8e..c176c27 100644
--- a/src/BreCalClient/SearchFilterControl.xaml.cs
+++ b/src/BreCalClient/SearchFilterControl.xaml.cs
@@ -101,8 +101,11 @@ namespace BreCalClient
}
if(sfm.Categories != null)
{
- foreach(ShipcallType category in sfm.Categories)
- this.comboBoxCategories.SelectedItems.Add(category);
+ EnumToStringConverter enumToStringConverter = new();
+ foreach (ShipcallType category in sfm.Categories)
+ {
+ this.comboBoxCategories.SelectedItems.Add(enumToStringConverter.Convert(category, typeof(ShipcallControl), new object(), System.Globalization.CultureInfo.CurrentCulture));
+ }
}
if (sfm.SearchString != null) this.textBoxSearch.Text = sfm.SearchString;
this.upDownShiplengthFrom.Value = sfm.ShipLengthFrom;
@@ -129,7 +132,7 @@ namespace BreCalClient
private void UserControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
- this.comboBoxCategories.ItemsSource = Enum.GetValues(typeof(ShipcallType));
+
}
private void datePickerETAFrom_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
@@ -146,9 +149,15 @@ namespace BreCalClient
private void comboBoxCategories_ItemSelectionChanged(object sender, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventArgs e)
{
+ EnumToStringConverter enumToStringConverter = new();
+
_model.Categories.Clear();
- foreach(ShipcallType category in comboBoxCategories.SelectedItems)
- _model.Categories.Add(category);
+ foreach (string categoryString in comboBoxCategories.SelectedItems)
+ {
+ ShipcallType? type = (ShipcallType?)enumToStringConverter.ConvertBack(categoryString, typeof(ShipcallType), new object(), System.Globalization.CultureInfo.CurrentCulture);
+ if(type != null)
+ _model.Categories.Add(type.Value);
+ }
SearchFilterChanged?.Invoke();
}
diff --git a/src/BreCalClient/ShipListDialog.xaml b/src/BreCalClient/ShipListDialog.xaml
index 6d98467..3dc1bd8 100644
--- a/src/BreCalClient/ShipListDialog.xaml
+++ b/src/BreCalClient/ShipListDialog.xaml
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:p = "clr-namespace:BreCalClient.Resources"
xmlns:local="clr-namespace:BreCalClient"
- mc:Ignorable="d" Left="{local:SettingBinding W2Left}" Top="{local:SettingBinding W2Top}"
+ mc:Ignorable="d" Left="{local:SettingBinding W2Left}" Top="{local:SettingBinding W2Top}" Title="{x:Static p:Resources.textShips}"
Height="490" Width="800" ResizeMode="CanResize" Icon="Resources/containership.ico" Loaded="Window_Loaded">