private void MySQLDeleteColumn_Click(object sender, RoutedEventArgs e) { try { var rowData = ((Hyperlink)e.OriginalSource).DataContext as DatabaseViewModel; if (rowData == null) { return; } MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this backup?", "Confirm Action", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.No) { return; } MYSQLHelper helper = new MYSQLHelper(); helper.DeleteConfig(rowData.Id); MessageBox.Show("Backup was successfully deleted.", "Information", MessageBoxButton.OK, MessageBoxImage.Information); LoadMySQL(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while opening edit dialog.\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private async void btnSave_Click(object sender, RoutedEventArgs e) { //validations if (string.IsNullOrWhiteSpace(ServerName)) { Message = "Server name cannot be empty"; return; } if (string.IsNullOrWhiteSpace(DatabaseName)) { Message = "Database name cannot be empty"; return; } if (string.IsNullOrWhiteSpace(Username)) { Message = "Username cannot be empty"; return; } if (string.IsNullOrWhiteSpace(Password)) { Message = "Password cannot be empty"; return; } if (BackupTime == null) { Message = "Backup time cannot be empty"; return; } //Try connecting try { btnSave.IsEnabled = false; Message = "Please wait while checking connection..."; MYSQLHelper helper = new MYSQLHelper(ServerName, DatabaseName, Username, Password); string tempFile = Path.Combine(EnVar.AppTempPath, Functions.RandomString(10) + "_test_backup.sqldump"); bool Result = await helper.BackupDatabase(tempFile); btnSave.IsEnabled = true; Message = ""; if (Result == false) { Message = "Could not connect to database server. \n" + helper.Message; return; } if (File.Exists(tempFile)) { File.Delete(tempFile); } //connection successful, save settings //delete if editing if (!string.IsNullOrWhiteSpace(EditId)) { helper.DeleteConfig(EditId); } helper.AddConfig(new MYSQLBackup { Id = Functions.RandomString(20), ServerName = ServerName, DatabaseName = DatabaseName, Username = Username, Password = Password, BackupTime = (DateTime)BackupTime, CreatedOn = DateTime.UtcNow, IsActive = BackupIsActive, }); Close(); } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while connecting to server.\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }