diff --git a/DataStructures.cs b/DataStructures.cs index 171c746..4c6e2c0 100644 --- a/DataStructures.cs +++ b/DataStructures.cs @@ -5,7 +5,7 @@ namespace Logof_Client; public class KasAddressList //Address-Set { - public List errors = new(); + //public List errors = new(); public List KasPersons; public KasAddressList(string name) @@ -13,12 +13,9 @@ public class KasAddressList //Address-Set KasPersons = new List(); 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, List)> errorList) - { - errors.Clear(); - foreach (var error in errorList) errors.Add(new KasPersonError(error)); - } + // public void UpdateErrorList(List 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, List) single_result) + public KasPersonError((List, List) 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 errors { get; set; } = new(); public List warnings { get; set; } = new(); } \ No newline at end of file diff --git a/ResultWindow.axaml.cs b/ResultWindow.axaml.cs index 905b3d6..d9586ab 100644 --- a/ResultWindow.axaml.cs +++ b/ResultWindow.axaml.cs @@ -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 errortypecheckboxes = new(); public KasAddressList ur_addresses = new("Ergebnis_" + DateTime.Now.ToString("ddMMyy_HHmmss")); - public List ur_result; + public List ur_result; public List warningtypecheckboxes = new(); - public ResultWindow(List result, + public ResultWindow(List result, int addressSetID) { InitializeComponent(); @@ -24,12 +25,12 @@ public partial class ResultWindow : Window //ViewSingle(200552426); } - private void GenerateView(List result) + private void GenerateView(List result) { - // var errors = new List(); - //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 result) + private void Load(List result) { var knownErrors = new List(); var knownWarnings = new List(); - 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(); + var temp_result = new List(); var checked_types = new List(); var checked_types_war = new List(); 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(); - //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) diff --git a/Tasks/AddressCheck.cs b/Tasks/AddressCheck.cs index 0d4e3b6..3cc96e8 100644 --- a/Tasks/AddressCheck.cs +++ b/Tasks/AddressCheck.cs @@ -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> Perform(int id) + public async Task> 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(); - 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(); - var warnings = new List(); - var hasFaults = false; + if (adset_index == -1) return new List(); - 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(); + var warnings = new List(); + 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(); } } \ No newline at end of file