Added functionality to edit persons
This commit is contained in:
@@ -16,4 +16,15 @@ namespace DebtMgr.Model
|
||||
[Description("Charge")]
|
||||
Charge
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Values that represent person dialog modes. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 12.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public enum PersonDialogMode
|
||||
{
|
||||
New,
|
||||
Edit
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
@@ -16,7 +16,7 @@
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
<RowDefinition Height="Auto"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Label Grid.Row="0" Content="New Person" FontWeight="Bold" FontSize="18"></Label>
|
||||
<Label Grid.Row="0" Content="{Binding ElementName=NewPersonDialogViewWindow, Path=Title}" FontWeight="Bold" FontSize="18"></Label>
|
||||
<StackPanel Grid.Row="1" Orientation="Vertical" Margin="10 0">
|
||||
<TextBox KeyUp="TextBox_OnKeyUp" Name="FirstNameTextBox" Text="{Binding FirstNameTextBoxText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" FontSize="16" Margin="0 0 0 -5"></TextBox>
|
||||
<Label Content="First name"></Label>
|
||||
@@ -30,7 +30,7 @@
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button Grid.Column="1" Content="Create Person" FontSize="14" Padding="5" Margin="10 -10" Command="{Binding CreatePersonButtonClickCommand}"></Button>
|
||||
<Button Grid.Column="1" Content="{Binding SaveButtonText}" FontSize="14" Padding="5" Margin="10 -10" Command="{Binding CreatePersonButtonClickCommand}"></Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
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()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Event handler. Called by TextBox for on key up events. </summary>
|
||||
///
|
||||
@@ -34,6 +43,10 @@ namespace DebtMgr.View.Dialogs
|
||||
App.Locator.NewPersonDialogView.CreatePersonButtonClickCommand.Execute(null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Window_KeyUp()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Event handler. Called by Window for key up events. </summary>
|
||||
///
|
||||
@@ -47,5 +60,7 @@ namespace DebtMgr.View.Dialogs
|
||||
if (e.Key.Equals(Key.Escape))
|
||||
Close();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
<TextBlock Text="€" Foreground="{Binding OverallBalanceLabel, Converter={StaticResource AmountToColorConverter}}"></TextBlock>
|
||||
</TextBlock>
|
||||
<Button Grid.Column="1" Padding="5" ToolTip="New Person" Margin="5 0 5 5" Command="{Binding NewPersonContextMenuCommand}">
|
||||
<Image Source="../Content/addperson.ico" Width="30" />
|
||||
<Image Source="../Content/addperson.ico" Height="30" />
|
||||
</Button>
|
||||
|
||||
</Grid>
|
||||
@@ -82,10 +82,12 @@
|
||||
</ListView.View>
|
||||
<ListBox.Resources>
|
||||
<ContextMenu x:Key="PersonListViewContextMenu">
|
||||
<MenuItem Header="Add charge" Command="{Binding AddChargeContextMenuCommand}" />
|
||||
<MenuItem Header="Add deposit" Command="{Binding AddDepositContextMenuCommand}" />
|
||||
<MenuItem Header="New Person" Command="{Binding NewPersonContextMenuCommand}" />
|
||||
<MenuItem Header="Delete Person" Command="{Binding DeletePersonContextMenuCommand}" CommandParameter="{Binding Path=SelectedItem}" />
|
||||
<MenuItem Header="_Edit Person" Command="{Binding EditPersonContextMenuCommand}" />
|
||||
<MenuItem Header="Delete Person" Command="{Binding DeletePersonContextMenuCommand}" />
|
||||
<MenuItem Header="_New Person" Command="{Binding NewPersonContextMenuCommand}" />
|
||||
<Separator></Separator>
|
||||
<MenuItem Header="Add _Charge" Command="{Binding AddChargeContextMenuCommand}" />
|
||||
<MenuItem Header="Add _Deposit" Command="{Binding AddDepositContextMenuCommand}" />
|
||||
</ContextMenu>
|
||||
</ListBox.Resources>
|
||||
<ListBox.ContextMenu>
|
||||
@@ -122,10 +124,10 @@
|
||||
<TextBlock Text="€" Foreground="{Binding DetailViewBalanceLabel, Converter={StaticResource AmountToColorConverter}}"></TextBlock>
|
||||
</TextBlock>
|
||||
<Button Grid.Column="1" Padding="5" ToolTip="Add Charge" Margin="5 0 0 5" Command="{Binding AddChargeContextMenuCommand}">
|
||||
<Image Source="../Content/money_red.ico" Width="30" />
|
||||
<Image Source="../Content/money_red.ico" Height="30" />
|
||||
</Button>
|
||||
<Button Grid.Column="2" Padding="5" ToolTip="Add Deposit" Margin="5 0 5 5" Command="{Binding AddDepositContextMenuCommand}">
|
||||
<Image Source="../Content/money_green.ico" Width="30" />
|
||||
<Image Source="../Content/money_green.ico" Height="30" />
|
||||
</Button>
|
||||
</Grid>
|
||||
<ListView Name="TransactionHistoryListView" Grid.Row="2" ItemsSource="{Binding TransactionHistoryListViewItemSource}" SelectedItem="{Binding TransactionHistoryListViewSelectedItem}" HorizontalContentAlignment="Stretch">
|
||||
@@ -149,10 +151,11 @@
|
||||
</ListView.View>
|
||||
<ListBox.Resources>
|
||||
<ContextMenu x:Key="TransactionHistoryListViewContextMenu">
|
||||
<MenuItem Header="Edit Transaction" Command="{Binding EditTransactionContextMenuCommand}" CommandParameter="{Binding Path=SelectedItem}" />
|
||||
<MenuItem Header="Add charge" Command="{Binding AddChargeContextMenuCommand}" />
|
||||
<MenuItem Header="Add deposit" Command="{Binding AddDepositContextMenuCommand}" />
|
||||
<MenuItem Header="_Edit Transaction" Command="{Binding EditTransactionContextMenuCommand}" CommandParameter="{Binding Path=SelectedItem}" />
|
||||
<MenuItem Header="Delete Transaction" Command="{Binding DeleteTransactionContextMenuCommand}" CommandParameter="{Binding Path=SelectedItem}" />
|
||||
<Separator></Separator>
|
||||
<MenuItem Header="Add _Charge" Command="{Binding AddChargeContextMenuCommand}" />
|
||||
<MenuItem Header="Add _Deposit" Command="{Binding AddDepositContextMenuCommand}" />
|
||||
</ContextMenu>
|
||||
</ListBox.Resources>
|
||||
<ListBox.ContextMenu>
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <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 SaveButtonText (string) Property
|
||||
|
||||
/// <summary>
|
||||
/// Privater Teil von <see cref="SaveButtonText" />
|
||||
/// </summary>
|
||||
private string _saveButtonText;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
///</summary>
|
||||
public string SaveButtonText
|
||||
{
|
||||
get { return _saveButtonText; }
|
||||
|
||||
set
|
||||
{
|
||||
_saveButtonText = value;
|
||||
RaisePropertyChanged(() => SaveButtonText);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region FirstNameTextBoxText (string) Property
|
||||
|
||||
@@ -81,6 +133,9 @@ namespace DebtMgr.ViewModel.Dialogs
|
||||
private void CreatePersonButtonClickCommand_Execute()
|
||||
{
|
||||
if (CreatePersonButtonClickCommand_CanExecute())
|
||||
{
|
||||
bool success = false;
|
||||
if (DialogMode == PersonDialogMode.New)
|
||||
{
|
||||
var newPerson = new Person
|
||||
{
|
||||
@@ -88,14 +143,23 @@ namespace DebtMgr.ViewModel.Dialogs
|
||||
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()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary> Sets mode specifics. </summary>
|
||||
///
|
||||
/// <remarks> Andre Beging, 12.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public void SetModeSpecifics()
|
||||
{
|
||||
if (DialogMode != PersonDialogMode.Edit || EditPersonId == Guid.Empty)
|
||||
{
|
||||
ClearView();
|
||||
return;
|
||||
}
|
||||
|
||||
// edit mode
|
||||
EditPerson = App.Database.Get<Person>(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
|
||||
///
|
||||
/// <remarks> Andre Beging, 08.09.2017. </remarks>
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
private void ClearView()
|
||||
public void ClearView()
|
||||
{
|
||||
FirstNameTextBoxText = string.Empty;
|
||||
LastNameTextBoxText = string.Empty;
|
||||
DialogMode = PersonDialogMode.New;
|
||||
WindowTitle = "New Person";
|
||||
SaveButtonText = "Create";
|
||||
EditPersonId = Guid.Empty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -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
|
||||
|
||||
/// <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>
|
||||
@@ -262,7 +239,14 @@ namespace DebtMgr.ViewModel
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
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
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Private member backing variable for <see cref="EditPersonContextMenuCommand" />
|
||||
/// </summary>
|
||||
private RelayCommand _editPersonContextMenuCommand = null;
|
||||
|
||||
/// <summary>
|
||||
/// Comment
|
||||
/// </summary>
|
||||
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} <20>\n{0}",
|
||||
TransactionHistoryListViewSelectedItem.Description,
|
||||
TransactionHistoryListViewSelectedItem.Amount),
|
||||
"Delete Transaction",
|
||||
"Are you sure to delete this {0}?\n\n{1} {2}\nAmount: {3} <20>\n{4}",
|
||||
TransactionHistoryListViewSelectedItem.Type,
|
||||
TransactionHistoryListViewSelectedItem.Person.FirstName,
|
||||
TransactionHistoryListViewSelectedItem.Person.LastName,
|
||||
TransactionHistoryListViewSelectedItem.Amount,
|
||||
TransactionHistoryListViewSelectedItem.Description),
|
||||
string.Format("Delete {0}", TransactionHistoryListViewSelectedItem.Type),
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Question);
|
||||
|
||||
@@ -498,6 +523,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))
|
||||
PersonListViewSelectedItem = PersonListViewItemSource.First(x => x.Id == rememberSelection);
|
||||
|
||||
Reference in New Issue
Block a user