Do not require ComboBoxes to be valid if they are not required

This commit is contained in:
2023-04-16 19:38:30 +02:00
parent e68a7ce8a9
commit 2c2ac46b2e
4 changed files with 7 additions and 18 deletions

View File

@ -13,7 +13,8 @@ namespace Elwig.Helpers {
public DbSet<AT_Gem> Gemeinden { get; set; }
public DbSet<AT_Kg> Katastralgemeinden { get; set; }
public DbSet<AT_Ort> Orte { get; set; }
public DbSet<AT_PlzDest> Postleitzahlen { get; set; }
public DbSet<AT_Plz> Postleitzahlen { get; set; }
public DbSet<AT_PlzDest> PlzDestinations { get; set; }
public DbSet<PostalDest> PostalDestinations { get; set; }
public DbSet<Branch> Branches { get; set; }
public DbSet<WbKg> WbKgs { get; set; }

View File

@ -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;
}

View File

@ -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() {

View File

@ -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
};
}