4 Commits

Author SHA1 Message Date
fierke a46539c3cc [fix:] wrong sorting of imported address sets 2026-05-06 06:35:23 +02:00
fierke 72a5630db1 [chore:] enable shortener usage 2026-05-06 06:34:48 +02:00
fierke 7697edac5e [fix:] shorten-button was enabled too early 2026-05-06 06:33:55 +02:00
fierke 028b9793db [chore:] basic address shortener 2026-05-06 06:33:37 +02:00
3 changed files with 115 additions and 2 deletions
+1 -1
View File
@@ -121,7 +121,7 @@
FontWeight="Bold" /> FontWeight="Bold" />
</StackPanel> </StackPanel>
</Button> </Button>
<Button Width="250" IsEnabled="False" <Button Width="250" IsEnabled="False" Click="BtnShorten_OnClick"
HorizontalContentAlignment="Center" x:Name="BtnShorten" HorizontalContentAlignment="Center" x:Name="BtnShorten"
Margin="0,0,0,10"> Margin="0,0,0,10">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
+35 -1
View File
@@ -96,7 +96,28 @@ public partial class MainWindow : Window
new ResultWindow(result, addresSetID).Show(); new ResultWindow(result, addresSetID).Show();
Settings.Save();
//await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
}
private async void StartAddressShortener(KasAddressList set)
{
//var addresses = DataImport.ImportKasAddressList(path); // Ihr Code hier
var progressWindow = new ProgressWindow();
progressWindow.Show(_instance);
var processor = new AddressShortener(progressWindow);
await processor.Perform(set);
// foreach (var item in result)
// {
// }
progressWindow.Close();
Settings.Save();
//await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig"); //await MessageBox.Show(_instance, $"{result.Count} Einträge fehlerhaft.", "Fertig");
} }
@@ -543,7 +564,7 @@ public partial class MainWindow : Window
var selected_path = paths[0].Path; var selected_path = paths[0].Path;
foreach (var customer in Settings._instance.customers.customers) foreach (var customer in Settings._instance.customers.customers)
if (customer.ID == ((Customer)LstSettingsCustomers.SelectedItems[0]).ID) if (customer == ((Customer)LstCustomers.SelectedItems[0]))
{ {
if (customer.patch == null) if (customer.patch == null)
{ {
@@ -617,6 +638,7 @@ public partial class MainWindow : Window
BtnCheck.IsEnabled = true; BtnCheck.IsEnabled = true;
BtnCombine.IsEnabled = true; BtnCombine.IsEnabled = true;
BtnGenerateLabels.IsEnabled = true; BtnGenerateLabels.IsEnabled = true;
BtnShorten.IsEnabled = true;
// BtnRepair.IsEnabled = true; // BtnRepair.IsEnabled = true;
// BtnShorten.IsEnabled = true; // BtnShorten.IsEnabled = true;
@@ -1086,4 +1108,16 @@ public partial class MainWindow : Window
} }
RefreshCustomerItems(); RefreshCustomerItems();
} }
private void BtnShorten_OnClick(object? sender, RoutedEventArgs e)
{
MakeCalcManVisible();
if (LstCustomerAdressSets.SelectedIndex == -1)
{
MessageBox.Show(null, "Bitte zunächst ein Adress-Set auswählen", "Kein Adress-Set ausgewählt");
return;
}
StartAddressShortener((KasAddressList)LstCustomerAdressSets.SelectedItem);
}
} }
+79
View File
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace Logof_Client;
public class AddressShortener(ProgressWindow progressWindow)
{
private readonly ProgressWindow _progress = progressWindow;
public async Task Perform(KasAddressList list)
{
// find doubled addresses by refsid
List<int> doubled_ids = new List<int>();
for (int i = 0; i < list.KasPersons.Count; i++)
{
var address = list.KasPersons[i];
for (int j = 0; j < list.KasPersons.Count; j++)
{
if (i == j) continue;
var sec_address = list.KasPersons[j];
if (address.refsid == sec_address.refsid && !doubled_ids.Contains(address.refsid) && address.refsid != 0)
{
doubled_ids.Add(address.refsid);
}
}
}
// delete doubled addresses by refsid
foreach (int id in doubled_ids)
{
// does this remove both of the doubled addresses?
list.KasPersons.Remove(list.KasPersons.FirstOrDefault(x => x.refsid == id));
}
List<int> toRemove = new List<int>();
foreach (var address in list.KasPersons)
{
try
{
if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.NoPLZorPPLZ))
{
toRemove.Add(address.id);
}
else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PlzNotUsable) &&
address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PPlzNotUsable))
{
toRemove.Add(address.id);
} else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PlzNotUsable) &&
address.PersonError.warnings.Contains(AddressCheck.WarningTypes.NoPPLZ))
{
toRemove.Add(address.id);
}
else if (address.PersonError.errors.Contains(AddressCheck.ErrorTypes.PPlzNotUsable) &&
address.PersonError.warnings.Contains(AddressCheck.WarningTypes.NoPLZ))
{
toRemove.Add(address.id);
}
}
catch
{
Console.WriteLine("PersonError not accessible: " + address.id);
}
}
// delete doubled addresses by refsid
foreach (int id in toRemove)
{
// does this remove both of the doubled addresses?
list.KasPersons.Remove(list.KasPersons.Find(x => x.id == id));
}
//return null;
}
}