Example #1
0
        public void HienthiSPTheoMa()
        {
            ThongTinSanPham sp = new ThongTinSanPham();

            sp.MaSanPham = int.Parse(Request.QueryString.Get("MaSanPham"));
            XulyLayThongTinSanPhamByID SanphamID = new XulyLayThongTinSanPhamByID();

            SanphamID.thongtinsanpham.MaSanPham = sp.MaSanPham;
            try
            {
                SanphamID.Thucthi();

                DropdownMaNSX.SelectedIndex      = DropdownMaNSX.Items.IndexOf(DropdownMaNSX.Items.FindByText(SanphamID.thongtinsanpham.Nhasx.TenNSX));
                DropdownPhongCach.SelectedIndex  = DropdownPhongCach.Items.IndexOf(DropdownPhongCach.Items.FindByText(SanphamID.thongtinsanpham.Phongcach.TenPhongCach));
                DropdownMaKieuDang.SelectedIndex = DropdownMaKieuDang.Items.IndexOf(DropdownMaKieuDang.Items.FindByText(SanphamID.thongtinsanpham.Kieudang.TenKieuDang));
                txtTenSanPham.Text  = SanphamID.thongtinsanpham.TenSanPham;
                txtMoTaSanPham.Text = SanphamID.thongtinsanpham.MoTa;
                txtGiaSanPham.Text  = SanphamID.thongtinsanpham.GiaSanPham.ToString();
                txtSoLuong.Text     = SanphamID.thongtinsanpham.SoLuong.ToString();
                txtHDH.Text         = SanphamID.thongtinsanpham.TenHDH;
                txtRAM.Text         = SanphamID.thongtinsanpham.RAM;
                txtCamera.Text      = SanphamID.thongtinsanpham.Camera;
                txtPin.Text         = SanphamID.thongtinsanpham.Pin.ToString();
                Label1.Text         = SanphamID.thongtinsanpham.ImageSP;
                image1.ImageUrl     = SanphamID.thongtinsanpham.ImageSP;
            }
            catch
            { lbThongbao.Text = "Lỗi! không lấy được DL"; }
        }
Example #2
0
        protected void btnThem_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                XulyThemSanPhamMoi themsanpham = new XulyThemSanPhamMoi();
                ThongTinSanPham    ttsanpham   = new ThongTinSanPham();
                string             linkimage   = this.Laylink_file_image();

                ttsanpham.MaNSX       = DropdownMaNSX.SelectedItem.Value;
                ttsanpham.MaKieuDang  = DropdownMaKieuDang.SelectedItem.Value;
                ttsanpham.MaPhongCach = DropdownPhongCach.SelectedItem.Value;

                ttsanpham.TenSanPham  = txtTenSanPham.Text;
                ttsanpham.MoTa        = txtMoTaSanPham.Text;
                ttsanpham.GiaSanPham  = Convert.ToInt32(txtGiaSanPham.Text);
                ttsanpham.SoLuong     = Convert.ToInt32(txtSoLuong.Text);
                ttsanpham.TenHDH      = DropDownList1.SelectedItem.Value;
                ttsanpham.RAM         = txtRAM.Text;
                ttsanpham.Camera      = txtCamera.Text;
                ttsanpham.Pin         = Convert.ToInt32(txtPin.Text);
                ttsanpham.ImageSP     = linkimage.ToString();
                themsanpham.ttsanpham = ttsanpham;

                themsanpham.Thucthi();
                txtTenSanPham.Focus();

                // lbThongbao.Text = "Không thêm được";
            }
        }
        //Nhận số giỏ hàng
        public async Task <IActionResult> Index()
        {
            List <int> lstShoppingCart = HttpContext.Session.Get <List <int> >("ssShopppingCart");

            if (lstShoppingCart.Count > 0)
            {
                foreach (int cartItem in lstShoppingCart)
                {
                    ThongTinSanPham thongTinSanPham = _db.ThongTinSanPham.Include(p => p.HangSanXuat).Include(p => p.ThongTinLoaiSanPham).Where(p => p.Id == cartItem).FirstOrDefault();
                    ShopppingCartVM.ThongTinSanPhams.Add(thongTinSanPham);
                }
            }

            return(View(ShopppingCartVM));
        }
