diff --git a/Elwig/Dialogs/ManualWeighingDialog.xaml.cs b/Elwig/Dialogs/ManualWeighingDialog.xaml.cs index b9b5cf2..d0b7cf2 100644 --- a/Elwig/Dialogs/ManualWeighingDialog.xaml.cs +++ b/Elwig/Dialogs/ManualWeighingDialog.xaml.cs @@ -9,19 +9,16 @@ namespace Elwig.Dialogs { public int Weight = 0; public string? Reason = null; - public ManualWeighingDialog() { + public ManualWeighingDialog(string? reason = null) { InitializeComponent(); + ReasonInput.Text = reason; } private void ConfirmButton_Click(object sender, RoutedEventArgs evt) { DialogResult = true; Weight = int.Parse(WeightInput.Text); - Reason = Regex.Replace(ReasonInput.Text, @"\s+", "").Trim(); - if (Reason == "") { - Reason = null; - } else if (!Reason.EndsWith(".") || !Reason.EndsWith("!") || !Reason.EndsWith("?")) { - Reason += "."; - } + Reason = Regex.Replace(ReasonInput.Text, @"\s+", " ").Trim(); + if (Reason == "") Reason = null; Close(); } diff --git a/Elwig/Helpers/Utils.cs b/Elwig/Helpers/Utils.cs index b90dd04..88125f1 100644 --- a/Elwig/Helpers/Utils.cs +++ b/Elwig/Helpers/Utils.cs @@ -219,8 +219,8 @@ namespace Elwig.Helpers { .Sum(); } - public static (int, string?)? ShowManualWeighingDialog() { - var d = new ManualWeighingDialog(); + public static (int, string?)? ShowManualWeighingDialog(string? reason = null) { + var d = new ManualWeighingDialog(reason); return d.ShowDialog() == true ? (d.Weight, d.Reason) : null; } diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs index 1b507a6..2d7aa75 100644 --- a/Elwig/Windows/AdministrationWindow.cs +++ b/Elwig/Windows/AdministrationWindow.cs @@ -413,7 +413,7 @@ namespace Elwig.Windows { UpdateButtons(); } - protected void TextBox_TextChanged(object sender, RoutedEventArgs evt) { + protected void TextBox_TextChanged(object sender, RoutedEventArgs? evt) { var input = (TextBox)sender; if (SenderIsRequired(input) && input.Text.Length == 0) { ValidateInput(input, false); diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml.cs b/Elwig/Windows/DeliveryAdminWindow.xaml.cs index 0b96781..5a56e6b 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml.cs +++ b/Elwig/Windows/DeliveryAdminWindow.xaml.cs @@ -25,6 +25,7 @@ namespace Elwig.Windows { private List TextFilter = new(); private readonly RoutedCommand CtrlF = new(); + private string? LastScaleError = null; private string? ManualWeighingReason = null; private string? ScaleId = null; private string? WeighingId = null; @@ -147,6 +148,11 @@ namespace Elwig.Windows { } private void InitialInputs() { + LastScaleError = null; + WeighingId = null; + ScaleId = null; + ManualWeighingReason = null; + ClearOriginalValues(); ClearDefaultValues(); @@ -651,12 +657,18 @@ namespace Elwig.Windows { ScaleId = null; WeighingId = null; } - ManualWeighingReason = null; - ManualWeighingInput.IsChecked = false; + LastScaleError = null; } catch (Exception e) { + LastScaleError = e.Message.Split(": ")[^1]; + WeightInput.Text = ""; + ScaleId = null; + WeighingId = null; MessageBox.Show($"Beim Wiegen ist ein Fehler aufgetreten:\n\n{e.Message}", "Waagenfehler", MessageBoxButton.OK, MessageBoxImage.Error); } + ManualWeighingReason = null; + ManualWeighingInput.IsChecked = false; + base.TextBox_TextChanged(WeightInput, null); EnableWeighingButtons(); UpdateButtons(); } @@ -885,7 +897,7 @@ namespace Elwig.Windows { } private void WeighingManualButton_Click(object sender, RoutedEventArgs evt) { - var res = Utils.ShowManualWeighingDialog(); + var res = Utils.ShowManualWeighingDialog(LastScaleError); if (res == null) return; WeightInput.Text = $"{res?.Item1:N0}"; ManualWeighingInput.IsChecked = true;