示例#1
0
        public static bool remove(LoaiSanPham loaisanPham)
        {
            try
            {
                LoaiSanPham temp = find(loaisanPham.maLoaiSanPham);
                if (temp != null)
                {
                    if (temp.trangThai == 0)
                    {
                        temp.trangThai = 1;

                        quanLyQuanCoffee.SaveChanges();
                    }
                    else
                    {
                        temp.trangThai = 0;
                        quanLyQuanCoffee.SaveChanges();
                    }
                }
            }
            catch (DbUpdateException)
            {
                MessageBox.Show("Lỗi! không thể lưu dữ liệu");
                return(false);
            }
            catch (DbEntityValidationException)
            {
                MessageBox.Show("Lỗi! kiểu dữ liệu");
                return(false);
            }
            return(true);
        }
        public bool Delete(int id)
        {
            LoaiSanPham loaiSanPham = db.LoaiSanPhams.Find(id);

            if (loaiSanPham != null)
            {
                bool sp = db.SanPhams.Any(n => n.MaLSP == id);
                if (sp == true)
                {
                    TempData["Message"] = "Xóa không thành công vì vẫn tồn tại sản phẩm thuộc loại này";
                    TempData["Type"]    = "error";
                    return(false);
                }
                db.LoaiSanPhams.Remove(loaiSanPham);
                db.SaveChanges();
                TempData["Message"] = "Xóa loại sản phẩm thành công";
                TempData["Type"]    = "success";
                return(true);
            }
            else
            {
                TempData["Message"] = "Xóa loại sản phẩm không thành công";
                TempData["Type"]    = "error";
                return(false);
            }
        }
示例#3
0
        public static void UpdateLSP(string id, LoaiSanPham lsp)
        {
            var db = new ConnectDBShopDB();

            // Lỗi cái chỗ update
            db.Update(lsp, id);
        }
