73 lines
2.1 KiB
C#
73 lines
2.1 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|