public void HienThiSanPham() { BUS_SanPham bus = new BUS_SanPham(); dtlSanPham.DataSource = bus.LoadSanPhamChuDe(1); dtlSanPham.DataBind(); }
public void LayThongTinSanPham() { if (Request.QueryString["action"] == "chitiet") { int id = int.Parse(Request.QueryString["id"].ToString()); Session["MaSP"] = id; BUS_SanPham bus = new BUS_SanPham(); SanPham sp = new SanPham(); sp = bus.LayThongTinSanPham(id); lblTenSP.Text = sp.TenSP; lblGiaBan.Text = "Giá : " + sp.GiaBan.ToString() + " VNĐ"; imgSanPham.ImageUrl = sp.HinhAnh; pGiaBan.InnerText = sp.ThongTin; //do thong tin size len combobox if (bus.LayKichThuocSanPham(id).Rows.Count == 0) { ibtnMua.Visible = false; ddlSize.DataSource = null; lblTinhTrang.Text = "Tình trạng : hết hàng."; ddlSize.DataBind(); } else { ddlSize.DataSource = bus.LayKichThuocSanPham(id); ddlSize.DataBind(); lblTinhTrang.Text = "Tình trạng : Còn hàng."; } ibtnMua.PostBackUrl = "ChiTietSanPham.aspx?action=add&id=" + id + "&url=chitiet"; } }
public void HienThiGioHang() { DataTable dt = new DataTable(); dt.Columns.Add("MaSP"); dt.Columns.Add("Ten"); dt.Columns.Add("SL"); int SoLuong = 0, TongTien = 0; if (Session["GioHang"] != null) { ArrayList giohang = (ArrayList)Session["GioHang"]; BUS_SanPham bus_sp = new BUS_SanPham(); foreach (SanPham sp in giohang) { DataRow dr = dt.NewRow(); dr["MaSP"] = sp.MaSP; dr["Ten"] = sp.TenSP; dr["SL"] = sp.SoLuong; SoLuong += sp.SoLuong; TongTien += (sp.SoLuong * sp.GiaBan); dt.Rows.Add(dr); } Session["TongSL"] = SoLuong; Session["TongTien"] = TongTien; lblTongSL.Text = "Số lượng : " + SoLuong.ToString() + " sản phẩm"; lblTongTien.Text = "Tổng tiền : " + TongTien.ToString() + " VNĐ"; dtlGioHang.DataSource = dt; dtlGioHang.DataBind(); } }
protected void gvCTHD_RowUpdating(object sender, GridViewUpdateEventArgs e) { int mahd = int.Parse(Session["MaHoaDon"].ToString()); GridViewRow row = gvCTHD.Rows[e.RowIndex]; BUS_SanPham busSp = new BUS_SanPham(); int masp = int.Parse(row.Cells[1].Text); int masize = 0; string s = row.Cells[3].Text; switch (row.Cells[3].Text) { case "s": masize = 0; break; case "m": masize = 1; break; case "l": masize = 2; break; case "xl ": masize = 3; break; case "xxl": masize = 4; break; } TextBox txtSoLuong = row.FindControl("txtSoLuong") as TextBox; string soluong = txtSoLuong.Text.Trim(); CTHD ct = new CTHD(); ct.MAHD = mahd; ct.MASP = masp; ct.MASIZE = masize; ct.SOLUONG = int.Parse(soluong); BUS_CTHD bus = new BUS_CTHD(); bus.CapNhatCTHD(ct); gvCTHD.EditIndex = -1; DataTable dt = new DataTable(); BUS_CTHD busCTHD = new BUS_CTHD(); dt = busCTHD.LoadCTHD(mahd); gvCTHD.DataSource = dt.DefaultView; gvCTHD.PageIndex = int.Parse(Session["cthdPage"].ToString()); gvCTHD.DataBind(); }
public void LoadSP(int loaisp, int gioitinh) { BUS_SanPham busSP = new BUS_SanPham(); DataTable dt = new DataTable(); dt = busSP.LoadSPTheoLoaiAdmin(loaisp, gioitinh); gvDSSP.DataSource = dt.DefaultView; gvDSSP.DataBind(); }
public void LoadTopSP() { int top = int.Parse(ddlTop.SelectedValue); BUS_SanPham bus = new BUS_SanPham(); DataTable dt = new DataTable(); dt = bus.TopSanPham(top); gvTop.DataSource = dt.DefaultView; gvTop.DataBind(); }
public void ThemSP_GioHang() { if (Request.QueryString["action"] == "add" && Session["Username"] == null) { Response.Write("<Script>alert(\"Vui lòng đăng nhập , để sử dụng chức năng này .\")</Script>"); return; } if (Request.QueryString["action"] == "add") { int id = int.Parse(Request.QueryString["id"]); int size = int.Parse(ddlSize.SelectedValue.ToString()); if (Session["GioHang"] == null) { ArrayList giohang = new ArrayList(); // tạo mới món hàng BUS_SanPham bus = new BUS_SanPham(); SanPham sp = bus.LayThongTinSanPham(id); // thêm vào slg 1 sp.SoLuong = 1; sp.MASIZE = size; // thêm vào giỏ hàng giohang.Add(sp); // lưu trong session Session["GioHang"] = giohang; } else { ArrayList giohang = (ArrayList)Session["GioHang"]; bool flag = false; foreach (SanPham sp in giohang) { if (sp.MaSP == id && sp.MASIZE == size) { sp.SoLuong += 1; flag = true; break; } } if (flag == false) { // tạo mới món hàng BUS_SanPham bus = new BUS_SanPham(); SanPham sp = bus.LayThongTinSanPham(id); // thêm vào slg 1 sp.MASIZE = size; sp.SoLuong = 1; // thêm vào giỏ hàng giohang.Add(sp); } } Response.Redirect("ChiTietSanPham.aspx?action=chitiet&id=" + id + "&url=chitiet"); } }
public void LoadGioHang() { DataTable dt = new DataTable(); dt.Columns.Add("MaSP"); dt.Columns.Add("TenSP"); dt.Columns.Add("Size"); dt.Columns.Add("SoLuong"); dt.Columns.Add("GiaBan"); if (Session["GioHang"] != null) { ArrayList giohang = (ArrayList)Session["GioHang"]; BUS_SanPham bus_sp = new BUS_SanPham(); foreach (SanPham sp in giohang) { DataRow dr = dt.NewRow(); dr["MaSP"] = sp.MaSP; dr["TenSP"] = sp.TenSP; switch (sp.MASIZE) { case 0: dr["Size"] = "S"; break; case 1: dr["Size"] = "M"; break; case 2: dr["Size"] = "L"; break; case 3: dr["Size"] = "XL"; break; case 4: dr["Size"] = "XXL"; break; } dr["SoLuong"] = sp.SoLuong; dr["GiaBan"] = sp.GiaBan; dt.Rows.Add(dr); } gvGioHang.DataSource = dt.DefaultView; gvGioHang.DataBind(); } }
protected void gvDSSP_RowDeleting(object sender, GridViewDeleteEventArgs e) { int masp = int.Parse(gvDSSP.DataKeys[e.RowIndex].Value.ToString()); BUS_SanPham busSP = new BUS_SanPham(); busSP.XoaSP(masp); int loaisp = int.Parse(ddlLoaiSP.SelectedValue); int gioitinh = 0; if (rblGioitinh.SelectedValue.Equals("Nam")) { gioitinh = 1; } LoadSP(loaisp, gioitinh); }
public void LoadSanPham() { if (Request.QueryString["url"] != null) { string ulr = Request.QueryString["url"]; Session["url"] = Request.UrlReferrer.ToString(); BUS_SanPham bus = new BUS_SanPham(); switch (ulr) { case "nam0": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(0, 1); dtlSanPham.DataBind(); Session["LoaiSP"] = "nam0"; break; case "nam1": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(1, 1); dtlSanPham.DataBind(); Session["LoaiSP"] = "nam1"; break; case "nam2": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(2, 1); dtlSanPham.DataBind(); Session["LoaiSP"] = "nam2"; break; case "nam3": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(3, 1); dtlSanPham.DataBind(); Session["LoaiSP"] = "nam3"; break; case "nam4": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(4, 1); dtlSanPham.DataBind(); Session["LoaiSP"] = "nam4"; break; case "nu0": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(0, 0); dtlSanPham.DataBind(); Session["LoaiSP"] = "nu0"; break; case "nu1": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(1, 0); dtlSanPham.DataBind(); Session["LoaiSP"] = "nu1"; break; case "nu2": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(2, 0); dtlSanPham.DataBind(); Session["LoaiSP"] = "nu2"; break; case "nu3": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(3, 0); dtlSanPham.DataBind(); Session["LoaiSP"] = "nu3"; break; case "nu5": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(5, 0); dtlSanPham.DataBind(); Session["LoaiSP"] = "nu4"; break; case "pknam": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(6, 1); dtlSanPham.DataBind(); Session["LoaiSP"] = "pknam"; break; case "pknu": dtlSanPham.DataSource = bus.LoadSanPhamTheoLoai(6, 0); dtlSanPham.DataBind(); Session["LoaiSP"] = "pknu"; break; case "saleoff": dtlSanPham.DataSource = bus.LoadSanPhamChuDe(3); dtlSanPham.DataBind(); Session["LoaiSP"] = "saleoff"; break; case "new": dtlSanPham.DataSource = bus.LoadSanPhamChuDe(2); dtlSanPham.DataBind(); Session["LoaiSP"] = "new"; break; case "hot": dtlSanPham.DataSource = bus.LoadSanPhamChuDe(1); dtlSanPham.DataBind(); Session["LoaiSP"] = "hot"; break; case "tk": string TenSP = Request.QueryString["value"]; dtlSanPham.DataSource = bus.TimKiemSanPham(TenSP); dtlSanPham.DataBind(); break; default: break; } } }
protected void gvDSSP_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("capnhatSP")) { txtSoLuongS.Enabled = false; txtSoLuongM.Enabled = false; txtSoLuongL.Enabled = false; txtSoLuongXL.Enabled = false; txtSoLuongXXL.Enabled = false; rfvSoLuongS.Visible = false; rfvSoLuongM.Visible = false; rfvSoLuongL.Visible = false; rfvSoLuongXL.Visible = false; rfvSoLuongXXL.Visible = false; int id = int.Parse(e.CommandArgument.ToString()); int masp = int.Parse(gvDSSP.DataKeys[id].Value.ToString()); SanPham sp = new SanPham(); BUS_SanPham bus = new BUS_SanPham(); sp = bus.LayThongTinSanPham(masp); Label2.Text = "Cập nhật sản phẩm"; btnThemSP.Text = "Cập nhật"; txtMaSP.Enabled = false; txtMaSP.Text = sp.MaSP.ToString(); txtTenSP.Text = sp.TenSP; txtGiaMua.Text = sp.GiaMua.ToString(); txtGiaBan.Text = sp.GiaBan.ToString(); switch (sp.MASIZE) { case 0: txtSoLuongS.Text = sp.SoLuong.ToString(); txtSoLuongS.Enabled = true; Session["MaSize"] = 0; rfvSoLuongS.Visible = true; break; case 1: txtSoLuongM.Text = sp.SoLuong.ToString(); txtSoLuongM.Enabled = true; Session["MaSize"] = 1; rfvSoLuongM.Visible = true; break; case 2: txtSoLuongL.Text = sp.SoLuong.ToString(); txtSoLuongL.Enabled = true; Session["MaSize"] = 2; rfvSoLuongL.Visible = true; break; case 3: txtSoLuongXL.Text = sp.SoLuong.ToString(); txtSoLuongXL.Enabled = true; Session["MaSize"] = 3; rfvSoLuongXL.Visible = true; break; case 4: txtSoLuongXXL.Text = sp.SoLuong.ToString(); txtSoLuongXXL.Enabled = true; Session["MaSize"] = 4; rfvSoLuongXXL.Visible = true; break; } ddlLoai.SelectedIndex = sp.LoaiSP; ddlChuDe.SelectedIndex = sp.ChuDe; txtThongTin.Text = sp.ThongTin; rbtngt.SelectedValue = sp.GioiTinh.ToString(); txtNgayNhap.Text = sp.NgayNhap.ToShortDateString(); txtHinhAnh.Text = sp.HinhAnh; } }
protected void btnThemSP_Click(object sender, EventArgs e) { if (btnThemSP.Text.Equals("Cập nhật")) { SanPham sp = new SanPham(); BUS_SanPham bus = new BUS_SanPham(); sp.MaSP = int.Parse(txtMaSP.Text); sp.TenSP = txtTenSP.Text; sp.GiaMua = int.Parse(txtGiaMua.Text); sp.GiaBan = int.Parse(txtGiaBan.Text); sp.MASIZE = int.Parse(Session["MaSize"].ToString()); switch (sp.MASIZE) { case 0: sp.SoLuong = int.Parse(txtSoLuongS.Text.Trim()); break; case 1: sp.SoLuong = int.Parse(txtSoLuongM.Text.Trim()); break; case 2: sp.SoLuong = int.Parse(txtSoLuongL.Text.Trim()); break; case 3: sp.SoLuong = int.Parse(txtSoLuongXL.Text.Trim()); break; case 4: sp.SoLuong = int.Parse(txtSoLuongXXL.Text.Trim()); break; } sp.LoaiSP = int.Parse(ddlLoai.SelectedValue); sp.ChuDe = int.Parse(ddlChuDe.SelectedValue); sp.ThongTin = txtThongTin.Text; sp.GioiTinh = int.Parse(rbtngt.SelectedValue); sp.NgayNhap = DateTime.Parse(txtNgayNhap.Text); sp.HinhAnh = txtHinhAnh.Text; bus.CapNhatSP(sp); DienDuLieu(); lblThongBao.Text = "Cập nhật sản phẩm thành công !"; } if (btnThemSP.Text.Equals("Thêm")) { SanPham sp = new SanPham(); BUS_SanPham busSP = new BUS_SanPham(); sp.MaSP = int.Parse(txtMaSP.Text); if (busSP.LaTrungMaSP(sp.MaSP) == 1) { lblMaSP1.Text = "Trùng mã sản phẩm !"; return; } sp.TenSP = txtTenSP.Text; sp.GiaMua = int.Parse(txtGiaMua.Text); sp.GiaBan = int.Parse(txtGiaBan.Text); sp.LoaiSP = int.Parse(ddlLoai.SelectedValue); sp.ChuDe = int.Parse(ddlChuDe.SelectedValue); sp.ThongTin = txtThongTin.Text; sp.GioiTinh = int.Parse(rbtngt.SelectedValue); sp.NgayNhap = DateTime.Parse(txtNgayNhap.Text); sp.HinhAnh = txtHinhAnh.Text; busSP.ThemSP(sp); //them size s sp.MASIZE = 0; sp.SoLuong = int.Parse(txtSoLuongS.Text.Trim()); busSP.ThemSoLuongSanPham(sp); //them size m sp.MASIZE = 1; sp.SoLuong = int.Parse(txtSoLuongM.Text.Trim()); busSP.ThemSoLuongSanPham(sp); //them size l sp.MASIZE = 2; sp.SoLuong = int.Parse(txtSoLuongL.Text.Trim()); busSP.ThemSoLuongSanPham(sp); //them size xl sp.MASIZE = 3; sp.SoLuong = int.Parse(txtSoLuongXL.Text.Trim()); busSP.ThemSoLuongSanPham(sp); //them size xxl sp.MASIZE = 4; sp.SoLuong = int.Parse(txtSoLuongXXL.Text.Trim()); busSP.ThemSoLuongSanPham(sp); lblThongBao.Text = "Thêm sản phẩm thành công !"; DienDuLieu(); } }