Beispiel #1
0
        public ActionResult Create(SanPham sanpham)
        {
            if (ModelState.IsValid)
            {
                if (sanpham.ImageFile.FileName != null)
                {
                    string fileName  = Path.GetFileNameWithoutExtension(sanpham.ImageFile.FileName);
                    string extension = Path.GetExtension(sanpham.ImageFile.FileName);
                    fileName           = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                    sanpham.AnhSanPham = "~/FileUpload/" + fileName;
                    fileName           = Path.Combine(Server.MapPath("~/FileUpload/"), fileName);
                    sanpham.ImageFile.SaveAs(fileName);
                }
                using (var db = new BanHangEntity())
                {
                    db.SanPhams.Add(sanpham);
                    db.SaveChanges();
                    return(RedirectToAction("Edit", "SanPham", new { id = sanpham.SanPhamID }));
                }
            }
            else
            {
                using (var db = new BanHangEntity())
                {
                    sanpham.LoaiSanPhamCollection = db.LoaiSanPhams.ToList <LoaiSanPham>();
                    sanpham.DonViTinhCollection   = db.DonViTinhs.ToList <DonViTinh>();
                    sanpham.NhaCungCapCollection  = db.NhaCungCaps.ToList <NhaCungCap>();

                    return(View(sanpham));
                }
            }
        }
        List <SanPham> getlstSanpham()
        {
            db = new BanHangEntity();
            var lst = db.SanPhams.SqlQuery("Select * from SanPham").ToList <SanPham>();

            return(lst);
        }
        List <DonViTinh> getlstDVT()
        {
            db = new BanHangEntity();
            var lst = db.DonViTinhs.ToList();

            return(lst);
        }
Beispiel #4
0
        List <ThuocTinhSanPham> getlstThuocTinhSanPham()
        {
            db = new BanHangEntity();
            var lst = db.ThuocTinhSanPhams.SqlQuery("Select * from ThuocTinhSanPham").ToList <ThuocTinhSanPham>();

            return(lst);
        }
Beispiel #5
0
 public ActionResult Edit(LoaiSanPham dv)
 {
     if (Session["username"] == null)
     {
         return(RedirectToAction("/Index", "Users"));
     }
     else
     {
         if (ModelState.IsValid)
         {
             if (dv.ImageFile != null)
             {
                 string fileName  = Path.GetFileNameWithoutExtension(dv.ImageFile.FileName);
                 string extension = Path.GetExtension(dv.ImageFile.FileName);
                 fileName      = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                 dv.AnhDaiDien = "~/FileUpload/" + fileName;
                 fileName      = Path.Combine(Server.MapPath("~/FileUpload/"), fileName);
                 dv.ImageFile.SaveAs(fileName);
             }
             using (var db = new BanHangEntity())
             {
                 db.Entry(dv).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         return(View(dv));
     }
 }
        public ActionResult Edit(int id)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("/Index", "Users"));
            }
            else
            {
                using (var db = new BanHangEntity())
                {
                    try
                    {
                        SanPham sanPham = db.SanPhams.Include("ThuocTinhSanPhams").Include("ThuocTinhSanPhams.ThuocTinh").FirstOrDefault(x => x.SanPhamID == id);
                        sanPham.LoaiSanPhamCollection = db.LoaiSanPhams.ToList <LoaiSanPham>();
                        sanPham.DonViTinhCollection   = db.DonViTinhs.ToList <DonViTinh>();
                        sanPham.NhaCungCapCollection  = db.NhaCungCaps.ToList <NhaCungCap>();

                        return(View(sanPham));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return(new HttpStatusCodeResult(404, "Error in cloud - GetPLUInfo" + ex.Message));
                    }
                }
            }
        }
