ControlUtils: Cleanup SelectItem() method and use accordingly
This commit is contained in:
@ -288,7 +288,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void InitInputs() {
|
||||
ControlUtils.SelectComboBoxItem(BranchInput, i => (i as Branch)?.ZwstId, App.ZwstId);
|
||||
ControlUtils.SelectItemWithPk(BranchInput, App.ZwstId);
|
||||
OnSecondPassed(null, null);
|
||||
UpdateLsNr().GetAwaiter().GetResult();
|
||||
InitialInputs();
|
||||
@ -646,7 +646,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
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);
|
||||
await RefreshDeliveryParts();
|
||||
|
||||
@ -795,21 +795,21 @@ namespace Elwig.Windows {
|
||||
await RefreshDeliveryList();
|
||||
var d = DeliveryList.SelectedItem as Delivery;
|
||||
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(BranchInput, await Context.Branches.OrderBy(b => b.Name).ToListAsync(), i => (i as Branch)?.ZwstId);
|
||||
ControlUtils.RenewItemsSource(WineVarietyInput, await Context.WineVarieties.OrderBy(v => v.Name).ToListAsync(), i => (i as WineVar)?.SortId);
|
||||
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());
|
||||
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();
|
||||
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();
|
||||
cultList.Insert(0, new NullItem(""));
|
||||
ControlUtils.RenewItemsSource(CultivationInput, cultList, i => (i as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(WineQualityLevelInput, await Context.WineQualityLevels.ToListAsync(), i => (i as WineQualLevel)?.QualId);
|
||||
ControlUtils.RenewItemsSource(ModifiersInput, await Context.Modifiers.Where(m => m.Year == y).OrderBy(m => m.Ordering).ToListAsync(), i => (i as Modifier)?.ModId);
|
||||
ControlUtils.RenewItemsSource(WineOriginInput, (await Context.WineOrigins.ToListAsync()).OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId), i => (i as WineOrigin)?.HkId);
|
||||
ControlUtils.RenewItemsSource(CultivationInput, cultList, null, ControlUtils.RenewSourceDefault.First);
|
||||
ControlUtils.RenewItemsSource(WineQualityLevelInput, await Context.WineQualityLevels.ToListAsync());
|
||||
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));
|
||||
var kgList = await Context.WbKgs.Select(k => k.AtKg).OrderBy(k => k.Name).Cast<object>().ToListAsync();
|
||||
kgList.Insert(0, new NullItem());
|
||||
ControlUtils.RenewItemsSource(WineKgInput, kgList, i => (i as AT_Kg)?.KgNr);
|
||||
ControlUtils.RenewItemsSource(WineKgInput, kgList);
|
||||
UpdateRdInput();
|
||||
if (IsCreating) await UpdateLsNr();
|
||||
|
||||
@ -826,10 +826,10 @@ namespace Elwig.Windows {
|
||||
|
||||
private async Task RefreshDeliveryParts() {
|
||||
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(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(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(), DeliveryPartList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@ -854,7 +854,7 @@ namespace Elwig.Windows {
|
||||
ClearDefaultValues();
|
||||
|
||||
MgNrInput.Text = d.MgNr.ToString();
|
||||
ControlUtils.SelectComboBoxItem(BranchInput, i => (i as Branch)?.ZwstId, d.ZwstId);
|
||||
ControlUtils.SelectItemWithPk(BranchInput, d.ZwstId);
|
||||
LsNrInput.Text = d.LsNr;
|
||||
DateInput.Text = d.Date.ToString("dd.MM.yyyy");
|
||||
TimeInput.Text = d.Time?.ToString("HH:mm") ?? "";
|
||||
@ -877,17 +877,17 @@ namespace Elwig.Windows {
|
||||
ClearDefaultValues();
|
||||
|
||||
SortIdInput.Text = p?.SortId ?? "";
|
||||
ControlUtils.SelectComboBoxItem(AttributeInput, p?.Attribute, i => (i as WineAttr)?.AttrId);
|
||||
ControlUtils.SelectComboBoxItem(CultivationInput, p?.Cultivation, i => (i as WineCult)?.CultId);
|
||||
ControlUtils.SelectItemWithPk(AttributeInput, p?.AttrId);
|
||||
ControlUtils.SelectItemWithPk(CultivationInput, p?.CultId);
|
||||
GradationKmwInput.Text = (p != null) ? $"{p.Kmw:N1}" : "";
|
||||
ControlUtils.SelectComboBoxItem(WineQualityLevelInput, q => (q as WineQualLevel)?.QualId, p?.QualId);
|
||||
ControlUtils.SelectComboBoxItem(WineKgInput, k => (k as AT_Kg)?.KgNr, p?.KgNr);
|
||||
ControlUtils.SelectComboBoxItem(WineRdInput, r => (r as WbRd)?.RdNr, p?.RdNr);
|
||||
ControlUtils.SelectComboBoxItem(WineOriginInput, r => (r as WineOrigin)?.HkId, p?.HkId);
|
||||
ControlUtils.SelectItemWithPk(WineQualityLevelInput, p?.QualId);
|
||||
ControlUtils.SelectItemWithPk(WineKgInput, p?.KgNr);
|
||||
ControlUtils.SelectItemWithPk(WineRdInput, p?.KgNr, p?.RdNr);
|
||||
ControlUtils.SelectItemWithPk(WineOriginInput, p?.HkId);
|
||||
WeightInput.Text = (p != null) ? $"{p.Weight:N0}" : "";
|
||||
ManualWeighingInput.IsChecked = p?.IsManualWeighing ?? 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 ?? "";
|
||||
TemperatureInput.Text = (p != null && p.Temperature != null) ? $"{p.Temperature: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) {
|
||||
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) {
|
||||
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) {
|
||||
@ -1134,8 +1134,8 @@ namespace Elwig.Windows {
|
||||
UnsetDefaultValue(WineKgInput);
|
||||
WineKgInput.SelectedIndex = 0;
|
||||
} else {
|
||||
SetDefaultValue(WineKgInput, m.DefaultKg);
|
||||
WineKgInput.SelectedItem = m.DefaultKg;
|
||||
ControlUtils.SelectItemWithPk(WineKgInput, m.DefaultKgNr);
|
||||
SetDefaultValue(WineKgInput);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1155,7 +1155,7 @@ namespace Elwig.Windows {
|
||||
await RefreshDeliveryList();
|
||||
await RefreshDeliveryParts();
|
||||
NewDeliveryPartButton.Cursor = null;
|
||||
DeliveryList.SelectedItem = p?.Delivery;
|
||||
ControlUtils.SelectItem(DeliveryList, p?.Delivery);
|
||||
DeliveryPartList.SelectedItem = null;
|
||||
RefreshInputs();
|
||||
InitialInputs();
|
||||
@ -1201,8 +1201,8 @@ namespace Elwig.Windows {
|
||||
|
||||
var attrList = await Context.WineAttributes.OrderBy(a => a.Name).Cast<object>().ToListAsync();
|
||||
attrList.Insert(0, new NullItem(""));
|
||||
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, 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(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());
|
||||
if (DeliveryList.SelectedItem is not Delivery d) {
|
||||
// switch away from creating mode
|
||||
IsCreating = false;
|
||||
@ -1220,7 +1220,7 @@ namespace Elwig.Windows {
|
||||
} else {
|
||||
// switch to last delivery part
|
||||
DeliveryPartList.IsEnabled = true;
|
||||
DeliveryPartList.SelectedItem = d.FilteredParts.Last();
|
||||
ControlUtils.SelectItem(DeliveryPartList, d.FilteredParts.Last());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1229,8 +1229,8 @@ namespace Elwig.Windows {
|
||||
SearchInput.Text = "";
|
||||
var attrList = await Context.WineAttributes.Where(a => a.IsActive).OrderBy(a => a.Name).Cast<object>().ToListAsync();
|
||||
attrList.Insert(0, new NullItem(""));
|
||||
ControlUtils.RenewItemsSource(AttributeInput, attrList, i => (i as WineAttr)?.AttrId, 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(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());
|
||||
IsCreating = true;
|
||||
DeliveryList.IsEnabled = false;
|
||||
DeliveryPartList.IsEnabled = false;
|
||||
@ -1253,8 +1253,8 @@ namespace Elwig.Windows {
|
||||
Mouse.OverrideCursor = Cursors.AppStarting;
|
||||
ClearOriginalValues();
|
||||
if (res >= p.Weight) {
|
||||
ControlUtils.SelectComboBoxItem(WineQualityLevelInput, q => (q as WineQualLevel)?.QualId, "WEI");
|
||||
ControlUtils.SelectComboBoxItem(WineOriginInput, o => (o as WineOrigin)?.HkId, "OEST");
|
||||
ControlUtils.SelectItemWithPk(WineQualityLevelInput, "WEI");
|
||||
ControlUtils.SelectItemWithPk(WineOriginInput, "OEST");
|
||||
p.QualId = "WEI";
|
||||
p.HkId = "OEST";
|
||||
entry1 = Context.Update(p);
|
||||
@ -1449,7 +1449,7 @@ namespace Elwig.Windows {
|
||||
|
||||
Mouse.OverrideCursor = null;
|
||||
await RefreshDeliveryList();
|
||||
DeliveryList.SelectedItem = d;
|
||||
ControlUtils.SelectItem(DeliveryList, d);
|
||||
} catch (Exception exc) {
|
||||
if (entry != null) {
|
||||
entry.State = EntityState.Detached;
|
||||
@ -1612,10 +1612,10 @@ namespace Elwig.Windows {
|
||||
private void UpdateWineVariety(bool valid) {
|
||||
if (valid) {
|
||||
var text = SortIdInput.Text;
|
||||
WineVarietyInput.SelectedItem = Context.WineVarieties.Find(text[0..2]);
|
||||
ControlUtils.SelectItemWithPk(WineVarietyInput, text[0..2]);
|
||||
if (text.Length >= 3) {
|
||||
ControlUtils.SelectComboBoxItem(AttributeInput, Context.WineAttributes.Find(text[2..]), a => (a as WineAttr)?.AttrId);
|
||||
ControlUtils.SelectComboBoxItem(CultivationInput, Context.WineCultivations.Find(text[2..]), i => (i as WineCult)?.CultId);
|
||||
ControlUtils.SelectItemWithPk(AttributeInput, text[2..]);
|
||||
ControlUtils.SelectItemWithPk(CultivationInput, text[2..]);
|
||||
SortIdInput.Text = text[0..2];
|
||||
}
|
||||
} else {
|
||||
@ -1649,7 +1649,7 @@ namespace Elwig.Windows {
|
||||
var qual = Context.GetWineQualityLevel(kmw).GetAwaiter().GetResult();
|
||||
SetDefaultValue(WineQualityLevelInput, qual);
|
||||
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;
|
||||
while (o != null && o.Level > qual.OriginLevel) o = o.Parent;
|
||||
SetDefaultValue(WineOriginInput, o);
|
||||
WineOriginInput.SelectedItem = o;
|
||||
ControlUtils.SelectItem(WineOriginInput, o);
|
||||
}
|
||||
|
||||
private void WineQualityLevelInput_SelectionChanged(object sender, SelectionChangedEventArgs evt) {
|
||||
@ -1756,7 +1756,7 @@ namespace Elwig.Windows {
|
||||
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());
|
||||
ControlUtils.RenewItemsSource(WineRdInput, list, i => ((i as WbRd)?.KgNr, (i as WbRd)?.RdNr));
|
||||
ControlUtils.RenewItemsSource(WineRdInput, list);
|
||||
if (WineRdInput.SelectedItem == null) WineRdInput.SelectedIndex = 0;
|
||||
WineRdInput.IsEnabled = (IsEditing || IsCreating) && list.Count > 1;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user