登录按键:
private void button1_Click(object sender, EventArgs e)
{
//用户登录
pwd = GetHash(password);
try
{
string connect = "数据库连接字符串";
SqlConnection conn = new SqlConnection(connect);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select userno from userinfo where userno = '" + userno.Text + "' and (userpwd = '" + pwd + "'or userpwd = '" + userpwd.Text + "')";
SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
if (adapter1.Fill(ds) == 0)
{
MessageBox.Show("用户编号或密码错,请重新登录!");
userpwd.Focus();
password = "";
}
else
{
Main newForm = new Main();
newForm.userno1 = ds.Tables[0].Rows[0]["userno"].ToString();
newForm.roleid1 = ds.Tables[0].Rows[0]["roleid"].ToString();
newForm.Show();
this.Hide();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
this.Close();
}