diff --git a/Elwig/Helpers/AppDbContext.cs b/Elwig/Helpers/AppDbContext.cs index bd13968..5cd372d 100644 --- a/Elwig/Helpers/AppDbContext.cs +++ b/Elwig/Helpers/AppDbContext.cs @@ -123,11 +123,17 @@ namespace Elwig.Helpers { } public async Task NextDId(int year) { - return await Deliveries.Where(d => d.Year == year).Select(d => d.DId).MaxAsync() + 1; + int c = 0; + (await Deliveries.Where(d => d.Year == year).Select(d => d.DId).ToListAsync()) + .ForEach(a => { if (a <= c + 10) c = a; }); + return c + 1; } public async Task NextDPNr(int year, int did) { - return await DeliveryParts.Where(p => p.Year == year && p.DId == did).Select(d => d.DPNr).MaxAsync() + 1; + int c = 0; + (await DeliveryParts.Where(p => p.Year == year && p.DId == did).Select(d => d.DPNr).ToListAsync()) + .ForEach(a => { if (a <= c + 10) c = a; }); + return c + 1; } public async Task GetWineQualityLevel(double kmw) { diff --git a/Elwig/Helpers/ControlUtils.cs b/Elwig/Helpers/ControlUtils.cs index d6da3e0..e6b295b 100644 --- a/Elwig/Helpers/ControlUtils.cs +++ b/Elwig/Helpers/ControlUtils.cs @@ -145,7 +145,7 @@ namespace Elwig.Helpers { selItem = source.Cast().FirstOrDefault(i => selectedId.Equals(getId(i))); if (source != null && selItem == null) { if ((def == RenewSourceDefault.IfOnly && source.Cast().Count() == 1) || def == RenewSourceDefault.First) { - selItem = source.Cast().First(); + selItem = source.Cast().FirstOrDefault(); } } if (handler != null && selItem != null) listBox.SelectionChanged -= handler; diff --git a/Elwig/Helpers/Utils.cs b/Elwig/Helpers/Utils.cs index 4ac0f5c..4cebd4d 100644 --- a/Elwig/Helpers/Utils.cs +++ b/Elwig/Helpers/Utils.cs @@ -12,6 +12,7 @@ using Elwig.Dialogs; namespace Elwig.Helpers { public static partial class Utils { + public static int CurrentYear => DateTime.Now.Year; public static int CurrentNextSeason => DateTime.Now.Year - (DateTime.Now.Month <= 3 ? 1 : 0); public static int CurrentLastSeason => DateTime.Now.Year - (DateTime.Now.Month <= 7 ? 1 : 0); public static DateTime Today => (DateTime.Now.Hour >= 3) ? DateTime.Today : DateTime.Today.AddDays(-1);