From 3f97fbfae4a8d45ca163e2b9154ba6bb2931e076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Erbsh=C3=A4u=C3=9Fer?= Date: Mon, 15 Jun 2020 18:25:35 +0200 Subject: [PATCH] Implemented restrictions for the entry and departure dates. Implemented restrictions for decimal values. --- ucalc/BillingWindow.xaml.cs | 1 + ucalc/Constants.cs | 2 +- ucalc/Models/Model.cs | 4 ++++ ucalc/Models/Properties.cs | 17 +++++++++++++---- ucalc/Pages/TenantsPage.xaml.cs | 3 ++- ucalc/TenantWindow.xaml | 6 +++++- ucalc/TenantWindow.xaml.cs | 4 +++- 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ucalc/BillingWindow.xaml.cs b/ucalc/BillingWindow.xaml.cs index e496078..1bb0ddf 100644 --- a/ucalc/BillingWindow.xaml.cs +++ b/ucalc/BillingWindow.xaml.cs @@ -52,6 +52,7 @@ namespace UCalc private void OnTenantsFrameLoadCompleted(object sender, NavigationEventArgs e) { var page = (TenantsPage) ((Frame) sender).Content; + page.Model = Model; page.Tenants = Model.Root.Tenants; page.House = Model.Root.House; page.ParentWindow = this; diff --git a/ucalc/Constants.cs b/ucalc/Constants.cs index 199cbe3..db656b2 100644 --- a/ucalc/Constants.cs +++ b/ucalc/Constants.cs @@ -11,7 +11,7 @@ namespace UCalc public static readonly SolidColorBrush MainColor = Brushes.White; public static readonly SolidColorBrush SubMainColor = new SolidColorBrush(Color.FromRgb(0x00, 0x7A, 0xCC)); - public const string DecimalFormat = ".00"; + public const string DecimalFormat = "0.00"; public const string DateFormat = "dd.MM.yyyy"; public static readonly ImmutableList SalutationStrs = diff --git a/ucalc/Models/Model.cs b/ucalc/Models/Model.cs index 378bdef..4175295 100644 --- a/ucalc/Models/Model.cs +++ b/ucalc/Models/Model.cs @@ -127,11 +127,15 @@ namespace UCalc.Models } private readonly Validator _validator; + public DateTime StartDate { get; } + public DateTime EndDate { get; } public BillingProperty Root { get; } public Model(Billing billing) { _validator = new Validator(this); + StartDate = billing.StartDate; + EndDate = billing.EndDate; using var validator = BeginValidation(); Root = new BillingProperty(this, null, billing); diff --git a/ucalc/Models/Properties.cs b/ucalc/Models/Properties.cs index fbea7c5..c2e5ff3 100644 --- a/ucalc/Models/Properties.cs +++ b/ucalc/Models/Properties.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; @@ -171,9 +172,17 @@ namespace UCalc.Models protected override string ValidateValue() { - return !decimal.TryParse(Value, out var n) || n < 0 - ? $"{Name}: Der eingegebene Wert ist kein gültiger Betrag." - : ""; + if (!decimal.TryParse(Value, out var n) || n < 0) + { + return $"{Name}: Der eingegebene Wert ist kein gültiger Betrag."; + } + + if (Math.Round(n, 2) != n) + { + return $"{Name}: Der eingegebene Wert besitzt mehr als 2 Nachkommastellen."; + } + + return ""; } } diff --git a/ucalc/Pages/TenantsPage.xaml.cs b/ucalc/Pages/TenantsPage.xaml.cs index 5ccb7ad..fef3a89 100644 --- a/ucalc/Pages/TenantsPage.xaml.cs +++ b/ucalc/Pages/TenantsPage.xaml.cs @@ -7,6 +7,7 @@ namespace UCalc.Pages public partial class TenantsPage { public Window ParentWindow { get; set; } + public Model Model { get; set; } public TenantsProperty Tenants { get; set; } public HouseProperty House { get; set; } @@ -35,7 +36,7 @@ namespace UCalc.Pages { var tenant = (TenantProperty) ((HighlightButton) sender).DataContext; - new TenantWindow(tenant, House) {Owner = ParentWindow}.ShowDialog(); + new TenantWindow(Model, tenant, House) {Owner = ParentWindow}.ShowDialog(); } } } \ No newline at end of file diff --git a/ucalc/TenantWindow.xaml b/ucalc/TenantWindow.xaml index 55995a4..bf3c455 100644 --- a/ucalc/TenantWindow.xaml +++ b/ucalc/TenantWindow.xaml @@ -151,9 +151,11 @@ DockPanel.Dock="Right" VerticalAlignment="Center" Property="{Binding Path=Tenant.EntryDate, RelativeSource={RelativeSource AncestorType=local:TenantWindow}}" /> - + @@ -170,6 +172,8 @@ diff --git a/ucalc/TenantWindow.xaml.cs b/ucalc/TenantWindow.xaml.cs index 151ed85..2b4c218 100644 --- a/ucalc/TenantWindow.xaml.cs +++ b/ucalc/TenantWindow.xaml.cs @@ -7,11 +7,13 @@ namespace UCalc { public partial class TenantWindow { + public Model Model { get; } public TenantProperty Tenant { get; } public HouseProperty House { get; } - public TenantWindow(TenantProperty tenant, HouseProperty house) + public TenantWindow(Model model, TenantProperty tenant, HouseProperty house) { + Model = model; Tenant = tenant; House = house; InitializeComponent();