예제 #1
0
        public List<clsCateNew> GetAll()
        {
            try
            {
                List<clsCateNew> list = new List<clsCateNew>();
                string str = "select * from tblCateNew";
                SqlCommand com = new SqlCommand(str, con.getCon());
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsCateNew obj = new clsCateNew();
                    if (dr["tieude"] != DBNull.Value)
                    {
                        obj.TieuDe = dr["tieude"].ToString();
                    }
                    if (dr["id"] != DBNull.Value)
                    {
                        obj.Id = Convert.ToInt32(dr["id"].ToString());
                    }
                    list.Add(obj);
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
예제 #2
0
        public clsCateNew GetById(int id)
        {
            try
            {
                clsCateNew obj = new clsCateNew();
                string str = "select * from tblCateNew 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();
                    }

                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
예제 #3
0
        public int Insert(clsCateNew obj)
        {
            try
            {
                return this.obj.Insert(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
예제 #4
0
        public void Delete(clsCateNew obj)
        {
            try
            {
                this.obj.Delete(obj.Id);
            }
            catch (Exception)
            {

                throw;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                clsCateNew cate = new clsCateNew();
                cate.TieuDe = this.TextBox1.Text;
                obj.Insert(cate);
                this.TextBox1.Text = "";
                this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Thêm mới thành công')</script>");
                this.odsCateNews.DataBind();
                this.GridView1.DataBind();
            }
            catch (Exception)
            {

                throw;
            }
        }
예제 #6
0
        public void Update(clsCateNew obj)
        {
            try
            {
                string str = "Update tblCateNew set tieude=@tieude where id=@id";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@tieude", obj.TieuDe);
                com.Parameters.AddWithValue("@id", obj.Id);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
예제 #7
0
        public int Insert(clsCateNew obj)
        {
            try
            {
                string str = "insert into tblCateNew(tieude) values(@tieude)";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@tieude", obj.TieuDe);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
                return clsDAStaticMethod.getIDIdentity("tblCateNew");
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
예제 #8
0
        public void Update(clsCateNew obj)
        {
            try
            {
                this.obj.Update(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }