Add ManualWeighingDialog
This commit is contained in:
41
Elwig/Dialogs/ManualWeighingDialog.xaml.cs
Normal file
41
Elwig/Dialogs/ManualWeighingDialog.xaml.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using Elwig.Helpers;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Elwig.Dialogs {
|
||||
public partial class ManualWeighingDialog : Window {
|
||||
|
||||
public int Weight = 0;
|
||||
public string? Reason = null;
|
||||
|
||||
public ManualWeighingDialog() {
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void ConfirmButton_Click(object sender, RoutedEventArgs evt) {
|
||||
DialogResult = true;
|
||||
Weight = int.Parse(WeightInput.Text.Replace(".", ""));
|
||||
Reason = Regex.Replace(ReasonInput.Text, @"\s+", "").Trim();
|
||||
if (Reason == "") {
|
||||
Reason = null;
|
||||
} else if (!Reason.EndsWith(".") || !Reason.EndsWith("!") || !Reason.EndsWith("?")) {
|
||||
Reason += ".";
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
private void UpdateButtons() {
|
||||
ConfirmButton.IsEnabled = WeightInput.Text.Length > 0 && ReasonInput.Text.Trim().Length > 0;
|
||||
}
|
||||
|
||||
private void WeightInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
Validator.CheckInteger(WeightInput, true, 5);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void ReasonInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
UpdateButtons();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user