This commit is contained in:
2025-04-17 17:40:16 +02:00
parent c666da8ba7
commit bbc4894921
16 changed files with 370 additions and 0 deletions

9
SQLMan/App.xaml Normal file
View File

@@ -0,0 +1,9 @@
<Application x:Class="SQLMan.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SQLMan"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>

14
SQLMan/App.xaml.cs Normal file
View File

@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace SQLMan
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}

10
SQLMan/AssemblyInfo.cs Normal file
View File

@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]

35
SQLMan/MainWindow.xaml Normal file
View File

@@ -0,0 +1,35 @@
<Window x:Class="SQLMan.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SQLMan"
mc:Ignorable="d"
Title="SQL Broo" Height="450" Width="800">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Button Grid.Row="0"
Content="Select SQL Script"
Click="SelectButonClick"/>
<TextBox Grid.Row="1"
Margin="3"
IsEnabled="False"
Name="SkriptTextBox"/>
<StackPanel Grid.Row="2"
Orientation="Horizontal">
<Label>Connection String</Label>
<TextBox Width="500"
Name="ConnectionTextBox"/>
</StackPanel>
<Button Grid.Row="3"
Content="Execute SQL Script"
Click="ExecuteButonClick"/>
</Grid>
</Grid>
</Window>

67
SQLMan/MainWindow.xaml.cs Normal file
View File

@@ -0,0 +1,67 @@
using Microsoft.Win32;
using MySqlConnector;
using System.IO;
using System.Windows;
namespace SQLMan;
/// <summary>
/// Interaction logic for MainWindow.xaml.
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.ConnectionTextBox.Text = "Server=localhost;User ID=root;Password=root";
}
private void SelectButonClick(object sender, RoutedEventArgs e)
{
FileInfo? datei = this.SkriptDateiWahlen();
string dateiInhalt = this.DateiEinlesen(datei);
this.SkriptTextBox.Text = dateiInhalt;
}
private FileInfo? SkriptDateiWahlen()
{
OpenFileDialog dateiDialog = new OpenFileDialog();
dateiDialog.Filter = "SQL files (*.sql)|*.sql";
if (dateiDialog.ShowDialog() == true)
{
return new FileInfo(dateiDialog.FileName);
}
else
{
return null;
}
}
private string DateiEinlesen(FileInfo? datei)
{
if (datei == null) return string.Empty;
string dateiInhalt = File.ReadAllText(datei.FullName);
return dateiInhalt;
}
private void ExecuteButonClick(object sender, RoutedEventArgs e)
{
try {
this.FuehreSkriptAus(this.SkriptTextBox.Text, this.ConnectionTextBox.Text);
MessageBox.Show("Das Skript wurde erfolgreich ausgeführt!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void FuehreSkriptAus(string sqlScript, string connectionString)
{
using var datenbankVerbindung = new MySqlConnection(connectionString);
datenbankVerbindung.Open();
using var kommando = new MySqlCommand(sqlScript, datenbankVerbindung);
kommando.ExecuteNonQuery();
}
}

15
SQLMan/SQLMan.csproj Normal file
View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MySqlConnector" Version="2.4.0" />
</ItemGroup>
</Project>