Files
elwig/Elwig/Dialogs/ManualWeighingDialog.xaml.cs

39 lines
1.1 KiB
C#

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(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;
Close();
}
private void UpdateButtons() {
ConfirmButton.IsEnabled = WeightInput.Text.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();
}
}
}