public ActionResult CreateCtPn(Pn item, IEnumerable <Ctpn> lst) { try { SanPham sp; foreach (var x in lst) { // cap nhap so luong sp = SanPhamMager.GetSanPhamByID(x.MaSp); if (PhieuNhapMager.ktthamso(x.MaSp, x.SoLuong) == true) { sp.SoLuongTon = sp.SoLuongTon + x.SoLuong; SanPhamMager.uppdateSanPham(sp); x.MaPN = item.MaPN; x.TenSP = sp.TenSp; } else { return(PartialView("error")); //return Content("<script> alert(\"" + x.SanPham.TenSp + " da bi loi \")+ location.reload(); </script>"); } } CtPnMager.insertall(lst); return(RedirectToAction("Index")); } catch { return(View("error")); } }
public ActionResult create(Hd hd, IEnumerable <Cthd> lstcthd) { try { TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"]; HoaDonManger.insert(hd); SanPham sp; Hd item = HoaDonManger.GetItemById(hd.MaHD); KhachHang kh = KhachHangMager.GetKhachHangByID(hd.MaKH); if (kh != null) { decimal?thanhtien; foreach (var x in lstcthd) { sp = SanPhamMager.GetSanPhamByID(x.MaSp); if (x.SoLuong < sp.SoLuongTon) { sp.SoLuongTon = sp.SoLuongTon - x.SoLuong; SanPhamMager.tinhgiaban(x.MaSp); SanPhamMager.uppdateSanPham(sp); x.MaHD = item.MaHD; x.TenSP = sp.TenSp; x.DonGiaBan = sp.DonGiaBan; thanhtien = x.SoLuong * x.DonGiaBan * (decimal)0.1; kh.Diemso = kh.Diemso + (int)thanhtien; KhachHangMager.uppdateKhachHang(kh); } } } CTHDMager.insertall(lstcthd); KhachHangMager.checkpointKH(kh.MaKh); return(RedirectToAction("Index")); } catch { TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"]; List <SanPham> lst = SanPhamMager.getAllSanPham(); List <KhachHang> lstkh = KhachHangMager.GetAllKhachHang(); ViewBag.khachhang = lstkh; ViewBag.sanpham = new SelectList(lst, "Masp", "TenSp"); ViewBag.nhanvien = TaiKhoanMager.getNVbytk(tk.MaTK); return(View()); } }
[HttpPost] // xoa san pham , luu tt nhan vien xoa public ActionResult Delete(int id, FormCollection f) { TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"]; int idtk = tk.MaTK; NhanVien nv = NhanVienMager.GetbyTK(idtk); var spxoa = SanPhamMager.delete(id); spxoa.MaNVchinhsua = nv.MaNV; spxoa.Ngaycapnhap = DateTime.Now; SanPhamMager.uppdateSanPham(spxoa); if (spxoa != null) { return(RedirectToAction("Index")); } return(View()); }
[HttpPost] // sua sp co luu ten nhan vien sua public ActionResult Edit(SanPham sp) { try { TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"]; int id = tk.MaTK; NhanVien nv = NhanVienMager.GetbyTK(id); sp.MaNVchinhsua = nv.MaNV; SanPhamMager.uppdateSanPham(sp); TempData["message"] = "sua thanh tong"; return(RedirectToAction("Index")); } catch { return(RedirectToAction("Edit", sp.Masp)); } }
public ActionResult caidatthamso(FormCollection f) { try { int id = int.Parse(f["Masp"]); SanPham sp = SanPhamMager.GetSanPhamByID(id); int thamso = int.Parse(f["ThamSoN"]); if (sp.SoLuongTon < thamso) { sp.ThamSoN = thamso; SanPhamMager.uppdateSanPham(sp); return(RedirectToAction("chucnang")); } else { return(RedirectToAction("Index", "Error")); } } catch { return(RedirectToAction("Index", "Error")); } }
//Xây dựng chức năng đặt hàng public ActionResult DatHang(int?id) { if (Session["GioHang"] == null) { return(RedirectToAction("Index", "MuaHang")); } try { NhanVien nv = new NhanVien(); if (Session["USER_SESSION"] == null) { return(RedirectToAction("Index", "Home")); } else { // Thêm kh bằng session Taikhoan TaiKhoan tk = Session["USER_SESSION"] as TaiKhoan; nv = NhanVienMager.GetbyTK(tk.MaTK); } // //Thêm đơn hàng Hd ddh = new Hd(); // ddh.MaKH = id; ddh.MaNV = nv.MaNV; ddh.NgayDat = DateTime.Now; ddh.Status = "trong"; HoaDonManger.insert(ddh); KhachHang kh = KhachHangMager.GetKhachHangByID(id); // Thêm chi tiết đơn hàng List <itemGioHang> lstGioHang = LayGioHang(); foreach (var item in lstGioHang) { Cthd ctdh = new Cthd(); ctdh.MaHD = ddh.MaHD; ctdh.TenSP = item.TenSP; ctdh.MaSp = item.MaSP; ctdh.SoLuong = item.SoLuong; ctdh.DonGiaBan = item.DonGia; CTHDMager.insert(ctdh); } // tich diem decimal?tichluy = TinhTongTien() * (decimal)0.1; kh.Diemso = kh.Diemso + (int)tichluy; KhachHangMager.uppdateKhachHang(kh); // cap nhap so luong foreach (var item in lstGioHang) { SanPham sp = SanPhamMager.GetSanPhamByID(item.MaSP); sp.SoLuongTon = sp.SoLuongTon - item.SoLuong; SanPhamMager.uppdateSanPham(sp); } // gui mail //string content = System.IO.File.ReadAllText(Server.MapPath("~/Content/gmail/donhang.html")); //content = content.Replace("{{TenKH}}", kh.TenKH); //content = content.Replace("{{NgayMua}}", DateTime.Now.ToString()); //content = content.Replace("{{MaHD}}", ddh.MaHD.ToString()); //content = content.Replace("{{TenNV}}", ddh.NhanVien.TenNv.ToString()); //content = content.Replace("{{diachi}}", kh.DiaChi.ToString()); //content = content.Replace("{{Total}}", TinhTongTien().ToString("N0")); //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString(); //new Gmail().SendMail(kh.Email, "Đơn hàng mới từ asp", content); //new Gmail().SendMail(toEmail, "Đơn hàng mới từ asp", content); Session["GioHang"] = null; return(RedirectToAction("XemGioHang")); } catch { return(RedirectToAction("Index", "Error")); } }