localized the shipcall type combobox selection
This commit is contained in:
parent
8c7169d291
commit
82c9b14f73
@ -5,12 +5,13 @@
|
||||
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: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">
|
||||
<Window.Resources>
|
||||
<local:BoolToIndexConverter x:Key="boolToIndexConverter" />
|
||||
<local:EnumToStringConverter x:Key="enumToStringConverter" />
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@ -46,7 +47,7 @@
|
||||
|
||||
<Label Content="{x:Static p:Resources.textType}" Grid.Column="2" Grid.Row="0" HorizontalContentAlignment="Right" />
|
||||
|
||||
<ComboBox x:Name="comboBoxCategories" Grid.Column="3" Margin="2" Grid.Row="0" SelectionChanged="comboBoxCategories_SelectionChanged"/>
|
||||
<ComboBox ItemsSource="{local:Enumerate {x:Type api:ShipcallType}}" Grid.Column="3" Margin="2" Grid.Row="0" SelectionChanged="comboBoxCategories_SelectionChanged" x:Name="comboBoxCategories" />
|
||||
|
||||
<Label Content="{x:Static p:Resources.textBerth}" Grid.Column="2" Grid.Row="1" HorizontalContentAlignment="Right"/>
|
||||
<Grid Grid.Row="1" Grid.Column="3">
|
||||
|
||||
@ -51,14 +51,14 @@ namespace BreCalClient
|
||||
|
||||
this.comboBoxShip.ItemsSource = BreCalLists.Ships;
|
||||
Array types = Enum.GetValues(typeof(ShipcallType));
|
||||
List<ShipcallType> shipcallTypes = new List<ShipcallType>();
|
||||
List<ShipcallType> 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;
|
||||
|
||||
71
src/BreCalClient/EnumHelper.cs
Normal file
71
src/BreCalClient/EnumHelper.cs
Normal file
@ -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
|
||||
|
||||
}
|
||||
@ -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) ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
45
src/BreCalClient/Resources/Resources.Designer.cs
generated
45
src/BreCalClient/Resources/Resources.Designer.cs
generated
@ -80,6 +80,15 @@ namespace BreCalClient.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Incoming.
|
||||
/// </summary>
|
||||
public static string Arrival {
|
||||
get {
|
||||
return ResourceManager.GetString("Arrival", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
@ -200,6 +209,15 @@ namespace BreCalClient.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Outgoing.
|
||||
/// </summary>
|
||||
public static string Departure {
|
||||
get {
|
||||
return ResourceManager.GetString("Departure", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
@ -250,6 +268,15 @@ namespace BreCalClient.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Shifting.
|
||||
/// </summary>
|
||||
public static string Shifting {
|
||||
get {
|
||||
return ResourceManager.GetString("Shifting", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
@ -999,6 +1026,15 @@ namespace BreCalClient.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Ships.
|
||||
/// </summary>
|
||||
public static string textShips {
|
||||
get {
|
||||
return ResourceManager.GetString("textShips", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Show cancelled calls.
|
||||
/// </summary>
|
||||
@ -1277,6 +1313,15 @@ namespace BreCalClient.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Undefined.
|
||||
/// </summary>
|
||||
public static string Undefined {
|
||||
get {
|
||||
return ResourceManager.GetString("Undefined", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
|
||||
@ -481,4 +481,19 @@
|
||||
<data name="textTriggerManualRefresh" xml:space="preserve">
|
||||
<value>Manuelle Aktualisierung der Anläufe auslösen</value>
|
||||
</data>
|
||||
<data name="Arrival" xml:space="preserve">
|
||||
<value>Einkommend</value>
|
||||
</data>
|
||||
<data name="Departure" xml:space="preserve">
|
||||
<value>Ausgehend</value>
|
||||
</data>
|
||||
<data name="Shifting" xml:space="preserve">
|
||||
<value>Verholung</value>
|
||||
</data>
|
||||
<data name="Undefined" xml:space="preserve">
|
||||
<value>Unbekannt</value>
|
||||
</data>
|
||||
<data name="textShips" xml:space="preserve">
|
||||
<value>Schiffe</value>
|
||||
</data>
|
||||
</root>
|
||||
@ -121,6 +121,9 @@
|
||||
<data name="add" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>add.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="Arrival" xml:space="preserve">
|
||||
<value>Incoming</value>
|
||||
</data>
|
||||
<data name="arrow_down_green" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>arrow_down_green.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
@ -157,6 +160,9 @@
|
||||
<data name="delete2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>delete2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="Departure" xml:space="preserve">
|
||||
<value>Outgoing</value>
|
||||
</data>
|
||||
<data name="edit" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>edit.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
@ -172,6 +178,9 @@
|
||||
<data name="nav_refresh_green" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>nav_refresh_green.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="Shifting" xml:space="preserve">
|
||||
<value>Shifting</value>
|
||||
</data>
|
||||
<data name="ship2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>ship2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
@ -421,6 +430,9 @@
|
||||
<data name="textShipLength" xml:space="preserve">
|
||||
<value>Ship length</value>
|
||||
</data>
|
||||
<data name="textShips" xml:space="preserve">
|
||||
<value>Ships</value>
|
||||
</data>
|
||||
<data name="textShowCancelledShipcalls" xml:space="preserve">
|
||||
<value>Show cancelled calls</value>
|
||||
</data>
|
||||
@ -511,6 +523,9 @@
|
||||
<data name="umbrella_open" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>umbrella_open.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="Undefined" xml:space="preserve">
|
||||
<value>Undefined</value>
|
||||
</data>
|
||||
<data name="worker2" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>worker2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
|
||||
@ -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">
|
||||
<UserControl.Resources>
|
||||
<local:EnumToStringConverter x:Key="enumToStringConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="28" />
|
||||
@ -63,7 +67,7 @@
|
||||
<Label Grid.Column="1" Content="{x:Static p:Resources.textTo}" />
|
||||
<DatePicker x:Name="datePickerETATo" Grid.Column="2" Margin="2" SelectedDateChanged="datePickerETATo_SelectedDateChanged" SelectedDate="{Binding Path=EtaTo}"/>
|
||||
</Grid>
|
||||
<xctk:CheckComboBox x:Name="comboBoxCategories" Grid.Column="4" Margin="2" ItemSelectionChanged="comboBoxCategories_ItemSelectionChanged" />
|
||||
<xctk:CheckComboBox x:Name="comboBoxCategories" Grid.Column="4" Margin="2" ItemSelectionChanged="comboBoxCategories_ItemSelectionChanged" ItemsSource="{local:Enumerate {x:Type api:ShipcallType}}" />
|
||||
<Grid Grid.Column="6" Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=".5*" />
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -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">
|
||||
|
||||
<Grid>
|
||||
|
||||
Reference in New Issue
Block a user