Add Bic and Plz validation
This commit is contained in:
@ -49,7 +49,7 @@ namespace WGneu {
|
|||||||
int pos = input.CaretIndex;
|
int pos = input.CaretIndex;
|
||||||
for (int i = 0; i < input.Text.Length; i++) {
|
for (int i = 0; i < input.Text.Length; i++) {
|
||||||
char ch = input.Text[i];
|
char ch = input.Text[i];
|
||||||
if (Char.IsDigit(ch))
|
if (char.IsDigit(ch))
|
||||||
text += ch;
|
text += ch;
|
||||||
if (i == input.CaretIndex - 1)
|
if (i == input.CaretIndex - 1)
|
||||||
pos = text.Length;
|
pos = text.Length;
|
||||||
@ -63,13 +63,24 @@ namespace WGneu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (maxLen >= 0 && input.Text.Length > maxLen) {
|
if (maxLen >= 0 && input.Text.Length > maxLen) {
|
||||||
input.Text = input.Text.Substring(0, maxLen);
|
input.Text = input.Text[..maxLen];
|
||||||
input.CaretIndex = Math.Min(pos, maxLen);
|
input.CaretIndex = Math.Min(pos, maxLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new(true, null);
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ValidationResult CheckPlz(TextBox input, bool optional) {
|
||||||
|
CheckNumericInput(input, true, 4);
|
||||||
|
if (optional && input.Text.Length == 0) {
|
||||||
|
return new(true, null);
|
||||||
|
} else if (input.Text.Length != 4) {
|
||||||
|
return new(false, "PLZ zu kurz");
|
||||||
|
} else {
|
||||||
|
return new(true, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckPhoneNumber(TextBox input, bool optional) {
|
public static ValidationResult CheckPhoneNumber(TextBox input, bool optional) {
|
||||||
string text = "";
|
string text = "";
|
||||||
int pos = input.CaretIndex;
|
int pos = input.CaretIndex;
|
||||||
@ -195,11 +206,50 @@ namespace WGneu {
|
|||||||
return new(true, null);
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ValidationResult CheckBic(TextBox input, bool optional) {
|
||||||
|
string text = "";
|
||||||
|
int pos = input.CaretIndex;
|
||||||
|
for (int i = 0, v = 0; i < input.Text.Length; i++) {
|
||||||
|
char ch = input.Text[i];
|
||||||
|
if ((v < 4 || v >= 6) && char.IsAscii(ch) && char.IsLetterOrDigit(ch)) {
|
||||||
|
v++;
|
||||||
|
text += char.ToUpper(ch);
|
||||||
|
} else if (v >= 4 && v < 6 && char.IsAscii(ch) && char.IsLetter(ch)) {
|
||||||
|
v++;
|
||||||
|
text += char.ToUpper(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == input.CaretIndex - 1)
|
||||||
|
pos = text.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.Length == 0) {
|
||||||
|
if (optional) return new(true, null);
|
||||||
|
return new(false, "BIC ist nicht optional");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.Length > 11) {
|
||||||
|
text = text[..11];
|
||||||
|
pos = Math.Min(pos, 11);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.Length == 11 && text.EndsWith("XXX"))
|
||||||
|
text = text[..8];
|
||||||
|
|
||||||
|
input.Text = text;
|
||||||
|
input.CaretIndex = pos;
|
||||||
|
|
||||||
|
if (text.Length != 11 && text.Length != 8)
|
||||||
|
return new(false, "BIC ist ungültig");
|
||||||
|
|
||||||
|
return new(true, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckLfbisNr(TextBox input, bool optional) {
|
public static ValidationResult CheckLfbisNr(TextBox input, bool optional) {
|
||||||
var res = CheckNumericInput(input, optional, 7);
|
var res = CheckNumericInput(input, true, 7);
|
||||||
if (!res.IsValid)
|
if (!res.IsValid)
|
||||||
return res;
|
return res;
|
||||||
if (input.Text.Length == 0)
|
if (optional && input.Text.Length == 0)
|
||||||
return new(true, null);
|
return new(true, null);
|
||||||
if (input.Text.Length != 7)
|
if (input.Text.Length != 7)
|
||||||
return new(false, "Betriebsnummer zu kurz");
|
return new(false, "Betriebsnummer zu kurz");
|
||||||
|
@ -111,7 +111,7 @@
|
|||||||
|
|
||||||
<Label Content="PLZ/Ort:" HorizontalAlignment="Left" Margin="10,162,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="PLZ/Ort:" HorizontalAlignment="Left" Margin="10,162,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="PlzInput" IsReadOnly="True"
|
<TextBox x:Name="PlzInput" IsReadOnly="True"
|
||||||
TextChanged="PlzInput_TextChanged"
|
TextChanged="PlzInput_TextChanged" LostFocus="PlzInput_LostFocus"
|
||||||
HorizontalAlignment="Left" Margin="0,160,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
HorizontalAlignment="Left" Margin="0,160,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
<ComboBox x:Name="OrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
<ComboBox x:Name="OrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
||||||
SelectionChanged="ComboBox_SelectionChanged"
|
SelectionChanged="ComboBox_SelectionChanged"
|
||||||
@ -156,10 +156,11 @@
|
|||||||
<Label Content="IBAN:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="IBAN:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="IbanInput" IsReadOnly="True"
|
<TextBox x:Name="IbanInput" IsReadOnly="True"
|
||||||
TextChanged="IbanInput_TextChanged" LostFocus="IbanInput_LostFocus"
|
TextChanged="IbanInput_TextChanged" LostFocus="IbanInput_LostFocus"
|
||||||
Margin="0,10,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
Margin="0,10,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
|
|
||||||
<Label Content="BIC:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="BIC:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="BicInput" IsReadOnly="True"
|
<TextBox x:Name="BicInput" IsReadOnly="True"
|
||||||
|
TextChanged="BicInput_TextChanged" LostFocus="BicInput_LostFocus"
|
||||||
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
@ -201,7 +202,7 @@
|
|||||||
|
|
||||||
<Label Content="PLZ/Ort:" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="PLZ/Ort:" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="BillingPlzInput" IsReadOnly="True"
|
<TextBox x:Name="BillingPlzInput" IsReadOnly="True"
|
||||||
TextChanged="PlzInput_TextChanged"
|
TextChanged="BillingPlzInput_TextChanged" LostFocus="BillingPlzInput_LostFocus"
|
||||||
HorizontalAlignment="Left" Margin="0,70,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1"/>
|
HorizontalAlignment="Left" Margin="0,70,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1"/>
|
||||||
<ComboBox x:Name="BillingOrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
<ComboBox x:Name="BillingOrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
|
||||||
SelectionChanged="ComboBox_SelectionChanged"
|
SelectionChanged="ComboBox_SelectionChanged"
|
||||||
|
@ -101,15 +101,6 @@ namespace WGneu.Windows {
|
|||||||
RefreshInputs();
|
RefreshInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlzInput_TextChanged(object sender, RoutedEventArgs e) {
|
|
||||||
if (PlzInput.Text.Length == 4 && PlzInput.Text.All(char.IsDigit)) {
|
|
||||||
int plz = int.Parse(PlzInput.Text);
|
|
||||||
var o = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
|
||||||
OrtInput.ItemsSource = o;
|
|
||||||
OrtInput.SelectedItem = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void NewMemberButton_Click(object sender, RoutedEventArgs e) {
|
private void NewMemberButton_Click(object sender, RoutedEventArgs e) {
|
||||||
IsCreating = true;
|
IsCreating = true;
|
||||||
MemberList.IsEnabled = false;
|
MemberList.IsEnabled = false;
|
||||||
@ -385,6 +376,18 @@ namespace WGneu.Windows {
|
|||||||
return true; // TODO
|
return true; // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdatePlz(TextBox plzInput, ComboBox ortInput) {
|
||||||
|
if (plzInput.Text.Length == 4) {
|
||||||
|
int plz = int.Parse(plzInput.Text);
|
||||||
|
ortInput.ItemsSource = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
||||||
|
} else {
|
||||||
|
ortInput.ItemsSource = null;
|
||||||
|
}
|
||||||
|
ortInput.SelectedItem = null;
|
||||||
|
Valid[plzInput] = (ortInput.ItemsSource != null);
|
||||||
|
UpdateButtons();
|
||||||
|
}
|
||||||
|
|
||||||
private void InputTextChanged(TextBox input, bool optional, Func<TextBox, bool, ValidationResult> checker) {
|
private void InputTextChanged(TextBox input, bool optional, Func<TextBox, bool, ValidationResult> checker) {
|
||||||
var res = checker(input, optional);
|
var res = checker(input, optional);
|
||||||
Valid[input] = res.IsValid;
|
Valid[input] = res.IsValid;
|
||||||
@ -405,6 +408,16 @@ namespace WGneu.Windows {
|
|||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PlzInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||||
|
InputTextChanged((TextBox)sender, false, Validator.CheckPlz);
|
||||||
|
UpdatePlz((TextBox)sender, OrtInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlzInput_LostFocus(object sender, RoutedEventArgs e) {
|
||||||
|
InputLostFocus((TextBox)sender, true, Validator.CheckPlz, null);
|
||||||
|
UpdatePlz((TextBox)sender, OrtInput);
|
||||||
|
}
|
||||||
|
|
||||||
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs e) {
|
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||||
InputTextChanged((TextBox)sender, true, Validator.CheckPhoneNumber);
|
InputTextChanged((TextBox)sender, true, Validator.CheckPhoneNumber);
|
||||||
}
|
}
|
||||||
@ -429,6 +442,14 @@ namespace WGneu.Windows {
|
|||||||
InputLostFocus((TextBox)sender, true, Validator.CheckIban, null);
|
InputLostFocus((TextBox)sender, true, Validator.CheckIban, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BicInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||||
|
InputTextChanged((TextBox)sender, true, Validator.CheckBic);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BicInput_LostFocus(object sender, RoutedEventArgs e) {
|
||||||
|
InputLostFocus((TextBox)sender, true, Validator.CheckBic, null);
|
||||||
|
}
|
||||||
|
|
||||||
private void LfbisNrInput_TextChanged(object sender, RoutedEventArgs e) {
|
private void LfbisNrInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||||
InputTextChanged((TextBox)sender, true, Validator.CheckLfbisNr);
|
InputTextChanged((TextBox)sender, true, Validator.CheckLfbisNr);
|
||||||
}
|
}
|
||||||
@ -436,5 +457,15 @@ namespace WGneu.Windows {
|
|||||||
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e) {
|
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e) {
|
||||||
InputLostFocus((TextBox)sender, true, Validator.CheckLfbisNr, "Betriebsnummer ungültig");
|
InputLostFocus((TextBox)sender, true, Validator.CheckLfbisNr, "Betriebsnummer ungültig");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BillingPlzInput_TextChanged(object sender, RoutedEventArgs e) {
|
||||||
|
InputTextChanged((TextBox)sender, true, Validator.CheckPlz);
|
||||||
|
UpdatePlz((TextBox)sender, BillingOrtInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BillingPlzInput_LostFocus(object sender, RoutedEventArgs e) {
|
||||||
|
InputLostFocus((TextBox)sender, true, Validator.CheckPlz, null);
|
||||||
|
UpdatePlz((TextBox)sender, BillingOrtInput);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user