コード例 #1
0
        public ActionResult Form(int?Id)
        {
            HTMDb db = new HTMDb();
            var   YeuCauNguoiDung           = db.YeuCauNguoiDungs.Where(x => x.DaPheDuyet == false && x.TrangThai == false).Count();
            var   YeuCauNguoiDungLenQuanTri = db.YeuCauNguoiDungs.Where(x => x.DaPheDuyet == false && x.TrangThai == true).Count();
            var   YeuCauDuyetLenPhongBan    = db.YeuCauNguoiDungs.Where(x => x.DaPheDuyet == false && x.TrangThai == false).Count();
            var   SanPhamChoNhapKho         = db.SanPhams.Where(x => x.DaXoa == false && x.DaNhapKho == true && x.DaPheDuyet == false && x.SoLuong >= 0).Count();
            var   SanPhamHetHang            = db.SanPhams.Where(x => x.DaXoa == false && x.DaNhapKho == true && x.SoLuong <= 0).Count();
            var   YeuCauDaDuyet             = db.YeuCauNguoiDungs.Where(x => x.DaPheDuyet == true && x.TrangThai == true).Count();


            ViewBag.YeuCauNguoiDung           = YeuCauNguoiDung.ToString();
            ViewBag.YeuCauNguoiDungLenQuanTri = YeuCauNguoiDungLenQuanTri.ToString();
            ViewBag.YeuCauDuyetLenPhongBan    = YeuCauDuyetLenPhongBan.ToString();
            ViewBag.SanPhamChoNhapKho         = SanPhamChoNhapKho.ToString();
            ViewBag.SanPhamHetHang            = SanPhamHetHang.ToString();
            ViewBag.YeuCauDaDuyet             = YeuCauDaDuyet.ToString();
            var sp = new Models.SanPham();

            if (Id.HasValue && Id != null)
            {
                var sanPham = new SanPhamService();
                sp = sanPham.FindByKeys(Id);
            }
            return(View(sp));
        }
コード例 #2
0
        public PartialViewResult _PheDuyetYeuCau(int?Id)
        {
            var sp = new Models.SanPham();

            if (Id.HasValue && Id != null)
            {
                var _sp = new SanPhamService();
                sp = _sp.FindByKeys(Id);
            }
            return(PartialView(sp));
        }
コード例 #3
0
        public PartialViewResult _SanPhamChiTiet(int?Id)
        {
            var sp = new Models.SanPham();

            if (Id.HasValue && Id != null)
            {
                var sanPham = new SanPhamService();
                sp = sanPham.FindByKeys(Id);
            }
            return(PartialView(sp));
        }
コード例 #4
0
        public ActionResult Form(int?Id
                                 , string TenSanPham
                                 , string MaSanPham
                                 , string TieuDe
                                 , string MoTa
                                 , double?Gia
                                 , int?SoLuong
                                 , int?TheLoadId
                                 , string ChiTiet
                                 , string[] thumbnails
                                 )
        {
            var            session = (UserLogin)Session[CommonConstants.USER_SESSION];
            SanPhamService _sp     = new SanPhamService();

            Models.SanPham sp = _sp.FindByKeys(Id);
            sp.TenSanPham = TenSanPham;
            sp.MaSanPham  = MaSanPham;
            sp.TieuDe     = TieuDe;
            sp.MaSanPham  = MoTa;
            sp.Gia        = Gia;
            sp.NguoiTao   = session.Name;
            sp.SoLuong    = SoLuong;
            sp.TheLoaiId  = TheLoadId;
            sp.ChiTiet    = ChiTiet;
            sp.DaPheDuyet = true;
            sp.TrangThai  = false;
            sp.DaNhapKho  = false;

            sp.DaXoa = false;
            if (Id.HasValue)
            {
                if (thumbnails != null && thumbnails.Length > 0)
                {
                    sp.Anh = string.Join(";", thumbnails);
                }
                sp.NguoiSua = session.Name;
                sp.NgaySua  = DateTime.Now;
                _sp.Update(sp);
                setAlert("Thông tin sản phẩm đã được cập nhập", "success");
            }
            else
            {
                if (thumbnails != null && thumbnails.Length > 0)
                {
                    sp.Anh = string.Join(";", thumbnails);
                }
                sp.NgayTao = DateTime.Now;
                _sp.Insert(sp);
                setAlert("Thêm sản phẩm thành công", "success");
            }
            return(RedirectToAction("Index"));
        }
