欢迎来到天天文库
浏览记录
ID:17001432
大小:31.00 KB
页数:6页
时间:2018-08-26
《c#登录窗体密码错误三次关闭窗体》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Configuration;usingSystem.Data.SqlClient;namespacedenglu1._0{publicpartialc
2、lassForm1:Form{stringstr=string.Empty;interrorcount=0;publicForm1(){InitializeComponent();}privatevoidbtn_login_Click(objectsender,EventArgse){str=ConfigurationManager.ConnectionStrings["strcnn"].ConnectionString;intsqlerror=GetError();//获取当期用户的登陆次数,以便进行比
3、较if(sqlerror>=3){20currencydeposit,weprescribeapassonaregularbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebondsapplyformortgageloans,acceptingonlythelenderDateTimeerrortim
4、e=GetErrorTime();//Subtract函数减去指定时间,返回一个时间差,时间的格式可以是分钟也可以是秒、小时TimeSpanspan=DateTime.Now.Subtract(errortime);doubleminute=span.TotalMinutes;//取时间间隔的分钟数//doublem=span.TotalSeconds;if(minute<2){MessageBox.Show("您已经连续3次输入密码错误,系统已被锁定,请两分钟之后再次重试");//后面的代码不执行ret
5、urn;}else{errorcount=0;UpdateError(errorcount);}}errorcount=GetError();DataTabledt=GetDataTable();if(dt.Rows.Count<=0){errorcount++;UpdateError(errorcount);UpdateErrorTime();MessageBox.Show("输入的用户名和密码不正确,请重新输入");}20currencydeposit,weprescribeapassonaregul
6、arbasis,qilucardaccountonaregularbasis),certificatebondsandsavingsbonds(electronic);3.notdrawnonabanksavingscertificate,certificatebondsapplyformortgageloans,acceptingonlythelenderelseif(dt.Rows.Count>1){MessageBox.Show("系统出现故障,请与管理员联系");}else{//登陆成功后,错误次
7、数清零errorcount=0;UpdateError(errorcount);MessageBox.Show("登陆成功");}}//更改用户登陆错误的当前时间privatevoidUpdateErrorTime(){SqlConnectionsqlcnn=newSqlConnection(str);SqlCommandsqlcmm=newSqlCommand();sqlcnn.Open();sqlcmm.Connection=sqlcnn;sqlcmm.CommandText="updateusers
8、seterrortime=@errortimewhereusername=@username";sqlcmm.Parameters.AddWithValue("@errortime",DateTime.Now);sqlcmm.Parameters.AddWithValue("@username",this.txt_name.Text);sqlcmm.ExecuteNonQuery();}//获取当前用户错误登陆时的时间priv
此文档下载收益归作者所有