[#43] AdministrationWindow: Do not use Context from ContextWindow any more
This commit is contained in:
@ -128,13 +128,14 @@ namespace Elwig.Helpers {
|
|||||||
return new(true, null);
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckPlz(TextBox input, bool required, AppDbContext ctx) {
|
public static ValidationResult CheckPlz(TextBox input, bool required) {
|
||||||
CheckInteger(input, false, 4);
|
CheckInteger(input, false, 4);
|
||||||
if (!required && input.Text.Length == 0) {
|
if (!required && input.Text.Length == 0) {
|
||||||
return new(true, null);
|
return new(true, null);
|
||||||
} else if (input.Text.Length != 4) {
|
} else if (input.Text.Length != 4) {
|
||||||
return new(false, "PLZ zu kurz");
|
return new(false, "PLZ zu kurz");
|
||||||
}
|
}
|
||||||
|
using var ctx = new AppDbContext();
|
||||||
int plz = int.Parse(input.Text);
|
int plz = int.Parse(input.Text);
|
||||||
if (ctx.Postleitzahlen.Find(plz) == null) {
|
if (ctx.Postleitzahlen.Find(plz) == null) {
|
||||||
return new(false, "Ungültige PLZ");
|
return new(false, "Ungültige PLZ");
|
||||||
@ -413,7 +414,7 @@ namespace Elwig.Helpers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckMgNr(TextBox input, bool required, AppDbContext ctx) {
|
public static ValidationResult CheckMgNr(TextBox input, bool required) {
|
||||||
var res = CheckInteger(input, required);
|
var res = CheckInteger(input, required);
|
||||||
if (!res.IsValid) {
|
if (!res.IsValid) {
|
||||||
return res;
|
return res;
|
||||||
@ -421,6 +422,7 @@ namespace Elwig.Helpers {
|
|||||||
return new(true, null);
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var ctx = new AppDbContext();
|
||||||
int nr = int.Parse(input.Text);
|
int nr = int.Parse(input.Text);
|
||||||
if (!ctx.MgNrExists(nr).GetAwaiter().GetResult()) {
|
if (!ctx.MgNrExists(nr).GetAwaiter().GetResult()) {
|
||||||
return new(false, "Ungültige Mitgliedsnummer");
|
return new(false, "Ungültige Mitgliedsnummer");
|
||||||
@ -446,7 +448,7 @@ namespace Elwig.Helpers {
|
|||||||
return new(true, null);
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckSortId(TextBox input, bool required, AppDbContext ctx) {
|
public static ValidationResult CheckSortId(TextBox input, bool required) {
|
||||||
var res = CheckUpperCase(input, required, 3);
|
var res = CheckUpperCase(input, required, 3);
|
||||||
if (!res.IsValid) {
|
if (!res.IsValid) {
|
||||||
return res;
|
return res;
|
||||||
@ -454,6 +456,7 @@ namespace Elwig.Helpers {
|
|||||||
return new(true, null);
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using var ctx = new AppDbContext();
|
||||||
if (input.Text.Length < 2 || !ctx.SortIdExists(input.Text[0..2]).GetAwaiter().GetResult()) {
|
if (input.Text.Length < 2 || !ctx.SortIdExists(input.Text[0..2]).GetAwaiter().GetResult()) {
|
||||||
return new(false, "Ungültige Sorte");
|
return new(false, "Ungültige Sorte");
|
||||||
} else if (input.Text.Length >= 3) {
|
} else if (input.Text.Length >= 3) {
|
||||||
@ -466,8 +469,9 @@ namespace Elwig.Helpers {
|
|||||||
return new(true, null);
|
return new(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckPredecessorMgNr(TextBox input, bool required, AppDbContext ctx) {
|
public static ValidationResult CheckPredecessorMgNr(TextBox input, bool required) {
|
||||||
var res = CheckInteger(input, required);
|
var res = CheckInteger(input, required);
|
||||||
|
using var ctx = new AppDbContext();
|
||||||
if (!res.IsValid) {
|
if (!res.IsValid) {
|
||||||
return res;
|
return res;
|
||||||
} else if (!required && input.Text.Length == 0) {
|
} else if (!required && input.Text.Length == 0) {
|
||||||
|
@ -4,6 +4,7 @@ using Elwig.Models.Entities;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@ -50,18 +51,18 @@ namespace Elwig.Windows {
|
|||||||
public AdministrationWindow() : base() {
|
public AdministrationWindow() : base() {
|
||||||
IsEditing = false;
|
IsEditing = false;
|
||||||
IsCreating = false;
|
IsCreating = false;
|
||||||
ExemptInputs = Array.Empty<Control>();
|
ExemptInputs = [];
|
||||||
RequiredInputs = Array.Empty<Control>();
|
RequiredInputs = [];
|
||||||
TextBoxInputs = Array.Empty<TextBox>();
|
TextBoxInputs = [];
|
||||||
PlzInputs = Array.Empty<TextBox>();
|
PlzInputs = [];
|
||||||
ComboBoxInputs = Array.Empty<ComboBox>();
|
ComboBoxInputs = [];
|
||||||
CheckComboBoxInputs = Array.Empty<CheckComboBox>();
|
CheckComboBoxInputs = [];
|
||||||
PlzOrtInputs = Array.Empty<ComboBox>();
|
PlzOrtInputs = [];
|
||||||
CheckBoxInputs = Array.Empty<CheckBox>();
|
CheckBoxInputs = [];
|
||||||
RadioButtonInputs = Array.Empty<RadioButton>();
|
RadioButtonInputs = [];
|
||||||
Valid = new();
|
Valid = [];
|
||||||
OriginalValues = new();
|
OriginalValues = [];
|
||||||
DefaultValues = new();
|
DefaultValues = [];
|
||||||
Closing += OnClosing;
|
Closing += OnClosing;
|
||||||
Loaded -= base.OnLoaded;
|
Loaded -= base.OnLoaded;
|
||||||
Loaded += OnLoaded;
|
Loaded += OnLoaded;
|
||||||
@ -104,7 +105,7 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
protected override async Task OnRenewContext() {
|
protected override async Task OnRenewContext() {
|
||||||
for (int i = 0; i < PlzInputs.Length; i++)
|
for (int i = 0; i < PlzInputs.Length; i++)
|
||||||
UpdatePlz(PlzInputs[i], PlzOrtInputs[i]);
|
await UpdatePlz(PlzInputs[i], PlzOrtInputs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ValidateInput(Control input, bool valid) {
|
protected void ValidateInput(Control input, bool valid) {
|
||||||
@ -284,7 +285,7 @@ namespace Elwig.Windows {
|
|||||||
} else if (input is ComboBox sb) {
|
} else if (input is ComboBox sb) {
|
||||||
return OriginalValues[sb] != sb.SelectedItem;
|
return OriginalValues[sb] != sb.SelectedItem;
|
||||||
} else if (input is CheckComboBox ccb) {
|
} else if (input is CheckComboBox ccb) {
|
||||||
return !ccb.SelectedItems.Cast<object>().ToArray().SequenceEqual(((object[]?)OriginalValues[ccb]) ?? Array.Empty<object>());
|
return !ccb.SelectedItems.Cast<object>().ToArray().SequenceEqual(((object[]?)OriginalValues[ccb]) ?? []);
|
||||||
} else if (input is CheckBox cb) {
|
} else if (input is CheckBox cb) {
|
||||||
return (string?)OriginalValues[cb] != cb.IsChecked?.ToString();
|
return (string?)OriginalValues[cb] != cb.IsChecked?.ToString();
|
||||||
} else if (input is RadioButton rb) {
|
} else if (input is RadioButton rb) {
|
||||||
@ -303,7 +304,7 @@ namespace Elwig.Windows {
|
|||||||
} else if (input is ComboBox sb) {
|
} else if (input is ComboBox sb) {
|
||||||
return DefaultValues[sb] != sb.SelectedItem;
|
return DefaultValues[sb] != sb.SelectedItem;
|
||||||
} else if (input is CheckComboBox ccb) {
|
} else if (input is CheckComboBox ccb) {
|
||||||
return !ccb.SelectedItems.Cast<object>().ToArray().SequenceEqual(((object[]?)DefaultValues[ccb]) ?? Array.Empty<object>());
|
return !ccb.SelectedItems.Cast<object>().ToArray().SequenceEqual(((object[]?)DefaultValues[ccb]) ?? []);
|
||||||
} else if (input is CheckBox cb) {
|
} else if (input is CheckBox cb) {
|
||||||
return (string?)DefaultValues[cb] != cb.IsChecked?.ToString();
|
return (string?)DefaultValues[cb] != cb.IsChecked?.ToString();
|
||||||
} else if (input is RadioButton rb) {
|
} else if (input is RadioButton rb) {
|
||||||
@ -329,10 +330,19 @@ namespace Elwig.Windows {
|
|||||||
RadioButtonInputs.Any(InputIsNotDefault)
|
RadioButtonInputs.Any(InputIsNotDefault)
|
||||||
);
|
);
|
||||||
|
|
||||||
protected void UpdatePlz(TextBox plzInput, ComboBox ortInput) {
|
protected async Task UpdatePlz(TextBox plzInput, ComboBox ortInput) {
|
||||||
var plzInputValid = Validator.CheckPlz(plzInput, RequiredInputs.Contains(plzInput), Context).IsValid;
|
var plzInputValid = Validator.CheckPlz(plzInput, RequiredInputs.Contains(plzInput)).IsValid;
|
||||||
var item = ortInput.SelectedItem;
|
|
||||||
var list = plzInputValid && plzInput.Text.Length == 4 ? Context.Postleitzahlen.Find(int.Parse(plzInput.Text))?.Orte.ToList() : null;
|
List<AT_PlzDest>? list = null;
|
||||||
|
if (plzInputValid && plzInput.Text.Length == 4) {
|
||||||
|
var plz = int.Parse(plzInput.Text);
|
||||||
|
using var ctx = new AppDbContext();
|
||||||
|
list = await ctx.PlzDestinations
|
||||||
|
.Where(p => p.Plz == plz)
|
||||||
|
.Include(p => p.Ort)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
ControlUtils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id);
|
ControlUtils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id);
|
||||||
if (list != null && ortInput.SelectedItem == null && list.Count == 1)
|
if (list != null && ortInput.SelectedItem == null && list.Count == 1)
|
||||||
ortInput.SelectedItem = list[0];
|
ortInput.SelectedItem = list[0];
|
||||||
@ -360,11 +370,7 @@ namespace Elwig.Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) {
|
protected bool InputTextChanged(TextBox input, Func<TextBox, bool, ValidationResult> checker) {
|
||||||
return InputTextChanged(input, (tb, required, ctx) => checker(tb, required));
|
return InputTextChanged(input, checker(input, SenderIsRequired(input)));
|
||||||
}
|
|
||||||
|
|
||||||
protected bool InputTextChanged(TextBox input, Func<TextBox, bool, AppDbContext, ValidationResult> checker) {
|
|
||||||
return InputTextChanged(input, checker(input, SenderIsRequired(input), Context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool InputTextChanged(TextBox input, ValidationResult res) {
|
protected bool InputTextChanged(TextBox input, ValidationResult res) {
|
||||||
@ -385,11 +391,7 @@ namespace Elwig.Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected bool InputLostFocus(TextBox input, Func<TextBox, bool, ValidationResult> checker, string? msg = null) {
|
protected bool InputLostFocus(TextBox input, Func<TextBox, bool, ValidationResult> checker, string? msg = null) {
|
||||||
return InputLostFocus(input, (tb, requiered, ctx) => checker(tb, requiered), msg);
|
return InputLostFocus(input, checker(input, SenderIsRequired(input)), msg);
|
||||||
}
|
|
||||||
|
|
||||||
protected bool InputLostFocus(TextBox input, Func<TextBox, bool, AppDbContext, ValidationResult> checker, string? msg = null) {
|
|
||||||
return InputLostFocus(input, checker(input, SenderIsRequired(input), Context), msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected bool InputLostFocus(TextBox input, ValidationResult res, string? msg = null) {
|
protected bool InputLostFocus(TextBox input, ValidationResult res, string? msg = null) {
|
||||||
@ -506,18 +508,18 @@ namespace Elwig.Windows {
|
|||||||
InputLostFocus((TextBox)sender, Validator.CheckTime);
|
InputLostFocus((TextBox)sender, Validator.CheckTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void PlzInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
protected async void PlzInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||||
var plz = (TextBox)sender;
|
var plz = (TextBox)sender;
|
||||||
InputTextChanged(plz, Validator.CheckPlz);
|
InputTextChanged(plz, Validator.CheckPlz);
|
||||||
if ("PLZ".Equals(plz.Tag))
|
if ("PLZ".Equals(plz.Tag))
|
||||||
UpdatePlz(plz, GetPlzOrtInput(plz));
|
await UpdatePlz(plz, GetPlzOrtInput(plz));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void PlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
protected async void PlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||||
var plz = (TextBox)sender;
|
var plz = (TextBox)sender;
|
||||||
InputLostFocus(plz, Validator.CheckPlz);
|
InputLostFocus(plz, Validator.CheckPlz);
|
||||||
if ("PLZ".Equals(plz.Tag))
|
if ("PLZ".Equals(plz.Tag))
|
||||||
UpdatePlz(plz, GetPlzOrtInput(plz));
|
await UpdatePlz(plz, GetPlzOrtInput(plz));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void EmailAddressInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
protected void EmailAddressInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||||
|
Reference in New Issue
Block a user