Add email and phone validators

This commit is contained in:
2023-02-26 16:04:31 +01:00
parent 0059f57e5e
commit 4be27ee5ff
4 changed files with 368 additions and 70 deletions

View File

@ -14,14 +14,71 @@ namespace WGneu.Models
[Column("mgnr")]
public int MgNr { get; set; }
[Column("predecessor_mgnr")]
public int? PredecessorMgNr { get; set; }
[Column("prefix")]
public string? Prefix { get; set; }
[Column("given_name")]
public string GivenName { get; set; }
[Column("middle_names")]
public string? MiddleName { get; set; }
[NotMapped]
public string[] MiddleNames {
get { return (MiddleName != null) ? MiddleName.Split(" ") : Array.Empty<string>(); }
set { MiddleName = (value.Length > 0) ? string.Join(" ", value) : null; }
}
[Column("family_name")]
public string FamilyName { get; set; }
[Column("suffix")]
public string? Suffix { get; set; }
[Column("birthday")]
public string? Birthday { get; set; }
[Column("entry_date")]
public string? EntryDate { get; set; }
[Column("exit_date")]
public string? ExitDate { get; set; }
[Column("business_shares")]
public int BusinessShares { get; set; }
[Column("accounting_nr")]
public string? AccountingNr { get; set; }
[Column("zwstid")]
public string ZwstId { get; set; }
public string? ZwstId { get; set; }
[Column("lfbis_nr")]
public string? LfbisNr { get; set; }
[Column("ustid")]
public string? UstId { get; set; }
[Column("volllieferant")]
public bool VollLieferant { get; set; }
[Column("buchführend")]
public bool Buchführend { get; set; }
[Column("funktionär")]
public bool Funktionär { get; set; }
[Column("active")]
public bool Active { get; set; }
[Column("iban")]
public string? Iban { get; set; }
[Column("bic")]
public string? Bic { get; set; }
[Column("country")]
public string CountryCode { get; set; }
@ -32,9 +89,30 @@ namespace WGneu.Models
[Column("address")]
public string Address { get; set; }
[Column("email")]
public string? Email { get; set; }
[Column("phone_landline")]
public string? PhoneLandline { get; set; }
[Column("phone_mobile_1")]
public string? PhoneMobile1 { get; set; }
[Column("phone_mobile_2")]
public string? PhoneMobile2 { get; set; }
[Column("default_kgnr")]
public int DefaultKgNr { get; set; }
[Column("default_contact")]
public string DefaultContact { get; set; }
[Column("comment")]
public string? Comment { get; set; }
[ForeignKey("PredecessorMgNr")]
public virtual Member? Predecessor { get; set; }
[ForeignKey("CountryCode")]
public virtual Country Country { get; set; }

View File

