diff --git a/Model/Enums.cs b/Model/Enums.cs
index c51cd62..fe4b092 100644
--- a/Model/Enums.cs
+++ b/Model/Enums.cs
@@ -16,4 +16,15 @@ namespace DebtMgr.Model
[Description("Charge")]
Charge
}
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
+ /// Values that represent person dialog modes.
+ ///
+ /// Andre Beging, 12.09.2017.
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
+ public enum PersonDialogMode
+ {
+ New,
+ Edit
+ }
}
diff --git a/View/Dialogs/AddTransactionView.xaml.cs b/View/Dialogs/AddTransactionView.xaml.cs
index 7b35f70..6a0bfa8 100644
--- a/View/Dialogs/AddTransactionView.xaml.cs
+++ b/View/Dialogs/AddTransactionView.xaml.cs
@@ -24,10 +24,6 @@ namespace DebtMgr.View.Dialogs
App.Locator.AddTransactionView.RequestClose += (s, e) => Close();
DataContext = App.Locator.AddTransactionView;
-
- //Uri iconUri = new Uri("pack://application:,,,/Content/money_red.ico", UriKind.RelativeOrAbsolute);
-
- //this.Icon = BitmapFrame.Create(iconUri);
}
#region TextBox_OnKeyUp()
diff --git a/View/Dialogs/NewPersonDialogView.xaml b/View/Dialogs/NewPersonDialogView.xaml
index fc3bd5f..26247aa 100644
--- a/View/Dialogs/NewPersonDialogView.xaml
+++ b/View/Dialogs/NewPersonDialogView.xaml
@@ -7,7 +7,7 @@
mc:Ignorable="d"
Name="NewPersonDialogViewWindow"
Icon="../../Content/addperson.ico"
- Title="New Person" Height="205" Width="300"
+ Title="{Binding WindowTitle}" Height="205" Width="300"
KeyUp="Window_KeyUp">
@@ -16,7 +16,7 @@
-
+
@@ -30,7 +30,7 @@
-
+
diff --git a/View/Dialogs/NewPersonDialogView.xaml.cs b/View/Dialogs/NewPersonDialogView.xaml.cs
index 146d0fd..1e779c2 100644
--- a/View/Dialogs/NewPersonDialogView.xaml.cs
+++ b/View/Dialogs/NewPersonDialogView.xaml.cs
@@ -1,6 +1,8 @@
-using System.Windows;
+using System;
+using System.Windows;
using System.Windows.Input;
using DebtMgr.Extensions;
+using DebtMgr.Model;
namespace DebtMgr.View.Dialogs
{
@@ -9,17 +11,24 @@ namespace DebtMgr.View.Dialogs
///
public partial class NewPersonDialogView : Window
{
- public NewPersonDialogView()
+ public NewPersonDialogView(PersonDialogMode mode, Guid personId = default(Guid))
{
InitializeComponent();
this.CenterOnParent();
+ App.Locator.NewPersonDialogView.ClearView();
+ App.Locator.NewPersonDialogView.DialogMode = mode;
+ App.Locator.NewPersonDialogView.EditPersonId = personId;
+ App.Locator.NewPersonDialogView.SetModeSpecifics();
+
App.Locator.NewPersonDialogView.RequestClose += (s, e) => Close();
DataContext = App.Locator.NewPersonDialogView;
FirstNameTextBox.Focus();
}
+ #region TextBox_OnKeyUp()
+
////////////////////////////////////////////////////////////////////////////////////////////////////
/// Event handler. Called by TextBox for on key up events.
///
@@ -34,6 +43,10 @@ namespace DebtMgr.View.Dialogs
App.Locator.NewPersonDialogView.CreatePersonButtonClickCommand.Execute(null);
}
+ #endregion
+
+ #region Window_KeyUp()
+
////////////////////////////////////////////////////////////////////////////////////////////////////
/// Event handler. Called by Window for key up events.
///
@@ -47,5 +60,7 @@ namespace DebtMgr.View.Dialogs
if (e.Key.Equals(Key.Escape))
Close();
}
+
+ #endregion
}
}
diff --git a/View/MainView.xaml b/View/MainView.xaml
index 14ab1e6..1cc9982 100644
--- a/View/MainView.xaml
+++ b/View/MainView.xaml
@@ -57,7 +57,7 @@
@@ -82,10 +82,12 @@
-
-
-
-
+
+
+
+
+
+
@@ -122,10 +124,10 @@
@@ -149,10 +151,11 @@
-
-
-
+
+
+
+
diff --git a/ViewModel/Dialogs/DatabaseSelectorDialogViewModel.cs b/ViewModel/Dialogs/DatabaseSelectorDialogViewModel.cs
index 7e009f6..b14869f 100644
--- a/ViewModel/Dialogs/DatabaseSelectorDialogViewModel.cs
+++ b/ViewModel/Dialogs/DatabaseSelectorDialogViewModel.cs
@@ -12,9 +12,13 @@ namespace DebtMgr.ViewModel.Dialogs
{
public class DatabaseSelectorDialogViewModel : ViewModelBase
{
+ #region Public Properties
+
public event EventHandler RequestClose;
public bool ProgramRequestedClose;
+ #endregion
+
#region SelectDatabasePathText (string) Property
///
diff --git a/ViewModel/Dialogs/NewPersonDialogViewModel.cs b/ViewModel/Dialogs/NewPersonDialogViewModel.cs
index e4da540..411ffb0 100644
--- a/ViewModel/Dialogs/NewPersonDialogViewModel.cs
+++ b/ViewModel/Dialogs/NewPersonDialogViewModel.cs
@@ -8,7 +8,59 @@ namespace DebtMgr.ViewModel.Dialogs
{
public class NewPersonDialogViewModel : ViewModelBase
{
+ #region Public Properties
+
public event EventHandler RequestClose;
+ public PersonDialogMode DialogMode { get; set; }
+ public Guid EditPersonId { get; set; }
+ public Person EditPerson { get; set; }
+
+ #endregion
+
+ #region WindowTitle (string) Property
+
+ ///
+ /// Privater Teil von
+ ///
+ private string _windowTitle;
+
+ ///
+ /// Comment
+ ///
+ public string WindowTitle
+ {
+ get { return _windowTitle; }
+
+ set
+ {
+ _windowTitle = value;
+ RaisePropertyChanged(() => WindowTitle);
+ }
+ }
+
+ #endregion
+ #region SaveButtonText (string) Property
+
+ ///
+ /// Privater Teil von
+ ///
+ private string _saveButtonText;
+
+ ///
+ /// Comment
+ ///
+ public string SaveButtonText
+ {
+ get { return _saveButtonText; }
+
+ set
+ {
+ _saveButtonText = value;
+ RaisePropertyChanged(() => SaveButtonText);
+ }
+ }
+
+ #endregion
#region FirstNameTextBoxText (string) Property
@@ -82,20 +134,32 @@ namespace DebtMgr.ViewModel.Dialogs
{
if (CreatePersonButtonClickCommand_CanExecute())
{
- var newPerson = new Person
+ bool success = false;
+ if (DialogMode == PersonDialogMode.New)
{
- FirstName = FirstNameTextBoxText,
- LastName = LastNameTextBoxText
- };
+ var newPerson = new Person
+ {
+ FirstName = FirstNameTextBoxText,
+ LastName = LastNameTextBoxText
+ };
- var resultId = App.Database.Insert(newPerson);
+ if (App.Database.Insert(newPerson) == 1)
+ success = true;
+ }
- if (resultId == 1)
+ if (DialogMode == PersonDialogMode.Edit)
+ {
+ EditPerson.FirstName = FirstNameTextBoxText;
+ EditPerson.LastName = LastNameTextBoxText;
+ if(App.Database.InsertOrReplace(EditPerson) == 1)
+ success = true;
+ }
+
+ if (success)
{
App.Locator.MainView.UpdatePersonsList();
App.Locator.AddTransactionView.UpdatesPersonsComboBox();
RequestClose?.Invoke(null, null);
- ClearView();
}
else
{
@@ -106,6 +170,38 @@ namespace DebtMgr.ViewModel.Dialogs
#endregion
+ #region SetModeSpecifics()
+
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
+ /// Sets mode specifics.
+ ///
+ /// Andre Beging, 12.09.2017.
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
+ public void SetModeSpecifics()
+ {
+ if (DialogMode != PersonDialogMode.Edit || EditPersonId == Guid.Empty)
+ {
+ ClearView();
+ return;
+ }
+
+ // edit mode
+ EditPerson = App.Database.Get(EditPersonId);
+
+ if (EditPerson == null)
+ {
+ ClearView();
+ return;
+ }
+
+ FirstNameTextBoxText = EditPerson.FirstName;
+ LastNameTextBoxText = EditPerson.LastName;
+ WindowTitle = "Edit Person";
+ SaveButtonText = "Save";
+ }
+
+ #endregion
+
#region ClearView()
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -113,10 +209,14 @@ namespace DebtMgr.ViewModel.Dialogs
///
/// Andre Beging, 08.09.2017.
////////////////////////////////////////////////////////////////////////////////////////////////////
- private void ClearView()
+ public void ClearView()
{
FirstNameTextBoxText = string.Empty;
LastNameTextBoxText = string.Empty;
+ DialogMode = PersonDialogMode.New;
+ WindowTitle = "New Person";
+ SaveButtonText = "Create";
+ EditPersonId = Guid.Empty;
}
#endregion
diff --git a/ViewModel/MainViewModel.cs b/ViewModel/MainViewModel.cs
index 956f1f7..5895389 100644
--- a/ViewModel/MainViewModel.cs
+++ b/ViewModel/MainViewModel.cs
@@ -56,6 +56,7 @@ namespace DebtMgr.ViewModel
_personListViewSelectedItem = value;
RaisePropertyChanged(() => PersonListViewSelectedItem);
DeletePersonContextMenuCommand.RaiseCanExecuteChanged();
+ EditPersonContextMenuCommand.RaiseCanExecuteChanged();
UpdateDetailView();
}
@@ -180,30 +181,6 @@ namespace DebtMgr.ViewModel
#endregion
- #region MenuNewPersonCommand Command
-
- ///
- /// Private member backing variable for
- ///
- private RelayCommand _menuNewPersonCommand = null;
-
- ///
- /// Comment
- ///
- 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
/// The sort person list view command.
@@ -262,7 +239,14 @@ namespace DebtMgr.ViewModel
///
/// Comment
///
- public RelayCommand AddChargeContextMenuCommand => _addChargeContextMenuCommand ?? (_addChargeContextMenuCommand = new RelayCommand(AddChargeContextMenuCommand_Execute));
+ public RelayCommand AddChargeContextMenuCommand => _addChargeContextMenuCommand ?? (_addChargeContextMenuCommand = new RelayCommand(AddChargeContextMenuCommand_Execute, AddChargeContextMenuCommand_CanExecute));
+
+ private bool AddChargeContextMenuCommand_CanExecute()
+ {
+ if (PersonListViewItemSource != null & PersonListViewItemSource.Count > 0)
+ return true;
+ return false;
+ }
private void AddChargeContextMenuCommand_Execute()
{
@@ -281,7 +265,14 @@ namespace DebtMgr.ViewModel
///
/// Comment
///
- public RelayCommand AddDepositContextMenuCommand => _addDepositContextMenuCommand ?? (_addDepositContextMenuCommand = new RelayCommand(AddDepositContextMenuCommand_Execute));
+ public RelayCommand AddDepositContextMenuCommand => _addDepositContextMenuCommand ?? (_addDepositContextMenuCommand = new RelayCommand(AddDepositContextMenuCommand_Execute, AddDepositContextMenuCommand_CanExecute));
+
+ private bool AddDepositContextMenuCommand_CanExecute()
+ {
+ if (PersonListViewItemSource != null & PersonListViewItemSource.Count > 0)
+ return true;
+ return false;
+ }
private void AddDepositContextMenuCommand_Execute()
{
@@ -304,10 +295,41 @@ namespace DebtMgr.ViewModel
private void NewPersonContextMenuCommand_Execute()
{
- var window = new NewPersonDialogView();
+ var window = new NewPersonDialogView(PersonDialogMode.New);
window.ShowDialog();
}
+ #endregion
+
+ #region EditPersonContextMenuCommand Command
+
+ ///
+ /// Private member backing variable for
+ ///
+ private RelayCommand _editPersonContextMenuCommand = null;
+
+ ///
+ /// Comment
+ ///
+ public RelayCommand EditPersonContextMenuCommand => _editPersonContextMenuCommand ?? (_editPersonContextMenuCommand = new RelayCommand(EditPersonContextMenuCommand_Execute, EditPersonContextMenuCommand_CanExecute));
+
+ private bool EditPersonContextMenuCommand_CanExecute()
+ {
+ if (PersonListViewSelectedItem != null)
+ return true;
+ return false;
+ }
+
+ private void EditPersonContextMenuCommand_Execute()
+ {
+ if (PersonListViewSelectedItem != null)
+ {
+ var window = new NewPersonDialogView(PersonDialogMode.Edit, PersonListViewSelectedItem.Id);
+ window.ShowDialog();
+ }
+
+ }
+
#endregion
#region DeletePersonContextMenuCommand Command
@@ -334,7 +356,7 @@ namespace DebtMgr.ViewModel
var result = MessageBox.Show(
string.Format(
- "Are you sure to delete?\n\n{0} {1}",
+ "Are you sure to delete this person including all transactions?\n\n{0} {1}",
PersonListViewSelectedItem.FirstName,
PersonListViewSelectedItem.LastName),
"Delete Person",
@@ -376,10 +398,13 @@ namespace DebtMgr.ViewModel
var result = MessageBox.Show(
string.Format(
- "Are you sure to delete?\n\n{1} €\n{0}",
- TransactionHistoryListViewSelectedItem.Description,
- TransactionHistoryListViewSelectedItem.Amount),
- "Delete Transaction",
+ "Are you sure to delete this {0}?\n\n{1} {2}\nAmount: {3} €\n{4}",
+ TransactionHistoryListViewSelectedItem.Type,
+ TransactionHistoryListViewSelectedItem.Person.FirstName,
+ TransactionHistoryListViewSelectedItem.Person.LastName,
+ TransactionHistoryListViewSelectedItem.Amount,
+ TransactionHistoryListViewSelectedItem.Description),
+ string.Format("Delete {0}", TransactionHistoryListViewSelectedItem.Type),
MessageBoxButton.YesNo,
MessageBoxImage.Question);
@@ -497,6 +522,9 @@ namespace DebtMgr.ViewModel
var overallBalance = personList.Sum(x => x.Total);
OverallBalanceLabel = overallBalance.ToString();
+
+ AddChargeContextMenuCommand.RaiseCanExecuteChanged();
+ AddDepositContextMenuCommand.RaiseCanExecuteChanged();
// Restore selection
if (rememberSelection != null && PersonListViewItemSource.Any(x => x.Id == rememberSelection))