代码如下:
static int n=0;
private void btnqd_Click(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection("Data Source=(local);Integrated Security=SSPI;Initial Catalog=Rab_MIS");
string sql="select * from users where User_id='" + txtUserid.Text.Trim() + "' and User_password = '" + txtPWD.Text.Trim() +"' ";
conn.Open();
SqlDataAdapter mycmd=new SqlDataAdapter(sql,conn);
DataSet ds=new DataSet();
mycmd.Fill(ds,"User");
conn.Close();
if (ds.Tables["User"].Rows.Count!=0)
{
//if(
power.quanxian=ds.Tables["User"].Rows[0]["User_power"].ToString();
Form FormDep=new frmMain();
FormDep.Show();
this.Hide();
}
else
{
n=n+1;
if(n==3)
{
MessageBox.Show("对不起,你无权使用该系统,单击确定退出!","警告");
Application.Exit();
}
else
{
string disp="";
disp="无法登陆!你还有"+(3-n)+"次机会";
MessageBox.Show(disp,"警告");
txtUserid.Text="";
txtPWD.Text="";
}
}
}