67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
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();
|
|
}
|
|
} |