コード例 #5
0
 public ActionResult Create(Models.SanPham createPro, HttpPostedFileBase file)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         ViewBag.pdcListCreate  = new SelectList(dbPro.ThuongHieux, "MaThuongHieu", "TenTH");
         ViewBag.typeListCreate = new SelectList(dbPro.LoaiSPs, "MaLoaiSP", "TenLoaiSP");
         var pro = dbPro.SanPhams.SingleOrDefault(c => c.MaSP.Equals(createPro.MaSP));
         if (file != null)
         {
             if (file.ContentLength > 0)
             {
                 try
                 {
                     string nameFile = Path.GetFileName(file.FileName);
                     file.SaveAs(Path.Combine(Server.MapPath("/Images"), nameFile));
                     createPro.HinhAnh = "/Images/" + nameFile;
                 }
                 catch (Exception)
                 {
                     ViewBag.CreateProError = "Không thể chọn ảnh.";
                 }
             }
             try
             {
                 if (pro != null)
                 {
                     ViewBag.CreateProError = "Mã sản phẩm đã tồn tại.";
                 }
                 else
                 {
                     aDB.ThemSanPham(createPro);
                     ViewBag.CreateProError = "Thêm sản phẩm thành công.";
                 }
             }
             catch (Exception)
             {
                 ViewBag.CreateProError = "Không thể thêm sản phẩm.";
             }
         }
         else
         {
             ViewBag.HinhAnh = "Vui lòng chọn hình ảnh.";
         }
         return(View());
     }
 }
コード例 #6
0
        private Models.SanPham GetData()
        {
            Models.SanPham sp = new Models.SanPham();
            int            id;

            if (int.TryParse(textBox2.Text, out id))
            {
                sp.SanphamID = id;
            }
            LoaiSanPham lsp = lstLoaisanpham.Items.Find(x => x.Tenloaisanpham == comboBox3.SelectedItem.ToString());
            Nhacungcap  ncc = lstNhacungcap.Items.Find(x => x.Tennhacungcap == comboBox4.SelectedItem.ToString());

            sp.LoaisanphamID = lsp.LoaisanphamID;
            sp.NhacungcapID  = ncc.NhacungcapID;
            sp.Tensanpham    = textBox4.Text;
            sp.Donvitinh     = textBox6.Text;
            sp.Giaban        = double.Parse(textBox7.Text);
            sp.Soluong       = int.Parse(textBox8.Text);
            return(sp);
        }
コード例 #7
0
 private void LoadInfo()
 {
     if (GridView_Sanpham.CurrentRow != null)
     {
         int SanphamID;
         int.TryParse(GridView_Sanpham.CurrentRow.Cells[0].Value.ToString(), out SanphamID);
         if (SanphamID > 0)
         {
             Models.SanPham sp = lstSanpham.Items.Find(x => x.SanphamID == SanphamID);
             comboBox3.SelectedIndex = comboBox3.Items.IndexOf(sp.Tenloaisanpham);
             comboBox4.SelectedIndex = comboBox4.Items.IndexOf(sp.Tennhacungcap);
             textBox4.Text           = sp.Tensanpham;
             textBox6.Text           = sp.Donvitinh;
             textBox7.Text           = sp.Giaban.ToString();
             textBox8.Text           = sp.Soluong.ToString();
             textBox2.Text           = sp.SanphamID.ToString();
             textBox8.Enabled        = false;
         }
     }
 }
コード例 #8
0
ファイル: DataHelper.cs プロジェクト: lkimlyen/webbangiay
            public List <ShoppingCardItemModel> getListShoppingCardItemModelFromListOrderDetails(Models.QLShopOnlineEntities data, List <Models.ChiTietDonDatHang> listChiTietDonDatHangs)
            {
                List <ShoppingCardItemModel> result = new List <ShoppingCardItemModel>();

                foreach (var ChiTietDonDatHang in listChiTietDonDatHangs)
                {
                    Models.SanPham        item  = ProductHelper.getInstance().getProductById(data, ChiTietDonDatHang.IdSanPham.Value);
                    ShoppingCardItemModel model = new ShoppingCardItemModel();
                    model.id       = ChiTietDonDatHang.IdSanPham.Value;
                    model.name     = item.TenSanPham;
                    model.image    = item.HinhAnh;
                    model.quantity = ChiTietDonDatHang.SoLuong.Value;
                    model.price    = item.DonGia.Value;
                    model.total    = model.price * model.quantity;
                    model.orderid  = ChiTietDonDatHang.IdDDH.HasValue ? ChiTietDonDatHang.IdDDH.Value : 0;
                    model.modelid  = ChiTietDonDatHang.IdCTDDH;
                    result.Add(model);
                }

                return(result);
            }
