[struc:] moved KasPersonError-Instance from addressset to KasPerson-Instance

This commit is contained in:
Elias Fierke
2025-12-07 13:30:25 +01:00
parent 8c56717b9c
commit b70bd5e324
3 changed files with 82 additions and 89 deletions

View File

@@ -5,7 +5,7 @@ namespace Logof_Client;
public class KasAddressList //Address-Set
{
public List<KasPersonError> errors = new();
//public List<KasPersonError> errors = new();
public List<KasPerson> KasPersons;
public KasAddressList(string name)
@@ -13,12 +13,9 @@ public class KasAddressList //Address-Set
KasPersons = new List<KasPerson>();
Name = name;
foreach (var set in Settings._instance.addressSets.addresses)
{
if (Name == set.Name)
{
Name = name + "-new";
}
}
var highest = 0;
foreach (var k in Settings._instance.addressSets.addresses)
if (highest <= k.ID)
@@ -37,17 +34,20 @@ public class KasAddressList //Address-Set
public static string GenerateName(string basic_type, bool? is_rest = false)
{
if(is_rest == true)
if (is_rest == true)
return basic_type + " - " + DateTime.Now.ToShortDateString() + " - Rest";
else
return basic_type + " - " + DateTime.Now.ToShortDateString();
return basic_type + " - " + DateTime.Now.ToShortDateString();
}
public void UpdateErrorList(List<(int, List<AddressCheck.ErrorTypes>, List<AddressCheck.WarningTypes>)> errorList)
{
errors.Clear();
foreach (var error in errorList) errors.Add(new KasPersonError(error));
}
// public void UpdateErrorList(List<KasPersonError> errorList)
// {
// //errors.Clear();
// // foreach (KasPersonError err in errorList)
// // {
// //
// // }
// //foreach (var error in errorList) errors.Add(new KasPersonError(error));
// }
public static int GetIDByAddressSetListItem(string listItemName)
{
@@ -58,6 +58,8 @@ public class KasAddressList //Address-Set
public class KasPerson
{
public KasPersonError PersonError = null;
public KasPerson()
{
refsid = 0;
@@ -165,37 +167,14 @@ public class KasPerson
public class KasPersonError
{
public KasPersonError((int, List<AddressCheck.ErrorTypes>, List<AddressCheck.WarningTypes>) single_result)
public KasPersonError((List<AddressCheck.ErrorTypes>, List<AddressCheck.WarningTypes>) single_result)
{
refsid = single_result.Item1;
errors = single_result.Item2;
warnings = single_result.Item3;
// try
// {
// foreach (var err in single_result.Item2) errors += err + ", ";
// errors = errors.Trim();
// errors = errors.TrimEnd(',');
// }
// catch
// {
// }
//
// try
// {
// if (single_result.Item3 != null)
// {
// foreach (var err in single_result.Item3) warnings += err + ", ";
// warnings = warnings.Trim();
// warnings = warnings.TrimEnd(',');
// }
// }
// catch (Exception e)
// {
// Console.WriteLine(e.Message);
// }
//refsid = single_result.Item1;
errors = single_result.Item1;
warnings = single_result.Item2;
}
public int refsid { get; set; }
//public int refsid { get; set; }
public List<AddressCheck.ErrorTypes> errors { get; set; } = new();
public List<AddressCheck.WarningTypes> warnings { get; set; } = new();
}

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
@@ -11,10 +12,10 @@ public partial class ResultWindow : Window
{
public List<CheckBox> errortypecheckboxes = new();
public KasAddressList ur_addresses = new("Ergebnis_" + DateTime.Now.ToString("ddMMyy_HHmmss"));
public List<KasPersonError> ur_result;
public List<KasPerson> ur_result;
public List<CheckBox> warningtypecheckboxes = new();
public ResultWindow(List<KasPersonError> result,
public ResultWindow(List<KasPerson> result,
int addressSetID)
{
InitializeComponent();
@@ -24,12 +25,12 @@ public partial class ResultWindow : Window
//ViewSingle(200552426);
}
private void GenerateView(List<KasPersonError> result)
private void GenerateView(List<KasPerson> result)
{
// var errors = new List<KasPersonError>();
//foreach (var single_result in result) errors.Add(single_result);
LblResultCount.Content = $"{result.Count}/{ur_result.Count} Ergebnisse";
DgResult.ItemsSource = result;
// Filter to only show persons with errors
var result_with_errors = result.Where(p => p.PersonError != null).ToList();
LblResultCount.Content = $"{result_with_errors.Count}/{ur_result.Count} Ergebnisse";
DgResult.ItemsSource = result_with_errors;
}
private void ViewSingle(int refsid)
@@ -62,18 +63,20 @@ public partial class ResultWindow : Window
}
}
private void Load(List<KasPersonError> result)
private void Load(List<KasPerson> result)
{
var knownErrors = new List<AddressCheck.ErrorTypes>();
var knownWarnings = new List<AddressCheck.WarningTypes>();
foreach (var single_result in result)
foreach (var person in result)
{
foreach (var errtyp in single_result.errors)
if (person.PersonError == null) continue;
foreach (var errtyp in person.PersonError.errors)
if (!knownErrors.Contains(errtyp))
knownErrors.Add(errtyp);
foreach (var wartyp in single_result.warnings)
foreach (var wartyp in person.PersonError.warnings)
if (!knownWarnings.Contains(wartyp))
knownWarnings.Add(wartyp);
}
@@ -108,7 +111,7 @@ public partial class ResultWindow : Window
private void UpdateFilter()
{
var temp_result = new List<KasPersonError>();
var temp_result = new List<KasPerson>();
var checked_types = new List<AddressCheck.ErrorTypes>();
var checked_types_war = new List<AddressCheck.WarningTypes>();
foreach (var cb in errortypecheckboxes)
@@ -121,21 +124,19 @@ public partial class ResultWindow : Window
checked_types_war.Add(
(AddressCheck.WarningTypes)Enum.Parse(typeof(AddressCheck.WarningTypes), cb.Content.ToString()));
foreach (var sres in ur_result)
foreach (var person in ur_result)
{
foreach (var err in sres.errors)
if (checked_types.Contains(err) && !temp_result.Contains(sres))
temp_result.Add(sres);
if (person.PersonError == null) continue;
foreach (var war in sres.warnings)
if (checked_types_war.Contains(war) && !temp_result.Contains(sres))
temp_result.Add(sres);
foreach (var err in person.PersonError.errors)
if (checked_types.Contains(err) && !temp_result.Contains(person))
temp_result.Add(person);
foreach (var war in person.PersonError.warnings)
if (checked_types_war.Contains(war) && !temp_result.Contains(person))
temp_result.Add(person);
}
//var errors = new List<KasPersonError>();
//foreach (var single_result in temp_result) errors.Add(new KasPersonError(single_result));
LblResultCount.Content = $"{temp_result.Count}/{ur_result.Count} Ergebnisse";
DgResult.ItemsSource = temp_result;
}
@@ -145,7 +146,7 @@ public partial class ResultWindow : Window
foreach (var selected in DgResult.SelectedItems)
try
{
var _asKas = (KasPersonError)selected;
var _asKas = (KasPerson)selected;
ViewSingle(_asKas.refsid);
}
catch (Exception ex)

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Threading;
@@ -35,24 +36,32 @@ public class AddressCheck
_progress = progressWindow;
}
public async Task<List<KasPersonError>> Perform(int id)
public async Task<List<KasPerson>> Perform(int id)
{
foreach (var adset in Settings._instance.addressSets.addresses)
if (adset.ID == id)
// Find the index of the address set with the given id
var adset_index = -1;
for (var i = 0; i < Settings._instance.addressSets.addresses.Count; i++)
if (Settings._instance.addressSets.addresses[i].ID == id)
{
var failed_refsids = new List<KasPersonError>();
var total = adset.KasPersons.Count;
var current = 0;
adset_index = i;
break;
}
await Task.Run(async () =>
{
foreach (var person in adset.KasPersons)
{
var errors = new List<ErrorTypes>();
var warnings = new List<WarningTypes>();
var hasFaults = false;
if (adset_index == -1) return new List<KasPerson>();
var address_component_count = 2; // cause anrede and name are first
var adset = Settings._instance.addressSets.addresses[adset_index];
var total = adset.KasPersons.Count;
var current = 0;
await Task.Run(async () =>
{
foreach (var person in adset.KasPersons)
{
var errors = new List<ErrorTypes>();
var warnings = new List<WarningTypes>();
var hasFaults = false;
var address_component_count = 2; // cause anrede and name are first
// PLZ-Prüfung
if (person.plz == "" || person.plz == null)
@@ -92,13 +101,12 @@ public class AddressCheck
}
else
{
if (!AddressCreator.CheckPLZ(person.pplz, person.land))
{
hasFaults = true;
errors.Add(ErrorTypes.PPlzNotUsable);
}
// if ((person.pplz < 10000 && string.IsNullOrWhiteSpace(person.land)) ||
// (person.pplz < 10000 && person.land == "GER") ||
// (person.pplz < 10000 && person.land == "DE"))
@@ -224,9 +232,13 @@ public class AddressCheck
}
if (hasFaults)
lock (failed_refsids)
lock (Settings._instance.addressSets.addresses)
{
failed_refsids.Add(new KasPersonError((person.refsid, errors, warnings)));
// Directly set PersonError in the address set
var person_index = adset.KasPersons.IndexOf(person);
if (person_index >= 0)
Settings._instance.addressSets.addresses[adset_index].KasPersons[person_index].PersonError =
new KasPersonError((errors, warnings));
}
// Fortschritt aktualisieren
@@ -241,11 +253,12 @@ public class AddressCheck
});
}
});
adset.errors = failed_refsids;
Settings.Save();
return failed_refsids;
}
return null;
Settings.Save();
// Return only the persons with errors from the address set
return Settings._instance.addressSets.addresses[adset_index].KasPersons
.Where(p => p.PersonError != null)
.ToList();
}
}