diff --git a/ucalc/App.xaml.cs b/ucalc/App.xaml.cs
index a703461..616fa75 100644
--- a/ucalc/App.xaml.cs
+++ b/ucalc/App.xaml.cs
@@ -9,7 +9,7 @@ namespace UCalc
public App()
{
- _recentlyOpenedList = new RecentlyOpenedList();
+ _recentlyOpenedList = new RecentlyOpenedList("recently.txt");
}
}
}
\ No newline at end of file
diff --git a/ucalc/BillingWindow.xaml b/ucalc/BillingWindow.xaml
index 70c020c..8b29f1d 100644
--- a/ucalc/BillingWindow.xaml
+++ b/ucalc/BillingWindow.xaml
@@ -5,6 +5,37 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:UCalc"
mc:Ignorable="d"
- Title="BillingWindow" Height="450" Width="800">
-
-
+ Title="MietRechner"
+ Width="800"
+ Height="600"
+ MinWidth="600"
+ MinHeight="400"
+ Closed="OnClosed">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ucalc/BillingWindow.xaml.cs b/ucalc/BillingWindow.xaml.cs
index 1c09c9f..97bd516 100644
--- a/ucalc/BillingWindow.xaml.cs
+++ b/ucalc/BillingWindow.xaml.cs
@@ -1,4 +1,8 @@
-using UCalc.Data;
+using System;
+using System.Windows;
+using System.Windows.Navigation;
+using UCalc.Data;
+using UCalc.Pages;
namespace UCalc
{
@@ -12,6 +16,21 @@ namespace UCalc
_savedBilling = savedBilling;
Billing = billing;
InitializeComponent();
+
+ Title =
+ $"MietRechner - Abrechnung von {billing.StartDate.ToShortDateString()} - {billing.EndDate.Date.ToShortDateString()}";
+ }
+
+ private void OnClosed(object sender, EventArgs e)
+ {
+ Application.Current.MainWindow?.Show();
+ }
+
+ private void OnSideBarFrameLoadCompleted(object sender, NavigationEventArgs e)
+ {
+ var sideBar = (SideBar) SideBarFrame.Content;
+ sideBar.TabControl = TabControl;
+ sideBar.LandlordButton.Selected = true;
}
}
}
\ No newline at end of file
diff --git a/ucalc/Controls/ErrorCounter.xaml b/ucalc/Controls/ErrorCounter.xaml
new file mode 100644
index 0000000..3c219c5
--- /dev/null
+++ b/ucalc/Controls/ErrorCounter.xaml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/ucalc/Controls/ErrorCounter.xaml.cs b/ucalc/Controls/ErrorCounter.xaml.cs
new file mode 100644
index 0000000..df8dae4
--- /dev/null
+++ b/ucalc/Controls/ErrorCounter.xaml.cs
@@ -0,0 +1,10 @@
+namespace UCalc.Controls
+{
+ public partial class ErrorCounter
+ {
+ public ErrorCounter()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Controls/Helpers.cs b/ucalc/Controls/Helpers.cs
new file mode 100644
index 0000000..865f82d
--- /dev/null
+++ b/ucalc/Controls/Helpers.cs
@@ -0,0 +1,30 @@
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+using System.Windows.Shapes;
+
+namespace UCalc.Controls
+{
+ public static class Helpers
+ {
+ public static IEnumerable FindChildren(this Panel parent) where T : FrameworkElement
+ {
+ foreach (var child in parent.Children)
+ {
+ if (child is T t)
+ {
+ yield return t;
+ }
+ }
+ }
+
+ public static void ChangeColor(this Viewbox viewbox, SolidColorBrush brush)
+ {
+ foreach (var path in ((Canvas) viewbox.Child).FindChildren())
+ {
+ path.Fill = brush;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Controls/HighlightButton.cs b/ucalc/Controls/HighlightButton.cs
new file mode 100644
index 0000000..10e0f17
--- /dev/null
+++ b/ucalc/Controls/HighlightButton.cs
@@ -0,0 +1,132 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Shapes;
+
+namespace UCalc.Controls
+{
+ public class HighlightButton : DockPanel
+ {
+ public static readonly RoutedEvent ClickEvent =
+ EventManager.RegisterRoutedEvent(nameof(Click), RoutingStrategy.Bubble, typeof(RoutedEventHandler),
+ typeof(HighlightButton));
+
+ public event RoutedEventHandler Click
+ {
+ add => AddHandler(ClickEvent, value);
+ remove => RemoveHandler(ClickEvent, value);
+ }
+
+ public SolidColorBrush HighlightForeground { get; set; }
+ public SolidColorBrush HighlightBackground { get; set; }
+ public bool Selectable { get; set; }
+ private bool _selected;
+
+ public bool Selected
+ {
+ get => _selected;
+ set
+ {
+ if (_selected && !value)
+ {
+ Unhighlight();
+ }
+ else if (value)
+ {
+ if (!_selected)
+ {
+ Highlight();
+ }
+
+ RaiseEvent(new RoutedEventArgs(ClickEvent));
+ }
+
+ _selected = value;
+ }
+ }
+
+ public HighlightButton()
+ {
+ HighlightForeground = Brushes.White;
+ HighlightBackground = Brushes.Black;
+ }
+
+ private void SetColors(SolidColorBrush foreground, SolidColorBrush background)
+ {
+ Background = background;
+
+ foreach (var child in Children)
+ {
+ switch (child)
+ {
+ case Label label:
+ label.Foreground = foreground;
+ break;
+ case Path path:
+ path.Fill = foreground;
+ break;
+ case Viewbox viewbox:
+ viewbox.ChangeColor(foreground);
+ break;
+ }
+ }
+ }
+
+ private void Highlight()
+ {
+ SetColors(HighlightBackground, HighlightForeground);
+ }
+
+ private void Unhighlight()
+ {
+ SetColors(HighlightForeground, HighlightBackground);
+ }
+
+ protected override void OnMouseEnter(MouseEventArgs e)
+ {
+ base.OnMouseEnter(e);
+
+ if (!Selected)
+ {
+ Highlight();
+ }
+ }
+
+ protected override void OnMouseLeave(MouseEventArgs e)
+ {
+ base.OnMouseLeave(e);
+
+ if (!Selected)
+ {
+ Unhighlight();
+ }
+ }
+
+ protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
+ {
+ base.OnMouseLeftButtonUp(e);
+
+ if (Selectable)
+ {
+ Selected = true;
+ }
+ else
+ {
+ RaiseEvent(new RoutedEventArgs(ClickEvent));
+ }
+ }
+
+ protected override void OnInitialized(EventArgs e)
+ {
+ base.OnInitialized(e);
+
+ if (!Selected)
+ {
+ Highlight();
+ Unhighlight();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Data/BillingLoader.cs b/ucalc/Data/BillingLoader.cs
new file mode 100644
index 0000000..3bf9595
--- /dev/null
+++ b/ucalc/Data/BillingLoader.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace UCalc.Data
+{
+ public class BillingLoader
+ {
+ public Billing Load(string path)
+ {
+ // TODO
+ return new Billing();
+ }
+
+ public void Store(string path, Billing billing)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Data/RecentlyOpened.cs b/ucalc/Data/RecentlyOpened.cs
index fefb881..dc30b1e 100644
--- a/ucalc/Data/RecentlyOpened.cs
+++ b/ucalc/Data/RecentlyOpened.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.IO;
+using System.Linq;
namespace UCalc.Data
{
@@ -40,11 +42,43 @@ namespace UCalc.Data
public class RecentlyOpenedList : ICollection
{
+ private const int MaxCount = 10;
+ private readonly string _path;
private readonly List _list;
- public RecentlyOpenedList()
+ public RecentlyOpenedList(string path)
{
+ _path = path;
_list = new List();
+
+ Load(path);
+ }
+
+ private void Load(string path)
+ {
+ try
+ {
+ var lines = File.ReadAllLines(path);
+
+ _list.AddRange(lines.Where(itemPath => itemPath != "").Take(MaxCount)
+ .Select(itemPath => new RecentlyOpenedItem(itemPath)));
+ }
+ catch (IOException)
+ {
+ // Do nothing
+ }
+ }
+
+ private void Store(string path)
+ {
+ try
+ {
+ File.WriteAllLines(path, _list.Select(item => item.Path));
+ }
+ catch (IOException)
+ {
+ // Do nothing
+ }
}
public IEnumerator GetEnumerator()
@@ -67,15 +101,19 @@ namespace UCalc.Data
_list.Insert(0, item);
- if (_list.Count > 10)
+ if (_list.Count > MaxCount)
{
- _list.RemoveAt(10);
+ _list.RemoveAt(MaxCount);
}
+
+ Store(_path);
}
public void Clear()
{
_list.Clear();
+
+ Store(_path);
}
public bool Contains(RecentlyOpenedItem item)
@@ -90,7 +128,10 @@ namespace UCalc.Data
public bool Remove(RecentlyOpenedItem item)
{
- return _list.Remove(item);
+ var result = _list.Remove(item);
+
+ Store(_path);
+ return result;
}
public int Count => _list.Count;
diff --git a/ucalc/MainWindow.xaml b/ucalc/MainWindow.xaml
index 1397d60..f561b6a 100644
--- a/ucalc/MainWindow.xaml
+++ b/ucalc/MainWindow.xaml
@@ -44,7 +44,7 @@
-
+
-
+
@@ -69,7 +68,7 @@
-
+
-
+
diff --git a/ucalc/MainWindow.xaml.cs b/ucalc/MainWindow.xaml.cs
index 129bfcd..0343b3c 100644
--- a/ucalc/MainWindow.xaml.cs
+++ b/ucalc/MainWindow.xaml.cs
@@ -1,9 +1,11 @@
using System;
+using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Microsoft.Win32;
+using UCalc.Data;
namespace UCalc
{
@@ -50,7 +52,7 @@ namespace UCalc
if (dialog.ShowDialog() == true)
{
- throw new NotImplementedException();
+ OpenBilling(dialog.FileName);
}
if (e != null)
@@ -61,7 +63,25 @@ namespace UCalc
private void OnOpenRecentClick(object sender, RoutedEventArgs e)
{
- throw new NotImplementedException();
+ var recentlyOpenedItem = (RecentlyOpenedItem) ((MenuItem) sender).DataContext;
+
+ OpenBilling(recentlyOpenedItem.Path);
+ }
+
+ private void OpenBilling(string path)
+ {
+ try
+ {
+ var billing = new BillingLoader().Load(path);
+ App.RecentlyOpenedList.Add(new RecentlyOpenedItem(path));
+
+ new BillingWindow(billing, billing.Clone()).Show();
+ Hide();
+ }
+ catch (IOException)
+ {
+ throw new NotImplementedException();
+ }
}
}
}
\ No newline at end of file
diff --git a/ucalc/Pages/CostsPage.xaml b/ucalc/Pages/CostsPage.xaml
new file mode 100644
index 0000000..9a64e18
--- /dev/null
+++ b/ucalc/Pages/CostsPage.xaml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/ucalc/Pages/CostsPage.xaml.cs b/ucalc/Pages/CostsPage.xaml.cs
new file mode 100644
index 0000000..0ab3ec0
--- /dev/null
+++ b/ucalc/Pages/CostsPage.xaml.cs
@@ -0,0 +1,12 @@
+using System.Windows.Controls;
+
+namespace UCalc.Pages
+{
+ public partial class CostsPage : Page
+ {
+ public CostsPage()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Pages/DetailsPage.xaml b/ucalc/Pages/DetailsPage.xaml
new file mode 100644
index 0000000..91c26cd
--- /dev/null
+++ b/ucalc/Pages/DetailsPage.xaml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/ucalc/Pages/DetailsPage.xaml.cs b/ucalc/Pages/DetailsPage.xaml.cs
new file mode 100644
index 0000000..4f1e050
--- /dev/null
+++ b/ucalc/Pages/DetailsPage.xaml.cs
@@ -0,0 +1,12 @@
+using System.Windows.Controls;
+
+namespace UCalc.Pages
+{
+ public partial class DetailsPage : Page
+ {
+ public DetailsPage()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Pages/HousePage.xaml b/ucalc/Pages/HousePage.xaml
new file mode 100644
index 0000000..2737663
--- /dev/null
+++ b/ucalc/Pages/HousePage.xaml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/ucalc/Pages/HousePage.xaml.cs b/ucalc/Pages/HousePage.xaml.cs
new file mode 100644
index 0000000..b2fba02
--- /dev/null
+++ b/ucalc/Pages/HousePage.xaml.cs
@@ -0,0 +1,10 @@
+namespace UCalc.Pages
+{
+ public partial class HousePage
+ {
+ public HousePage()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Pages/LandlordPage.xaml b/ucalc/Pages/LandlordPage.xaml
new file mode 100644
index 0000000..a6a4551
--- /dev/null
+++ b/ucalc/Pages/LandlordPage.xaml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/ucalc/Pages/LandlordPage.xaml.cs b/ucalc/Pages/LandlordPage.xaml.cs
new file mode 100644
index 0000000..34e8f1c
--- /dev/null
+++ b/ucalc/Pages/LandlordPage.xaml.cs
@@ -0,0 +1,12 @@
+using System.Windows.Controls;
+
+namespace UCalc.Pages
+{
+ public partial class LandlordPage : Page
+ {
+ public LandlordPage()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Pages/SideBar.xaml b/ucalc/Pages/SideBar.xaml
new file mode 100644
index 0000000..ce9faeb
--- /dev/null
+++ b/ucalc/Pages/SideBar.xaml
@@ -0,0 +1,253 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ucalc/Pages/SideBar.xaml.cs b/ucalc/Pages/SideBar.xaml.cs
new file mode 100644
index 0000000..3657988
--- /dev/null
+++ b/ucalc/Pages/SideBar.xaml.cs
@@ -0,0 +1,39 @@
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Controls;
+using UCalc.Controls;
+
+namespace UCalc.Pages
+{
+ public partial class SideBar
+ {
+ public TabControl TabControl { get; set; }
+
+ public SideBar()
+ {
+ InitializeComponent();
+ }
+
+ private void OnTabButtonClick(object sender, RoutedEventArgs e)
+ {
+ foreach (var button in ((Panel) ((HighlightButton) sender).Parent).FindChildren())
+ {
+ if (!ReferenceEquals(sender, button))
+ {
+ button.Selected = false;
+ }
+ }
+
+ var buttons = new List
+ {LandlordButton, HouseButton, TenantsButton, CostsButton, DetailsButton};
+ for (var i = 0; i < buttons.Count; ++i)
+ {
+ if (ReferenceEquals(sender, buttons[i]))
+ {
+ TabControl.SelectedIndex = i;
+ break;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/Pages/TenantsPage.xaml b/ucalc/Pages/TenantsPage.xaml
new file mode 100644
index 0000000..06942bf
--- /dev/null
+++ b/ucalc/Pages/TenantsPage.xaml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/ucalc/Pages/TenantsPage.xaml.cs b/ucalc/Pages/TenantsPage.xaml.cs
new file mode 100644
index 0000000..c7740f5
--- /dev/null
+++ b/ucalc/Pages/TenantsPage.xaml.cs
@@ -0,0 +1,12 @@
+using System.Windows.Controls;
+
+namespace UCalc.Pages
+{
+ public partial class TenantsPage : Page
+ {
+ public TenantsPage()
+ {
+ InitializeComponent();
+ }
+ }
+}
\ No newline at end of file
diff --git a/ucalc/ucalc.csproj b/ucalc/ucalc.csproj
index 006fba8..4aeb087 100644
--- a/ucalc/ucalc.csproj
+++ b/ucalc/ucalc.csproj
@@ -6,20 +6,58 @@
true
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
BillingWindow.xaml
+
+ SideBar.xaml
+
+
+ LandlordPage.xaml
+
+
+ HousePage.xaml
+
+
+ CostsPage.xaml
+
+
+ TenantsPage.xaml
+
+
+ DetailsPage.xaml
+
+
+ ErrorCounter.xaml
+
\ No newline at end of file