Skip to content

Commit

Permalink
Recipes wizard (#7)
Browse files Browse the repository at this point in the history
* Fixed logging

* Change flies structure

* Added recipes dialog

* Added projects column

* Highlight expanse with no category

* Split VM and DTO

* Highlight active items

* Clean code

Co-authored-by: vov4uk <[email protected]>
  • Loading branch information
vov4uk and vov4uk authored Nov 4, 2021
1 parent a1fe494 commit d93e69e
Show file tree
Hide file tree
Showing 93 changed files with 2,289 additions and 1,287 deletions.
2 changes: 1 addition & 1 deletion src/Financier.DataAccess/Data/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Financier.DataAccess.Data
{
[DebuggerDisplay("{Title}")]
[Table(Backup.ACCOUNT_TABLE)]
public class Account : Entity, IIdentity
public class Account : Entity, IActive
{
[Column(IdColumn)]
public int Id { get; set; } = -1;
Expand Down
9 changes: 9 additions & 0 deletions src/Financier.DataAccess/Data/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,14 @@ public class Category : Entity, IIdentity
Right = 2,
Title = "<NO_CATEGORY>"
};

[NotMapped]
public static Category Split = new Category()
{
Id = -1,
Left = 0,
Right = 0,
Title = "<SPLIT_CATEGORY>"
};
}
}
9 changes: 9 additions & 0 deletions src/Financier.DataAccess/Data/IActive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Financier.DataAccess.Data
{
public interface IActive : IIdentity
{
bool IsActive { get; set; }

string Title { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Financier.DataAccess/Data/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Financier.DataAccess.Data
{
[DebuggerDisplay("{Title}")]
[Table(Backup.LOCATIONS_TABLE)]
public class Location : Entity, IIdentity
public class Location : Entity, IActive
{
[Column(IdColumn)]
public int Id { get; set; } = -1;

[Column(IsActiveColumn)]
public bool? IsActive { get; set; } = true;
public bool IsActive { get; set; } = true;

[Column(TitleColumn)]
public string Title { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Financier.DataAccess/Data/Payee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Financier.DataAccess.Data
{
[DebuggerDisplay("{Title}")]
[Table(Backup.PAYEE_TABLE)]
public class Payee : Entity, IIdentity
public class Payee : Entity, IActive
{
[Column(IdColumn)]
public int Id { get; set; } = -1;
Expand Down
4 changes: 2 additions & 2 deletions src/Financier.DataAccess/Data/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Financier.DataAccess.Data
{
[DebuggerDisplay("{Title}")]
[Table(Backup.PROJECT_TABLE)]
public class Project : Entity, IIdentity
public class Project : Entity, IActive
{
[Column(IdColumn)]
public int Id { get; set; } = -1;

[Column(IsActiveColumn)]
public bool? IsActive { get; set; } = true;
public bool IsActive { get; set; } = true;

[Column(TitleColumn)]
public string Title { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Financier.DataAccess/Data/SmsTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Financier.DataAccess.Data
{
[Table(Backup.SMS_TEMPLATES_TABLE)]
public class SmsTemplate : Entity
public class SmsTemplate : Entity, IActive
{
[Column(IdColumn)]
public int Id { get; set; } = -1;
Expand Down
10 changes: 5 additions & 5 deletions src/Financier.DataAccess/Utils/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Financier.DataAccess.Utils
{
public static class Utils
{
public static decimal HUNDRED = new Decimal(100);
public static decimal HUNDRED = new decimal(100);
public static string TRANSFER_DELIMITER = " \u00BB ";

public static string SetAmountText(Currency c, long amount, bool addPlus)
Expand All @@ -26,12 +26,12 @@ public static string SetAmountText(Currency originalCurrency, long originalAmoun
return sb.ToString();
}

public static String AmountToString(Currency c, long amount)
public static string AmountToString(Currency c, long amount)
{
return AmountToString(c, amount, false);
}

public static String AmountToString(Currency c, decimal amount)
public static string AmountToString(Currency c, decimal amount)
{
StringBuilder sb = new StringBuilder();
return AmountToString(sb, c, amount, false).ToString();
Expand Down Expand Up @@ -66,7 +66,7 @@ public static StringBuilder AmountToString(StringBuilder sb, Currency c, decimal
{
c = Currency.Empty;
}
String s = (amount / HUNDRED).ToString("F2");
string s = (amount / HUNDRED).ToString("F2");
if (s.EndsWith("."))
{
s = s.Substring(0, s.Length - 1);
Expand All @@ -79,7 +79,7 @@ public static StringBuilder AmountToString(StringBuilder sb, Currency c, decimal
return sb;
}

public static String GetTransferAmountText(Currency fromCurrency, long fromAmount, Currency toCurrency, long toAmount)
public static string GetTransferAmountText(Currency fromCurrency, long fromAmount, Currency toCurrency, long toAmount)
{
var sb = new StringBuilder();
if (SameCurrency(fromCurrency, toCurrency))
Expand Down
3 changes: 3 additions & 0 deletions src/Financier.DataAccess/View/TransactionsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,8 @@ public string BalanceTitle
return Utils.Utils.SetAmountText(from_account_currency, from_account_balance ?? 0, false);
}
}

[NotMapped]
public bool HasNoCategory => Type == "Expense" && category_id == 0;
}
}
37 changes: 36 additions & 1 deletion src/Financier.Desktop/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Windows;
using NLog;
using System;
using System.Threading.Tasks;
using System.Windows;

namespace Financier.Desktop
{
Expand All @@ -7,5 +10,37 @@ namespace Financier.Desktop
/// </summary>
public partial class App : Application
{
private static Logger _logger = LogManager.GetCurrentClassLogger();

protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);

SetupExceptionHandling();
}

private void SetupExceptionHandling()
{
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
LogUnhandledException((Exception)e.ExceptionObject);

DispatcherUnhandledException += (s, e) =>
{
LogUnhandledException(e.Exception);
e.Handled = true;
};

TaskScheduler.UnobservedTaskException += (s, e) =>
{
LogUnhandledException(e.Exception);
e.SetObserved();
};
}

private void LogUnhandledException(Exception exception)
{
MessageBox.Show(exception.Message);
_logger.Error(exception);
}
}
}
20 changes: 20 additions & 0 deletions src/Financier.Desktop/Assets/Generic.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:Financier.DataAccess.Data;assembly=Financier.DataAccess">

<DataTemplate DataType="{x:Type data:IActive}" x:Key="IActive">
<TextBlock x:Name="Txt" Text="{Binding Title}" Foreground="DarkGreen" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsActive}" Value="False">
<DataTrigger.Setters>
<Setter TargetName="Txt" Property="Foreground" Value="DarkRed"/>
</DataTrigger.Setters>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type data:Category}" x:Key="CategoryTemplate">
<emoji:TextBlock x:Name="Txt" Text="{Binding Title}"/>
</DataTemplate>

</ResourceDictionary>
7 changes: 4 additions & 3 deletions src/Financier.Desktop/Assets/Resource.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ViewModel="clr-namespace:Financier.Desktop.ViewModel"
xmlns:View="clr-namespace:Financier.Desktop.Entities">
xmlns:ViewModel="clr-namespace:Financier.Desktop.ViewModel"
xmlns:Report="clr-namespace:Financier.Desktop.Reports.ViewModel"
xmlns:View="clr-namespace:Financier.Desktop.Views">

<DataTemplate DataType="{x:Type ViewModel:AccountsVM}">
<View:Accounts/>
Expand Down Expand Up @@ -33,7 +34,7 @@
<DataTemplate DataType="{x:Type ViewModel:InfoVM}">
<View:InfoControl/>
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModel:ReportVM}">
<DataTemplate DataType="{x:Type Report:ReportVM}">
<View:Report/>
</DataTemplate>

Expand Down
4 changes: 2 additions & 2 deletions src/Financier.Desktop/Financier.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@
<PackageReference Include="DataGridExtensions" Version="2.6.0-beta1" />
<PackageReference Include="DotNetProjects.Extended.Wpf.Toolkit" Version="4.6.97" />
<PackageReference Include="Emoji.Wpf" Version="0.3.3" />
<PackageReference Include="Humanizer.Core" Version="2.11.10" />
<PackageReference Include="NLog" Version="4.7.10" />
<PackageReference Include="NLog" Version="5.0.0-preview.2" />
<PackageReference Include="Prism.Core" Version="8.1.97" />
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
<PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions src/Financier.Desktop/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Financier.Desktop.MonoWizard.View;
using Financier.Desktop.MonoWizard.ViewModel;
using Financier.Desktop.ViewModel;
using Financier.Adapter;
Expand All @@ -9,6 +8,7 @@
using System.Windows.Controls.Ribbon;
using System.Windows.Forms;
using DataFormats = System.Windows.DataFormats;
using Financier.Desktop.Wizards;

namespace Financier.Desktop
{
Expand All @@ -33,7 +33,6 @@ static MainWindow()

public MainWindow()
{
AppDomain.CurrentDomain.UnhandledException += (_, e ) => Logger.Error((Exception)e.ExceptionObject);
InitializeComponent();
VM = new FinancierVM();

Expand Down Expand Up @@ -75,14 +74,15 @@ private async void Mono_Click(object sender, RoutedEventArgs e)
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
var fileName = openFileDialog.FileName;
var dialog = new MonoWizardWindow();
var dialog = new WizardWindow();

var accounts = VM.Pages.OfType<AccountsVM>().First().Entities.ToList();
var currencies = VM.Pages.OfType<CurrenciesVM>().First().Entities.ToList();
var locations = VM.Pages.OfType<LocationsVM>().First().Entities.ToList();
var categories = VM.Pages.OfType<CategoriesVM>().First().Entities.ToList();
var projects = VM.Pages.OfType<ProjectsVM>().First().Entities.ToList();

var viewModel = new MonoWizardViewModel(accounts, currencies, locations, categories, fileName);
var viewModel = new MonoWizardVM(accounts, currencies, locations, categories, projects, fileName);
await viewModel.LoadTransactions();
viewModel.RequestClose += async (o, args) =>
{
Expand Down
27 changes: 0 additions & 27 deletions src/Financier.Desktop/MonoWizard/Assets/Resource.xaml

This file was deleted.

Loading

0 comments on commit d93e69e

Please sign in to comment.