@ -10,6 +10,11 @@ namespace WGneu
{
static class Validator
{
private static readonly string[] MOBILE_NRS = {
"650", "651", "652", "653", "655", "657", "659", "660", "661",
"663", "664", "665", "666", "667", "668", "669", "67", "68", "69"
};
public static ValidationResult CheckNumericInput(TextBox input)
{
return CheckNumericInput(input, -1);
@ -36,7 +41,91 @@ namespace WGneu
input.CaretIndex = Math.Min(pos, maxLen);
}
return new ValidationResult(true, "");
return new(true, null);
}
public static ValidationResult CheckPhoneNumber(TextBox input)
{
string text = "";
int pos = input.CaretIndex;
for (int i = 0, v = 0; i < input.Text.Length; i++)
{
char ch = input.Text[i];
if (v == 0 && ch == '0')
{
v += 3;
text += "+43";
}
else if (v == 0 && ch == '+')
{
v++;
text += ch;
}
else if (v > 0 && char.IsDigit(ch))
{
if (text == "+43")
text += " ";
else if (v == 6 && MOBILE_NRS.Any(nr => text.StartsWith("+43 " + nr)))
text += " ";
else if (v == 4 && text.StartsWith("+43 1"))
text += " ";
else if (v == 7 && text.Length == 8 && text.StartsWith("+43 "))
text += " ";
v++;
text += ch;
}
if (i == input.CaretIndex - 1)
pos = text.Length;
}
input.Text = text;
input.CaretIndex = pos;
if (text.Length == 0)
return new(true, null);
if (text.Length < 10)
return new(false, "Telefonnummer zu kurz");
return new(true, null);
}
public static ValidationResult CheckEmailAddress(TextBox input)
{
string text = "";
int pos = input.CaretIndex;
bool domain = false;
for (int i = 0; i < input.Text.Length; i++)
{
char ch = input.Text[i];
if (domain)
{
if ((char.IsAscii(ch) && char.IsLetterOrDigit(ch)) || ".-_öäüßÖÄÜẞ".Any(c => c == ch))
{
if (!(text.Last() == '.' && ch == '.'))
text += char.ToLower(ch);
}
}
else
{
if (ch == '@') domain = true;
if (!char.IsControl(ch) && !char.IsWhiteSpace(ch))
text += ch;
}
if (i == input.CaretIndex - 1)
pos = text.Length;
}
input.Text = text;
input.CaretIndex = pos;
if (text.Length == 0)
return new(true, null);
else if (text[0] == '@' || !domain)
return new(false, "E-Mail-Adresse ungültig");
var last = text.Split(".").Last();
if (last.Length < 2 || !last.All(ch => char.IsAscii(ch) && char.IsLower(ch)))
return new(false, "E-Mail-Adresse ungültig");
return new(true, null);
}
public static ValidationResult CheckLfbisNr(TextBox input)
@ -45,18 +134,18 @@ namespace WGneu
if (!res.IsValid)
return res;
if (input.Text.Length == 0)
return new ValidationResult(true, "");
return new(true, null);
if (input.Text.Length != 7)
return new ValidationResult(false, "Betriebsnummer zu kurz");
return new(false, "Betriebsnummer zu kurz");
// TODO
return new ValidationResult(true, "Not implemented yet");
return new(true, "Not implemented yet");
}
public static ValidationResult CheckUstIdInput(TextBox input)
{
return new ValidationResult(false, "Not implemented yet");
return new(false, "Not implemented yet");
}
public static void SetInputInvalid(TextBox input)

View File

