我想使用条件在我的计数中创建用户尝试。我如何使用条件来执行这种逻辑以及在下面的代码中放置的位置。示例:如果用户尝试登录 3 次,但用户输入错误并通过,他将收到一条消息,提示您已达到登录尝试次数
private void btn_login_Click(object sender, EventArgs e)
{
var obj = new Usercontrols.SIMSMain();
obj.Dock = DockStyle.Fill;
conn.Open();
SqlCommand selectCommand = new SqlCommand("Select * from admin_access where Username=@admin AND Password=@eyelab",conn);
selectCommand.Parameters.AddWithValue("@admin", txt_username.Text);
selectCommand.Parameters.AddWithValue("@eyelab", txt_password.Text);
SqlDataReader dataReader;
dataReader = selectCommand.ExecuteReader();
var count = 0;
while (dataReader.Read())
{
count = count + 1;
}
if (string.IsNullOrEmpty(txt_username.Text) || string.IsNullOrEmpty(txt_password.Text))
{
MetroMessageBox.Show(this, "Please input the Required Fields", "System Message:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
if (count == 1)
{
MetroMessageBox.Show(this, "Login Successful", "System Message:", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
this.Parent.Controls.Add(obj);
}
else if (count == 3)
{
count++;
MetroMessageBox.Show(this, "Super Attempt", "System Message:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MetroMessageBox.Show(this, "Invalid Username/Password", "System Message:", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
}
conn.Close();
}
慕哥9229398
至尊宝的传说
红糖糍粑
相关分类