【前言】
在七层登录的 基础上进行登录用户的密码修改。
【实现】
代码片
UI
public void btnOk_Click(object sender, EventArgs e)
{
if (txtOldPWD.Text.Trim().Length == 0 || txtNewPWD.Text.Trim().Length == 0 || txtCheckPWD.Text.Trim().Length == 0)
{
MessageBox.Show("请输入完整!","");
return;
}
if (txtNewPWD.Text.Trim() != txtCheckPWD.Text.Trim())
{
MessageBox.Show("两次密码输入不一致,请重新输入!");
return;
}
if (txtOldPWD.Text != frmLogin.PassWord)
{
MessageBox.Show("原密码输入错误,请重新输入", "提示");
return;
}
else
{
LoginFacade Facade = new LoginFacade();
Entity.AdUserInfo user = new AdUserInfo();
user.UserID = frmLogin.UserID;
user.PassWord = txtNewPWD.Text;
Boolean result = false;
UpDateUserPWD updateuserpwd = new UpDateUserPWD();
result = updateuserpwd.UpDateUserpwd(user);
if (result != false)
{
MessageBox.Show("操作错误!", "提示");
txtCheckPWD.Clear();
txtNewPWD.Clear();
txtOldPWD.Clear();
}
else
{
MessageBox.Show("修改成功", "提示");
txtCheckPWD.Clear();
txtNewPWD.Clear();
txtOldPWD.Clear();
}
}
DAL
public class ChangePWD :IDAL.PassWordIDAL
{
public int UpDateUser(AdUserInfo UserInfo)
{
SQLHelper sqlhelper = new SQLHelper();
SqlParameter[] sqlParams =
{ new SqlParameter("@userID", UserInfo.UserID),
new SqlParameter("@PassWord", UserInfo.PassWord) };
string sql = @"update T_User set PWD=@Password where userID =@userID ";
int res = sqlhelper.ExecuteNonQuery(sql, sqlParams, CommandType.Text);
return res;
BLL
namespace BLL
{
public class ChangePWDBLL
{
public bool UserPassWord(Entity.UserInfo UserInfo)
{
Factory. AllFactory fact = new Factory.AllFactory();//工厂实例化
IDAL.PassWordIDAL idal = fact.UpdateUser();//调用工厂方法创建接口
int table = idal.UpDateUser(UserInfo);
bool falg;
if (table> 0)//返回的DataTable类型,如果它的行数等于0,说明没有符合该帐号密码的用户
{
falg = false; }
else
{
falg = true;
}
return falg;
}
}
Facade
public class UpDateUserPWD
{
public Boolean UpDateUserpwd(Entity.AdUserInfo User)
{
bool flag;
BLL.ChangePWDBLL userBLL = new BLL.ChangePWDBLL();
flag = userBLL.UserPassWord(User);
return flag;
}
}
【收获】
还有接口跟工厂的就不贴出来了,自己在这一段时间为了个这个这的是头疼啊。
想想还是先辈说的对“实践是检验真理的唯一标准!!!”
加油吧,少年!