コード例 #1
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     if (Request.QueryString["action"] != null)
     {
         clsDetail detail = new clsDetail();
         detail.NoiDung = this.txtNoiDung.Value;
         detail.Tour.Id = Convert.ToInt32(Request.QueryString["tourid"]);
         detail.TypeDetail.Id = Convert.ToInt32(this.ddlLoai.SelectedValue);
         if (Request.QueryString["action"].ToString().Equals("new"))
         {
             obj.Insert(detail);
             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"]);
                     detail.Id = id;
                     obj.Update(detail);
                     this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Cập nhật thành công')</script>");
                 }
             }
         }
     }
     this.odsDetail.DataBind();
     this.GridView1.DataBind();
 }
コード例 #2
0
        public int Insert(clsDetail obj)
        {
            try
            {
                return this.obj.Insert(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #3
0
        public clsDetail GetById(int id)
        {
            try
            {
                clsDetail obj = new clsDetail();
                obj.TypeDetail = new clsTypeDetail();
                obj.Tour = new clsTour();
                string str = "select * from tblDetail 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["tourid"] != DBNull.Value)
                    {
                        obj.Tour.Id = Convert.ToInt32(dr["tourid"].ToString());
                    }
                    if (dr["typedetailid"] != DBNull.Value)
                    {
                        obj.TypeDetail.Id = Convert.ToInt32(dr["typedetailid"].ToString());
                    }
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
コード例 #4
0
        public List<clsDetail> GetByLoai(int loai)
        {
            try
            {
                List<clsDetail> list = new List<clsDetail>();
                string str = "select * from tblDetail where typedetailid=@typedetailid";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@typedetailid", loai);
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsDetail obj = new clsDetail();
                    obj.TypeDetail = new clsTypeDetail();
                    obj.Tour = new clsTour();
                    if (dr["noidung"] != DBNull.Value)
                    {
                        obj.NoiDung = dr["noidung"].ToString();
                    }
                    if (dr["tourid"] != DBNull.Value)
                    {
                        obj.Tour.Id = Convert.ToInt32(dr["tourid"].ToString());
                    }
                    if (dr["typedetailid"] != DBNull.Value)
                    {
                        obj.TypeDetail.Id = Convert.ToInt32(dr["typedetailid"].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 void Update(clsDetail obj)
        {
            try
            {
                string str = "Update tblDetail set noidung=@noidung,tourid=@tourid,typedetailid=@typedetailid where id=@id";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@noidung", obj.NoiDung);
                com.Parameters.AddWithValue("@tourid", obj.Tour.Id);
                com.Parameters.AddWithValue("@typedetailid", obj.TypeDetail.Id);
                com.Parameters.AddWithValue("@id", obj.Id);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
            }
            catch (Exception)
            {

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

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
コード例 #7
0
        public void Update(clsDetail obj)
        {
            try
            {
                this.obj.Update(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #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;
                            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"]);
                                    clsDetail detail = new clsDetail();
                                    detail = obj.GetById(id);
                                    this.txtNoiDung.Value = detail.NoiDung;
                                    this.ddlLoai.SelectedValue = detail.TypeDetail.Id.ToString();
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.pnInfo.Visible = false;
                }

            }
            catch (Exception)
            {

                throw;
            }
        }