[#10] MemberAdminWindow: Implement MVVM
This commit is contained in:
@ -162,9 +162,9 @@ namespace Elwig.Windows {
|
||||
if (input is TextBox tb && tb.Text.Length == 0) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
Valid[input] = false;
|
||||
} else if (input is ComboBox cb && cb.SelectedItem == null && cb.ItemsSource != null) {
|
||||
} else if (input is ComboBox cb && cb.SelectedItem == null && cb.ItemsSource != null && cb.ItemsSource.Cast<object>().Any()) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (input is ListBox lb && lb.SelectedItem == null && lb.ItemsSource != null) {
|
||||
} else if (input is ListBox lb && lb.SelectedItem == null && lb.ItemsSource != null && lb.ItemsSource.Cast<object>().Any()) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
} else if (input is CheckBox ckb && ckb.IsChecked != true) {
|
||||
ControlUtils.SetInputInvalid(input);
|
||||
@ -271,16 +271,28 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
protected void ClearInputs(bool validate = true) {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
foreach (var tb in TextBoxInputs) {
|
||||
tb.Text = "";
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
var binding = tb.GetBindingExpression(TextBox.TextProperty);
|
||||
binding?.UpdateSource();
|
||||
}
|
||||
foreach (var cb in ComboBoxInputs) {
|
||||
cb.SelectedItem = null;
|
||||
var binding = cb.GetBindingExpression(ComboBox.SelectedItemProperty);
|
||||
binding?.UpdateSource();
|
||||
}
|
||||
foreach (var lb in ListBoxInputs)
|
||||
lb.SelectedItems.Clear();
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
foreach (var cb in CheckBoxInputs) {
|
||||
cb.IsChecked = cb.IsThreeState ? null : false;
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
var binding = cb.GetBindingExpression(CheckBox.IsCheckedProperty);
|
||||
binding?.UpdateSource();
|
||||
}
|
||||
foreach (var rb in RadioButtonInputs) {
|
||||
rb.IsChecked = rb.IsThreeState ? null : false;
|
||||
var binding = rb.GetBindingExpression(RadioButton.IsCheckedProperty);
|
||||
binding?.UpdateSource();
|
||||
}
|
||||
if (validate) ValidateRequiredInputs();
|
||||
}
|
||||
|
||||
@ -327,7 +339,7 @@ namespace Elwig.Windows {
|
||||
protected async Task UpdatePlz(TextBox plzInput, ComboBox ortInput) {
|
||||
var plzInputValid = Validator.CheckPlz(plzInput, RequiredInputs.Contains(plzInput)).IsValid;
|
||||
|
||||
List<AT_PlzDest>? list = null;
|
||||
List<AT_PlzDest> list = [];
|
||||
if (plzInputValid && plzInput.Text.Length == 4) {
|
||||
var plz = int.Parse(plzInput.Text);
|
||||
using var ctx = new AppDbContext();
|
||||
@ -338,7 +350,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
ControlUtils.RenewItemsSource(ortInput, list);
|
||||
if (list != null && ortInput.SelectedItem == null && list.Count == 1)
|
||||
if (ortInput.SelectedItem == null && list.Count == 1)
|
||||
ortInput.SelectedItem = list[0];
|
||||
UpdateComboBox(ortInput);
|
||||
}
|
||||
@ -444,9 +456,9 @@ namespace Elwig.Windows {
|
||||
private void UpdateComboBox(Control input) {
|
||||
bool valid = false;
|
||||
if (input is ComboBox cb) {
|
||||
valid = cb.ItemsSource == null || cb.SelectedItem != null || !RequiredInputs.Contains(input);
|
||||
valid = cb.ItemsSource == null || cb.SelectedItem != null || !RequiredInputs.Contains(input) || !cb.ItemsSource.Cast<object>().Any();
|
||||
} else if (input is ListBox lb) {
|
||||
valid = lb.ItemsSource == null || lb.SelectedItem != null || !RequiredInputs.Contains(input);
|
||||
valid = lb.ItemsSource == null || lb.SelectedItem != null || !RequiredInputs.Contains(input) || !lb.ItemsSource.Cast<object>().Any();
|
||||
}
|
||||
if (valid) {
|
||||
ValidateInput(input, true);
|
||||
|
Reference in New Issue
Block a user