Example #4
0
        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                ThongTinSanPham        ttsanpham = new ThongTinSanPham();
                XulySuaThongTinSanPham editSp    = new XulySuaThongTinSanPham();
                string linkimage = this.Laylink_file_image();

                ttsanpham.MaSanPham = int.Parse(Request.QueryString.Get("MaSanPham"));

                ttsanpham.MaNSX       = DropdownMaNSX.SelectedItem.Value;
                ttsanpham.MaKieuDang  = DropdownMaKieuDang.SelectedItem.Value;
                ttsanpham.MaPhongCach = DropdownPhongCach.SelectedItem.Value;

                ttsanpham.TenSanPham = txtTenSanPham.Text;
                ttsanpham.MoTa       = txtMoTaSanPham.Text;
                ttsanpham.GiaSanPham = Convert.ToInt32(txtGiaSanPham.Text);
                ttsanpham.SoLuong    = Convert.ToInt32(txtSoLuong.Text);
                ttsanpham.TenHDH     = txtHDH.Text;
                ttsanpham.RAM        = txtRAM.Text;
                ttsanpham.Camera     = txtCamera.Text;
                ttsanpham.Pin        = Convert.ToInt32(txtPin.Text);
                ttsanpham.ImageSP    = Label1.Text;
                if (FileUpload1.HasFile == true)
                {
                    ttsanpham.ImageSP = this.Laylink_file_image();
                }

                editSp.Thongtinsanpham = ttsanpham;
                try
                {
                    editSp.Thucthi();

                    lbThongbao.Text = "sửa sảnh phẩm thành công";
                }
                catch
                {
                    lbThongbao.Text = "Không sửa được";
                }
            }
        }
Example #5
0
        public string AddProduct(ProductDto product, string type)
        {
            try
            {
                using (var dbContext = new XeNangEntities())
                {
                    var checkIfExists = (from p in dbContext.SanPhams
                                         where p.Ten.ToUpper().Equals(product.Ten.ToUpper())
                                         select p.ID).Count();

                    if (checkIfExists > 0)
                    {
                        return(Constant.MESSAGE_ERROR);
                    }
                    var getCount = (from p in dbContext.SanPhams select p.ID).Count();
                    int ID       = getCount + 1;
                    dbContext.SanPhams.Add(new SanPham()
                    {
                        Loai = type,
                        Ten  = product.Ten,
                        ID   = ID
                    });

                    ThongTinSanPham productInfomation = new ThongTinSanPham()
                    {
                        Hieu      = product.Hieu,
                        Doi       = product.Doi,
                        Hang      = product.Hang,
                        MoTa      = product.MoTa,
                        TinhTrang = product.TinhTrang,
                        PhanLoai  = product.PhanLoai,
                        Image1    = product.Image1,
                        ID        = ID
                    };
                    if (product.Image2 != null)
                    {
                        productInfomation.Image2 = product.Image2;
                    }
                    if (product.Image3 != null)
                    {
                        productInfomation.Image3 = product.Image3;
                    }
                    if (product.Image4 != null)
                    {
                        productInfomation.Image4 = product.Image4;
                    }
                    if (product.Image5 != null)
                    {
                        productInfomation.Image5 = product.Image5;
                    }
                    dbContext.ThongTinSanPhams.Add(productInfomation);

                    dbContext.SaveChanges();
                    return(Constant.MESSAGE_SUCCESS);
                }
            }
            // CATCH EXEPTION FOR DEBUG PURPOSE
            catch (DbEntityValidationException ex)
            {
                foreach (var e in ex.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      e.Entry.Entity.GetType().Name, e.Entry.State);
                    foreach (var ve in e.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }

                return(Constant.MESSAGE_ERROR);
            }
            catch (DbUpdateException ex)
            {
                return(Constant.MESSAGE_ERROR);
            }
        }