Added functionality to switch database

This commit is contained in:
Andre Beging
2017-09-11 11:52:20 +02:00
parent 3d2d4851cc
commit 68cd02e99b
4 changed files with 40 additions and 15 deletions

View File

@@ -1,17 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using DebtMgr.Extensions;
namespace DebtMgr.View.Dialogs
@@ -34,6 +24,14 @@ namespace DebtMgr.View.Dialogs
private void Window_OnKeyUp(object sender, KeyEventArgs e)
{
if (e.Key.Equals(Key.Escape))
Close();
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
if (!App.Locator.DatabaseSelectorDialogView.ProgramRequestedClose)
Application.Current.Shutdown();
}
}

View File

@@ -22,11 +22,8 @@
<DockPanel Grid.Row="0">
<Menu DockPanel.Dock="Top">
<MenuItem Header="Person">
<MenuItem Header="_New" Command="{Binding MenuNewPersonCommand}" />
<MenuItem Header="_Manage" IsEnabled="False" />
<Separator />
<MenuItem Header="_Exit" Command="{Binding MenuExitCommand}" />
<MenuItem Header="Menu">
<MenuItem Header="_Switch Database" Command="{Binding SwitchDatabaseMenuCommand}" />
</MenuItem>
</Menu>
</DockPanel>

View File

@@ -16,6 +16,7 @@ namespace DebtMgr.ViewModel.Dialogs
public class DatabaseSelectorDialogViewModel : ViewModelBase
{
public event EventHandler RequestClose;
public bool ProgramRequestedClose = false;
#region SelectDatabasePathText (string) Property
@@ -71,6 +72,7 @@ namespace DebtMgr.ViewModel.Dialogs
Properties.Settings.Default["Database"] = openFileDialog.FileName;
Properties.Settings.Default.Save();
ProgramRequestedClose = true;
RequestClose?.Invoke(null, null);
}
catch (Exception)
@@ -113,6 +115,7 @@ namespace DebtMgr.ViewModel.Dialogs
Properties.Settings.Default["Database"] = saveFileDialog.FileName;
Properties.Settings.Default.Save();
ProgramRequestedClose = true;
RequestClose?.Invoke(null, null);
}
}

View File

@@ -8,6 +8,7 @@ using System.Linq;
using System.Windows;
using System;
using System.Configuration;
using System.Threading;
using SQLite.Net;
using SQLite.Net.Platform.Generic;
@@ -390,6 +391,32 @@ namespace DebtMgr.ViewModel
#endregion
#region SwitchDatabaseMenuCommand Command
/// <summary>
/// Private member backing variable for <see cref="SwitchDatabaseMenuCommand" />
/// </summary>
private RelayCommand _PrivateCommandName = null;
/// <summary>
/// Comment
/// </summary>
public RelayCommand SwitchDatabaseMenuCommand => _PrivateCommandName ?? (_PrivateCommandName = new RelayCommand(SwitchDatabaseMenuCommand_Execute));
private void SwitchDatabaseMenuCommand_Execute()
{
Properties.Settings.Default["Database"] = string.Empty;
Properties.Settings.Default.Save();
Thread.Sleep(100);
System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////////////////
/// <summary> Initializes a new instance of the MainViewModel class. </summary>
///