Fix bug where it is not possible to create new members
This commit is contained in:
@ -65,5 +65,11 @@ namespace WGneu.Helpers {
|
|||||||
public static bool MgNrExists(AppDbContext ctx, int mgnr) {
|
public static bool MgNrExists(AppDbContext ctx, int mgnr) {
|
||||||
return ctx.Members.Find(mgnr) != null;
|
return ctx.Members.Find(mgnr) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int NextMgNr(AppDbContext ctx) {
|
||||||
|
int c = ctx.Members.Select(m => m.MgNr).Min();
|
||||||
|
ctx.Members.OrderBy(m => m.MgNr).Select(m => m.MgNr).ToList().ForEach(a => { if (a <= c + 100) c = a; });
|
||||||
|
return c + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ namespace WGneu.Helpers {
|
|||||||
return new(true, "Not implemented yet");
|
return new(true, "Not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult CheckMgNr(TextBox input, bool optional, AppDbContext ctx, Member m) {
|
public static ValidationResult CheckMgNr(TextBox input, bool optional, AppDbContext ctx, Member? m) {
|
||||||
var res = CheckNumeric(input, optional);
|
var res = CheckNumeric(input, optional);
|
||||||
if (!res.IsValid) {
|
if (!res.IsValid) {
|
||||||
return res;
|
return res;
|
||||||
@ -264,7 +264,7 @@ namespace WGneu.Helpers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int nr = int.Parse(input.Text);
|
int nr = int.Parse(input.Text);
|
||||||
if (nr != m.MgNr && Utils.MgNrExists(ctx, nr)) {
|
if (nr != m?.MgNr && Utils.MgNrExists(ctx, nr)) {
|
||||||
return new(false, "Mitgliedsnummer wird bereits verwendet");
|
return new(false, "Mitgliedsnummer wird bereits verwendet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,8 @@ namespace WGneu.Windows {
|
|||||||
Utils.ClearInputState(rb);
|
Utils.ClearInputState(rb);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshInputs() {
|
private void RefreshInputs(bool validate = false) {
|
||||||
|
ClearInputStates();
|
||||||
Member m = (Member)MemberList.SelectedItem;
|
Member m = (Member)MemberList.SelectedItem;
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
EditMemberButton.IsEnabled = true;
|
EditMemberButton.IsEnabled = true;
|
||||||
@ -104,12 +105,16 @@ namespace WGneu.Windows {
|
|||||||
DeleteMemberButton.IsEnabled = false;
|
DeleteMemberButton.IsEnabled = false;
|
||||||
ClearInputs();
|
ClearInputs();
|
||||||
}
|
}
|
||||||
ClearInputStates();
|
if (!validate) ClearInputStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitInputs() {
|
private void InitInputs() {
|
||||||
ClearInputs();
|
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) {
|
private void MemberList_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||||
@ -123,10 +128,11 @@ namespace WGneu.Windows {
|
|||||||
private void NewMemberButton_Click(object sender, RoutedEventArgs evt) {
|
private void NewMemberButton_Click(object sender, RoutedEventArgs evt) {
|
||||||
IsCreating = true;
|
IsCreating = true;
|
||||||
MemberList.IsEnabled = false;
|
MemberList.IsEnabled = false;
|
||||||
InitInputs();
|
MemberList.SelectedItem = null;
|
||||||
HideNewEditDeleteButtons();
|
HideNewEditDeleteButtons();
|
||||||
ShowSaveResetCancelButtons();
|
ShowSaveResetCancelButtons();
|
||||||
UnlockInputs();
|
UnlockInputs();
|
||||||
|
InitInputs();
|
||||||
LockSearchInputs();
|
LockSearchInputs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,6 +207,7 @@ namespace WGneu.Windows {
|
|||||||
m.ZwstId = ((Branch)BranchInput.SelectedItem).ZwstId;
|
m.ZwstId = ((Branch)BranchInput.SelectedItem).ZwstId;
|
||||||
m.DefaultKgNr = ((AT_Kg)DefaultKgInput.SelectedItem).KgNr;
|
m.DefaultKgNr = ((AT_Kg)DefaultKgInput.SelectedItem).KgNr;
|
||||||
m.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
|
m.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
|
||||||
|
m.DefaultContact = "post";
|
||||||
if (ContactPostInput.IsChecked ?? false) m.DefaultContact = "post";
|
if (ContactPostInput.IsChecked ?? false) m.DefaultContact = "post";
|
||||||
if (ContactEmailInput.IsChecked ?? false) m.DefaultContact = "email";
|
if (ContactEmailInput.IsChecked ?? false) m.DefaultContact = "email";
|
||||||
|
|
||||||
@ -245,6 +252,7 @@ namespace WGneu.Windows {
|
|||||||
HideSaveResetCancelButtons();
|
HideSaveResetCancelButtons();
|
||||||
ShowNewEditDeleteButtons();
|
ShowNewEditDeleteButtons();
|
||||||
RefreshInputs();
|
RefreshInputs();
|
||||||
|
ClearInputStates();
|
||||||
LockInputs();
|
LockInputs();
|
||||||
UnlockSearchInputs();
|
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() {
|
private void ShowSaveResetCancelButtons() {
|
||||||
SaveButton.IsEnabled = false;
|
SaveButton.IsEnabled = false;
|
||||||
ResetButton.IsEnabled = false;
|
ResetButton.IsEnabled = false;
|
||||||
@ -397,6 +399,10 @@ namespace WGneu.Windows {
|
|||||||
|
|
||||||
Menu_Member_SendEmail.IsEnabled = m.Email != null;
|
Menu_Member_SendEmail.IsEnabled = m.Email != null;
|
||||||
|
|
||||||
|
FillOriginalValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FillOriginalValues() {
|
||||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
|
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
|
||||||
OriginalValues[tb] = tb.Text;
|
OriginalValues[tb] = tb.Text;
|
||||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
|
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
|
||||||
@ -410,8 +416,10 @@ namespace WGneu.Windows {
|
|||||||
private void ClearInputs() {
|
private void ClearInputs() {
|
||||||
Menu_Member_SendEmail.IsEnabled = false;
|
Menu_Member_SendEmail.IsEnabled = false;
|
||||||
OriginalValues.Clear();
|
OriginalValues.Clear();
|
||||||
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs))
|
foreach (var tb in Utils.FindVisualChilds<TextBox>(this, ExemptInputs)) {
|
||||||
|
tb.Text = " ";
|
||||||
tb.Text = "";
|
tb.Text = "";
|
||||||
|
}
|
||||||
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
|
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this, ExemptInputs))
|
||||||
cb.SelectedItem = null;
|
cb.SelectedItem = null;
|
||||||
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
|
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this, ExemptInputs))
|
||||||
@ -456,7 +464,7 @@ namespace WGneu.Windows {
|
|||||||
Utils.FindVisualChilds<RadioButton>(this, ExemptInputs).Any(InputHasChanged);
|
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) {
|
if (plzInput.Text.Length == 4) {
|
||||||
int plz = int.Parse(plzInput.Text);
|
int plz = int.Parse(plzInput.Text);
|
||||||
ortInput.ItemsSource = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
ortInput.ItemsSource = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
|
||||||
@ -464,7 +472,7 @@ namespace WGneu.Windows {
|
|||||||
ortInput.ItemsSource = null;
|
ortInput.ItemsSource = null;
|
||||||
}
|
}
|
||||||
ortInput.SelectedItem = null;
|
ortInput.SelectedItem = null;
|
||||||
Valid[plzInput] = (ortInput.ItemsSource != null);
|
Valid[plzInput] = optional || (ortInput.ItemsSource != null);
|
||||||
UpdateButtons();
|
UpdateButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -499,7 +507,7 @@ namespace WGneu.Windows {
|
|||||||
InputLostFocus(input, optional, (tb, optional, ctx, m) => checker(tb, optional, ctx), msg);
|
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);
|
var res = checker(input, optional, Context, (Member)MemberList.SelectedItem);
|
||||||
if (!res.IsValid)
|
if (!res.IsValid)
|
||||||
MessageBox.Show(res.ErrorContent.ToString(), msg ?? res.ErrorContent.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
|
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) {
|
private void PlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||||
InputTextChanged((TextBox)sender, false, Validator.CheckPlz);
|
InputTextChanged((TextBox)sender, false, Validator.CheckPlz);
|
||||||
UpdatePlz((TextBox)sender, OrtInput);
|
UpdatePlz((TextBox)sender, OrtInput, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
private void PlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||||
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
||||||
UpdatePlz((TextBox)sender, OrtInput);
|
UpdatePlz((TextBox)sender, OrtInput, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||||
@ -630,12 +638,12 @@ namespace WGneu.Windows {
|
|||||||
|
|
||||||
private void BillingPlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
private void BillingPlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||||
InputTextChanged((TextBox)sender, true, Validator.CheckPlz);
|
InputTextChanged((TextBox)sender, true, Validator.CheckPlz);
|
||||||
UpdatePlz((TextBox)sender, BillingOrtInput);
|
UpdatePlz((TextBox)sender, BillingOrtInput, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BillingPlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
private void BillingPlzInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||||
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
InputLostFocus((TextBox)sender, true, Validator.CheckPlz);
|
||||||
UpdatePlz((TextBox)sender, BillingOrtInput);
|
UpdatePlz((TextBox)sender, BillingOrtInput, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DateInput_TextChanged(object sender, RoutedEventArgs evt) {
|
private void DateInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||||
|
Reference in New Issue
Block a user