Beispiel #1
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";
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns a user
        /// </summary>
        /// <param name="userID">UserID to find user</param>
        /// <returns>Copy of user object</returns>
        public User GetUser(int userID)
        {
            User u = new Final_Project.User();

            //Declare user table
            businessDataSet.UsersDataTable userTable;
            //Fill table with user data
            userTable = userAdapter.GetData();
            //Declare user dataset row
            businessDataSet.UsersRow row;
            //Set row equal to user with matching user ID
            row          = userTable.FindById(userID);
            u.Username   = row.Username;
            u.Password   = row.Password;
            u.Permission = row.Permission;

            return(u);
        }