AreaComWindow: Fix wine cultivation null crash

This commit is contained in:
2024-02-29 13:03:00 +01:00
parent cc5396711d
commit cc72a8365e

View File

@ -170,6 +170,7 @@ namespace Elwig.Windows {
FbNrInput.Text = (await Context.NextFbNr()).ToString(); FbNrInput.Text = (await Context.NextFbNr()).ToString();
MgNrInput.Text = Member.MgNr.ToString(); MgNrInput.Text = Member.MgNr.ToString();
YearFromInput.Text = DateTime.Now.Year.ToString(); YearFromInput.Text = DateTime.Now.Year.ToString();
WineCultivationInput.SelectedIndex = 0;
SetDefaultValue(FbNrInput); SetDefaultValue(FbNrInput);
ValidateRequiredInputs(); ValidateRequiredInputs();
@ -181,7 +182,7 @@ namespace Elwig.Windows {
ControlUtils.RenewItemsSource(AreaComTypeInput, await Context.AreaCommitmentTypes.OrderBy(v => v.VtrgId).ToListAsync(), i => (i as AreaComType)?.VtrgId); ControlUtils.RenewItemsSource(AreaComTypeInput, await Context.AreaCommitmentTypes.OrderBy(v => v.VtrgId).ToListAsync(), i => (i as AreaComType)?.VtrgId);
var cultList = await Context.WineCultivations.OrderBy(c => c.Name).Cast<object>().ToListAsync(); var cultList = await Context.WineCultivations.OrderBy(c => c.Name).Cast<object>().ToListAsync();
cultList.Insert(0, new NullItem()); cultList.Insert(0, new NullItem());
ControlUtils.RenewItemsSource(WineCultivationInput, cultList, i => (i as WineCult)?.CultId); ControlUtils.RenewItemsSource(WineCultivationInput, cultList, i => (i as WineCult)?.CultId, null, ControlUtils.RenewSourceDefault.First);
await RefreshAreaCommitmentList(); await RefreshAreaCommitmentList();
} }
@ -233,7 +234,7 @@ namespace Elwig.Windows {
a.GstNr = GstNrInput.Text; a.GstNr = GstNrInput.Text;
a.Area = int.Parse(AreaInput.Text); a.Area = int.Parse(AreaInput.Text);
a.VtrgId = (AreaComTypeInput.SelectedItem as AreaComType)!.VtrgId; a.VtrgId = (AreaComTypeInput.SelectedItem as AreaComType)!.VtrgId;
a.CultId = (WineCultivationInput.SelectedItem as WineCult)!.CultId; a.CultId = (WineCultivationInput.SelectedItem as WineCult)?.CultId;
a.Comment = (CommentInput.Text == "") ? null : CommentInput.Text; a.Comment = (CommentInput.Text == "") ? null : CommentInput.Text;
EntityEntry<AreaCom>? tr = null; EntityEntry<AreaCom>? tr = null;