Move more input checker methods to AdminWindow
This commit is contained in:
@ -7,7 +7,6 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Diagnostics;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
public static class Utils {
|
||||
@ -46,22 +45,36 @@ namespace Elwig.Helpers {
|
||||
return toggleButton?.Template.FindName("templateRoot", toggleButton) as Border;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj) where T : DependencyObject {
|
||||
public static IEnumerable<T> FindAllChildren<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)
|
||||
foreach (var child in LogicalTreeHelper.GetChildren(depObj)) {
|
||||
if (child == null) {
|
||||
continue;
|
||||
if (ithChild is T t)
|
||||
} else if (child is T t) {
|
||||
yield return t;
|
||||
foreach (T childOfChild in FindVisualChilds<T>(ithChild))
|
||||
yield return childOfChild;
|
||||
} else if (child is DependencyObject childDepOpj) {
|
||||
foreach (T childOfChild in FindAllChildren<T>(childDepOpj)) {
|
||||
yield return childOfChild;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<T> FindVisualChilds<T>(DependencyObject depObj, IEnumerable<DependencyObject> exempt) where T : DependencyObject {
|
||||
return FindVisualChilds<T>(depObj).Where(c => !exempt.Contains(c));
|
||||
public static IEnumerable<T> FindAllChildren<T>(DependencyObject depObj, IEnumerable<DependencyObject> exempt) where T : DependencyObject {
|
||||
return FindAllChildren<T>(depObj).Where(c => !exempt.Contains(c));
|
||||
}
|
||||
|
||||
public static T? FindNextSibling<T>(Control me) where T : DependencyObject {
|
||||
var found = false;
|
||||
foreach (var child in LogicalTreeHelper.GetChildren(me.Parent)) {
|
||||
if (found && child is T c) {
|
||||
return c;
|
||||
} else if (child == me) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int Modulo(string a, int b) {
|
||||
|
@ -30,7 +30,7 @@ namespace Elwig.Helpers {
|
||||
{ "423", Array.Empty<string[]>() },
|
||||
};
|
||||
|
||||
public static ValidationResult CheckNumeric(TextBox input, bool required) {
|
||||
public static ValidationResult CheckInteger(TextBox input, bool required) {
|
||||
return CheckNumeric(input, required, -1);
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
public static ValidationResult CheckMgNr(TextBox input, bool required, AppDbContext ctx, Member? m) {
|
||||
var res = CheckNumeric(input, required);
|
||||
var res = CheckInteger(input, required);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
} else if (!required && input.Text.Length == 0) {
|
||||
@ -273,7 +273,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
public static ValidationResult CheckPredecessorMgNr(TextBox input, bool required, AppDbContext ctx) {
|
||||
var res = CheckNumeric(input, required);
|
||||
var res = CheckInteger(input, required);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
} else if (!required && input.Text.Length == 0) {
|
||||
@ -296,7 +296,7 @@ namespace Elwig.Helpers {
|
||||
}
|
||||
|
||||
public static ValidationResult CheckVNr(TextBox input, bool required, AppDbContext ctx, Contract? c) {
|
||||
var res = CheckNumeric(input, required);
|
||||
var res = CheckInteger(input, required);
|
||||
if (!res.IsValid) {
|
||||
return res;
|
||||
} else if (!required && input.Text.Length == 0) {
|
||||
|
Reference in New Issue
Block a user