[#4] MemberAdminWindow: Add more input fields for email addresses

This commit is contained in:
2024-01-28 16:22:54 +01:00
parent 75e02751f0
commit 85c8783f7e
2 changed files with 121 additions and 33 deletions

View File

@ -17,7 +17,8 @@ namespace Elwig.Windows {
public partial class MemberAdminWindow : AdministrationWindow {
private List<string> TextFilter = [];
private readonly (ComboBox, TextBox, TextBox)[] PhoneNrInputs;
private readonly (ComboBox Type, TextBox Number, TextBox Comment)[] PhoneNrInputs;
private readonly (Label Label, TextBox Address)[] EmailAddressInputs;
private readonly RoutedCommand CtrlF = new("CtrlF", typeof(MemberAdminWindow), [new KeyGesture(Key.F, ModifierKeys.Control)]);
private readonly RoutedCommand CtrlP = new("CtrlP", typeof(MemberAdminWindow), [new KeyGesture(Key.P, ModifierKeys.Control)]);
@ -38,6 +39,17 @@ namespace Elwig.Windows {
AddressInput, PlzInput, OrtInput, BillingOrtInput,
BusinessSharesInput, BranchInput, DefaultKgInput
];
EmailAddressInputs = [
(EmailAddress1Label, EmailAddress1Input),
(EmailAddress2Label, EmailAddress2Input),
(EmailAddress3Label, EmailAddress3Input),
(EmailAddress4Label, EmailAddress4Input),
(EmailAddress5Label, EmailAddress5Input),
(EmailAddress6Label, EmailAddress6Input),
(EmailAddress7Label, EmailAddress7Input),
(EmailAddress8Label, EmailAddress8Input),
(EmailAddress9Label, EmailAddress9Input),
];
PhoneNrInputs = [
(PhoneNr1TypeInput, PhoneNr1Input, PhoneNr1CommentInput),
(PhoneNr2TypeInput, PhoneNr2Input, PhoneNr2CommentInput),
@ -63,7 +75,7 @@ namespace Elwig.Windows {
Menu_Print_MemberDataSheet.IsEnabled = App.IsPrintingReady;
ActiveMemberInput.IsChecked = true;
UpdatePhoneNrInputVisibility();
UpdateContactInfoVisibility();
LockInputs();
}
@ -236,27 +248,55 @@ namespace Elwig.Windows {
private void SetPhoneNrInput(int nr, string? type, string? number, string? comment) {
var inputs = PhoneNrInputs[nr];
inputs.Item1.SelectedItem = (type == null) ? null : inputs.Item1.ItemsSource.Cast<KeyValuePair<string, string>>().FirstOrDefault(p => p.Key == type);
inputs.Item2.Text = number;
inputs.Item3.Text = comment;
inputs.Type.SelectedItem = (type == null) ? null : inputs.Type.ItemsSource.Cast<KeyValuePair<string, string>>().FirstOrDefault(p => p.Key == type);
inputs.Number.Text = number;
inputs.Comment.Text = comment;
}
private void SetEmailAddressInput(int nr, string? address) {
var inputs = EmailAddressInputs[nr];
inputs.Address.Text = address;
}
private (string, string, string?)? GetPhoneNrInput(int nr) {
var inputs = PhoneNrInputs[nr];
var number = inputs.Item2.Text;
var number = inputs.Number.Text;
if (string.IsNullOrEmpty(number))
return null;
var type = (inputs.Item1.SelectedItem as KeyValuePair<string, string>?)?.Key ?? (number.StartsWith("+43 ") && number[4] == '6' ? "mobile" : "landline");
var comment = inputs.Item3.Text;
var type = (inputs.Type.SelectedItem as KeyValuePair<string, string>?)?.Key ?? (number.StartsWith("+43 ") && number[4] == '6' ? "mobile" : "landline");
var comment = inputs.Comment.Text;
return (type, number, comment == "" ? null : comment);
}
private void SetPhoneNrInputVisible(int nr, bool visible) {
private string? GetEmailAddressInput(int nr) {
var inputs = EmailAddressInputs[nr];
return inputs.Address.Text == "" ? null : inputs.Address.Text;
}
private void SetPhoneNrInputVisible(int nr, bool visible, int? position = null) {
var inputs = PhoneNrInputs[nr];
if (position is int p) {
var mt = 10 + p * 30;
inputs.Type.Margin = new(6, mt, 5, 0);
inputs.Number.Margin = new(0, mt, 5, 0);
inputs.Comment.Margin = new(0, mt, 10, 0);
}
var vis = visible ? Visibility.Visible : Visibility.Hidden;
inputs.Item1.Visibility = vis;
inputs.Item2.Visibility = vis;
inputs.Item3.Visibility = vis;
inputs.Type.Visibility = vis;
inputs.Number.Visibility = vis;
inputs.Comment.Visibility = vis;
}
private void SetEmailAddressInputVisible(int nr, bool visible, int? position = null) {
var inputs = EmailAddressInputs[nr];
if (position is int p) {
var mt = 10 + p * 30;
inputs.Label.Margin = new(10, mt, 0, 0);
inputs.Address.Margin = new(0, mt, 10, 0);
}
var vis = visible ? Visibility.Visible : Visibility.Hidden;
inputs.Label.Visibility = vis;
inputs.Address.Visibility = vis;
}
private void MemberList_SelectionChanged(object sender, RoutedEventArgs evt) {
@ -274,7 +314,7 @@ namespace Elwig.Windows {
HideNewEditDeleteButtons();
ShowSaveResetCancelButtons();
UnlockInputs();
UpdatePhoneNrInputVisibility(true);
UpdateContactInfoVisibility(true);
InitInputs();
LockSearchInputs();
}
@ -289,7 +329,7 @@ namespace Elwig.Windows {
HideNewEditDeleteButtons();
ShowSaveResetCancelButtons();
UnlockInputs();
UpdatePhoneNrInputVisibility(true);
UpdateContactInfoVisibility(true);
LockSearchInputs();
}
@ -315,7 +355,7 @@ namespace Elwig.Windows {
HideSaveResetCancelButtons();
ShowNewEditDeleteButtons();
LockInputs();
UpdatePhoneNrInputVisibility();
UpdateContactInfoVisibility();
UnlockSearchInputs();
FinishInputFilling();
await RefreshMemberList();
@ -342,7 +382,7 @@ namespace Elwig.Windows {
ShowNewEditDeleteButtons();
RefreshInputs();
LockInputs();
UpdatePhoneNrInputVisibility();
UpdateContactInfoVisibility();
UnlockSearchInputs();
}
@ -504,13 +544,24 @@ namespace Elwig.Windows {
ActiveMemberInput.IsEnabled = true;
}
private void UpdatePhoneNrInputVisibility(bool extra = false) {
bool lastVisible = true;
var m = (Member)MemberList.SelectedItem;
private void UpdateContactInfoVisibility(bool extra = false) {
var m = MemberList.SelectedItem as Member;
bool lastVisible;
int num = 0;
lastVisible = true;
for (int i = 0; i < EmailAddressInputs.Length; i++) {
var input = EmailAddressInputs[i];
var vis = !string.IsNullOrEmpty(input.Address.Text) || (m?.EmailAddresses.Any(a => a.Nr - 1 == i) ?? false);
var cVis = vis || (extra && lastVisible);
SetEmailAddressInputVisible(i, cVis, cVis ? num++ : null);
lastVisible = vis;
}
lastVisible = true;
for (int i = 0; i < PhoneNrInputs.Length; i++) {
var input = PhoneNrInputs[i];
var vis = !string.IsNullOrEmpty(input.Item2.Text) || (m?.TelephoneNumbers.Any(p => p.Nr - 1 == i) ?? false);
SetPhoneNrInputVisible(i, vis || (extra && lastVisible));
var vis = !string.IsNullOrEmpty(input.Number.Text) || (m?.TelephoneNumbers.Any(n => n.Nr - 1 == i) ?? false);
var cVis = vis || (extra && lastVisible);
SetPhoneNrInputVisible(i, cVis, cVis ? num++ : null);
lastVisible = vis;
}
}
@ -605,17 +656,17 @@ namespace Elwig.Windows {
}
}
for (int i = 0; i < 2; i++) {
var input = i == 0 ? EmailAddress1Input : EmailAddress2Input;
for (int i = 0; i < EmailAddressInputs.Length; i++) {
var input = GetEmailAddressInput(i);
var emailAddr = m.EmailAddresses.FirstOrDefault(a => a.Nr - 1 == i);
if (input.Text == "") {
if (input == null || input == "") {
if (emailAddr != null) {
Context.Remove(emailAddr);
}
} else {
MemberEmailAddr a = emailAddr ?? Context.CreateProxy<MemberEmailAddr>();
a.Nr = i + 1;
a.Address = input.Text;
a.Address = input ?? "";
a.Comment = null;
if (emailAddr == null) {
a.MgNr = newMgNr;
@ -678,8 +729,14 @@ namespace Elwig.Windows {
}
var emailAddrs = m.EmailAddresses.OrderBy(a => a.Nr).ToList();
EmailAddress1Input.Text = emailAddrs.Count > 0 ? emailAddrs[0].Address : "";
EmailAddress2Input.Text = emailAddrs.Count > 1 ? emailAddrs[1].Address : "";
for (int i = 0; i< EmailAddressInputs.Length; i++) {
if (i < emailAddrs.Count) {
var emailAddr = emailAddrs[i];
SetEmailAddressInput(i, emailAddr.Address);
} else {
SetEmailAddressInput(i, null);
}
}
var phoneNrs = m.TelephoneNumbers.OrderBy(p => p.Nr).ToList();
for (int i = 0; i < PhoneNrInputs.Length; i++) {
@ -690,7 +747,7 @@ namespace Elwig.Windows {
SetPhoneNrInput(i, null, null, null);
}
}
UpdatePhoneNrInputVisibility(IsEditing || IsCreating);
UpdateContactInfoVisibility(IsEditing || IsCreating);
IbanInput.Text = m.Iban;
BicInput.Text = m.Bic;
@ -786,9 +843,14 @@ namespace Elwig.Windows {
InputLostFocus((TextBox)sender, Validator.CheckPredecessorMgNr);
}
private new void EmailAddressInput_TextChanged(object sender, TextChangedEventArgs evt) {
base.EmailAddressInput_TextChanged(sender, evt);
UpdateContactInfoVisibility(IsEditing || IsCreating);
}
private new void PhoneNrInput_TextChanged(object sender, TextChangedEventArgs evt) {
base.PhoneNrInput_TextChanged(sender, evt);
UpdatePhoneNrInputVisibility(IsEditing || IsCreating);
UpdateContactInfoVisibility(IsEditing || IsCreating);
}
private void KgDetailsButton_Click(object sender, RoutedEventArgs evt) {