private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;"))
{
using (SqlCommand com = new SqlCommand())
{
com.CommandText = "select * from T_Users where UserName=@username";
com.Connection = con;
con.Open();
com.Parameters.Add(new SqlParameter("username", txbUserName.Text));
//com.Parameters.Add(new SqlParameter("password", textBox2.Text));
using (SqlDataReader read = com.ExecuteReader())
{
if (read.Read())
{
int errortimes = read.GetInt32(read.GetOrdinal("ErrorTimes")); //读取错误登陆次数
if (errortimes >= 3) //判断错误次数是否大于等于三
{
MessageBox.Show("sorry 你已经不能再登陆了!");
}
else
{
string passwored = read.GetString(read.GetOrdinal("PassWord"));
if (passwored == txbPassWord.Text)
{
MessageBox.Show("登陆成功!");
this.qingling(); //登陆成功把错误登陆次数清零
}
else
{
MessageBox.Show("登陆失败!");
this.leiji(); //登陆失败把错误登陆次数加一
}
}
}
}
}
}
}
public void leiji()
{
using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;"))
{
using (SqlCommand com = new SqlCommand())
{
com.Connection = con;
com.CommandText = "update T_Users set ErrorTimes=ErrorTimes+1 where UserName=@username";
com.Parameters.Add(new SqlParameter("username", txbUserName.Text));
con.Open();
com.ExecuteNonQuery();
}
}
}
public void qingling()
{
using (SqlConnection con = new SqlConnection("server=.; database=text; integrated security=SSPI;"))
{
using (SqlCommand com = new SqlCommand())
{
com.Connection = con;
com.CommandText = "update T_Users set ErrorTimes=0 where UserName=@username";
com.Parameters.Add(new SqlParameter("username", txbUserName.Text));
con.Open();
com.ExecuteNonQuery();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有