protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Request.QueryString["action"] != null)
     {
         clsTestimonials about = new clsTestimonials();
         about.Stt = Convert.ToInt32(this.txtSTT.Text);
         about.NoiDung = this.txtNoiDung.Value;
         if (Request.QueryString["action"].ToString().Equals("new"))
         {
             obj.Insert(about);
             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"]);
                     about.Id = id;
                     obj.Update(about);
                     this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Cập nhật thành công')</script>");
                 }
             }
         }
     }
     this.odsTestimonials.DataBind();
     this.GridView1.DataBind();
 }
        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.txtSTT.Text = "1";
                            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"]);
                                    clsTestimonials about = new clsTestimonials();
                                    about = obj.GetById(id);
                                    this.txtSTT.Text = about.Stt.ToString();
                                    this.txtNoiDung.Value = about.NoiDung;
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.pnInfo.Visible = false;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }
        public List<clsTestimonials> GetAll()
        {
            try
            {
                List<clsTestimonials> list = new List<clsTestimonials>();
                string str = "select * from tblTestimonials order by stt ASC";
                SqlCommand com = new SqlCommand(str, con.getCon());
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsTestimonials obj = new clsTestimonials();
                    if (dr["noidung"] != DBNull.Value)
                    {
                        obj.NoiDung = dr["noidung"].ToString().Substring(0,dr["noidung"].ToString().Length>400?400:dr["noidung"].ToString().Length);
                    }
                    if (dr["stt"] != DBNull.Value)
                    {
                        obj.Stt = Convert.ToInt32(dr["stt"].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 clsTestimonials GetById(int id)
        {
            try
            {
                clsTestimonials obj = new clsTestimonials();
                string str = "select * from tblTestimonials 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["noidung"] != DBNull.Value)
                    {
                        obj.NoiDung = dr["noidung"].ToString();
                    }
                    if (dr["stt"] != DBNull.Value)
                    {
                        obj.Stt = Convert.ToInt32(dr["stt"].ToString());
                    }
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
        public void Update(clsTestimonials obj)
        {
            try
            {
                string str = "Update tblTestimonials set noidung=@noidung,stt=@stt where id=@id";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@noidung", obj.NoiDung);
                com.Parameters.AddWithValue("@stt", obj.Stt);
                com.Parameters.AddWithValue("@id", obj.Id);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
        public int Insert(clsTestimonials obj)
        {
            try
            {
                string str = "insert into tblTestimonials(noidung,stt) values(@noidung,@stt)";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@noidung", obj.NoiDung);
                com.Parameters.AddWithValue("@stt", obj.Stt);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
                return clsDAStaticMethod.getIDIdentity("tblTestimonials");
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
        public clsTestimonials GetByShort()
        {
            try
            {
                clsTestimonials obj = new clsTestimonials();
                obj= this.obj.GetAll()[0];
                obj.NoiDung = obj.NoiDung.Substring(0, obj.NoiDung.Length > 300 ? 300 : obj.NoiDung.Length);
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void Update(clsTestimonials obj)
        {
            try
            {
                this.obj.Update(obj);
            }
            catch (Exception)
            {

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

                throw;
            }
        }