diff --git a/toolbox/Config/settings.json b/toolbox/Config/settings.json new file mode 100644 index 0000000..1b6a531 --- /dev/null +++ b/toolbox/Config/settings.json @@ -0,0 +1,4 @@ +{ + "LastServer": "localhost", + "Theme": "Light" +} \ No newline at end of file diff --git a/toolbox/DBAToolBox.ps1 b/toolbox/DBAToolBox.ps1 index 9146840..384feb7 100644 --- a/toolbox/DBAToolBox.ps1 +++ b/toolbox/DBAToolBox.ps1 @@ -3,6 +3,16 @@ Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase # Import Custom Modules Import-Module (Join-Path $PSScriptRoot "Modules\SQLManager.psm1") -Force +# Configuration Paths +$configPath = Join-Path $PSScriptRoot "Config\settings.json" + +# Load Settings +if (Test-Path $configPath) { + $settings = Get-Content $configPath | ConvertFrom-Json +} else { + $settings = [pscustomobject]@{ LastServer = ""; Theme = "Light" } +} + # 1. Path to XAML $xamlFile = Join-Path $PSScriptRoot "UI\MainWindow.xaml" @@ -17,6 +27,9 @@ $txtServerName = $Window.FindName("txtServerName") $txtLogs = $Window.FindName("txtLogs") $dgServerInfo = $Window.FindName("dgServerInfo") +# Set initial values from settings +$txtServerName.Text = $settings.LastServer + # 4. Helper function for logging function Write-Log { param([string]$Message) @@ -38,9 +51,9 @@ $btnConnect.Add_Click({ $btnConnect.IsEnabled = $false Write-Log "Attempting to connect to $server..." - # Running connection test in a separate thread/job would be better for UI responsiveness, - # but for this prototype we'll keep it simple or use a minimal background approach if possible. - # For now, let's just do it directly. + # Save last server + $settings.LastServer = $server + $settings | ConvertTo-Json | Set-Content $configPath try { $result = Test-SQLConnection -ServerInstance $server @@ -64,6 +77,7 @@ try { Write-Log "DBAToolBox started. dbatools module loaded." } catch { [System.Windows.MessageBox]::Show($_.Exception.Message, "Dependency Error", "OK", "Error") + # In some environments ShowDialog might fail if no UI thread, but for WPF it should work. $Window.Close() }