public List<clsAdmin> GetAll() { try { List<clsAdmin> list = new List<clsAdmin>(); string str = "select * from tblAdmin"; SqlCommand com = new SqlCommand(str, con.getCon()); con.openCon(); SqlDataReader dr = com.ExecuteReader(); while (dr.Read()) { clsAdmin obj = new clsAdmin(); if (dr["ten"] != DBNull.Value) { obj.Ten = dr["ten"].ToString(); } if (dr["tendangnhap"] != DBNull.Value) { obj.TenDangNhap = dr["tendangnhap"].ToString(); } if (dr["matkhau"] != DBNull.Value) { obj.MatKhau = dr["matkhau"].ToString(); } if (dr["id"] != DBNull.Value) { obj.Id = Convert.ToInt32(dr["id"].ToString()); } list.Add(obj); } return list; } catch (Exception) { throw; } finally { con.closeCon(); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["AdminID"] == null || Session["AdminID"].ToString() == "") { Response.Redirect("~/Admin/Login/Login.aspx"); } else { clsBSAdmin obj = new clsBSAdmin(); clsAdmin clss = new clsAdmin(); clss = obj.GetById(Convert.ToInt32(Session["AdminID"])); lblMessage.Visible = true; lblMessage.Text = "Xin chào: " + clss.Ten + " - <a href=\"Login\\Logout.aspx\">Logout</a>"; } //this.MenuMain.LoadContentFile("~/Admin/File/menu_vn.xml"); //this.MenuMain.DataBind(); if (!Page.IsPostBack) { Session["Status"] = null; } }
protected void btnLogin_Click(object sender, EventArgs e) { try { clsBSAdmin obj = new clsBSAdmin(); clsAdmin clss = new clsAdmin(); clss = obj.GetByUserPassword(this.txtUserName.Text, this.txtPassword.Text); if (clss != null) { Session["AdminID"] = clss.Id; Response.Redirect("~/Admin/Default.aspx"); } else { this.lblMessage.Text = "Đăng nhập không thành công"; } } catch (Exception) { throw; } }
public clsAdmin GetById(int id) { try { clsAdmin obj = new clsAdmin(); string str = "select * from tblAdmin where id=@id"; SqlCommand com = new SqlCommand(str, con.getCon()); com.Parameters.AddWithValue("@id", id); con.openCon(); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { obj.Id = id; if (dr["ten"] != DBNull.Value) { obj.Ten = dr["ten"].ToString(); } if (dr["tendangnhap"] != DBNull.Value) { obj.TenDangNhap = dr["tendangnhap"].ToString(); } if (dr["matkhau"] != DBNull.Value) { obj.MatKhau = dr["matkhau"].ToString(); } } return obj; } catch (Exception) { throw; } finally { con.closeCon(); } }
public void Update(clsAdmin obj) { try { string str = "Update tblAdmin set ten=@ten,tendangnhap=@tendangnhap,matkhau=@matkhau where id=@id"; SqlCommand com = new SqlCommand(str, con.getCon()); com.Parameters.AddWithValue("@ten", obj.Ten); com.Parameters.AddWithValue("@tendangnhap", obj.TenDangNhap); com.Parameters.AddWithValue("@id", obj.Id); com.Parameters.AddWithValue("@matkhau", obj.MatKhau); con.openCon(); com.ExecuteNonQuery(); con.closeCon(); } catch (Exception) { throw; } finally { con.closeCon(); } }
public int Insert(clsAdmin obj) { try { string str = "insert into tblAdmin(ten,tendangnhap,matkhau) values(@ten,@tendangnhap,@matkhau)"; SqlCommand com = new SqlCommand(str, con.getCon()); com.Parameters.AddWithValue("@ten", obj.Ten); com.Parameters.AddWithValue("@tendangnhap", obj.TenDangNhap); com.Parameters.AddWithValue("@matkhau", obj.MatKhau); con.openCon(); com.ExecuteNonQuery(); con.closeCon(); return clsDAStaticMethod.getIDIdentity("tblAdmin"); } catch (Exception) { throw; } finally { con.closeCon(); } }
public clsAdmin GetByUserPassword(string username,string password) { try { clsAdmin obj = new clsAdmin(); string str = "select * from tblAdmin where tendangnhap=@tendangnhap and matkhau=@matkhau"; SqlCommand com = new SqlCommand(str, con.getCon()); com.Parameters.AddWithValue("@tendangnhap", username); com.Parameters.AddWithValue("@matkhau", password); con.openCon(); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { if (dr["ten"] != DBNull.Value) { obj.Ten = dr["ten"].ToString(); } if (dr["tendangnhap"] != DBNull.Value) { obj.TenDangNhap = dr["tendangnhap"].ToString(); } if (dr["matkhau"] != DBNull.Value) { obj.MatKhau = dr["matkhau"].ToString(); } if (dr["id"] != DBNull.Value) { obj.Id = Convert.ToInt32(dr["id"].ToString()); } } return obj; } catch (Exception) { throw; } finally { con.closeCon(); } }