private void ButtonConfirm_Click(object sender, EventArgs e) { string cabinetCode = comboBoxCabinetCode.Text; try { _dbController.CabinetCode = cabinetCode; _dbController.CheckCabinet(); _dbController.SaveIniFile(); _isCabinetSelected = true; this.Close(); } catch (InvalidCabinetException exception) { exception.ShowErrorMessage(); } catch (InvalidDatabaseConnectionException exception) { exception.ShowErrorMessage(); } }
// 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; } } }