protected void dl2_ItemCommand(object source, DataListCommandEventArgs e) { LinkButton lable = (LinkButton)e.Item.FindControl("TenSPLabel"); SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.TenSP == lable.Text); string clickdangnhap = Request.QueryString["ClickDangNhap"]; if (clickdangnhap == null) { Response.Redirect("~/TrangDangNhap.aspx?MaSanPham=" + sanpham.MaSanPham); } else { string makh = Request.QueryString["MaKhachHang"]; GioHangs giohang = db.GioHangs.SingleOrDefault(p => p.MaKhachHang.ToString() == makh && p.MaSanPham == sanpham.MaSanPham); if (giohang != null) { giohang.SoLuong = giohang.SoLuong + 1; db.SubmitChanges(); } else { giohang = new GioHangs(); giohang.SoLuong = 1; giohang.MaSanPham = Convert.ToInt32(sanpham.MaSanPham); giohang.MaKhachHang = Convert.ToInt32(makh); db.GioHangs.InsertOnSubmit(giohang); db.SubmitChanges(); } Response.Redirect("~/GioHang.aspx?MaKhachHang=" + makh); } }
protected void btnSua_Click(object sender, EventArgs e) { SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.TenSP == txtTenSP.Text); ChiTietNhap chitietnhap = db.ChiTietNhaps.SingleOrDefault(p => p.SoHoaDon.ToString() == txtSoHD.Text && p.MaSanPham == sanpham.MaSanPham); if (chitietnhap == null) { CustomValidator1.ErrorMessage = "Bạn hãy chọn một chi tiết nhập để sửa "; CustomValidator1.IsValid = false; } else { updatesoluongsp("update", chitietnhap); chitietnhap.SoLuongNhap = Convert.ToInt32(txtSoLuong.Text); chitietnhap.GiaNhap = Convert.ToDouble(txtGiaNhap.Text); db.SubmitChanges(); LoadTatCaSP(); } txtSoHD.Enabled = true; txtThongSoKyThuat.Enabled = true; txtTenSP.Enabled = true; txtNhaSanXuat.Enabled = true; txtLoaiSP.Enabled = true; FileUpload1.Enabled = true; btnupload.Enabled = true; txtNhaSanXuat.Enabled = true; txtThongSoKyThuat.Enabled = true; }
protected void dl1_ItemDataBound(object sender, DataListItemEventArgs e) { DataListItem item = e.Item; Label lbGiaMoi = (Label)item.FindControl("GiaBanMoiLabel"); Label lbGiaBan = (Label)item.FindControl("GiaBanLabel"); lbGiaBan.Text = "Giá: " + HienThiGia(Convert.ToDouble(lbGiaBan.Text)); LinkButton linkbutton = (LinkButton)item.FindControl("lbtTenSP"); SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.TenSP == linkbutton.Text); Label tenkhuyenmai = (Label)item.FindControl("TenKhuyenMai"); SanPham_KhuyenMai sanphamkhuyenmai = db.SanPham_KhuyenMais.SingleOrDefault(p => p.MaSanPham == sanpham.MaSanPham); if (sanphamkhuyenmai != null) { KhuyenMai khuyenmai = db.KhuyenMais.SingleOrDefault(p => p.MaKhuyenMai == sanphamkhuyenmai.MaKhuyenMai); tenkhuyenmai.Text = khuyenmai.NoiDungKhuyenMai; if (khuyenmai.NoiDungKhuyenMai.ToString().Length > 30) { tenkhuyenmai.Text = khuyenmai.NoiDungKhuyenMai.Substring(0, 30) + "..."; } lbGiaBan.Font.Strikeout = true; lbGiaMoi.ForeColor = System.Drawing.Color.Red; lbGiaMoi.Text = "Giá bán: " + HienThiGia(Convert.ToDouble(TinhGiamGia(khuyenmai.GiaCanGiam, sanpham.GiaBan).ToString())); } else { lbGiaBan.Font.Size = 11; lbGiaBan.Font.Bold = true; } }
public ActionResult PartialDanhSachSanPham() { var lstKetQua = new List <SanPhams>(); using (DauGiaEntities ctx = new DauGiaEntities()) { var lstSanPham = ctx.SanPhams.where (x => x.DaDuyet == false).ToList(); foreach (var item in lstSanPham) { var danhmuc = ctx.DanhMucs.SingleOrDefault(x => x.MaTheLoai == item.MaTheLoai.Value); var nguoiDung = ctx.NguoiDungs.SingleOrDefault(x => x.MaNguoiDung = item.MaNguoiDung.Value); var sanpham = new SanPhams() { MaSanPham = item.MaSanPham, Gia = item.Gia, Hinhanh1 = item.HinhAnh1, HinhAnh2 = item.HinhAnh2, HinhAnh3 = item.HinhAnh3, NgayBatDau = item.NgayBatDau, NgayKetThuc = item.NgayKetThuc, TenSanPham = item.TenSanPham, LoaiSanPham = item.DanhMuc, NguoiDung = nguoiDung }; lstKetQua.Add(sanpham); } lstKetQua.OrderBy(x => x.NgayBatDau).ToList(); return(partialView("DanhSachSanPham", lstKetQua)); } }
protected void GridView3_SelectedIndexChanged(object sender, EventArgs e) { SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.MaSanPham.ToString() == GridView3.Rows[GridView3.SelectedIndex].Cells[0].Text.ToString()); ChiTietNhap chitietnhap = db.ChiTietNhaps.SingleOrDefault(p => p.MaSanPham == sanpham.MaSanPham && p.SoHoaDon.ToString() == GridView3.Rows[GridView3.SelectedIndex].Cells[6].Text); txtSoHD.Enabled = false; txtThongSoKyThuat.Enabled = false; txtTenSP.Enabled = false; txtNhaSanXuat.Enabled = false; txtLoaiSP.Enabled = false; FileUpload1.Enabled = false; btnupload.Enabled = false; txtNhaSanXuat.Enabled = false; txtThongSoKyThuat.Enabled = false; txtBaoHanh.Enabled = false; if (sanpham.HinhAnh != null) { hinhanh.ImageUrl = sanpham.HinhAnh; hinhanh.DataBind(); } txtNhaSanXuat.SelectedItem.Text = sanpham.NhaSanXuat; txtSoHD.SelectedItem.Text = chitietnhap.SoHoaDon.ToString(); txtNhaCungCap.SelectedItem.Text = chitietnhap.NhaCungCap.TenNhaCungCap; txtSoLuong.Text = chitietnhap.SoLuongNhap.ToString(); txtTenSP.SelectedItem.Text = sanpham.TenSP; txtGiaNhap.Text = chitietnhap.GiaNhap.ToString(); txtGhichu.Text = chitietnhap.GhiChu; }
public void ThemSanPham(SanPham sp, int sl, bool laCapNhat) { var SanPhamGioHang = new SanPhamGioHang() { MaSP = sp.MaSP, TenSP = sp.TenSP, MieuTa = sp.MieuTa, GiaSP = sp.GiaSP, AnhSP = sp.AnhSP, XuatSu = sp.XuatSu, ChatLieu = sp.ChatLieu, GioiTinh = sp.GioiTinh, MaLoaiSanPham = sp.MaLoaiSanPham, LoaiSanPham = sp.LoaiSanPham.TenLoaiSanPham, SoLuong = sl, }; // kiểm tra tồn tại Product có trong giỏ hàng theo id chưa var existKey = SanPhams.ContainsKey(sp.MaSP); if (!laCapNhat && existKey) { var existingItem = SanPhams[sp.MaSP]; SanPhamGioHang.SoLuong += existingItem.SoLuong; } if (existKey) { SanPhams[sp.MaSP] = SanPhamGioHang; } else { SanPhams.Add(sp.MaSP, SanPhamGioHang); } }
public void Remove(int MaSP) { if (SanPhams.ContainsKey(MaSP)) { SanPhams.Remove(MaSP); } }
protected void btnMua_Click(object sender, ImageClickEventArgs e) { string masp = Request.QueryString["MaSanPham"]; SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.MaSanPham.ToString() == masp); Response.Redirect("~/TrangDangNhap.aspx?MaSanPham=" + sanpham.MaSanPham); }
protected void Page_Load(object sender, EventArgs e) { string masp = Request.QueryString["MaSanPham"]; SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.MaSanPham.ToString() == masp); lblTenSanPham.Text = sanpham.TenSP; lblThongSoTongThe.Text = sanpham.ThongSoKyThuat; if (sanpham.SanPham_KhuyenMai.KhuyenMai.GiaCanGiam != null) { lblGiaBan.Font.Strikeout = true; lblGiaMoi.Text = "Giá bán: " + HienThiGia(Convert.ToDouble(TinhGiamGia(sanpham.SanPham_KhuyenMai.KhuyenMai.GiaCanGiam, sanpham.GiaBan).ToString())); } lblGiaBan.Text = HienThiGia(sanpham.GiaBan); lblBaoHanh.Text = sanpham.BaoHanh; lblKhuyenMai.Text = sanpham.SanPham_KhuyenMai.KhuyenMai.TenKhuyenMai; if (sanpham.SoLuong > 0) { lblKhoHang.Text = "Còn hàng"; } Image6.ImageUrl = sanpham.HinhAnh; Image6.DataBind(); var chitiet = from p in db.ChiTietThongSos where p.ThongSoKyThuat == sanpham.ThongSoKyThuat select p; if (chitiet != null) { DataList1.DataSource = chitiet; DataList1.DataBind(); } }
protected void dl1_ItemCommand(object source, DataListCommandEventArgs e) { DataListItem item = e.Item; LinkButton linkbutton = (LinkButton)item.FindControl("TenSPLabel"); SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.TenSP == linkbutton.Text); Response.Redirect("~/TrangDangNhap.aspx?MaSanPham=" + sanpham.MaSanPham); }
void updatesoluongsp(string type, ChiTietNhap chitietnhap) { SanPhams sp = db.SanPhams.SingleOrDefault(p => p.MaSanPham == chitietnhap.MaSanPham); if (type == "insert") { sp.SoLuong = sp.SoLuong + Convert.ToInt16(txtSoLuong.Text); db.SubmitChanges(); } if (type == "update") { sp.SoLuong = sp.SoLuong - chitietnhap.SoLuongNhap + Convert.ToInt32(txtSoLuong.Text); db.SubmitChanges(); } if (type == "delete") { sp.SoLuong = sp.SoLuong - chitietnhap.SoLuongNhap; db.SubmitChanges(); } }
protected void btnNhap_Click(object sender, EventArgs e) { if (kiemtra() == true) { NhaCungCap nhacungcap = db.NhaCungCaps.SingleOrDefault(p => p.TenNhaCungCap == txtNhaCungCap.Text); SanPhams Sanpham = db.SanPhams.SingleOrDefault(p => p.TenSP == txtTenSP.Text); if (Sanpham != null) { ChiTietNhap chitietnhap = db.ChiTietNhaps.SingleOrDefault(p => p.MaSanPham == Sanpham.MaSanPham && p.SoHoaDon.ToString() == txtSoHD.Text); if (chitietnhap != null) { chitietnhap.SoLuongNhap = chitietnhap.SoLuongNhap + Convert.ToInt16(txtSoLuong.Text); chitietnhap.GiaNhap = chitietnhap.GiaNhap + Convert.ToDouble(txtGiaNhap.Text); db.SubmitChanges(); updatesoluongsp("insert", chitietnhap); } else { ChiTietNhap Chitietnhap = new ChiTietNhap(); Chitietnhap.SoLuongNhap = Convert.ToInt16(txtSoLuong.Text); Chitietnhap.SoHoaDon = Convert.ToInt16(txtSoHD.Text); Chitietnhap.GhiChu = txtGhichu.Text; Chitietnhap.GiaNhap = Convert.ToDouble(txtGiaNhap.Text); if (nhacungcap != null) { Chitietnhap.MaNhaCungCap = nhacungcap.MaNhaCungCap; } Chitietnhap.MaSanPham = Sanpham.MaSanPham; Chitietnhap.NgayNhap = DateTime.Now.ToShortDateString(); db.ChiTietNhaps.InsertOnSubmit(Chitietnhap); db.SubmitChanges(); updatesoluongsp("insert", Chitietnhap); } } else { SanPhams sanpham = new SanPhams(); sanpham.TenSP = txtTenSP.Text; sanpham.ThongSoKyThuat = txtThongSoKyThuat.Text; sanpham.NhaSanXuat = txtNhaSanXuat.Text; sanpham.LoaiSP = txtLoaiSP.Text; sanpham.HinhAnh = hinhanh.ImageUrl; sanpham.BaoHanh = txtBaoHanh.Text; sanpham.SoLuong = Convert.ToInt16(txtSoLuong.Text); db.SanPhams.InsertOnSubmit(sanpham); db.SubmitChanges(); ChiTietNhap chitietnhap = new ChiTietNhap(); chitietnhap.SoLuongNhap = Convert.ToInt16(txtSoLuong.Text); chitietnhap.SoHoaDon = Convert.ToInt16(txtSoHD.Text); chitietnhap.GhiChu = txtGhichu.Text; chitietnhap.GiaNhap = Convert.ToDouble(txtGiaNhap.Text); if (nhacungcap != null) { chitietnhap.MaNhaCungCap = nhacungcap.MaNhaCungCap; } chitietnhap.MaSanPham = sanpham.MaSanPham; chitietnhap.NgayNhap = DateTime.Now.ToShortDateString(); db.ChiTietNhaps.InsertOnSubmit(chitietnhap); db.SubmitChanges(); } } LoadTatCaSP(); }