MemberListWindow Validator
This commit is contained in:
29
WGneu/Utils.cs
Normal file
29
WGneu/Utils.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace WGneu
|
||||||
|
{
|
||||||
|
class Utils
|
||||||
|
{
|
||||||
|
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject
|
||||||
|
{
|
||||||
|
if (depObj == null)
|
||||||
|
yield return (T)Enumerable.Empty<T>();
|
||||||
|
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
|
||||||
|
{
|
||||||
|
DependencyObject ithChild = VisualTreeHelper.GetChild(depObj, i);
|
||||||
|
if (ithChild == null)
|
||||||
|
continue;
|
||||||
|
if (ithChild is T t)
|
||||||
|
yield return t;
|
||||||
|
foreach (T childOfChild in FindVisualChilds<T>(ithChild))
|
||||||
|
yield return childOfChild;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
WGneu/Validator.cs
Normal file
72
WGneu/Validator.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
|
namespace WGneu
|
||||||
|
{
|
||||||
|
static class Validator
|
||||||
|
{
|
||||||
|
public static ValidationResult CheckNumericInput(TextBox input)
|
||||||
|
{
|
||||||
|
return CheckNumericInput(input, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ValidationResult CheckNumericInput(TextBox input, int maxLen)
|
||||||
|
{
|
||||||
|
string text = "";
|
||||||
|
int pos = input.CaretIndex;
|
||||||
|
for (int i = 0; i < input.Text.Length; i++)
|
||||||
|
{
|
||||||
|
char ch = input.Text[i];
|
||||||
|
if (Char.IsDigit(ch))
|
||||||
|
text += ch;
|
||||||
|
if (i == input.CaretIndex - 1)
|
||||||
|
pos = text.Length;
|
||||||
|
}
|
||||||
|
input.Text = text;
|
||||||
|
input.CaretIndex = pos;
|
||||||
|
|
||||||
|
if (maxLen >= 0 && input.Text.Length > maxLen)
|
||||||
|
{
|
||||||
|
input.Text = input.Text.Substring(0, maxLen);
|
||||||
|
input.CaretIndex = Math.Min(pos, maxLen);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ValidationResult(true, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ValidationResult CheckLfbisNr(TextBox input)
|
||||||
|
{
|
||||||
|
var res = CheckNumericInput(input, 7);
|
||||||
|
if (!res.IsValid)
|
||||||
|
return res;
|
||||||
|
if (input.Text.Length == 0)
|
||||||
|
return new ValidationResult(true, "");
|
||||||
|
if (input.Text.Length != 7)
|
||||||
|
return new ValidationResult(false, "Betriebsnummer zu kurz");
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
return new ValidationResult(true, "Not implemented yet");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ValidationResult CheckUstIdInput(TextBox input)
|
||||||
|
{
|
||||||
|
return new ValidationResult(false, "Not implemented yet");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetInputInvalid(TextBox input)
|
||||||
|
{
|
||||||
|
input.BorderBrush = System.Windows.Media.Brushes.Red;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SetInputValid(TextBox input)
|
||||||
|
{
|
||||||
|
input.ClearValue(TextBox.BorderBrushProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -171,6 +171,7 @@
|
|||||||
|
|
||||||
<Label Content="BetriebsNr.:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
<Label Content="BetriebsNr.:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
|
||||||
<TextBox x:Name="LfbisNrInput" IsReadOnly="True"
|
<TextBox x:Name="LfbisNrInput" IsReadOnly="True"
|
||||||
|
TextChanged="LfbisNrInput_TextChanged" LostFocus="LfbisNrInput_LostFocus"
|
||||||
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25" Width="64" HorizontalAlignment="Left"/>
|
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25" Width="64" HorizontalAlignment="Left"/>
|
||||||
|
|
||||||
<CheckBox x:Name="BuchführendInput" Content="Buchführend" IsEnabled="False"
|
<CheckBox x:Name="BuchführendInput" Content="Buchführend" IsEnabled="False"
|
||||||
|
@ -294,26 +294,26 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private void LockInputs()
|
private void LockInputs()
|
||||||
{
|
{
|
||||||
MgNrInput.IsReadOnly = true;
|
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||||
GivenNameInput.IsReadOnly = true;
|
if (tb.Name != "SearchInput") tb.IsReadOnly = true;
|
||||||
FamilyNameInput.IsReadOnly = true;
|
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||||
AddressInput.IsReadOnly = true;
|
cb.IsEnabled = false;
|
||||||
PlzInput.IsReadOnly = true;
|
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
|
||||||
OrtInput.IsEnabled = false;
|
cb.IsEnabled = false;
|
||||||
BranchInput.IsEnabled = false;
|
foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
|
||||||
DefaultKgInput.IsEnabled = false;
|
rb.IsEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UnlockInputs()
|
private void UnlockInputs()
|
||||||
{
|
{
|
||||||
MgNrInput.IsReadOnly = false;
|
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||||
GivenNameInput.IsReadOnly = false;
|
if (tb.Name != "SearchInput") tb.IsReadOnly = false;
|
||||||
FamilyNameInput.IsReadOnly = false;
|
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||||
AddressInput.IsReadOnly = false;
|
cb.IsEnabled = true;
|
||||||
PlzInput.IsReadOnly = false;
|
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
|
||||||
OrtInput.IsEnabled = true;
|
cb.IsEnabled = true;
|
||||||
BranchInput.IsEnabled = true;
|
foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
|
||||||
DefaultKgInput.IsEnabled = true;
|
rb.IsEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FillInputs(Member m)
|
private void FillInputs(Member m)
|
||||||
@ -341,14 +341,24 @@ namespace WGneu.Windows
|
|||||||
|
|
||||||
private void ClearInputs()
|
private void ClearInputs()
|
||||||
{
|
{
|
||||||
MgNrInput.Text = "";
|
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
|
||||||
GivenNameInput.Text = "";
|
if (tb.Name != "SearchInput") tb.Text = "";
|
||||||
FamilyNameInput.Text = "";
|
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
|
||||||
BranchInput.SelectedItem = null;
|
cb.SelectedItem = null;
|
||||||
PlzInput.Text = "";
|
}
|
||||||
OrtInput.SelectedItem = null;
|
|
||||||
AddressInput.Text = "";
|
private void LfbisNrInput_TextChanged(object sender, RoutedEventArgs e)
|
||||||
DefaultKgInput.SelectedItem = null;
|
{
|
||||||
|
var res = Validator.CheckLfbisNr(LfbisNrInput);
|
||||||
|
if (res.IsValid) Validator.SetInputValid(LfbisNrInput);
|
||||||
|
else Validator.SetInputInvalid(LfbisNrInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var res = Validator.CheckLfbisNr(LfbisNrInput);
|
||||||
|
if (!res.IsValid)
|
||||||
|
MessageBox.Show(res.ErrorContent.ToString(), "Betriebsnummer ungültig", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user