May 28, 2026, 8:56 AM

This commit is contained in:
Paweł Domański
2026-05-28 06:56:18 +00:00
parent a6824dbd33
commit fea2a546f7
2 changed files with 21 additions and 3 deletions
+4
View File
@@ -0,0 +1,4 @@
{
"LastServer": "localhost",
"Theme": "Light"
}
+17 -3
View File
@@ -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()
}