diff --git a/WGneu/Utils.cs b/WGneu/Utils.cs new file mode 100644 index 0000000..1827713 --- /dev/null +++ b/WGneu/Utils.cs @@ -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 FindVisualChilds(DependencyObject depObj) where T : DependencyObject + { + if (depObj == null) + yield return (T)Enumerable.Empty(); + 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(ithChild)) + yield return childOfChild; + } + } + } +} diff --git a/WGneu/Validator.cs b/WGneu/Validator.cs new file mode 100644 index 0000000..4906231 --- /dev/null +++ b/WGneu/Validator.cs @@ -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); + } + } +} diff --git a/WGneu/Windows/MemberListWindow.xaml b/WGneu/Windows/MemberListWindow.xaml index 3071697..4d64170 100644 --- a/WGneu/Windows/MemberListWindow.xaml +++ b/WGneu/Windows/MemberListWindow.xaml @@ -171,6 +171,7 @@