QueryWindow: Minor improvements

This commit is contained in:
2024-03-12 18:23:38 +01:00
parent 2a3a69d96f
commit 239b8a9091
3 changed files with 35 additions and 9 deletions

View File

@ -90,7 +90,7 @@ namespace Elwig.Windows {
private set => SetValue(EmailWishCountProperty, value); private set => SetValue(EmailWishCountProperty, value);
} }
private ICommand _deleteCommand; private ICommand? _deleteCommand;
public ICommand DeleteCommand => _deleteCommand ??= new ActionCommand(() => { public ICommand DeleteCommand => _deleteCommand ??= new ActionCommand(() => {
var idx = SelectedDocumentsList.SelectedIndex; var idx = SelectedDocumentsList.SelectedIndex;
if (idx == -1) if (idx == -1)

View File

@ -1,19 +1,33 @@
<Window x:Class="Elwig.Windows.QueryWindow" <Window x:Class="Elwig.Windows.QueryWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Datenbankabfragen - Elwig" Height="450" Width="800"> xmlns:local="clr-namespace:Elwig.Windows"
Title="Datenbankabfragen - Elwig" Height="450" Width="800" MinWidth="400" MinHeight="300">
<Grid> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="1*" MinHeight="100"/>
<RowDefinition Height="5"/>
<RowDefinition Height="3*" MinHeight="100"/>
</Grid.RowDefinitions>
<TextBox x:Name="QueryInput" Text="SELECT * FROM v_delivery" <TextBox x:Name="QueryInput" Text="SELECT * FROM v_delivery"
AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" TextWrapping="Wrap"
HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="10,10,120,10" Height="100" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,120,5"
FontFamily="Cascadia Code Light" FontSize="13"/> FontFamily="Cascadia Code Light" FontSize="13">
<TextBox.InputBindings>
<KeyBinding Key="Return" Modifiers="Control" Command="{Binding EnterCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:QueryWindow}}}" />
</TextBox.InputBindings>
</TextBox>
<Button x:Name="QueryButton" Content="Abfragen" <Button x:Name="QueryButton" Content="Abfragen"
HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,10,10,10" HorizontalAlignment="Right" VerticalAlignment="Stretch" Margin="10,10,10,5"
Click="QueryButton_Click" Height="100" Width="100" Click="QueryButton_Click" Width="100"
FontSize="14"/> FontSize="14"/>
<DataGrid x:Name="DataList"
AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Single" <GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
<DataGrid x:Name="DataList" Grid.Row="2"
AutoGenerateColumns="False" HeadersVisibility="Column" IsReadOnly="True" GridLinesVisibility="None" SelectionMode="Extended"
CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False" CanUserAddRows="False"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,120,10,10"/> HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,5,10,10"/>
</Grid> </Grid>
</Window> </Window>

View File

@ -6,14 +6,26 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Input;
namespace Elwig.Windows { namespace Elwig.Windows {
public partial class QueryWindow : Window { public partial class QueryWindow : Window {
private ICommand? _enterCommand;
public ICommand EnterCommand => _enterCommand ??= new ActionCommand(async () => {
await ExecuteQuery();
});
public QueryWindow() { public QueryWindow() {
InitializeComponent(); InitializeComponent();
} }
private async void QueryButton_Click(object sender, RoutedEventArgs evt) { private async void QueryButton_Click(object sender, RoutedEventArgs evt) {
await ExecuteQuery();
}
private async Task ExecuteQuery() {
try { try {
await ExecuteQuery(QueryInput.Text); await ExecuteQuery(QueryInput.Text);
} catch (Exception e) { } catch (Exception e) {