public List<clsInfomationContent> GetAll()
        {
            try
            {
                List<clsInfomationContent> list = new List<clsInfomationContent>();
                string str = "select * from tblinfomationcontent order by id DESC";
                SqlCommand com = new SqlCommand(str, con.getCon());
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsInfomationContent obj = new clsInfomationContent();
                    if (dr["tieude"] != DBNull.Value)
                    {
                        obj.TieuDe = dr["tieude"].ToString();
                    }
                    if (dr["noidung"] != DBNull.Value)
                    {
                        obj.NoiDung = dr["noidung"].ToString();
                    }
                    if (dr["ghichu"] != DBNull.Value)
                    {
                        obj.GhiChu = dr["ghichu"].ToString();
                    }
                    if (dr["hinhanh"] != DBNull.Value)
                    {
                        obj.HinhAnh = dr["hinhanh"].ToString();
                    }

                    if (dr["infoid"] != DBNull.Value)
                    {
                        obj.InfoId = Convert.ToInt32(dr["infoid"].ToString());
                    }
                    if (dr["id"] != DBNull.Value)
                    {
                        obj.Id = Convert.ToInt32(dr["id"].ToString());
                    }
                    list.Add(obj);
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
        public clsInfomationContent GetById(int id)
        {
            try
            {
                clsInfomationContent obj = new clsInfomationContent();
                string str = "select * from tblInfomationContent 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["tieude"] != DBNull.Value)
                    {
                        obj.TieuDe = dr["tieude"].ToString();
                    }
                    if (dr["noidung"] != DBNull.Value)
                    {
                        obj.NoiDung = dr["noidung"].ToString();
                    }
                    if (dr["ghichu"] != DBNull.Value)
                    {
                        obj.GhiChu = dr["ghichu"].ToString();
                    }
                    if (dr["hinhanh"] != DBNull.Value)
                    {
                        obj.HinhAnh = dr["hinhanh"].ToString();
                    }
                    if (dr["infoid"] != DBNull.Value)
                    {
                        obj.InfoId = Convert.ToInt32(dr["infoid"].ToString());
                    }
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
        public int Insert(clsInfomationContent obj)
        {
            try
            {
                string str = "insert into tblinfomationcontent(tieude,noidung,ghichu,hinhanh,infoid) values(@tieude,@noidung,@ghichu,@hinhanh,@infoid)";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@tieude", obj.TieuDe);
                com.Parameters.AddWithValue("@noidung", obj.NoiDung);
                com.Parameters.AddWithValue("@ghichu", obj.GhiChu);
                com.Parameters.AddWithValue("@hinhanh", obj.HinhAnh);
                com.Parameters.AddWithValue("@infoid", obj.InfoId);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
                return clsDAStaticMethod.getIDIdentity("tblnews");
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
        public void Update(clsInfomationContent obj)
        {
            try
            {
                string str = "Update tblinfomationcontent set tieude=@tieude,noidung=@noidung,ghichu=@ghichu,hinhanh=@hinhanh,infoid=@infoid where id=@id";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@tieude", obj.TieuDe);
                com.Parameters.AddWithValue("@noidung", obj.NoiDung);
                com.Parameters.AddWithValue("@ghichu", obj.GhiChu);
                com.Parameters.AddWithValue("@hinhanh", obj.HinhAnh);
                com.Parameters.AddWithValue("@infoid", obj.InfoId);
                com.Parameters.AddWithValue("@id", obj.Id);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
        public void Update(clsInfomationContent obj)
        {
            try
            {
                this.obj.Update(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public int Insert(clsInfomationContent obj)
        {
            try
            {
                return this.obj.Insert(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName.Equals("Xoa"))
         {
             clsInfomationContent news = new clsInfomationContent();
             news = obj.GetById(Convert.ToInt32(e.CommandArgument));
             clsBSFileUpload.DeleteFile(Server.MapPath("~/Images/HinhAnh/") + news.HinhAnh);
             obj.Delete(Convert.ToInt32(e.CommandArgument));
             this.GridView1.DataBind();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (Request.QueryString["action"] != null)
         {
             clsInfomationContent news = new clsInfomationContent();
             news.TieuDe = this.txtTieuDe.Text;
             news.HinhAnh = hfHinhAnh.Value;
             news.InfoId = Convert.ToInt32(this.ddlCateNew.SelectedValue);
             news.GhiChu = this.txtGhiChu.Text;
             news.NoiDung = this.txtNoiDung.Value;
             string filename = "";
             if (Request.QueryString["action"].ToString().Equals("new"))
             {
                 if (this.fuFile.HasFile)
                 {
                     filename = clsBSFileUpload.SaveFile(this.fuFile, Server.MapPath("~/Images/HinhAnh/"));
                     news.HinhAnh = filename;
                 }
                 obj.Insert(news);
                 this.txtTieuDe.Text = "";
                 this.imgHinhAnh.ImageUrl = "";
                 this.txtGhiChu.Text = "";
                 this.txtNoiDung.Value = "";
                 this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Thêm mới thành công')</script>");
             }
             else
             {
                 if (Request.QueryString["action"].ToString().Equals("edit"))
                 {
                     if (Request.QueryString["ID"] != null)
                     {
                         int id = Convert.ToInt32(Request.QueryString["ID"]);
                         news.Id = id;
                         if (this.fuFile.HasFile)
                         {
                             clsBSFileUpload.DeleteFile(Server.MapPath("~/Images/HinhAnh/") + this.hfHinhAnh.Value);
                             filename = clsBSFileUpload.SaveFile(this.fuFile, Server.MapPath("~/Images/HinhAnh/"));
                             news.HinhAnh = filename;
                         }
                         obj.Update(news);
                         this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Cập nhật thành công')</script>");
                         news = obj.GetById(id);
                         this.txtTieuDe.Text = news.TieuDe;
                         this.txtGhiChu.Text = news.GhiChu;
                         this.txtNoiDung.Value = news.NoiDung;
                         this.imgHinhAnh.ImageUrl = "~/Images/HinhAnh/" + news.HinhAnh;
                         this.hfHinhAnh.Value = news.HinhAnh;
                     }
                 }
             }
         }
         this.odsNews.DataBind();
         this.GridView1.DataBind();
     }
     catch (Exception)
     {
         throw;
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                if (Request.QueryString["action"] != null)
                {
                    if (this.pnInfo.Visible == false)
                    {
                        if (Request.QueryString["action"].ToString().Equals("new"))
                        {
                            this.pnInfo.Visible = true;
                            this.txtTieuDe.Text = "";
                            this.imgHinhAnh.ImageUrl = "";
                            this.txtGhiChu.Text = "";
                            this.txtNoiDung.Value = "";

                        }
                        else
                        {
                            if (Request.QueryString["action"].ToString().Equals("edit"))
                            {
                                if (Request.QueryString["ID"] != null)
                                {
                                    this.pnInfo.Visible = true;
                                    int id = Convert.ToInt32(Request.QueryString["ID"]);
                                    clsInfomationContent news = new clsInfomationContent();
                                    news = obj.GetById(id);
                                    this.txtTieuDe.Text = news.TieuDe;
                                    this.txtGhiChu.Text = news.GhiChu;
                                    this.txtNoiDung.Value = news.NoiDung;
                                    this.imgHinhAnh.ImageUrl = "~/Images/HinhAnh/" + news.HinhAnh;
                                    this.hfHinhAnh.Value = news.HinhAnh;
                                    this.ddlCateNew.SelectedValue = news.InfoId.ToString();
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.pnInfo.Visible = false;
                }

            }
            catch (Exception)
            {
                throw;
            }
        }