Skip to content

Commit b488921

Browse files
authored
Merge pull request #2 from EitanBlumin/codex/ensure-sqlauthpanel-is-not-null-in-selectionchanged
Add WPF skeleton with null check fix
2 parents 75c529b + 47cc277 commit b488921

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# sqlcmd-gui
22

3+
An attempt to implement a graphical user interface based on SQLCMD for executing parameterized TSQL scripts.
4+
35
This repository contains a minimal Windows desktop application for executing parameterized SQL scripts with `sqlcmd`.
46

57
The application allows you to:

SqlcmdGuiApp/MainWindow.xaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,17 @@
66
<Grid.RowDefinitions>
77
<RowDefinition Height="Auto"/>
88
<RowDefinition Height="Auto"/>
9-
<RowDefinition Height="*"/>
10-
<RowDefinition Height="Auto"/>
119
</Grid.RowDefinitions>
10+
<ComboBox x:Name="AuthComboBox" Margin="0,0,0,10">
11+
<ComboBoxItem Content="Windows Authentication"/>
12+
<ComboBoxItem Content="SQL Server Authentication"/>
13+
</ComboBox>
14+
<StackPanel x:Name="SqlAuthPanel" Grid.Row="1" Visibility="Collapsed">
15+
<TextBlock Text="Username:"/>
16+
<TextBox x:Name="UsernameBox"/>
17+
<TextBlock Text="Password:"/>
18+
<PasswordBox x:Name="PasswordBox"/>
19+
</StackPanel>
1220
<Grid.ColumnDefinitions>
1321
<ColumnDefinition Width="*"/>
1422
<ColumnDefinition Width="Auto"/>

SqlcmdGuiApp/MainWindow.xaml.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System.Windows;
2+
using System.Windows.Controls;
13
using Microsoft.Win32;
24
using System;
35
using System.Collections.Generic;
@@ -6,7 +8,6 @@
68
using System.IO;
79
using System.Linq;
810
using System.Text.RegularExpressions;
9-
using System.Windows;
1011

1112
namespace SqlcmdGuiApp
1213
{
@@ -17,9 +18,19 @@ public partial class MainWindow : Window
1718
public MainWindow()
1819
{
1920
InitializeComponent();
21+
// Hook the event after initialization to avoid early invocation while components load
22+
AuthComboBox.SelectionChanged += AuthComboBox_SelectionChanged;
23+
2024
ParametersPanel.ItemsSource = Parameters;
2125
}
2226

27+
private void AuthComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
28+
{
29+
if (SqlAuthPanel == null) return; // may be null during XAML load
30+
SqlAuthPanel.Visibility =
31+
AuthComboBox.SelectedIndex == 1 ? Visibility.Visible : Visibility.Collapsed;
32+
}
33+
2334
private void BrowseButton_Click(object sender, RoutedEventArgs e)
2435
{
2536
var dlg = new OpenFileDialog { Filter = "SQL Files (*.sql)|*.sql|All Files (*.*)|*.*" };

SqlcmdGuiApp/SqlcmdGuiApp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
22
<PropertyGroup>
33
<OutputType>WinExe</OutputType>
44
<TargetFramework>net6.0-windows</TargetFramework>
55
<UseWPF>true</UseWPF>
6+
<Nullable>enable</Nullable>
67
</PropertyGroup>
78
</Project>

0 commit comments

Comments
 (0)