// event method for when the delete booking button has been clicked
        private void btnDeleteBook_Click(object sender, EventArgs e)
        {
            // show confirmation message - if answered yes, continue
            if (MessageBox.Show("Are you sure?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
            {
                // delete the booking with id of x from tblBookings
                string cmd = String.Format("DELETE from tblBookings WHERE Id = {0}", book.id);

                Debug.WriteLine("Started delete process..");

                try
                {
                    // execute command with the miscAction method
                    db.miscAction(cmd);
                    help.refreshHomeForm();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }

                // closes the form
                this.Close();
            }
        }
Exemple #2
0
 // event method for when the delete all bookings button is clicked
 private void btnDeleteAll_Click(object sender, EventArgs e)
 {
     // show confirmation dialog to user. continue if user clicked 'yes'
     if (MessageBox.Show("Are you sure you want to delete all bookings?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
     {
         // sends misc query to database
         db.miscAction("TRUNCATE TABLE tblBookings");
     }
 }
Exemple #3
0
        // when delete all bookings button is clicked
        private void btnDeleteAll_Click(object sender, EventArgs e)
        {
            // show confirmation message - if answer is yes
            if (MessageBox.Show("Are you sure you want to delete all bookings?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Yes)
            {
                // delete all bookings
                db.miscAction("TRUNCATE TABLE tblBookings");

                // refresh the form
                refreshForm();
            }
        }
Exemple #4
0
        // when the submit button is clicked
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            // default the password given to null
            string givenPassword = null;

            // CHECK: password match
            if (!String.IsNullOrEmpty(txtPass1.Text))
            {
                // if both passwords are tge sane
                if (txtPass1.Text == txtPass2.Text)
                {
                    // the given password is that has been entered into txtPass1
                    givenPassword = txtPass1.Text;
                }
                // else throw error message, abandon checks and force password reattempt
                else
                {
                    MessageBox.Show("The two passwords you entered don't match!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            // CHECK: username already exists
            if (db.checkUsernameExists(txtUsername.Text, userID))
            {
                // throw error message to user
                MessageBox.Show("That username is taken!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // CHECK: username alphanumeric
            Regex alphanumeric = new Regex("^[a-zA-Z0-9]*$");

            // if the username does not meet the regex requirements: throw error message
            if (!alphanumeric.IsMatch(txtUsername.Text))
            {
                MessageBox.Show("The username should only contain alphanumeric characters! (A-Z, a-z and 0-9)", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // CHECK: username length is less than or = 15
            if (txtUsername.Text.Length > 15)
            {
                MessageBox.Show("The username should be 15 characters or less!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // if form is set to new user mode
            if (newUserMode)
            {
                try
                {
                    // set SQL command to INSERT
                    string cmd = String.Format("INSERT INTO tblUsers (FirstName, SecondName, Password, Role, Username) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}')", txtName1.Text, txtName2.Text, txtPass1.Text, bxRoleList.Text, txtUsername.Text);

                    // send the command to the Database server
                    db.miscAction(cmd);

                    // refresh the home form to accomodate for new data
                    helper.refreshHomeForm();

                    // close this form
                    this.Close();
                }
                // if error in the sending of the SQL command: throw to user
                catch (Exception ex)
                {
                    MessageBox.Show("An unexpected error occured. \nDetails: " + ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            // if form is in edit mode
            else
            {
                // if no new password is given, set the given password to their current password
                if (String.IsNullOrEmpty(givenPassword))
                {
                    givenPassword = user.password;
                }

                try
                {
                    // call updateuser method and pass through all user details
                    db.updateUser(userID, txtName1.Text, txtName2.Text, givenPassword, bxRoleList.Text, txtUsername.Text);

                    // if the user being edited is the current logged in user
                    if (session.userID == userID)
                    {
                        // change their name shown at top to updated name
                        session.name = new string[] { txtName1.Text, txtName2.Text };
                    }
                    // refresh the home form to show new details
                    helper.refreshHomeForm();

                    // close the form
                    this.Close();
                }
                // if an error occurs, throw to user
                catch (Exception ex)
                {
                    MessageBox.Show("An unexpected error occured. \nDetails: " + ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }