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