Exemplo n.º 1
0
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            sanPhamDAL spDAL = new sanPhamDAL();
            SAN_PHAM   sp    = new SAN_PHAM();

            lb_messenger.Visible = true;

            if (FileUpload_hinh.HasFile)
            {
                try
                {
                    if (FileUpload_hinh.PostedFile.ContentType == "image/jpeg")
                    {
                        if (FileUpload_hinh.PostedFile.ContentLength < 102400)
                        {
                            string filename = Path.GetFileName(FileUpload_hinh.FileName.ToString());
                            FileUpload_hinh.SaveAs(Server.MapPath("~/Resource/image/") + filename);
                        }
                    }
                }
                catch { }
            }

            if (!String.IsNullOrEmpty(txt_tenSP.Text) && !String.IsNullOrEmpty(txt_gia.Text))
            {
                sp.TEN_SP = txt_tenSP.Text;
                sp.MO_TA  = txt_moTa.Text;
                sp.ANH    = Path.GetFileName(FileUpload_hinh.FileName.ToString());
                sp.GIA    = Convert.ToDouble(txt_gia.Text);

                int result = spDAL.Add(sp);

                if (result == 1)
                {
                    lb_messenger.Text     = "Thêm Sản Phẩm Thành Công";
                    lb_messenger.CssClass = "text-success";
                }
                else
                {
                    lb_messenger.Text = "Thêm Sản Phẩm Thất Bại";
                }
            }
            else
            {
                lb_messenger.Text = "Phải Nhập Đủ Các Trường";
            }
        }
        protected void btn_luuhinh_Click(object sender, EventArgs e)
        {
            string mahinh = ketnoi.TaoMaTuDong(kn, null, "HinhAnh", "MaHinh");
            string hinh   = "";

            if (FileUpload_hinh.HasFile)
            {
                FileUpload_hinh.SaveAs(Server.MapPath("~/hinh/" + FileUpload_hinh.FileName));
                hinh = "hinh/" + FileUpload_hinh.FileName;

                string     sql_luu = "insert into HinhAnh values ('" + mahinh + "','" + Request.QueryString["maphong"].ToString() + "',N'" + hinh + "')";
                SqlCommand cmd_luu = new SqlCommand(sql_luu, kn);
                kn.Open();
                cmd_luu.ExecuteNonQuery();
                kn.Close();
                Response.Redirect("~/ThemHinh_KhachSan.aspx?maphong=" + Request.QueryString["maphong"].ToString() + "");
            }
            else
            {
                Response.Write("<script>alert('Bạn phải chọn hình trước !');</script>");
            }
        }