diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..0b1717c --- /dev/null +++ b/logo.svg @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/logo.xaml b/logo.xaml new file mode 100644 index 0000000..0809363 --- /dev/null +++ b/logo.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ucalc/BillingWindow.xaml b/ucalc/BillingWindow.xaml index 82044a2..50144c4 100644 --- a/ucalc/BillingWindow.xaml +++ b/ucalc/BillingWindow.xaml @@ -11,7 +11,8 @@ Height="600" MinWidth="600" MinHeight="400" - Closed="OnClosed"> + Closed="OnClosed" + Icon="logo.ico"> diff --git a/ucalc/BillingWindow.xaml.cs b/ucalc/BillingWindow.xaml.cs index 1bb0ddf..91f6ed7 100644 --- a/ucalc/BillingWindow.xaml.cs +++ b/ucalc/BillingWindow.xaml.cs @@ -57,5 +57,14 @@ namespace UCalc page.House = Model.Root.House; page.ParentWindow = this; } + + private void OnCostsFrameLoadCompleted(object sender, NavigationEventArgs e) + { + var page = (CostsPage) ((Frame) sender).Content; + page.Model = Model; + page.Costs = Model.Root.Costs; + page.House = Model.Root.House; + page.ParentWindow = this; + } } } \ No newline at end of file diff --git a/ucalc/Controls/Converters.cs b/ucalc/Controls/Converters.cs index 16f26dd..a03fc1b 100644 --- a/ucalc/Controls/Converters.cs +++ b/ucalc/Controls/Converters.cs @@ -113,4 +113,24 @@ namespace UCalc.Controls return null; } } + + public class NameToTextConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var str = (string) value; + + if (str == "") + { + return "(Unbenannt)"; + } + + return str; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new InvalidOperationException(); + } + } } \ No newline at end of file diff --git a/ucalc/CostWindow.xaml b/ucalc/CostWindow.xaml new file mode 100644 index 0000000..2ba7d02 --- /dev/null +++ b/ucalc/CostWindow.xaml @@ -0,0 +1,60 @@ + + + + + + + + @@ -79,7 +129,7 @@ - diff --git a/ucalc/Models/BillingProperty.cs b/ucalc/Models/BillingProperty.cs index bcdf237..d30ddb5 100644 --- a/ucalc/Models/BillingProperty.cs +++ b/ucalc/Models/BillingProperty.cs @@ -8,9 +8,7 @@ namespace UCalc.Models public LandlordProperty Landlord { get; } public HouseProperty House { get; } public TenantsProperty Tenants { get; } - - - // TODO: Costs + public CostsProperty Costs { get; } public BillingProperty(Model model, Property parent, Billing data) : base(model, parent) { @@ -24,6 +22,7 @@ namespace UCalc.Models } Tenants = Add(new TenantsProperty(model, this, data.Tenants, flatToProperty)); + Costs = Add(new CostsProperty(model, this, data.Costs, flatToProperty)); } } } \ No newline at end of file diff --git a/ucalc/Models/CostProperty.cs b/ucalc/Models/CostProperty.cs new file mode 100644 index 0000000..ab409f7 --- /dev/null +++ b/ucalc/Models/CostProperty.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using UCalc.Data; + +namespace UCalc.Models +{ + public class CostProperty : NestedProperty + { + public NotEmptyStringProperty Name { get; } + public AlwaysValidProperty Division { get; } + public AlwaysValidProperty AffectsAll { get; } + + public AlwaysValidProperty IncludeUnrented { get; } + + // TODO: public HashSet AffectedFlats { get; } + // TODO: public List Entries { get; } + public AlwaysValidProperty DisplayInBill { get; } + + public CostProperty(Model model, Property parent, Cost cost, + IReadOnlyDictionary flatToProperty = null) : base(model, parent) + { + Name = Add(new NotEmptyStringProperty(model, this, "Name", cost.Name)); + Division = Add(new AlwaysValidProperty(model, this, "Aufteilung", (int) cost.Division)); + AffectsAll = Add(new AlwaysValidProperty(model, this, "Betrifft alle", cost.AffectsAll)); + IncludeUnrented = + Add(new AlwaysValidProperty(model, this, "Unvermietete einbeziehen", cost.IncludeUnrented)); + DisplayInBill = Add(new AlwaysValidProperty(model, this, "In Rechnung anzeigen", cost.DisplayInBill)); + } + } +} \ No newline at end of file diff --git a/ucalc/Models/CostsProperty.cs b/ucalc/Models/CostsProperty.cs new file mode 100644 index 0000000..253e4eb --- /dev/null +++ b/ucalc/Models/CostsProperty.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using UCalc.Data; + +namespace UCalc.Models +{ + public class CostsProperty : MultiProperty + { + public CostsProperty(Model model, Property parent, IEnumerable data, + IReadOnlyDictionary flatToProperty = null) : base(model, parent, + "Kosten: Geben Sie einen oder mehr Kostenpunkte an.") + { + using var validator = Model.BeginValidation(); + + foreach (var cost in data) + { + base.Add(new CostProperty(Model, this, cost, flatToProperty)); + } + + Modified = false; + } + + public CostProperty Add() + { + using var validator = Model.BeginValidation(); + + var cost = new CostProperty(Model, this, new Cost()); + base.Add(cost); + return cost; + } + + public new void Remove(CostProperty cost) + { + using var validator = Model.BeginValidation(); + + base.Remove(cost); + } + } +} \ No newline at end of file diff --git a/ucalc/Models/FlatsProperty.cs b/ucalc/Models/FlatsProperty.cs index fa74019..d3d39e8 100644 --- a/ucalc/Models/FlatsProperty.cs +++ b/ucalc/Models/FlatsProperty.cs @@ -19,7 +19,7 @@ namespace UCalc.Models Modified = false; } - public void Add() + public FlatProperty Add() { FlatProperty flat; { @@ -33,6 +33,8 @@ namespace UCalc.Models using var validator = Model.BeginValidation(); validator.Validate(flat); } + + return flat; } public new void Remove(FlatProperty flat) diff --git a/ucalc/Models/TenantsProperty.cs b/ucalc/Models/TenantsProperty.cs index fd8b33a..95f2b68 100644 --- a/ucalc/Models/TenantsProperty.cs +++ b/ucalc/Models/TenantsProperty.cs @@ -20,11 +20,13 @@ namespace UCalc.Models Modified = false; } - public void Add() + public TenantProperty Add() { using var validator = Model.BeginValidation(); - base.Add(new TenantProperty(Model, this, new Tenant())); + var tenant = new TenantProperty(Model, this, new Tenant()); + base.Add(tenant); + return tenant; } public new void Remove(TenantProperty tenant) diff --git a/ucalc/NewWindow.xaml b/ucalc/NewWindow.xaml index a389baf..72a3f5f 100644 --- a/ucalc/NewWindow.xaml +++ b/ucalc/NewWindow.xaml @@ -10,7 +10,8 @@ ShowInTaskbar="False" ResizeMode="NoResize" WindowStartupLocation="CenterOwner" - PreviewMouseUp="OnPreviewMouseUp"> + PreviewMouseUp="OnPreviewMouseUp" + Icon="logo.ico"> diff --git a/ucalc/Pages/CostsPage.xaml b/ucalc/Pages/CostsPage.xaml index 9a64e18..66d03cb 100644 --- a/ucalc/Pages/CostsPage.xaml +++ b/ucalc/Pages/CostsPage.xaml @@ -3,7 +3,99 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:UCalc.Pages" + xmlns:controls="clr-namespace:UCalc.Controls" + xmlns:local="clr-namespace:UCalc" + xmlns:pages="clr-namespace:UCalc.Pages" mc:Ignorable="d"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ucalc/Pages/CostsPage.xaml.cs b/ucalc/Pages/CostsPage.xaml.cs index 0ab3ec0..71b4fc3 100644 --- a/ucalc/Pages/CostsPage.xaml.cs +++ b/ucalc/Pages/CostsPage.xaml.cs @@ -1,12 +1,43 @@ -using System.Windows.Controls; +using System.Windows; +using UCalc.Controls; +using UCalc.Models; namespace UCalc.Pages { - public partial class CostsPage : Page + public partial class CostsPage { + public Window ParentWindow { get; set; } + public Model Model { get; set; } + public CostsProperty Costs { get; set; } + public HouseProperty House { get; set; } + public CostsPage() { InitializeComponent(); } + + private void OnAddCostClick(object sender, RoutedEventArgs e) + { + var cost = Costs.Add(); + new CostWindow(Model, cost, House) {Owner = ParentWindow}.ShowDialog(); + } + + private void OnCostDeleteClick(object sender, RoutedEventArgs e) + { + var cost = (CostProperty) ((HighlightButton) sender).DataContext; + + if (MessageBox.Show($"Möchten Sie den Kostenpunkt \"{cost.Name.Value}\" wirlick löschen?", "Löschen?", + MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) + { + Costs.Remove(cost); + } + } + + private void OnCostEditClick(object sender, RoutedEventArgs e) + { + var cost = (CostProperty) ((HighlightButton) sender).DataContext; + + new CostWindow(Model, cost, House) {Owner = ParentWindow}.ShowDialog(); + } } } \ No newline at end of file diff --git a/ucalc/Pages/HousePage.xaml b/ucalc/Pages/HousePage.xaml index 506b90b..b618aae 100644 --- a/ucalc/Pages/HousePage.xaml +++ b/ucalc/Pages/HousePage.xaml @@ -10,6 +10,7 @@ + - diff --git a/ucalc/Pages/HousePage.xaml.cs b/ucalc/Pages/HousePage.xaml.cs index 658ecf4..833f69d 100644 --- a/ucalc/Pages/HousePage.xaml.cs +++ b/ucalc/Pages/HousePage.xaml.cs @@ -16,7 +16,9 @@ namespace UCalc.Pages private void OnAddFlatClick(object sender, RoutedEventArgs e) { - House.Flats.Add(); + var flat = House.Flats.Add(); + + new FlatWindow(flat) {Owner = ParentWindow}.ShowDialog(); } private void OnFlatDeleteClick(object sender, RoutedEventArgs e) diff --git a/ucalc/Pages/SideBar.xaml b/ucalc/Pages/SideBar.xaml index 7b5e1f5..c632952 100644 --- a/ucalc/Pages/SideBar.xaml +++ b/ucalc/Pages/SideBar.xaml @@ -227,6 +227,11 @@ + +