ControlUtils: Cleanup SelectItem() method and use accordingly

This commit is contained in:
2024-03-18 17:55:27 +01:00
parent 51e345f1fd
commit 2f3524db9d
20 changed files with 181 additions and 194 deletions

View File

@ -248,7 +248,7 @@ namespace Elwig {
public static BaseDataWindow FocusBaseDataSeason(int year) { public static BaseDataWindow FocusBaseDataSeason(int year) {
var w = FocusBaseData(); var w = FocusBaseData();
w.Seasons.Focus(); w.Seasons.Focus();
ControlUtils.SelectListBoxItem(w.SeasonList, s => (s as Season)?.Year, year); ControlUtils.SelectItemWithPk(w.SeasonList, year);
return w; return w;
} }

View File

@ -1,4 +1,5 @@
using Elwig.Models.Entities; using Elwig.Models.Entities;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -45,6 +46,7 @@ namespace Elwig.Helpers.Billing {
} }
} }
[PrimaryKey("Listing")]
public class Varibute : IComparable<Varibute> { public class Varibute : IComparable<Varibute> {
public WineVar? Variety { get; } public WineVar? Variety { get; }

View File

@ -84,13 +84,13 @@ namespace Elwig.Helpers {
return null; return null;
} }
public static void RenewItemsSource(Selector selector, IEnumerable? source, Func<object?, object?> getId, SelectionChangedEventHandler? handler = null, RenewSourceDefault def = RenewSourceDefault.None) { public static void RenewItemsSource(Selector selector, IEnumerable? source, SelectionChangedEventHandler? handler = null, RenewSourceDefault def = RenewSourceDefault.None) {
if (selector.ItemsSource == source) if (selector.ItemsSource == source)
return; return;
var selectedId = getId(selector.SelectedItem); var selectedId = Utils.GetEntityIdentifier(selector.SelectedItem);
object? selItem = null; object? selItem = null;
if (selectedId != null && source != null) if (selectedId != 0 && source != null)
selItem = source.Cast<object>().FirstOrDefault(i => selectedId.Equals(getId(i))); selItem = source.Cast<object>().FirstOrDefault(i => selectedId.Equals(Utils.GetEntityIdentifier(i)));
if (source != null && selItem == null) { if (source != null && selItem == null) {
if ((def == RenewSourceDefault.IfOnly && source.Cast<object>().Count() == 1) || def == RenewSourceDefault.First) { if ((def == RenewSourceDefault.IfOnly && source.Cast<object>().Count() == 1) || def == RenewSourceDefault.First) {
selItem = source.Cast<object>().First(); selItem = source.Cast<object>().First();
@ -102,30 +102,30 @@ namespace Elwig.Helpers {
selector.SelectedItem = selItem; selector.SelectedItem = selItem;
} }
public static void RenewItemsSource(Xceed.Wpf.Toolkit.Primitives.Selector selector, IEnumerable? source, Func<object?, object?> getId, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventHandler? handler = null) { public static void RenewItemsSource(Xceed.Wpf.Toolkit.Primitives.Selector selector, IEnumerable? source, Xceed.Wpf.Toolkit.Primitives.ItemSelectionChangedEventHandler? handler = null) {
if (selector.ItemsSource == source) if (selector.ItemsSource == source)
return; return;
var selectedIds = selector.SelectedItems.Cast<object>().Select(i => getId(i)).ToList(); var selectedIds = selector.SelectedItems.Cast<object>().Select(i => Utils.GetEntityIdentifier(i)).ToList();
if (handler != null && selectedIds != null) selector.ItemSelectionChanged -= handler; if (handler != null && selectedIds != null) selector.ItemSelectionChanged -= handler;
selector.ItemsSource = source; selector.ItemsSource = source;
if (source != null) { if (source != null) {
selector.SelectedItems.Clear(); selector.SelectedItems.Clear();
foreach (var i in source.Cast<object>().Where(i => selectedIds.Contains(getId(i)))) foreach (var i in source.Cast<object>().Where(i => selectedIds.Contains(Utils.GetEntityIdentifier(i))))
selector.SelectedItems.Add(i); selector.SelectedItems.Add(i);
} }
if (handler != null && selectedIds != null) selector.ItemSelectionChanged += handler; if (handler != null && selectedIds != null) selector.ItemSelectionChanged += handler;
} }
public static void RenewItemsSource(DataGrid dataGrid, IEnumerable? source, Func<object?, object?> getId, SelectionChangedEventHandler? handler = null, RenewSourceDefault def = RenewSourceDefault.None, bool keepSort = true) { public static void RenewItemsSource(DataGrid dataGrid, IEnumerable? source, SelectionChangedEventHandler? handler = null, RenewSourceDefault def = RenewSourceDefault.None, bool keepSort = true) {
if (dataGrid.ItemsSource == source) if (dataGrid.ItemsSource == source)
return; return;
var column = dataGrid.CurrentCell.Column; var column = dataGrid.CurrentCell.Column;
var sortColumns = dataGrid.Columns.Select(c => c.SortDirection).ToList(); var sortColumns = dataGrid.Columns.Select(c => c.SortDirection).ToList();
var sort = dataGrid.Items.SortDescriptions.ToList(); var sort = dataGrid.Items.SortDescriptions.ToList();
var selectedId = getId(dataGrid.SelectedItem); var selectedId = Utils.GetEntityIdentifier(dataGrid.SelectedItem);
object? selItem = null; object? selItem = null;
if (selectedId != null && source != null) if (selectedId != 0 && source != null)
selItem = source.Cast<object>().FirstOrDefault(i => selectedId.Equals(getId(i))); selItem = source.Cast<object>().FirstOrDefault(i => selectedId.Equals(Utils.GetEntityIdentifier(i)));
if (source != null && selItem == null) { if (source != null && selItem == null) {
if ((def == RenewSourceDefault.IfOnly && source.Cast<object>().Count() == 1) || def == RenewSourceDefault.First) { if ((def == RenewSourceDefault.IfOnly && source.Cast<object>().Count() == 1) || def == RenewSourceDefault.First) {
selItem = source.Cast<object>().First(); selItem = source.Cast<object>().First();
@ -145,13 +145,13 @@ namespace Elwig.Helpers {
dataGrid.CurrentCell = new(dataGrid.SelectedItem, column); dataGrid.CurrentCell = new(dataGrid.SelectedItem, column);
} }
public static void RenewItemsSource(ListBox listBox, IEnumerable? source, Func<object?, object?> getId, SelectionChangedEventHandler? handler = null, RenewSourceDefault def = RenewSourceDefault.None) { public static void RenewItemsSource(ListBox listBox, IEnumerable? source, SelectionChangedEventHandler? handler = null, RenewSourceDefault def = RenewSourceDefault.None) {
if (listBox.ItemsSource == source) if (listBox.ItemsSource == source)
return; return;
var selectedId = getId(listBox.SelectedItem); var selectedId = Utils.GetEntityIdentifier(listBox.SelectedItem);
object? selItem = null; object? selItem = null;
if (selectedId != null && source != null) if (selectedId != 0 && source != null)
selItem = source.Cast<object>().FirstOrDefault(i => selectedId.Equals(getId(i))); selItem = source.Cast<object>().FirstOrDefault(i => selectedId.Equals(Utils.GetEntityIdentifier(i)));
if (source != null && selItem == null) { if (source != null && selItem == null) {
if ((def == RenewSourceDefault.IfOnly && source.Cast<object>().Count() == 1) || def == RenewSourceDefault.First) { if ((def == RenewSourceDefault.IfOnly && source.Cast<object>().Count() == 1) || def == RenewSourceDefault.First) {
selItem = source.Cast<object>().FirstOrDefault(); selItem = source.Cast<object>().FirstOrDefault();
@ -163,61 +163,65 @@ namespace Elwig.Helpers {
listBox.SelectedItem = selItem; listBox.SelectedItem = selItem;
} }
public static object? GetItemFromSource(IEnumerable source, Func<object?, object?> getId, object? id) { public static object? GetItemFromSource(IEnumerable source, int? hash) {
if (source == null) if (source == null)
return null; return null;
var items = source.Cast<object>(); var items = source.Cast<object>();
var item = items.Where(i => getId(i)?.Equals(id) ?? false).FirstOrDefault(); var item = items.Where(i => Utils.GetEntityIdentifier(i) == hash).FirstOrDefault();
if (item == null && items.Any(i => i is NullItem)) if (item == null && items.Any(i => i is NullItem))
return items.Where(i => i is NullItem).First(); return items.Where(i => i is NullItem).First();
return item; return item;
} }
public static object? GetItemFromSource(IEnumerable source, object? item, Func<object?, object?> getId) { public static object? GetItemFromSource(IEnumerable source, object? item) {
return GetItemFromSource(source, getId, getId(item)); return GetItemFromSource(source, Utils.GetEntityIdentifier(item));
} }
public static void SelectComboBoxItem(ComboBox cb, Func<object?, object?> getId, object? id) { public static void SelectItemWithHash(Selector input, int? hash) {
cb.SelectedItem = GetItemFromSource(cb.ItemsSource, getId, id); if (hash == null) {
input.SelectedItem = null;
} else {
input.SelectedItem = GetItemFromSource(input.ItemsSource, (int)hash);
}
if (input is ListBox lb) {
lb.ScrollIntoView(lb.SelectedItem);
} else if (input is DataGrid dg) {
dg.ScrollIntoView(dg.SelectedItem);
}
} }
public static void SelectComboBoxItem(ComboBox cb, object? item, Func<object?, object?> getId) { public static void SelectItemWithPk(Selector input, params object?[] pk) {
SelectComboBoxItem(cb, getId, getId(item)); SelectItemWithHash(input, Utils.GetEntityIdentifier(pk));
} }
public static void SelectListBoxItem(ListBox lb, Func<object?, object?> getId, object? id) { public static void SelectItem(Selector input, object? item) {
lb.SelectedItem = GetItemFromSource(lb.ItemsSource, getId, id); SelectItemWithHash(input, Utils.GetEntityIdentifier(item));
lb.ScrollIntoView(lb.SelectedItem);
} }
public static void SelectListBoxItem(ListBox lb, object? item, Func<object?, object?> getId) { public static IEnumerable<object?> GetItemsFromSource(IEnumerable source, IEnumerable<int?> ids) {
SelectListBoxItem(lb, getId, getId(item));
}
public static IEnumerable<object?> GetItemsFromSource(IEnumerable source, Func<object?, object?> getId, IEnumerable<object?> ids) {
if (source == null) if (source == null)
return Array.Empty<object>(); return [];
return source.Cast<object>().Where(i => ids.Any(c => c?.Equals(getId(i)) ?? false)); return source.Cast<object>().Where(i => ids.Any(c => c == Utils.GetEntityIdentifier(i)));
} }
public static IEnumerable<object?> GetItemsFromSource(IEnumerable source, IEnumerable<object?>? items, Func<object?, object?> getId) { public static IEnumerable<object?> GetItemsFromSource(IEnumerable source, IEnumerable<object?>? items) {
if (items == null) if (items == null)
return Array.Empty<object>(); return [];
return GetItemsFromSource(source, getId, items.Select(i => getId(i))); return GetItemsFromSource(source, items.Select(Utils.GetEntityIdentifier));
} }
public static void SelectCheckComboBoxItems(Xceed.Wpf.Toolkit.CheckComboBox ccb, Func<object?, object?> getId, IEnumerable<object?>? ids) { public static void SelectItems(Xceed.Wpf.Toolkit.CheckComboBox ccb, IEnumerable<int?>? ids) {
ccb.SelectedItems.Clear(); ccb.SelectedItems.Clear();
if (ids == null) return; if (ids == null) return;
foreach (var id in ids) foreach (var id in ids)
ccb.SelectedItems.Add(GetItemFromSource(ccb.ItemsSource, getId, id)); ccb.SelectedItems.Add(GetItemFromSource(ccb.ItemsSource, id));
} }
public static void SelectCheckComboBoxItems(Xceed.Wpf.Toolkit.CheckComboBox ccb, IEnumerable<object>? items, Func<object?, object?> getId) { public static void SelectItems(Xceed.Wpf.Toolkit.CheckComboBox ccb, IEnumerable<object>? items) {
SelectCheckComboBoxItems(ccb, getId, items?.Select(i => getId(i))); SelectItems(ccb, items?.Select(Utils.GetEntityIdentifier));
} }
public static int GetInputHashCode(Control input) { public static int? GetInputHashCode(Control input) {
if (input is TextBox tb) { if (input is TextBox tb) {
return Utils.GetEntityIdentifier(tb.Text); return Utils.GetEntityIdentifier(tb.Text);
} else if (input is ComboBox sb) { } else if (input is ComboBox sb) {
@ -229,7 +233,7 @@ namespace Elwig.Helpers {
} else if (input is RadioButton rb) { } else if (input is RadioButton rb) {
return Utils.GetEntityIdentifier(rb.IsChecked); return Utils.GetEntityIdentifier(rb.IsChecked);
} else { } else {
return 0; return null;
} }
} }
} }

View File

@ -435,17 +435,17 @@ namespace Elwig.Helpers {
return client; return client;
} }
public static int GetEntityIdentifier(object? obj) { public static int? GetEntityIdentifier(object? obj) {
if (obj == null) { if (obj == null) {
return 0; return null;
} else if (obj is IEnumerable list) { } else if (obj is IEnumerable list && obj is not string) {
var arr = list.Cast<object>().Select(o => GetEntityIdentifier(o)).ToArray(); var arr = list.Cast<object>().Select(GetEntityIdentifier).ToArray();
return ((IStructuralEquatable)arr).GetHashCode(EqualityComparer<int>.Default); return ((IStructuralEquatable)arr).GetHashCode(EqualityComparer<int?>.Default);
} else if (obj.GetType().GetCustomAttribute(typeof(PrimaryKeyAttribute), false) is not PrimaryKeyAttribute pkAttr) { } else if (obj.GetType().GetCustomAttribute(typeof(PrimaryKeyAttribute), true) is PrimaryKeyAttribute pkAttr) {
return obj.GetHashCode();
} else {
var pk = pkAttr.PropertyNames.Select(name => obj.GetType().GetProperty(name)!.GetValue(obj)?.GetHashCode() ?? 0).ToArray(); var pk = pkAttr.PropertyNames.Select(name => obj.GetType().GetProperty(name)!.GetValue(obj)?.GetHashCode() ?? 0).ToArray();
return ((IStructuralEquatable)pk).GetHashCode(EqualityComparer<int>.Default); return ((IStructuralEquatable)pk).GetHashCode(EqualityComparer<int>.Default);
} else {
return obj.GetHashCode();
} }
} }
} }

View File

@ -198,15 +198,15 @@ namespace Elwig.Windows {
protected void FillOriginalValues() { protected void FillOriginalValues() {
foreach (var tb in TextBoxInputs) foreach (var tb in TextBoxInputs)
OriginalValues[tb] = Utils.GetEntityIdentifier(tb.Text); OriginalValues[tb] = ControlUtils.GetInputHashCode(tb);
foreach (var cb in ComboBoxInputs) foreach (var cb in ComboBoxInputs)
OriginalValues[cb] = Utils.GetEntityIdentifier(cb.SelectedItem); OriginalValues[cb] = ControlUtils.GetInputHashCode(cb);
foreach (var ccb in CheckComboBoxInputs) foreach (var ccb in CheckComboBoxInputs)
OriginalValues[ccb] = Utils.GetEntityIdentifier(ccb.SelectedItems); OriginalValues[ccb] = ControlUtils.GetInputHashCode(ccb);
foreach (var cb in CheckBoxInputs) foreach (var cb in CheckBoxInputs)
OriginalValues[cb] = Utils.GetEntityIdentifier(cb.IsChecked); OriginalValues[cb] = ControlUtils.GetInputHashCode(cb);
foreach (var rb in RadioButtonInputs) foreach (var rb in RadioButtonInputs)
OriginalValues[rb] = Utils.GetEntityIdentifier(rb.IsChecked); OriginalValues[rb] = ControlUtils.GetInputHashCode(rb);
} }
protected void SetOriginalValue(Control input, object? value) { protected void SetOriginalValue(Control input, object? value) {
@ -232,7 +232,7 @@ namespace Elwig.Windows {
protected void SetDefaultValue(Control input, object? value) { protected void SetDefaultValue(Control input, object? value) {
if (input is UnitTextBox utbx) input = utbx.TextBox; if (input is UnitTextBox utbx) input = utbx.TextBox;
DefaultValues[input] = value != null ? Utils.GetEntityIdentifier(value) : null; DefaultValues[input] = Utils.GetEntityIdentifier(value);
if (!InputHasChanged(input)) { if (!InputHasChanged(input)) {
if (InputIsNotDefault(input)) { if (InputIsNotDefault(input)) {
ControlUtils.SetInputNotDefault(input); ControlUtils.SetInputNotDefault(input);
@ -278,39 +278,21 @@ namespace Elwig.Windows {
protected bool InputHasChanged(Control input) { protected bool InputHasChanged(Control input) {
if (input is UnitTextBox utbx) input = utbx.TextBox; if (input is UnitTextBox utbx) input = utbx.TextBox;
if (!OriginalValues.ContainsKey(input)) { if (!OriginalValues.TryGetValue(input, out int? original)) {
return false; return false;
} else if (input is TextBox tb) {
return OriginalValues[tb] != Utils.GetEntityIdentifier(tb.Text);
} else if (input is ComboBox sb) {
return OriginalValues[sb] != Utils.GetEntityIdentifier(sb.SelectedItem);
} else if (input is CheckComboBox ccb) {
return OriginalValues[ccb] != Utils.GetEntityIdentifier(ccb.SelectedItems);
} else if (input is CheckBox cb) {
return OriginalValues[cb] != Utils.GetEntityIdentifier(cb.IsChecked);
} else if (input is RadioButton rb) {
return OriginalValues[rb] != Utils.GetEntityIdentifier(rb.IsChecked);
} else { } else {
return false; var current = ControlUtils.GetInputHashCode(input);
return original != current;
} }
} }
protected bool InputIsNotDefault(Control input) { protected bool InputIsNotDefault(Control input) {
if (input is UnitTextBox utbx) input = utbx.TextBox; if (input is UnitTextBox utbx) input = utbx.TextBox;
if (!DefaultValues.ContainsKey(input)) { if (!DefaultValues.TryGetValue(input, out int? defaultValue)) {
return false; return false;
} else if (input is TextBox tb) {
return DefaultValues[tb] != Utils.GetEntityIdentifier(tb.Text);
} else if (input is ComboBox sb) {
return DefaultValues[sb] != Utils.GetEntityIdentifier(sb.SelectedItem);
} else if (input is CheckComboBox ccb) {
return DefaultValues[ccb] != Utils.GetEntityIdentifier(ccb.SelectedItems);
} else if (input is CheckBox cb) {
return DefaultValues[cb] != Utils.GetEntityIdentifier(cb.IsChecked);
} else if (input is RadioButton rb) {
return DefaultValues[rb] != Utils.GetEntityIdentifier(rb.IsChecked);
} else { } else {
return false; var current = ControlUtils.GetInputHashCode(input);
return defaultValue != current;
} }
} }
@ -343,7 +325,7 @@ namespace Elwig.Windows {
.ToListAsync(); .ToListAsync();
} }
ControlUtils.RenewItemsSource(ortInput, list, i => (i as AT_PlzDest)?.Id); ControlUtils.RenewItemsSource(ortInput, list);
if (list != null && ortInput.SelectedItem == null && list.Count == 1) if (list != null && ortInput.SelectedItem == null && list.Count == 1)
ortInput.SelectedItem = list[0]; ortInput.SelectedItem = list[0];
UpdateComboBox(ortInput); UpdateComboBox(ortInput);

View File

@ -61,7 +61,7 @@ namespace Elwig.Windows {
.ToList(); .ToList();
} }
ControlUtils.RenewItemsSource(AreaCommitmentList, areaComs, i => (i as AreaCom)?.FbNr, ControlUtils.RenewItemsSource(AreaCommitmentList, areaComs,
AreaCommitmentList_SelectionChanged, filter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort); AreaCommitmentList_SelectionChanged, filter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort);
RefreshInputs(); RefreshInputs();
@ -153,18 +153,18 @@ namespace Elwig.Windows {
YearFromInput.Text = a.YearFrom.ToString(); YearFromInput.Text = a.YearFrom.ToString();
YearToInput.Text = a.YearTo.ToString(); YearToInput.Text = a.YearTo.ToString();
ControlUtils.SelectComboBoxItem(KgInput, k => (k as AT_Kg)?.KgNr, a.KgNr); ControlUtils.SelectItemWithPk(KgInput, a.KgNr);
if (a.RdNr != null) { if (a.RdNr != null) {
ControlUtils.SelectComboBoxItem(RdInput, r => (r as WbRd)?.RdNr, a.RdNr); ControlUtils.SelectItemWithPk(RdInput, a.KgNr, a.RdNr);
} else { } else {
RdInput.SelectedIndex = 0; RdInput.SelectedIndex = 0;
} }
GstNrInput.Text = a.GstNr; GstNrInput.Text = a.GstNr;
AreaInput.Text = a.Area.ToString(); AreaInput.Text = a.Area.ToString();
ControlUtils.SelectComboBoxItem(AreaComTypeInput, t => (t as AreaComType)?.VtrgId, a.VtrgId); ControlUtils.SelectItemWithPk(AreaComTypeInput, a.VtrgId);
if (a.CultId != null) { if (a.CultId != null) {
ControlUtils.SelectComboBoxItem(WineCultivationInput, c => (c as WineCult)?.CultId, a.CultId); ControlUtils.SelectItemWithPk(WineCultivationInput, a.CultId);
} else { } else {
WineCultivationInput.SelectedIndex = 0; WineCultivationInput.SelectedIndex = 0;
} }
@ -196,17 +196,17 @@ namespace Elwig.Windows {
.Include(k => k.AtKg.WbKg!.Rds) .Include(k => k.AtKg.WbKg!.Rds)
.Select(k => k.AtKg) .Select(k => k.AtKg)
.OrderBy(k => k.Name) .OrderBy(k => k.Name)
.ToListAsync(), i => (i as AT_Kg)?.KgNr); .ToListAsync());
ControlUtils.RenewItemsSource(AreaComTypeInput, await ctx.AreaCommitmentTypes ControlUtils.RenewItemsSource(AreaComTypeInput, await ctx.AreaCommitmentTypes
.Include(c => c.WineVar) .Include(c => c.WineVar)
.Include(c => c.WineAttr) .Include(c => c.WineAttr)
.OrderBy(v => v.VtrgId) .OrderBy(v => v.VtrgId)
.ToListAsync(), i => (i as AreaComType)?.VtrgId); .ToListAsync());
var cultList = await ctx.WineCultivations var cultList = await ctx.WineCultivations
.OrderBy(c => c.Name) .OrderBy(c => c.Name)
.Cast<object>().ToListAsync(); .Cast<object>().ToListAsync();
cultList.Insert(0, new NullItem()); cultList.Insert(0, new NullItem());
ControlUtils.RenewItemsSource(WineCultivationInput, cultList, i => (i as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(WineCultivationInput, cultList, null, ControlUtils.RenewSourceDefault.First);
await RefreshAreaCommitmentList(); await RefreshAreaCommitmentList();
} }
@ -312,7 +312,7 @@ namespace Elwig.Windows {
await RefreshAreaCommitmentList(); await RefreshAreaCommitmentList();
RefreshInputs(); RefreshInputs();
SearchInput.Text = ""; SearchInput.Text = "";
AreaCommitmentList.SelectedItem = AreaCommitmentList.ItemsSource.Cast<AreaCom>().Where(a => a.FbNr == fbnr).FirstOrDefault(); ControlUtils.SelectItem(AreaCommitmentList, AreaCommitmentList.ItemsSource.Cast<AreaCom>().Where(a => a.FbNr == fbnr).FirstOrDefault());
} }
private void AreaCommitmentResetButton_Click(object sender, RoutedEventArgs evt) { private void AreaCommitmentResetButton_Click(object sender, RoutedEventArgs evt) {
@ -418,10 +418,10 @@ namespace Elwig.Windows {
if (KgInput.SelectedItem is AT_Kg kg) { if (KgInput.SelectedItem is AT_Kg kg) {
var rdList = kg.WbKg!.Rds.OrderBy(r => r.Name).Cast<object>().ToList(); var rdList = kg.WbKg!.Rds.OrderBy(r => r.Name).Cast<object>().ToList();
rdList.Insert(0, new NullItem()); rdList.Insert(0, new NullItem());
ControlUtils.RenewItemsSource(RdInput, rdList, i => (i as WbRd)?.RdNr, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(RdInput, rdList, null, ControlUtils.RenewSourceDefault.First);
} else { } else {
var rdList = new object[] { new NullItem() }; var rdList = new object[] { new NullItem() };
ControlUtils.RenewItemsSource(RdInput, rdList, i => (i as WbRd)?.RdNr, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(RdInput, rdList, null, ControlUtils.RenewSourceDefault.First);
} }
ComboBox_SelectionChanged(sender, evt); ComboBox_SelectionChanged(sender, evt);
} }

View File

@ -26,12 +26,12 @@ namespace Elwig.Windows {
.ToListAsync()); .ToListAsync());
_acts = _actList.ToDictionary(v => v.VtrgId, v => (string?)v.VtrgId); _acts = _actList.ToDictionary(v => v.VtrgId, v => (string?)v.VtrgId);
_actIds = _actList.ToDictionary(v => v, v => v.VtrgId); _actIds = _actList.ToDictionary(v => v, v => v.VtrgId);
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, _actList, a => (a as AreaComType)?.VtrgId); ControlUtils.RenewItemsSource(AreaCommitmentTypeList, _actList);
AreaCommitmentTypeList_SelectionChanged(null, null); AreaCommitmentTypeList_SelectionChanged(null, null);
} }
private async Task AreaCommitmentTypesFinishEditing(AppDbContext ctx) { private async Task AreaCommitmentTypesFinishEditing(AppDbContext ctx) {
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await ctx.AreaCommitmentTypes.OrderBy(v => v.SortId).ToListAsync(), v => (v as AreaComType)?.VtrgId); ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await ctx.AreaCommitmentTypes.OrderBy(v => v.SortId).ToListAsync());
_actList = null; _actList = null;
_acts = null; _acts = null;
_actIds = null; _actIds = null;
@ -73,8 +73,8 @@ namespace Elwig.Windows {
_actUpdate = true; _actUpdate = true;
if (AreaCommitmentTypeList.SelectedItem is AreaComType type) { if (AreaCommitmentTypeList.SelectedItem is AreaComType type) {
AreaCommitmentTypeIdInput.Text = $"{type.SortId}{type.AttrId}"; AreaCommitmentTypeIdInput.Text = $"{type.SortId}{type.AttrId}";
ControlUtils.SelectComboBoxItem(AreaCommitmentTypeWineVariantInput, s => (s as WineVar)?.SortId, type.SortId); ControlUtils.SelectItemWithPk(AreaCommitmentTypeWineVariantInput, type.SortId);
ControlUtils.SelectComboBoxItem(AreaCommitmentTypeWineAttributeInput, a => (a as WineAttr)?.AttrId, type.AttrId); ControlUtils.SelectItemWithPk(AreaCommitmentTypeWineAttributeInput, type.AttrId);
AreaCommitmentTypeMinKgPerHaInput.Text = $"{type.MinKgPerHa}"; AreaCommitmentTypeMinKgPerHaInput.Text = $"{type.MinKgPerHa}";
AreaCommitmentTypePenaltyPerKgInput.Text = $"{type.PenaltyPerKg}"; AreaCommitmentTypePenaltyPerKgInput.Text = $"{type.PenaltyPerKg}";
AreaCommitmentTypePenaltyInput.Text = $"{type.PenaltyAmount}"; AreaCommitmentTypePenaltyInput.Text = $"{type.PenaltyAmount}";

View File

@ -25,7 +25,7 @@ namespace Elwig.Windows {
.ToListAsync()); .ToListAsync());
_branches = _branchList.ToDictionary(b => b.ZwstId, b => (string?)b.ZwstId); _branches = _branchList.ToDictionary(b => b.ZwstId, b => (string?)b.ZwstId);
_branchIds = _branchList.ToDictionary(b => b, b => b.ZwstId); _branchIds = _branchList.ToDictionary(b => b, b => b.ZwstId);
ControlUtils.RenewItemsSource(BranchList, _branchList, b => (b as Branch)?.ZwstId); ControlUtils.RenewItemsSource(BranchList, _branchList);
BranchList_SelectionChanged(null, null); BranchList_SelectionChanged(null, null);
} }
@ -33,7 +33,7 @@ namespace Elwig.Windows {
ControlUtils.RenewItemsSource(BranchList, await ctx.Branches ControlUtils.RenewItemsSource(BranchList, await ctx.Branches
.OrderBy(b => b.Name) .OrderBy(b => b.Name)
.Include(b => b.PostalDest!.AtPlz) .Include(b => b.PostalDest!.AtPlz)
.ToListAsync(), b => (b as Branch)?.ZwstId); .ToListAsync());
_branchList = null; _branchList = null;
_branches = null; _branches = null;
_branchIds = null; _branchIds = null;
@ -85,7 +85,7 @@ namespace Elwig.Windows {
BranchIdInput.Text = branch.ZwstId; BranchIdInput.Text = branch.ZwstId;
BranchNameInput.Text = branch.Name; BranchNameInput.Text = branch.Name;
BranchPlzInput.Text = branch.PostalDest?.AtPlz?.Plz.ToString() ?? ""; BranchPlzInput.Text = branch.PostalDest?.AtPlz?.Plz.ToString() ?? "";
ControlUtils.SelectComboBoxItem(BranchOrtInput, o => (o as AT_PlzDest)?.Okz, branch.PostalDest?.AtPlz?.Okz); ControlUtils.SelectItem(BranchOrtInput, branch.PostalDest?.AtPlz);
BranchAddressInput.Text = branch.Address; BranchAddressInput.Text = branch.Address;
BranchPhoneNrInput.Text = branch.PhoneNr; BranchPhoneNrInput.Text = branch.PhoneNr;
BranchFaxNrInput.Text = branch.FaxNr; BranchFaxNrInput.Text = branch.FaxNr;

View File

@ -25,13 +25,13 @@ namespace Elwig.Windows {
_modList = new(await ctx.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync()); _modList = new(await ctx.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync());
_mods = _modList.ToDictionary(m => m.ModId, m => (string?)m.ModId); _mods = _modList.ToDictionary(m => m.ModId, m => (string?)m.ModId);
_modIds = _modList.ToDictionary(m => m, m => m.ModId); _modIds = _modList.ToDictionary(m => m, m => m.ModId);
ControlUtils.RenewItemsSource(SeasonModifierList, _modList, m => (m as Modifier)?.ModId); ControlUtils.RenewItemsSource(SeasonModifierList, _modList);
SeasonModifierList_SelectionChanged(null, null); SeasonModifierList_SelectionChanged(null, null);
} }
private async Task ModifiersFinishEditing(AppDbContext ctx) { private async Task ModifiersFinishEditing(AppDbContext ctx) {
var year = (SeasonList.SelectedItem as Season)?.Year; var year = (SeasonList.SelectedItem as Season)?.Year;
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync(), m => (m as Modifier)?.ModId); ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.Modifiers.Where(m => m.Year == year).OrderBy(m => m.Ordering).ToListAsync());
_modList = null; _modList = null;
_mods = null; _mods = null;
_modIds = null; _modIds = null;

View File

@ -13,12 +13,12 @@ namespace Elwig.Windows {
private bool _seasonUpdate = false; private bool _seasonUpdate = false;
private async Task SeasonsInitEditing(AppDbContext ctx) { private async Task SeasonsInitEditing(AppDbContext ctx) {
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).ToListAsync(), s => (s as Season)?.Year); ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).ToListAsync());
SeasonList_SelectionChanged(null, null); SeasonList_SelectionChanged(null, null);
} }
private async Task SeasonsFinishEditing(AppDbContext ctx) { private async Task SeasonsFinishEditing(AppDbContext ctx) {
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).Include(s => s.Modifiers).ToListAsync(), s => (s as Season)?.Year); ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons.OrderByDescending(s => s.Year).Include(s => s.Modifiers).ToListAsync());
_seasonChanged = false; _seasonChanged = false;
} }

View File

@ -22,12 +22,12 @@ namespace Elwig.Windows {
_attrList = new(await ctx.WineAttributes.OrderBy(a => a.Name).ToListAsync()); _attrList = new(await ctx.WineAttributes.OrderBy(a => a.Name).ToListAsync());
_attrs = _attrList.ToDictionary(a => a.AttrId, a => (string?)a.AttrId); _attrs = _attrList.ToDictionary(a => a.AttrId, a => (string?)a.AttrId);
_attrIds = _attrList.ToDictionary(a => a, a => a.AttrId); _attrIds = _attrList.ToDictionary(a => a, a => a.AttrId);
ControlUtils.RenewItemsSource(WineAttributeList, _attrList, a => (a as WineAttr)?.AttrId); ControlUtils.RenewItemsSource(WineAttributeList, _attrList);
WineAttributeList_SelectionChanged(null, null); WineAttributeList_SelectionChanged(null, null);
} }
private async Task WineAttributesFinishEditing(AppDbContext ctx) { private async Task WineAttributesFinishEditing(AppDbContext ctx) {
ControlUtils.RenewItemsSource(WineAttributeList, await ctx.WineAttributes.OrderBy(a => a.Name).ToListAsync(), a => (a as WineAttr)?.AttrId); ControlUtils.RenewItemsSource(WineAttributeList, await ctx.WineAttributes.OrderBy(a => a.Name).ToListAsync());
_attrList = null; _attrList = null;
_attrs = null; _attrs = null;
_attrIds = null; _attrIds = null;

View File

@ -22,12 +22,12 @@ namespace Elwig.Windows {
_cultList = new(await ctx.WineCultivations.OrderBy(c => c.Name).ToListAsync()); _cultList = new(await ctx.WineCultivations.OrderBy(c => c.Name).ToListAsync());
_cults = _cultList.ToDictionary(c => c.CultId, c => (string?)c.CultId); _cults = _cultList.ToDictionary(c => c.CultId, c => (string?)c.CultId);
_cultIds = _cultList.ToDictionary(c => c, c => c.CultId); _cultIds = _cultList.ToDictionary(c => c, c => c.CultId);
ControlUtils.RenewItemsSource(WineCultivationList, _cultList, c => (c as WineCult)?.CultId); ControlUtils.RenewItemsSource(WineCultivationList, _cultList);
WineCultivationList_SelectionChanged(null, null); WineCultivationList_SelectionChanged(null, null);
} }
private async Task WineCultivationsFinishEditing(AppDbContext ctx) { private async Task WineCultivationsFinishEditing(AppDbContext ctx) {
ControlUtils.RenewItemsSource(WineCultivationList, await ctx.WineCultivations.OrderBy(c => c.Name).ToListAsync(), c => (c as WineCult)?.CultId); ControlUtils.RenewItemsSource(WineCultivationList, await ctx.WineCultivations.OrderBy(c => c.Name).ToListAsync());
_cultList = null; _cultList = null;
_cults = null; _cults = null;
_cultIds = null; _cultIds = null;

View File

@ -137,33 +137,33 @@ namespace Elwig.Windows {
FillInputs(App.Client); FillInputs(App.Client);
ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons ControlUtils.RenewItemsSource(SeasonList, await ctx.Seasons
.OrderByDescending(s => s.Year) .OrderByDescending(s => s.Year)
.ToListAsync(), s => (s as Season)?.Year, null, ControlUtils.RenewSourceDefault.First); .ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
var year = (SeasonList.SelectedItem as Season)?.Year; var year = (SeasonList.SelectedItem as Season)?.Year;
ControlUtils.RenewItemsSource(BranchList, await ctx.Branches ControlUtils.RenewItemsSource(BranchList, await ctx.Branches
.OrderBy(b => b.Name) .OrderBy(b => b.Name)
.Include(b => b.PostalDest!.AtPlz) .Include(b => b.PostalDest!.AtPlz)
.ToListAsync(), b => (b as Branch)?.ZwstId, null, ControlUtils.RenewSourceDefault.First); .ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineAttributeList, await ctx.WineAttributes ControlUtils.RenewItemsSource(WineAttributeList, await ctx.WineAttributes
.OrderBy(a => a.Name) .OrderBy(a => a.Name)
.ToListAsync(), a => (a as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First); .ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineVariantInput, await ctx.WineVarieties ControlUtils.RenewItemsSource(AreaCommitmentTypeWineVariantInput, await ctx.WineVarieties
.OrderBy(s => s.Name) .OrderBy(s => s.Name)
.ToListAsync(), s => (s as WineVar)?.SortId); .ToListAsync());
var attrList = await ctx.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync(); var attrList = await ctx.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem("")); attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AreaCommitmentTypeWineAttributeInput, attrList, a => (a as WineAttr)?.AttrId); ControlUtils.RenewItemsSource(AreaCommitmentTypeWineAttributeInput, attrList);
ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await ctx.AreaCommitmentTypes ControlUtils.RenewItemsSource(AreaCommitmentTypeList, await ctx.AreaCommitmentTypes
.OrderBy(t => t.VtrgId) .OrderBy(t => t.VtrgId)
.Include(t => t.WineVar) .Include(t => t.WineVar)
.Include(t => t.WineAttr) .Include(t => t.WineAttr)
.ToListAsync(), t => (t as AreaComType)?.VtrgId, null, ControlUtils.RenewSourceDefault.First); .ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineCultivationList, await ctx.WineCultivations ControlUtils.RenewItemsSource(WineCultivationList, await ctx.WineCultivations
.OrderBy(c => c.Name) .OrderBy(c => c.Name)
.ToListAsync(), c=> (c as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First); .ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.Modifiers ControlUtils.RenewItemsSource(SeasonModifierList, await ctx.Modifiers
.Where(m => m.Year == year) .Where(m => m.Year == year)
.OrderBy(m => m.Ordering) .OrderBy(m => m.Ordering)
.ToListAsync(), m => (m as Modifier)?.ModId, null, ControlUtils.RenewSourceDefault.First); .ToListAsync(), null, ControlUtils.RenewSourceDefault.First);
} }
protected override void UpdateButtons() { protected override void UpdateButtons() {

View File

@ -139,9 +139,9 @@ namespace Elwig.Windows {
}); });
FillingInputs = true; FillingInputs = true;
ControlUtils.RenewItemsSource(VaributeInput, Vaributes, v => (v as Varibute)?.Listing); ControlUtils.RenewItemsSource(VaributeInput, Vaributes);
FillingInputs = false; FillingInputs = false;
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.VaributeStringChange, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(GraphList, GraphEntries, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
RefreshInputs(); RefreshInputs();
} }
@ -194,7 +194,7 @@ namespace Elwig.Windows {
GebundenFlatBonus.Text = ""; GebundenFlatBonus.Text = "";
} }
ControlUtils.SelectCheckComboBoxItems(VaributeInput, SelectedGraphEntry?.Vaributes ?? [], i => (i as Varibute)?.Listing); ControlUtils.SelectItems(VaributeInput, SelectedGraphEntry?.Vaributes ?? []);
InitPlot(); InitPlot();
OechslePricePlot.IsEnabled = true; OechslePricePlot.IsEnabled = true;

View File

@ -396,10 +396,10 @@
<CheckBox x:Name="LesewagenInput" Content="Lesewagen" Margin="10,75,0,0" Grid.Column="2" <CheckBox x:Name="LesewagenInput" Content="Lesewagen" Margin="10,75,0,0" Grid.Column="2"
VerticalAlignment="Top" HorizontalAlignment="Left" VerticalAlignment="Top" HorizontalAlignment="Left"
Checked="LesewagenInput_Changed" Unchecked="LesewagenInput_Changed"/> Checked="LesewagenInput_Changed" Unchecked="LesewagenInput_Changed" Click="HandPickedInput_Changed"/>
<CheckBox x:Name="HandPickedInput" Content="Handlese" Margin="10,105,0,0" Grid.Column="2" IsThreeState="True" <CheckBox x:Name="HandPickedInput" Content="Handlese" Margin="10,105,0,0" Grid.Column="2" IsThreeState="True"
VerticalAlignment="Top" HorizontalAlignment="Left" VerticalAlignment="Top" HorizontalAlignment="Left"
Checked="HandPickedInput_Changed" Unchecked="HandPickedInput_Changed"/> Checked="HandPickedInput_Changed" Unchecked="HandPickedInput_Changed" Click="HandPickedInput_Changed"/>
</Grid> </Grid>
</GroupBox> </GroupBox>

View File

@ -288,7 +288,7 @@ namespace Elwig.Windows {
} }
private void InitInputs() { private void InitInputs() {
ControlUtils.SelectComboBoxItem(BranchInput, i => (i as Branch)?.ZwstId, App.ZwstId); ControlUtils.SelectItemWithPk(BranchInput, App.ZwstId);
OnSecondPassed(null, null); OnSecondPassed(null, null);
UpdateLsNr().GetAwaiter().GetResult(); UpdateLsNr().GetAwaiter().GetResult();
InitialInputs(); InitialInputs();
@ -646,7 +646,7 @@ namespace Elwig.Windows {
} }
deliveries.ForEach(d => { d.PartFilter = predicate; }); deliveries.ForEach(d => { d.PartFilter = predicate; });
ControlUtils.RenewItemsSource(DeliveryList, deliveries, d => ((d as Delivery)?.Year, (d as Delivery)?.DId), ControlUtils.RenewItemsSource(DeliveryList, deliveries,
DeliveryList_SelectionChanged, filter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort); DeliveryList_SelectionChanged, filter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort);
await RefreshDeliveryParts(); await RefreshDeliveryParts();
@ -795,21 +795,21 @@ namespace Elwig.Windows {
await RefreshDeliveryList(); await RefreshDeliveryList();
var d = DeliveryList.SelectedItem as Delivery; var d = DeliveryList.SelectedItem as Delivery;
var y = d?.Year ?? Utils.CurrentLastSeason; var y = d?.Year ?? Utils.CurrentLastSeason;
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsCreating).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr); ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsCreating).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync());
ControlUtils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId); ControlUtils.RenewItemsSource(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync());
ControlUtils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId); ControlUtils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync());
var attrList = await Context.WineAttributes.Where(a => !IsCreating || a.IsActive).OrderBy(a => a.Name).Cast<object>().ToListAsync(); var attrList = await Context.WineAttributes.Where(a => !IsCreating || a.IsActive).OrderBy(a => a.Name).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem("")); attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(AttributeInput, attrList, null, ControlUtils.RenewSourceDefault.First);
var cultList = await Context.WineCultivations.OrderBy(a => a.Name).Cast<object>().ToListAsync(); var cultList = await Context.WineCultivations.OrderBy(a => a.Name).Cast<object>().ToListAsync();
cultList.Insert(0, new NullItem("")); cultList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(CultivationInput, cultList, i => (i as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(CultivationInput, cultList, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(WineQualityLevelInput, await Context.WineQualityLevels.ToListAsync(), i => (i as WineQualLevel)?.QualId); ControlUtils.RenewItemsSource(WineQualityLevelInput, await Context.WineQualityLevels.ToListAsync());
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == y).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId); ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == y).OrderBy(m => m.Ordering).ToListAsync());
ControlUtils.RenewItemsSource(WineOriginInput, (await Context.WineOrigins.ToListAsync()).OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId), i => (i as WineOrigin)?.HkId); ControlUtils.RenewItemsSource(WineOriginInput, (await Context.WineOrigins.ToListAsync()).OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId));
var kgList = await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).Cast<object>().ToListAsync(); var kgList = await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).Cast<object>().ToListAsync();
kgList.Insert(0, new NullItem()); kgList.Insert(0, new NullItem());
ControlUtils.RenewItemsSource(WineKgInput, kgList, i => (i as AT_Kg)?.KgNr); ControlUtils.RenewItemsSource(WineKgInput, kgList);
UpdateRdInput(); UpdateRdInput();
if (IsCreating) await UpdateLsNr(); if (IsCreating) await UpdateLsNr();
@ -826,10 +826,10 @@ namespace Elwig.Windows {
private async Task RefreshDeliveryParts() { private async Task RefreshDeliveryParts() {
if (DeliveryList.SelectedItem is Delivery d) { if (DeliveryList.SelectedItem is Delivery d) {
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == d.Year).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId); ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == d.Year).OrderBy(m => m.Ordering).ToListAsync());
ControlUtils.RenewItemsSource(DeliveryPartList, d.FilteredParts.OrderBy(p => p.DPNr).ToList(), i => ((i as DeliveryPart)?.Year, (i as DeliveryPart)?.DId, (i as DeliveryPart)?.DPNr), DeliveryPartList_SelectionChanged, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(DeliveryPartList, d.FilteredParts.OrderBy(p => p.DPNr).ToList(), DeliveryPartList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
} else { } else {
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == Utils.CurrentLastSeason).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId); ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == Utils.CurrentLastSeason).OrderBy(m => m.Ordering).ToListAsync());
DeliveryPartList.ItemsSource = null; DeliveryPartList.ItemsSource = null;
} }
} }
@ -854,7 +854,7 @@ namespace Elwig.Windows {
ClearDefaultValues(); ClearDefaultValues();
MgNrInput.Text = d.MgNr.ToString(); MgNrInput.Text = d.MgNr.ToString();
ControlUtils.SelectComboBoxItem(BranchInput, i => (i as Branch)?.ZwstId, d.ZwstId); ControlUtils.SelectItemWithPk(BranchInput, d.ZwstId);
LsNrInput.Text = d.LsNr; LsNrInput.Text = d.LsNr;
DateInput.Text = d.Date.ToString("dd.MM.yyyy"); DateInput.Text = d.Date.ToString("dd.MM.yyyy");
TimeInput.Text = d.Time?.ToString("HH:mm") ?? ""; TimeInput.Text = d.Time?.ToString("HH:mm") ?? "";
@ -877,17 +877,17 @@ namespace Elwig.Windows {
ClearDefaultValues(); ClearDefaultValues();
SortIdInput.Text = p?.SortId ?? ""; SortIdInput.Text = p?.SortId ?? "";
ControlUtils.SelectComboBoxItem(AttributeInput, p?.Attribute, i => (i as WineAttr)?.AttrId); ControlUtils.SelectItemWithPk(AttributeInput, p?.AttrId);
ControlUtils.SelectComboBoxItem(CultivationInput, p?.Cultivation, i => (i as WineCult)?.CultId); ControlUtils.SelectItemWithPk(CultivationInput, p?.CultId);
GradationKmwInput.Text = (p != null) ? $"{p.Kmw:N1}" : ""; GradationKmwInput.Text = (p != null) ? $"{p.Kmw:N1}" : "";
ControlUtils.SelectComboBoxItem(WineQualityLevelInput, q => (q as WineQualLevel)?.QualId, p?.QualId); ControlUtils.SelectItemWithPk(WineQualityLevelInput, p?.QualId);
ControlUtils.SelectComboBoxItem(WineKgInput, k => (k as AT_Kg)?.KgNr, p?.KgNr); ControlUtils.SelectItemWithPk(WineKgInput, p?.KgNr);
ControlUtils.SelectComboBoxItem(WineRdInput, r => (r as WbRd)?.RdNr, p?.RdNr); ControlUtils.SelectItemWithPk(WineRdInput, p?.KgNr, p?.RdNr);
ControlUtils.SelectComboBoxItem(WineOriginInput, r => (r as WineOrigin)?.HkId, p?.HkId); ControlUtils.SelectItemWithPk(WineOriginInput, p?.HkId);
WeightInput.Text = (p != null) ? $"{p.Weight:N0}" : ""; WeightInput.Text = (p != null) ? $"{p.Weight:N0}" : "";
ManualWeighingInput.IsChecked = p?.IsManualWeighing ?? false; ManualWeighingInput.IsChecked = p?.IsManualWeighing ?? false;
GerebeltGewogenInput.IsChecked = p?.IsNetWeight ?? false; GerebeltGewogenInput.IsChecked = p?.IsNetWeight ?? false;
ControlUtils.SelectCheckComboBoxItems(ModifiersInput, p?.Modifiers, i => (i as Modifier)?.ModId); ControlUtils.SelectItems(ModifiersInput, p?.Modifiers);
PartCommentInput.Text = p?.Comment ?? ""; PartCommentInput.Text = p?.Comment ?? "";
TemperatureInput.Text = (p != null && p.Temperature != null) ? $"{p.Temperature:N1}" : ""; TemperatureInput.Text = (p != null && p.Temperature != null) ? $"{p.Temperature:N1}" : "";
AcidInput.Text = (p != null && p.Acid != null) ? $"{p.Acid:N1}" : ""; AcidInput.Text = (p != null && p.Acid != null) ? $"{p.Acid:N1}" : "";
@ -1118,12 +1118,12 @@ namespace Elwig.Windows {
private void MgNrInput_TextChanged(object sender, TextChangedEventArgs evt) { private void MgNrInput_TextChanged(object sender, TextChangedEventArgs evt) {
var valid = InputTextChanged((TextBox)sender, Validator.CheckMgNr); var valid = InputTextChanged((TextBox)sender, Validator.CheckMgNr);
MemberInput.SelectedItem = valid ? Context.Members.Find(int.Parse(MgNrInput.Text)) : null; ControlUtils.SelectItemWithPk(MemberInput, valid ? int.Parse(MgNrInput.Text) : null);
} }
private void MgNrInput_LostFocus(object sender, RoutedEventArgs evt) { private void MgNrInput_LostFocus(object sender, RoutedEventArgs evt) {
var valid = InputLostFocus((TextBox)sender, Validator.CheckMgNr); var valid = InputLostFocus((TextBox)sender, Validator.CheckMgNr);
MemberInput.SelectedItem = valid ? Context.Members.Find(int.Parse(MgNrInput.Text)) : null; ControlUtils.SelectItemWithPk(MemberInput, valid ? int.Parse(MgNrInput.Text) : null);
} }
private void MemberInput_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) { private void MemberInput_SelectionChanged(object? sender, SelectionChangedEventArgs? evt) {
@ -1134,8 +1134,8 @@ namespace Elwig.Windows {
UnsetDefaultValue(WineKgInput); UnsetDefaultValue(WineKgInput);
WineKgInput.SelectedIndex = 0; WineKgInput.SelectedIndex = 0;
} else { } else {
SetDefaultValue(WineKgInput, m.DefaultKg); ControlUtils.SelectItemWithPk(WineKgInput, m.DefaultKgNr);
WineKgInput.SelectedItem = m.DefaultKg; SetDefaultValue(WineKgInput);
} }
} }
@ -1155,7 +1155,7 @@ namespace Elwig.Windows {
await RefreshDeliveryList(); await RefreshDeliveryList();
await RefreshDeliveryParts(); await RefreshDeliveryParts();
NewDeliveryPartButton.Cursor = null; NewDeliveryPartButton.Cursor = null;
DeliveryList.SelectedItem = p?.Delivery; ControlUtils.SelectItem(DeliveryList, p?.Delivery);
DeliveryPartList.SelectedItem = null; DeliveryPartList.SelectedItem = null;
RefreshInputs(); RefreshInputs();
InitialInputs(); InitialInputs();
@ -1201,8 +1201,8 @@ namespace Elwig.Windows {
var attrList = await Context.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync(); var attrList = await Context.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem("")); attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(AttributeInput, attrList, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr); ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync());
if (DeliveryList.SelectedItem is not Delivery d) { if (DeliveryList.SelectedItem is not Delivery d) {
// switch away from creating mode // switch away from creating mode
IsCreating = false; IsCreating = false;
@ -1220,7 +1220,7 @@ namespace Elwig.Windows {
} else { } else {
// switch to last delivery part // switch to last delivery part
DeliveryPartList.IsEnabled = true; DeliveryPartList.IsEnabled = true;
DeliveryPartList.SelectedItem = d.FilteredParts.Last(); ControlUtils.SelectItem(DeliveryPartList, d.FilteredParts.Last());
} }
} }
@ -1229,8 +1229,8 @@ namespace Elwig.Windows {
SearchInput.Text = ""; SearchInput.Text = "";
var attrList = await Context.WineAttributes.Where(a => a.IsActive).OrderBy(a => a.Name).Cast<object>().ToListAsync(); var attrList = await Context.WineAttributes.Where(a => a.IsActive).OrderBy(a => a.Name).Cast<object>().ToListAsync();
attrList.Insert(0, new NullItem("")); attrList.Insert(0, new NullItem(""));
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, null, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(AttributeInput, attrList, null, ControlUtils.RenewSourceDefault.First);
ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync(), i => (i as Member)?.MgNr); ControlUtils.RenewItemsSource(MemberInput, await Context.Members.Where(m => m.IsActive || !IsReceipt).OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToListAsync());
IsCreating = true; IsCreating = true;
DeliveryList.IsEnabled = false; DeliveryList.IsEnabled = false;
DeliveryPartList.IsEnabled = false; DeliveryPartList.IsEnabled = false;
@ -1253,8 +1253,8 @@ namespace Elwig.Windows {
Mouse.OverrideCursor = Cursors.AppStarting; Mouse.OverrideCursor = Cursors.AppStarting;
ClearOriginalValues(); ClearOriginalValues();
if (res >= p.Weight) { if (res >= p.Weight) {
ControlUtils.SelectComboBoxItem(WineQualityLevelInput, q => (q as WineQualLevel)?.QualId, "WEI"); ControlUtils.SelectItemWithPk(WineQualityLevelInput, "WEI");
ControlUtils.SelectComboBoxItem(WineOriginInput, o => (o as WineOrigin)?.HkId, "OEST"); ControlUtils.SelectItemWithPk(WineOriginInput, "OEST");
p.QualId = "WEI"; p.QualId = "WEI";
p.HkId = "OEST"; p.HkId = "OEST";
entry1 = Context.Update(p); entry1 = Context.Update(p);
@ -1449,7 +1449,7 @@ namespace Elwig.Windows {
Mouse.OverrideCursor = null; Mouse.OverrideCursor = null;
await RefreshDeliveryList(); await RefreshDeliveryList();
DeliveryList.SelectedItem = d; ControlUtils.SelectItem(DeliveryList, d);
} catch (Exception exc) { } catch (Exception exc) {
if (entry != null) { if (entry != null) {
entry.State = EntityState.Detached; entry.State = EntityState.Detached;
@ -1612,10 +1612,10 @@ namespace Elwig.Windows {
private void UpdateWineVariety(bool valid) { private void UpdateWineVariety(bool valid) {
if (valid) { if (valid) {
var text = SortIdInput.Text; var text = SortIdInput.Text;
WineVarietyInput.SelectedItem = Context.WineVarieties.Find(text[0..2]); ControlUtils.SelectItemWithPk(WineVarietyInput, text[0..2]);
if (text.Length >= 3) { if (text.Length >= 3) {
ControlUtils.SelectComboBoxItem(AttributeInput, Context.WineAttributes.Find(text[2..]), a => (a as WineAttr)?.AttrId); ControlUtils.SelectItemWithPk(AttributeInput, text[2..]);
ControlUtils.SelectComboBoxItem(CultivationInput, Context.WineCultivations.Find(text[2..]), i => (i as WineCult)?.CultId); ControlUtils.SelectItemWithPk(CultivationInput, text[2..]);
SortIdInput.Text = text[0..2]; SortIdInput.Text = text[0..2];
} }
} else { } else {
@ -1649,7 +1649,7 @@ namespace Elwig.Windows {
var qual = Context.GetWineQualityLevel(kmw).GetAwaiter().GetResult(); var qual = Context.GetWineQualityLevel(kmw).GetAwaiter().GetResult();
SetDefaultValue(WineQualityLevelInput, qual); SetDefaultValue(WineQualityLevelInput, qual);
if (WineQualityLevelInput.SelectedItem == null || (WineQualityLevelInput.SelectedItem is WineQualLevel selected && !selected.IsPredicate)) { if (WineQualityLevelInput.SelectedItem == null || (WineQualityLevelInput.SelectedItem is WineQualLevel selected && !selected.IsPredicate)) {
WineQualityLevelInput.SelectedItem = qual; ControlUtils.SelectItem(WineQualityLevelInput, qual);
} }
} }
@ -1744,7 +1744,7 @@ namespace Elwig.Windows {
var o = kg.Origin; var o = kg.Origin;
while (o != null && o.Level > qual.OriginLevel) o = o.Parent; while (o != null && o.Level > qual.OriginLevel) o = o.Parent;
SetDefaultValue(WineOriginInput, o); SetDefaultValue(WineOriginInput, o);
WineOriginInput.SelectedItem = o; ControlUtils.SelectItem(WineOriginInput, o);
} }
private void WineQualityLevelInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) { private void WineQualityLevelInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
@ -1756,7 +1756,7 @@ namespace Elwig.Windows {
if (WineKgInput.SelectedItem is AT_Kg kg) { if (WineKgInput.SelectedItem is AT_Kg kg) {
var list = Context.WbRde.Where(r => r.KgNr == kg.KgNr).OrderBy(r => r.Name).Cast<object>().ToList(); var list = Context.WbRde.Where(r => r.KgNr == kg.KgNr).OrderBy(r => r.Name).Cast<object>().ToList();
list.Insert(0, new NullItem()); list.Insert(0, new NullItem());
ControlUtils.RenewItemsSource(WineRdInput, list, i => ((i as WbRd)?.KgNr, (i as WbRd)?.RdNr)); ControlUtils.RenewItemsSource(WineRdInput, list);
if (WineRdInput.SelectedItem == null) WineRdInput.SelectedIndex = 0; if (WineRdInput.SelectedItem == null) WineRdInput.SelectedIndex = 0;
WineRdInput.IsEnabled = (IsEditing || IsCreating) && list.Count > 1; WineRdInput.IsEnabled = (IsEditing || IsCreating) && list.Count > 1;
} else { } else {

View File

@ -142,7 +142,7 @@ namespace Elwig.Windows {
ControlUtils.RenewItemsSource(MemberBranchInput, await ctx.Branches ControlUtils.RenewItemsSource(MemberBranchInput, await ctx.Branches
.Where(b => b.Members.Any()) .Where(b => b.Members.Any())
.OrderBy(b => b.Name) .OrderBy(b => b.Name)
.ToListAsync(), b => (b as Branch)?.ZwstId, MemberInput_SelectionChanged); .ToListAsync(), MemberInput_SelectionChanged);
if (MemberBranchInput.SelectedItems.Count == 0) { if (MemberBranchInput.SelectedItems.Count == 0) {
MemberBranchInput.ItemSelectionChanged -= MemberInput_SelectionChanged; MemberBranchInput.ItemSelectionChanged -= MemberInput_SelectionChanged;
MemberBranchInput.SelectAll(); MemberBranchInput.SelectAll();
@ -151,7 +151,7 @@ namespace Elwig.Windows {
ControlUtils.RenewItemsSource(MemberKgInput, await ctx.Katastralgemeinden ControlUtils.RenewItemsSource(MemberKgInput, await ctx.Katastralgemeinden
.Where(k => k.WbKg!.Members.Any()) .Where(k => k.WbKg!.Members.Any())
.OrderBy(k => k.Name) .OrderBy(k => k.Name)
.ToListAsync(), k => (k as AT_Kg)?.KgNr, MemberInput_SelectionChanged); .ToListAsync(), MemberInput_SelectionChanged);
if (MemberKgInput.SelectedItems.Count == 0) { if (MemberKgInput.SelectedItems.Count == 0) {
MemberKgInput.ItemSelectionChanged -= MemberInput_SelectionChanged; MemberKgInput.ItemSelectionChanged -= MemberInput_SelectionChanged;
MemberKgInput.SelectAll(); MemberKgInput.SelectAll();
@ -159,7 +159,7 @@ namespace Elwig.Windows {
} }
ControlUtils.RenewItemsSource(MemberAreaComInput, await ctx.AreaCommitmentTypes ControlUtils.RenewItemsSource(MemberAreaComInput, await ctx.AreaCommitmentTypes
.OrderBy(a => a.VtrgId) .OrderBy(a => a.VtrgId)
.ToListAsync(), a => (a as AreaComType)?.VtrgId, MemberInput_SelectionChanged); .ToListAsync(), MemberInput_SelectionChanged);
if (MemberAreaComInput.SelectedItems.Count == 0) { if (MemberAreaComInput.SelectedItems.Count == 0) {
MemberAreaComInput.ItemSelectionChanged -= MemberInput_SelectionChanged; MemberAreaComInput.ItemSelectionChanged -= MemberInput_SelectionChanged;
MemberAreaComInput.SelectAll(); MemberAreaComInput.SelectAll();
@ -169,7 +169,7 @@ namespace Elwig.Windows {
.Where(m => m.IsActive) .Where(m => m.IsActive)
.OrderBy(m => m.FamilyName) .OrderBy(m => m.FamilyName)
.ThenBy(m => m.GivenName) .ThenBy(m => m.GivenName)
.ToListAsync(), m => (m as Member)?.MgNr, MemberInput_SelectionChanged); .ToListAsync(), MemberInput_SelectionChanged);
if (MemberCustomInput.SelectedItems.Count == 0) { if (MemberCustomInput.SelectedItems.Count == 0) {
MemberCustomInput.ItemSelectionChanged -= MemberInput_SelectionChanged; MemberCustomInput.ItemSelectionChanged -= MemberInput_SelectionChanged;
MemberCustomInput.SelectAll(); MemberCustomInput.SelectAll();

View File

@ -90,8 +90,7 @@ namespace Elwig.Windows {
FocusMember(mgnr); FocusMember(mgnr);
}); });
} else { } else {
MemberList.SelectedItem = item; ControlUtils.SelectItem(MemberList, item);
MemberList.ScrollIntoView(MemberList.SelectedItem);
} }
} }
@ -218,7 +217,7 @@ namespace Elwig.Windows {
.ToList(); .ToList();
} }
ControlUtils.RenewItemsSource(MemberList, members, i => (i as Member)?.MgNr, ControlUtils.RenewItemsSource(MemberList, members,
MemberList_SelectionChanged, TextFilter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort); MemberList_SelectionChanged, TextFilter.Count > 0 ? ControlUtils.RenewSourceDefault.IfOnly : ControlUtils.RenewSourceDefault.None, !updateSort);
} }
@ -268,8 +267,8 @@ namespace Elwig.Windows {
protected override async Task OnRenewContext() { protected override async Task OnRenewContext() {
await base.OnRenewContext(); await base.OnRenewContext();
using var ctx = new AppDbContext(); using var ctx = new AppDbContext();
ControlUtils.RenewItemsSource(BranchInput, await ctx.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId); ControlUtils.RenewItemsSource(BranchInput, await ctx.Branches.OrderBy(b => b.Name).ToListAsync());
ControlUtils.RenewItemsSource(DefaultKgInput, await ctx.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync(), i => (i as AT_Kg)?.KgNr); ControlUtils.RenewItemsSource(DefaultKgInput, await ctx.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToListAsync());
await RefreshMemberList(); await RefreshMemberList();
StatusMembers.Text = $"Mitglieder: {await ctx.Members.CountAsync(m => m.IsActive):N0} ({await ctx.Members.CountAsync():N0})"; StatusMembers.Text = $"Mitglieder: {await ctx.Members.CountAsync(m => m.IsActive):N0} ({await ctx.Members.CountAsync():N0})";
StatusBusinessShares.Text = $"Geschäftsanteile: {await ctx.Members.Where(m => m.IsActive).SumAsync(m => m.BusinessShares):N0} ({await ctx.Members.SumAsync(m => m.BusinessShares):N0})"; StatusBusinessShares.Text = $"Geschäftsanteile: {await ctx.Members.Where(m => m.IsActive).SumAsync(m => m.BusinessShares):N0} ({await ctx.Members.SumAsync(m => m.BusinessShares):N0})";
@ -686,7 +685,7 @@ namespace Elwig.Windows {
AT_PlzDest? p = m.PostalDest.AtPlz; AT_PlzDest? p = m.PostalDest.AtPlz;
if (p != null) { if (p != null) {
PlzInput.Text = p.Plz.ToString(); PlzInput.Text = p.Plz.ToString();
ControlUtils.SelectComboBoxItem(OrtInput, o => (o as AT_PlzDest)?.Okz, p.Okz); ControlUtils.SelectItem(OrtInput, p);
} else { } else {
PlzInput.Text = null; PlzInput.Text = null;
OrtInput.SelectedItem = null; OrtInput.SelectedItem = null;
@ -728,7 +727,7 @@ namespace Elwig.Windows {
AT_PlzDest? b = billingAddr.PostalDest.AtPlz; AT_PlzDest? b = billingAddr.PostalDest.AtPlz;
if (b != null) { if (b != null) {
BillingPlzInput.Text = b.Plz.ToString(); BillingPlzInput.Text = b.Plz.ToString();
ControlUtils.SelectComboBoxItem(BillingOrtInput, o => (o as AT_PlzDest)?.Okz, b.Okz); ControlUtils.SelectItem(BillingOrtInput, b);
} }
} else { } else {
BillingNameInput.Text = ""; BillingNameInput.Text = "";
@ -741,8 +740,8 @@ namespace Elwig.Windows {
ExitDateInput.Text = (m.ExitDateString != null) ? string.Join(".", m.ExitDateString.Split("-").Reverse()) : null; ExitDateInput.Text = (m.ExitDateString != null) ? string.Join(".", m.ExitDateString.Split("-").Reverse()) : null;
BusinessSharesInput.Text = m.BusinessShares.ToString(); BusinessSharesInput.Text = m.BusinessShares.ToString();
AccountingNrInput.Text = m.AccountingNr; AccountingNrInput.Text = m.AccountingNr;
ControlUtils.SelectComboBoxItem(BranchInput, b => (b as Branch)?.ZwstId, m.ZwstId); ControlUtils.SelectItemWithPk(BranchInput, m.ZwstId);
ControlUtils.SelectComboBoxItem(DefaultKgInput, k => (k as AT_Kg)?.KgNr, m.DefaultKgNr); ControlUtils.SelectItemWithPk(DefaultKgInput, m.DefaultKgNr);
CommentInput.Text = m.Comment; CommentInput.Text = m.Comment;
ActiveInput.IsChecked = m.IsActive; ActiveInput.IsChecked = m.IsActive;
VollLieferantInput.IsChecked = m.IsVollLieferant; VollLieferantInput.IsChecked = m.IsVollLieferant;

View File

@ -28,7 +28,7 @@ namespace Elwig.Windows {
.ToListAsync()) .ToListAsync())
.OrderByDescending(o => o.SortKey) .OrderByDescending(o => o.SortKey)
.ThenBy(o => o.HkId); .ThenBy(o => o.HkId);
ControlUtils.RenewItemsSource(WineOrigins, origins, i => (i as WineOrigin)?.HkId, WineOrigins_SelectionChanged); ControlUtils.RenewItemsSource(WineOrigins, origins, WineOrigins_SelectionChanged);
if (WineOrigins.SelectedItem == null) { if (WineOrigins.SelectedItem == null) {
var hkid = await ctx.WbKgs var hkid = await ctx.WbKgs
.GroupBy(k => k.AtKg.Gem.WbGem!.HkId) .GroupBy(k => k.AtKg.Gem.WbGem!.HkId)
@ -36,14 +36,14 @@ namespace Elwig.Windows {
.OrderByDescending(g => g.Count()) .OrderByDescending(g => g.Count())
.Select(g => g.Key) .Select(g => g.Key)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
ControlUtils.SelectListBoxItem(WineOrigins, o => (o as WineOrigin)?.HkId, hkid); ControlUtils.SelectItemWithPk(WineOrigins, hkid);
} }
var gls = await ctx.WbGls var gls = await ctx.WbGls
.OrderBy(g => g.GlNr) .OrderBy(g => g.GlNr)
.Include("Kgs.Rds") .Include("Kgs.Rds")
.AsSplitQuery() .AsSplitQuery()
.ToListAsync(); .ToListAsync();
ControlUtils.RenewItemsSource(WbGls, gls, g => (g as WbGl)?.GlNr, WbGls_SelectionChanged, ControlUtils.RenewSourceDefault.First); ControlUtils.RenewItemsSource(WbGls, gls, WbGls_SelectionChanged, ControlUtils.RenewSourceDefault.First);
} }
UpdateWbGems(); UpdateWbGems();
UpdateWbKgs(); UpdateWbKgs();
@ -55,7 +55,7 @@ namespace Elwig.Windows {
WbGemsHeader.Content = "Gemeinden" + (WineOrigins.SelectedItem is WineOrigin o ? $" ({o.Name})" : ""); WbGemsHeader.Content = "Gemeinden" + (WineOrigins.SelectedItem is WineOrigin o ? $" ({o.Name})" : "");
var origin = (WineOrigins.SelectedItem as WineOrigin); var origin = (WineOrigins.SelectedItem as WineOrigin);
var gems = origin?.Gems.Select(g => g.AtGem).OrderBy(g => g.Name).ToList(); var gems = origin?.Gems.Select(g => g.AtGem).OrderBy(g => g.Name).ToList();
ControlUtils.RenewItemsSource(WbGems, gems, g => (g as AT_Gem)?.Gkz, WbGems_SelectionChanged); ControlUtils.RenewItemsSource(WbGems, gems, WbGems_SelectionChanged);
UpdateWbKgs(); UpdateWbKgs();
} }
@ -72,7 +72,7 @@ namespace Elwig.Windows {
kgs = null; kgs = null;
} }
var kgList = kgs?.OrderBy(k => k.WbKg?.Gl == null).ThenBy(k => k.WbKg?.GlNr).ThenBy(k => k.Name).ToList(); var kgList = kgs?.OrderBy(k => k.WbKg?.Gl == null).ThenBy(k => k.WbKg?.GlNr).ThenBy(k => k.Name).ToList();
ControlUtils.RenewItemsSource(WbKgs, kgList, k => (k as AT_Kg)?.KgNr, WbKgs_SelectionChanged); ControlUtils.RenewItemsSource(WbKgs, kgList, WbKgs_SelectionChanged);
} }
private void UpdateWbGlKgs() { private void UpdateWbGlKgs() {
@ -80,7 +80,7 @@ namespace Elwig.Windows {
if (WbGls.SelectedItem is WbGl g) { if (WbGls.SelectedItem is WbGl g) {
WbGlKgsHeader.Content += $" ({g.Name})"; WbGlKgsHeader.Content += $" ({g.Name})";
var kgs = g.Kgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToList(); var kgs = g.Kgs.Select(k => k.AtKg).OrderBy(k => k.Name).ToList();
ControlUtils.RenewItemsSource(WbGlKgs, kgs, k => (k as AT_Kg)?.KgNr, WbGlKgs_SelectionChanged); ControlUtils.RenewItemsSource(WbGlKgs, kgs, WbGlKgs_SelectionChanged);
} else { } else {
WbGlKgs.ItemsSource = null; WbGlKgs.ItemsSource = null;
} }
@ -122,7 +122,7 @@ namespace Elwig.Windows {
if (WbGlKgs.SelectedItem is AT_Kg k) { if (WbGlKgs.SelectedItem is AT_Kg k) {
WbRdsHeader.Content += $" ({k.Name})"; WbRdsHeader.Content += $" ({k.Name})";
var rds = k.WbKg?.Rds.OrderBy(r => r.Name).ToList(); var rds = k.WbKg?.Rds.OrderBy(r => r.Name).ToList();
ControlUtils.RenewItemsSource(WbRds, rds, k => (k as AT_Kg)?.KgNr); ControlUtils.RenewItemsSource(WbRds, rds);
} else { } else {
WbRds.ItemsSource = null; WbRds.ItemsSource = null;
} }
@ -145,9 +145,9 @@ namespace Elwig.Windows {
UpdateWbRds(); UpdateWbRds();
if (!isUpdating && WbGlKgs.SelectedItem is AT_Kg k) { if (!isUpdating && WbGlKgs.SelectedItem is AT_Kg k) {
isUpdating = true; isUpdating = true;
ControlUtils.SelectListBoxItem(WineOrigins, o => (o as WineOrigin)?.HkId, k.Gem.WbGem?.HkId); ControlUtils.SelectItemWithPk(WineOrigins, k.Gem.WbGem?.HkId);
ControlUtils.SelectListBoxItem(WbGems, g => (g as AT_Gem)?.Gkz, k.Gkz); ControlUtils.SelectItemWithPk(WbGems, k.Gkz);
ControlUtils.SelectListBoxItem(WbKgs, k => (k as AT_Kg)?.KgNr, k.KgNr); ControlUtils.SelectItemWithPk(WbKgs, k.KgNr);
isUpdating = false; isUpdating = false;
} }
await UpdateStatusBar(); await UpdateStatusBar();
@ -157,8 +157,8 @@ namespace Elwig.Windows {
UpdateButtons(); UpdateButtons();
if (!isUpdating && WbKgs.SelectedItem is AT_Kg k && k.WbKg != null && ((WbGls.SelectedItem as WbGl)?.GlNr == k.WbKg?.GlNr || WbGls.SelectedItem == null)) { if (!isUpdating && WbKgs.SelectedItem is AT_Kg k && k.WbKg != null && ((WbGls.SelectedItem as WbGl)?.GlNr == k.WbKg?.GlNr || WbGls.SelectedItem == null)) {
isUpdating = true; isUpdating = true;
ControlUtils.SelectListBoxItem(WbGls, g => (g as WbGl)?.GlNr, k.WbKg?.GlNr); ControlUtils.SelectItemWithPk(WbGls, k.WbKg?.GlNr);
ControlUtils.SelectListBoxItem(WbGlKgs, k => (k as AT_Kg)?.KgNr, k.KgNr); ControlUtils.SelectItemWithPk(WbGlKgs, k.KgNr);
isUpdating = false; isUpdating = false;
} }
} }
@ -194,7 +194,7 @@ namespace Elwig.Windows {
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
} }
await App.HintContextChange(); await App.HintContextChange();
ControlUtils.SelectListBoxItem(WbGlKgs, kg => (kg as AT_Kg)?.KgNr, k.KgNr); ControlUtils.SelectItemWithPk(WbGlKgs, k.KgNr);
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; 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; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
@ -214,7 +214,7 @@ namespace Elwig.Windows {
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
} }
await App.HintContextChange(); await App.HintContextChange();
ControlUtils.SelectListBoxItem(WbKgs, kg => (kg as AT_Kg)?.KgNr, k.KgNr); ControlUtils.SelectItemWithPk(WbKgs, k.KgNr);
} catch (Exception exc) { } catch (Exception exc) {
await HintContextChange(); await HintContextChange();
var str = "Der Eintrag konnte nicht aus der Datenbank gelöscht werden!\n\n" + exc.Message; var str = "Der Eintrag konnte nicht aus der Datenbank gelöscht werden!\n\n" + exc.Message;
@ -226,8 +226,8 @@ namespace Elwig.Windows {
public void FocusKgNr(int kgnr) { public void FocusKgNr(int kgnr) {
using var ctx = new AppDbContext(); using var ctx = new AppDbContext();
var kg = ctx.Katastralgemeinden.Find(kgnr); var kg = ctx.Katastralgemeinden.Find(kgnr);
ControlUtils.SelectListBoxItem(WbGls, kg?.WbKg?.Gl, g => (g as WbGl)?.GlNr); ControlUtils.SelectItemWithPk(WbGls, kg?.WbKg?.GlNr);
ControlUtils.SelectListBoxItem(WbGlKgs, kg, k => (k as AT_Kg)?.KgNr); ControlUtils.SelectItemWithPk(WbGlKgs, kg?.KgNr);
WbGlKgs.Focus(); WbGlKgs.Focus();
WbGlKgs.ScrollIntoView(kg?.WbKg?.Gl); WbGlKgs.ScrollIntoView(kg?.WbKg?.Gl);
} }

View File

@ -42,7 +42,7 @@ namespace Elwig.Windows {
.Where(v => v.Year == Year) .Where(v => v.Year == Year)
.OrderBy(v => v.AvNr) .OrderBy(v => v.AvNr)
.Include(v => v.Season.Currency) .Include(v => v.Season.Currency)
.ToListAsync(), v => (v as PaymentVar)?.AvNr); .ToListAsync());
await Update(); await Update();
} }
@ -207,7 +207,7 @@ namespace Elwig.Windows {
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
await App.HintContextChange(); await App.HintContextChange();
ControlUtils.SelectListBoxItem(PaymentVariantList, v, v => (v as PaymentVar)?.AvNr); ControlUtils.SelectItem(PaymentVariantList, v);
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; 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; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;
@ -232,7 +232,7 @@ namespace Elwig.Windows {
await ctx.SaveChangesAsync(); await ctx.SaveChangesAsync();
await App.HintContextChange(); await App.HintContextChange();
ControlUtils.SelectListBoxItem(PaymentVariantList, n, v => (v as PaymentVar)?.AvNr); ControlUtils.SelectItem(PaymentVariantList, n);
} catch (Exception exc) { } catch (Exception exc) {
var str = "Der Eintrag konnte nicht in der Datenbank aktualisiert werden!\n\n" + exc.Message; 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; if (exc.InnerException != null) str += "\n\n" + exc.InnerException.Message;