Ejemplo n.º 1
0
 // xoa
 public ActionResult Delete(int?id)
 {
     if (Ktdangnhap() == true)
     {
         return(View(HoaDonManger.GetItemById(id)));
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }
Ejemplo n.º 2
0
        public ActionResult Delete(int?id, FormCollection f)
        {
            try
            {
                HoaDonManger.delete(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Delete", id));
            }
        }
Ejemplo n.º 3
0
        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());
            }
        }
Ejemplo n.º 4
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"));
            }
        }
Ejemplo n.º 5
0
        // GET: HoaDon
        public ActionResult Index()
        {
            List <Hd> lst = HoaDonManger.getAll();

            return(View(lst));
        }