protected void Page_Load(object sender, EventArgs e) { bllSanPham = new SanPhamBLL(); DataTable dtNewPhone = bllSanPham.selectSPByNew(); PagedDataSource pdsNewPhone = new PagedDataSource(); DataView dvNewPhone = new DataView(dtNewPhone); pdsNewPhone.DataSource = dvNewPhone; pdsNewPhone.AllowPaging = true; pdsNewPhone.PageSize = 4; NewPhone.DataSource = pdsNewPhone; NewPhone.DataBind(); // bllSanPham = new SanPhamBLL(); DataTable dtSmartPhone = bllSanPham.selectSPByIDPhanLoai(1); PagedDataSource pdsSmartPhone = new PagedDataSource(); DataView dvSmartPhone = new DataView(dtSmartPhone); pdsSmartPhone.DataSource = dvSmartPhone; pdsSmartPhone.AllowPaging = true; pdsSmartPhone.PageSize = 4; SmartPhone.DataSource = pdsSmartPhone; SmartPhone.DataBind(); // bllSanPham = new SanPhamBLL(); DataTable dtPhoThong = bllSanPham.selectSPByIDPhanLoai(0); PagedDataSource pdsPhoThong = new PagedDataSource(); DataView dvPhoThong = new DataView(dtPhoThong); pdsPhoThong.DataSource = dvPhoThong; pdsPhoThong.AllowPaging = true; pdsPhoThong.PageSize = 4; PhoThong.DataSource = pdsPhoThong; PhoThong.DataBind(); }
protected void Submit_Click(object sender, EventArgs e) { dtoSanPham = new SanPham(); bllSanPham = new SanPhamBLL(); string fname = null; dtoSanPham.MaSX = Convert.ToInt32(TenSX.SelectedValue); dtoSanPham.TenSP = TenSP.Text; dtoSanPham.GiaBan = GiaBan.Text; dtoSanPham.PhanLoai = PhanLoai.SelectedValue; //Upload image HttpPostedFile file = Request.Files["FileUpload"]; //check file was submitted if (file != null && file.ContentLength > 0) { fname = Path.GetFileName(file.FileName); } dtoSanPham.HinhAnh = fname; dtoSanPham.ChiTiet = Request.Form["ChiTiet"]; if (bllSanPham.insertSanPham(dtoSanPham)) { if (fname != null) { file.SaveAs(Server.MapPath(Path.Combine("../Images/", fname))); } Page_Clear(); gvSanPhamBindData(); lblMessage.Text = null; error.Text = "Thêm thành công!"; } else { lblMessage.Text = null; error.Text = "Lỗi! Vui lòng thử lại."; } }
protected void Page_Load(object sender, EventArgs e) { bllSanPham = new SanPhamBLL(); if (Request.QueryString["MaSP"]!=null) { sdrSanPham = bllSanPham.selectSanPhamByMaSP(int.Parse(Request.QueryString["MaSP"])); if (sdrSanPham.Read()) { TenSP.Text = (string)sdrSanPham["TenSP"]; TenSX.Text = (string)sdrSanPham["TenSX"]; GiaBan.Text = sdrSanPham["GiaBan"].ToString(); NgayNhap.Text = ((DateTime)sdrSanPham["NgayNhap"]).ToString("dd/MM/yyyy"); HinhAnh.ImageUrl = "/Images/" + (string)sdrSanPham["HinhAnh"]; ChiTiet.Text = (string)sdrSanPham["ChiTiet"]; } else { Response.Redirect("/Default.aspx"); } } else { Response.Redirect("/Default.aspx"); } }
protected void DeleteRecord(object sender, GridViewDeleteEventArgs e) { bllSanPham = new SanPhamBLL(); int MaSP = Int32.Parse(gvSanPham.DataKeys[e.RowIndex].Value.ToString()); try { bllSanPham.deleteSanPham(MaSP); error.Text = null; lblMessage.Text = "Xóa thành công!"; gvSanPhamBindData(); } catch (Exception) { throw; } }
//gvSanPham private void gvSanPhamBindData() { DataTable dtSanPham; bllSanPham = new SanPhamBLL(); dtSanPham = bllSanPham.getSanPham(); gvSanPham.DataSource = dtSanPham; gvSanPham.DataBind(); }