/// <summary>
        /// Closes the user search form, opens Users form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Hide();
            UsersForm frmUsers = new UsersForm();

            frmUsers.ShowDialog();
        }
Beispiel #2
0
        /// <summary>
        /// Opens User form, if logged in user has
        /// adequate permission level
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Users_ViewAll_Click(object sender, EventArgs e)
        {
            //Declare session permission table
            businessDataSet.SessionPermissionDataTable table;
            //Fill table with session permission data
            table = adapter.GetData();

            //Get current user's permission level
            int permissionLevel = Convert.ToInt32(table.Rows[0]["Permission"]);

            //If user has administrator privileges
            if (permissionLevel == 1)
            {
                //Close form, display User form
                this.Hide();
                UsersForm frmUsers = new UsersForm();
                frmUsers.ShowDialog();
            }
            //Block access
            else
            {
                lblStatus.Text = "You do not have permission to enter this area";
                return;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds a user to the database based on user input
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            //Make sure text boxes aren't empty
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    TextBox t = (TextBox)c;
                    if (t.Text == "")
                    {
                        lblStatus.Text = t.Tag + " can't be blank";
                        t.Focus();
                        return;
                    }
                }
            }

            //Make sure combo box value is selected
            if (cboPermission.SelectedIndex == -1)
            {
                lblStatus.Text = "Permission level must be selected";
                cboPermission.Focus();
                return;
            }

            //Assign values
            string username    = txtUsername.Text;
            string password    = txtPassword.Text;
            string permissions = cboPermission.SelectedItem.ToString();

            //Create new user with input values
            User newUser = new Final_Project.User(username, password, permissions);

            //Add user to database
            if (newUser.AddUserToDB() == true)
            {
                //Close form
                this.Hide();
                //Go back to users form
                UsersForm frmUsers = new UsersForm();
                frmUsers.ShowDialog();
            }
            //Display error message
            else
            {
                lblStatus.Text = "Error Adding to Database";
            }
        }
        /// <summary>
        /// Updates user in database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdateUser_Click(object sender, EventArgs e)
        {
            //Check text boxes aren't blank
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                {
                    TextBox t = (TextBox)c;
                    if (t.Equals(""))
                    {
                        lblStatus.Text = t.Tag + " can't be blank";
                        return;
                    }
                }
            }

            //Validate combo box selection
            if (cboPermissions.SelectedIndex == -1)
            {
                lblStatus.Text = "Permission level must be selected";
                return;
            }

            //Set fields to user input
            string username   = txtUsername.Text;
            string password   = txtPassword.Text;
            string permission = cboPermissions.SelectedItem.ToString();

            //Update User
            if (userToUpdate.UpdateUserInDB(userID, username, password, permission) == true)
            {
                this.Hide();
                UsersForm frmUsers = new UsersForm();
                frmUsers.ShowDialog();
            }
            else
            {
                //Display error message
                lblStatus.Text = "Error updating database";
                return;
            }
        }