Changed cost page to view affected flats together with the name.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
using UCalc.Models;
|
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 class NegateConverter : IValueConverter
|
||||||
{
|
{
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ namespace UCalc.Controls
|
|||||||
case Label label:
|
case Label label:
|
||||||
label.Foreground = foreground;
|
label.Foreground = foreground;
|
||||||
break;
|
break;
|
||||||
|
case TextBlock block:
|
||||||
|
block.Foreground = foreground;
|
||||||
|
break;
|
||||||
case Path path:
|
case Path path:
|
||||||
path.Fill = foreground;
|
path.Fill = foreground;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UCalc.Data;
|
using UCalc.Data;
|
||||||
|
|
||||||
@@ -13,13 +14,16 @@ namespace UCalc.Models
|
|||||||
|
|
||||||
protected override string ValidateValue()
|
protected override string ValidateValue()
|
||||||
{
|
{
|
||||||
|
var affectedFlats = ((CostProperty) Parent).AffectedFlats;
|
||||||
|
|
||||||
using var validator = Model.BeginValidation();
|
using var validator = Model.BeginValidation();
|
||||||
validator.Validate(((CostProperty) Parent).AffectedFlats);
|
validator.Validate(affectedFlats);
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AffectedFlatsProperty : Property
|
public class AffectedFlatsProperty : Property, IReadOnlyCollection<FlatProperty>
|
||||||
{
|
{
|
||||||
private const string NoFlatsError = "Betroffene Wohnungen: Es wurde keine Wohnung zugewiesen.";
|
private const string NoFlatsError = "Betroffene Wohnungen: Es wurde keine Wohnung zugewiesen.";
|
||||||
private readonly HashSet<FlatProperty> _flats;
|
private readonly HashSet<FlatProperty> _flats;
|
||||||
@@ -81,7 +85,21 @@ namespace UCalc.Models
|
|||||||
|
|
||||||
using var validator = Model.BeginValidation();
|
using var validator = Model.BeginValidation();
|
||||||
validator.Notify(this, "Errors");
|
validator.Notify(this, "Errors");
|
||||||
|
|
||||||
|
Model.Root.Costs.NotifyChanged((CostProperty) Parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerator<FlatProperty> GetEnumerator()
|
||||||
|
{
|
||||||
|
return _flats.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Count => _flats.Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CostProperty : NestedProperty
|
public class CostProperty : NestedProperty
|
||||||
|
|||||||
@@ -285,6 +285,18 @@ namespace UCalc.Models
|
|||||||
validator.ValidateRange(_properties);
|
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)
|
public sealed override void OnPropertyChanged(string propertyName = null)
|
||||||
{
|
{
|
||||||
switch (propertyName)
|
switch (propertyName)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<Page.Resources>
|
<Page.Resources>
|
||||||
<controls:EmptyMultiPropertyToVisibilityConverter x:Key="EmptyMultiPropertyToVisibilityConverter" />
|
<controls:EmptyMultiPropertyToVisibilityConverter x:Key="EmptyMultiPropertyToVisibilityConverter" />
|
||||||
<controls:NameToTextConverter x:Key="NameToTextConverter" />
|
<controls:NameToTextConverter x:Key="NameToTextConverter" />
|
||||||
|
<controls:CostToAffectedConverter x:Key="CostToAffectedConverter" />
|
||||||
</Page.Resources>
|
</Page.Resources>
|
||||||
|
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
@@ -88,8 +89,13 @@
|
|||||||
DockPanel.Dock="Left"
|
DockPanel.Dock="Left"
|
||||||
Margin="12, 12, 8, 12" />
|
Margin="12, 12, 8, 12" />
|
||||||
|
|
||||||
<Label Content="{Binding Path=Name.Value, Converter={StaticResource NameToTextConverter}}"
|
<TextBlock VerticalAlignment="Center">
|
||||||
VerticalAlignment="Center" />
|
<Run
|
||||||
|
Text="{Binding Path=Name.Value, Converter={StaticResource NameToTextConverter}}" />
|
||||||
|
<LineBreak />
|
||||||
|
<Run
|
||||||
|
Text="{Binding Path=., Converter={StaticResource CostToAffectedConverter}}" />
|
||||||
|
</TextBlock>
|
||||||
</controls:HighlightButton>
|
</controls:HighlightButton>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|||||||
Reference in New Issue
Block a user