Beispiel #7
0
        public ActionResult Create(LoaiSanPham loaiSanPham)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("/Index", "Users"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    if (loaiSanPham.ImageFile != null)
                    {
                        string fileName  = Path.GetFileNameWithoutExtension(loaiSanPham.ImageFile.FileName);
                        string extension = Path.GetExtension(loaiSanPham.ImageFile.FileName);
                        fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
                        loaiSanPham.AnhDaiDien = "~/FileUpload/" + fileName;
                        fileName = Path.Combine(Server.MapPath("~/FileUpload/"), fileName);
                        loaiSanPham.ImageFile.SaveAs(fileName);
                    }

                    using (var db = new BanHangEntity())
                    {
                        db.LoaiSanPhams.Add(loaiSanPham);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                return(View(loaiSanPham));
            }
        }
        public ActionResult DeleteItem(int SanPhamID)
        {
            using (var db = new BanHangEntity())
            {
                if (Session["username"] == null)
                {
                    return(RedirectToAction("/Index", "Users"));
                }
                else
                {
                    int id = (int)Session["usernameid"];
                    //var lstSanPham = db.SanPhams.Include(x => x.ChiTietDonDatHangs).ToList();
                    var donDatHang = db.DonDatHangs.Where(x => x.TaiKhoanDatHangID == id && x.TinhTrang == 0).FirstOrDefault();
                    var chiTiet    = db.ChiTietDonDatHangs.Where(x => x.SanPhamID == SanPhamID && x.DonDatHangID == donDatHang.DonDatHangID).FirstOrDefault();
                    if (donDatHang != null)
                    {
                        donDatHang.ChiTietDonDatHangs.Remove(chiTiet);
                        db.SaveChanges();
                        int?soluong = 0;
                        foreach (var i in donDatHang.ChiTietDonDatHangs)
                        {
                            soluong = soluong + i.SoLuong;
                        }
                        Session["soluong"] = soluong;
                    }

                    return(RedirectToAction("/CartView", "Home"));
                }
            }
        }
Beispiel #9
0
        List <NhaCungCap> GetNhaCungCaps()
        {
            db = new BanHangEntity();
            var lst = db.NhaCungCaps.ToList();

            return(lst);
        }
Beispiel #10
0
        List <ThuocTinh> GetThuocTinhs()
        {
            db = new BanHangEntity();
            var lst = db.ThuocTinhs.ToList();

            return(lst);
        }
Beispiel #11
0
 public ActionResult Create(int id, int SanPhamID, int ThuocTinhID, string mota, string ghichu)
 {
     using (var db = new BanHangEntity())
     {
         if (id == 0)
         {
             ThuocTinhSanPham thuocTinhSanPham = new ThuocTinhSanPham();
             thuocTinhSanPham.SanPhamID   = SanPhamID;
             thuocTinhSanPham.ThuocTinhID = ThuocTinhID;
             thuocTinhSanPham.NoiDungMoTa = mota;
             thuocTinhSanPham.GhiChu      = ghichu;
             db.ThuocTinhSanPhams.Add(thuocTinhSanPham);
         }
         else
         {
             ThuocTinhSanPham thuocTinhSanPham = db.ThuocTinhSanPhams.Find(id);
             thuocTinhSanPham.ThuocTinhID = ThuocTinhID;
             thuocTinhSanPham.SanPhamID   = SanPhamID;
             thuocTinhSanPham.NoiDungMoTa = mota;
             thuocTinhSanPham.GhiChu      = ghichu;
         }
         db.SaveChanges();
         return(RedirectToAction("Edit", "SanPham", new { id = SanPhamID }));
     }
 }
Beispiel #12
0
        List <DonDatHang> getlstDonDatHang()
        {
            db = new BanHangEntity();
            var lst = db.DonDatHangs.OrderBy(x => x.DonDatHangID).ToList();

            return(lst);
        }
Beispiel #13
0
        List <LoaiSanPham> getlstLoaiSanPham()
        {
            db = new BanHangEntity();
            var lst = db.LoaiSanPhams.OrderBy(x => x.LoaiSanPhamID).ToList();

            return(lst);
        }
