Add telephone numbers
This commit is contained in:
Elwig
@ -9,12 +9,20 @@ using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class MemberAdminWindow : AdministrationWindow {
|
||||
|
||||
private List<string> TextFilter = new();
|
||||
private readonly RoutedCommand CtrlF = new();
|
||||
private readonly (ComboBox, TextBox, TextBox)[] PhoneNrInputs;
|
||||
|
||||
private static ObservableCollection<KeyValuePair<string, string>> PhoneNrTypes { get; set; } = new() {
|
||||
new("landline", "Tel.-Nr. (Festnetz)"),
|
||||
new("mobile", "Tel.-Nr. (mobil)"),
|
||||
new("fax", "Fax-Nr."),
|
||||
};
|
||||
|
||||
public MemberAdminWindow() {
|
||||
InitializeComponent();
|
||||
@ -30,10 +38,23 @@ namespace Elwig.Windows {
|
||||
AddressInput, PlzInput, OrtInput, BillingOrtInput,
|
||||
BusinessSharesInput, BranchInput, DefaultKgInput
|
||||
};
|
||||
PhoneNrInputs = new (ComboBox, TextBox, TextBox)[] {
|
||||
(PhoneNr1TypeInput, PhoneNr1Input, PhoneNr1CommentInput),
|
||||
(PhoneNr2TypeInput, PhoneNr2Input, PhoneNr2CommentInput),
|
||||
(PhoneNr3TypeInput, PhoneNr3Input, PhoneNr3CommentInput),
|
||||
(PhoneNr4TypeInput, PhoneNr4Input, PhoneNr4CommentInput),
|
||||
(PhoneNr5TypeInput, PhoneNr5Input, PhoneNr5CommentInput),
|
||||
(PhoneNr6TypeInput, PhoneNr6Input, PhoneNr6CommentInput),
|
||||
(PhoneNr7TypeInput, PhoneNr7Input, PhoneNr7CommentInput),
|
||||
(PhoneNr8TypeInput, PhoneNr8Input, PhoneNr8CommentInput),
|
||||
(PhoneNr9TypeInput, PhoneNr9Input, PhoneNr9CommentInput),
|
||||
};
|
||||
foreach (var input in PhoneNrInputs) input.Item1.ItemsSource = PhoneNrTypes;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||
ActiveMemberInput.IsChecked = true;
|
||||
UpdatePhoneNrInputVisibility();
|
||||
}
|
||||
|
||||
private async Task RefreshMemberList() {
|
||||
@ -108,6 +129,31 @@ namespace Elwig.Windows {
|
||||
await RefreshMemberList();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private (string, string, string?)? GetPhonenrInput(int nr) {
|
||||
var inputs = PhoneNrInputs[nr];
|
||||
var number = inputs.Item2.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;
|
||||
return (type, number, comment == "" ? null : comment);
|
||||
}
|
||||
|
||||
private void SetPhoneNrInputVisible(int nr, bool visible) {
|
||||
var inputs = PhoneNrInputs[nr];
|
||||
var vis = visible ? Visibility.Visible : Visibility.Hidden;
|
||||
inputs.Item1.Visibility = vis;
|
||||
inputs.Item2.Visibility = vis;
|
||||
inputs.Item3.Visibility = vis;
|
||||
}
|
||||
|
||||
private void MemberList_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
RefreshInputs();
|
||||
}
|
||||
@ -123,6 +169,7 @@ namespace Elwig.Windows {
|
||||
HideNewEditDeleteButtons();
|
||||
ShowSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
UpdatePhoneNrInputVisibility(true);
|
||||
InitInputs();
|
||||
LockSearchInputs();
|
||||
}
|
||||
@ -137,6 +184,7 @@ namespace Elwig.Windows {
|
||||
HideNewEditDeleteButtons();
|
||||
ShowSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
UpdatePhoneNrInputVisibility(true);
|
||||
LockSearchInputs();
|
||||
}
|
||||
|
||||
@ -164,6 +212,7 @@ namespace Elwig.Windows {
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
LockInputs();
|
||||
UpdatePhoneNrInputVisibility();
|
||||
UnlockSearchInputs();
|
||||
await RefreshMemberList();
|
||||
SearchInput.Text = "";
|
||||
@ -189,6 +238,7 @@ namespace Elwig.Windows {
|
||||
RefreshInputs();
|
||||
ClearInputStates();
|
||||
LockInputs();
|
||||
UpdatePhoneNrInputVisibility();
|
||||
UnlockSearchInputs();
|
||||
}
|
||||
|
||||
@ -259,6 +309,17 @@ namespace Elwig.Windows {
|
||||
ActiveMemberInput.IsEnabled = true;
|
||||
}
|
||||
|
||||
private void UpdatePhoneNrInputVisibility(bool extra = false) {
|
||||
bool lastVisible = true;
|
||||
var m = (Member)MemberList.SelectedItem;
|
||||
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));
|
||||
lastVisible = vis;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Member> UpdateMember(Member m) {
|
||||
int newMgNr = int.Parse(MgNrInput.Text);
|
||||
m.PredecessorMgNr = (PredecessorMgNrInput.Text == "") ? null : int.Parse(PredecessorMgNrInput.Text);
|
||||
@ -272,9 +333,6 @@ namespace Elwig.Windows {
|
||||
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;
|
||||
@ -324,6 +382,29 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0, j = 0; i < PhoneNrInputs.Length; i++) {
|
||||
var input = GetPhonenrInput(i);
|
||||
var phoneNr = m.TelephoneNumbers.FirstOrDefault(p => p.Nr - 1 == i);
|
||||
if (input == null) {
|
||||
if (phoneNr != null) {
|
||||
Context.Remove(phoneNr);
|
||||
}
|
||||
} else {
|
||||
var pInput = input.Value;
|
||||
MemberTelNr p = phoneNr ?? Context.CreateProxy<MemberTelNr>();
|
||||
p.Nr = ++j;
|
||||
p.Type = pInput.Item1;
|
||||
p.Number = pInput.Item2;
|
||||
p.Comment = pInput.Item3;
|
||||
if (phoneNr == null) {
|
||||
p.MgNr = newMgNr;
|
||||
await Context.AddAsync(p);
|
||||
} else {
|
||||
Context.Update(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
if (newMgNr != m.MgNr) {
|
||||
@ -369,9 +450,16 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
EmailInput.Text = m.Email;
|
||||
PhoneLandlineInput.Text = m.PhoneLandline;
|
||||
PhoneMobile1Input.Text = m.PhoneMobile1;
|
||||
PhoneMobile2Input.Text = m.PhoneMobile2;
|
||||
var phoneNrs = m.TelephoneNumbers.OrderBy(p => p.Nr).ToList();
|
||||
for (int i = 0; i < PhoneNrInputs.Length; i++) {
|
||||
if (i < phoneNrs.Count) {
|
||||
var phoneNr = phoneNrs[i];
|
||||
SetPhoneNrInput(i, phoneNr.Type, phoneNr.Number, phoneNr.Comment);
|
||||
} else {
|
||||
SetPhoneNrInput(i, null, null, null);
|
||||
}
|
||||
}
|
||||
UpdatePhoneNrInputVisibility(IsEditing || IsCreating);
|
||||
|
||||
IbanInput.Text = m.Iban;
|
||||
BicInput.Text = m.Bic;
|
||||
@ -453,5 +541,10 @@ namespace Elwig.Windows {
|
||||
private void PredecessorMgNrInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, Validator.CheckPredecessorMgNr);
|
||||
}
|
||||
|
||||
private new void PhoneNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
base.PhoneNrInput_TextChanged(sender, evt);
|
||||
UpdatePhoneNrInputVisibility(IsEditing || IsCreating);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user