diff --git a/WGneu/Helpers/Utils.cs b/WGneu/Helpers/Utils.cs index f27a78f..4d181cf 100644 --- a/WGneu/Helpers/Utils.cs +++ b/WGneu/Helpers/Utils.cs @@ -61,5 +61,9 @@ namespace WGneu.Helpers { UseShellExecute = true, }); } + + public static bool MgNrExists(AppDbContext ctx, int mgnr) { + return ctx.Members.Find(mgnr) != null; + } } } diff --git a/WGneu/Helpers/Validator.cs b/WGneu/Helpers/Validator.cs index 315faa3..c5e3e39 100644 --- a/WGneu/Helpers/Validator.cs +++ b/WGneu/Helpers/Validator.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Windows.Controls; +using WGneu.Models; namespace WGneu.Helpers { static class Validator { @@ -29,11 +30,11 @@ namespace WGneu.Helpers { { "423", Array.Empty() }, }; - public static ValidationResult CheckNumericInput(TextBox input, bool optional) { - return CheckNumericInput(input, optional, -1); + public static ValidationResult CheckNumeric(TextBox input, bool optional) { + return CheckNumeric(input, optional, -1); } - private static ValidationResult CheckNumericInput(TextBox input, bool optional, int maxLen) { + private static ValidationResult CheckNumeric(TextBox input, bool optional, int maxLen) { string text = ""; int pos = input.CaretIndex; for (int i = 0; i < input.Text.Length; i++) { @@ -60,7 +61,7 @@ namespace WGneu.Helpers { } public static ValidationResult CheckPlz(TextBox input, bool optional) { - CheckNumericInput(input, true, 4); + CheckNumeric(input, true, 4); if (optional && input.Text.Length == 0) { return new(true, null); } else if (input.Text.Length != 4) { @@ -235,21 +236,51 @@ namespace WGneu.Helpers { } public static ValidationResult CheckLfbisNr(TextBox input, bool optional) { - var res = CheckNumericInput(input, true, 7); - if (!res.IsValid) + var res = CheckNumeric(input, true, 7); + if (!res.IsValid) { return res; - if (optional && input.Text.Length == 0) + } else if (optional && input.Text.Length == 0) { return new(true, null); - if (input.Text.Length != 7) + } else if (input.Text.Length != 7) { return new(false, "Betriebsnummer zu kurz"); + } // TODO return new(true, "Not implemented yet"); } - public static ValidationResult CheckUstIdInput(TextBox input, bool optional) { + public static ValidationResult CheckUstId(TextBox input, bool optional) { return new(false, "Not implemented yet"); } + + public static ValidationResult CheckMgNr(TextBox input, bool optional, AppDbContext ctx, Member m) { + var res = CheckNumeric(input, optional); + if (!res.IsValid) { + return res; + } else if (optional && input.Text.Length == 0) { + return new(true, null); + } + + int nr = int.Parse(input.Text); + if (nr != m.MgNr && Utils.MgNrExists(ctx, nr)) { + return new(false, "Mitgliedsnummer wird bereits verwendet"); + } + + return new(true, null); + } + + public static ValidationResult CheckPredecessorMgNr(TextBox input, bool optional, AppDbContext ctx) { + var res = CheckNumeric(input, optional); + if (!res.IsValid) { + return res; + } else if (optional && input.Text.Length == 0) { + return new(true, null); + } else if (!Utils.MgNrExists(ctx, int.Parse(input.Text))) { + return new(false, "Ein Mitglied mit dieser Mitgliedsnummer existiert nicht"); + } + + return new(true, null); + } } } diff --git a/WGneu/Windows/MemberListWindow.xaml b/WGneu/Windows/MemberListWindow.xaml index 26e18f4..2a8dcdd 100644 --- a/WGneu/Windows/MemberListWindow.xaml +++ b/WGneu/Windows/MemberListWindow.xaml @@ -115,10 +115,12 @@