黑马程序员 员工管理系统登录 功能实现

----------- Windows Phone 7手机开发、.Net培训、期待与您交流! ------------

 

 1   int errorTimes = 0;
 2 
 3         private void btnOk_Click(object sender, RoutedEventArgs e)
 4         {
 5             if (txtUser.Text.Length <= 0)
 6             {
 7                 MessageBox.Show("请输入用户名!");
 8                 txtUser.Focus();
 9                 return;
10             }
11             if (txtPwd.Password.Length <= 0)
12             {
13                 MessageBox.Show("请输入密码!");
14                 txtPwd.Focus();
15                 return;
16             }
17             EmpInfoWindow empInfo = new EmpInfoWindow();
18 
19             DataTable table = SqlHelper.ExecuteDataTable("select * from T_EmpUser where username=@UserName",
20                 new SqlParameter("@UserName", txtUser.Text));
21 
22             if (table.Rows.Count <= 0)
23             {
24                 MessageBox.Show("用户不存在!");
25                 txtUser.Focus();
26                 txtUser.SelectAll();
27                 return;
28             }
29 
30             //防止意外两个重名用户,做处理。
31             if (table.Rows.Count > 1)
32             {
33                 throw new Exception("用户名重复");
34             }
35 
36             DataRow row = table.Rows[0];
37             string dbPwd = (string)row["password"];
38             long Id = (long)row["id"];
39             errorTimes = (int)row["errortimes"];
40             if (errorTimes >= 3)
41             {
42                 MessageBox.Show("输入次数超过3次,用户已被锁定");
43                 return;
44             }
45             if (dbPwd != txtPwd.Password)
46             {
47                 SqlHelper.ExecuteNonQuery("update T_EmpUser set errortimes = errortimes + 1 where @Id = id",
48                     new SqlParameter("@Id",Id));
49                 MessageBox.Show("密码输入错误!还有" + (3 - errorTimes) + "次输入机会,如果连续输入超过3次,用户将被锁定!");
50                 txtPwd.Focus();
51                 txtPwd.SelectAll();
52                 this.Focus();
53             }
54             else
55             {
56                 this.Hide();
57                 empInfo.ShowDialog();
58             }
59 
60  

 

 

 

转载于:https://www.cnblogs.com/octlee/archive/2013/04/10/3012816.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值