private void ExportDB_Button_Click(object sender, RoutedEventArgs e) { // Allow user to pick a DB file to export to the existing DB. SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Database Files (*.db)|*.db"; if (saveFileDialog.ShowDialog() == true) { try { // If user attempts to Overwrite catch it here. File.Copy("Alert_DB.db", saveFileDialog.FileName, false); // Log info var Log = new LogHandler("Exported DB."); Log.WriteLogFile(); } catch (IOException exception) { InformUserDialog areYouSureDialog = new InformUserDialog("OPERATION DENIED. Exception logged. \n\n" + "Name cannot match or overwrite current DB.", "Ok", "Please try a different name or destination."); areYouSureDialog.Owner = this; areYouSureDialog.ShowDialog(); // Log info var Log = new LogHandler("Export DB Denied.", exception); Log.WriteLogFile(); } } }
private static bool EnsureValidCharsInEventIDTextBox(TextBox eventIDTextBox) { // Ensure that only valid chars are entered. // If they are not display dialog to user. bool ContainsValidChars = true; char[] ValidChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-' }; foreach (char c in eventIDTextBox.Text) { if (!ValidChars.Contains(c)) { eventIDTextBox.Text = eventIDTextBox.Text.Remove(eventIDTextBox.Text.Length - 1); InformUserDialog informUserDialog = new InformUserDialog("Please enter the correct characters.", "OK", "Valid characters: (0,1,2,3,4,5,6,7,8,9,-)"); informUserDialog.Owner = Window.GetWindow(eventIDTextBox); informUserDialog.ShowDialog(); ContainsValidChars = false; } } // Put the caret back at the end of the textbox for the user // and return bool value. eventIDTextBox.CaretIndex = eventIDTextBox.Text.Length; return(ContainsValidChars); }
private void DeleteDB_Button_Click(object sender, RoutedEventArgs e) { // Give the user one last chance to change their mind before they reset the DB. SystemSounds.Exclamation.Play(); InformUserDialog areYouSureDialog = new InformUserDialog("Are you sure you wish to reset the DB?", "DELETE", "WARNING: This action CLEARS ALL RECORDS in the database " + "and this cannot be undone. Are you absolutely sure?"); areYouSureDialog.Owner = this; if ((bool)areYouSureDialog.ShowDialog()) { SQLite_Data_Access.DeleteAllIn_DB(); // Log info var Log = new LogHandler("WIPED all DB entries."); Log.WriteLogFile(); this.Close(); } }
private void EditDB_Button_Click(object sender, RoutedEventArgs e) { // Allow user to edit the DB after confirming prompt. InformUserDialog areYouSureDialog = new InformUserDialog("Are you sure you wish to edit the DB?", "Continue", "WARNING: Improper modifications to this database can cause " + "corrupted data or put the database in a nonrecoverable state. " + "Continue with caution."); areYouSureDialog.Owner = this; if ((bool)areYouSureDialog.ShowDialog()) { // Log info var Log = new LogHandler("Edit DB called."); Log.WriteLogFile(); SQLite_Data_Access.UpdateIn_DB(""); this.Close(); } }