日期:2014-05-17 浏览次数:20620 次
um.UserName = this.TextBox1.Text;
um.UserPwd = this.TextBox2.Text;
um.DepartMentName = this.DropDownList1.SelectedItem.Text;
if(ub.Login(um))
{
Response.Redirect("Admin.aspx");
}
public bool Login(UserModel um)
{
return userdal.Login(um);
}
public bool Login(UserModel um)
{
bool flag = false;
string sql = "select * from Users where UserName=@username and UserPwd=@userpwd and DepartMentName=@departmentname";
SqlParameter[] paras = new SqlParameter[]{
new SqlParameter("username",um.UserName),
new SqlParameter("userpwd",um.UserPwd),
new SqlParameter("departmentname",um.DepartMentName)
};
int res = sqlhelper.CheckLogin(sql, paras, CommandType.Text);
if (res > 0)
{
flag = true;
}
return flag;
}
public int CheckLogin(string CmdText, SqlParameter[] paras, CommandType ct)
{
int res;
using (cmd = new SqlCommand(CmdText, Getconn()))
{
cmd.CommandType = ct;
cmd.Parameters.AddRange(paras);
res = cmd.ExecuteNonQuery();
}
return res;
}
SqlConnection conn = new SqlConnection("server=.;uid=customer adm;pwd=6568986z;database=customer");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select*from cdetials where uname='"+this.textBox1.Text+"'";---执行tsql语句,读取数据库中的信息
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();--- SqlDataReader读取行的操作,ExecuteReader()执行读取
if (dr.HasRows)————读取第一个值,即第一个uname
{
dr.Read();————继续读下一条
if (this.textBox2.Text == dr["upwd"].ToString())
{
Form2 f2 = new Form2();
f2.Show();
this.Visible = false;
}
else
MessageBox.Show("密码错误!");
}
else
MessageBox.Show("账号错误!");
conn.Close();