May 28, 2026, 8:56 AM
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"LastServer": "localhost",
|
||||||
|
"Theme": "Light"
|
||||||
|
}
|
||||||
+17
-3
@@ -3,6 +3,16 @@ Add-Type -AssemblyName PresentationFramework, PresentationCore, WindowsBase
|
|||||||
# Import Custom Modules
|
# Import Custom Modules
|
||||||
Import-Module (Join-Path $PSScriptRoot "Modules\SQLManager.psm1") -Force
|
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
|
# 1. Path to XAML
|
||||||
$xamlFile = Join-Path $PSScriptRoot "UI\MainWindow.xaml"
|
$xamlFile = Join-Path $PSScriptRoot "UI\MainWindow.xaml"
|
||||||
|
|
||||||
@@ -17,6 +27,9 @@ $txtServerName = $Window.FindName("txtServerName")
|
|||||||
$txtLogs = $Window.FindName("txtLogs")
|
$txtLogs = $Window.FindName("txtLogs")
|
||||||
$dgServerInfo = $Window.FindName("dgServerInfo")
|
$dgServerInfo = $Window.FindName("dgServerInfo")
|
||||||
|
|
||||||
|
# Set initial values from settings
|
||||||
|
$txtServerName.Text = $settings.LastServer
|
||||||
|
|
||||||
# 4. Helper function for logging
|
# 4. Helper function for logging
|
||||||
function Write-Log {
|
function Write-Log {
|
||||||
param([string]$Message)
|
param([string]$Message)
|
||||||
@@ -38,9 +51,9 @@ $btnConnect.Add_Click({
|
|||||||
$btnConnect.IsEnabled = $false
|
$btnConnect.IsEnabled = $false
|
||||||
Write-Log "Attempting to connect to $server..."
|
Write-Log "Attempting to connect to $server..."
|
||||||
|
|
||||||
# Running connection test in a separate thread/job would be better for UI responsiveness,
|
# Save last server
|
||||||
# but for this prototype we'll keep it simple or use a minimal background approach if possible.
|
$settings.LastServer = $server
|
||||||
# For now, let's just do it directly.
|
$settings | ConvertTo-Json | Set-Content $configPath
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = Test-SQLConnection -ServerInstance $server
|
$result = Test-SQLConnection -ServerInstance $server
|
||||||
@@ -64,6 +77,7 @@ try {
|
|||||||
Write-Log "DBAToolBox started. dbatools module loaded."
|
Write-Log "DBAToolBox started. dbatools module loaded."
|
||||||
} catch {
|
} catch {
|
||||||
[System.Windows.MessageBox]::Show($_.Exception.Message, "Dependency Error", "OK", "Error")
|
[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()
|
$Window.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user