Ejemplo n.º 1
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (Request.QueryString["action"] != null)
         {
             clsHinhAnh hinhanh = new clsHinhAnh();
             hinhanh.TieuDe = this.txtTieuDe.Text;
             hinhanh.Url = hfHinhAnh.Value;
             hinhanh.LoaiHinhAnh= new clsLoaiHinhAnh();
             if (Request.QueryString["loaiid"] != null && !String.IsNullOrEmpty(Request.QueryString["loaiid"]))
             hinhanh.LoaiHinhAnh.Id = Convert.ToInt32(Request.QueryString["loaiid"].ToString());
             hinhanh.Tour= new clsTour();
             if (Request.QueryString["tourid"] != null && !String.IsNullOrEmpty(Request.QueryString["tourid"]))
                 hinhanh.Tour.Id = Convert.ToInt32(Request.QueryString["tourid"].ToString());
             string filename = "";
             if (Request.QueryString["action"].ToString().Equals("new"))
             {
                 if (this.fuFile.HasFile)
                 {
                     filename = clsBSFileUpload.SaveFile(this.fuFile, Server.MapPath("~/Images/HinhAnh/"));
                     hinhanh.Url = filename;
                 }
                 obj.Insert(hinhanh);
                 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"]);
                         hinhanh.Id = id;
                         if (this.fuFile.HasFile)
                         {
                             clsBSFileUpload.DeleteFile(Server.MapPath("~/Images/HinhAnh/") + this.hfHinhAnh.Value);
                             filename = clsBSFileUpload.SaveFile(this.fuFile, Server.MapPath("~/Images/HinhAnh/"));
                             hinhanh.Url = filename;
                         }
                         obj.Update(hinhanh);
                         this.Page.ClientScript.RegisterStartupScript(Page.GetType(), "show", "<script type='text/javascript'>alert('Cập nhật thành công')</script>");
                     }
                 }
             }
         }
         this.odsHinhAnh.DataBind();
         this.GridView1.DataBind();
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        public clsHinhAnh GetById(int id)
        {
            try
            {
                clsHinhAnh obj = new clsHinhAnh();
                obj.Tour = new clsTour();
                obj.LoaiHinhAnh = new clsLoaiHinhAnh();
                string str = "select * from tblHinhAnh 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["url"] != DBNull.Value)
                    {
                        obj.Url = dr["url"].ToString();
                    }
                    if (dr["Loai"] != DBNull.Value)
                    {
                        obj.LoaiHinhAnh.Id = Convert.ToInt32(dr["Loai"].ToString());
                    }
                    if (dr["tourid"] != DBNull.Value)
                    {
                        obj.Tour.Id = Convert.ToInt32(dr["tourid"].ToString());
                    }
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
Ejemplo n.º 3
0
        public int Insert(clsHinhAnh obj)
        {
            try
            {
                return this.obj.Insert(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
Ejemplo n.º 4
0
        public void Update(clsHinhAnh obj)
        {
            try
            {
                this.obj.Update(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
Ejemplo n.º 5
0
        public List<clsHinhAnh> GetByLoai(int loai)
        {
            try
            {
                List<clsHinhAnh> list = new List<clsHinhAnh>();
                string str = "select * from tblHinhAnh where loai=@loai";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@loai", loai);
                con.openCon();
                SqlDataReader dr = com.ExecuteReader();
                while (dr.Read())
                {
                    clsHinhAnh obj = new clsHinhAnh();
                    obj.Tour = new clsTour();
                    obj.LoaiHinhAnh = new clsLoaiHinhAnh();
                    if (dr["tieude"] != DBNull.Value)
                    {
                        obj.TieuDe = dr["tieude"].ToString();
                    }
                    if (dr["url"] != DBNull.Value)
                    {
                        obj.Url = dr["url"].ToString();
                    }
                    if (dr["Loai"] != DBNull.Value)
                    {
                        obj.LoaiHinhAnh.Id = Convert.ToInt32(dr["Loai"].ToString());
                    }
                    if (dr["tourid"] != DBNull.Value)
                    {
                        obj.Tour.Id = Convert.ToInt32(dr["tourid"].ToString());
                    }
                    if (dr["id"] != DBNull.Value)
                    {
                        obj.Id = Convert.ToInt32(dr["id"].ToString());
                    }
                    list.Add(obj);
                }
                return list;
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
Ejemplo n.º 6
0
        public void Update(clsHinhAnh obj)
        {
            try
            {
                string str = "Update tblHinhAnh set tieude=@tieude,url=@url,loai=@loai,tourid=@tourid where id=@id";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@tieude", obj.TieuDe);
                com.Parameters.AddWithValue("@url", obj.Url);
                com.Parameters.AddWithValue("@loai", obj.LoaiHinhAnh.Id);
                if (obj.Tour.Id > 0)
                    com.Parameters.AddWithValue("@tourid", obj.Tour.Id);
                else
                {
                    com.Parameters.AddWithValue("@tourid", DBNull.Value);
                }
                com.Parameters.AddWithValue("@id", obj.Id);
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
Ejemplo n.º 7
0
        public int Insert(clsHinhAnh obj)
        {
            try
            {
                string str = "insert into tblHinhAnh(tieude,url,loai,tourid) values(@tieude,@url,@loai,@tourid)";
                SqlCommand com = new SqlCommand(str, con.getCon());
                com.Parameters.AddWithValue("@tieude", obj.TieuDe);
                com.Parameters.AddWithValue("@url", obj.Url);
                com.Parameters.AddWithValue("@loai", obj.LoaiHinhAnh.Id);
                if (obj.Tour.Id > 0)
                    com.Parameters.AddWithValue("@tourid", obj.Tour.Id);
                else
                {
                    com.Parameters.AddWithValue("@tourid", DBNull.Value);
                }
                con.openCon();
                com.ExecuteNonQuery();
                con.closeCon();
                return clsDAStaticMethod.getIDIdentity("tblHinhAnh");
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.closeCon();
            }
        }
Ejemplo n.º 8
0
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     try
     {
         if (e.CommandName.Equals("Xoa"))
         {
             clsHinhAnh hinhanh = new clsHinhAnh();
             hinhanh = obj.GetById(Convert.ToInt32(e.CommandArgument));
             clsBSFileUpload.DeleteFile(Server.MapPath("~/Images/HinhAnh/") + hinhanh.Url);
             obj.Delete(Convert.ToInt32(e.CommandArgument));
             this.GridView1.DataBind();
         }
         else
         {
             if (e.CommandName.Equals("sua"))
             {
                 Response.Redirect("HinhAnh.aspx?action=edit&id=" + e.CommandArgument + "&loaiid=" + Request.QueryString["loaiid"] + "&tourid=" + Request.QueryString["tourid"]);
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 9
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.imgHinhAnh.ImageUrl = "";
                        }
                        else
                        {
                            if (Request.QueryString["action"].ToString().Equals("edit"))
                            {
                                if (Request.QueryString["ID"] != null)
                                {
                                    this.pnInfo.Visible = true;
                                    int id = Convert.ToInt32(Request.QueryString["ID"]);
                                    clsHinhAnh hinhanh = new clsHinhAnh();
                                    hinhanh = obj.GetById(id);
                                    this.txtTieuDe.Text = hinhanh.TieuDe;
                                    this.imgHinhAnh.ImageUrl = "~/Images/HinhAnh/" + hinhanh.Url;
                                    this.hfHinhAnh.Value = hinhanh.Url;
                                }
                            }
                        }
                    }
                }
                else
                {
                    this.pnInfo.Visible = false;
                }

            }
            catch (Exception)
            {
                throw;
            }
        }