示例#4
0
 public ActionResult EditAction(LoaiSanPham lsp, string gt)
 {
     lsp.gioitinh        = gt;
     db.Entry(lsp).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#5
0
 public List <LoaiSanPham> HienThiDanhSachLoaiSanPhamTheoMa(string MaLoaiSanPham)
 {
     try
     {
         List <LoaiSanPham> DanhSachLSP = new List <LoaiSanPham>();
         OpenDataBase();
         SqlCommand sqlCommand = new SqlCommand();
         sqlCommand.CommandType = CommandType.StoredProcedure;
         sqlCommand.CommandText = "HienThiDanhSachLoaiSanPhamTheoMa";
         sqlCommand.Connection  = sqlConnection;
         sqlCommand.Parameters.Add("@MaLoaiSanPham", SqlDbType.NVarChar).Value = MaLoaiSanPham;
         SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
         while (sqlDataReader.Read())
         {
             LoaiSanPham loaiSanPham = new LoaiSanPham()
             {
                 MaLoaiSanPham  = sqlDataReader[0] + "",
                 TenLoaiSanPham = sqlDataReader[1] + "",
                 DonViTinh      = sqlDataReader[2] + "",
                 GhiChu         = sqlDataReader[3] + ""
             };
             DanhSachLSP.Add(loaiSanPham);
         }
         CloseDataBase();
         return(DanhSachLSP);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#6
0
        public bool InserLoaiSanPham(LoaiSanPham lsp)
        {
            var result = loaiSanPhamDAL.sp_Insert_LOAISP(lsp.TenLoai, lsp.Dvt);

            loaiSanPhamDAL.SubmitChanges();
            return(true);
        }
示例#7
0
        public bool DeleteLoaiSanPham(LoaiSanPham lsp)
        {
            var result = loaiSanPhamDAL.sp_DELETE_LOAISP(lsp.MaLoai);

            loaiSanPhamDAL.SubmitChanges();
            return(true);
        }
        //Delete Loại Sản Phẩm
        public bool DeleteLoaiSanPham(LoaiSanPham lsp)
        {
            bool isCheck = false;

            try
            {
                OpenConnection();
                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.CommandText = "sp_DELETE_LOAISP";
                sqlCommand.Connection  = conn;

                sqlCommand.Parameters.Add("@MALOAI", SqlDbType.Int).Value = lsp.MaLoai;

                int result = sqlCommand.ExecuteNonQuery();

                if (result > 0)
                {
                    isCheck = true;
                }

                return(isCheck);
            }
            catch
            {
                throw;
            }
            finally
            {
                CloseConnection();
            }
        }
示例#9
0
        public ActionResult AddCategory(LoaiSanPham model)
        {
            //kiểm tra dữ liệu hợp lệ
            if (ModelState.IsValid)
            {
                //khởi tao biến admin trong hidohieu.Models.Process
                var admin = new AdminProcess();

                //khởi tạo biến thuộc đối tượng thể loại trong db
                var tl = new LoaiSanPham();

                //gán thuộc tính tên thể loại
                tl.TenLoai = model.TenLoai;

                //gọi hàm thêm thể loại (InsertCategory) trong biến admin
                var result = admin.InsertCategory(tl);

                //kiểm tra hàm
                if (result > 0)
                {
                    ViewBag.Success = "Thêm mới thành công";
                    //xóa trạng thái
                    ModelState.Clear();

                    return(View());
                }
                else
                {
                    ModelState.AddModelError("", "Thêm không thành công.");
                }
            }

            return(View(model));
        }
        public ActionResult List(LoaiSanPhamSearchModel searchModel)
        {
            var pagedList = LoaiSanPham.Search(searchModel.Tendanhmuc, searchModel.PageIndex);

            pagedList.SearchModel = searchModel;
            return(PartialView("_List", pagedList));
        }
        public ActionResult CreateEdit(PRODUCT_TYPE model)
        {
            if (model.ID == 0)
            {
                var result = LoaiSanPham.Create(model);
                return

                    (Json(
                         new RedirectCommand()
                {
                    Code = result.Code, Message = result.Message, Url = Url.Action("Index", new { id = model.ID })
                },
                         JsonRequestBehavior.AllowGet));
            }
            else
            {
                var result = LoaiSanPham.Edit(model);
                return
                    (Json(
                         new RedirectCommand()
                {
                    Code = result.Code, Message = result.Message, Url = Url.Action("Index", new { id = model.ID })
                },
                         JsonRequestBehavior.AllowGet));
            }
        }
示例#12
0
 public ActionResult ChinhSua(LoaiSanPham loaisanpham)
 {
     db.LoaiSanPhams.Add(loaisanpham);
     db.Entry(loaisanpham).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#13
0
        public ActionResult itemCategoryEdit(FormCollection form, HttpPostedFileBase fileUpload)
        {
            var id = form["id"];

            if (id == null)
            {
                return(itemCategoryCreate(form, fileUpload));
            }
            else
            {
                LoaiSanPham tic    = getOneItemCategory(Int32.Parse(id));
                var         name   = form["name"];
                var         info   = form["info"];
                var         bidanh = form["bidanh"];
                bool        err    = false;
                if (String.IsNullOrEmpty(name))
                {
                    err = true;
                    ViewData["Error"] += "Vui lòng nhập tên danh mục!\n";
                }
                tic.TenLoai  = name;
                tic.ThongTin = info;
                tic.BiDanh   = bidanh;
                if (err == false)
                {
                    UpdateModel(tic);
                    data.SaveChanges();
                    return(RedirectToAction("itemCategoryView"));
                }
                else
                {
                    return(View(URLHelper.URL_ADMIN_ITEM_CATEGORY_M, tic));
                }
            }
        }
示例#14
0
        public ActionResult Sua_Get(int id)
        {
            LoaiSanPhamContext loaiSanPhamContext = new LoaiSanPhamContext();
            LoaiSanPham        loaisanpham        = loaiSanPhamContext.LoaiSanPham.Single(lsp => lsp.MaLoaiSP == id);

            return(View(loaisanpham));
        }
示例#15
0
        public List <LoaiSanPham> GetCategory()
        {
            List <LoaiSanPham> CateList         = new List <LoaiSanPham>();
            string             connectionString = Configuration["ConnectionStrings:DefaultConnection"];

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand("LayDSLoaiHang", connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }

                    SqlDataAdapter da = new SqlDataAdapter(command);
                    DataSet        ds = new DataSet();
                    da.Fill(ds);

                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        LoaiSanPham loaiSP = new LoaiSanPham();
                        loaiSP.CateID   = Convert.ToInt32(ds.Tables[0].Rows[i]["maloai"]);
                        loaiSP.CateName = ds.Tables[0].Rows[i]["tenloai"].ToString();
                        CateList.Add(loaiSP);
                    }
                }
            }
            return(CateList);
        }
示例#16
0
        public HttpResponseMessage KhoaMo(HttpRequestMessage request, int id)
        {
            LoaiSanPham modelLoaiSanPham = null;

            try
            {
                _loaiSanPhamService.KhoaMo(id);
                _loaiSanPhamService.SaveChange();
                modelLoaiSanPham = _loaiSanPhamService.GetById(id);
                if (modelLoaiSanPham != null)
                {
                    if (modelLoaiSanPham.TrangThai != null && (bool)modelLoaiSanPham.TrangThai)
                    {
                        Message = "Mở loại sản phẩm thành công";
                    }
                    else
                    {
                        Message = "Khóa loại sản phẩm thành công";
                    }
                }
                else
                {
                    throw new DbEntityValidationException("Khóa mở loại sản phẩm không thành công");
                }
            }
            catch (DbEntityValidationException ex)
            {
                LogException(ex);
            }
            return(GetResponseMessage(IsSuccess, Message, 1, modelLoaiSanPham));
        }
        public void DeleteLoaiSPDAO(int id)
        {
            LoaiSanPham loai = db.LoaiSanPham.Find(id);

            db.LoaiSanPham.Remove(loai);
            db.SaveChanges();
        }
        // GET: Admin/LoaiSanPham/Details/5
        public IActionResult Details(int?id)
        {
            //if (id == null)
            //{
            //    return NotFound();
            //}

            //var loaiSanPham = await _context.LoaiSanPhams
            //    .FirstOrDefaultAsync(m => m.MaLoaiSP == id);
            //if (loaiSanPham == null)
            //{
            //    return NotFound();
            //}

            //return View(loaiSanPham);
            LoaiSanPham    category = _context.LoaiSanPhams.FirstOrDefault(p => p.MaLoaiSP == id);
            var            item     = _context.Sanphams.Where(p => p.MaLoaiSP == id).ToList();
            List <SanPham> products = new List <SanPham>();

            foreach (var item2 in item)
            {
                SanPham product = _context.Sanphams.FirstOrDefault(p => p.MaSP == item2.MaSP);
                products.Add(product);
            }
            ViewBag.Category = products.ToList();
            return(View(category));
        }
示例#19
0
        public bool EditLoaiSanPham(LoaiSanPham lsp)
        {
            var result = loaiSanPhamDAL.sp_UPDATE_LOAISP(lsp.TenLoai, lsp.Dvt.Trim(), lsp.MaLoai);

            loaiSanPhamDAL.SubmitChanges();
            return(true);
        }
示例#20
0
        public ActionResult ShowWithNSX(int?MaNSX, int?MaLoaiSP, int?page)
        {
            IEnumerable <SanPham> ListProduct;
            NhaSanXuat            sp  = DB.NhaSanXuats.Single(p => p.MaNSX == MaNSX);
            LoaiSanPham           lsp = DB.LoaiSanPhams.SingleOrDefault(p => p.MaLoaiSP == MaLoaiSP);

            if (MaLoaiSP.HasValue)
            {
                ListProduct = DB.SanPhams.Where(p => p.SoLuongTon > 0 && p.DaXoa != true && p.MaNSX == MaNSX && p.MaLoaiSP == MaLoaiSP)
                              .OrderByDescending(p => p.NgayCapNhap)
                              .ToList();

                ViewBag.Title = "Sản phẩm " + lsp.TenLoai + " của nhà sản xuất : " + sp.TenNSX;
            }
            else
            {
                ListProduct = DB.SanPhams.Where(p => p.SoLuongTon > 0 && p.DaXoa != true && p.MaNSX == MaNSX)
                              .OrderByDescending(p => p.NgayCapNhap)
                              .ToList();

                ViewBag.Title = "Nhà sản xuất : " + sp.TenNSX;
            }
            ViewBag.MaLoaiSP = MaLoaiSP;
            ViewBag.MaNSX    = MaNSX;
            int pageNumber = (page ?? 1);

            return(View(ListProduct.ToPagedList(pageNumber, pagasize)));
        }
示例#21
0
 public ActionResult CreateAction(LoaiSanPham lsp, string gt)
 {
     lsp.gioitinh = gt;
     db.LoaiSanPhams.Add(lsp);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#22
0
 public static void UpdateProductType(LoaiSanPham lsp)
 {
     using (var db = new ShopConnectionDB())
     {
         db.Update <LoaiSanPham>("SET TenLoaiSanPham=@0 WHERE MaLoaiSanPham=@1", lsp.TenLoaiSanPham, lsp.MaLoaiSanPham);
     }
 }
        public async Task <IActionResult> Edit(int id, [Bind("ID,TenLoaiSPCoDau,TenLoaiSPKhongDau")] LoaiSanPham loaiSanPham)
        {
            if (id != loaiSanPham.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(loaiSanPham);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoaiSanPhamExists(loaiSanPham.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(loaiSanPham));
        }
示例#24
0
 private void btnSuaLoaiSP_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (a == null)
         {
             MessageBox.Show("Vui lòng chọn Loại sản phẩm cần sửa");
         }
         else
         {
             LoaiSanPham b = new LoaiSanPham();
             b.maLoaiSanPham = txtmaLoai.Text;
             b.tenLoai       = txttenLoai.Text;
             b.trangThai     = 0;
             if (CLoaiSanPham_BUS.KTRong(b))
             {
                 if (CLoaiSanPham_BUS.edit(b))
                 {
                     MessageBox.Show("Sửa thành công");
                     HienThiDSLoaiSanPham();
                     load();
                 }
             }
             else
             {
                 MessageBox.Show("Yêu cầu nhập đầy đủ thông tin sản phẩm");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Có lỗi: " + ex.Message);
     }
     HienThiDSLoaiSanPham();
 }
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(textBoxID.Text))
            {
                MessageBox.Show("Xin nhập loại sản phẩm mới, bấm nút Nhập lại để xoá các field.");
                return;
            }
            else
            {
                using (CuaHangTienLoiDbContext dbCxt = new CuaHangTienLoiDbContext(ClassKetnoi.contextOptions))
                {
                    Repository <LoaiSanPham> loaiSpRepo = new Repository <LoaiSanPham>(dbCxt);

                    LoaiSanPham lspMoi = new LoaiSanPham
                    {
                        Id             = Guid.NewGuid(),
                        TenLoaiSanPham = textBoxTenLoai.Text
                    };

                    loaiSpRepo.Insert(lspMoi);

                    MessageBox.Show("Thêm loại sản phẩm xong.");
                }
                RefreshGridView();
            }
        }
 // GET: Administrator/LoaiSanPhams/Delete/5
 public ActionResult Delete(int[] idLoai)
 {
     foreach (var i in idLoai)
     {
         LoaiSanPham lsp  = db.LoaiSanPhams.Find(i);
         var         dssp = db.Sanphams.Where(s => s.IdLoai == i).ToList();
         if (dssp.Count > 0)
         {
             foreach (var sp in dssp)
             {
                 db.Sanphams.Remove(sp);
             }
             db.SaveChanges();
         }
         db.LoaiSanPhams.Remove(lsp);
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
     //if (id == null)
     //{
     //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     //}
     //LoaiSanPham loaiSanPham = db.LoaiSanPhams.Find(id);
     //if (loaiSanPham == null)
     //{
     //    return HttpNotFound();
     //}
     //return View(loaiSanPham);
 }
 private void btn_Xoa_Click(object sender, EventArgs e)
 {
     if (txt_TenLoai.Text != null && txt_ThuongHieu.Text != null && txt_SoLuong.Text != null && cb_ChucVu.SelectedValue.ToString() != null)
     {
         string TenLoai = txt_TenLoai.Text;
         int    SoLuong;
         string ThuongHieu = txt_ThuongHieu.Text;
         int    malohang   = int.Parse(cb_ChucVu.SelectedValue.ToString());
         try
         {
             SoLuong = int.Parse(txt_SoLuong.Text);
             LoaiSanPham a = new LoaiSanPham();
             a.TenLoai    = TenLoai;
             a.SoLuong    = SoLuong;
             a.MaLoHang   = malohang;
             a.ThuongHieu = ThuongHieu;
             LoaiSanPhamModels.LoaiSP.ThemLoai(a);
         }
         catch (Exception)
         {
             MessageBox.Show("Số lượng không được để kí tự ");
         }
     }
     else
     {
         MessageBox.Show("Chưa điền đủ thông tin");
     }
 }
示例#28
0
        public ActionResult DanhMucSanPhamPartial()
        {
            LoaiSanPham lsp = new LoaiSanPham();

            ViewBag.lstLoaiSP = db.LoaiSanPhams;
            return(View(lsp));
        }
示例#29
0
        private void btnCapnhat_Click(object sender, EventArgs e)
        {
            string maloaisp   = txtMaLoaisp.Text;
            string tenloaisp  = txtTenLoaisp.Text;
            string motaloaisp = txtMotaLoaiSP.Text;

            if (maloaisp.Equals("") || tenloaisp.Equals("") || motaloaisp.Equals(""))
            {
                MessageBox.Show("Không được bỏ trống trường nào !!");
            }
            else
            {
                LoaiSanPham loaiSanPham = new LoaiSanPham(maloaisp, tenloaisp, motaloaisp);
                LoaiSanPham lsptimdc    = lspDao.CheckLoaiSP(loaiSanPham.MaLoaiSP);
                if (lsptimdc == null)
                {
                    MessageBox.Show("Không tồn tại loại sản phẩm mã " + loaiSanPham.MaLoaiSP);
                }
                else
                {
                    lspDao.UpdateLoaisp(loaiSanPham);
                    displayLoaiSP(dgvLoaiSP, lspDao.getAllLoaiSP());
                    clearAllField();
                    MessageBox.Show("Đã cập nhật thông tin loại sản phẩm " + loaiSanPham.TenLoaiSP);
                    if (isClose)
                    {
                        this.Close();
                    }
                }
            }
        }
示例#30
0
        public static bool edit(LoaiSanPham loaisanPham)
        {
            LoaiSanPham temp = find(loaisanPham.maLoaiSanPham);

            if (temp != null)
            {
                try
                {
                    temp.tenLoai   = loaisanPham.tenLoai;
                    temp.trangThai = loaisanPham.trangThai;
                    quanLyQuanCoffee.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    MessageBox.Show("Lỗi! không thể lưu dữ liệu");
                    return(false);
                }
                catch (DbEntityValidationException)
                {
                    MessageBox.Show("Lỗi! kiểu dữ liệu");
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("Không tìm thấy mã loại này");
            }
            return(true);
        }