Пример #1
0
        // Check if the person exit the program have the master key
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            MasterPasswordForm masterPasswordForm = new MasterPasswordForm(false, true);

            masterPasswordForm.ShowDialog();

            if (!masterPasswordForm.Verify)
            {
                MessageBox.Show("Exit Error: Authetication Failed" +
                                "\nNo permission can be granted without the master password verification." +
                                "\nYou need the master password to exit the program.", "Exit Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                // Cancel the exit operation
                e.Cancel = true;
            }
            else
            {
                MessageBox.Show("Exit Success" +
                                "\nThe program will exit now.", "Exit Success", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }
Пример #2
0
        // Methods
        public void LoadMainForm()
        {
            DatabaseController dbController = new DatabaseController();

            //  Check the DbConfig file existence and determine the next operation
            if (!dbController.DbConfigExists())
            {
                //  Set the Master Password
                MasterPasswordForm newMasterPasswordForm = new MasterPasswordForm();
                newMasterPasswordForm.ShowDialog();

                //  Exit the program if user exit the Master Password Initial Setup, else Load Database Connection Form
                if (!newMasterPasswordForm.PwSetted)
                {
                    this.Close();
                }
                else
                {
                    //  Set the Database Connection
                    DatabaseConnectionForm dbConForm = new DatabaseConnectionForm(newMasterPasswordForm.MasterPw, false);
                    dbConForm.ShowDialog();

                    //  Exit the program if user exit the Database Connection Initial Setup
                    if (!dbConForm.Connected)
                    {
                        MessageBox.Show("Connection Error: Database not connected." +
                                        "\nThere is no database to be connected. The program will exit now.", "Connection Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                    else
                    {
                        //  Set Up the cabinet for this system
                        SetCabinetForm setCabinetForm = new SetCabinetForm(dbConForm.DbContoller);
                        setCabinetForm.ShowDialog();

                        if (!setCabinetForm.IsCabinetSelected())
                        {
                            MessageBox.Show("Initialize Error: No cabinet assigned." +
                                            "\nThe system cannot recognize a valid cabinet. The program will exit now.", "Initialize Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.Close();
                        }
                        else
                        {
                            //  The Main Form will be displayed by default if Database Connection Succeed
                            // Show the Cabinet Code if load successfully
                            labelCabinetCode.Text = setCabinetForm.GetCabinetCode();
                            _isLoaded             = true;
                        }
                    }
                }
            }
            else
            {
                dbController.LoadIniFile();
                try
                {
                    dbController.ConnectDatabase();
                    dbController.CheckCabinet();
                }
                catch (InvalidDatabaseConnectionException error)
                {
                    error.ShowErrorMessage();
                }

                if (!dbController.Connected)
                {
                    MasterPasswordForm verifyPasswordForm = new MasterPasswordForm(true, false);
                    verifyPasswordForm.ShowDialog();
                    if (verifyPasswordForm.Verify)
                    {
                        //  Set the Database Connection
                        DatabaseConnectionForm dbConForm = new DatabaseConnectionForm(verifyPasswordForm.MasterPw, true);
                        dbConForm.ShowDialog();

                        //  Exit the program if user exit the Database Connection Initial Setup
                        if (!dbConForm.Connected)
                        {
                            MessageBox.Show("Database Not Connected");
                            this.Close();
                        }
                        else
                        {
                            SetCabinetForm setCabinetForm = new SetCabinetForm(dbConForm.DbContoller);
                            setCabinetForm.ShowDialog();

                            if (!setCabinetForm.IsCabinetSelected())
                            {
                                MessageBox.Show("Initialize Error: No cabinet assigned." +
                                                "\nThe system cannot recognize a valid cabinet. The program will exit now.", "Initialize Error",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                                this.Close();
                            }
                            else
                            {
                                // Show the Cabinet Code if load successfully
                                labelCabinetCode.Text = dbController.CabinetCode;
                                _isLoaded             = true;
                            }
                        }
                    }
                    else
                    {
                        this.Close();
                    }
                }
                else
                {
                    // Show the Cabinet Code if load successfully
                    labelCabinetCode.Text = dbController.CabinetCode;
                    _isLoaded             = true;
                }
            }
        }