@ -82,7 +82,7 @@
HorizontalAlignment="Left" Margin="0,10,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="48" FontSize="14" Padding="2" Grid.Column="1" TextAlignment="Right"/>
<Label Content="Vorg.:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="2"/>
<TextBox x:Name="MgNrPredecessorInput" IsReadOnly="True"
<TextBox x:Name="PredecessorMgNrInput" IsReadOnly="True"
HorizontalAlignment="Left" Margin="0,10,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" Width="48" FontSize="14" Padding="2" Grid.Column="3" TextAlignment="Right"/>
<Label Content="Vorname:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="0"/>
@ -98,12 +98,12 @@
Margin="0,70,0,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1"/>
<Label Content="Suffix:" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="2"/>
<TextBox x:Name="SuffixInpu" IsReadOnly="True"
<TextBox x:Name="SuffixInput" IsReadOnly="True"
Margin="0,70,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="3"/>
<Label Content="Geburtstag:" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2" Grid.Column="0"/>
<TextBox x:Name="BirthdayInput" IsReadOnly="True"
Grid.Column="1" TextWrapping="NoWrap" Margin="0,100,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="14" Padding="2" Height="25" Width="76" TextAlignment="Right"/>
Grid.Column="1" TextWrapping="NoWrap" Margin="0,100,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="14" Padding="2" Height="25" Width="78" TextAlignment="Right"/>
<Label Content="Adresse:" HorizontalAlignment="Left" Margin="10,132,0,0" VerticalAlignment="Top" Padding="2"/>
<TextBox x:Name="AddressInput" IsReadOnly="True"
@ -114,6 +114,7 @@
TextChanged="PlzInput_TextChanged"
HorizontalAlignment="Left" Margin="0,160,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
<ComboBox x:Name="OrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
SelectionChanged="ComboBox_SelectionChanged"
Margin="47,160,10,0" VerticalAlignment="Top" FontSize="14" Grid.Column="1" Grid.ColumnSpan="3" Height="25"/>
</Grid>
</GroupBox>
@ -126,18 +127,22 @@
<Label Content="E-Mail-Adresse:" HorizontalAlignment="Left" Margin="10,12,0,0" VerticalAlignment="Top" Padding="2"/>
<TextBox x:Name="EmailInput" IsReadOnly="True"
TextChanged="EmailInput_TextChanged" LostFocus="EmailInput_LostFocus"
Margin="0,10,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
<Label Content="Tel.-Nr. (Festnetz):" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
<TextBox x:Name="PhoneLandlineInput" IsReadOnly="True"
TextChanged="PhoneNrInput_TextChanged" LostFocus="PhoneNrInput_LostFocus"
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
<Label Content="Tel.-Nr. (mobil):" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Padding="2"/>
<TextBox x:Name="PhoneMobile1Input" IsReadOnly="True"
TextChanged="PhoneNrInput_TextChanged" LostFocus="PhoneNrInput_LostFocus"
Margin="0,70,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
<Label Content="Tel.-Nr. (mobil):" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2"/>
<TextBox x:Name="PhoneMobile2Input" IsReadOnly="True"
TextChanged="PhoneNrInput_TextChanged" LostFocus="PhoneNrInput_LostFocus"
Margin="0,100,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25"/>
</Grid>
</GroupBox>
@ -172,7 +177,7 @@
<Label Content="BetriebsNr.:" HorizontalAlignment="Left" Margin="10,42,0,0" VerticalAlignment="Top" Padding="2"/>
<TextBox x:Name="LfbisNrInput" IsReadOnly="True"
TextChanged="LfbisNrInput_TextChanged" LostFocus="LfbisNrInput_LostFocus"
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25" Width="64" HorizontalAlignment="Left"/>
Margin="0,40,10,0" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Height="25" Width="64" HorizontalAlignment="Left" TextAlignment="Right"/>
<CheckBox x:Name="BuchführendInput" Content="Buchführend" IsEnabled="False"
Grid.Column="2" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Top" IsChecked="False"/>
@ -198,6 +203,7 @@
TextChanged="PlzInput_TextChanged"
HorizontalAlignment="Left" Margin="0,70,0,0" VerticalAlignment="Top" Width="42" FontSize="14" Padding="2" Grid.Column="1"/>
<ComboBox x:Name="BillingOrtInput" ItemTemplate="{StaticResource PostalDestComboBoxTemplate}" IsEnabled="False"
SelectionChanged="ComboBox_SelectionChanged"
Margin="47,70,10,0" VerticalAlignment="Top" FontSize="14" Grid.Column="1"/>
</Grid>
</GroupBox>
@ -224,7 +230,7 @@
<CheckBox x:Name="ActiveInput" Content="Aktiv" IsEnabled="False"
Grid.Column="2" HorizontalAlignment="Left" Margin="10,15,0,0" VerticalAlignment="Top" IsChecked="False"/>
<CheckBox x:Name="VolllieferantInput" Content="Volllieferant" IsEnabled="False"
<CheckBox x:Name="VollLieferantInput" Content="Volllieferant" IsEnabled="False"
Grid.Column="2" HorizontalAlignment="Left" Margin="10,45,0,0" VerticalAlignment="Top" IsChecked="False"/>
<CheckBox x:Name="FunkionärInput" Content="Funktionär" IsEnabled="False"
@ -232,10 +238,12 @@
<Label Content="StammZwst.:" HorizontalAlignment="Left" Margin="10,102,0,0" VerticalAlignment="Top" Padding="2"/>
<ComboBox x:Name="BranchInput" ItemTemplate="{StaticResource BranchTemplate}" IsEnabled="False"
SelectionChanged="ComboBox_SelectionChanged"
Margin="0,100,10,0" VerticalAlignment="Top" Grid.Column="1" FontSize="14" Height="25" Grid.ColumnSpan="2"/>
<Label Content="Stammgemeinde:" HorizontalAlignment="Left" Margin="10,132,0,0" VerticalAlignment="Top" Padding="2"/>
<ComboBox x:Name="DefaultKgInput" ItemTemplate="{StaticResource KgTemplate}" IsEnabled="False"
SelectionChanged="ComboBox_SelectionChanged"
Margin="0,130,10,0" VerticalAlignment="Top" Grid.Column="1" FontSize="14" Height="25" Grid.ColumnSpan="2"/>
<Label Content="Anmerkung:" HorizontalAlignment="Left" Margin="10,162,0,0" VerticalAlignment="Top" Padding="2"/>
@ -243,9 +251,9 @@
Margin="0,160,10,0" TextWrapping="NoWrap" VerticalAlignment="Top" FontSize="14" Padding="2" Grid.Column="1" Grid.ColumnSpan="2" TextAlignment="Right"/>
<Label Content="Kontaktart:" HorizontalAlignment="Left" Margin="10,192,0,0" VerticalAlignment="Top" Padding="2"/>
<RadioButton x:Name="ContactPostInput" Content="Post" IsEnabled="False"
<RadioButton x:Name="ContactPostInput" GroupName="DefaultContact" Content="Post" IsEnabled="False"
HorizontalAlignment="Left" Margin="0,195,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
<RadioButton x:Name="ContactEmailInput" Content="E-Mail" IsEnabled="False"
<RadioButton x:Name="ContactEmailInput" GroupName="DefaultContact" Content="E-Mail" IsEnabled="False"
HorizontalAlignment="Left" Margin="60,195,0,0" VerticalAlignment="Top" Grid.Column="1" Grid.ColumnSpan="2"/>
</Grid>
</GroupBox>

