private void button1_Click(object sender, System.EventArgs e)
{
if(this.comboBox1.Text.Length<1)
{
this.errorProvider1.SetError(this.comboBox1,"用户名输入错误");
DialogResult a=MessageBox.Show(this,"用户名输入错误,是否重新输入?","信息提示",
MessageBoxButtons.YesNo,MessageBoxIcon.Question);
switch(a)
{
case DialogResult.Yes:
this.comboBox1.Text="";
break;
case DialogResult.No:
break;
}
}
if(this.textBox2.Text.Length<6)
{
MessageBox.Show("密码长度不能小于6!请重新输入!");
textBox2.Text="";
return;
}
string sql="select * from 管理员 where 用户名='"+comboBox1.Text+"'and 密码='"+textBox2.Text+"'";
SqlConnection sqlcon=new SqlConnection("server=839B2FF55DCC463;database=仓库;User ID=sa;Password=123456");
sqlcon.Open();
SqlCommand com=new SqlCommand(sql,sqlcon);
SqlDataReader sdr=com.ExecuteReader();
if(sdr.HasRows)
{ sdr.Close();
string sql1="update 管理员 set 状态='1' where 用户名='"+comboBox1.Text+"'and 密码='"+textBox2.Text+"'";
SqlDataAdapter s1=new SqlDataAdapter(sql1,sqlcon);
DataSet ds1=new DataSet();
s1.Fill(ds1,"管理员");
this.Hide();
new Form2().Show();
}
else
{
MessageBox.Show("名和密码不匹配!请重新输入!");
this.Show();
textBox2.Text="";
textBox2.Focus();
}
}
private void Form2_Load(object sender, System.EventArgs e)
{
string sql="select 用户名 from 管理员";
SqlConnection sqlcon=new SqlConnection("server=839B2FF55DCC463;database=仓库;uid=sa;pwd=123456");
string sql2="update 管理员 set 状态='0' ";
SqlDataAdapter s2=new SqlDataAdapter(sql2,sqlcon);
DataSet ds2=new DataSet();
s2.Fill(ds2,"管理员");
SqlDataAdapter s=new SqlDataAdapter(sql,sqlcon);
DataSet ds=new DataSet();
s.Fill(ds,"管理员");
comboBox1.DataSource=ds.Tables[0].DefaultView;
comboBox1.Text="用户名";
comboBox1.ValueMember="用户名";
}
private void button2_Click(object sender, System.EventArgs e)
{
comboBox1.Text="";
textBox2.Text="";
}