Fix bug where it is not possible to create new members
This commit is contained in:
@ -93,7 +93,8 @@ namespace WGneu.Windows {
|
||||
Utils.ClearInputState(rb);
|
||||
}
|
||||
|
||||
private void RefreshInputs() {
|
||||
private void RefreshInputs(bool validate = false) {
|
||||
ClearInputStates();
|
||||
Member m = (Member)MemberList.SelectedItem;
|
||||
if (m != null) {
|
||||
EditMemberButton.IsEnabled = true;
|
||||
@ -104,12 +105,16 @@ namespace WGneu.Windows {
|
||||
DeleteMemberButton.IsEnabled = false;
|
||||
ClearInputs();
|
||||
}
|
||||
ClearInputStates();
|
||||
if (!validate) ClearInputStates();
|
||||
}
|
||||
|
||||
private void InitInputs() {
|
||||
ClearInputs();
|
||||
MgNrInput.Text = NextMgNr().ToString();
|
||||
MgNrInput.Text = Utils.NextMgNr(Context).ToString();
|
||||
EntryDateInput.Text = DateTime.Now.ToString("dd.MM.yyyy");
|
||||
if (Context.Branches.Count() == 1)
|
||||
BranchInput.SelectedItem = Context.Branches.First();
|
||||
FillOriginalValues();
|
||||
}
|
||||
|
||||
private void MemberList_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
@ -123,10 +128,11 @@ namespace WGneu.Windows {
|
||||
private void NewMemberButton_Click(object sender, RoutedEventArgs evt) {
|
||||
IsCreating = true;
|
||||
MemberList.IsEnabled = false;
|
||||
InitInputs();
|
||||
MemberList.SelectedItem = null;
|
||||
HideNewEditDeleteButtons();
|
||||
ShowSaveResetCancelButtons();
|
||||
UnlockInputs();
|
||||
InitInputs();
|
||||
LockSearchInputs();
|
||||
}
|
||||
|
||||
@ -201,6 +207,7 @@ namespace WGneu.Windows {
|
||||
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";
|
||||
|
||||
@ -245,6 +252,7 @@ namespace WGneu.Windows {
|
||||
HideSaveResetCancelButtons();
|
||||
ShowNewEditDeleteButtons();
|
||||
RefreshInputs();
|
||||
ClearInputStates();
|
||||
LockInputs();
|
||||
UnlockSearchInputs();
|
||||
}
|
||||
@ -270,12 +278,6 @@ namespace WGneu.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
private int NextMgNr() {
|
||||
int c = Context.Members.Select(m => m.MgNr).Min();
|
||||
Context.Members.OrderBy(m => m.MgNr).Select(m => m.MgNr).ToList().ForEach(a => { if (a <= c + 100) c = a; });
|
||||
return c + 1;
|
||||
}
|
||||
|
||||
private void ShowSaveResetCancelButtons() {
|
||||
SaveButton.IsEnabled = false;
|
||||
ResetButton.IsEnabled = false;
|
||||
@ -397,6 +399,10 @@ namespace WGneu.Windows {
|
||||
|
||||
Menu_Member_SendEmail.IsEnabled = m.Email != null;
|
||||
|
||||
FillOriginalValues();
|
||||
}
|
||||
|
||||
private void FillOriginalValues() {
|
||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
|
||||
OriginalValues[tb] = tb.Text;
|
||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
|
||||
@ -410,8 +416,10 @@ namespace WGneu.Windows {
|
||||
private void ClearInputs() {
|
||||
Menu_Member_SendEmail.IsEnabled = false;
|
||||
OriginalValues.Clear();
|
||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
|
||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) {
|
||||
tb.Text = " ";
|
||||
tb.Text = "";
|
||||
}
|
||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
|
||||
cb.SelectedItem = null;
|
||||
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
|
||||
@ -456,7 +464,7 @@ namespace WGneu.Windows {
|
||||
Utils.FindVisualChilds<RadioButton>(this, ExemptInputs).Any(InputHasChanged);
|
||||
}
|
||||
|
||||
private void UpdatePlz(TextBox plzInput, ComboBox ortInput) {
|
||||
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();
|
||||
@ -464,7 +472,7 @@ namespace WGneu.Windows {
|
||||
ortInput.ItemsSource = null;
|
||||
}
|
||||
ortInput.SelectedItem = null;
|
||||
Valid[plzInput] = (ortInput.ItemsSource != null);
|
||||
Valid[plzInput] = optional || (ortInput.ItemsSource != null);
|
||||
UpdateButtons();
|
||||
}
|
||||
|
||||
@ -499,7 +507,7 @@ namespace WGneu.Windows {
|
||||
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) {
|
||||
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);
|
||||
@ -572,12 +580,12 @@ namespace WGneu.Windows {
|
||||
|
||||
private void PlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, false, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, OrtInput);
|
||||
UpdatePlz((TextBox)sender, OrtInput, false);
|
||||
}
|
||||
|
||||
private void PlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, OrtInput);
|
||||
UpdatePlz((TextBox)sender, OrtInput, false);
|
||||
}
|
||||
|
||||
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
@ -630,12 +638,12 @@ namespace WGneu.Windows {
|
||||
|
||||
private void BillingPlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, true, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, BillingOrtInput);
|
||||
UpdatePlz((TextBox)sender, BillingOrtInput, true);
|
||||
}
|
||||
|
||||
private void BillingPlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
||||
UpdatePlz((TextBox)sender, BillingOrtInput);
|
||||
UpdatePlz((TextBox)sender, BillingOrtInput, true);
|
||||
}
|
||||
|
||||
private void DateInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
|
Reference in New Issue
Block a user