[feat:] added Country implementation for country code editing (unused)
This commit is contained in:
@@ -385,9 +385,79 @@
|
||||
<Label FontSize="16" Content="Länder" VerticalContentAlignment="Center" />
|
||||
</StackPanel>
|
||||
</TabItem.Header>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Grid ColumnDefinitions="400,*" />
|
||||
</StackPanel>
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
<Grid Grid.Column="0" Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListBox x:Name="CountryList" Grid.Row="0"
|
||||
SelectionChanged="CountryList_OnSelectionChanged" />
|
||||
|
||||
<Grid Grid.Row="1" ColumnDefinitions="*,250" Margin="0,5,0,0">
|
||||
<TextBox x:Name="TbSettingsNewCountry" />
|
||||
<Button Grid.Column="1" x:Name="BtnSettingsNewCountry"
|
||||
HorizontalAlignment="Stretch" Click="BtnSettingsNewCountry_OnClick"
|
||||
HorizontalContentAlignment="Center" Content="+ Hinzufügen"
|
||||
Margin="5,0,0,0" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Column="1" Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid ColumnDefinitions="300,*" Margin="0,0,0,5">
|
||||
<TextBlock Text="Name:" VerticalAlignment="Center" />
|
||||
<TextBox Grid.Column="1" x:Name="TbSettingsCountryName"
|
||||
TextChanged="TbSettingsCountryName_OnTextChanged" />
|
||||
</Grid>
|
||||
|
||||
<Grid ColumnDefinitions="300,*" Margin="0,0,0,5" Grid.Row="1">
|
||||
<TextBlock Text="Übersetzung:" VerticalAlignment="Center" />
|
||||
<TextBox Grid.Column="1" x:Name="TbSettingsCountryTranslation"
|
||||
TextChanged="TbSettingsCountryTranslation_OnTextChanged" />
|
||||
</Grid>
|
||||
|
||||
<Grid Grid.Row="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ListBox x:Name="LbSettingsAlternatives" Grid.Row="0" SelectionMode="Multiple" />
|
||||
|
||||
<Grid Grid.Row="1" ColumnDefinitions="*,200" Margin="0,5,0,0">
|
||||
<TextBox x:Name="TbSettingsNewCountryAlternative"
|
||||
Watermark="Kürzel/Alternative" />
|
||||
<Button Grid.Column="1" x:Name="BtnSettingsNewCountryAlternative"
|
||||
Content="+ Hinzufügen" Margin="5 0 0 0"
|
||||
HorizontalContentAlignment="Center"
|
||||
Click="BtnSettingsNewCountryAlternative_OnClick"
|
||||
HorizontalAlignment="Stretch" />
|
||||
</Grid>
|
||||
|
||||
<Button x:Name="BtnSettingsRemoveSelectedAlternatives" Grid.Row="2"
|
||||
Content="Ausgewählte Entfernen" Background="#99963434"
|
||||
HorizontalContentAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
Click="BtnSettingsRemoveSelectedAlternatives_OnClick"
|
||||
Margin="0,5,0,0" />
|
||||
|
||||
<Button Grid.Row="3"
|
||||
Content="Land Entfernen" Background="#99963434"
|
||||
HorizontalContentAlignment="Center" x:Name="BtnSettingsRemoveCountry"
|
||||
HorizontalAlignment="Stretch" Click="BtnSettingsRemoveCountry_OnClick"
|
||||
Margin="0,5,0,0" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</TabItem>
|
||||
|
||||
@@ -11,6 +11,9 @@ namespace Logof_Client;
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
public static MainWindow _instance;
|
||||
|
||||
private Country _selectedCountry;
|
||||
private bool _suppressCountryRefresh = false;
|
||||
public Uri filePath;
|
||||
|
||||
public MainWindow()
|
||||
@@ -26,6 +29,8 @@ public partial class MainWindow : Window
|
||||
Global.Load();
|
||||
Settings.Load();
|
||||
|
||||
RefreshCountryView();
|
||||
|
||||
//Thread.Sleep(3000);
|
||||
//Show();
|
||||
}
|
||||
@@ -585,4 +590,133 @@ public partial class MainWindow : Window
|
||||
if (customer.ID == Settings._instance.customers.current)
|
||||
customer.sender_address = TbSettingsCustomerSenderAddress.Text;
|
||||
}
|
||||
|
||||
|
||||
// Country Section
|
||||
private void BtnSettingsRemoveCountry_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_selectedCountry != null)
|
||||
{
|
||||
Global._instance.countries.Remove(_selectedCountry);
|
||||
_selectedCountry = null;
|
||||
}
|
||||
|
||||
RefreshCountryView();
|
||||
}
|
||||
|
||||
public void RefreshCountryView()
|
||||
{
|
||||
if (_suppressCountryRefresh) return;
|
||||
try
|
||||
{
|
||||
_suppressCountryRefresh = true;
|
||||
|
||||
Global.Save();
|
||||
var alt_index = LbSettingsAlternatives.SelectedIndex;
|
||||
var country_index = CountryList.SelectedIndex;
|
||||
|
||||
LbSettingsAlternatives.Items.Clear();
|
||||
try
|
||||
{
|
||||
CountryList.Items.Clear();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
foreach (var c in Global._instance.countries) CountryList.Items.Add(c.name);
|
||||
try
|
||||
{
|
||||
CountryList.SelectedIndex = country_index;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_selectedCountry = Country.GetByName(CountryList.SelectedItems[0].ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
_selectedCountry = null;
|
||||
}
|
||||
|
||||
if (_selectedCountry == null) return;
|
||||
//Console.WriteLine("Refreshing alternatives...");
|
||||
foreach (var a in _selectedCountry.alternatives)
|
||||
{
|
||||
LbSettingsAlternatives.Items.Add(a);
|
||||
//Console.WriteLine(a);
|
||||
}
|
||||
|
||||
TbSettingsCountryName.Text = _selectedCountry.name;
|
||||
TbSettingsCountryTranslation.Text = _selectedCountry.translation;
|
||||
|
||||
try
|
||||
{
|
||||
LbSettingsAlternatives.SelectedIndex = alt_index;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_suppressCountryRefresh = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnSettingsRemoveSelectedAlternatives_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (var selected in LbSettingsAlternatives.SelectedItems)
|
||||
try
|
||||
{
|
||||
_selectedCountry.alternatives.Remove(selected.ToString());
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Error while removing country alternative");
|
||||
}
|
||||
|
||||
RefreshCountryView();
|
||||
}
|
||||
|
||||
private void BtnSettingsNewCountryAlternative_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(TbSettingsNewCountryAlternative.Text)) return;
|
||||
_selectedCountry.alternatives.Add(TbSettingsNewCountryAlternative.Text.Trim());
|
||||
RefreshCountryView();
|
||||
}
|
||||
|
||||
private void TbSettingsCountryTranslation_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(TbSettingsCountryTranslation.Text))
|
||||
{
|
||||
_selectedCountry.translation = TbSettingsCountryTranslation.Text.Trim();
|
||||
RefreshCountryView();
|
||||
}
|
||||
}
|
||||
|
||||
private void TbSettingsCountryName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(TbSettingsCountryName.Text))
|
||||
{
|
||||
_selectedCountry.name = TbSettingsCountryName.Text.Trim();
|
||||
RefreshCountryView();
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnSettingsNewCountry_OnClick(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(TbSettingsNewCountry.Text)) return;
|
||||
Global._instance.countries.Add(new Country(TbSettingsNewCountry.Text));
|
||||
RefreshCountryView();
|
||||
}
|
||||
|
||||
private void CountryList_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
_selectedCountry = Country.GetByName(CountryList.SelectedItems[0].ToString());
|
||||
RefreshCountryView();
|
||||
}
|
||||
}
|
||||
35
Settings.cs
35
Settings.cs
@@ -62,6 +62,7 @@ public class Global
|
||||
}
|
||||
|
||||
public string config_path { get; set; } = "";
|
||||
public List<Country> countries { get; set; } = new();
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
@@ -144,6 +145,40 @@ public class AddressSets
|
||||
if (i.ID == ID)
|
||||
return i;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Country
|
||||
{
|
||||
public Country(string name, string translation, List<string> alternatives)
|
||||
{
|
||||
this.name = name;
|
||||
this.translation = translation;
|
||||
this.alternatives = alternatives;
|
||||
}
|
||||
|
||||
public Country(string name)
|
||||
{
|
||||
this.name = name;
|
||||
translation = "";
|
||||
alternatives = new List<string>();
|
||||
}
|
||||
|
||||
public Country()
|
||||
{
|
||||
}
|
||||
|
||||
public string? name { get; set; }
|
||||
public string translation { get; set; }
|
||||
public List<string> alternatives { get; set; }
|
||||
|
||||
public static Country GetByName(string name)
|
||||
{
|
||||
foreach (var country in Global._instance.countries)
|
||||
if (country.name == name)
|
||||
return country;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user