View File

@ -23,42 +23,45 @@ namespace WGneu.Windows
{
public partial class MemberListWindow : Window
{
private bool isEditing = false;
private bool isCreating = false;
private List<string> textFilter = new();
private static RoutedCommand controlF = new RoutedCommand();
private readonly WgContext context = new();
private bool IsEditing = false;
private bool IsCreating = false;
private List<string> TextFilter = new();
private readonly Dictionary<TextBox, bool> Valid = new();
private static readonly RoutedCommand CtrlF = new();
private readonly WgContext Context = new();
public MemberListWindow()
{
InitializeComponent();
CtrlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
CommandBindings.Add(new CommandBinding(CtrlF, FocusSearchInput));
foreach (var tb in Utils.FindVisualChilds<TextBox>(this))
if (tb.Name != "SearchInput") Valid[tb] = true;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
RefreshMemberList();
BranchInput.ItemsSource = context.Branches.OrderBy(b => b.Name).ToList();
DefaultKgInput.ItemsSource = context.WbKgs.Select(k => k.Kg).OrderBy(k => k.Name).ToList();
controlF.InputGestures.Add(new KeyGesture(Key.F, ModifierKeys.Control));
CommandBindings.Add(new CommandBinding(controlF, FocusSearchInput));
BranchInput.ItemsSource = Context.Branches.OrderBy(b => b.Name).ToList();
DefaultKgInput.ItemsSource = Context.WbKgs.Select(k => k.Kg).OrderBy(k => k.Name).ToList();
}
protected override void OnClosing(CancelEventArgs e)
{
context.Dispose();
Context.Dispose();
base.OnClosing(e);
}
private int CountMatchesInMember(Member m)
{
if (textFilter.Count == 0) return 0;
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 (textFilter.Any(f => c == f))
if (TextFilter.Any(f => c == f))
i += 10;
else if (textFilter.Any(f => c.Contains(f)))
else if (TextFilter.Any(f => c.Contains(f)))
i += 1;
}
return i;
@ -66,10 +69,10 @@ namespace WGneu.Windows
private void RefreshMemberList()
{
context.Members.Load();
List<Member> members = context.Members.OrderBy(m => m.FamilyName + " " + m.GivenName).ToList();
Context.Members.Load();
List<Member> members = Context.Members.OrderBy(m => m.FamilyName + " " + m.GivenName).ToList();
if (textFilter.Count > 0)
if (TextFilter.Count > 0)
{
members = members
.ToDictionary(m => m, m => CountMatchesInMember(m))
@ -118,7 +121,7 @@ namespace WGneu.Windows
if (PlzInput.Text.Length == 4 && PlzInput.Text.All(char.IsDigit))
{
int plz = int.Parse(PlzInput.Text);
var o = context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
var o = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet();
OrtInput.ItemsSource = o;
OrtInput.SelectedItem = null;
}
@ -126,7 +129,7 @@ namespace WGneu.Windows
private void NewMemberButton_Click(object sender, RoutedEventArgs e)
{
isCreating = true;
IsCreating = true;
MemberList.IsEnabled = false;
InitInputs();
HideNewEditDeleteButtons();
@ -139,7 +142,7 @@ namespace WGneu.Windows
if (MemberList.SelectedItem == null)
return;
isEditing = true;
IsEditing = true;
MemberList.IsEnabled = false;
HideNewEditDeleteButtons();
@ -157,8 +160,8 @@ namespace WGneu.Windows
"Mitglied löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
if (r == MessageBoxResult.Yes)
{
context.Remove(m);
context.SaveChanges();
Context.Remove(m);
Context.SaveChanges();
RefreshMemberList();
}
}
@ -167,42 +170,70 @@ namespace WGneu.Windows
{
// TODO only allow to click button, if values were checked
Member? m = null;
if (isEditing)
Member? m = new();
if (IsEditing)
m = (Member)MemberList.SelectedItem;
else if (isCreating)
else if (IsCreating)
m = new();
int newMgNr = int.Parse(MgNrInput.Text);
m.Prefix = (PrefixInput.Text == "") ? null : PrefixInput.Text;
m.GivenName = GivenNameInput.Text;
m.FamilyName = FamilyNameInput.Text;
m.ZwstId = ((Branch)BranchInput.SelectedItem).ZwstId;
m.Suffix = (SuffixInput.Text == "") ? null : SuffixInput.Text;
m.Birthday = (BirthdayInput.Text == "") ? null : string.Join("-", BirthdayInput.Text.Split(".").Reverse());
m.CountryCode = "AT";
m.PostalDestId = ((AT_Plz)OrtInput.SelectedItem).Id;
m.PostalDest = context.PostalDestinations.Find(m.CountryCode, m.PostalDestId);
m.PostalDest = Context.PostalDestinations.Find(m.CountryCode, m.PostalDestId);
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.Buchfü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.Active = ActiveInput.IsChecked ?? false;
m.VollLieferant = VollLieferantInput.IsChecked ?? false;
m.Funktionä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;
if (ContactPostInput.IsChecked ?? false) m.DefaultContact = "post";
if (ContactEmailInput.IsChecked ?? false) m.DefaultContact = "email";
// TODO Buchhaltungskonto
try
{
if (isEditing)
context.Update(m);
else if (isCreating)
context.Add(m);
context.SaveChanges();
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}");
Context.Database.ExecuteSql($"UPDATE member SET mgnr = {newMgNr} WHERE mgnr = {m.MgNr}");
}
catch (Exception exc)
{
MessageBox.Show(
"Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message.ToString(),
"Mitglied aktualisieren", MessageBoxButton.OK, MessageBoxImage.Error);
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;
IsEditing = false;
IsCreating = false;
MemberList.IsEnabled = true;
HideSaveResetCancelButtons();
ShowNewEditDeleteButtons();
@ -212,16 +243,16 @@ namespace WGneu.Windows
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
if (isEditing)
if (IsEditing)
RefreshInputs();
else if (isCreating)
else if (IsCreating)
InitInputs();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
isEditing = false;
isCreating = false;
IsEditing = false;
IsCreating = false;
MemberList.IsEnabled = true;
HideSaveResetCancelButtons();
ShowNewEditDeleteButtons();
@ -231,14 +262,13 @@ namespace WGneu.Windows
private void SearchInput_TextChanged(object sender, RoutedEventArgs e)
{
// TODO implement STRG+F
textFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(s => s != "");
TextFilter = SearchInput.Text.ToLower().Split(" ").ToList().FindAll(s => s != "");
RefreshMemberList();
}
private void FocusSearchInput(object sender, RoutedEventArgs e)
{
if (!isEditing && !isCreating)
if (!IsEditing && !IsCreating)
{
SearchInput.Focus();
SearchInput.SelectAll();
@ -247,8 +277,8 @@ 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; });
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;
}
@ -319,24 +349,55 @@ namespace WGneu.Windows
private void FillInputs(Member m)
{
MgNrInput.Text = m.MgNr.ToString();
PredecessorMgNrInput.Text = m.PredecessorMgNr.ToString();
PrefixInput.Text = m.Prefix;
GivenNameInput.Text = m.GivenName;
FamilyNameInput.Text = m.FamilyName;
BranchInput.SelectedItem = m.Branch;
DefaultKgInput.SelectedItem = m.DefaultKg;
SuffixInput.Text = m.Suffix;
BirthdayInput.Text = (m.Birthday != null) ? string.Join(".", m.Birthday.Split("-").Reverse()) : null;
AddressInput.Text = m.Address;
AT_Plz? p = m.PostalDest.Plz(context);
AT_Plz? p = m.PostalDest.Plz(Context);
if (p != null)
{
PlzInput.Text = p.Plz.ToString();
OrtInput.ItemsSource = p.Orte(context);
OrtInput.ItemsSource = p.Orte(Context);
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.Buchfü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();
BranchInput.SelectedItem = m.Branch;
DefaultKgInput.SelectedItem = m.DefaultKg;
CommentInput.Text = m.Comment;
ActiveInput.IsChecked = m.Active;
VollLieferantInput.IsChecked = m.VollLieferant;
FunkionärInput.IsChecked = m.Funktionär;
switch (m.DefaultContact)
{
case "post": ContactPostInput.IsChecked = true; break;
case "email": ContactEmailInput.IsChecked = true; break;
}
}
private void ClearInputs()
@ -345,20 +406,82 @@ namespace WGneu.Windows
if (tb.Name != "SearchInput") tb.Text = "";
foreach (var cb in Utils.FindVisualChilds<ComboBox>(this))
cb.SelectedItem = null;
foreach (var cb in Utils.FindVisualChilds<CheckBox>(this))
cb.IsChecked = false;
foreach (var rb in Utils.FindVisualChilds<RadioButton>(this))
rb.IsChecked = false;
}
private bool IsValid()
{
return Valid.All(kv => kv.Value) &&
Utils.FindVisualChilds<ComboBox>(this).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 HasChanged()
{
return true; // TODO
}
private void InputTextChanged(TextBox input, Func<TextBox, ValidationResult> checker)
{
var res = checker(input);
Valid[input] = res.IsValid;
if (res.IsValid)
Validator.SetInputValid(input);
else
Validator.SetInputInvalid(input);
UpdateButtons();
}
private void InputLostFocus(TextBox input, Func<TextBox, ValidationResult> checker, string? msg)
{
var res = checker(input);
if (!res.IsValid)
MessageBox.Show(res.ErrorContent.ToString(), msg ?? res.ErrorContent.ToString(), MessageBoxButton.OK, MessageBoxImage.Warning);
}
private void ComboBox_SelectionChanged(object sender, RoutedEventArgs e)
{
UpdateButtons();
}
private void PhoneNrInput_TextChanged(object sender, RoutedEventArgs e)
{
InputTextChanged((TextBox)sender, Validator.CheckPhoneNumber);
}
private void PhoneNrInput_LostFocus(object sender, RoutedEventArgs e)
{
InputLostFocus((TextBox)sender, Validator.CheckPhoneNumber, null);
}
private void EmailInput_TextChanged(object sender, RoutedEventArgs e)
{
InputTextChanged((TextBox)sender, Validator.CheckEmailAddress);
}
private void EmailInput_LostFocus(object sender, RoutedEventArgs e)
{
InputLostFocus((TextBox)sender, Validator.CheckEmailAddress, null);
}
private void LfbisNrInput_TextChanged(object sender, RoutedEventArgs e)
{
var res = Validator.CheckLfbisNr(LfbisNrInput);
if (res.IsValid) Validator.SetInputValid(LfbisNrInput);
else Validator.SetInputInvalid(LfbisNrInput);
InputTextChanged((TextBox)sender, Validator.CheckLfbisNr);
}
private void LfbisNrInput_LostFocus(object sender, RoutedEventArgs e)
{
var res = Validator.CheckLfbisNr(LfbisNrInput);
if (!res.IsValid)
MessageBox.Show(res.ErrorContent.ToString(), "Betriebsnummer ungültig", MessageBoxButton.OK, MessageBoxImage.Warning);
InputLostFocus((TextBox)sender, Validator.CheckLfbisNr, "Betriebsnummer ungültig");
}
}
}