【机房重构】- 修改密码

修改密码
  1. 相关的输入限制
  2. 判断原密码是否正确
  3. 将新密码添加到数据库
代码实现

U层

public partial class Login : Form
{
	public static string id;//在登录窗体中定义一个静态全局变量,登录窗体存在时,变量id的值就会存在
	Boolean flag = false;
	flag = user.SelectUser(userinfo.UserId, userinfo.Pwd);
	if (flag!=false)
	{
		id = txtUserName.Text.Trim();//在用户名密码判断完成之后,将用户名文本框中的内容赋给变量id
		this.Hide();
		this.DialogResult = System.Windows.Forms.DialogResult.OK;
		...
	}
    else
    {
     	MessageBox.Show("密码或用户名错误");
     }	
}
public partial class ModifyPWD : Form
{
	private void btOK_Click(object sender, EventArgs e)
	{
		//前面是常规有关输入问题的判断
		...
		try
		{
			Facade.UserFacade fact = new Facade.UserFacade();
			string id = Login.id;//不用实例化登录窗体,使用登录窗体中变量id的值赋给修改密码窗体中的变量id
			string password = txtOldPWD.Text;
			string newpwd = txtNewPWD.Text;
			bool flag = fact.UpdatePwd(id, password,newpwd);//利用三者之间的关系来修改密码
			if (flag!=false)
			{
				MessageBox.Show("修改密码成功!", "提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				this.Hide();
			}
			else
			{
				MessageBox.Show("原密码不正确!", "提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
		}
		catch (Exception)
		{
			throw;
		}
	}
}

Facade层

public Boolean UpdatePwd(string userid,string password,string newpwd)
{
	bool flag = userBll.UpdatePwd(userid, password,newpwd);
	return flag;
}

B层

public bool UpdatePwd(string userid,string password,string newpwd)
{
	bool flag = idal.UpdatePwd(userid, password,newpwd);
	return flag;
}

D层

public bool UpdatePwd(string userid,string password,string newpwd)
{
	SqlParameter[] sqlParams = {new SqlParameter("@userId",userid),
									new SqlParameter("@password",password),
									new SqlParameter("@newpwd",newpwd)};
	string sql = @"update [User_Info] set pwd=@newpwd where userId=@userId and pwd=@password ";
	return sqlHelper.ExecuteNonQuery(sql, sqlParams, CommandType.Text) > 0;
}
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值