Exemplo n.º 1
0
 public ActionResult Edit(KhachHang kh)
 {
     try
     {
         TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"];
         int      id = tk.MaTK;
         NhanVien nv = NhanVienMager.GetbyTK(id);
         kh.MaNVchinhsua = nv.MaNV;
         KhachHangMager.uppdateKhachHang(kh);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(RedirectToAction("Edit", kh.MaKh));
     }
 }
Exemplo n.º 2
0
 public ActionResult Edit(DanHMuc item)
 {
     try
     {
         TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"];
         int      id = tk.MaTK;
         NhanVien nv = NhanVienMager.GetbyTK(id);
         item.MaNVchinhsua = nv.MaNV;
         DanhMucMager.uppdate(item);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(RedirectToAction("Edit", item.MaDM));
     }
 }
Exemplo n.º 3
0
        [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());
        }
Exemplo n.º 4
0
 [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));
     }
 }
Exemplo n.º 5
0
        } // h kiem tra session tai khoan  nhan vien

        public ActionResult Create()
        {
            if (Ktdangnhap() == true)
            {
                List <NhaCungCap> lstcc = NhaCungCapMager.getAll();
                ViewBag.nhaccc = lstcc;
                TaiKhoan tk = (TaiKhoan)Session["USER_SESSION"];
                int      id = tk.MaTK;
                NhanVien nv = NhanVienMager.GetbyTK(id);

                ViewBag.MaNv = nv.MaNV;
                return(View());
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 6
0
        public ActionResult Delete(int?id, FormCollection f)
        {
            try
            {
                TaiKhoan tk      = (TaiKhoan)Session["USER_SESSION"];
                int      idtk    = tk.MaTK;
                NhanVien nv      = NhanVienMager.GetbyTK(idtk);
                var      itemxoa = NhanVienMager.delete(id);
                itemxoa.MaNVchinhsua = nv.MaNV;
                itemxoa.Ngaycapnhap  = DateTime.Now;
                NhanVienMager.uppdate(itemxoa);


                return(RedirectToAction("Index"));
            }

            catch
            {
                return(RedirectToAction("Delete", id));
            }
        }
Exemplo n.º 7
0
        //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"));
            }
        }