コード例 #9
0
 public ActionResult Edit(Models.SanPham editPro, HttpPostedFileBase file)
 {
     if (Session["accname"] == null)
     {
         Session["accname"] = null;
         return(RedirectToAction("Login", "Account"));
     }
     else
     {
         ViewBag.pdcListCreate  = new SelectList(dbPro.ThuongHieux, "MaThuongHieu", "TenTH");
         ViewBag.typeListCreate = new SelectList(dbPro.LoaiSPs, "MaLoaiSP", "TenLoaiSP");
         if (file != null)
         {
             if (file.ContentLength > 0)
             {
                 try
                 {
                     string nameFile = Path.GetFileName(file.FileName);
                     file.SaveAs(Path.Combine(Server.MapPath("/Images"), nameFile));
                     editPro.HinhAnh = "/Images/" + nameFile;
                 }
                 catch (Exception)
                 {
                     ViewBag.EditProError = "Không thể chọn ảnh.";
                 }
             }
         }
         try
         {
             aDB.SuaSanPham(editPro);
             ViewBag.EditProError = "Cập nhật sản phẩm thành công.";
         }
         catch (Exception)
         {
             ViewBag.EditProError = "Không thể cập nhật sản phẩm.";
         }
         return(View());
     }
 }
コード例 #10
0
        public ActionResult ThemVaoGio(int SanPhamID)
        {
            if (Session["giohang"] == null)                 // Nếu giỏ hàng chưa được khởi tạo
            {
                Session["giohang"] = new List <CartItem>(); // Khởi tạo Session["giohang"] là 1 List<CartItem>
            }

            List <CartItem> giohang = Session["giohang"] as List <CartItem>;  // Gán qua biến giohang dễ code

            // Kiểm tra xem sản phẩm khách đang chọn đã có trong giỏ hàng chưa

            if (giohang.FirstOrDefault(m => m.SanPhamID == SanPhamID) == null) // ko co sp nay trong gio hang
            {
                Models.SanPham sp = db.SanPhams.Find(SanPhamID);               // tim sp theo sanPhamID

                CartItem newItem = new CartItem()
                {
                    SanPhamID  = SanPhamID,
                    TenSanPham = sp.TenSP,
                    SoLuong    = 1,
                    soluongmax = (int)sp.SoLuongSP,
                    Hinh       = sp.HinhAnh,
                    DonGia     = (sp.Gia - (sp.Gia * sp.Discount) / 100)
                };                    // Tạo ra 1 CartItem mới

                giohang.Add(newItem); // Thêm CartItem vào giỏ
            }
            else
            {
                // Nếu sản phẩm khách chọn đã có trong giỏ hàng thì không thêm vào giỏ nữa mà tăng số lượng lên.
                CartItem cardItem = giohang.FirstOrDefault(m => m.SanPhamID == SanPhamID);
                cardItem.SoLuong++;
            }

            // Action này sẽ chuyển hướng về trang chi tiết sp khi khách hàng đặt vào giỏ thành công. Bạn có thể chuyển về chính trang khách hàng vừa đứng bằng lệnh return Redirect(Request.UrlReferrer.ToString()); nếu muốn.
            return(Redirect(Request.UrlReferrer.ToString()));
        }
コード例 #11
0
ファイル: DataHelper.cs プロジェクト: lkimlyen/webbangiay
 public Models.SanPham getProductById(Models.QLShopOnlineEntities data, int id)
 {
     Models.SanPham result = data.SanPhams.Where(n => n.IdSanPham == id).Single();
     return(result);
 }
コード例 #12
0
 private Models.SanPham GetData()
 {
     Models.SanPham sp = new Models.SanPham();
     int id;
     if (int.TryParse(textBox2.Text, out id))
     {
         sp.SanphamID = id;
     }
     LoaiSanPham lsp = lstLoaisanpham.Items.Find(x => x.Tenloaisanpham == comboBox3.SelectedItem.ToString());
     Nhacungcap ncc = lstNhacungcap.Items.Find(x => x.Tennhacungcap == comboBox4.SelectedItem.ToString());
     sp.LoaisanphamID = lsp.LoaisanphamID;
     sp.NhacungcapID = ncc.NhacungcapID;
     sp.Tensanpham = textBox4.Text;
     sp.Donvitinh = textBox6.Text;
     sp.Giaban = double.Parse(textBox7.Text);
     sp.Soluong = int.Parse(textBox8.Text);
     return sp;
 }