Add RenewContext
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Threading;
|
||||
@ -25,7 +27,6 @@ namespace Elwig.Windows {
|
||||
WineOriginInput, WineKgInput
|
||||
};
|
||||
ExemptInputs = new Control[] {
|
||||
MgNrInput, MemberInput,
|
||||
LsNrInput, DateInput, TimeInput, BranchInput,
|
||||
MemberAddressField
|
||||
};
|
||||
@ -37,15 +38,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||
MemberInput.ItemsSource = Context.Members.OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToList();
|
||||
BranchInput.ItemsSource = Context.Branches.OrderBy(b => b.Name).ToList();
|
||||
BranchInput.SelectedItem = BranchInput.ItemsSource.Cast<Branch>().First(b => b.ZwstId == App.ZwstId);
|
||||
WineVarietyInput.ItemsSource = Context.WineVarieties.OrderBy(v => v.Name).ToList();
|
||||
AttributesInput.ItemsSource = Context.WineAttributes.OrderBy(a => a.Name).ToList();
|
||||
WineQualityLevelInput.ItemsSource = Context.WineQualityLevels.ToList();
|
||||
ModifiersInput.ItemsSource = Context.Modifiers.Where(m => m.Season.Year == 2022).OrderBy(m => m.Name).ToList();
|
||||
WineOriginInput.ItemsSource = Context.WineOrigins.ToList().OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId);
|
||||
WineKgInput.ItemsSource = Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToList();
|
||||
|
||||
}
|
||||
|
||||
private void OnSecondPassed(object? sender, EventArgs evt) {
|
||||
@ -58,6 +51,21 @@ namespace Elwig.Windows {
|
||||
|
||||
}
|
||||
|
||||
protected override async Task RenewContext() {
|
||||
await base.RenewContext();
|
||||
Utils.RenewItemsSource(MemberInput, await Context.Members.OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr);
|
||||
Utils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId);
|
||||
BranchInput.SelectedItem = BranchInput.ItemsSource.Cast<Branch>().First(b => b.ZwstId == App.ZwstId);
|
||||
Utils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId);
|
||||
Utils.RenewItemsSource(AttributesInput, await Context.WineAttributes.OrderBy(a => a.Name).ToListAsync(), i => (i as WineAttr)?.AttrId);
|
||||
Utils.RenewItemsSource(WineQualityLevelInput, await Context.WineQualityLevels.ToListAsync(), i => (i as WineQualLevel)?.QualId);
|
||||
Utils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Season.Year == 2022).OrderBy(m => m.Name).ToListAsync(), i => (i as Modifier)?.ModId);
|
||||
Utils.RenewItemsSource(WineOriginInput, (await Context.WineOrigins.ToListAsync()).OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId), i => (i as WineOrigin)?.HkId);
|
||||
Utils.RenewItemsSource(WineKgInput, await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync(), i => (i as AT_Kg)?.KgNr);
|
||||
UpdateWineQualityLevels();
|
||||
UpdateRdInput();
|
||||
}
|
||||
|
||||
private void MgNrInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
var valid = InputTextChanged((TextBox)sender, Validator.CheckMgNr);
|
||||
MemberInput.SelectedItem = valid ? Context.Members.Find(int.Parse(MgNrInput.Text)) : null;
|
||||
@ -177,17 +185,20 @@ namespace Elwig.Windows {
|
||||
UpdateWineOrigin();
|
||||
}
|
||||
|
||||
private void WineKgInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
UpdateWineOrigin();
|
||||
var kg = (AT_Kg)WineKgInput.SelectedItem;
|
||||
if (kg != null) {
|
||||
private void UpdateRdInput() {
|
||||
if (WineKgInput.SelectedItem is AT_Kg kg) {
|
||||
var list = Context.WbRde.Where(r => r.KgNr == kg.KgNr).OrderBy(r => r.Name).Cast<object>().ToList();
|
||||
list.Insert(0, new NullItem());
|
||||
WineRdInput.ItemsSource = list;
|
||||
WineRdInput.SelectedIndex = 0;
|
||||
Utils.RenewItemsSource(WineRdInput, list, i => ((i as WbRd)?.KgNr, (i as WbRd)?.RdNr));
|
||||
if (WineRdInput.SelectedItem == null) WineRdInput.SelectedIndex = 0;
|
||||
} else {
|
||||
WineRdInput.ItemsSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void WineKgInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
UpdateWineOrigin();
|
||||
UpdateRdInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user