Net学习日记_ADO.Net_2_练习(登录逻辑)
2021-05-16 13:27
标签:nta ade sys for logs username min 多少 namespace 要求: 页面: 数据库设定 主程序 辅助 Net学习日记_ADO.Net_2_练习(登录逻辑) 标签:nta ade sys for logs username min 多少 namespace 原文地址:http://www.cnblogs.com/lisong-home/p/7747770.htmlusing System;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace Test01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BtOK_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=PC201609230944\\SQL2005;database=HeiMaBlog;user=sa;pwd=123456");
SqlCommand cmd = new SqlCommand("select *,datediff(minute,LastErrTime,GETDATE()) from UserInfo where UserName=@UserName", conn);
cmd.Parameters.Add(new SqlParameter("@UserName", TxName.Text.Trim()));
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();////不管dr取到多少条数据,只取出前面第一行(调用一次read,就会读取一行,也只读取一行)
if (dr.GetInt32(5) 15)
{
MessageBox.Show("时间未到,请稍后重试!!");
return;
}
if (dr[2].ToString() == TxPwd.Text.Trim())
{
MessageBox.Show("登录成功!!");
UserInfo.ReSetErrTimes(dr.GetInt32(0));//登录成功后,就重置错误时间
}
else
{
//如果密码不正确!!
MessageBox.Show("登录失败,密码错误");
UserInfo.UpDateErrTimes(dr.GetInt32(0));
// 错误三次就更新错误时间
if (dr.GetInt32(3) + 1 == 3)
{
UserInfo.UpDateLastErrTime(dr.GetInt32(0));
UserInfo.ReSetErrTimes(dr.GetInt32(0));
}
}
}
else
{
MessageBox.Show("该用户不存在!!!");
}
}
}
}
using System.Data.SqlClient;
namespace Test01
{
class UserInfo
{
///
文章标题:Net学习日记_ADO.Net_2_练习(登录逻辑)
文章链接:http://soscw.com/index.php/essay/86262.html