Ejemplo n.º 1
0
        /// <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();
        }
Ejemplo n.º 2
0
        /// <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();
        }