[chore:] added address patch
This commit is contained in:
118
AddressPatch.cs
Normal file
118
AddressPatch.cs
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
public class AddressPatch
|
||||||
|
{
|
||||||
|
public string refsid_is { get; set; } = "";
|
||||||
|
public string anrede_is { get; set; } = "";
|
||||||
|
public string titel_is { get; set; } = "";
|
||||||
|
public string vorname_is { get; set; } = "";
|
||||||
|
public string adel_is { get; set; } = "";
|
||||||
|
public string name_is { get; set; } = "";
|
||||||
|
public string namezus_is { get; set; } = "";
|
||||||
|
public string anredzus_is { get; set; } = "";
|
||||||
|
public string strasse_is { get; set; } = "";
|
||||||
|
public string strasse2_is { get; set; } = "";
|
||||||
|
public string plz_is { get; set; } = "";
|
||||||
|
public string ort_is { get; set; } = "";
|
||||||
|
public string land_is { get; set; } = "";
|
||||||
|
public string pplz_is { get; set; } = "";
|
||||||
|
public string postfach_is { get; set; } = "";
|
||||||
|
public string name1_is { get; set; } = "";
|
||||||
|
public string name2_is { get; set; } = "";
|
||||||
|
public string name3_is { get; set; } = "";
|
||||||
|
public string name4_is { get; set; } = "";
|
||||||
|
public string name5_is { get; set; } = "";
|
||||||
|
public string funktion_is { get; set; } = "";
|
||||||
|
public string funktion2_is { get; set; } = "";
|
||||||
|
public string abteilung_is { get; set; } = "";
|
||||||
|
public string funktionad_is { get; set; } = "";
|
||||||
|
|
||||||
|
public bool has_refsid { get; set; }
|
||||||
|
public bool has_anrede { get; set; }
|
||||||
|
public bool has_titel { get; set; }
|
||||||
|
public bool has_vorname { get; set; }
|
||||||
|
public bool has_adel { get; set; }
|
||||||
|
public bool has_name { get; set; }
|
||||||
|
public bool has_namezus { get; set; }
|
||||||
|
public bool has_anredzus { get; set; }
|
||||||
|
public bool has_strasse { get; set; }
|
||||||
|
public bool has_strasse2 { get; set; }
|
||||||
|
public bool has_plz { get; set; }
|
||||||
|
public bool has_ort { get; set; }
|
||||||
|
public bool has_land { get; set; }
|
||||||
|
public bool has_pplz { get; set; }
|
||||||
|
public bool has_postfach { get; set; }
|
||||||
|
public bool has_name1 { get; set; }
|
||||||
|
public bool has_name2 { get; set; }
|
||||||
|
public bool has_name3 { get; set; }
|
||||||
|
public bool has_name4 { get; set; }
|
||||||
|
public bool has_name5 { get; set; }
|
||||||
|
public bool has_funktion { get; set; }
|
||||||
|
public bool has_funktion2 { get; set; }
|
||||||
|
public bool has_abteilung { get; set; }
|
||||||
|
public bool has_funktionad { get; set; }
|
||||||
|
|
||||||
|
public static AddressPatch Import(Uri filename)
|
||||||
|
{
|
||||||
|
var patch = new AddressPatch();
|
||||||
|
|
||||||
|
// Alle Zeilen aus der Datei laden
|
||||||
|
var lines = File.ReadAllLines(filename.LocalPath);
|
||||||
|
|
||||||
|
// Alle Properties der Klasse (Strings und bools)
|
||||||
|
var properties = typeof(AddressPatch).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||||
|
|
||||||
|
// Nur die Properties, die mit _is enden (also die String-Werte)
|
||||||
|
var stringProps = properties.Where(p => p.PropertyType == typeof(string) && p.Name.EndsWith("_is"));
|
||||||
|
|
||||||
|
foreach (var prop in stringProps)
|
||||||
|
{
|
||||||
|
// Beispiel: prop.Name = "name_is"
|
||||||
|
var baseName = prop.Name.Substring(0, prop.Name.Length - 3); // "name"
|
||||||
|
|
||||||
|
// In der Datei wird nach "name:" gesucht (ohne _is)
|
||||||
|
var line = lines.FirstOrDefault(l => l.StartsWith(baseName + ":"));
|
||||||
|
if (line != null)
|
||||||
|
{
|
||||||
|
// Wert extrahieren (alles nach dem Doppelpunkt)
|
||||||
|
var value = line.Substring(line.IndexOf(':') + 1).Trim();
|
||||||
|
|
||||||
|
// Wert im Patch-Objekt setzen
|
||||||
|
prop.SetValue(patch, value);
|
||||||
|
|
||||||
|
// Passendes has_ Feld aktivieren, z.B. "has_name"
|
||||||
|
var hasProp = properties.FirstOrDefault(p => p.Name == "has_" + baseName);
|
||||||
|
if (hasProp != null && hasProp.PropertyType == typeof(bool)) hasProp.SetValue(patch, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||||
|
var stringProps = properties.Where(p => p.PropertyType == typeof(string) && p.Name.EndsWith("_is"));
|
||||||
|
|
||||||
|
var lines = new StringBuilder();
|
||||||
|
|
||||||
|
foreach (var prop in stringProps)
|
||||||
|
{
|
||||||
|
// passendes has_ Feld
|
||||||
|
var hasProp =
|
||||||
|
properties.FirstOrDefault(p => p.Name == "has_" + prop.Name.Substring(0, prop.Name.Length - 3));
|
||||||
|
if (hasProp != null && (bool)hasProp.GetValue(this))
|
||||||
|
{
|
||||||
|
var value = (string)prop.GetValue(this);
|
||||||
|
lines.AppendLine($"{prop.Name} => {value}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines.ToString().TrimEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,10 @@ namespace Logof_Client;
|
|||||||
|
|
||||||
public class DataImport
|
public class DataImport
|
||||||
{
|
{
|
||||||
public static (bool, KasAddressList) ImportKasAddressList(Uri pathToCsv, char separator = ',')
|
public static (bool, KasAddressList) ImportKasAddressList(Uri pathToCsv, AddressPatch patch = null,
|
||||||
|
char separator = ',')
|
||||||
{
|
{
|
||||||
|
// Prüfen, ob die Datei existiert
|
||||||
if (!File.Exists(pathToCsv.LocalPath))
|
if (!File.Exists(pathToCsv.LocalPath))
|
||||||
{
|
{
|
||||||
Console.WriteLine($"File not found: {pathToCsv}");
|
Console.WriteLine($"File not found: {pathToCsv}");
|
||||||
@@ -14,6 +16,8 @@ public class DataImport
|
|||||||
}
|
}
|
||||||
|
|
||||||
using var reader = new StreamReader(pathToCsv.LocalPath);
|
using var reader = new StreamReader(pathToCsv.LocalPath);
|
||||||
|
|
||||||
|
// Erste Zeile: CSV-Header lesen
|
||||||
var headerLine = reader.ReadLine();
|
var headerLine = reader.ReadLine();
|
||||||
if (headerLine == null)
|
if (headerLine == null)
|
||||||
{
|
{
|
||||||
@@ -21,7 +25,12 @@ public class DataImport
|
|||||||
return (false, null);
|
return (false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
var imported = new KasAddressList();
|
var headers = headerLine.Split(separator); // Header in Spaltennamen aufteilen (z. B. name, vorname, ort, ...)
|
||||||
|
|
||||||
|
// Neue Adressliste anlegen
|
||||||
|
var imported = new KasAddressList(Path.GetFileNameWithoutExtension(pathToCsv.LocalPath));
|
||||||
|
|
||||||
|
// Zeilenweise durchgehen
|
||||||
while (!reader.EndOfStream)
|
while (!reader.EndOfStream)
|
||||||
{
|
{
|
||||||
var line = reader.ReadLine();
|
var line = reader.ReadLine();
|
||||||
@@ -30,46 +39,67 @@ public class DataImport
|
|||||||
|
|
||||||
var parts = line.Split(separator);
|
var parts = line.Split(separator);
|
||||||
|
|
||||||
if (parts.Length < 24)
|
// Werte-Array vorbereiten – immer 24 Felder für KasPerson
|
||||||
|
var values = new string[24];
|
||||||
|
for (var i = 0; i < 24; i++)
|
||||||
|
if (i < parts.Length)
|
||||||
|
values[i] = parts[i];
|
||||||
|
else
|
||||||
|
values[i] = ""; // fehlende Spalten leer lassen
|
||||||
|
|
||||||
|
// Patch anwenden (falls vorhanden)
|
||||||
|
if (patch != null)
|
||||||
|
for (var i = 0; i < headers.Length; i++)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"No enough columns in line: {line}");
|
var header = headers[i].Trim(); // z. B. "name", "vorname", "ort"
|
||||||
continue;
|
|
||||||
|
// Das zugehörige Patch-Feld heißt z. B. "name_is"
|
||||||
|
var patchProperty = typeof(AddressPatch).GetProperty(header + "_is");
|
||||||
|
var hasProperty = typeof(AddressPatch).GetProperty("has_" + header);
|
||||||
|
|
||||||
|
if (patchProperty != null && hasProperty != null)
|
||||||
|
// Prüfen, ob das Patch-Feld aktiv ist
|
||||||
|
if ((bool)hasProperty.GetValue(patch))
|
||||||
|
// Dann den Wert aus dem Patch übernehmen
|
||||||
|
values[i] = (string)patchProperty.GetValue(patch);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// KasPerson erstellen – Reihenfolge der Werte muss mit dem Konstruktor übereinstimmen
|
||||||
var person = new KasPerson(
|
var person = new KasPerson(
|
||||||
ParseInt(parts[0]),
|
ParseInt(values[0]),
|
||||||
parts[1],
|
values[1],
|
||||||
parts[2],
|
values[2],
|
||||||
parts[3],
|
values[3],
|
||||||
parts[4],
|
values[4],
|
||||||
parts[5],
|
values[5],
|
||||||
parts[6],
|
values[6],
|
||||||
parts[7],
|
values[7],
|
||||||
parts[8],
|
values[8],
|
||||||
parts[9],
|
values[9],
|
||||||
ParseInt(parts[10]),
|
ParseInt(values[10]),
|
||||||
parts[11],
|
values[11],
|
||||||
parts[12],
|
values[12],
|
||||||
ParseInt(parts[13]),
|
ParseInt(values[13]),
|
||||||
parts[14],
|
values[14],
|
||||||
parts[15],
|
values[15],
|
||||||
parts[16],
|
values[16],
|
||||||
parts[17],
|
values[17],
|
||||||
parts[18],
|
values[18],
|
||||||
parts[19],
|
values[19],
|
||||||
parts[20],
|
values[20],
|
||||||
parts[21],
|
values[21],
|
||||||
parts[22],
|
values[22],
|
||||||
parts[23]
|
values[23]
|
||||||
);
|
);
|
||||||
|
|
||||||
imported.KasPersons.Add(person);
|
imported.KasPersons.Add(person);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Error while parsing line: {line} - {ex.Message}");
|
Console.WriteLine($"Error while parsing line: {line} - {ex.Message}");
|
||||||
Console.WriteLine($"{ex.StackTrace}");
|
Console.WriteLine(ex.StackTrace);
|
||||||
return (false, null);
|
return (false, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +107,7 @@ public class DataImport
|
|||||||
return (true, imported);
|
return (true, imported);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static int ParseInt(string input)
|
private static int ParseInt(string input)
|
||||||
{
|
{
|
||||||
return int.TryParse(input, out var result) ? result : 0;
|
return int.TryParse(input, out var result) ? result : 0;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
<ListBox Grid.Row="1"
|
<ListBox Grid.Row="1"
|
||||||
Margin="0,5,0,0"
|
Margin="0,5,0,0"
|
||||||
x:Name="LstCustomers"
|
x:Name="LstCustomers"
|
||||||
Background="AliceBlue"
|
Background="AliceBlue" SelectionChanged="LstCustomers_OnSelectionChanged"
|
||||||
SelectionMode="Single" />
|
SelectionMode="Single" />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
@@ -63,11 +63,13 @@
|
|||||||
|
|
||||||
<ListBox Grid.Row="1"
|
<ListBox Grid.Row="1"
|
||||||
x:Name="LstCustomerAdressSets"
|
x:Name="LstCustomerAdressSets"
|
||||||
|
SelectionChanged="LstCustomerAdressSets_OnSelectionChanged"
|
||||||
Background="AliceBlue"
|
Background="AliceBlue"
|
||||||
Margin="0,5,0,5"
|
Margin="0,5,0,5"
|
||||||
SelectionMode="Multiple,Toggle" />
|
SelectionMode="Multiple,Toggle" />
|
||||||
|
|
||||||
<Button Grid.Row="2" HorizontalAlignment="Stretch">
|
<Button Grid.Row="2" HorizontalAlignment="Stretch" x:Name="BtnCustomerAddressSetImport"
|
||||||
|
Click="BtnCustomerAddressSetImport_OnClick">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="Plus" Width="16" Height="16" Size="16" />
|
<LucideIcon Kind="Plus" Width="16" Height="16" Size="16" />
|
||||||
<Label Content="Importieren" VerticalContentAlignment="Center" />
|
<Label Content="Importieren" VerticalContentAlignment="Center" />
|
||||||
@@ -92,7 +94,7 @@
|
|||||||
<StackPanel Grid.Column="0" Width="250" Orientation="Vertical" HorizontalAlignment="Right"
|
<StackPanel Grid.Column="0" Width="250" Orientation="Vertical" HorizontalAlignment="Right"
|
||||||
Margin="0,0,5,0">
|
Margin="0,0,5,0">
|
||||||
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center"
|
<Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Center"
|
||||||
Margin="0,0,0,10"
|
Margin="0,0,0,10" IsEnabled="False"
|
||||||
x:Name="BtnCheck" Click="BtnCheck_OnClick">
|
x:Name="BtnCheck" Click="BtnCheck_OnClick">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="SpellCheck" Width="36" Height="36" />
|
<LucideIcon Kind="SpellCheck" Width="36" Height="36" />
|
||||||
@@ -100,7 +102,7 @@
|
|||||||
FontWeight="Bold" />
|
FontWeight="Bold" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
<Button HorizontalAlignment="Stretch" IsEnabled="True"
|
<Button HorizontalAlignment="Stretch" IsEnabled="False"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center"
|
||||||
Click="BtnCombine_OnClick" x:Name="BtnCombine"
|
Click="BtnCombine_OnClick" x:Name="BtnCombine"
|
||||||
Margin="0,0,0,10">
|
Margin="0,0,0,10">
|
||||||
@@ -111,7 +113,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
<Button HorizontalAlignment="Stretch" IsEnabled="False"
|
<Button HorizontalAlignment="Stretch" IsEnabled="False"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center" x:Name="BtnRepair"
|
||||||
Margin="0,0,0,10">
|
Margin="0,0,0,10">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="Hammer" Width="36" Height="36" />
|
<LucideIcon Kind="Hammer" Width="36" Height="36" />
|
||||||
@@ -123,7 +125,7 @@
|
|||||||
<StackPanel Grid.Column="1" Width="250" Orientation="Vertical" HorizontalAlignment="Left"
|
<StackPanel Grid.Column="1" Width="250" Orientation="Vertical" HorizontalAlignment="Left"
|
||||||
Margin="5,0,0,0">
|
Margin="5,0,0,0">
|
||||||
<Button HorizontalAlignment="Stretch" IsEnabled="False"
|
<Button HorizontalAlignment="Stretch" IsEnabled="False"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center" x:Name="BtnShorten"
|
||||||
Margin="0,0,0,10">
|
Margin="0,0,0,10">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="ListX" Width="36" Height="36" />
|
<LucideIcon Kind="ListX" Width="36" Height="36" />
|
||||||
@@ -132,7 +134,7 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
<Button HorizontalAlignment="Stretch" IsEnabled="False"
|
<Button HorizontalAlignment="Stretch" IsEnabled="False"
|
||||||
HorizontalContentAlignment="Center"
|
HorizontalContentAlignment="Center" x:Name="BtnGenerateLabels"
|
||||||
Margin="0,0,0,10">
|
Margin="0,0,0,10">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="Tags" Width="36" Height="36" />
|
<LucideIcon Kind="Tags" Width="36" Height="36" />
|
||||||
@@ -187,7 +189,7 @@
|
|||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<Grid ColumnDefinitions="400,*">
|
<Grid ColumnDefinitions="400,*">
|
||||||
<Label Grid.Column="0">config-Datei</Label>
|
<Label Grid.Column="0">config-Datei</Label>
|
||||||
<StackPanel Grid.Column="1" Orientation="Horizontal">
|
<StackPanel Grid.Column="1" Orientation="Horizontal" Spacing="5">
|
||||||
<TextBox x:Name="TbConfigPath" HorizontalAlignment="Stretch"
|
<TextBox x:Name="TbConfigPath" HorizontalAlignment="Stretch"
|
||||||
Watermark="/home/username/.config/logofclient/config.json" />
|
Watermark="/home/username/.config/logofclient/config.json" />
|
||||||
<Button>
|
<Button>
|
||||||
@@ -211,8 +213,10 @@
|
|||||||
</TabItem.Header>
|
</TabItem.Header>
|
||||||
<Grid ColumnDefinitions="300,*">
|
<Grid ColumnDefinitions="300,*">
|
||||||
<Grid RowDefinitions="*,60">
|
<Grid RowDefinitions="*,60">
|
||||||
<ListBox x:Name="LstSettingsCustomers" />
|
<ListBox x:Name="LstSettingsCustomers"
|
||||||
<Button Grid.Row="1" HorizontalAlignment="Stretch"
|
SelectionChanged="LstSettingsCustomers_OnSelectionChanged" />
|
||||||
|
<Button Grid.Row="1" HorizontalAlignment="Stretch" x:Name="BtnSettingsAddCustomer"
|
||||||
|
Click="BtnSettingsAddCustomer_OnClick"
|
||||||
HorizontalContentAlignment="Center">
|
HorizontalContentAlignment="Center">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="Plus" Width="32" Height="32" />
|
<LucideIcon Kind="Plus" Width="32" Height="32" />
|
||||||
@@ -230,6 +234,7 @@
|
|||||||
<Grid ColumnDefinitions="150,*">
|
<Grid ColumnDefinitions="150,*">
|
||||||
<Label Content="Name" />
|
<Label Content="Name" />
|
||||||
<TextBox Grid.Column="1" Watermark="Kundenbezeichnung"
|
<TextBox Grid.Column="1" Watermark="Kundenbezeichnung"
|
||||||
|
TextChanged="TbSettingsCustomerName_OnTextChanged"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
x:Name="TbSettingsCustomerName" />
|
x:Name="TbSettingsCustomerName" />
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -237,6 +242,7 @@
|
|||||||
<Label Content="Beschreibung" />
|
<Label Content="Beschreibung" />
|
||||||
<TextBox Grid.Column="1" Watermark="Kundenbeschreibung"
|
<TextBox Grid.Column="1" Watermark="Kundenbeschreibung"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
|
TextChanged="TbSettingsCustomerDescription_OnTextChanged"
|
||||||
x:Name="TbSettingsCustomerDescription" />
|
x:Name="TbSettingsCustomerDescription" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid ColumnDefinitions="150,*">
|
<Grid ColumnDefinitions="150,*">
|
||||||
@@ -246,6 +252,8 @@
|
|||||||
x:Name="TbSettingsCustomerPatchInfo" />
|
x:Name="TbSettingsCustomerPatchInfo" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Button HorizontalAlignment="Stretch"
|
<Button HorizontalAlignment="Stretch"
|
||||||
|
x:Name="BtnSettingsImportCustomerAddressPatch"
|
||||||
|
Click="BtnSettingsImportCustomerAddressPatch_OnClick"
|
||||||
HorizontalContentAlignment="Center">
|
HorizontalContentAlignment="Center">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
<LucideIcon Kind="Route" Width="16" Height="16" Size="16" />
|
<LucideIcon Kind="Route" Width="16" Height="16" Size="16" />
|
||||||
@@ -253,6 +261,15 @@
|
|||||||
VerticalContentAlignment="Center" />
|
VerticalContentAlignment="Center" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button HorizontalAlignment="Stretch" x:Name="BtnSettingsSaveCustomerData"
|
||||||
|
Click="BtnSettingsSaveCustomerData_OnClick"
|
||||||
|
HorizontalContentAlignment="Center">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<LucideIcon Kind="Save" Width="16" Height="16" Size="16" />
|
||||||
|
<Label FontSize="16" Content="Speichern"
|
||||||
|
VerticalContentAlignment="Center" />
|
||||||
|
</StackPanel>
|
||||||
|
</Button>
|
||||||
<Button Background="#99963434" HorizontalAlignment="Stretch"
|
<Button Background="#99963434" HorizontalAlignment="Stretch"
|
||||||
HorizontalContentAlignment="Center">
|
HorizontalContentAlignment="Center">
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
|
|||||||
@@ -18,23 +18,26 @@ public partial class MainWindow : Window
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_instance = this;
|
_instance = this;
|
||||||
WindowState = WindowState.Maximized;
|
WindowState = WindowState.Maximized;
|
||||||
|
Global.Load();
|
||||||
|
Settings.Load();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void StartAddressCheck(Uri path)
|
private async void StartAddressCheck(KasAddressList addresses)
|
||||||
{
|
{
|
||||||
var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier
|
//var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier
|
||||||
|
|
||||||
var progressWindow = new ProgressWindow();
|
var progressWindow = new ProgressWindow();
|
||||||
|
|
||||||
progressWindow.Show(_instance);
|
progressWindow.Show(_instance);
|
||||||
|
|
||||||
var processor = new AddressCheck(progressWindow);
|
var processor = new AddressCheck(progressWindow);
|
||||||
var result = await processor.Perform(addresses.Item2);
|
var result = await processor.Perform(addresses);
|
||||||
|
|
||||||
|
|
||||||
progressWindow.Close();
|
progressWindow.Close();
|
||||||
|
|
||||||
|
|
||||||
new ResultWindow(result, addresses.Item2).Show();
|
new ResultWindow(result, addresses).Show();
|
||||||
//await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
|
//await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,13 +108,18 @@ public partial class MainWindow : Window
|
|||||||
|
|
||||||
private void BtnCheck_OnClick(object? sender, RoutedEventArgs e)
|
private void BtnCheck_OnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (filePath == null)
|
if (LstCustomerAdressSets.SelectedIndex == -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show(null, "Bitte zunächst eine Datei auswählen", "Datei fehlt");
|
MessageBox.Show(null, "Bitte zunächst ein Adress-Set auswählen", "Kein Adress-Set ausgewählt");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StartAddressCheck(filePath);
|
var set = new KasAddressList("");
|
||||||
|
foreach (var adset in Settings._instance.addressSets.addresses)
|
||||||
|
if (adset.Name == LstCustomerAdressSets.SelectedItem.ToString())
|
||||||
|
set = adset;
|
||||||
|
|
||||||
|
StartAddressCheck(set);
|
||||||
// var result = DataImport.ImportKasAddressList(filePath);
|
// var result = DataImport.ImportKasAddressList(filePath);
|
||||||
// if (result.Item1)
|
// if (result.Item1)
|
||||||
// {
|
// {
|
||||||
@@ -209,4 +217,185 @@ public partial class MainWindow : Window
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BtnSettingsAddCustomer_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Settings._instance.customers.customers.Add(new Customer());
|
||||||
|
TbSettingsCustomerDescription.Text = "";
|
||||||
|
TbSettingsCustomerName.Text = "";
|
||||||
|
TbSettingsCustomerPatchInfo.Text = "";
|
||||||
|
//Settings.Save();
|
||||||
|
//RefreshCustomerItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TbSettingsCustomerName_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
if (customer.ID == Settings._instance.customers.current)
|
||||||
|
customer.name = TbSettingsCustomerName.Text;
|
||||||
|
//Settings.Save();
|
||||||
|
//RefreshCustomerItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LstSettingsCustomers_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (LstSettingsCustomers.SelectedIndex < 0) return;
|
||||||
|
Settings._instance.customers.current =
|
||||||
|
Customer.GetIDByCustomerListItem(LstSettingsCustomers.SelectedItems[0].ToString());
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
if (customer.ID == Settings._instance.customers.current)
|
||||||
|
{
|
||||||
|
TbSettingsCustomerDescription.Text = customer.description;
|
||||||
|
TbSettingsCustomerName.Text = customer.name;
|
||||||
|
if (customer.patch != null)
|
||||||
|
TbSettingsCustomerPatchInfo.Text = customer.patch.ToString();
|
||||||
|
else
|
||||||
|
TbSettingsCustomerPatchInfo.Text = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RefreshCustomerItems()
|
||||||
|
{
|
||||||
|
if (LstCustomers.Items.Count > 0)
|
||||||
|
LstCustomers.SelectedIndex = -1;
|
||||||
|
else
|
||||||
|
LstCustomers.SelectedItem = null;
|
||||||
|
|
||||||
|
LstCustomers.Items.Clear();
|
||||||
|
if (LstSettingsCustomers.Items.Count > 0)
|
||||||
|
LstSettingsCustomers.SelectedIndex = -1;
|
||||||
|
else
|
||||||
|
LstSettingsCustomers.SelectedItem = null;
|
||||||
|
|
||||||
|
LstSettingsCustomers.Items.Clear();
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
{
|
||||||
|
LstCustomers.Items.Add(customer.ID + " - " + customer.name);
|
||||||
|
LstSettingsCustomers.Items.Add(customer.ID + " - " + customer.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TbSettingsCustomerDescription_OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||||
|
{
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
if (customer.ID == Settings._instance.customers.current)
|
||||||
|
customer.description = TbSettingsCustomerDescription.Text;
|
||||||
|
//Settings.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BtnSettingsSaveCustomerData_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
Settings.Save();
|
||||||
|
RefreshCustomerItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LstCustomers_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (LstCustomers.SelectedItems == null || LstCustomers.SelectedIndex == -1) return;
|
||||||
|
var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]);
|
||||||
|
RefreshAddressSetListItems(customer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void BtnCustomerAddressSetImport_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var opts = new FilePickerOpenOptions();
|
||||||
|
opts.Title = "Address-Set importieren...";
|
||||||
|
opts.AllowMultiple = false;
|
||||||
|
|
||||||
|
var type = new FilePickerFileType("CSV-Dateien (*.csv)");
|
||||||
|
type.Patterns = new[] { "*.csv" };
|
||||||
|
opts.FileTypeFilter = new[] { type };
|
||||||
|
|
||||||
|
var paths = await StorageProvider.OpenFilePickerAsync(opts);
|
||||||
|
|
||||||
|
if (paths?.Count <= 0) return;
|
||||||
|
|
||||||
|
if (LstCustomers.SelectedIndex < 0) return;
|
||||||
|
|
||||||
|
|
||||||
|
var selected_path = paths[0].Path;
|
||||||
|
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
if (customer.ID == Customer.GetIDByCustomerListItem(LstCustomers.SelectedItems[0].ToString()))
|
||||||
|
if (customer.patch == null)
|
||||||
|
{
|
||||||
|
var got = DataImport.ImportKasAddressList(selected_path, customer.patch);
|
||||||
|
if (!got.Item1)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error while importing. Please try another file.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
got.Item2.SetOwner(customer.ID);
|
||||||
|
Settings._instance.addressSets.addresses.Add(got.Item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
var customer_id = int.Parse(LstCustomers.SelectedItem.ToString().Split(" - ")[0]);
|
||||||
|
RefreshAddressSetListItems(customer_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Settings.Save();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RefreshAddressSetListItems(int customer_id)
|
||||||
|
{
|
||||||
|
if (LstCustomers.SelectedIndex < 0) return;
|
||||||
|
LstCustomerAdressSets.SelectedItems = null;
|
||||||
|
LstCustomerAdressSets.Items.Clear();
|
||||||
|
foreach (var k in Settings._instance.addressSets.addresses)
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
if (customer.ID == k.owner_id && customer.ID == customer_id)
|
||||||
|
LstCustomerAdressSets.Items.Add(k.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LstCustomerAdressSets_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (LstCustomerAdressSets.SelectedItems == null || LstCustomerAdressSets.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
BtnCheck.IsEnabled = false;
|
||||||
|
BtnCombine.IsEnabled = false;
|
||||||
|
|
||||||
|
BtnGenerateLabels.IsEnabled = false;
|
||||||
|
BtnRepair.IsEnabled = false;
|
||||||
|
BtnShorten.IsEnabled = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
BtnCheck.IsEnabled = true;
|
||||||
|
BtnCombine.IsEnabled = true;
|
||||||
|
|
||||||
|
// BtnGenerateLabels.IsEnabled = true;
|
||||||
|
// BtnRepair.IsEnabled = true;
|
||||||
|
// BtnShorten.IsEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void BtnSettingsImportCustomerAddressPatch_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (LstSettingsCustomers.SelectedIndex == null || LstSettingsCustomers.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
var opts = new FilePickerOpenOptions();
|
||||||
|
opts.Title = "Address-Patch für " + LstSettingsCustomers.SelectedItems[0] + "importieren...";
|
||||||
|
opts.AllowMultiple = false;
|
||||||
|
|
||||||
|
var type = new FilePickerFileType("ADPAC-Dateien (*.adpac)");
|
||||||
|
type.Patterns = new[] { "*.adpac" };
|
||||||
|
opts.FileTypeFilter = new[] { type };
|
||||||
|
|
||||||
|
var paths = await StorageProvider.OpenFilePickerAsync(opts);
|
||||||
|
|
||||||
|
if (paths?.Count <= 0) return;
|
||||||
|
|
||||||
|
if (LstSettingsCustomers.SelectedIndex < 0) return;
|
||||||
|
|
||||||
|
|
||||||
|
var selected_path = paths[0].Path;
|
||||||
|
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
if (customer.ID == Customer.GetIDByCustomerListItem(LstSettingsCustomers.SelectedItems[0].ToString()))
|
||||||
|
customer.patch = AddressPatch.Import(selected_path);
|
||||||
|
|
||||||
|
|
||||||
|
Settings.Save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
137
Settings.cs
Normal file
137
Settings.cs
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Logof_Client;
|
||||||
|
|
||||||
|
public class Settings
|
||||||
|
{
|
||||||
|
public static Settings _instance = new();
|
||||||
|
public AddressSets addressSets = new();
|
||||||
|
public Customers customers = new();
|
||||||
|
|
||||||
|
public string settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"logofclient", "config.json");
|
||||||
|
|
||||||
|
public Settings()
|
||||||
|
{
|
||||||
|
_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void Save()
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"logofclient")))
|
||||||
|
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"logofclient"));
|
||||||
|
if (!string.IsNullOrEmpty(Global._instance.config_path)) _instance.settingsPath = Global._instance.config_path;
|
||||||
|
|
||||||
|
var json = JsonConvert.SerializeObject(_instance);
|
||||||
|
File.WriteAllText(_instance.settingsPath, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Load()
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(Global._instance.config_path)) _instance.settingsPath = Global._instance.config_path;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var contents = File.ReadAllText(_instance.settingsPath);
|
||||||
|
_instance = JsonConvert.DeserializeObject<Settings>(contents);
|
||||||
|
MainWindow._instance.RefreshCustomerItems();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
Console.WriteLine(ex.StackTrace);
|
||||||
|
Console.WriteLine("Error while reading settings. Generating new...");
|
||||||
|
_instance = new Settings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Global
|
||||||
|
{
|
||||||
|
public static Global _instance;
|
||||||
|
|
||||||
|
public Global()
|
||||||
|
{
|
||||||
|
_instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string config_path { get; set; } = "";
|
||||||
|
|
||||||
|
public static void Save()
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"logofclient")))
|
||||||
|
Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"logofclient"));
|
||||||
|
var json = JsonConvert.SerializeObject(_instance, Formatting.Indented);
|
||||||
|
File.WriteAllText(
|
||||||
|
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
||||||
|
"global.config"), json);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Load()
|
||||||
|
{
|
||||||
|
// if (!File.Exists(Path.Combine(
|
||||||
|
// Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
||||||
|
// "global.config")))
|
||||||
|
// File.Create(Path.Combine(
|
||||||
|
// Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
||||||
|
// "global.config"));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var contents = File.ReadAllText(Path.Combine(
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "logofclient",
|
||||||
|
"global.config"));
|
||||||
|
_instance = JsonConvert.DeserializeObject<Global>(contents);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.Message);
|
||||||
|
Console.WriteLine(ex.StackTrace);
|
||||||
|
Console.WriteLine("Error while reading global settings. Generating new...");
|
||||||
|
_instance = new Global();
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Customers
|
||||||
|
{
|
||||||
|
public List<Customer> customers = new();
|
||||||
|
public int current { get; set; } = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Customer
|
||||||
|
{
|
||||||
|
public Customer()
|
||||||
|
{
|
||||||
|
var highestID = 0;
|
||||||
|
foreach (var customer in Settings._instance.customers.customers)
|
||||||
|
if (customer.ID > highestID)
|
||||||
|
highestID = customer.ID;
|
||||||
|
|
||||||
|
ID = highestID + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string name { get; set; } = "";
|
||||||
|
public string description { get; set; } = "";
|
||||||
|
public AddressPatch patch { get; set; }
|
||||||
|
public int ID { get; }
|
||||||
|
|
||||||
|
public static int GetIDByCustomerListItem(string item_content)
|
||||||
|
{
|
||||||
|
var id = item_content.Split(" - ")[0];
|
||||||
|
return int.Parse(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AddressSets
|
||||||
|
{
|
||||||
|
public List<KasAddressList> addresses = new();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user