Check MgNr and PredecessorMgNr
This commit is contained in:
@ -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<string[]>() },
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user