public List <danhmucDAL> getDanhMuclv(int y) { List <danhmucDAL> list = new List <danhmucDAL>(); SqlConnection cn = cnn.connectToSql(); cn.Open(); // string sql = "SELECT * FROM danhmuc"; string sql = "SELECT * FROM danhmuc ORDER BY groupdanhmuc ASC"; SqlCommand cmd = new SqlCommand(sql, cn); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { string j = Convert.ToString(rd.GetDouble(2)); string[] spl = j.Split('.'); if (Convert.ToInt32(spl[1]) == y) { danhmucDAL ds = new danhmucDAL(); ds.id_danhmuc = rd.GetInt32(0); ds.ten_danhmuc = rd.GetString(1); ds.groupdanhmuc = rd.GetDouble(2); list.Add(ds); } } return(list); cmd.Dispose(); cn.Close(); }
// xem theo danh muc: public List <danhmucDAL> getDanhMuclvXem(double y) { List <danhmucDAL> list = new List <danhmucDAL>(); SqlConnection cn = cnn.connectToSql(); cn.Open(); // string sql = "SELECT * FROM danhmuc"; string sql = "SELECT * FROM danhmuc WHERE groupdanhmuc=" + y; SqlCommand cmd = new SqlCommand(sql, cn); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { danhmucDAL ds = new danhmucDAL(); ds.id_danhmuc = rd.GetInt32(0); ds.ten_danhmuc = rd.GetString(1); ds.groupdanhmuc = rd.GetDouble(2); list.Add(ds); } return(list); cmd.Dispose(); cn.Close(); }
// load menu: public List <danhmucDAL> getMenu() { double id = -1; List <danhmucDAL> list = new List <danhmucDAL>(); SqlConnection cn = cnn.connectToSql(); cn.Open(); string sql = "SELECT * FROM danhmuc ORDER BY groupdanhmuc ASC"; SqlCommand cmd = new SqlCommand(sql, cn); SqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { danhmucDAL ds = new danhmucDAL(); if (list.Count() == 0) { ds.id_danhmuc = rd.GetInt32(0); ds.ten_danhmuc = "<li class='menu-item-1'><a href='#'>" + rd.GetString(1) + "</a><ul>"; ds.groupdanhmuc = rd.GetDouble(2); id = Math.Round(rd.GetDouble(2), 0); } else { if (Math.Round(rd.GetDouble(2), 0) != id) { ds.id_danhmuc = rd.GetInt32(0); ds.ten_danhmuc = "</ul></li><li class='menu-item-1'><a href='#'>" + rd.GetString(1) + "</a><ul>"; ds.groupdanhmuc = rd.GetDouble(2); id = Math.Round(rd.GetDouble(2), 0); } else { ds.id_danhmuc = rd.GetInt32(0); ds.ten_danhmuc = "<li class=''><a href='sanpham.aspx?id=" + rd.GetInt32(0) + "'>" + rd.GetString(1) + "</a></li>"; ds.groupdanhmuc = rd.GetDouble(2); id = Math.Round(rd.GetDouble(2), 0); } } list.Add(ds); } return(list); cmd.Dispose(); cn.Close(); }