public LoaiSachCollection TimDSLoaiSach(string tenloai)
        {

            LoaiSachCollection loaicoll = new LoaiSachCollection();
            SqlConnection cnn = new SqlConnection(cnnstr);
            string query = "select * from LoaiSach where tenloai <> '' ";
            query += "order by tenloai";
            SqlCommand cmd = new SqlCommand(query, cnn);
            if (tenloai != "")
            {
                query = "select * from LoaiSach where tenloai like @tenloai and tenloai <>''";
                query += "order by tenloai";
                cmd = new SqlCommand(query, cnn);
                cmd.Parameters.AddWithValue("@tenloai", "%" + tenloai + "%");
            }
            cnn.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                LoaiSachBO loaiBO = new LoaiSachBO();
                loaiBO.MaLoai = dr["maloai"].ToString();
                loaiBO.TenLoai = dr["tenloai"].ToString();
                loaicoll.Add(loaiBO);
            }
            cnn.Close();
            return loaicoll;
        }
 public void SuaLoaiSach(LoaiSachBO loaisachBO)
 {
     SqlConnection cnn = new SqlConnection(cnnstr);
     string query = "update LoaiSach set tenloai=@tenloai where maloai=@maloai ";
     SqlCommand cmd = new SqlCommand(query, cnn);
     cmd.Parameters.AddWithValue("@tenloai", loaisachBO.TenLoai);
     cmd.Parameters.AddWithValue("@maloai", loaisachBO.MaLoai);
     cnn.Open();
     cmd.ExecuteNonQuery();
     cnn.Close();
 }
        public bool SuaLoaiSach(string maloai, string tenloai)
        {
            try
            {

                LoaiSachBO loaisachBO = new LoaiSachBO();
                loaisachBO.MaLoai = maloai;
                loaisachBO.TenLoai = tenloai;
                loaisachDAO.SuaLoaiSach(loaisachBO);

                return true;
            }
            catch
            {
                return false;
            }

        }
 public LoaiSachBO Tim1LoaiSach(string maloai)
 {
     LoaiSachBO nxbBO = new LoaiSachBO();
     SqlConnection cnn = new SqlConnection(cnnstr);
     string query = "select * from LoaiSach where tenloai <> '' ";
     query += " AND maloai=@maloai";
     SqlCommand cmd = new SqlCommand(query, cnn);
     cmd.Parameters.AddWithValue("@maloai", maloai);
     cnn.Open();
     SqlDataReader dr = cmd.ExecuteReader();
     while (dr.Read())
     {
         nxbBO.MaLoai = dr["maloai"].ToString();
         nxbBO.TenLoai = dr["tenloai"].ToString();
         break;
     }
     cnn.Close();
     return nxbBO;
 }
 public void NapLoaiSach()
 {
     LoaisachDropdown.Items.Clear();
     LoaiSachCollection source = new LoaiSachCollection();
     LoaiSachBO loaisachBO= new LoaiSachBO();
     loaisachBO.TenLoai = "Tất cả";
     loaisachBO.MaLoai = "";
     source.Add(loaisachBO);
     //add
     LoaiSachCollection temp = new LoaiSachCollection();
     temp = loaisachBUS.TimDSLoaiSach("");
     for (int i = 0; i < temp.Count; i++)
     {
         source.Add(temp.Index(i));
     }
     LoaisachDropdown.DataSource =source;
     LoaisachDropdown.DataTextField = "TenLoai";
     LoaisachDropdown.DataValueField = "Maloai";
     LoaisachDropdown.DataBind();
 }
 public void Add(LoaiSachBO loaisachBO)
 {
     List.Add(loaisachBO);
 }