diff --git a/Elwig/Helpers/AppDbContext.cs b/Elwig/Helpers/AppDbContext.cs index bb8f272..11a6113 100644 --- a/Elwig/Helpers/AppDbContext.cs +++ b/Elwig/Helpers/AppDbContext.cs @@ -13,7 +13,8 @@ namespace Elwig.Helpers { public DbSet Gemeinden { get; set; } public DbSet Katastralgemeinden { get; set; } public DbSet Orte { get; set; } - public DbSet Postleitzahlen { get; set; } + public DbSet Postleitzahlen { get; set; } + public DbSet PlzDestinations { get; set; } public DbSet PostalDestinations { get; set; } public DbSet Branches { get; set; } public DbSet WbKgs { get; set; } diff --git a/Elwig/Windows/AdministrationWindow.cs b/Elwig/Windows/AdministrationWindow.cs index af2f6ad..f7c6f0b 100644 --- a/Elwig/Windows/AdministrationWindow.cs +++ b/Elwig/Windows/AdministrationWindow.cs @@ -1,15 +1,13 @@ using Elwig.Helpers; -using Elwig.Models; using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; namespace Elwig.Windows { public abstract class AdministrationWindow : ContextWindow { + protected Control[] ExemptInputs { private get; set; } protected Control[] RequiredInputs { private get; set; } private TextBox[] TextBoxInputs; @@ -66,14 +64,10 @@ namespace Elwig.Windows { if (input is TextBox tb && tb.Text.Length == 0) { Utils.SetInputInvalid(input); Valid[input] = false; - } else if (input is ComboBox cb && cb.SelectedItem == null) { + } else if (input is ComboBox cb && cb.SelectedItem == null && cb.ItemsSource != null) { Utils.SetInputInvalid(input); } } - foreach (var cb in ComboBoxInputs) { - if (cb.ItemsSource != null && cb.SelectedItem == null) - Utils.SetInputInvalid(cb); - } } protected void LockInputs() { @@ -155,8 +149,7 @@ namespace Elwig.Windows { protected void UpdatePlz(TextBox plzInput, ComboBox ortInput) { if (plzInput.Text.Length == 4) { - int plz = int.Parse(plzInput.Text); - ortInput.ItemsSource = Context.Postleitzahlen.Where(p => p.Plz == plz).ToHashSet(); + ortInput.ItemsSource = Context.Postleitzahlen.Find(int.Parse(plzInput.Text))?.Orte.ToList(); } else { ortInput.ItemsSource = null; } diff --git a/Elwig/Windows/ContextWindow.cs b/Elwig/Windows/ContextWindow.cs index 4d4bead..8aa7581 100644 --- a/Elwig/Windows/ContextWindow.cs +++ b/Elwig/Windows/ContextWindow.cs @@ -1,14 +1,10 @@ using Elwig.Helpers; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Windows; namespace Elwig.Windows { public abstract class ContextWindow : Window { + protected readonly AppDbContext Context; public ContextWindow() : base() { diff --git a/Elwig/Windows/MemberAdminWindow.xaml.cs b/Elwig/Windows/MemberAdminWindow.xaml.cs index ec37479..1706242 100644 --- a/Elwig/Windows/MemberAdminWindow.xaml.cs +++ b/Elwig/Windows/MemberAdminWindow.xaml.cs @@ -1,7 +1,6 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using System.Windows; using System.Windows.Controls; @@ -29,7 +28,7 @@ namespace Elwig.Windows { }; RequiredInputs = new Control[] { MgNrInput, GivenNameInput, FamilyNameInput, - AddressInput, PlzInput, + AddressInput, PlzInput, OrtInput, BillingOrtInput, BusinessSharesInput, BranchInput, DefaultKgInput }; }