diff --git a/WGneu/Models/Member.cs b/WGneu/Models/Member.cs index d51712d..bc87abd 100644 --- a/WGneu/Models/Member.cs +++ b/WGneu/Models/Member.cs @@ -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(); } + 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; } diff --git a/WGneu/Validator.cs b/WGneu/Validator.cs index 4906231..c000274 100644 --- a/WGneu/Validator.cs +++ b/WGneu/Validator.cs @@ -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) diff --git a/WGneu/Windows/MemberListWindow.xaml b/WGneu/Windows/MemberListWindow.xaml index 4d64170..fd39913 100644 --- a/WGneu/Windows/MemberListWindow.xaml +++ b/WGneu/Windows/MemberListWindow.xaml @@ -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"/>