//----------Hiện sản phẩm theo id sản phẩm-------------- private void HienSanPham() { MOONLY.Common.SanPham Spham = new MOONLY.Common.SanPham(); Spham.Idsanpham = int.Parse(Request.QueryString["Idsanpham"]); XuLyLaySanPhamByID laySanPhamByID = new XuLyLaySanPhamByID(); laySanPhamByID.Sanpham = Spham; try { laySanPhamByID.Thucthi(); txtTenSanPham.Text = laySanPhamByID.Sanpham.Ten; CKEditorControlMoTa.Text = laySanPhamByID.Sanpham.Mota; textGia.Text = laySanPhamByID.Sanpham.Giasanpham.ToString(); imgHinhSanPham.ImageUrl = "../HienThiHinhSanPham.ashx?Idhinhsanpham=" + laySanPhamByID.Sanpham.Idhinhsanpham.ToString(); dropDanhMucSanPham.SelectedIndex = dropDanhMucSanPham.Items.IndexOf(dropDanhMucSanPham.Items.FindByText( laySanPhamByID.Sanpham.Danhmucsanpham.Tendanhmucsanpham)); LuuTamIdHinhSanPham = laySanPhamByID.Sanpham.Idhinhsanpham; } catch { Response.Redirect("../Trangloi.aspx"); } }
//---------------Cập nhật thay đổi sản phẩm-------------------- protected void btnCapNhat_Click(object sender, EventArgs e) { if (IsValid) { MOONLY.Common.SanPham Spham = new MOONLY.Common.SanPham(); Spham.Idsanpham = int.Parse(Request.QueryString["IDsanpham"]); Spham.Ten = txtTenSanPham.Text; Spham.Mota = CKEditorControlMoTa.Text; Spham.Giasanpham = Convert.ToDecimal(textGia.Text); Spham.Iddanhmucsanpham = int.Parse( dropDanhMucSanPham.SelectedItem.Value); Spham.Idhinhsanpham = LuuTamIdHinhSanPham; if (fileuploadHinhSanPham.HasFile) { Spham.Dulieuhinhsanpham = fileuploadHinhSanPham.FileBytes; } else { XuLyLayHinhSanPham XuLyLayHinh = new XuLyLayHinhSanPham(); XuLyLayHinh.Sanpham = Spham; try { XuLyLayHinh.Thucthi(); } catch { Response.Redirect("../Trangloi.aspx"); } SqlDataSource src = new SqlDataSource(); src = XuLyLayHinh.Ketqua; DataView view = (DataView)src.Select(DataSourceSelectArguments.Empty); Spham.Dulieuhinhsanpham = (byte[])view[0]["DuLieuHinhSanPham"]; } XuLyCapNhatSanPham capnhatsanpham = new XuLyCapNhatSanPham(); capnhatsanpham.Sanpham = Spham; try { capnhatsanpham.Thucthi(); } catch { Response.Redirect("../Trangloi.aspx"); } Response.Redirect("SanPham.aspx"); } }
protected void btnCapNhat_Click(object sender, EventArgs e) { if (IsValid) { XuLyThemSanPham themsanpham = new XuLyThemSanPham(); MOONLY.Common.SanPham Spham = new MOONLY.Common.SanPham(); Spham.Iddanhmucsanpham = int.Parse(dropDanhMucSanPham.SelectedItem.Value); Spham.Ten = txtTenSanPham.Text; // txtTenSanPham là ID của TextBox Spham.Mota = CKEditorControlMoTa.Text; //txtTenSanPham là ID của TextBox Spham.Dulieuhinhsanpham = fileuploadHinhSanPham.FileBytes; // fileuploadHinhSanPham là ID của điều khiển FileUpLoad Spham.Giasanpham = Convert.ToDecimal(txtGia.Text); // txtGia là ID của TextBox themsanpham.Sanpham = Spham; try { themsanpham.Thucthi(); } catch { Response.Redirect("../Trangloi.aspx"); } Response.Redirect("SanPham.aspx"); } }