Beispiel #14
0
        List <DichVu> getlstDichVu()
        {
            db = new BanHangEntity();
            var lst = db.DichVus.OrderBy(x => x.DichVuID).ToList();

            return(lst);
        }
        // GET: Users
        List <User> getlstUser()
        {
            db = new BanHangEntity();
            var lst = db.Users.ToList();

            return(lst);
        }
 public ActionResult Create(DonDatHang donDatHang)
 {
     using (var db = new BanHangEntity())
     {
         db.DonDatHangs.Add(donDatHang);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
 public ActionResult Edit(DonDatHang donDatHang)
 {
     using (var db = new BanHangEntity())
     {
         db.Entry(donDatHang).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit(User us)
 {
     using (var db = new BanHangEntity())
     {
         db.Entry(us).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("/List"));
 }
Beispiel #19
0
 public ActionResult Edit(ThuocTinhSanPham sanPham)
 {
     using (var db = new BanHangEntity())
     {
         db.Entry(sanPham).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #20
0
        // GET: DonDatHang
        public ActionResult BangKeMuaHangHoa(string currentSFilter, string searchDateS, string currentFFilter, string searchDateF, int?option, int?sanPhamID, int?page)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("/Index", "Users"));
            }
            else
            {
                db = new BanHangEntity();
                ViewBag.lstSanPham = new SelectList(db.SanPhams, "SanPhamID", "TenSanPham", sanPhamID);
                ViewBag.sanPhamID  = sanPhamID;
                if (searchDateS != null || searchDateF != null)
                {
                    page = 1;
                }
                else
                {
                    searchDateS = currentSFilter;
                    searchDateF = currentFFilter;
                }

                ViewBag.CurrentSFilter = searchDateS;
                ViewBag.CurrentFFilter = searchDateF;

                var lstDonDatHang = getlstDonDatHang().AsQueryable().Where(x => x.TinhTrang != 0);

                if (sanPhamID.HasValue)
                {
                    lstDonDatHang = lstDonDatHang.Where(s => s.ChiTietDonDatHangs.Any(x => x.SanPhamID == sanPhamID));
                }
                if (!String.IsNullOrEmpty(searchDateS))
                {
                    lstDonDatHang = lstDonDatHang.Where(s => s.NgayDat >= Convert.ToDateTime(searchDateS));
                }
                if (!String.IsNullOrEmpty(searchDateF))
                {
                    lstDonDatHang = lstDonDatHang.Where(s => s.NgayDat <= Convert.ToDateTime(searchDateF));
                }
                if (option.HasValue)
                {
                    if (option == -1)
                    {
                        lstDonDatHang = lstDonDatHang.Where(o => o.TinhTrang != TrangThaiDonHang.CHUA_GUI && o.TinhTrang != TrangThaiDonHang.THANH_LY_HUY_HANG);
                    }
                    else
                    {
                        lstDonDatHang = lstDonDatHang.Where(o => o.TinhTrang == option);
                    }
                }

                int pageSize   = 5;
                int pageNumber = (page ?? 1);
                return(View(lstDonDatHang.ToPagedList(pageNumber, pageSize)));
            }
        }
Beispiel #21
0
 public ActionResult Create()
 {
     using (var db = new BanHangEntity())
     {
         SanPham sp = new SanPham();
         sp.LoaiSanPhamCollection = db.LoaiSanPhams.ToList <LoaiSanPham>();
         sp.DonViTinhCollection   = db.DonViTinhs.ToList <DonViTinh>();
         sp.NhaCungCapCollection  = db.NhaCungCaps.ToList <NhaCungCap>();
         return(View(sp));
     }
 }
        public FileResult ExportMau03(string searchDateS = null, string searchDateF = null, int?option = null, int?sanPhamID = null)
        {
            using (var db = new BanHangEntity())
            {
                IQueryable <DonDatHang> results = db.DonDatHangs;
                string tenHang = "";
                if (option.HasValue)
                {
                    if (option == -1)
                    {
                        results = results.Where(o => o.TinhTrang != TrangThaiDonHang.CHUA_GUI && o.TinhTrang != TrangThaiDonHang.THANH_LY_HUY_HANG);
                    }
                    else
                    {
                        results = results.Where(o => o.TinhTrang == option);
                    }
                }
                string[] strTu, strDen;
                DateTime?tu = null, den = null;

                if (!string.IsNullOrWhiteSpace(searchDateS) && searchDateS != "undefined" && searchDateS != "null")
                {
                    strTu = searchDateS.Split(' ');
                    tu    = DateTime.Parse(strTu[0]);
                    if (tu.HasValue)
                    {
                        results = results.Where(o => o.NgayDat >= tu);
                    }
                }

                if (!string.IsNullOrWhiteSpace(searchDateF) && searchDateF != "undefined" && searchDateF != "null")
                {
                    strDen = searchDateF.Split(' ');
                    den    = DateTime.Parse(strDen[0]);
                    if (den.HasValue)
                    {
                        results = results.Where(o => o.NgayDat <= den);
                    }
                }
                if (sanPhamID.HasValue)
                {
                    results = results.Where(o => o.ChiTietDonDatHangs.Any(y => y.SanPhamID == sanPhamID));
                    tenHang = db.SanPhams.Find(sanPhamID) != null?db.SanPhams.Find(sanPhamID).TenSanPham : "";
                }
                results = results.OrderBy(o => o.TinhTrang).OrderByDescending(o => o.NgayDat);
                string sWebRootFolder = HostingEnvironment.ApplicationPhysicalPath + "\\FileUpload";

                ExportMau03(results.ToList(), "Mau03", sWebRootFolder, tu, den, sanPhamID, tenHang);
                string             fPath = sWebRootFolder + "\\" + "Mau03.xlsx";
                System.IO.FileInfo fi    = new System.IO.FileInfo(fPath);
                return(File(fPath, System.Net.Mime.MediaTypeNames.Application.Octet, "Mau03" + fi.Extension));
            }
        }
Beispiel #23
0
 public ActionResult Create()
 {
     //if (Session["username"] == null)
     //    return RedirectToAction("/Index", "Users");
     //else
     //{
     using (var db = new BanHangEntity())
     {
         ThuocTinhSanPham sp = new ThuocTinhSanPham();
         return(View(sp));
     }
     //}
 }
Beispiel #24
0
 public ActionResult Create(ThuocTinh thuocTinh)
 {
     if (ModelState.IsValid)
     {
         using (var db = new BanHangEntity())
         {
             db.ThuocTinhs.Add(thuocTinh);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     return(View(thuocTinh));
 }
 public ActionResult Delete(float id)
 {
     using (var db = new BanHangEntity())
     {
         User user = db.Users.Find(id);
         if (user != null)
         {
             db.Users.Remove(user);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("/List"));
 }
Beispiel #26
0
 public ActionResult Edit(ThuocTinh thuocTinh)
 {
     if (ModelState.IsValid)
     {
         using (var db = new BanHangEntity())
         {
             db.Entry(thuocTinh).State = System.Data.Entity.EntityState.Modified;
             db.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     return(View(thuocTinh));
 }
Beispiel #27
0
 public ActionResult Delete(float id)
 {
     using (var db = new BanHangEntity())
     {
         DichVu dichVu = db.DichVus.Find(id);
         if (dichVu != null)
         {
             db.DichVus.Remove(dichVu);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("/Index"));
 }
 public ActionResult DeleteChiTietDon(int idChiTiet, int idDonHang)
 {
     using (var db = new BanHangEntity())
     {
         ChiTietDonDatHang chiTietDonDatHang = db.ChiTietDonDatHangs.Find(idChiTiet);
         if (chiTietDonDatHang != null)
         {
             db.ChiTietDonDatHangs.Remove(chiTietDonDatHang);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("/Edit/" + idDonHang));
 }
Beispiel #29
0
 public ActionResult Delete(float id)
 {
     using (var db = new BanHangEntity())
     {
         NhaCungCap nhaCungCap = db.NhaCungCaps.Find(id);
         if (nhaCungCap != null)
         {
             db.NhaCungCaps.Remove(nhaCungCap);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("/Index"));
 }
Beispiel #30
0
 public ActionResult Delete(float id)
 {
     using (var db = new BanHangEntity())
     {
         LoaiSanPham loaiSanPham = db.LoaiSanPhams.Find(id);
         if (loaiSanPham != null)
         {
             db.LoaiSanPhams.Remove(loaiSanPham);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("/Index"));
 }