DeliveryAdminWindow: Use last scale error as default manual weighing reason
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -25,6 +25,7 @@ namespace Elwig.Windows {
|
||||
private List<string> 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;
|
||||
|
Reference in New Issue
Block a user