private void loadsanpham() { sanphamBLL sp = new sanphamBLL(); khuyenmaiBLL km = new khuyenmaiBLL(); int id = Convert.ToInt32(Request.Form["id"]); dathangdetailBLL bs = new dathangdetailBLL(); List <dathangdetail> ds = bs.getdathangDetail(id); rpDatHang.DataSource = ds; rpDatHang.DataBind(); decimal gia = 0; for (int i = 0; i <= ds.Count - 1; i++) { decimal giasp = 0; List <sanphamDAL> list = sp.getSPbyId(ds[i].id_sanpham); if (list[0].khuyenmai == true) { giasp = ds[i].gia - (ds[i].gia * km.getKhuyenMaibyId(1) / 100); } else { giasp = ds[i].gia; } Label lbSTT = rpDatHang.Items[i].FindControl("lbSTT") as Label; gia += (giasp * ds[i].soluong); lbSTT.Text = (i + 1).ToString(); } lbTongTien.Text = String.Format("{0:0,0 VNĐ}", gia); }
// san pham mua nhieu private void load10muanhieu(int id_khm) { khuyenmaiBLL km = new khuyenmaiBLL(); sanphamBLL spbs = new sanphamBLL(); dathangdetailBLL bs = new dathangdetailBLL(); List <dathangdetail> ds = bs.getdathangDetailMuaNhieuPubLic(); rpbanchay.DataSource = ds; rpbanchay.DataBind(); for (int i = 0; i <= ds.Count() - 1; i++) { Label lbA = rpbanchay.Items[i].FindControl("lbA") as Label; Label lbHinh = rpbanchay.Items[i].FindControl("lbHinh") as Label; Label lbTen = rpbanchay.Items[i].FindControl("lbTen") as Label; Label lbGia = rpbanchay.Items[i].FindControl("lbGia") as Label; List <sanphamDAL> sptt = spbs.getSPbyId(ds[i].id_sanpham); lbA.Text = "<a href='chitietsanpham.aspx?id=" + sptt[0].id_sanpham + "&gr=" + sptt[0].id_danhmuc + "' title='" + sptt[0].ten_sanpham + "'>"; lbHinh.Text = "<img class='hinhsp' height='350' width='275' alt='" + sptt[0].ten_sanpham + "' src='/uploads/" + sptt[0].hinhanh + "' style='display: block;' />"; lbTen.Text = "<span class='productName'>" + sptt[0].ten_sanpham + "</span>"; if (sptt[0].khuyenmai == true) { decimal khm = sptt[0].gia - (sptt[0].gia * km.getKhuyenMaibyId(id_khm) / 100); lbGia.Text = "<span class='price'><span style='color:Red;'><del>" + String.Format("{0:0,0 vnđ}", sptt[0].gia) + "</del> </span>" + String.Format("{0:0,0 vnđ}", khm) + "</span>"; } else { lbGia.Text = "<span class='price'>" + String.Format("{0:0,0 vnđ}", sptt[0].gia) + "</span>"; } } }
protected void Page_Load(object sender, EventArgs e) { string noidung = Request.Form["gui"]; sanphamBLL bl = new sanphamBLL(); string[] noidungspli = noidung.Split('&'); int id = Convert.ToInt32(noidungspli[0].Substring(4)); List <sanphamDAL> ds = bl.getSPbyId(id); lbnoidung.Text = ds[0].tt_chitiet; }
// load thong tin san pham: private void loadTTSP(int id) { sanphamBLL bs = new sanphamBLL(); List <sanphamDAL> list = bs.getSPbyId(id); if (list.Count == 1) { lbGia.Text = string.Format("{0:0,0 vnđ}", list[0].gia); txtGia.Text = list[0].gia.ToString();; txtSoLuong.Text = list[0].soluong.ToString(); txtTen.Text = list[0].ten_sanpham; txtTT.Text = list[0].tt_chitiet; // ddlist: ddlDM.SelectedValue = list[0].id_danhmuc.ToString(); // radio: if (list[0].khuyenmai == true) { rbYes.Checked = true; } else { rbNo.Checked = true; } // hinh anh: if (list[0].hinhanh != "") { lbHinh.Text = "<img width='100' height='100' style='display: block;' src='/uploads/" + list[0].hinhanh + "' alt='" + list[0].ten_sanpham + "'>"; lbHinh.ToolTip = list[0].hinhanh; fuPicture.Visible = false; lbErrorPic.Visible = false; btnHinhKhac.Visible = true; } else { lbHinh.Visible = false; fuPicture.Visible = true; lbErrorPic.Visible = true; btnHinhKhac.Visible = false; } } else { Response.Redirect("error.aspx"); } }
// load thong tin san pham private void loadTTSP() { khuyenmaiBLL km = new khuyenmaiBLL(); sanphamBLL bs = new sanphamBLL(); List <sanphamDAL> ds = bs.getSPbyId(id); decimal khm = 0; if (ds.Count() == 1) { imgsp.ImageUrl = "/uploads/" + ds[0].hinhanh; hinh = "/uploads/" + ds[0].hinhanh; if (ds[0].khuyenmai == true) { khm = ds[0].gia - (ds[0].gia * km.getKhuyenMaibyId(1) / 100); lbGia.Text = "<del style='color:red'>" + String.Format("{0:0,0 vnđ}", ds[0].gia) + "</del>" + "   " + String.Format("{0:0,0 vnđ}", khm); } else { khm = ds[0].gia; lbGia.Text = String.Format("{0:0,0 vnđ}", khm); } gia = khm; lbTenSP.Text = ds[0].ten_sanpham; ten = ds[0].ten_sanpham; if (ds[0].soluong <= 2) { lbTinhTrang.Text = "Còn rất ít"; } else if (ds[0].soluong == 0) { lbTinhTrang.Text = "Hết hàng"; } else { lbTinhTrang.Text = "Còn hàng"; } lbnoidung.Text = ds[0].tt_chitiet; atitle.Text = ten + " Shop thời trang FMStyle"; } else { Response.Redirect("error.aspx"); } }
protected void btnMua_Click(object sender, EventArgs e) { sanphamBLL bs = new sanphamBLL(); List <sanphamDAL> ds = bs.getSPbyId(id); string size = ddlMau.Text; int soluong = Convert.ToInt32(txtSoLuong.Text); int qd = ds[0].soluong - soluong; if (qd >= 0) { addCart(id, ten, soluong, hinh, gia, size); Response.Redirect("muahang.aspx"); } else { lbError.Text = "Sản phẩm này đã hết hàng !<br>"; } }
// xoa hinh anh private void del_Hinh() { bool xoa = false; // xoa hinh trong thu muc uploads int id = Convert.ToInt32(Request.QueryString["id"]); sanphamBLL bs = new sanphamBLL(); List <sanphamDAL> list = bs.getSPbyId(id); string imageFilePath = Server.MapPath("~/uploads/" + list[0].hinhanh + ""); try { System.IO.File.Delete(imageFilePath); xoa = true; } catch { xoa = false; } // xoa hinh trong csdl: bool tf = bs.delHinh("", id); if (xoa == true && tf == true) { lbError.Text = "<div class='success'> " + " <div class='tl'></div><div class='tr'></div>" + "<div class='desc'>" + " <p>Xóa hình thành công !</p>" + "</div>" + "<div class='bl'></div><div class='br'></div>" + "</div>"; } else { lbError.Text = "<div class='error'> " + " <div class='tl'></div><div class='tr'></div>" + "<div class='desc'>" + " <p>Xóa hình không thành công!</p>" + "</div>" + "<div class='bl'></div><div class='br'></div>" + "</div>"; } }
// load san pham ban chay: private void spbanchay(int id_khm) { lbtitle.Text = "Sản phẩm bán chạy"; lbDanhMuc.Text = "Sản phẩm bán chạy"; int row = 10; int hide = 0; if (Request.QueryString["p"] != null) { hide = Convert.ToInt32(Request.QueryString["p"]); } phantrang pt = new phantrang(); khuyenmaiBLL km = new khuyenmaiBLL(); sanphamBLL spbs = new sanphamBLL(); dathangdetailBLL bs = new dathangdetailBLL(); List <dathangdetail> ds = bs.getdathangDetailMuaNhieuP(row, hide); rpbanchay.DataSource = ds; rpbanchay.DataBind(); for (int i = 0; i <= ds.Count() - 1; i++) { Label lbA = rpbanchay.Items[i].FindControl("lbA") as Label; Label lbHinh = rpbanchay.Items[i].FindControl("lbHinh") as Label; Label lbTen = rpbanchay.Items[i].FindControl("lbTen") as Label; Label lbGia = rpbanchay.Items[i].FindControl("lbGia") as Label; List <sanphamDAL> sptt = spbs.getSPbyId(ds[i].id_sanpham); lbA.Text = "<a href='chitietsanpham.aspx?id=" + sptt[0].id_sanpham + "&gr=" + sptt[0].id_danhmuc + "' title='" + sptt[0].ten_sanpham + "'>"; lbHinh.Text = "<img class='hinhsp' height='350' width='275' alt='" + sptt[0].ten_sanpham + "' src='/uploads/" + sptt[0].hinhanh + "' style='display: block;' />"; lbTen.Text = "<span class='productName'>" + sptt[0].ten_sanpham + "</span>"; if (sptt[0].khuyenmai == true) { decimal khm = sptt[0].gia - (sptt[0].gia * km.getKhuyenMaibyId(id_khm) / 100); lbGia.Text = "<span class='price'><span style='color:Red;'><del>" + String.Format("{0:0,0 vnđ}", sptt[0].gia) + "</del> </span>" + String.Format("{0:0,0 vnđ}", khm) + "</span>"; } else { lbGia.Text = "<span class='price'>" + String.Format("{0:0,0 vnđ}", sptt[0].gia) + "</span>"; } } int r = bs.countMuaNhieuP(); lbPhanTrang.Text = pt.pagingpublic(r, row, "&v=bc", hide); }
protected void Page_Load(object sender, EventArgs e) { sanphamBLL sp = new sanphamBLL(); dathangdetailBLL bs = new dathangdetailBLL(); List <dathangdetail> ds = bs.getdathangDetailMuaNhieu(); rpDatHang.DataSource = ds; rpDatHang.DataBind(); for (int i = 0; i <= ds.Count - 1; i++) { Label lbSTT = rpDatHang.Items[i].FindControl("lbSTT") as Label; Label lbTen = rpDatHang.Items[i].FindControl("lbTen") as Label; lbSTT.Text += (i + 1).ToString(); List <sanphamDAL> lsp = sp.getSPbyId(ds[i].id_sanpham); lbTen.Text = lsp[0].ten_sanpham; } }
protected void btnThanhToan_Click(object sender, EventArgs e) { sanphamBLL bss = new sanphamBLL(); List <giohangDAL> cart = (List <giohangDAL>)Session["cart"]; List <userpublicDAL> usp = (List <userpublicDAL>)Session["userPublic"]; dathangBLL bs = new dathangBLL(); bs.add_dathang(usp[0].id_user, Convert.ToInt32(ddThanhToan.SelectedValue)); int id = bs.id_dathang(usp[0].id_user); for (int i = 0; i <= cart.Count - 1; i++) { int y = Convert.ToInt32(cart[i].id_sanpham); List <sanphamDAL> liSoLuong = bss.getSPbyId(y); bs.add_dathang_detail(cart[i].id_sanpham, id, cart[i].soluong, cart[i].size); int pi = liSoLuong[0].soluong - cart[i].soluong; bs.soluong_sp(cart[i].id_sanpham, pi); } Session.Remove("cart"); Response.Redirect("success.aspx"); }