Added functionality to edit persons
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <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);
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user