From 47d51ded5192456c03cd56c70a3a1b8085940611 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Fri, 29 Sep 2023 14:46:28 +0200 Subject: [PATCH] DeliveryAdminWindow: Allow date and time to be edited --- Elwig/Helpers/Validator.cs | 30 +++++++++++++ Elwig/Windows/AdministrationWindow.cs | 8 ++++ Elwig/Windows/DeliveryAdminWindow.xaml | 15 +++++-- Elwig/Windows/DeliveryAdminWindow.xaml.cs | 53 ++++++++++++++++++----- 4 files changed, 90 insertions(+), 16 deletions(-) diff --git a/Elwig/Helpers/Validator.cs b/Elwig/Helpers/Validator.cs index aa99de6..064572d 100644 --- a/Elwig/Helpers/Validator.cs +++ b/Elwig/Helpers/Validator.cs @@ -521,6 +521,36 @@ namespace Elwig.Helpers { return new(true, null); } + public static ValidationResult CheckTime(TextBox input, bool required) { + string text = ""; + int pos = input.CaretIndex; + int v = 0; + for (int i = 0; i < input.Text.Length; i++) { + char ch = input.Text[i]; + if (v >= 0 && v < 5 && v != 2 && char.IsAsciiDigit(ch)) { + if ((v == 0 && ch <= '2') || (v == 1 && (text[0] < '2' || ch <= '3')) || (v == 3 && ch <= '5') || v == 4) { + text += ch; + v++; + } + } else if (v == 2 && ch == ':') { + text += ch; + v++; + } + if (i == input.CaretIndex - 1) + pos = text.Length; + } + input.Text = text; + input.CaretIndex = pos; + + if (text.Length == 0) { + return required ? new(false, "Wert ist nicht optional") : new(true, null); + } else if (v != 5) { + return new(false, "Zeit ist ungültig"); + } else { + return new(true, null); + } + } + public static ValidationResult CheckFbNr(TextBox input, bool required, AppDbContext ctx, AreaCom? c) { var res = CheckInteger(input, required); if (!res.IsValid) { diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs index 5630c09..6b06f3a 100644 --- a/Elwig/Windows/AdministrationWindow.cs +++ b/Elwig/Windows/AdministrationWindow.cs @@ -482,6 +482,14 @@ namespace Elwig.Windows { InputLostFocus((TextBox)sender, Validator.CheckDate); } + protected void TimeInput_TextChanged(object sender, RoutedEventArgs evt) { + InputTextChanged((TextBox)sender, Validator.CheckTime); + } + + protected void TimeInput_LostFocus(object sender, RoutedEventArgs evt) { + InputLostFocus((TextBox)sender, Validator.CheckTime); + } + protected void PlzInput_TextChanged(object sender, RoutedEventArgs evt) { var plz = (TextBox)sender; InputTextChanged(plz, Validator.CheckPlz); diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml b/Elwig/Windows/DeliveryAdminWindow.xaml index 0fa822e..edcec92 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml +++ b/Elwig/Windows/DeliveryAdminWindow.xaml @@ -72,6 +72,10 @@ + + + @@ -228,18 +232,21 @@