Implement UID check
This commit is contained in:
@ -247,20 +247,72 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
// https://statistik.at/fileadmin/shared/QM/Standarddokumentationen/RW/std_r_land-forstw_register.pdf#page=41
|
||||
int s = 0;
|
||||
int s = 0, v = 0;
|
||||
for (int i = 0; i < 6; i++)
|
||||
s += (input.Text[i] - '0') * (7 - i);
|
||||
s = (11 - (s % 11)) % 10;
|
||||
v = (11 - (s % 11)) % 10;
|
||||
|
||||
if (s != (input.Text[6] - '0'))
|
||||
if (v != (input.Text[6] - '0'))
|
||||
return new(false, "Prüfsumme der Betriebsnummer ist falsch");
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckUstId(TextBox input, bool required) {
|
||||
// TODO
|
||||
return new(true, "Not implemented yet");
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
for (int i = 0, v = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (v < 2 && char.IsAscii(ch) && char.IsLetter(ch)) {
|
||||
v++;
|
||||
text += char.ToUpper(ch);
|
||||
} else if (v >= 2 && char.IsAscii(ch) && char.IsLetterOrDigit(ch)) {
|
||||
if (text.StartsWith("AT")) {
|
||||
if (v == 2 && (ch == 'u' || ch == 'U')) {
|
||||
v++;
|
||||
text += 'U';
|
||||
} else if (v > 2 && char.IsDigit(ch)) {
|
||||
v++;
|
||||
text += ch;
|
||||
}
|
||||
} else {
|
||||
v++;
|
||||
text += char.ToUpper(ch);
|
||||
}
|
||||
}
|
||||
|
||||
if (i == input.CaretIndex - 1) {
|
||||
pos = text.Length;
|
||||
} else if (v >= 14) {
|
||||
break;
|
||||
} else if (text.StartsWith("AT") && v >= 11) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
input.Text = text;
|
||||
input.CaretIndex = pos;
|
||||
|
||||
if (text.Length == 0)
|
||||
return required ? new(false, "UID ist nicht optional") : new(true, null);
|
||||
|
||||
if (text.StartsWith("AT")) {
|
||||
if (text.Length != 11 || text[2] != 'U')
|
||||
return new(false, "UID ist ungültig");
|
||||
|
||||
// http://www.pruefziffernberechnung.de/U/USt-IdNr.shtml
|
||||
int s = 0, v = 0;
|
||||
for (int i = 0; i < 8; i++)
|
||||
s += ((text[i + 3] - '0') * (i % 2 + 1)).ToString().Select(ch => ch - '0').Sum();
|
||||
v = (96 - s) % 10;
|
||||
|
||||
if (v != (text[10] - '0'))
|
||||
return new(false, "Prüfsumme der UID ist falsch");
|
||||
} else {
|
||||
return new(false, "Not implemented yet");
|
||||
}
|
||||
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckMgNr(TextBox input, bool required, AppDbContext ctx, Member? m) {
|
||||
|
Reference in New Issue
Block a user