Initial Commit
This commit is contained in:
13
ViewModel/Dialogs/AddDepositViewModel.cs
Normal file
13
ViewModel/Dialogs/AddDepositViewModel.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using GalaSoft.MvvmLight;
|
||||
|
||||
namespace DebtMgr.ViewModel.Dialogs
|
||||
{
|
||||
public class AddTransactionViewModel : ViewModelBase
|
||||
{
|
||||
}
|
||||
}
|
||||
301
ViewModel/Dialogs/AddTransactionViewModel.cs
Normal file
301
ViewModel/Dialogs/AddTransactionViewModel.cs
Normal file
@@ -0,0 +1,301 @@
|
||||
using DebtMgr.Model;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using SQLiteNetExtensions.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace DebtMgr.ViewModel.Dialogs
|
||||
{
|
||||
public class AddTransactionViewModel : ViewModelBase
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public event EventHandler RequestClose;
|
||||
public TransactionType DialogMode { get; set; }
|
||||
|
||||
public Person PreselectedPerson { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region WindowTitle (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="WindowTitle" />
|
||||
/// </summary>
|
||||
private string _windowTitle;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string WindowTitle
|
||||
{
|
||||
get { return _windowTitle; }
|
||||
|
||||
set
|
||||
{
|
||||
_windowTitle = value;
|
||||
RaisePropertyChanged(() => WindowTitle);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AmountTextBoxText (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="AmountTextBoxText" />
|
||||
/// </summary>
|
||||
private string _amountTextBoxText;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string AmountTextBoxText
|
||||
{
|
||||
get
|
||||
{
|
||||
return _amountTextBoxText;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_amountTextBoxText = value;
|
||||
RaisePropertyChanged(() => AmountTextBoxText);
|
||||
AddTransactionButtonClickCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Gets the amount text box text as number representation. </summary>
|
||||
///
|
||||
/// <value> The amount text box text number representation. </value>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public double AmountTextBoxTextNumberRepresentation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_amountTextBoxText)) return 0.0;
|
||||
return double.Parse(_amountTextBoxText, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region DescriptionTextBoxText (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="DescriptionTextBoxText" />
|
||||
/// </summary>
|
||||
private string _descriptionTextBoxText;
|
||||
|
||||
/// <summary>
|
||||
/// DescriptionTextBoxText
|
||||
///</summary>
|
||||
public string DescriptionTextBoxText
|
||||
{
|
||||
get { return _descriptionTextBoxText; }
|
||||
|
||||
set
|
||||
{
|
||||
_descriptionTextBoxText = value;
|
||||
RaisePropertyChanged(() => DescriptionTextBoxText);
|
||||
AddTransactionButtonClickCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region DatePickerSelectedDate (DateTime?) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="DatePickerSelectedDate" />
|
||||
/// </summary>
|
||||
private DateTime? _datePickerSelectedDate;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public DateTime? DatePickerSelectedDate
|
||||
{
|
||||
get { return _datePickerSelectedDate; }
|
||||
|
||||
set
|
||||
{
|
||||
_datePickerSelectedDate = value;
|
||||
RaisePropertyChanged(() => DatePickerSelectedDate);
|
||||
AddTransactionButtonClickCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region PersonComboBoxItemSource (List<Person>) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="PersonComboBoxItemSource" />
|
||||
/// </summary>
|
||||
private List<Person> _personComboBoxItemSource;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public List<Person> PersonComboBoxItemSource
|
||||
{
|
||||
get { return _personComboBoxItemSource; }
|
||||
|
||||
set
|
||||
{
|
||||
_personComboBoxItemSource = value;
|
||||
RaisePropertyChanged(() => PersonComboBoxItemSource);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region PersonComboBoxSelectedItem (Person) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="PersonComboBoxSelectedItem" />
|
||||
/// </summary>
|
||||
private Person _personComboBoxSelectedItem;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public Person PersonComboBoxSelectedItem
|
||||
{
|
||||
get { return _personComboBoxSelectedItem; }
|
||||
|
||||
set
|
||||
{
|
||||
_personComboBoxSelectedItem = value;
|
||||
RaisePropertyChanged(() => PersonComboBoxSelectedItem);
|
||||
AddTransactionButtonClickCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddTransactionButtonClickCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="AddTransactionButtonClickCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _addTransactionButtonClickCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand AddTransactionButtonClickCommand => _addTransactionButtonClickCommand ?? (_addTransactionButtonClickCommand = new RelayCommand(AddTransactionButtonClickCommand_Execute, AddTransactionButtonClickCommand_CanExecute));
|
||||
|
||||
private bool AddTransactionButtonClickCommand_CanExecute()
|
||||
{
|
||||
if (AmountTextBoxTextNumberRepresentation < 0.01) return false;
|
||||
if (string.IsNullOrWhiteSpace(DescriptionTextBoxText)) return false;
|
||||
if (PersonComboBoxSelectedItem == null) return false;
|
||||
if (DatePickerSelectedDate == null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AddTransactionButtonClickCommand_Execute()
|
||||
{
|
||||
if (AddTransactionButtonClickCommand_CanExecute())
|
||||
{
|
||||
try
|
||||
{
|
||||
var person = App.Database.Get<Person>(PersonComboBoxSelectedItem.Id);
|
||||
App.Database.GetChildren(person);
|
||||
|
||||
if (DatePickerSelectedDate != null)
|
||||
person.Transactions.Add(new Transaction
|
||||
{
|
||||
Amount = AmountTextBoxTextNumberRepresentation,
|
||||
Type = DialogMode,
|
||||
Description = DescriptionTextBoxText,
|
||||
PersonId = person.Id,
|
||||
Time = DatePickerSelectedDate.Value
|
||||
});
|
||||
|
||||
App.Database.InsertOrReplaceWithChildren(person);
|
||||
RequestClose?.Invoke(null, null);
|
||||
App.Locator.MainView.UpdatePersonsList();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show("Something bad happened", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Default constructor. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 10.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public AddTransactionViewModel()
|
||||
{
|
||||
UpdatesPersonsComboBox();
|
||||
}
|
||||
|
||||
#region UpdatesPersonsComboBox()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Updates persons combo box. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 09.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public void UpdatesPersonsComboBox()
|
||||
{
|
||||
var personList = App.Database.Table<Person>().OrderBy(x => x.FirstName).ToList();
|
||||
PersonComboBoxItemSource = personList;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region SetModeSpecificStrings()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Sets mode specific strings. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 09.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public void SetModeSpecificStrings()
|
||||
{
|
||||
if (DialogMode == TransactionType.Deposit)
|
||||
{
|
||||
WindowTitle = "Add Deposit";
|
||||
}
|
||||
|
||||
if (DialogMode == TransactionType.Charge)
|
||||
{
|
||||
WindowTitle = "Add Charge";
|
||||
}
|
||||
|
||||
PersonComboBoxSelectedItem =
|
||||
PersonComboBoxItemSource.FirstOrDefault(x => x.Id == PreselectedPerson?.Id);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region ClearView()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Clears the view. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 09.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public void ClearView()
|
||||
{
|
||||
AmountTextBoxText = string.Empty;
|
||||
DescriptionTextBoxText = string.Empty;
|
||||
PersonComboBoxSelectedItem = null;
|
||||
DatePickerSelectedDate = DateTime.Now;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
124
ViewModel/Dialogs/DatabaseSelectorDialogViewModel.cs
Normal file
124
ViewModel/Dialogs/DatabaseSelectorDialogViewModel.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using DebtMgr.Model;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using Microsoft.Win32;
|
||||
using SQLite.Net;
|
||||
using SQLite.Net.Platform.Generic;
|
||||
|
||||
namespace DebtMgr.ViewModel.Dialogs
|
||||
{
|
||||
public class DatabaseSelectorDialogViewModel : ViewModelBase
|
||||
{
|
||||
public event EventHandler RequestClose;
|
||||
|
||||
#region SelectDatabasePathText (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="SelectDatabasePathText" />
|
||||
/// </summary>
|
||||
private string _selectDatabasePathText;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string SelectDatabasePathText
|
||||
{
|
||||
get { return _selectDatabasePathText; }
|
||||
|
||||
set
|
||||
{
|
||||
_selectDatabasePathText = value;
|
||||
RaisePropertyChanged(() => SelectDatabasePathText);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SelectDatabaseButtonClick Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="SelectDatabaseButtonClick" />
|
||||
/// </summary>
|
||||
private RelayCommand _selectDatabaseButtonClick = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand SelectDatabaseButtonClick => _selectDatabaseButtonClick ?? (_selectDatabaseButtonClick = new RelayCommand(SelectDatabaseButtonClick_Execute));
|
||||
|
||||
private void SelectDatabaseButtonClick_Execute()
|
||||
{
|
||||
var openFileDialog = new OpenFileDialog();
|
||||
openFileDialog.CheckFileExists = true;
|
||||
openFileDialog.Filter = "Debt Manager Database|*.dmdb|All files|*.*";
|
||||
|
||||
//Application.Current.Shutdown();
|
||||
|
||||
if (openFileDialog.ShowDialog() == true)
|
||||
{
|
||||
var x = new SQLiteConnection(new SQLitePlatformGeneric(), openFileDialog.FileName);
|
||||
|
||||
try
|
||||
{
|
||||
x.Table<Person>().ToList();
|
||||
|
||||
Properties.Settings.Default["Database"] = openFileDialog.FileName;
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
RequestClose?.Invoke(null, null);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show(
|
||||
string.Format("File is not a Debt Manager database\n\n{0}", openFileDialog.FileName),
|
||||
"File invalid",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
x.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region CreateDatabaseButtonClick Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="CreateDatabaseButtonClick" />
|
||||
/// </summary>
|
||||
private RelayCommand _createDatabaseButtonClick = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand CreateDatabaseButtonClick => _createDatabaseButtonClick ?? (_createDatabaseButtonClick = new RelayCommand(CreateDatabaseButtonClick_Execute));
|
||||
|
||||
private void CreateDatabaseButtonClick_Execute()
|
||||
{
|
||||
var saveFileDialog = new SaveFileDialog();
|
||||
saveFileDialog.Filter = "Debt Manager Database|*.dmdb|Standard database|*.db";
|
||||
saveFileDialog.CreatePrompt = true;
|
||||
|
||||
if (saveFileDialog.ShowDialog() == true)
|
||||
{
|
||||
Properties.Settings.Default["Database"] = saveFileDialog.FileName;
|
||||
Properties.Settings.Default.Save();
|
||||
|
||||
RequestClose?.Invoke(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
125
ViewModel/Dialogs/NewPersonDialogViewModel.cs
Normal file
125
ViewModel/Dialogs/NewPersonDialogViewModel.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using DebtMgr.Model;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
|
||||
namespace DebtMgr.ViewModel.Dialogs
|
||||
{
|
||||
public class NewPersonDialogViewModel : ViewModelBase
|
||||
{
|
||||
public event EventHandler RequestClose;
|
||||
|
||||
#region FirstNameTextBoxText (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="FirstNameTextBoxText" />
|
||||
/// </summary>
|
||||
private string _firstNameTextBoxText;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string FirstNameTextBoxText
|
||||
{
|
||||
get { return _firstNameTextBoxText; }
|
||||
|
||||
set
|
||||
{
|
||||
_firstNameTextBoxText = value;
|
||||
RaisePropertyChanged(() => FirstNameTextBoxText);
|
||||
CreatePersonButtonClickCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region LastNameTextBoxText (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="LastNameTextBoxText" />
|
||||
/// </summary>
|
||||
private string _lastNameTextBoxText;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string LastNameTextBoxText
|
||||
{
|
||||
get { return _lastNameTextBoxText; }
|
||||
|
||||
set
|
||||
{
|
||||
_lastNameTextBoxText = value;
|
||||
RaisePropertyChanged(() => LastNameTextBoxText);
|
||||
CreatePersonButtonClickCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CreatePersonButtonClickCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="CreatePersonButtonClickCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _createPersonButtonClickCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand CreatePersonButtonClickCommand => _createPersonButtonClickCommand ?? (_createPersonButtonClickCommand = new RelayCommand(CreatePersonButtonClickCommand_Execute, CreatePersonButtonClickCommand_CanExecute));
|
||||
|
||||
private bool CreatePersonButtonClickCommand_CanExecute()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(FirstNameTextBoxText) || string.IsNullOrWhiteSpace(LastNameTextBoxText))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CreatePersonButtonClickCommand_Execute()
|
||||
{
|
||||
if (CreatePersonButtonClickCommand_CanExecute())
|
||||
{
|
||||
var newPerson = new Person
|
||||
{
|
||||
FirstName = FirstNameTextBoxText,
|
||||
LastName = LastNameTextBoxText
|
||||
};
|
||||
|
||||
var resultId = App.Database.Insert(newPerson);
|
||||
|
||||
if (resultId == 1)
|
||||
{
|
||||
App.Locator.MainView.UpdatePersonsList();
|
||||
App.Locator.AddTransactionView.UpdatesPersonsComboBox();
|
||||
RequestClose?.Invoke(null, null);
|
||||
ClearView();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Something bad happened", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ClearView()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Clears the view. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 08.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private void ClearView()
|
||||
{
|
||||
FirstNameTextBoxText = string.Empty;
|
||||
LastNameTextBoxText = string.Empty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
488
ViewModel/MainViewModel.cs
Normal file
488
ViewModel/MainViewModel.cs
Normal file
@@ -0,0 +1,488 @@
|
||||
using DebtMgr.Model;
|
||||
using DebtMgr.View.Dialogs;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using SQLiteNetExtensions.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using SQLite.Net;
|
||||
using SQLite.Net.Platform.Generic;
|
||||
|
||||
namespace DebtMgr.ViewModel
|
||||
{
|
||||
public class MainViewModel : ViewModelBase
|
||||
{
|
||||
#region PersonListViewItemSource (List<Person>) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="PersonListViewItemSource" />
|
||||
/// </summary>
|
||||
private List<Person> _personListViewItemSource;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public List<Person> PersonListViewItemSource
|
||||
{
|
||||
get { return _personListViewItemSource; }
|
||||
|
||||
set
|
||||
{
|
||||
_personListViewItemSource = value;
|
||||
RaisePropertyChanged(() => PersonListViewItemSource);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region PersonListViewSelectedItem (Person) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="PersonListViewSelectedItem" />
|
||||
/// </summary>
|
||||
private Person _personListViewSelectedItem;
|
||||
|
||||
/// <summary>
|
||||
/// PersonListViewSelectedItem
|
||||
///</summary>
|
||||
public Person PersonListViewSelectedItem
|
||||
{
|
||||
get { return _personListViewSelectedItem; }
|
||||
|
||||
set
|
||||
{
|
||||
_personListViewSelectedItem = value;
|
||||
RaisePropertyChanged(() => PersonListViewSelectedItem);
|
||||
DeletePersonContextMenuCommand.RaiseCanExecuteChanged();
|
||||
|
||||
UpdateDetailView();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region DetailViewHeaderLabelContent (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="DetailViewHeaderLabelContent" />
|
||||
/// </summary>
|
||||
private string _detailViewHeaderLabelContent;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string DetailViewHeaderLabelContent
|
||||
{
|
||||
get { return _detailViewHeaderLabelContent; }
|
||||
|
||||
set
|
||||
{
|
||||
_detailViewHeaderLabelContent = value;
|
||||
RaisePropertyChanged(() => DetailViewHeaderLabelContent);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region DetailViewBalanceLabel (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="DetailViewBalanceLabel" />
|
||||
/// </summary>
|
||||
private string _detailViewBalanceLabel;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string DetailViewBalanceLabel
|
||||
{
|
||||
get { return _detailViewBalanceLabel; }
|
||||
|
||||
set
|
||||
{
|
||||
_detailViewBalanceLabel = value;
|
||||
RaisePropertyChanged(() => DetailViewBalanceLabel);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region OverallBalanceLabel (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="OverallBalanceLabel" />
|
||||
/// </summary>
|
||||
private string _overallBalanceLabel;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string OverallBalanceLabel
|
||||
{
|
||||
get { return _overallBalanceLabel; }
|
||||
|
||||
set
|
||||
{
|
||||
_overallBalanceLabel = value;
|
||||
RaisePropertyChanged(() => OverallBalanceLabel);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TransactionHistoryListViewItemSource (List<Transaction>) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="TransactionHistoryListViewItemSource" />
|
||||
/// </summary>
|
||||
private List<Transaction> _transactionHistoryListViewItemSource;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public List<Transaction> TransactionHistoryListViewItemSource
|
||||
{
|
||||
get { return _transactionHistoryListViewItemSource; }
|
||||
|
||||
set
|
||||
{
|
||||
_transactionHistoryListViewItemSource = value;
|
||||
RaisePropertyChanged(() => TransactionHistoryListViewItemSource);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region TransactionHistoryListViewSelectedItem (Transaction) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="TransactionHistoryListViewSelectedItem" />
|
||||
/// </summary>
|
||||
private Transaction _transactionHistoryListViewSelectedItem;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public Transaction TransactionHistoryListViewSelectedItem
|
||||
{
|
||||
get { return _transactionHistoryListViewSelectedItem; }
|
||||
|
||||
set
|
||||
{
|
||||
_transactionHistoryListViewSelectedItem = value;
|
||||
RaisePropertyChanged(() => TransactionHistoryListViewSelectedItem);
|
||||
DeleteTransactionContextMenuCommand.RaiseCanExecuteChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MenuNewPersonCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="MenuNewPersonCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _menuNewPersonCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand MenuNewPersonCommand => _menuNewPersonCommand ?? (_menuNewPersonCommand = new RelayCommand(MenuNewPersonCommand_Execute, MenuNewPersonCommand_CanExecute));
|
||||
|
||||
private bool MenuNewPersonCommand_CanExecute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private void MenuNewPersonCommand_Execute()
|
||||
{
|
||||
var window = new NewPersonDialogView();
|
||||
window.ShowDialog();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region SortPersonListViewCommand
|
||||
|
||||
/// <summary> The sort person list view command. </summary>
|
||||
private RelayCommand<string> _sortPersonListViewCommand = null;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Gets the sort person list view command. </summary>
|
||||
///
|
||||
/// <value> The sort person list view command. </value>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public RelayCommand<string> SortPersonListViewCommand
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_sortPersonListViewCommand == null)
|
||||
_sortPersonListViewCommand = new RelayCommand<string>(SortPersonListViewCommand_Execute);
|
||||
|
||||
return _sortPersonListViewCommand;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Sort person list view command execute. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 08.09.2017. </remarks>
|
||||
///
|
||||
/// <param name="columnName"> Name of the column. </param>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private void SortPersonListViewCommand_Execute(string columnName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(columnName)) return;
|
||||
|
||||
switch (columnName)
|
||||
{
|
||||
case "FirstName":
|
||||
PersonListViewItemSource = PersonListViewItemSource.OrderBy(x => x.FirstName).ToList();
|
||||
break;
|
||||
case "LastName":
|
||||
PersonListViewItemSource = PersonListViewItemSource.OrderBy(x => x.LastName).ToList();
|
||||
break;
|
||||
case "Total":
|
||||
PersonListViewItemSource = PersonListViewItemSource.OrderBy(x => x.Total).ToList();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AddChargeContextMenuCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="AddChargeContextMenuCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _addChargeContextMenuCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand AddChargeContextMenuCommand => _addChargeContextMenuCommand ?? (_addChargeContextMenuCommand = new RelayCommand(AddChargeContextMenuCommand_Execute));
|
||||
|
||||
private void AddChargeContextMenuCommand_Execute()
|
||||
{
|
||||
var window = new AddTransactionView(TransactionType.Charge, PersonListViewSelectedItem);
|
||||
window.ShowDialog();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region AddDepositContextMenuCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="AddDepositContextMenuCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _addDepositContextMenuCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand AddDepositContextMenuCommand => _addDepositContextMenuCommand ?? (_addDepositContextMenuCommand = new RelayCommand(AddDepositContextMenuCommand_Execute));
|
||||
|
||||
private void AddDepositContextMenuCommand_Execute()
|
||||
{
|
||||
var window = new AddTransactionView(TransactionType.Deposit, PersonListViewSelectedItem);
|
||||
window.ShowDialog();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region NewPersonContextMenuCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="NewPersonContextMenuCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _newPersonContextMenuCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand NewPersonContextMenuCommand => _newPersonContextMenuCommand ?? (_newPersonContextMenuCommand = new RelayCommand(NewPersonContextMenuCommand_Execute));
|
||||
|
||||
private void NewPersonContextMenuCommand_Execute()
|
||||
{
|
||||
var window = new NewPersonDialogView();
|
||||
window.ShowDialog();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region DeletePersonContextMenuCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="DeletePersonContextMenuCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _deletePersonContextMenuCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand DeletePersonContextMenuCommand => _deletePersonContextMenuCommand ?? (_deletePersonContextMenuCommand = new RelayCommand(DeletePersonContextMenuCommand_Execute, DeletePersonContextMenuCommand_CanExecute));
|
||||
|
||||
private bool DeletePersonContextMenuCommand_CanExecute()
|
||||
{
|
||||
if (PersonListViewSelectedItem != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DeletePersonContextMenuCommand_Execute()
|
||||
{
|
||||
if (PersonListViewSelectedItem == null) return;
|
||||
|
||||
var result = MessageBox.Show(
|
||||
string.Format(
|
||||
"Are you sure to delete?\n\n{0} {1}",
|
||||
PersonListViewSelectedItem.FirstName,
|
||||
PersonListViewSelectedItem.LastName),
|
||||
"Delete Person",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
App.Database.Delete<Person>(PersonListViewSelectedItem.Id);
|
||||
UpdatePersonsList();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DeleteTransactionContextMenuCommand Command
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="DeleteTransactionContextMenuCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _deleteTransactionContextMenuCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
public RelayCommand DeleteTransactionContextMenuCommand => _deleteTransactionContextMenuCommand ?? (_deleteTransactionContextMenuCommand = new RelayCommand(DeleteTransactionContextMenuCommand_Execute, DeleteTransactionContextMenuCommand_CanExecute));
|
||||
|
||||
private bool DeleteTransactionContextMenuCommand_CanExecute()
|
||||
{
|
||||
if (TransactionHistoryListViewSelectedItem != null)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DeleteTransactionContextMenuCommand_Execute()
|
||||
{
|
||||
if (TransactionHistoryListViewSelectedItem == null) return;
|
||||
|
||||
var result = MessageBox.Show(
|
||||
string.Format(
|
||||
"Are you sure to delete?\n\n{1} <20>\n{0}",
|
||||
TransactionHistoryListViewSelectedItem.Description,
|
||||
TransactionHistoryListViewSelectedItem.Amount),
|
||||
"Delete Transaction",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
App.Database.Delete<Transaction>(TransactionHistoryListViewSelectedItem.Id);
|
||||
UpdatePersonsList();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Initializes a new instance of the MainViewModel class. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 10.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public MainViewModel()
|
||||
{
|
||||
CheckDatabase();
|
||||
|
||||
UpdatePersonsList();
|
||||
UpdateDetailView();
|
||||
}
|
||||
|
||||
#region UpdatePersonsList()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Updates the persons list. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 08.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public void UpdatePersonsList()
|
||||
{
|
||||
// Remember selection
|
||||
var rememberSelection = PersonListViewSelectedItem?.Id;
|
||||
|
||||
var personList = App.Database.GetAllWithChildren<Person>();
|
||||
PersonListViewItemSource = personList;
|
||||
|
||||
var overallBalance = personList.Sum(x => x.Total);
|
||||
OverallBalanceLabel = overallBalance.ToString();
|
||||
|
||||
// Restore selection
|
||||
if (rememberSelection != null && PersonListViewItemSource.Any(x => x.Id == rememberSelection))
|
||||
PersonListViewSelectedItem = PersonListViewItemSource.First(x => x.Id == rememberSelection);
|
||||
|
||||
UpdateDetailView();
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region UpdateDetailView()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Updates the detail view. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 10.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private void UpdateDetailView()
|
||||
{
|
||||
if (PersonListViewSelectedItem == null)
|
||||
{
|
||||
DetailViewHeaderLabelContent = string.Empty;
|
||||
DetailViewBalanceLabel = string.Empty;
|
||||
TransactionHistoryListViewItemSource = null;
|
||||
return;
|
||||
};
|
||||
|
||||
DetailViewHeaderLabelContent = string.Format("{0} {1}", PersonListViewSelectedItem.FirstName,
|
||||
PersonListViewSelectedItem.LastName);
|
||||
DetailViewBalanceLabel = PersonListViewSelectedItem.Total.ToString();
|
||||
|
||||
TransactionHistoryListViewItemSource = PersonListViewSelectedItem.Transactions.OrderByDescending(x => x.Time).ToList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CheckDatabase()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Check database. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 10.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private void CheckDatabase()
|
||||
{
|
||||
var databasePath = Properties.Settings.Default.Database;
|
||||
if (string.IsNullOrWhiteSpace(databasePath))
|
||||
{
|
||||
var window = new DatabaseSelectorDialogView();
|
||||
var result = window.ShowDialog();
|
||||
}
|
||||
|
||||
// Check if provided file path is a valid database
|
||||
try
|
||||
{
|
||||
App.Database.Table<Person>();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Properties.Settings.Default["Database"] = string.Empty;
|
||||
CheckDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
61
ViewModel/ViewModelLocator.cs
Normal file
61
ViewModel/ViewModelLocator.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
In App.xaml:
|
||||
<Application.Resources>
|
||||
<vm:ViewModelLocator xmlns:vm="clr-namespace:DebtMgr"
|
||||
x:Key="Locator" />
|
||||
</Application.Resources>
|
||||
|
||||
In the View:
|
||||
DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}"
|
||||
|
||||
You can also use Blend to do all this with the tool's support.
|
||||
See http://www.galasoft.ch/mvvm
|
||||
*/
|
||||
|
||||
using DebtMgr.ViewModel.Dialogs;
|
||||
using GalaSoft.MvvmLight.Ioc;
|
||||
using Microsoft.Practices.ServiceLocation;
|
||||
|
||||
namespace DebtMgr.ViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains static references to all the view models in the
|
||||
/// application and provides an entry point for the bindings.
|
||||
/// </summary>
|
||||
public class ViewModelLocator
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ViewModelLocator class.
|
||||
/// </summary>
|
||||
public ViewModelLocator()
|
||||
{
|
||||
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
|
||||
|
||||
////if (ViewModelBase.IsInDesignModeStatic)
|
||||
////{
|
||||
//// // Create design time view services and models
|
||||
//// SimpleIoc.Default.Register<IDataService, DesignDataService>();
|
||||
////}
|
||||
////else
|
||||
////{
|
||||
//// // Create run time view services and models
|
||||
//// SimpleIoc.Default.Register<IDataService, DataService>();
|
||||
////}
|
||||
|
||||
SimpleIoc.Default.Register<MainViewModel>();
|
||||
SimpleIoc.Default.Register<NewPersonDialogViewModel>();
|
||||
SimpleIoc.Default.Register<AddTransactionViewModel>();
|
||||
SimpleIoc.Default.Register<DatabaseSelectorDialogViewModel>();
|
||||
}
|
||||
|
||||
public MainViewModel MainView => ServiceLocator.Current.GetInstance<MainViewModel>();
|
||||
public NewPersonDialogViewModel NewPersonDialogView => ServiceLocator.Current.GetInstance<NewPersonDialogViewModel>();
|
||||
public AddTransactionViewModel AddTransactionView => ServiceLocator.Current.GetInstance<AddTransactionViewModel>();
|
||||
public DatabaseSelectorDialogViewModel DatabaseSelectorDialogView => ServiceLocator.Current.GetInstance<DatabaseSelectorDialogViewModel>();
|
||||
|
||||
public static void Cleanup()
|
||||
{
|
||||
// TODO Clear the ViewModels
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user