diff --git a/Elwig/App.xaml b/Elwig/App.xaml index 157b9b3..4962032 100644 --- a/Elwig/App.xaml +++ b/Elwig/App.xaml @@ -56,6 +56,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/Elwig/Helpers/Validator.cs b/Elwig/Helpers/Validator.cs index 3697acc..1da1e5a 100644 --- a/Elwig/Helpers/Validator.cs +++ b/Elwig/Helpers/Validator.cs @@ -542,7 +542,7 @@ namespace Elwig.Helpers { } var oe = double.Parse(input.Text); - if (oe < 10 || oe >= 200) { + if (oe < 10 || oe >= 300) { return new(false, "Ungültiger Oechsle-Wert"); } @@ -558,7 +558,7 @@ namespace Elwig.Helpers { } var kmw = double.Parse(input.Text); - if (kmw < 0 || kmw >= 50) { + if (kmw < 5 || kmw >= 50) { return new(false, "Ungültiger KMW-Wert"); } diff --git a/Elwig/Models/WineQualLevel.cs b/Elwig/Models/WineQualLevel.cs index d04fa77..ded8697 100644 --- a/Elwig/Models/WineQualLevel.cs +++ b/Elwig/Models/WineQualLevel.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations.Schema; namespace Elwig.Models { - [Table("wine_quality"), PrimaryKey("QualId")] + [Table("wine_quality_level"), PrimaryKey("QualId")] public class WineQualLevel { [Column("qualid")] public string QualId { get; private set; } @@ -22,5 +22,7 @@ namespace Elwig.Models { [Column("name")] public string Name { get; private set; } + + public string MinKmwStr => (MinKmw == null) ? "" : $"(mind. {MinKmw:#.0} °KMW)"; } } diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml b/Elwig/Windows/DeliveryAdminWindow.xaml index 47fdec7..337ef14 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml +++ b/Elwig/Windows/DeliveryAdminWindow.xaml @@ -112,17 +112,23 @@ - - @@ -137,7 +143,7 @@ + ItemTemplate="{StaticResource WineOriginTemplate}"/> diff --git a/Elwig/Windows/DeliveryAdminWindow.xaml.cs b/Elwig/Windows/DeliveryAdminWindow.xaml.cs index 5af538d..835a722 100644 --- a/Elwig/Windows/DeliveryAdminWindow.xaml.cs +++ b/Elwig/Windows/DeliveryAdminWindow.xaml.cs @@ -16,7 +16,8 @@ namespace Elwig.Windows { MgNrInput, MemberInput, SortIdInput, WineVarietyInput, GradationOeInput, GradationKmwInput, - WineOriginInput + WineQualityLevelInput, + WineOriginInput, }; ExemptInputs = new Control[] { MgNrInput, MemberInput, @@ -28,6 +29,7 @@ namespace Elwig.Windows { MemberInput.ItemsSource = Context.Members.OrderBy(m => m.FamilyName).ThenBy(m => m.GivenName).ToList(); WineVarietyInput.ItemsSource = Context.WineVarieties.OrderBy(v => v.Name).ToList(); AttributesInput.ItemsSource = Context.WineAttributes.OrderBy(a => a.Name).ToList(); + WineQualityLevelInput.ItemsSource = Context.WineQualityLevels.ToList(); ModifiersInput.ItemsSource = Context.Modifiers.Where(m => m.Season.Year == 2022).OrderBy(m => m.Name).ToList(); WineOriginInput.ItemsSource = Context.WineOrigins.ToList().OrderByDescending(o => o.SortKey).ThenBy(o => o.HkId); } @@ -80,12 +82,22 @@ namespace Elwig.Windows { if (s != null) SortIdInput.Text = s.SortId; } + private void UpdateWineQualityLevels() { + var kmw = double.Parse(GradationKmwInput.Text); + WineQualityLevelInput.ItemsSource = Context.WineQualityLevels.Where(q => q.MinKmw == null || q.MinKmw <= kmw).ToList(); + if (WineQualityLevelInput.SelectedItem == null || (WineQualityLevelInput.SelectedItem is WineQualLevel selected && !selected.IsPredicate)) { + var qual = Context.WineQualityLevels.Where(q => !q.IsPredicate && (q.MinKmw == null || q.MinKmw <= kmw)).OrderBy(q => q.MinKmw).LastOrDefault(); + WineQualityLevelInput.SelectedItem = qual; + } + } + private void UpdateGradationKmw() { IsUpdatingGradation = true; var caret = GradationKmwInput.CaretIndex; GradationKmwInput.Text = $"{Utils.OeToKmw(double.Parse(GradationOeInput.Text)):#.0}"; GradationKmwInput.CaretIndex = caret; IsUpdatingGradation = false; + UpdateWineQualityLevels(); } private void UpdateGradationOe() { @@ -94,6 +106,7 @@ namespace Elwig.Windows { GradationOeInput.Text = $"{Utils.KmwToOe(double.Parse(GradationKmwInput.Text)):#}"; GradationOeInput.CaretIndex = caret; IsUpdatingGradation = false; + UpdateWineQualityLevels(); } private void GradationOeInput_TextChanged(object sender, TextChangedEventArgs evt) { @@ -112,6 +125,7 @@ namespace Elwig.Windows { private void GradationKmwInput_LostFocus(object sender, RoutedEventArgs evt) { InputLostFocus((TextBox)sender, Validator.CheckGradationKmw); + if (!GradationKmwInput.Text.Contains(',')) GradationKmwInput.Text += ",0"; } private void AttributesInput_SelectionChanged(object sender, ItemSelectionChangedEventArgs evt) {