diff --git a/ucalc/Controls/Converters.cs b/ucalc/Controls/Converters.cs index 80cae75..e777fd4 100644 --- a/ucalc/Controls/Converters.cs +++ b/ucalc/Controls/Converters.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Windows; using System.Windows.Data; using UCalc.Models; @@ -149,6 +150,36 @@ namespace UCalc.Controls } } + public class CostToAffectedConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var cost = (CostProperty) value; + + if (cost == null) + { + return ""; + } + + if (cost.AffectsAll.Value) + { + return "Betrifft: Alle Wohnungen"; + } + + if (cost.AffectedFlats.Count == 0) + { + return "Betrifft: Niemanden"; + } + + return $"Betrifft: {string.Join(", ", cost.AffectedFlats.Select(flat => flat.Name.Value))}"; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new InvalidOperationException(); + } + } + public class NegateConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/ucalc/Controls/HighlightButton.cs b/ucalc/Controls/HighlightButton.cs index 10e0f17..2b3170c 100644 --- a/ucalc/Controls/HighlightButton.cs +++ b/ucalc/Controls/HighlightButton.cs @@ -64,6 +64,9 @@ namespace UCalc.Controls case Label label: label.Foreground = foreground; break; + case TextBlock block: + block.Foreground = foreground; + break; case Path path: path.Fill = foreground; break; diff --git a/ucalc/Models/CostProperty.cs b/ucalc/Models/CostProperty.cs index fa2a0cf..fc67d2d 100644 --- a/ucalc/Models/CostProperty.cs +++ b/ucalc/Models/CostProperty.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using UCalc.Data; @@ -13,13 +14,16 @@ namespace UCalc.Models protected override string ValidateValue() { + var affectedFlats = ((CostProperty) Parent).AffectedFlats; + using var validator = Model.BeginValidation(); - validator.Validate(((CostProperty) Parent).AffectedFlats); + validator.Validate(affectedFlats); + return ""; } } - public class AffectedFlatsProperty : Property + public class AffectedFlatsProperty : Property, IReadOnlyCollection { private const string NoFlatsError = "Betroffene Wohnungen: Es wurde keine Wohnung zugewiesen."; private readonly HashSet _flats; @@ -81,7 +85,21 @@ namespace UCalc.Models using var validator = Model.BeginValidation(); validator.Notify(this, "Errors"); + + Model.Root.Costs.NotifyChanged((CostProperty) Parent); } + + public IEnumerator GetEnumerator() + { + return _flats.GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count => _flats.Count; } public class CostProperty : NestedProperty diff --git a/ucalc/Models/Properties.cs b/ucalc/Models/Properties.cs index c2e5ff3..837434c 100644 --- a/ucalc/Models/Properties.cs +++ b/ucalc/Models/Properties.cs @@ -285,6 +285,18 @@ namespace UCalc.Models validator.ValidateRange(_properties); } + public void NotifyChanged(T property) + { + var index = _properties.IndexOf(property); + if (index == -1) + { + return; + } + + CollectionChanged?.Invoke(this, + new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); + } + public sealed override void OnPropertyChanged(string propertyName = null) { switch (propertyName) diff --git a/ucalc/Pages/CostsPage.xaml b/ucalc/Pages/CostsPage.xaml index 66d03cb..6eea034 100644 --- a/ucalc/Pages/CostsPage.xaml +++ b/ucalc/Pages/CostsPage.xaml @@ -7,10 +7,11 @@ xmlns:local="clr-namespace:UCalc" xmlns:pages="clr-namespace:UCalc.Pages" mc:Ignorable="d"> - + + @@ -88,8 +89,13 @@ DockPanel.Dock="Left" Margin="12, 12, 8, 12" /> - @@ -97,5 +103,5 @@ - - + + \ No newline at end of file