예제 #1
0
        public ActionResult ThemGioHang(long idSach)
        {
            var db = new HoaDonDAO();

            if (Session["TaiKhoan"] == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            else
            {
                KhachHang kh      = Session["TaiKhoan"] as KhachHang;
                HoaDon    hd      = db.FindHD(kh.IdKhachHang);
                var       CTHDDAO = new CTHDDAO();
                if (hd == null)
                {
                    HoaDon newHD = db.InsertHD(kh.IdKhachHang, DateTime.Today, "Chưa Thanh Toán", "Chưa Giao Hàng");
                    CTHDDAO.InsertCTHD(newHD.IdHoaDon, idSach);
                    Session["ListCTHD"] = CTHDDAO.GetList(newHD.IdHoaDon);
                    ViewBag.Them        = "Thêm vào giỏ hàng thành công";
                    return(View("Index"));
                }
                else
                {
                    int pb = 0;
                    int rs;
                    foreach (var item in CTHDDAO.GetList(hd.IdHoaDon))
                    {
                        if (item.IdSach == idSach)
                        {
                            rs = CTHDDAO.UpdateCTHD(hd.IdHoaDon, idSach);
                            if (rs == 1)
                            {
                                ViewBag.SL          = "Sách bạn muốn thêm giỏ hàng đã đạt giới hạn";
                                Session["ListCTHD"] = CTHDDAO.GetList(hd.IdHoaDon);
                                return(View("Index"));
                            }
                            else if (rs == 2)
                            {
                                ViewBag.SL          = "Sách tồn kho không đáp ứng được nhu cầu của bạn";
                                Session["ListCTHD"] = CTHDDAO.GetList(hd.IdHoaDon);
                                return(View("Index"));
                            }
                            else
                            {
                                pb = 1;
                                break;
                            }
                        }
                    }
                    if (pb == 0)
                    {
                        CTHDDAO.InsertCTHD(hd.IdHoaDon, idSach);
                    }
                    Session["ListCTHD"] = CTHDDAO.GetList(hd.IdHoaDon);
                    ViewBag.Them        = "Thêm vào giỏ hàng thành công";
                    return(View("Index"));
                }
            }
        }
        public ActionResult DeleteCTHD(long idCTHD)
        {
            CTHDDAO db = new CTHDDAO();

            db.DeleteCTHD(idCTHD);
            ViewBag.GioHang     = "Xóa thành công";
            Session["ListCTHD"] = db.GetList(idHD);
            return(View("Index"));
        }
        public ActionResult UpdateSL(long idCTHD, int sl)
        {
            CTHDDAO db = new CTHDDAO();
            int     rs = db.UpdateCTHD_GioHang(idCTHD, sl);

            if (rs == 1)
            {
                ViewBag.GioHang = "Số lượng chỉ <= 3";
            }
            else if (rs == 2)
            {
                ViewBag.GioHang = "Số lượng tồn kho không đủ cho nhu cầu của bạn";
            }
            else
            {
                ViewBag.GioHang = "Cập nhật thành công";
            }
            Session["ListCTHD"] = db.GetList(idHD);
            return(View("Index"));
        }
 // GET: GioHang
 public ActionResult Index()
 {
     if (Session["TaiKhoan"] == null)
     {
         return(RedirectToAction("Index", "Login"));
     }
     else
     {
         var       db      = new HoaDonDAO();
         KhachHang kh      = Session["TaiKhoan"] as KhachHang;
         HoaDon    hd      = db.FindHD(kh.IdKhachHang);
         var       CTHDDAO = new CTHDDAO();
         if (hd != null)
         {
             idHD = hd.IdHoaDon;
             Session["ListCTHD"] = CTHDDAO.GetList(hd.IdHoaDon);
         }
         return(View("Index"));
     }
 }
예제 #5
0
 // GET: CTHDHome
 public ActionResult Index(long?idHD)
 {
     if (Session["TaiKhoan"] == null)
     {
         return(View("../Login/Index"));
     }
     else
     {
         if (idHD == null)
         {
             return(View("../Home/Index"));
         }
         var cthd = new CTHDDAO();
         var db   = new ToyContext();
         Session["HDHome"] = db.HoaDon.Find(idHD);
         long id = Convert.ToInt64(idHD);
         Session["ListCTHDHome"] = cthd.GetList(id);
         return(View("Index"));
     }
 }
        public ActionResult ChiTietHoaDon(long idHD)
        {
            var tk = Session["TaiKhoan"] as KhachHang;

            if (tk == null)
            {
                return(View("../Login/Index"));
            }
            else
            {
                if (tk.LoaiTK != "Admin")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    var cthd = new CTHDDAO();
                    Session["IdHD"]         = idHD.ToString();
                    Session["ListCTHoaDon"] = cthd.GetList(idHD);
                    return(RedirectToAction("Index", "CTHD", new { area = "Admin" }));
                }
            }
        }
        public ActionResult XuatExcel(long idHD)
        {
            var tk = Session["TaiKhoan"] as KhachHang;

            if (tk == null)
            {
                return(View("../Login/Index"));
            }
            else
            {
                if (tk.LoaiTK != "Admin")
                {
                    return(View("../Home/Index"));
                }
                else
                {
                    var db   = new ToyContext();
                    var cthd = new CTHDDAO();
                    var list = cthd.GetList(idHD);
                    try
                    {
                        string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

                        Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                        Microsoft.Office.Interop.Excel.Workbook    wb    = excel.Workbooks.Add(XlSheetType.xlWorksheet);
                        Microsoft.Office.Interop.Excel.Worksheet   ws    = (Microsoft.Office.Interop.Excel.Worksheet)excel.ActiveSheet;
                        excel.Visible = false;
                        int index   = 2;
                        int process = list.Count;

                        ws.Cells[1, 1] = "Mã Sách";
                        ws.Cells[1, 2] = "Tên Sách";
                        ws.Cells[1, 3] = "Đơn Giá";
                        ws.Cells[1, 4] = "Số Lượng";
                        ws.Cells[1, 5] = "Thành Tiền";
                        double TongTien = 0;
                        foreach (var sinhVien in list)
                        {
                            idHD = sinhVien.IdHoaDon;
                            ws.Cells[index, 1] = sinhVien.IdSach;
                            ws.Cells[index, 2] = sinhVien.Sach.Ten;
                            ws.Cells[index, 3] = sinhVien.Sach.Gia;
                            ws.Cells[index, 4] = sinhVien.SoLuong;
                            ws.Cells[index, 5] = sinhVien.ThanhTien;
                            TongTien           = TongTien + sinhVien.ThanhTien;
                            index += 1;
                        }
                        ws.Cells[index, 4] = "Tổng Tiền";
                        ws.Cells[index, 5] = TongTien;
                        ws.SaveAs(@path + "/HoaDonAdmin" + idHD + ".xlsx",
                                  XlFileFormat.xlWorkbookDefault,
                                  Type.Missing,
                                  Type.Missing,
                                  true, false,
                                  XlSaveAsAccessMode.xlNoChange,
                                  XlSaveConflictResolution.xlLocalSessionChanges,
                                  Type.Missing,
                                  Type.Missing);
                        excel.Quit();
                    }
                    catch (Exception ex) { }
                    return(RedirectToAction("Reset", "HoaDon", new { area = "Admin" }));
                }
            }
        }