Example #1
0
        // Add new Administrator.
        private void Button_AddAdministrator_Click(object sender, EventArgs e)
        {
            string         chiefAdmin      = this.textBox_ChiefAdministrator.Text.Trim();
            string         adminPassword   = this.textBox_ChiefAdminPassword.Text.Trim();
            string         newAdmin        = this.textBox_NewAdministrator.Text.Trim();
            string         firstName       = this.textBox_AdministratorFirstName.Text.Trim();
            string         lastName        = this.textBox_AdministratorLastName.Text.Trim();
            string         password        = this.textBox_Password.Text.Trim();
            string         confirmPassword = this.textBox_ConfirmPassword.Text.Trim();
            Administrator  administrator   = new Administrator();
            Administration administration  = new Administration();

            if (administrator.IsDataValid(chiefAdmin, adminPassword, newAdmin, firstName, lastName, password, confirmPassword, out string message))
            {
                if (administration.IsChiefAdminCorrect(chiefAdmin, adminPassword, out int administrationId, out message))
                {
                    if (!administrator.DoesAdministratorExists(administrationId, newAdmin, out message))
                    {
                        if (password == confirmPassword)
                        {
                            if (administrator.AddNewAdministrator(administrationId, newAdmin, firstName, lastName, password, out message))
                            {
                                MessageBox.Show(message,
                                                "Add Administrator",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Information);
                                ClearNewAdminData();
                            }
                            else
                            {
                                MessageBox.Show(message,
                                                "Add Administrator",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Password and Confirm Password must be the same!",
                                            "Add Administrator",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show(message,
                                        "Add Administrator",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show(message,
                                    "Add Administrator",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }
        // Button Select Administrator. Shows list of all administrators.
        private void Button_ShowAdministrators_Click(object sender, EventArgs e)
        {
            string chiefAdmin    = this.textBox_ChiefAdministrator.Text.Trim();
            string chiefPassword = this.textBox_ChiefAdminPassword.Text.Trim();

            if (administrator.IsDataValid(chiefAdmin, chiefPassword, out string message))
            {
                if (administration.IsChiefAdminCorrect(chiefAdmin, chiefPassword, out int administrationId, out message))
                {
                    Id = administrationId;

                    // Show a Form to select the Administrator which we want to delete.
                    Form_SelectAdministrator selectAdmin = new Form_SelectAdministrator();

                    using (selectAdmin)
                    {
                        selectAdmin.ShowDialog();
                        this.textBox_AdministratorName.Text = selectAdmin.dataGridView_Administrators.CurrentRow.Cells["Administrator Login"].Value.ToString();
                    }
                }
                else
                {
                    MessageBox.Show(message,
                                    "Select Administrator",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
            }