public winMSSQL(string _editId = "") { InitializeComponent(); DataContext = this; EditId = _editId; //load settings if editing if (!string.IsNullOrWhiteSpace(EditId)) { try { MSSQLHelper helper = new MSSQLHelper(); MSSQLBackup backup = helper.GetConfig(EditId); if (backup == null) { EditId = ""; 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(MSSQLBackup backup) { try { backup.Id = Functions.RandomString(20); List <MSSQLBackup> existingList = GetConfigList() ?? new List <MSSQLBackup>(); existingList.Add(backup); string configFile = Path.Combine(EnVar.AppWorkingPath, "mssql.config"); File.WriteAllText(configFile, JsonConvert.SerializeObject(existingList)); return(true); } catch //(Exception ex) { return(false); } }