Rename MemberListWindow to MemberAdministrationWindow
This commit is contained in:
@ -1,674 +0,0 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ModernWpf.Controls;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class MemberListWindow : Window {
|
||||
private bool IsEditing = false;
|
||||
private bool IsCreating = false;
|
||||
private List<string> TextFilter = new();
|
||||
private readonly Control[] ExemptInputs;
|
||||
private IEnumerable<TextBox> TextBoxInputs = Array.Empty<TextBox>();
|
||||
private IEnumerable<ComboBox> ComboBoxInputs = Array.Empty<ComboBox>();
|
||||
private IEnumerable<CheckBox> CheckBoxInputs = Array.Empty<CheckBox>();
|
||||
private IEnumerable<RadioButton> RadioButtonInputs = Array.Empty<RadioButton>();
|
||||
private readonly Dictionary<Control, bool> Valid = new();
|
||||
private readonly Dictionary<Control, object?> OriginalValues = new();
|
||||
private readonly RoutedCommand CtrlF = new();
|
||||
private readonly AppDbContext Context = new();
|
||||
|
||||
public MemberListWindow() {
|
||||
InitializeComponent();
|
||||
CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
|
||||
CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
|
||||
ExemptInputs = new Control[] {
|
||||
SearchInput, ActiveMemberInput, MemberList,
|
||||
NewMemberButton, EditMemberButton, DeleteMemberButton,
|
||||
ResetButton, SaveButton, CancelButton
|
||||
};
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||
ActiveMemberInput.IsChecked = true;
|
||||
BranchInput.ItemsSource = Context.Branches.OrderBy(b => b.Name).ToList();
|
||||
DefaultKgInput.ItemsSource = Context.WbKgs.Select(k => k.Kg).OrderBy(k => k.Name).ToList();
|
||||
TextBoxInputs = Utils.FindVisualChilds<TextBox>(this, ExemptInputs).ToList();
|
||||
ComboBoxInputs = Utils.FindVisualChilds<ComboBox>(this, ExemptInputs).ToList();
|
||||
CheckBoxInputs = Utils.FindVisualChilds<CheckBox>(this, ExemptInputs).ToList();
|
||||
RadioButtonInputs = Utils.FindVisualChilds<RadioButton>(this, ExemptInputs).ToList();
|
||||
foreach (var tb in TextBoxInputs)
|
||||
Valid[tb] = true;
|
||||
}
|
||||
|
||||
protected override void OnClosing(CancelEventArgs evt) {
|
||||
Context.Dispose();
|
||||
base.OnClosing(evt);
|
||||
}
|
||||
|
||||
private int CountMatchesInMember(Member m) {
|
||||
if (TextFilter.Count == 0) return 0;
|
||||
string?[] check = new string?[] { m.MgNr.ToString(), m.FamilyName.ToLower(), m.GivenName.ToLower(), m.DefaultKg?.Name?.ToLower() };
|
||||
int i = 0;
|
||||
foreach (string? c in check) {
|
||||
if (c == null) continue;
|
||||
if (TextFilter.Any(f => c == f))
|
||||
i += 10;
|
||||
else if (TextFilter.Any(f => c.Contains(f)))
|
||||
i += 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
private void RefreshMemberList() {
|
||||
Context.Members.Load();
|
||||
IQueryable<Member> memberQuery = Context.Members;
|
||||
if (ActiveMemberInput.IsChecked == true)
|
||||
memberQuery = memberQuery.Where(m => m.IsActive);
|
||||
|
||||
List<Member> members = memberQuery.ToList();
|
||||
members = members.OrderBy(m => m.FamilyName + " " + m.GivenName).ToList();
|
||||
|
||||
if (TextFilter.Count > 0) {
|
||||
members = members
|
||||
.ToDictionary(m => m, m => CountMatchesInMember(m))
|
||||
.OrderByDescending(a => a.Value)
|
||||
.Where(a => a.Value > 0)
|
||||
.Select(a => a.Key)
|
||||
.ToList();
|
||||
}
|
||||
MemberList.ItemsSource = members;
|
||||
if (members.Count == 1)
|
||||
MemberList.SelectedIndex = 0;
|
||||
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
private void ClearInputStates() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
Utils.ClearInputState(tb);
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
Utils.ClearInputState(cb);
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
Utils.ClearInputState(cb);
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
Utils.ClearInputState(rb);
|
||||
}
|
||||
|
||||
private void RefreshInputs(bool validate = false) {
|
||||
ClearInputStates();
|
||||
Member m = (Member)MemberList.SelectedItem;
|
||||
if (m != null) {
|
||||
EditMemberButton.IsEnabled = true;
|
||||
DeleteMemberButton.IsEnabled = true;
|
||||
FillInputs(m);
|
||||
} else {
|
||||
EditMemberButton.IsEnabled = false;
|
||||
DeleteMemberButton.IsEnabled = false;
|
||||
ClearInputs();
|
||||
}
|
||||
if (!validate) ClearInputStates();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
private void InitInputs() {
|
||||
MgNrInput.Text = Utils.NextMgNr(Context).ToString();
|
||||
EntryDateInput.Text = DateTime.Now.ToString("dd.MM.yyyy");
|
||||
if (Context.Branches.Count() == 1)
|
||||
BranchInput.SelectedItem = Context.Branches.First();
|
||||
ActiveInput.IsChecked = true;
|
||||
ContactPostInput.IsChecked = true;
|
||||
FillOriginalValues();
|
||||
}
|
||||
|
||||
private void MemberList_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
private void ActiveMemberInput_Changed(object sender, RoutedEventArgs evt) {
|
||||
RefreshMemberList();
|
||||
}
|
||||
|
||||
private void NewMemberButton_Click(object sender, RoutedEventArgs evt) {
|
||||
IsCreating = true;
|
||||
MemberList.IsEnabled = false;
|
||||
MemberList.SelectedItem = null;
|
||||
HideNewEditDeleteButtons();
|
||||
ShowSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
InitInputs();
|
||||
LockSearchInputs();
|
||||
}
|
||||
|
||||
private void EditMemberButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (MemberList.SelectedItem == null)
|
||||
return;
|
||||
|
||||
IsEditing = true;
|
||||
MemberList.IsEnabled = false;
|
||||
|
||||
HideNewEditDeleteButtons();
|
||||
ShowSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
LockSearchInputs();
|
||||
}
|
||||
|
||||
private void DeleteMemberButton_Click(object sender, RoutedEventArgs evt) {
|
||||
Member m = (Member)MemberList.SelectedItem;
|
||||
if (m == null) return;
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll das Mitglied \"{m.FamilyName} {m.GivenName}\" (MgNr. {m.MgNr}) wirklich unwiderruflich gelöscht werden?",
|
||||
"Mitglied löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r == MessageBoxResult.Yes) {
|
||||
Context.Remove(m);
|
||||
Context.SaveChanges();
|
||||
RefreshMemberList();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs evt) {
|
||||
Member? m = new();
|
||||
if (IsEditing)
|
||||
m = (Member)MemberList.SelectedItem;
|
||||
else if (IsCreating)
|
||||
m = new();
|
||||
|
||||
int newMgNr = int.Parse(MgNrInput.Text);
|
||||
m.PredecessorMgNr = (PredecessorMgNrInput.Text == "") ? null : int.Parse(PredecessorMgNrInput.Text);
|
||||
m.Prefix = (PrefixInput.Text == "") ? null : PrefixInput.Text;
|
||||
m.GivenName = GivenNameInput.Text;
|
||||
m.FamilyName = FamilyNameInput.Text;
|
||||
m.Suffix = (SuffixInput.Text == "") ? null : SuffixInput.Text;
|
||||
m.Birthday = (BirthdayInput.Text == "") ? null : string.Join("-", BirthdayInput.Text.Split(".").Reverse());
|
||||
m.CountryCode = "AT";
|
||||
m.PostalDestId = ((AT_PlzDest)OrtInput.SelectedItem).Id;
|
||||
m.Address = AddressInput.Text;
|
||||
|
||||
m.Email = (EmailInput.Text == "") ? null : EmailInput.Text;
|
||||
m.PhoneLandline = (PhoneLandlineInput.Text == "") ? null : PhoneLandlineInput.Text.Replace(" ", "");
|
||||
m.PhoneMobile1 = (PhoneMobile1Input.Text == "") ? null : PhoneMobile1Input.Text.Replace(" ", "");
|
||||
m.PhoneMobile2 = (PhoneMobile2Input.Text == "") ? null : PhoneMobile2Input.Text.Replace(" ", "");
|
||||
|
||||
m.Iban = (IbanInput.Text == "") ? null : IbanInput.Text.Replace(" ", "");
|
||||
m.Bic = (BicInput.Text == "") ? null : BicInput.Text;
|
||||
|
||||
m.UstId = (UstIdInput.Text == "") ? null : UstIdInput.Text;
|
||||
m.LfbisNr = (LfbisNrInput.Text == "") ? null : LfbisNrInput.Text;
|
||||
m.IsBuchführend = BuchführendInput.IsChecked ?? false;
|
||||
|
||||
// TODO Rechnungsadresse
|
||||
|
||||
m.EntryDate = (EntryDateInput.Text == "") ? null : string.Join("-", EntryDateInput.Text.Split(".").Reverse());
|
||||
m.ExitDate = (ExitDateInput.Text == "") ? null : string.Join("-", ExitDateInput.Text.Split(".").Reverse());
|
||||
m.BusinessShares = (BusinessSharesInput.Text == "") ? 0 : int.Parse(BusinessSharesInput.Text);
|
||||
m.AccountingNr = (AccountingNrInput.Text == "") ? null : AccountingNrInput.Text;
|
||||
m.IsActive = ActiveInput.IsChecked ?? false;
|
||||
m.IsVollLieferant = VollLieferantInput.IsChecked ?? false;
|
||||
m.IsFunktionär = FunkionärInput.IsChecked ?? false;
|
||||
m.ZwstId = ((Branch)BranchInput.SelectedItem).ZwstId;
|
||||
m.DefaultKgNr = ((AT_Kg)DefaultKgInput.SelectedItem).KgNr;
|
||||
m.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
|
||||
m.DefaultContact = "post";
|
||||
if (ContactPostInput.IsChecked ?? false) m.DefaultContact = "post";
|
||||
if (ContactEmailInput.IsChecked ?? false) m.DefaultContact = "email";
|
||||
|
||||
try {
|
||||
if (IsEditing)
|
||||
Context.Update(m);
|
||||
else if (IsCreating)
|
||||
Context.Add(m);
|
||||
Context.SaveChanges();
|
||||
|
||||
if (newMgNr != m.MgNr)
|
||||
Context.Database.ExecuteSql($"UPDATE member SET mgnr = {newMgNr} WHERE mgnr = {m.MgNr}");
|
||||
} catch (Exception exc) {
|
||||
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message;
|
||||
if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
|
||||
MessageBox.Show(str, "Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
MemberList.IsEnabled = true;
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
LockInputs();
|
||||
UnlockSearchInputs();
|
||||
RefreshMemberList();
|
||||
}
|
||||
|
||||
private void ResetButton_Click(object sender, RoutedEventArgs evt) {
|
||||
if (IsEditing) {
|
||||
RefreshInputs();
|
||||
} else if (IsCreating) {
|
||||
InitInputs();
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void CancelButton_Click(object sender, RoutedEventArgs evt) {
|
||||
IsEditing = false;
|
||||
IsCreating = false;
|
||||
MemberList.IsEnabled = true;
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
RefreshInputs();
|
||||
ClearInputStates();
|
||||
LockInputs();
|
||||
UnlockSearchInputs();
|
||||
}
|
||||
|
||||
private void ContractButton_Click(object sender, RoutedEventArgs evt) {
|
||||
var w = new ContractListWindow((Member)MemberList.SelectedItem);
|
||||
w.Show();
|
||||
}
|
||||
|
||||
private void SearchInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
TextFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(s => s != "");
|
||||
RefreshMemberList();
|
||||
}
|
||||
|
||||
private void Menu_Member_SendEmail_Click(object sender, RoutedEventArgs evt) {
|
||||
Utils.MailTo(((Member)MemberList.SelectedItem).Email);
|
||||
}
|
||||
|
||||
private void FocusSearchInput(object sender, RoutedEventArgs evt) {
|
||||
if (!IsEditing && !IsCreating) {
|
||||
SearchInput.Focus();
|
||||
SearchInput.SelectAll();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowSaveResetCancelButtons() {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
CancelButton.IsEnabled = true;
|
||||
SaveButton.Visibility = Visibility.Visible;
|
||||
ResetButton.Visibility = Visibility.Visible;
|
||||
CancelButton.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void HideSaveResetCancelButtons() {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
CancelButton.IsEnabled = false;
|
||||
SaveButton.Visibility = Visibility.Hidden;
|
||||
ResetButton.Visibility = Visibility.Hidden;
|
||||
CancelButton.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void ShowNewEditDeleteButtons() {
|
||||
NewMemberButton.IsEnabled = true;
|
||||
EditMemberButton.IsEnabled = MemberList.SelectedItem != null;
|
||||
DeleteMemberButton.IsEnabled = MemberList.SelectedItem != null;
|
||||
NewMemberButton.Visibility = Visibility.Visible;
|
||||
EditMemberButton.Visibility = Visibility.Visible;
|
||||
DeleteMemberButton.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void HideNewEditDeleteButtons() {
|
||||
NewMemberButton.IsEnabled = false;
|
||||
EditMemberButton.IsEnabled = false;
|
||||
DeleteMemberButton.IsEnabled = false;
|
||||
NewMemberButton.Visibility = Visibility.Hidden;
|
||||
EditMemberButton.Visibility = Visibility.Hidden;
|
||||
DeleteMemberButton.Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void LockInputs() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
tb.IsReadOnly = true;
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
cb.IsEnabled = false;
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
cb.IsEnabled = false;
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
rb.IsEnabled = false;
|
||||
}
|
||||
|
||||
private void UnlockInputs() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
tb.IsReadOnly = false;
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
cb.IsEnabled = true;
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
cb.IsEnabled = true;
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
rb.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void LockSearchInputs() {
|
||||
SearchInput.IsEnabled = false;
|
||||
ActiveMemberInput.IsEnabled = false;
|
||||
}
|
||||
|
||||
private void UnlockSearchInputs() {
|
||||
SearchInput.IsEnabled = true;
|
||||
ActiveMemberInput.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void FillInputs(Member m) {
|
||||
OriginalValues.Clear();
|
||||
|
||||
MgNrInput.Text = m.MgNr.ToString();
|
||||
PredecessorMgNrInput.Text = m.PredecessorMgNr.ToString();
|
||||
PrefixInput.Text = m.Prefix;
|
||||
GivenNameInput.Text = m.GivenName;
|
||||
FamilyNameInput.Text = m.FamilyName;
|
||||
SuffixInput.Text = m.Suffix;
|
||||
BirthdayInput.Text = (m.Birthday != null) ? string.Join(".", m.Birthday.Split("-").Reverse()) : null;
|
||||
AddressInput.Text = m.Address;
|
||||
AT_PlzDest? p = m.PostalDest.AtPlz;
|
||||
if (p != null) {
|
||||
PlzInput.Text = p.Plz.ToString();
|
||||
OrtInput.ItemsSource = p.AtPlz.Orte;
|
||||
OrtInput.SelectedItem = p;
|
||||
} else {
|
||||
PlzInput.Text = null;
|
||||
OrtInput.ItemsSource = null;
|
||||
OrtInput.SelectedItem = null;
|
||||
}
|
||||
|
||||
EmailInput.Text = m.Email;
|
||||
PhoneLandlineInput.Text = m.PhoneLandline;
|
||||
PhoneMobile1Input.Text = m.PhoneMobile1;
|
||||
PhoneMobile2Input.Text = m.PhoneMobile2;
|
||||
|
||||
IbanInput.Text = m.Iban;
|
||||
BicInput.Text = m.Bic;
|
||||
|
||||
UstIdInput.Text = m.UstId;
|
||||
LfbisNrInput.Text = m.LfbisNr;
|
||||
BuchführendInput.IsChecked = m.IsBuchführend;
|
||||
|
||||
// TODO Rechnungsadresse
|
||||
|
||||
EntryDateInput.Text = (m.EntryDate != null) ? string.Join(".", m.EntryDate.Split("-").Reverse()) : null;
|
||||
ExitDateInput.Text = (m.ExitDate != null) ? string.Join(".", m.ExitDate.Split("-").Reverse()) : null;
|
||||
BusinessSharesInput.Text = m.BusinessShares.ToString();
|
||||
AccountingNrInput.Text = m.AccountingNr;
|
||||
BranchInput.SelectedItem = m.Branch;
|
||||
DefaultKgInput.SelectedItem = m.DefaultKg;
|
||||
CommentInput.Text = m.Comment;
|
||||
ActiveInput.IsChecked = m.IsActive;
|
||||
VollLieferantInput.IsChecked = m.IsVollLieferant;
|
||||
FunkionärInput.IsChecked = m.IsFunktionär;
|
||||
switch (m.DefaultContact) {
|
||||
case "post": ContactPostInput.IsChecked = true; break;
|
||||
case "email": ContactEmailInput.IsChecked = true; break;
|
||||
}
|
||||
|
||||
AreaCommitment.Text = $"{m.Contracts.Select(c => c.Area).Sum():N0} m²";
|
||||
|
||||
Menu_Member_SendEmail.IsEnabled = m.Email != null;
|
||||
|
||||
FillOriginalValues();
|
||||
}
|
||||
|
||||
private void FillOriginalValues() {
|
||||
foreach (var tb in TextBoxInputs)
|
||||
OriginalValues[tb] = tb.Text;
|
||||
foreach (var cb in ComboBoxInputs)
|
||||
OriginalValues[cb] = cb.SelectedItem;
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
OriginalValues[cb] = (cb.IsChecked ?? false) ? bool.TrueString : null;
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
OriginalValues[rb] = (rb.IsChecked ?? false) ? bool.TrueString : null;
|
||||
}
|
||||
|
||||
private void ClearInputs() {
|
||||
Menu_Member_SendEmail.IsEnabled = false;
|
||||
AreaCommitment.Text = "- m²";
|
||||
OriginalValues.Clear();
|
||||
foreach (var tb in TextBoxInputs) {
|
||||
tb.Text = " ";
|
||||
tb.Text = "";
|
||||
}
|
||||
foreach (var cb in ComboBoxInputs) {
|
||||
cb.SelectedItem = null;
|
||||
if (cb.ItemsSource != null)
|
||||
Utils.SetInputInvalid(cb);
|
||||
}
|
||||
foreach (var cb in CheckBoxInputs)
|
||||
cb.IsChecked = false;
|
||||
foreach (var rb in RadioButtonInputs)
|
||||
rb.IsChecked = false;
|
||||
}
|
||||
|
||||
private bool IsValid() {
|
||||
return Valid.All(kv => kv.Value) && ComboBoxInputs.All(cb => cb.ItemsSource == null || cb.SelectedItem != null);
|
||||
}
|
||||
|
||||
private void UpdateButtons() {
|
||||
if (!IsEditing && !IsCreating) return;
|
||||
bool ch = HasChanged(), v = IsValid();
|
||||
ResetButton.IsEnabled = (ch);
|
||||
SaveButton.IsEnabled = (v && ch);
|
||||
}
|
||||
|
||||
private bool InputHasChanged(Control input) {
|
||||
if (!OriginalValues.ContainsKey(input)) {
|
||||
return false;
|
||||
} else if (input is TextBox tb) {
|
||||
return OriginalValues[tb]?.ToString() != tb.Text;
|
||||
} else if (input is ComboBox sb) {
|
||||
return OriginalValues[sb] != sb.SelectedItem;
|
||||
} else if (input is CheckBox cb) {
|
||||
return (OriginalValues[cb] != null) != (cb.IsChecked ?? false);
|
||||
} else if (input is RadioButton rb) {
|
||||
return (OriginalValues[rb] != null) != (rb.IsChecked ?? false);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasChanged() {
|
||||
return !IsValid() ||
|
||||
TextBoxInputs.Any(InputHasChanged) ||
|
||||
ComboBoxInputs.Any(InputHasChanged) ||
|
||||
CheckBoxInputs.Any(InputHasChanged) ||
|
||||
RadioButtonInputs.Any(InputHasChanged);
|
||||
}
|
||||
|
||||
private void UpdatePlz(TextBox plzInput, ComboBox ortInput, bool optional) {
|
||||
if (plzInput.Text.Length == 4) {
|
||||
int plz = int.Parse(plzInput.Text);
|
||||
ortInput.ItemsSource = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
||||
} else {
|
||||
ortInput.ItemsSource = null;
|
||||
}
|
||||
ortInput.SelectedItem = null;
|
||||
if (ortInput.ItemsSource != null) {
|
||||
Utils.SetInputInvalid(ortInput);
|
||||
} else {
|
||||
Utils.ClearInputState(ortInput);
|
||||
}
|
||||
Valid[plzInput] = optional || (ortInput.ItemsSource != null);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void InputTextChanged(TextBox input, bool optional, Func<TextBox, bool, ValidationResult> checker) {
|
||||
InputTextChanged(input, optional, (tb, opt, ctx) => checker(tb, opt));
|
||||
}
|
||||
|
||||
private void InputTextChanged(TextBox input, bool optional, Func<TextBox, bool, AppDbContext, ValidationResult> checker) {
|
||||
InputTextChanged(input, optional, (tb, opt, ctx, m) => checker(tb, opt, ctx));
|
||||
}
|
||||
|
||||
private void InputTextChanged(TextBox input, bool optional, Func<TextBox, bool, AppDbContext, Member, ValidationResult> checker) {
|
||||
var res = checker(input, optional, Context, (Member)MemberList.SelectedItem);
|
||||
Valid[input] = res.IsValid;
|
||||
if (res.IsValid) {
|
||||
if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
} else {
|
||||
Utils.SetInputInvalid(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void InputLostFocus(TextBox input, bool optional, Func<TextBox, bool, ValidationResult> checker, string? msg = null) {
|
||||
InputLostFocus(input, optional, (tb, optional, ctx) => checker(tb, optional), msg);
|
||||
}
|
||||
|
||||
private void InputLostFocus(TextBox input, bool optional, Func<TextBox, bool, AppDbContext, ValidationResult> checker, string? msg = null) {
|
||||
InputLostFocus(input, optional, (tb, optional, ctx, m) => checker(tb, optional, ctx), msg);
|
||||
}
|
||||
|
||||
private void InputLostFocus(TextBox input, bool optional, Func<TextBox, bool, AppDbContext, Member?, ValidationResult> checker, string? msg = null) {
|
||||
var res = checker(input, optional, Context, (Member)MemberList.SelectedItem);
|
||||
if (!res.IsValid)
|
||||
MessageBox.Show(res.ErrorContent.ToString(), msg ?? res.ErrorContent.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
|
||||
private void CheckBox_Changed(object sender, RoutedEventArgs evt) {
|
||||
var input = (CheckBox)sender;
|
||||
if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void RadioButton_Changed(object sender, RoutedEventArgs evt) {
|
||||
var input = (RadioButton)sender;
|
||||
if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void TextBox_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
var input = (TextBox)sender;
|
||||
if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
var input = (ComboBox)sender;
|
||||
if (input.ItemsSource != null && input.SelectedItem == null) {
|
||||
Utils.SetInputInvalid(input);
|
||||
} else if (InputHasChanged(input)) {
|
||||
Utils.SetInputChanged(input);
|
||||
} else {
|
||||
Utils.ClearInputState(input);
|
||||
}
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
private void NumericInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, false, Validator.CheckNumeric);
|
||||
}
|
||||
|
||||
private void MgNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, false, Validator.CheckMgNr);
|
||||
}
|
||||
|
||||
private void MgNrInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, false, Validator.CheckMgNr);
|
||||
}
|
||||
|
||||
private void PredecessorMgNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckPredecessorMgNr);
|
||||
}
|
||||
|
||||
private void PredecessorMgNrInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckPredecessorMgNr);
|
||||
}
|
||||
|
||||
private void BirthdayInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckPartialDate);
|
||||
}
|
||||
|
||||
private void PlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, false, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, OrtInput, false);
|
||||
}
|
||||
|
||||
private void PlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, OrtInput, false);
|
||||
}
|
||||
|
||||
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckPhoneNumber);
|
||||
}
|
||||
|
||||
private void PhoneNrInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckPhoneNumber);
|
||||
}
|
||||
|
||||
private void EmailInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckEmailAddress);
|
||||
}
|
||||
|
||||
private void EmailInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckEmailAddress);
|
||||
}
|
||||
|
||||
private void IbanInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckIban);
|
||||
}
|
||||
|
||||
private void IbanInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckIban);
|
||||
}
|
||||
|
||||
private void BicInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckBic);
|
||||
}
|
||||
|
||||
private void BicInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckBic);
|
||||
}
|
||||
|
||||
private void UstIdInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckUstId);
|
||||
}
|
||||
|
||||
private void UstIdInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckUstId);
|
||||
}
|
||||
|
||||
private void LfbisNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckLfbisNr);
|
||||
}
|
||||
|
||||
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckLfbisNr);
|
||||
}
|
||||
|
||||
private void BillingPlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, BillingOrtInput, true);
|
||||
}
|
||||
|
||||
private void BillingPlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, BillingOrtInput, true);
|
||||
}
|
||||
|
||||
private void DateInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckDate);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user