⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formchangepassword.cs

📁 人事管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace HumanResourceManagement
{
    public partial class FormChangePassword : Form
    {
        SqlConnection cnBlueHill_HRM;

        public FormChangePassword()
        {
            InitializeComponent();
        }

        private const int CP_NOCLOSE_BUTTON = 0x200;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams myCp = base.CreateParams;
                myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
                return myCp;
            }
        } 

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtOldPassword.Text.Trim() == "")
            {
                DialogResult = MessageBox.Show("请输入旧密码!", "提示");
                txtOldPassword.Focus();
            }
            else if (txtNewPassword1.Text.Trim() == "")
            {
                DialogResult = MessageBox.Show("请输入新密码!", "提示");
                txtNewPassword1.Focus();
            }
            else if (txtNewPassword2.Text.Trim() == "")
            {
                DialogResult = MessageBox.Show("请再次输入新密码!", "提示");
                txtNewPassword2.Focus();
            }
            else if (txtNewPassword1.Text.Length < 6)
            {
                DialogResult = MessageBox.Show("新密码至少6位!", "提示");
                txtNewPassword1.Focus();
                txtNewPassword1.Text = "";
                txtNewPassword2.Text = "";
            }
            else if (txtNewPassword1.Text.ToString().Trim() != txtNewPassword2.Text.ToString().Trim())
            {
                DialogResult = MessageBox.Show("两次新密码不一致,请认真填写!", "提示");
                txtNewPassword2.Focus();
                txtNewPassword1.Text = "";
                txtNewPassword2.Text = "";
            }
            else
            {
                try
                {
                    cnBlueHill_HRM = new SqlConnection("data source=.;initial catalog=BlueHill_HRM;integrated security=true;");
                    cnBlueHill_HRM.Open();
                    SqlCommand cmd = new SqlCommand("select Password from tblEmployee where EmployeeID='" + DB.getA + "'", cnBlueHill_HRM);
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        string Password = dr[0].ToString().Trim();
                        dr.Close();
                        if (txtOldPassword.Text.ToString().Trim() == Password)
                        {
                            SqlCommand cmdupdate = new SqlCommand("update tblEmployee set Password =('" + txtNewPassword2.Text.ToString().Trim() + "') where LoginName= ('" + DB.getA + "')", cnBlueHill_HRM);
                            int count = Convert.ToInt32(cmdupdate.ExecuteNonQuery());
                            if (count > 0)
                            {
                                DialogResult = MessageBox.Show("修改密码成功!", "提示");
                                cnBlueHill_HRM.Close();
                                this.Dispose();
                            }
                            else
                                DialogResult = MessageBox.Show("操作失败!", "提示");
                        }
                        else

                            DialogResult = MessageBox.Show("原密码不正确!", "提示");
                    }
                    else
                        dr.Close();
                    cnBlueHill_HRM.Close();
                }
                catch (Exception EV)
                {
                    DialogResult = MessageBox.Show(EV.ToString(), "提示");
                }
            }

        }

        private void picPhoto_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -