Skip to content

Add WPF skeleton with null check fix #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# sqlcmd-gui

An attempt to implement a graphical user interface based on SQLCMD for executing parameterized TSQL scripts.

This repository contains a minimal Windows desktop application for executing parameterized SQL scripts with `sqlcmd`.

The application allows you to:
Expand Down
12 changes: 10 additions & 2 deletions SqlcmdGuiApp/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ComboBox x:Name="AuthComboBox" Margin="0,0,0,10">
<ComboBoxItem Content="Windows Authentication"/>
<ComboBoxItem Content="SQL Server Authentication"/>
</ComboBox>
<StackPanel x:Name="SqlAuthPanel" Grid.Row="1" Visibility="Collapsed">
<TextBlock Text="Username:"/>
<TextBox x:Name="UsernameBox"/>
<TextBlock Text="Password:"/>
<PasswordBox x:Name="PasswordBox"/>
</StackPanel>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
Expand Down
13 changes: 12 additions & 1 deletion SqlcmdGuiApp/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
Expand All @@ -6,7 +8,6 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;

namespace SqlcmdGuiApp
{
Expand All @@ -17,9 +18,19 @@ public partial class MainWindow : Window
public MainWindow()
{
InitializeComponent();
// Hook the event after initialization to avoid early invocation while components load
AuthComboBox.SelectionChanged += AuthComboBox_SelectionChanged;

ParametersPanel.ItemsSource = Parameters;
}

private void AuthComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SqlAuthPanel == null) return; // may be null during XAML load
SqlAuthPanel.Visibility =
AuthComboBox.SelectedIndex == 1 ? Visibility.Visible : Visibility.Collapsed;
}

private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
var dlg = new OpenFileDialog { Filter = "SQL Files (*.sql)|*.sql|All Files (*.*)|*.*" };
Expand Down
3 changes: 2 additions & 1 deletion SqlcmdGuiApp/SqlcmdGuiApp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>