public TheLoaiSachDTO GetRow(string maTheLoai)
        {
            try
            {
                TheLoaiSachDTO theLoai = new TheLoaiSachDTO();
                if (_connection.State != ConnectionState.Open)
                {
                    _connection.Open();
                }
                const string sql = "SELECT * FROM TheLoaiSach WHERE MaTheLoai = @matheloai";
                var          cmd = new SqlCommand(sql, _connection);
                cmd.Parameters.Add("@matheloai", SqlDbType.Char).Value = maTheLoai;
                var rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    theLoai.MaTheLoai  = rd["MaTheLoai"].ToString();
                    theLoai.TenTheLoai = rd["TenTheLoai"].ToString();
                    rd.Close();
                }

                //_connection.Close();
                return(theLoai);
            }
            catch (Exception ex)
            {
                _connection.Close();
                Console.WriteLine(ex.Message);
            }
            return(null);
        }
 public bool UpdateTheLoai(TheLoaiSachDTO tl)
 {
     if (objTheLoai.IsRowExists(tl.MaTheLoai))
     {
         return(objTheLoai.UpdateRow(tl));
     }
     else
     {
         return(false);
     }
 }
 public bool AddTheLoai(TheLoaiSachDTO tl)
 {
     if (!objTheLoai.IsRowExists(tl.MaTheLoai))
     {
         return(objTheLoai.AddRow(tl));
     }
     else
     {
         return(false);
     }
 }
        public List <TheLoaiSachDTO> LoadTheLoai()
        {
            List <TheLoaiSachDTO> ans = new List <TheLoaiSachDTO>();
            string query = "SELECT *";

            query += " FROM THELOAISACH";
            DataTable temp = dataprovider.Excutequery(query);

            for (int i = 0; i < temp.Rows.Count; ++i)
            {
                TheLoaiSachDTO tmp = new TheLoaiSachDTO();

                tmp.NewCategory(temp.Rows[i]);
                ans.Add(tmp);
            }

            return(ans);
        }
 public bool UpdateRow(TheLoaiSachDTO theLoai)
 {
     try
     {
         if (_connection.State != ConnectionState.Open)
         {
             _connection.Open();
         }
         const string cmdText = "UPDATE TheLoaiSach SET TenTheLoai = @TenTheLoai WHERE MaTheLoai = @MaTheLoai";
         var          command = new SqlCommand(cmdText, _connection);
         command.Parameters.Add("@MaTheLoai", SqlDbType.Char).Value      = theLoai.MaTheLoai;
         command.Parameters.Add("@TenTheLoai", SqlDbType.NVarChar).Value = theLoai.TenTheLoai;
         command.ExecuteNonQuery();
         _connection.Close();
         return(true);
     }
     catch (Exception ex)
     {
         _connection.Close();
         Console.WriteLine(ex.Message);
     }
     return(false);
 }