private void button1_Click(object sender, EventArgs e)
{
try
{
if (textBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("对不起用户名不能为空");
}
else
{
if (textBox2.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("对不起密码不能为空");
}
else
{
SqlConnection conn = new SqlConnection(@"Data Source=(local);Initial Catalog=工资信息管理系统;Integrated Security=True"); //创建数据库连接
conn.Open();
SqlCommand cmd = null;
if (comboBox1.Text.Trim().Equals("--请选择--"))
{
MessageBox.Show("请选择身份");
comboBox1.Focus();
return;
}
switch (comboBox1.Text)
{
case "高级职员":
cmd = new SqlCommand("select count(*) from 职员—职员分类 where 用户名='" + textBox1.Text + "' and 用户密码='" + textBox2.Text + "' and 职工分类ID='001'", conn);
break;
case "中级职员":
cmd = new SqlCommand("select count(*) from 职员—职员分类 where 用户名='" + textBox1.Text + "' and 用户密码='" + textBox2.Text + "'and 职工分类ID='002'", conn);
break;
case "普通职员":
cmd = new SqlCommand("select count(*) from 职员—职员分类 where 用户名='" + textBox1.Text + "' and 用户密码='" + textBox2.Text + "'and 职工分类ID='003'", conn);
break;
}
int i = Convert.ToInt32(cmd.ExecuteScalar()); //获取返回值
if (i > 0)
{
if (comboBox1.Text == "高级职员")
{
Form2 f = new Form2();
f.Show();
this.Hide();
}
}
else
{
MessageBox.Show("对不起!你无权进入,请检查你用户名和密码或登录界面选择是否正确!"); //弹出提示
}
}
} }
catch (Exception ex)
{
ex.GetType();
} }
请解释下 谢谢!!
{
try
{
if (textBox1.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("对不起用户名不能为空");
}
else
{
if (textBox2.Text.Trim().Equals(string.Empty))
{
MessageBox.Show("对不起密码不能为空");
}
else
{
SqlConnection conn = new SqlConnection(@"Data Source=(local);Initial Catalog=工资信息管理系统;Integrated Security=True"); //创建数据库连接
conn.Open();
SqlCommand cmd = null;
if (comboBox1.Text.Trim().Equals("--请选择--"))
{
MessageBox.Show("请选择身份");
comboBox1.Focus();
return;
}
switch (comboBox1.Text)
{
case "高级职员":
cmd = new SqlCommand("select count(*) from 职员—职员分类 where 用户名='" + textBox1.Text + "' and 用户密码='" + textBox2.Text + "' and 职工分类ID='001'", conn);
break;
case "中级职员":
cmd = new SqlCommand("select count(*) from 职员—职员分类 where 用户名='" + textBox1.Text + "' and 用户密码='" + textBox2.Text + "'and 职工分类ID='002'", conn);
break;
case "普通职员":
cmd = new SqlCommand("select count(*) from 职员—职员分类 where 用户名='" + textBox1.Text + "' and 用户密码='" + textBox2.Text + "'and 职工分类ID='003'", conn);
break;
}
int i = Convert.ToInt32(cmd.ExecuteScalar()); //获取返回值
if (i > 0)
{
if (comboBox1.Text == "高级职员")
{
Form2 f = new Form2();
f.Show();
this.Hide();
}
}
else
{
MessageBox.Show("对不起!你无权进入,请检查你用户名和密码或登录界面选择是否正确!"); //弹出提示
}
}
} }
catch (Exception ex)
{
ex.GetType();
} }
请解释下 谢谢!!
textBox1.Text.Trim().Equals(string.Empty);
//Equals全部换成
textBox1.Text.Trim() == string.Empty;
MessageBox.Show("有反应没?");
就知道该button有没有反应了.
导致这个按钮的Click事件没关联button1_Click这个事件,点击无效。
<asp:Button ID="Button3" runat="server" Text="Excel导出" OnClick="ExcelOut" OnClientClick="clint();" class="normal-button" />看看如果你有加OnClientClick事件 js有没有return true,如果false那就不会进入OnClick事件了