Exemplo n.º 1
0
        public FmThongTinSanPham(SanPham sp = null, SanPhamController spc = null)
        {
            InitializeComponent();
            dtgvHinhAnh.AutoGenerateColumns = false;
            dtgvChiTietSanPham.AutoGenerateColumns = false;
            //set primary context
            if (spc != null) SPCtr = spc;
            else SPCtr = new SanPhamController();

            HSXCtr = new HangSXController(this.SPCtr._db);
            MSCtr = new MauSacController(this.SPCtr._db);
            HACtr = new HinhAnhController(this.SPCtr._db);
            SPCTCtr = new SanPham_ChiTietController(this.SPCtr._db);
            MSCtr.timkiem();
            LoadCb_HangSX();
            if (sp == null)
            {
                this.sp = new SanPham(SPCtr._db);
                this.Text = "Thêm Mới Sản Phẩm";
            }
            else
            {
                this.sp = sp;
                this.sp._set_context(SPCtr._db);
                EditMode = true;
                ThongTinFormSanPham = this.sp;
                LoadDTGV_HinhAnh();
                LoadDTGV_ChiTietSP();
            }
        }
 public ActionResult Index(int id=0)
 {
     HangSXController ctr_hangsx = new HangSXController();
     SanPhamController ctr = new SanPhamController();
     SanPham obj = ctr.get_by_id(id);
     if (obj == null)
     {
         return RedirectToAction("Index","FrontHome");
     }
     ViewBag.sanpham = obj;
     return View();
 }
        public ActionResult Index(int page=1)
        {
            //controller
            SanPhamController ctr=new SanPhamController();
            HangSXController ctr_hangsx = new HangSXController();
            //varibles
            int gia_from = TextLibrary.ToInt(_timkiem_sanpham["gia_from"]);
            int gia_to = TextLibrary.ToInt(_timkiem_sanpham["gia_to"]);
            Boolean order_desc = TextLibrary.ToBoolean(_timkiem_sanpham["order_desc"]);
            int max_item_per_page= TextLibrary.ToInt(_timkiem_sanpham["max_item_per_page"]);
            int hang_sx_id = TextLibrary.ToInt(_timkiem_sanpham["hangsx_id"]);
            HangSX hangsx = ctr_hangsx.get_by_id(
                hang_sx_id
            );
            //pagination
            PaginationLibrary pagination = new PaginationLibrary();
            pagination.set_current_page(page);
            pagination.set_max_item_per_page(
                max_item_per_page
            );

            pagination.set_total_item(
                ctr.timkiem_count(
                "",
                "",
                _timkiem_sanpham["ten"],
                "",
                gia_from,
                gia_to,
                hangsx,
                "1"
                )
            );
            pagination.update();
            //View data
            ViewBag.SanPham_List = ctr.timkiem(
                "",
                "",
                _timkiem_sanpham["ten"],
                "",
                gia_from,
                gia_to,
                hangsx,
                "1",
                _timkiem_sanpham["order_by"],
                order_desc,
                pagination.start_point,
                pagination.max_item_per_page
            );
            ViewBag.pagination = pagination;
            return View();
        }
 /*
  * Hiển thị danh sách sản phẩm theo hãng SX có phân trang
  * Có nút Add to Cart => redirect đến trang Sản phẩm chi tiết để chọn
  * SL và màu sắc cần đặt
  */
 public ActionResult Index(int hangsx_id=0, int page=1)
 {
     SanPhamController ctr = new SanPhamController();
     HangSXController ctr_hangsx = new HangSXController();
     HangSX hangsx = ctr_hangsx.get_by_id(hangsx_id);
     //check
     if (hangsx==null || hangsx.active==false)
     {
         return RedirectToAction("Index","FrontHome");
     }
     //pagination
     int max_item_per_page=4;//will get from setting
     //pagination
         PaginationLibrary pg = new PaginationLibrary();
         pg.set_current_page(page);
         pg.set_max_item_per_page(max_item_per_page);
         pg.set_total_item(
             ctr.timkiem_count(
             "",
             "",
             "",
             "",
             0,
             0,
             hangsx,
             "1")
         );
     pg.update();
     ViewBag.SanPham_List = ctr.timkiem(
         "",
         "",
         "",
         "",
         -1,
         -1,
         hangsx,
         "1",
         _timkiem_sanpham["order_by"],
         TextLibrary.ToBoolean(_timkiem_sanpham["order_desc"])
         ,pg.start_point,
         max_item_per_page);
     ViewBag.pagination = pg;
     ViewBag.hangsx = hangsx;
     return View();
 }
Exemplo n.º 5
0
 public SanPham()
 {
     _ctr = new SanPhamController();
     this._Init();
 }
Exemplo n.º 6
0
 public SanPham(DTDDDbContext context)
 {
     _ctr = new SanPhamController(context);
     this._Init();
 }
Exemplo n.º 7
0
 public Boolean set_default(int id)
 {
     //get hinhanh obj
     HinhAnh obj = this.get_by_id(id);
     if (obj == null || obj.sanpham == null)
     {
         return false;
     }
     //get sanpham obj
     SanPhamController ctr_sanpham=new SanPhamController(this._db);
     SanPham sanpham = ctr_sanpham.get_by_id(obj.sanpham.id);
     //get all hinhanh belong to this sanpham
     List<HinhAnh> hinhanh_list = this._db.ds_hinhanh.Where(x => x.sanpham.id == sanpham.id).ToList();
     //set all to non-default
     foreach (HinhAnh item in hinhanh_list)
     {
         item.macdinh = false;
         //set to default
         if (item.id == obj.id)
         {
             item.macdinh = true;
         }
     }
     this._db.SaveChanges();
     return true;
 }