Example #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         string  userName    = this.txtBoxUser.Text.Trim();
         string  realname    = this.txtRealname.Text.Trim();
         string  passWord    = this.txtBoxPwd.Text.Trim();
         string  telePhone   = this.txtBoxPhone.Text.Trim();
         string  email       = this.txtBoxEmail.Text.Trim();
         string  address     = this.txtBoxAddress.Text.Trim();
         int     paramRoleID = Convert.ToInt32(this.cmbRole.SelectedValue.ToString());
         BUUsers myBUUsers   = new BUUsers();
         bool    result      = myBUUsers.InsertUse(userName, passWord, realname, telePhone, email, address, paramRoleID);
         if (result)
         {
             MessageBox.Show("用户添加成功");
             this.DialogResult = DialogResult.OK;
         }
     }
     catch
     {
         MessageBox.Show("操作错误");
         this.DialogResult = DialogResult.No;
     }
 }
        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                string  userName    = this.txtBoxUser.Text.Trim();
                string  telePhone   = this.txtBoxPhone.Text.Trim();
                string  email       = this.txtBoxEmail.Text.Trim();
                string  address     = this.txtBoxAddress.Text.Trim();
                string  realname    = this.txtRealname.Text.Trim();
                int     paramRoleID = Convert.ToInt32(this.cmbRole.SelectedValue.ToString());
                BUUsers myBUUsers   = new BUUsers();
                bool    checkValue  = myBUUsers.UpdateUser(userName, telePhone, realname, email, address, paramRoleID);

                if (checkValue)
                {
                    MessageBox.Show("用户修改成功");
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("用户修改成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnUserDel_Click(object sender, EventArgs e)
        {
            if (this.gdvInfo.SelectedRowsCount <= 0)
            {
                MessageBox.Show("请选择要删除的用户!");
                return;
            }

            int[] indexArr = this.gdvInfo.GetSelectedRows();
            bool  Result   = false;

            if (MessageBox.Show("确定删除被选中的信息吗?", "温馨提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                for (int i = 0; i < indexArr.Count(); i++)
                {
                    string  paramUserName = this.gdvInfo.GetDataRow(indexArr[i])["username"].ToString();//获取到需要删除的行的主健
                    BUUsers myBUUsers     = new BUUsers();
                    Result = myBUUsers.DeleteUser(paramUserName);;
                }
            }
            if (Result)
            {
                MessageBox.Show("删除成功");
                btnSearchUser_Click(sender, e);
            }
            else
            {
                MessageBox.Show("删除失败");;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            string  userName        = this.txtBoxMyName.Text.ToString();
            string  passWord        = this.txtBoxMyPassWord.Text.ToString();
            string  newPassword     = this.txtBoxNewPassWord.Text.ToString();
            string  confirmPassword = this.txtBoxConfirm.Text.ToString();
            BUUsers myBUUsers       = new BUUsers();
            string  md5_Password    = DbEncrypt.MD5Encrypt(passWord);
            string  md5_NewPassword = DbEncrypt.MD5Encrypt(newPassword);
            bool    isCheckPassword = myBUUsers.CheckUserPassword(userName, md5_Password);

            if (isCheckPassword)
            {
                if (newPassword == confirmPassword)
                {
                    bool check = myBUUsers.UpdateMyPassword(userName, md5_NewPassword);
                    if (check)
                    {
                        if (passWord != newPassword)
                        {
                            MessageBox.Show("密码修改成功", "恭喜您", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.txtBoxMyPassWord.Text  = string.Empty;
                            this.txtBoxNewPassWord.Text = string.Empty;
                            this.txtBoxConfirm.Text     = string.Empty;
                            this.txtBoxMyPassWord.Focus();
                        }
                        else if (passWord == newPassword)
                        {
                            MessageBox.Show("新密码与旧密码相同,请输入不同密码!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            this.txtBoxMyPassWord.Text  = string.Empty;
                            this.txtBoxNewPassWord.Text = string.Empty;
                            this.txtBoxConfirm.Text     = string.Empty;
                            this.txtBoxMyPassWord.Focus();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("您前后二次输入的密码不一致,请重新输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    this.txtBoxConfirm.Text = string.Empty;
                    this.txtBoxConfirm.Focus();
                }
            }
            else
            {
                MessageBox.Show("您输入的旧密码有误,请重新输入!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.txtBoxMyPassWord.Text = string.Empty;
                this.txtBoxMyPassWord.Focus();
            }
        }