Model层
[Serializable]
public partial class tb_admin
{ public tb_admin()
{}
#region Model private string _id;
private string _name; private string _pwd;
/// <summary>
///
/// </summary>
public string id { set{ _id=value;} get{return _id;} }
/// <summary>
///
/// </summary>
public string name { set{ _name=value;} get{return _name;} }
/// <summary>
///
/// </summary>
public string pwd { set{ _pwd=value;} get{return _pwd;} }
#endregion Model
}
DAL层
public class AdminServer {
public List<tb_admin> Tabletb_Admin( string name,string pwd) {
List<tb_admin> list = new List<tb_admin>();
string str = "select* from tb_admin where name=‘" + name + "‘and pwd=‘" + pwd + "‘";
DataTable table= DBHelper.GetDataTable(str);
if (table.Rows.Count>0)
{
foreach (DataRow item in table.Rows)
{
list.Add(DataRowToModel(item));
}
}
return list; }
/// <summary>
/// 得到一个对象实体
/// </summary>
public tb_admin DataRowToModel(DataRow row)
{
tb_admin model = new tb_admin();
if (row != null)
{
if (row["id"] != null)
{
model.id = row["id"].ToString();
}
if (row["name"] != null)
{
model.name = row["name"].ToString();
}
if (row["pwd"] != null)
{
model.pwd = row["pwd"].ToString();
}
}
return model;
}
BLL层
public static class AdminBLL
{
static AdminServer
Admin=new AdminServer();
public static List<tb_admin> Tabletb_Admin( string name, string
pwd)
{
return
Admin.Tabletb_Admin(name,pwd);
}
}
UI层
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
string pwd = TextBox2.Text;
string str=Convert.ToString(Session["code"]);
if (name=="")
{
Label2.Visible = true;
Label2.Text="用户名为空";
}
else if (pwd =="")
{
Label2.Visible = true;
Label2.Text = "密码名为空";
}
else
{
List<tb_admin> damin = AdminBLL.Tabletb_Admin(name, pwd);
if (damin.Count > 0)
{
if (TextBox3.Text == str)
{
Response.Redirect("TushuXinxiGuanl.aspx");
}
else
{
Label1.Visible = true;
Label1.Text = "验证码错误!";
}
}
}
}
原文地址:http://www.cnblogs.com/btmc/p/3731334.html