コード例 #1
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Request.QueryString["action"] != null)
     {
         clsAboutUS about = new clsAboutUS();
         about.Stt = Convert.ToInt32(this.txtSTT.Text);
         about.TieuDe = this.txtTieuDe.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.odsAboutUS.DataBind();
     this.GridView1.DataBind();
 }
コード例 #2
0
        public void Update(clsAboutUS obj)
        {
            try
            {
                this.obj.Update(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #3
0
        public int Insert(clsAboutUS obj)
        {
            try
            {
                return this.obj.Insert(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #4
0
        public List<clsAboutUS> GetAll()
        {
            try
            {
                List<clsAboutUS> list = new List<clsAboutUS>();
                string str = "select * from tblAboutUS";
                SqlCommand com = new SqlCommand(str, con.getCon());
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsAboutUS obj = new clsAboutUS();
                    if (dr["tieude"] != DBNull.Value)
                    {
                        obj.TieuDe = dr["tieude"].ToString();
                    }
                    if (dr["noidung"] != DBNull.Value)
                    {
                        obj.NoiDung = dr["noidung"].ToString();
                    }
                    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();
            }
        }
コード例 #5
0
        public clsAboutUS GetById(int id)
        {
            try
            {
                clsAboutUS obj = new clsAboutUS();
                string str = "select * from tblAboutUS 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["stt"] != DBNull.Value)
                    {
                        obj.Stt = Convert.ToInt32(dr["stt"].ToString());
                    }
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
コード例 #6
0
        public void Update(clsAboutUS obj)
        {
            try
            {
                string str = "Update tblAboutUS set tieude=@tieude,noidung=@noidung,stt=@stt 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("@stt", obj.Stt);
                com.Parameters.AddWithValue("@id", obj.Id);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
コード例 #7
0
        public int Insert(clsAboutUS obj)
        {
            try
            {
                string str = "insert into tblAboutUS(tieude,noidung,stt) values(@tieude,@noidung,@stt)";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@tieude", obj.TieuDe);
                com.Parameters.AddWithValue("@noidung", obj.NoiDung);
                com.Parameters.AddWithValue("@stt", obj.Stt);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
                return clsDAStaticMethod.getIDIdentity("tblAboutUS");
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
コード例 #8
0
        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.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"]);
                                    clsAboutUS about = new clsAboutUS();
                                    about = obj.GetById(id);
                                    this.txtSTT.Text = about.Stt.ToString();
                                    this.txtTieuDe.Text = about.TieuDe;
                                    this.txtNoiDung.Value = about.NoiDung;
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.pnInfo.Visible = false;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }