コード例 #1
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Request.QueryString["action"] != null)
     {
         clsContactUS about = new clsContactUS();
         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.odsContactUS.DataBind();
     this.GridView1.DataBind();
 }
コード例 #2
0
        public clsContactUS GetById(int id)
        {
            try
            {
                clsContactUS obj = new clsContactUS();
                string str = "select * from tblContactUS 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();
                    }
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
コード例 #3
0
        public List<clsContactUS> GetAll()
        {
            try
            {
                List<clsContactUS> list = new List<clsContactUS>();
                string str = "select * from tblContactUS";
                SqlCommand com = new SqlCommand(str, con.getCon());
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsContactUS obj = new clsContactUS();
                    if (dr["noidung"] != DBNull.Value)
                    {
                        obj.NoiDung = dr["noidung"].ToString();
                    }
                    if (dr["id"] != DBNull.Value)
                    {
                        obj.Id = Convert.ToInt32(dr["id"].ToString());
                    }
                    list.Add(obj);
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
コード例 #4
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.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"]);
                                    clsContactUS about = new clsContactUS();
                                    about = obj.GetById(id);
                                    this.txtNoiDung.Value = about.NoiDung;
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.pnInfo.Visible = false;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #5
0
        public void Update(clsContactUS obj)
        {
            try
            {
                string str = "Update tblContactUS set noidung=@noidung where id=@id";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@noidung", obj.NoiDung);
                com.Parameters.AddWithValue("@id", obj.Id);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
            }
            catch (Exception)
            {

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

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }