From a1fe3a079bc5186b212cd484b527a9b01f2d0920 Mon Sep 17 00:00:00 2001 From: emkael Date: Sat, 13 Oct 2018 10:47:27 +0200 Subject: Using MysqlBackup.NET to dump the database --- kurier/Form1.Designer.cs | 1 + kurier/Form1.cs | 21 +++++++++++++++++++++ kurier/MySQL.cs | 10 ++++++++++ kurier/kurier.csproj | 5 ++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/kurier/Form1.Designer.cs b/kurier/Form1.Designer.cs index 47549f4..c9a2934 100644 --- a/kurier/Form1.Designer.cs +++ b/kurier/Form1.Designer.cs @@ -103,6 +103,7 @@ this.bSave.Size = new System.Drawing.Size(140, 140); this.bSave.TabIndex = 4; this.bSave.UseVisualStyleBackColor = true; + this.bSave.Click += new System.EventHandler(this.bSave_Click); // // Form1 // diff --git a/kurier/Form1.cs b/kurier/Form1.cs index a8bd7eb..86754e5 100644 --- a/kurier/Form1.cs +++ b/kurier/Form1.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; +using System.IO; namespace kurier { @@ -51,5 +52,25 @@ namespace kurier this.cbDatabaseName.SelectedIndex = 0; dbs.Close(); } + + private void bSave_Click(object sender, EventArgs e) + { + FolderBrowserDialog fd = new FolderBrowserDialog(); + if (fd.ShowDialog() == DialogResult.OK) + { + string filePath = Path.Combine(fd.SelectedPath, this.cbDatabaseName.SelectedItem.ToString() + DateTime.Now.ToString("-yyyyMMdd-HHmmss") + ".sql"); + try + { + MySQL c = new MySQL(this.cbDatabaseName.SelectedItem.ToString()); + c.backup(filePath); + c.close(); + MessageBox.Show("Wyeksportowano pomyślnie do pliku: " + filePath, "Sukces eksportu!", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Błąd eksportu!", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } } diff --git a/kurier/MySQL.cs b/kurier/MySQL.cs index 81a3a0b..88b4fbf 100644 --- a/kurier/MySQL.cs +++ b/kurier/MySQL.cs @@ -8,6 +8,7 @@ namespace kurier public class MySQL { private MySqlConnection conn; + private MySqlCommand cmd; private string database; public MySQL(string database) @@ -72,5 +73,14 @@ namespace kurier public static string getPass() { return Properties.Settings.Default.PASS; } public static string getPort() { return Properties.Settings.Default.PORT; } public static bool getConfigured() { return Properties.Settings.Default.CONFIGURED; } + + internal void backup(string filePath) + { + cmd = new MySqlCommand(); + cmd.Connection = conn; + MySqlBackup backup = new MySqlBackup(cmd); + backup.ExportInfo.AddCreateDatabase = true; + backup.ExportToFile(filePath); + } } } diff --git a/kurier/kurier.csproj b/kurier/kurier.csproj index 02fde5e..a6caf88 100644 --- a/kurier/kurier.csproj +++ b/kurier/kurier.csproj @@ -54,7 +54,10 @@ False ..\res\MySql.Data.dll - + + ..\res\MySqlBackup.dll + + -- cgit v1.2.3