コード例 #1
0
        private void updateUserBTN_Click(object sender, EventArgs e)
        {
            if (addingUser)
            {
                string         perm = permissionDD.Text;
                UserPermission up   = userPermissions[perm];
                User           u    = new User(0, loginTB.Text, nameFirstTB.Text, nameLastTB.Text, up.DatabaseID);
                string         pw   = newPassTB.Text;
                string         pwv  = newPassVerifyTB.Text;
                if (pw != pwv)
                {
                    MessageBox.Show("Passwords do not match. Verify they match and try again.");
                }
                else if (!ValidatePassword(pw))
                {
                    MessageBox.Show("Password does not meet the strength requirements. Please update.");
                }
                else
                {
                    if (MessageBox.Show("Adding new user to the database." + Environment.NewLine +
                                        "Name: " + u.FullName() + Environment.NewLine +
                                        "Login: "******"Permission: " + up.Title, "ADDING USER", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)
                        == System.Windows.Forms.DialogResult.Yes)
                    {
                        // Add user to database
                        string pwh = FSManager.HashString(pw);
                        db.NewAccount(u, pwh);

                        // Refresh user list
                        EstablishUserManagement();
                    }
                }
            }
            else
            {
                // Editing user
                bool updatePassword = false;

                // Check to see if updating password
                string newPass  = newPassTB.Text;
                string newPassV = newPassVerifyTB.Text;
                if (newPass == newPassV && ValidatePassword(newPass))
                {
                    updatePassword = true;
                }

                if (users.ContainsKey(selUser))
                {
                    User u = users[selUser];
                    users[selUser].NameFirst = nameFirstTB.Text;
                    users[selUser].NameLast  = nameLastTB.Text;
                    users[selUser].Login     = loginTB.Text;
                    string permTitle = permissionDD.Text;
                    if (userPermissions.ContainsKey(permTitle))
                    {
                        UserPermission up = userPermissions[permTitle];
                        users[selUser].PermissionID    = up.DatabaseID;
                        users[selUser].PermissionLevel = up.Level;
                        users[selUser].PermissionTitle = up.Title;
                    }

                    if (updatePassword)
                    {
                        // Do full update
                        db.EditAccount(users[selUser], FSManager.HashString(newPass));
                        EstablishUserManagement();
                    }
                    else
                    {
                        db.EditAccount(users[selUser]);
                        EstablishUserManagement();
                        // Do standard update
                        //db.EditAccount(users[selUser]);
                        //EstablishUserManagement();
                    }
                }
            }
        }