Add DeliveryAdminWindow
This commit is contained in:
@ -59,6 +59,71 @@ namespace Elwig.Helpers {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckDecimal(TextBox input, bool required) {
|
||||
return CheckDecimal(input, required, -1, -1);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckDecimal(TextBox input, bool required, int maxLen, int maxDecimal) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
int v1 = 0, v2 = -1;
|
||||
for (int i = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (char.IsAsciiDigit(ch)) {
|
||||
if (v2 == -1 && v1 < maxLen) {
|
||||
text += ch; v1++;
|
||||
} else if (v2 != -1 && v2 < maxDecimal) {
|
||||
text += ch; v2++;
|
||||
}
|
||||
} else if (v2 == 0-1 && ch == ',' || ch == '.') {
|
||||
if (v1 == 0) { text += '0'; v1++; }
|
||||
text += ',';
|
||||
v2 = 0;
|
||||
}
|
||||
if (i == input.CaretIndex - 1)
|
||||
pos = text.Length;
|
||||
}
|
||||
input.Text = text;
|
||||
input.CaretIndex = pos;
|
||||
|
||||
if (text.Length == 0) {
|
||||
return required ? new(false, "Wert ist nicht optional") : new(true, null);
|
||||
} else if (v2 == 0) {
|
||||
return new(false, "Ungültige Kommazahl");
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckUpperCase(TextBox input, bool required) {
|
||||
return CheckUpperCase(input, required, -1);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckUpperCase(TextBox input, bool required, int maxLen) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (char.IsAsciiLetter(ch))
|
||||
text += char.ToUpper(ch);
|
||||
if (i == input.CaretIndex - 1)
|
||||
pos = text.Length;
|
||||
}
|
||||
input.Text = text;
|
||||
input.CaretIndex = pos;
|
||||
|
||||
if (text.Length == 0) {
|
||||
return required ? new(false, "Wert ist nicht optional") : new(true, null);
|
||||
}
|
||||
|
||||
if (maxLen >= 0 && input.Text.Length > maxLen) {
|
||||
input.Text = input.Text[..maxLen];
|
||||
input.CaretIndex = Math.Min(pos, maxLen);
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckPlz(TextBox input, bool required, AppDbContext ctx) {
|
||||
CheckInteger(input, false, 4);
|
||||
if (!required && input.Text.Length == 0) {
|
||||
@ -315,7 +380,23 @@ namespace Elwig.Helpers {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckMgNr(TextBox input, bool required, AppDbContext ctx, Member? m) {
|
||||
public static ValidationResult CheckMgNr(TextBox input, bool required, AppDbContext ctx) {
|
||||
var res = CheckInteger(input, required);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
} else if (!required && input.Text.Length == 0) {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
int nr = int.Parse(input.Text);
|
||||
if (!ctx.MgNrExists(nr).GetAwaiter().GetResult()) {
|
||||
return new(false, "Ungültige Mitgliedsnummer");
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckNewMgNr(TextBox input, bool required, AppDbContext ctx, Member? m) {
|
||||
var res = CheckInteger(input, required);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
@ -331,6 +412,26 @@ namespace Elwig.Helpers {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckSortId(TextBox input, bool required, AppDbContext ctx) {
|
||||
var res = CheckUpperCase(input, required, 3);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
} else if (!required && input.Text.Length == 0) {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
if (input.Text.Length < 2 || !ctx.SortIdExists(input.Text[0..2]).GetAwaiter().GetResult()) {
|
||||
return new(false, "Ungültige Sorte");
|
||||
} else if (input.Text.Length >= 3) {
|
||||
var attr = input.Text[2..];
|
||||
if (!ctx.AttrIdExists(attr).GetAwaiter().GetResult()) {
|
||||
return new(false, "Ungültiges Attribut");
|
||||
}
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckPredecessorMgNr(TextBox input, bool required, AppDbContext ctx) {
|
||||
var res = CheckInteger(input, required);
|
||||
if (!res.IsValid) {
|
||||
@ -431,5 +532,37 @@ namespace Elwig.Helpers {
|
||||
// TODO
|
||||
return new(true, "Not implemented yet");
|
||||
}
|
||||
|
||||
public static ValidationResult CheckGradatoinOe(TextBox input, bool required) {
|
||||
var res = CheckInteger(input, required, 3);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
} else if (!required && input.Text.Length == 0) {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
var oe = double.Parse(input.Text);
|
||||
if (oe < 10 || oe >= 200) {
|
||||
return new(false, "Ungültiger Oechsle-Wert");
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckGradationKmw(TextBox input, bool required) {
|
||||
var res = CheckDecimal(input, required, 2, 1);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
} else if (!required && input.Text.Length == 0) {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
var kmw = double.Parse(input.Text);
|
||||
if (kmw < 0 || kmw >= 50) {
|
||||
return new(false, "Ungültiger KMW-Wert");
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user