public winMySQL(string _editId = "") { InitializeComponent(); DataContext = this; EditId = _editId; //load settings if editing if (!string.IsNullOrWhiteSpace(EditId)) { try { MYSQLHelper helper = new MYSQLHelper(); MYSQLBackup backup = helper.GetConfig(EditId); if (backup == null) { MessageBox.Show("Settings were not found.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } ServerName = backup.ServerName; DatabaseName = backup.DatabaseName; Username = backup.Username; Password = backup.Password; BackupIsActive = backup.IsActive; BackupTime = backup.BackupTime; } catch (Exception ex) { string message = Functions.GetErrorFromException(ex); MessageBox.Show("A problem occurred while loading backup details.\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
public bool AddConfig(MYSQLBackup backup) { try { backup.Id = Functions.RandomString(20); List <MYSQLBackup> existingList = GetConfigList() ?? new List <MYSQLBackup>(); existingList.Add(backup); string configFile = Path.Combine(EnVar.AppWorkingPath, "mysql.config"); File.WriteAllText(configFile, JsonConvert.SerializeObject(existingList)); return(true); } catch //(Exception ex) { return(false); } }