예제 #1
0
        private void MIinitPass_Click(object sender, EventArgs e)
        {
            if (dgvUserView.SelectedRows.Count > 0)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to Initialize Password for this User?", "Password Initialization", MessageBoxButtons.YesNo);
                if (dialogResult != DialogResult.Yes)
                {
                    return;
                }

                int    thisId   = Convert.ToInt32(dgvUserView.SelectedRows[0].Cells["Id"].Value.ToString());
                string initPass = CreateUser.GetRandomPassword();
                byte[] HashPass = ChangePassword.Encrypt(initPass);

                if (ChangePassword.update_PasswordHistory_TableAllRecsPerUser(thisId, false))
                {
                    if (ChangePassword.insertInto_PasswordHistory_Table(thisId, HashPass))
                    {
                        MessageBox.Show("Password Initialized successfully!");

                        NewPassword frmNewPass = new NewPassword(initPass);
                        frmNewPass.ShowDialog();

                        userList = SelectedUser();
                        FillDataGridView(dgvUserView, userList);
                    }
                    else
                    {
                        MessageBox.Show("Error while initializing password!");
                    }
                }
                else
                {
                    MessageBox.Show("Error while initializing password!");
                }
            }
        }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Trim() == "")
            {
                MessageBox.Show("Please insert a User Name!");
                return;
            }
            if (txtFullName.Text.Trim() == "")
            {
                MessageBox.Show("Please insert a Full Name!");
                return;
            }
            if (txtEmail.Text.Trim() == "")
            {
                MessageBox.Show("Please insert an Email!");
                return;
            }
            if (cbRoles.Text.Trim() == "")
            {
                MessageBox.Show("Please choose a Role!");
                return;
            }

            newUserRecord = new User();

            newUserRecord.Email    = txtEmail.Text;
            newUserRecord.FullName = txtFullName.Text;
            newUserRecord.UserName = txtUserName.Text;
            newUserRecord.Role     = InsertNewAudit.getComboboxItem <Role>(cbRoles);
            newUserRecord.RolesId  = InsertNewAudit.getComboboxItem <Role>(cbRoles).Id;


            newUserRecord.Id = oldUserRecord.Id; //update only

            if (isInsert)                        //insert
            {
                int NewUserId = InsertUser(newUserRecord);
                if (NewUserId > -1)
                {
                    MessageBox.Show("New User inserted successfully!");
                    success = true;

                    string initPass = GetRandomPassword();

                    byte[] HashPass = ChangePassword.Encrypt(initPass);

                    if (ChangePassword.insertInto_PasswordHistory_Table(NewUserId, HashPass))
                    {
                        NewPassword frmNewPass = new NewPassword(initPass);
                        frmNewPass.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("Error while creating new password!");
                    }

                    Close();
                }
                else
                {
                    MessageBox.Show("The New User has not been inserted!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else //update
            {
                if (UpdateTable_User(newUserRecord))
                {
                    MessageBox.Show("User updated successfully!");
                    success = true;
                    Close();
                }
                else
                {
                    MessageBox.Show("The User has not been updated!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }