From 190ef8287239ff6906de5842b3789f7b22748345 Mon Sep 17 00:00:00 2001 From: Lorenz Stechauner Date: Fri, 23 Feb 2024 12:54:09 +0100 Subject: [PATCH] [#34] DeliveryAdminWindow: Show cultivation beside attribute --- Elwig/Windows/DeliveryAdminWindow.xaml | 4 +- Elwig/Windows/DeliveryAdminWindow.xaml.cs | 53 ++++++++++++++++------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml b/Elwig/Windows/DeliveryAdminWindow.xaml index 8f5e97f..f013e0a 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml +++ b/Elwig/Windows/DeliveryAdminWindow.xaml @@ -107,6 +107,7 @@ Saison: z.B. 2020, >2015, 2017-2019, <2005, 2019-, ... Zweigstelle: z.B. musterort, ... Attribut: z.B. kabinett, !kabinett (alle außer kabinett), ... + Bewirtschaftung: z.B. bio, !kip (alle außer KIP), ... Datum: z.B. 1.9., 15.9.-10.10., -15.10.2020, ... Uhrzeit: z.B. 06:00-08:00, 18:00-, ... Freitext: z.B. Lieferscheinnummern, Anmerkung, "quw" (sucht nach dem Text "quw") @@ -415,7 +416,8 @@ - + + diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml.cs b/Elwig/Windows/DeliveryAdminWindow.xaml.cs index ca22af4..9f70c8d 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml.cs +++ b/Elwig/Windows/DeliveryAdminWindow.xaml.cs @@ -118,7 +118,7 @@ namespace Elwig.Windows { NewDeliveryButton_Click(null, null); if ((Context.Seasons.Find(Utils.CurrentYear)) == null) { MessageBox.Show("Die Saison für das aktuelle Jahr wurde noch nicht erstellt. Neue Lieferungen können nicht abgespeichert werden.", - "Saison noch nicht erstellt", MessageBoxButton.OK, MessageBoxImage.Error); + "Saison noch nicht erstellt", MessageBoxButton.OK, MessageBoxImage.Warning); } } } @@ -335,6 +335,8 @@ namespace Elwig.Windows { var filterZwst = new List(); var filterAttr = new List(); var filterNotAttr = new List(); + var filterCult = new List(); + var filterNotCult = new List(); var filterDate = new List<(string?, string?)>(); var filterTime = new List<(string?, string?)>(); int filterYearGt = 0, filterYearLt = 0; @@ -347,7 +349,8 @@ namespace Elwig.Windows { var qual = await Context.WineQualityLevels.Where(q => !q.IsPredicate).ToDictionaryAsync(q => q.QualId, q => q); var mgnr = await Context.Members.ToDictionaryAsync(m => m.MgNr.ToString(), m => m); var zwst = await Context.Branches.ToDictionaryAsync(b => b.Name.ToLower().Split(" ")[0], b => b); - var attr = await Context.WineAttributes.ToDictionaryAsync(a => a.Name.ToLower().Split(" ")[0], a => a); + var attr = await Context.WineAttributes.ToDictionaryAsync(a => a.Name.ToLower().Split(' ')[0], a => a); + var cult = await Context.WineCultivations.ToDictionaryAsync(c => c.Name.ToLower().Split(' ')[0], c => c); for (int i = 0; i < filter.Count; i++) { var e = filter[i]; @@ -399,6 +402,16 @@ namespace Elwig.Windows { filterNotAttr.Add(a.AttrId); filter.RemoveAt(i--); filterNames.Add($"ohne Attribut {a.Name}"); + } else if (cult.ContainsKey(e.ToLower())) { + var c = cult[e.ToLower()]; + filterCult.Add(c.CultId); + filter.RemoveAt(i--); + filterNames.Add($"Bewirtschaftung {c.Name}"); + } else if (e[0] == '!' && cult.ContainsKey(e[1..].ToLower())) { + var c = cult[e[1..].ToLower()]; + filterNotCult.Add(c.CultId); + filter.RemoveAt(i--); + filterNames.Add($"ohne Bewirtschaftung {c.Name}"); } else if (zwst.ContainsKey(e.ToLower())) { var b = zwst[e.ToLower()]; filterZwst.Add(b.ZwstId); @@ -523,6 +536,8 @@ namespace Elwig.Windows { if (filterZwst.Count > 0) prd = prd.And(p => filterZwst.Contains(p.Delivery.ZwstId)); if (filterAttr.Count > 0) prd = prd.And(p => p.AttrId != null && filterAttr.Contains(p.AttrId)); if (filterNotAttr.Count > 0) prd = prd.And(p => p.AttrId == null || !filterNotAttr.Contains(p.AttrId)); + if (filterCult.Count > 0) prd = prd.And(p => p.CultId != null && filterCult.Contains(p.CultId)); + if (filterNotCult.Count > 0) prd = prd.And(p => p.CultId == null || !filterNotCult.Contains(p.CultId)); if (filterKmwGt > 0) prd = prd.And(p => p.Kmw >= filterKmwGt); if (filterKmwLt > 0) prd = prd.And(p => p.Kmw < filterKmwLt); if (filterOeGt > 0) prd = prd.And(p => p.Kmw * (4.54 + 0.022 * p.Kmw) >= filterOeGt); @@ -646,9 +661,10 @@ namespace Elwig.Windows { AddGradationToolTipRow(1, "Gradation", null, kmwMin, kmwAvg, kmwMax); var attrGroups = await deliveryParts - .GroupBy(p => p.Attribute.Name) + .GroupBy(p => new { Attr = p.Attribute.Name, Cult = p.Cultivation.Name }) .Select(g => new { - Attr = g.Key, + g.Key.Attr, + g.Key.Cult, Weight = g.Sum(p => p.Weight), Min = g.Min(p => p.Kmw), Avg = g.Sum(p => p.Kmw * p.Weight) / g.Sum(p => p.Weight), @@ -671,11 +687,13 @@ namespace Elwig.Windows { .ToListAsync(); var groups = await deliveryParts .GroupBy(p => new { - p.Attribute.Name, + Attr = p.Attribute.Name, + Cult = p.Cultivation.Name, p.SortId, }) .Select(g => new { - Attr = g.Key.Name, + g.Key.Attr, + g.Key.Cult, g.Key.SortId, Weight = g.Sum(p => p.Weight), Min = g.Min(p => p.Kmw), @@ -690,25 +708,28 @@ namespace Elwig.Windows { int rowNum = 1; foreach (var attrG in attrGroups) { rowNum++; - AddWeightToolTipRow(rowNum++, attrG.Attr, null, attrG.Weight, attrG.Weight, weight); - foreach (var g in groups.Where(g => g.Attr == attrG.Attr).OrderByDescending(g => g.Weight).ThenBy(g => g.SortId)) { + var name = attrG.Attr == null && attrG.Cult == null ? null : attrG.Attr + (attrG.Attr != null && attrG.Cult != null ? " / " : "") + attrG.Cult; + AddWeightToolTipRow(rowNum++, 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(rowNum++, null, g.SortId, g.Weight, attrG.Weight, weight); } } rowNum = 2; foreach (var attrG in attrGroups) { rowNum++; - AddGradationToolTipRow(rowNum++, attrG.Attr, null, attrG.Min, attrG.Avg, attrG.Max); - foreach (var g in groups.Where(g => g.Attr == attrG.Attr).OrderByDescending(g => g.Avg).ThenBy(g => g.SortId)) { + var name = attrG.Attr == null && attrG.Cult == null ? null : attrG.Attr + (attrG.Attr != null && attrG.Cult != null ? " / " : "") + attrG.Cult; + AddGradationToolTipRow(rowNum++, 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(rowNum++, null, g.SortId, g.Min, g.Avg, g.Max); } } if (attrGroups.Count == 1) { - var g = attrGroups.First().Attr; - if (g != null) { - StatusWeight.Text += $" [{g}]"; - StatusGradation.Text += $" [{g}]"; + var g = attrGroups.First(); + var name = g.Attr == null && g.Cult == null ? null : g.Attr + (g.Attr != null && g.Cult != null ? " / " : "") + g.Cult; + if (name != null) { + StatusWeight.Text += $" [{name}]"; + StatusGradation.Text += $" [{name}]"; } if (sortGroups.Count > 1 && sortGroups.Count <= 4) { StatusWeight.Text += $" = {string.Join(" + ", sortGroups.Select(g => $"{g.Weight:N0} kg ({(double)g.Weight / weight:0%})" + (g.SortId == null ? "" : $" [{g.SortId}]")))}"; @@ -716,8 +737,8 @@ namespace Elwig.Windows { } } else if (attrGroups.Count <= 4) { - StatusWeight.Text += $" = {string.Join(" + ", attrGroups.Select(g => $"{g.Weight:N0} kg ({(double)g.Weight / weight:0%})" + (g.Attr == null ? "" : $" [{g.Attr}]")))}"; - StatusGradation.Text += $" = {string.Join(" + ", attrGroups.Select(g => $"{g.Min:N1}/{g.Avg:N1}/{g.Max:N1}" + (g.Attr == null ? "" : $" [{g.Attr}]")))}"; + StatusWeight.Text += $" = {string.Join(" + ", attrGroups.Select(g => $"{g.Weight:N0} kg ({(double)g.Weight / weight:0%})" + (g.Attr == null && g.Cult == null ? "" : $" [{g.Attr}{(g.Attr != null && g.Cult != null ? " / " : "")}{g.Cult}]")))}"; + StatusGradation.Text += $" = {string.Join(" + ", attrGroups.Select(g => $"{g.Min:N1}/{g.Avg:N1}/{g.Max:N1}" + (g.Attr == null && g.Cult == null ? "" : $" [{g.Attr}{(g.Attr != null && g.Cult != null ? " / " : "")}{g.Cult}]")))}"; } } else { StatusGradation.Text = "Gradation: -";