/// <summary> /// The main form constructor. Initializes UI objects and binds events. /// </summary> public fec_Main(SplashScreenForm splashForm) { InitializeComponent(); this.Icon = Properties.Resources.fecIcon; SetupComponents(); // If a database file does not exist, create a new one with empty tables. if (!File.Exists(DatabaseGenerator.DATABASE_NAME)) { DatabaseGenerator.GenerateDB(); } // Setup and format the grid. SetupDatabaseGrid(); splashForm.Close(); }
static void Main() { // Set culture info to US // This is done so that '.' is used instead of ',' for decimals. Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // If a database file does not exist, create a new one with empty tables. if (!File.Exists(DatabaseProperties.DATABASE_NAME) && !File.Exists(DatabaseProperties.ENCRYPTED_DATABASE_NAME)) { SplashScreenForm splashForm = new SplashScreenForm(); splashForm.Show(); // Execute startup events so that splash screen images are loaded. Application.DoEvents(); DatabaseGenerator.GenerateDB(); Application.Run(new fec_Main(splashForm)); } // If an unencrypted datbase file exists, open the main form. else if (File.Exists(DatabaseProperties.DATABASE_NAME)) { SplashScreenForm splashForm = new SplashScreenForm(); splashForm.Show(); // Execute startup events so that splash screen images are loaded. Application.DoEvents(); Application.Run(new fec_Main(splashForm)); } // If an encrypted database file exists, prompt the user for a password. else if (File.Exists(DatabaseProperties.ENCRYPTED_DATABASE_NAME)) { EnterPasswordForm enterPasswordForm = new EnterPasswordForm(); enterPasswordForm.Show(); Application.Run(); } }
/// <summary> /// The main form constructor. Called when the application is opened. /// Creates a new database if one does not already exist, and setups the /// database grid and other UI components. /// </summary> public fec_Main(SplashScreenForm splashForm) { InitializeComponent(); // Set the form icon. this.Icon = Properties.Resources.fecIcon; // Set the minimum size of the form. this.MinimumSize = new Size(820, 561); oldSize = this.MinimumSize; // Set global message box style. MessageBoxAdv.MessageBoxStyle = MessageBoxAdv.Style.Metro; // Open a stream to the database file to prevent it from being deleted. DB_LOCK = File.Open(DatabaseProperties.DATABASE_NAME, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); // Verify that the database is not corrupted. try { if (DB_LOCK.Length == 0) { throw new Exception(); } DatabaseWorker.CheckIntegrity(); } catch (Exception) { // Display error message and force-exit application when message is dismissed. if (MessageBoxAdv.Show(this, "Unable to open database file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) { DB_LOCK.Close(); System.Diagnostics.Process.GetCurrentProcess().Kill(); } } // Setup and format the grid. SetupDatabaseGrid(); // Setup some UI components and bind some events. SetupComponents(); splashForm.Close(); }
static void Main() { CultureInfo ci = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = ci; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SplashScreenForm splashForm = new SplashScreenForm(); splashForm.Show(); // Execute startup events so that splash screen images are loaded Application.DoEvents(); // Open main form Application.Run(new fec_Main(splashForm)); }
/// <summary> /// If the background worker completed without errors, proceed with displaying the main UI. /// </summary> private void DecryptionWorker_WorkCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { // If the execution of the background worker was cancelled, hide the progress bar and show an error. if (e.Cancelled) { HideProgressBar(); MessageBoxAdv.Show(this, "Failed to decrypt database.\n\n" + decryptionError, "Error"); return; } SplashScreenForm splashForm = new SplashScreenForm(); // Hide this form so that only the splash screen is visible. this.Hide(); splashForm.Show(); // Execute startup events so that splash screen images are loaded. Application.DoEvents(); // Release the encrypted database lock. ENCRYPTED_DB_LOCK.Close(); // Delete the encrypted database file. File.Delete(DatabaseProperties.ENCRYPTED_DATABASE_NAME); // Create a secure string from the entered password. foreach (char c in passwordTextBox.Text) { DatabaseProperties.password.AppendChar(c); } // Create and display the main form. fec_Main mainForm = new fec_Main(splashForm); mainForm.Show(); closed = true; this.Close(); }