码迷,mamicode.com
首页 > 其他好文 > 详细

简单三层实现登陆

时间:2014-05-17 17:48:35      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:class   code   c   tar   ext   a   

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 = "验证码错误!";     

                }           

      }

            }

}

简单三层实现登陆,布布扣,bubuko.com

简单三层实现登陆

标签:class   code   c   tar   ext   a   

原文地址:http://www.cnblogs.com/btmc/p/3731334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!