diff --git a/Elwig/Services/AreaComService.cs b/Elwig/Services/AreaComService.cs index 8e4b3d2..994a7e5 100644 --- a/Elwig/Services/AreaComService.cs +++ b/Elwig/Services/AreaComService.cs @@ -162,20 +162,13 @@ namespace Elwig.Services { AddToolTipCell(grid, max == null ? "" : $"{max:N0} kg", row, 4, 1, bold, true); } - public static async Task<(string, Grid)> GenerateToolTip(IQueryable areaComs, int maxKgPerHa) { - var grid = new Grid(); - grid.ColumnDefinitions.Add(new() { Width = new(10) }); - grid.ColumnDefinitions.Add(new() { Width = new(60) }); - grid.ColumnDefinitions.Add(new() { Width = new(80) }); - grid.ColumnDefinitions.Add(new() { Width = new(80) }); - grid.ColumnDefinitions.Add(new() { Width = new(80) }); - AddToolTipCell(grid, "Lieferpflicht", 0, 3, 1, false, false, true); - AddToolTipCell(grid, "Lieferrecht", 0, 4, 1, false, false, true); + public static async Task<(string, (string?, string?, int, int?, int?)[])> GenerateToolTipData(IQueryable areaComs, int maxKgPerHa) { + var grid = new List<(string?, string?, int, int?, int?)>(); var text = "-"; var area = await areaComs.SumAsync(p => p.Area); text = $"{area:N0} m²"; - AddToolTipRow(grid, 1, "Geb. Fläche", null, area, null, null); + grid.Add(("Geb. Fläche", null, area, null, null)); if (await areaComs.AnyAsync()) { var attrGroups = await areaComs @@ -221,24 +214,38 @@ namespace Elwig.Services { .ThenBy(g => g.SortId) .ToListAsync(); - int rowNum = 2; if (noAttr.Count > 0) { - rowNum++; - AddToolTipRow(grid, rowNum++, null, null, noAttr.Sum(g => g.Area), noAttr.Sum(g => g.Min), noAttr.Sum(g => g.Max)); + grid.Add((null, null, noAttr.Sum(g => g.Area), noAttr.Sum(g => g.Min), noAttr.Sum(g => g.Max))); foreach (var g in noAttr) { - AddToolTipRow(grid, rowNum++, null, g.SortId, g.Area, g.Min, g.Max); + grid.Add((null, g.SortId, g.Area, g.Min, g.Max)); } } foreach (var attrG in attrGroups) { - rowNum++; - AddToolTipRow(grid, rowNum++, attrG.Attr, null, attrG.Area, attrG.Min, attrG.Max); + grid.Add((attrG.Attr, null, attrG.Area, attrG.Min, attrG.Max)); foreach (var g in groups.Where(g => g.Attr == attrG.Attr).OrderByDescending(g => g.Area).ThenBy(g => g.SortId)) { - AddToolTipRow(grid, rowNum++, null, g.SortId, g.Area, g.Min, g.Max); + grid.Add((null, g.SortId, g.Area, g.Min, g.Max)); } } } - return (text, grid); + return (text, grid.ToArray()); + } + + public static Grid GenerateToolTip((string?, string?, int, int?, int?)[] data) { + var grid = new Grid(); + grid.ColumnDefinitions.Add(new() { Width = new(10) }); + grid.ColumnDefinitions.Add(new() { Width = new(60) }); + grid.ColumnDefinitions.Add(new() { Width = new(80) }); + grid.ColumnDefinitions.Add(new() { Width = new(80) }); + grid.ColumnDefinitions.Add(new() { Width = new(80) }); + AddToolTipCell(grid, "Lieferpflicht", 0, 3, 1, false, false, true); + AddToolTipCell(grid, "Lieferrecht", 0, 4, 1, false, false, true); + int rowNum = 1; + foreach (var row in data) { + AddToolTipRow(grid, rowNum++, row.Item1, row.Item2, row.Item3, row.Item4, row.Item5); + if (rowNum == 2) rowNum++; + } + return grid; } } } diff --git a/Elwig/Services/DeliveryService.cs b/Elwig/Services/DeliveryService.cs index 20dd656..babe4f9 100644 --- a/Elwig/Services/DeliveryService.cs +++ b/Elwig/Services/DeliveryService.cs @@ -721,36 +721,22 @@ namespace Elwig.Services { AddToolTipCell(grid, $"{max:N1}°", row, 4, 1, bold, true); } - public static async Task<(string WeightText, Grid WeightGrid, string GradationText, Grid GradationGrid)> GenerateToolTip(IQueryable deliveryParts) { - var wGrid = new Grid(); - wGrid.ColumnDefinitions.Add(new() { Width = new(10) }); - wGrid.ColumnDefinitions.Add(new() { Width = new(60) }); - wGrid.ColumnDefinitions.Add(new() { Width = new(80) }); - wGrid.ColumnDefinitions.Add(new() { Width = new(50) }); - wGrid.ColumnDefinitions.Add(new() { Width = new(50) }); + public static async Task<(string WeightText, (string?, string?, int, int?, int)[] WeightGrid, string GradationText, (string?, string?, double, double, double)[] GradationGrid)> GenerateToolTipData(IQueryable deliveryParts) { + var wGrid = new List<(string?, string?, int, int?, int)>(); var wText = "-"; - - var gGrid = new Grid(); - gGrid.ColumnDefinitions.Add(new() { Width = new(10) }); - gGrid.ColumnDefinitions.Add(new() { Width = new(60) }); - gGrid.ColumnDefinitions.Add(new() { Width = new(35) }); - gGrid.ColumnDefinitions.Add(new() { Width = new(35) }); - gGrid.ColumnDefinitions.Add(new() { Width = new(35) }); - AddToolTipCell(gGrid, "Min.", 0, 2, 1, false, false, true); - AddToolTipCell(gGrid, "⌀", 0, 3, 1, false, false, true); - AddToolTipCell(gGrid, "Max.", 0, 4, 1, false, false, true); + var gGrid = new List<(string?, string?, double, double, double)>(); var gText = "-"; var weight = await deliveryParts.SumAsync(p => p.Weight); wText = $"{weight:N0} kg"; - AddWeightToolTipRow(wGrid, 0, "Gewicht", null, weight, null, weight); + wGrid.Add(("Gewicht", null, weight, null, weight)); if (await deliveryParts.AnyAsync()) { var kmwMin = await deliveryParts.MinAsync(p => p.Kmw); var kmwAvg = Utils.AggregateDeliveryPartsKmw(deliveryParts); var kmwMax = await deliveryParts.MaxAsync(p => p.Kmw); gText = $"{kmwMin:N1}° / {kmwAvg:N1}° / {kmwMax:N1}°"; - AddGradationToolTipRow(gGrid, 1, "Gradation", null, kmwMin, kmwAvg, kmwMax); + gGrid.Add(("Gradation", null, kmwMin, kmwAvg, kmwMax)); var attrGroups = await deliveryParts .GroupBy(p => new { Attr = p.Attribute!.Name, Cult = p.Cultivation!.Name }) @@ -799,22 +785,18 @@ namespace Elwig.Services { .ThenBy(g => g.SortId) .ToListAsync(); - int rowNum = 1; foreach (var attrG in attrGroups) { - rowNum++; var name = attrG.Attr == null && attrG.Cult == null ? null : attrG.Attr + (attrG.Attr != null && attrG.Cult != null ? " / " : "") + attrG.Cult; - AddWeightToolTipRow(wGrid, rowNum++, name, null, attrG.Weight, attrG.Weight, weight); + wGrid.Add((name, null, attrG.Weight, attrG.Weight, weight)); foreach (var g in groups.Where(g => g.Attr == attrG.Attr && g.Cult == attrG.Cult).OrderByDescending(g => g.Weight).ThenBy(g => g.SortId)) { - AddWeightToolTipRow(wGrid, rowNum++, null, g.SortId, g.Weight, attrG.Weight, weight); + wGrid.Add((null, g.SortId, g.Weight, attrG.Weight, weight)); } } - rowNum = 2; foreach (var attrG in attrGroups) { - rowNum++; var name = attrG.Attr == null && attrG.Cult == null ? null : attrG.Attr + (attrG.Attr != null && attrG.Cult != null ? " / " : "") + attrG.Cult; - AddGradationToolTipRow(gGrid, rowNum++, name, null, attrG.Min, attrG.Avg, attrG.Max); + gGrid.Add((name, null, attrG.Min, attrG.Avg, attrG.Max)); foreach (var g in groups.Where(g => g.Attr == attrG.Attr && g.Cult == attrG.Cult).OrderByDescending(g => g.Avg).ThenBy(g => g.SortId)) { - AddGradationToolTipRow(gGrid, rowNum++, null, g.SortId, g.Min, g.Avg, g.Max); + gGrid.Add((null, g.SortId, g.Min, g.Avg, g.Max)); } } @@ -836,7 +818,38 @@ namespace Elwig.Services { } } - return (wText, wGrid, gText, gGrid); + return (wText, wGrid.ToArray(), gText, gGrid.ToArray()); + } + + public static (Grid WeightGrid, Grid GradationGrid) GenerateToolTip((string?, string?, int, int?, int)[] weightData, (string?, string?, double, double, double)[] gradationData) { + var wGrid = new Grid(); + wGrid.ColumnDefinitions.Add(new() { Width = new(10) }); + wGrid.ColumnDefinitions.Add(new() { Width = new(60) }); + wGrid.ColumnDefinitions.Add(new() { Width = new(80) }); + wGrid.ColumnDefinitions.Add(new() { Width = new(50) }); + wGrid.ColumnDefinitions.Add(new() { Width = new(50) }); + int rowNum = 0; + foreach (var row in weightData) { + AddWeightToolTipRow(wGrid, rowNum++, row.Item1, row.Item2, row.Item3, row.Item4, row.Item5); + if (rowNum == 1) rowNum++; + } + + var gGrid = new Grid(); + gGrid.ColumnDefinitions.Add(new() { Width = new(10) }); + gGrid.ColumnDefinitions.Add(new() { Width = new(60) }); + gGrid.ColumnDefinitions.Add(new() { Width = new(35) }); + gGrid.ColumnDefinitions.Add(new() { Width = new(35) }); + gGrid.ColumnDefinitions.Add(new() { Width = new(35) }); + AddToolTipCell(gGrid, "Min.", 0, 2, 1, false, false, true); + AddToolTipCell(gGrid, "⌀", 0, 3, 1, false, false, true); + AddToolTipCell(gGrid, "Max.", 0, 4, 1, false, false, true); + rowNum = 1; + foreach (var row in gradationData) { + AddGradationToolTipRow(gGrid, rowNum++, row.Item1, row.Item2, row.Item3, row.Item4, row.Item5); + if (rowNum == 2) rowNum++; + } + + return (wGrid, gGrid); } } } diff --git a/Elwig/Services/MemberService.cs b/Elwig/Services/MemberService.cs index c0febb1..94bb31e 100644 --- a/Elwig/Services/MemberService.cs +++ b/Elwig/Services/MemberService.cs @@ -137,30 +137,26 @@ namespace Elwig.Services { vm.ContactViaPost = m.ContactViaPost; vm.ContactViaEmail = m.ContactViaEmail; - vm.StatusDeliveriesLastSeasonInfo = "letzte Saison"; - vm.StatusDeliveriesLastSeason = "-"; + vm.StatusDeliveriesLastSeasonInfo = $"{Utils.CurrentLastSeason - 1}"; + vm.StatusDeliveriesLastSeason = "..."; vm.StatusDeliveriesLastSeasonToolTip = null; - vm.StatusDeliveriesThisSeasonInfo = "aktuelle Saison"; - vm.StatusDeliveriesThisSeason = "-"; + vm.StatusDeliveriesThisSeasonInfo = $"{Utils.CurrentLastSeason}"; + vm.StatusDeliveriesThisSeason = "..."; vm.StatusDeliveriesThisSeasonToolTip = null; - vm.StatusAreaCommitmentInfo = "aktuelle Saison"; - vm.StatusAreaCommitment = "-"; + vm.StatusAreaCommitmentInfo = $"{Utils.CurrentLastSeason}"; + vm.StatusAreaCommitment = "..."; vm.StatusAreaCommitmentToolTip = null; - App.MainDispatcher.BeginInvoke(async () => { + Utils.RunBackground("Mitgliederdaten laden", async () => { using var ctx = new AppDbContext(); var d1 = ctx.Deliveries.Where(d => d.Year == Utils.CurrentLastSeason - 1 && d.MgNr == m.MgNr); - var (_, d1Grid, _, _) = await DeliveryService.GenerateToolTip(d1.SelectMany(d => d.Parts)); - vm.StatusDeliveriesLastSeasonInfo = $"{Utils.CurrentLastSeason - 1}"; - vm.StatusDeliveriesLastSeason = $"{await d1.CountAsync():N0} ({await d1.SumAsync(d => d.Parts.Count):N0}), {await d1.SelectMany(d => d.Parts).SumAsync(p => p.Weight):N0} kg"; - vm.StatusDeliveriesLastSeasonToolTip = d1Grid; + var (_, d1GridData, _, _) = await DeliveryService.GenerateToolTipData(d1.SelectMany(d => d.Parts)); + var textLast = $"{await d1.CountAsync():N0} ({await d1.SumAsync(d => d.Parts.Count):N0}), {await d1.SelectMany(d => d.Parts).SumAsync(p => p.Weight):N0} kg"; var d2 = ctx.Deliveries.Where(d => d.Year == Utils.CurrentLastSeason && d.MgNr == m.MgNr); - var (_, d2Grid, _, _) = await DeliveryService.GenerateToolTip(d2.SelectMany(d => d.Parts)); - vm.StatusDeliveriesThisSeasonInfo = $"{Utils.CurrentLastSeason}"; - vm.StatusDeliveriesThisSeason = $"{await d2.CountAsync():N0} ({await d2.SumAsync(d => d.Parts.Count):N0}), {await d2.SelectMany(d => d.Parts).SumAsync(p => p.Weight):N0} kg"; - vm.StatusDeliveriesThisSeasonToolTip = d2Grid; + var (_, d2GridData, _, _) = await DeliveryService.GenerateToolTipData(d2.SelectMany(d => d.Parts)); + var textThis = $"{await d2.CountAsync():N0} ({await d2.SumAsync(d => d.Parts.Count):N0}), {await d2.SelectMany(d => d.Parts).SumAsync(p => p.Weight):N0} kg"; var c = m.ActiveAreaCommitments(ctx, Utils.CurrentLastSeason); int maxKgPerHa = 10_000; @@ -168,10 +164,22 @@ namespace Elwig.Services { var s = await ctx.Seasons.FindAsync(await ctx.Seasons.MaxAsync(s => s.Year)); if (s != null) maxKgPerHa = s.MaxKgPerHa; } catch { } - var (text, grid) = await AreaComService.GenerateToolTip(c, maxKgPerHa); - vm.StatusAreaCommitmentInfo = $"{Utils.CurrentLastSeason}"; - vm.StatusAreaCommitment = text; - vm.StatusAreaCommitmentToolTip = grid; + var (text, gridData) = await AreaComService.GenerateToolTipData(c, maxKgPerHa); + + await App.MainDispatcher.BeginInvoke(() => { + var (d1Grid, _) = DeliveryService.GenerateToolTip(d1GridData, []); + var (d2Grid, _) = DeliveryService.GenerateToolTip(d2GridData, []); + var grid = AreaComService.GenerateToolTip(gridData); + vm.StatusDeliveriesLastSeasonInfo = $"{Utils.CurrentLastSeason - 1}"; + vm.StatusDeliveriesLastSeason = textLast; + vm.StatusDeliveriesLastSeasonToolTip = d1Grid; + vm.StatusDeliveriesThisSeasonInfo = $"{Utils.CurrentLastSeason}"; + vm.StatusDeliveriesThisSeason = textThis; + vm.StatusDeliveriesThisSeasonToolTip = d2Grid; + vm.StatusAreaCommitmentInfo = $"{Utils.CurrentLastSeason}"; + vm.StatusAreaCommitment = text; + vm.StatusAreaCommitmentToolTip = grid; + }); }); vm.MemberHasEmail = m.EmailAddresses.Count > 0; diff --git a/Elwig/Windows/AreaComAdminWindow.xaml.cs b/Elwig/Windows/AreaComAdminWindow.xaml.cs index 11b3909..77c97a4 100644 --- a/Elwig/Windows/AreaComAdminWindow.xaml.cs +++ b/Elwig/Windows/AreaComAdminWindow.xaml.cs @@ -79,9 +79,9 @@ namespace Elwig.Windows { if (filter.Count == 0) { ViewModel.StatusAreaCommitments = $"{await areaComQuery.CountAsync():N0}"; var s = await ctx.Seasons.FindAsync(await ctx.Seasons.MaxAsync(s => s.Year)); - var (text, grid) = await AreaComService.GenerateToolTip(areaComQuery, s?.MaxKgPerHa ?? 10_000); + var (text, gridData) = await AreaComService.GenerateToolTipData(areaComQuery, s?.MaxKgPerHa ?? 10_000); ViewModel.StatusArea = text; - ViewModel.StatusAreaToolTip = grid; + ViewModel.StatusAreaToolTip = AreaComService.GenerateToolTip(gridData); } else { ViewModel.StatusAreaCommitments = $"{areaComs.Count:N0}"; ViewModel.StatusArea = $"{areaComs.Select(a => a.Area).Sum():N0} m²"; diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml.cs b/Elwig/Windows/DeliveryAdminWindow.xaml.cs index f4ea414..c7a989b 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml.cs +++ b/Elwig/Windows/DeliveryAdminWindow.xaml.cs @@ -394,8 +394,10 @@ namespace Elwig.Windows { ViewModel.StatusDeliveries = $"{deliveries.Count} ({await deliveryParts.CountAsync()})"; var varieties = await deliveryParts.Select(d => d.SortId).Distinct().ToListAsync(); ViewModel.StatusVarieties = $"{varieties.Count}" + (varieties.Count > 0 && varieties.Count <= 10 ? $" ({string.Join(", ", varieties)})" : ""); - (ViewModel.StatusWeight, ViewModel.StatusWeightToolTip, - ViewModel.StatusGradation, ViewModel.StatusGradationToolTip) = await DeliveryService.GenerateToolTip(deliveryParts); + var (wText, wData, gText, gData) = await DeliveryService.GenerateToolTipData(deliveryParts); + ViewModel.StatusWeight = wText; + ViewModel.StatusGradation = gText; + (ViewModel.StatusWeightToolTip, ViewModel.StatusGradationToolTip) = DeliveryService.GenerateToolTip(wData, gData); } else { ViewModel.StatusVarieties = "-"; ViewModel.StatusWeight = "-";