private void Button2_Click(object sender, EventArgs e) { try { DialogResult result = MessageBox.Show("Bạn có chắc chắn muốn xóa Sản Phẩm " + txtNameP.Text.Trim(), "Thông Báo", MessageBoxButtons.YesNo); if (DialogResult.Yes == result) { if (ProductsBus.GetAllProductsByCategory(idUpdateCategory).Count > 0) { MessageBox.Show("Danh mục này đã có sản phẩm , Vui lòng xóa các sản phẩm của danh mục này để thực hiển", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } CategoryBus.DeleteCategory(idUpdateCategory); } } catch (Exception) { } finally { btnUpdateC.Enabled = false; btnAddC.Enabled = true; btnDeleteC.Enabled = false; loadListViewCategory(); ClearTextBoxCategory(); } }
private void BtnAddP_Click(object sender, EventArgs e) { if (!CheckValidateTextBoxEmptyProducts()) { MessageBox.Show("Vui Lòng Điền Đầy Đủ", "Thông Báo"); return; } if (txtNameP.Text.Trim() == ProductsBus.GetProductsByName(txtNameP.Text.Trim()).Name) { MessageBox.Show("Tên Đã Tồn Tại", "Thông Báo"); return; } try { Products products = new Products(); products.Name = txtNameP.Text; products.Price = int.Parse(txtPriceP.Text); products.Type = txtTypeP.Text; products.Describe = txtDescriptP.Text; products.IdCategory = CategoryBus.GetCategoryByName(cbCategoryP.SelectedItem.ToString()).Id; ProductsBus.AddProducts(products); } catch (Exception) { MessageBox.Show("Vui Lòng Điền Theo Định Dạng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { loadListViewProducts(); ClearTextBox(); } }
public JsonResult LoadData(string name, string status, int page, int pageSize = 3) { name = name.ToUpper(); var model = CategoryBus.List(); if (!string.IsNullOrEmpty(name)) { model = model.Where(x => x.Name.Contains(name)); } if (!string.IsNullOrEmpty(status)) { var statusBool = bool.Parse(status); model = model.Where(x => x.Status == statusBool); } int totalRow = model.Count(); model = model.Skip((page - 1) * pageSize).Take(pageSize); return(Json(new { data = model, total = totalRow, status = true }, JsonRequestBehavior.AllowGet)); }
public IActionResult Update(Guid id) { ViewBag.Categories = CategoryBus.GetAll().Result.Where(x => x.CategoryParent == TypeCategories.Child).ToList(); var product = ProductBus.GetById(id).Result; return(View(product)); }
private void BtnUpdateC_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNameC.Text)) { MessageBox.Show("Vui Lòng Điền Đầy Đủ", "Thông Báo"); return; } if (!string.IsNullOrEmpty(CategoryBus.GetCategoryByName(txtNameC.Text.Trim()).Name)) { if (CategoryBus.GetCategoryByName(txtNameC.Text.Trim()).Id != idUpdateCategory) { MessageBox.Show("Tên Danh Mục đã tồn tại trong hệ thống", "Thông Báo"); return; } } try { Category category = new Category(); category.Name = txtNameC.Text; category.Id = idUpdateCategory; CategoryBus.UpdateCategory(category); } catch (Exception) { MessageBox.Show("Vui Lòng Điền Theo Định Dạng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { btnUpdateC.Enabled = false; btnAddC.Enabled = true; btnDeleteC.Enabled = false; loadListViewCategory(); ClearTextBoxCategory(); } }
public IActionResult Update(ProductMv product) { ViewBag.Categories = CategoryBus.GetAll().Result.Where(x => x.CategoryParent == TypeCategories.Child).ToList(); var productData = ProductBus.GetById(product.Id).Result; if (!ModelState.IsValid) { return(View(productData)); } product.ModifiedBy = Guid.Parse("a845b16a-4ca6-48e2-4ca6-08d817450c1a"); if (product.FileImage != null) { var ms = new MemoryStream(); product.FileImage.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); product.FileData = s; product.FileImage = null; } if (ProductBus.Update(product.Id, product).Result) { TempData[ConstKey.Success] = "Success!"; return(RedirectToAction("Index")); } TempData[ConstKey.Error] = "Fail! Try again."; return(View(productData)); }
public JsonResult Details(int id) { var cate = CategoryBus.Details(id); return(Json(new { data = cate, status = true }, JsonRequestBehavior.AllowGet)); }
public JsonResult Categories() { var categories = CategoryBus.List(); return(Json(new { data = categories, status = true }, JsonRequestBehavior.AllowGet)); }
public void loadListViewCategory() { listViewCategory.Items.Clear(); foreach (var item in CategoryBus.GetAllCategory()) { var row = new string[] { item.Id.ToString(), item.Name }; var lvi = new ListViewItem(row); lvi.Tag = item; listViewCategory.Items.Add(lvi); } }
private void TxtSearchC_TextChanged(object sender, EventArgs e) { listViewCategory.Items.Clear(); foreach (var item in CategoryBus.GetAllCategorysBySearch(txtSearchC.Text)) { var row = new string[] { item.Id.ToString(), item.Name }; var lvi = new ListViewItem(row); lvi.Tag = item; listViewCategory.Items.Add(lvi); } }
private void TextBox1_TextChanged(object sender, EventArgs e) { lvProductsOrder.Items.Clear(); foreach (var item in ProductsBus.GetAllProductsBySearch(txtTenProductSearch.Text)) { var row = new string[] { item.Name, item.Price.ToString() , CategoryBus.GetCategoryById(item.IdCategory).Name }; var lvi = new ListViewItem(row); lvi.Tag = item; lvProductsOrder.Items.Add(lvi); } }
public void LoadCombo() { txtSoLuong.Text = "1"; foreach (Products item in ProductsBus.GetAllProducts()) { cbSanPham1.Items.Add(item.Name); } foreach (Category item in CategoryBus.GetAllCategory()) { cbCategorySearch.Items.Add(item.Name); } }
public void loadListViewProducts() { listViewProducts.Items.Clear(); foreach (var item in ProductsBus.GetAllProducts()) { var row = new string[] { item.Name, string.Format("{0:#,##0}", item.Price) , item.Describe, CategoryBus.GetCategoryById(item.IdCategory).Name, item.Type }; var lvi = new ListViewItem(row); lvi.Tag = item; listViewProducts.Items.Add(lvi); } }
private void TxtSearchP_TextChanged(object sender, EventArgs e) { listViewProducts.Items.Clear(); foreach (var item in ProductsBus.GetAllProductsBySearch(txtSearchP.Text)) { var row = new string[] { item.Name, item.Price.ToString() , item.Describe, CategoryBus.GetCategoryById(item.IdCategory).Name, item.Type }; var lvi = new ListViewItem(row); lvi.Tag = item; listViewProducts.Items.Add(lvi); } }
public IActionResult Index() { var products = ProductBus.GetAll().Result.ToList(); var categories = CategoryBus.GetAll().Result.ToList(); foreach (var product in products) { product.Category = categories.SingleOrDefault(x => x.Id == product.CategoryId); } ViewBag.Products = products; return(View()); }
public void loadDataInComboBoxProducts() { cbCategoryP.Items.Clear(); foreach (Category item in CategoryBus.GetAllCategory()) { cbCategoryP.Items.Add(item.Name); } cbSearchProductCategory.Items.Clear(); foreach (Category item in CategoryBus.GetAllCategory()) { cbSearchProductCategory.Items.Add(item.Name); } }
private void CbSearchProduct_SelectedIndexChanged(object sender, EventArgs e) { listViewProducts.Items.Clear(); Category category = CategoryBus.GetCategoryByName(cbSearchProductCategory.SelectedItem.ToString()); foreach (var item in ProductsBus.GetAllProductsByCategory(category.Id)) { var row = new string[] { item.Name, string.Format("{0:#,##0.00}", item.Price) , item.Describe, CategoryBus.GetCategoryById(item.IdCategory).Name, item.Type }; var lvi = new ListViewItem(row); lvi.Tag = item; listViewProducts.Items.Add(lvi); } }
public JsonResult SaveData(string strCategory) { JavaScriptSerializer serializer = new JavaScriptSerializer(); Category cate = serializer.Deserialize <Category>(strCategory); bool status = false; string message = string.Empty; //add new category if id = 0 if (cate.Id == 0) { cate.DateCreated = DateTime.Now; cate.DateModified = DateTime.Now; try { CategoryBus.Add(cate); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } else { //update existing DB //save db var entity = CategoryBus.Details(cate.Id); entity.Status = cate.Status; entity.Name = cate.Name; entity.DateModified = DateTime.Now; try { CategoryBus.Edit(entity); status = true; } catch (Exception ex) { status = false; message = ex.Message; } } return(Json(new { status = status, message = message })); }
private void ListViewCategory_SelectedIndexChanged(object sender, EventArgs e) { btnAddC.Enabled = false; btnUpdateC.Enabled = true; btnDeleteC.Enabled = true; try { var localcategory = (Category)listViewCategory.SelectedItems[0].Tag; Category category = CategoryBus.GetCategoryById(localcategory.Id); txtNameC.Text = category.Name; idUpdateCategory = category.Id; } catch (Exception) { idUpdateCategory = 0; } }
public JsonResult Delete(int id) { try { CategoryBus.Delete(id); return(Json(new { status = true })); } catch (Exception ex) { return(Json(new { status = false, message = ex.Message })); } }
private void BtnUpdateP_Click(object sender, EventArgs e) { if (!CheckValidateTextBoxEmptyProducts()) { MessageBox.Show("Vui Lòng Điền Đầy Đủ", "Thông Báo"); return; } //// nếu tên sản phẩm sửa mà id của nó khác với idupdate /// thì có nghĩa Tên Đó Đã Tồn Tại Trong Sản Phẩm nhưng nó k phải là chính sản /// phẩm mình muốn sữa if (!string.IsNullOrEmpty(ProductsBus.GetProductsByName(txtNameP.Text.Trim()).Name)) { if (ProductsBus.GetProductsByName(txtNameP.Text.Trim()).Id != idUpdateProducts) { MessageBox.Show("Tên sản phẩm đã tồn tại trong hệ thống", "Thông Báo"); return; } } try { Products products = new Products(); products.Name = txtNameP.Text; products.Price = int.Parse(txtPriceP.Text); products.Type = txtTypeP.Text; products.Describe = txtDescriptP.Text; products.IdCategory = CategoryBus.GetCategoryByName(cbCategoryP.SelectedItem.ToString()).Id; products.Id = idUpdateProducts; ProductsBus.UpdateProducts(products); MessageBox.Show("Sửa Thành Công", "Thông Báo"); } catch (Exception) { MessageBox.Show("Vui Lòng Điền Theo Định Dạng", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { btnAddP.Enabled = true; btnUpdateP.Enabled = false; btnDeleteP.Enabled = false; ClearTextBox(); loadListViewProducts(); } }
private void ListViewProducts_SelectedIndexChanged(object sender, EventArgs e) { btnAddP.Enabled = false; btnUpdateP.Enabled = true; btnDeleteP.Enabled = true; try { var localproduct = (Products)listViewProducts.SelectedItems[0].Tag; Products products = ProductsBus.GetProductsById(localproduct.Id); txtNameP.Text = products.Name; txtPriceP.Text = products.Price.ToString(); txtTypeP.Text = products.Type; txtDescriptP.Text = products.Describe; cbCategoryP.Text = CategoryBus.GetCategoryById(products.IdCategory).Name; idUpdateProducts = products.Id; } catch (Exception) { idUpdateProducts = 0; } }
public List <CategoryContract> listCategories() { var data = new CategoryBus().ListCategories(); return(data); }
public IActionResult Create() { ViewBag.Categories = CategoryBus.GetAll().Result.Where(x => x.CategoryParent == TypeCategories.Child).ToList(); return(View()); }
// GET: Product/ public ActionResult Index(int?BrandId, int?currentBrand, int?CateId, int?currentCate, int?TypeId, int?currentType, string currentFilter, string SearchString, int page = 1, int pageSize = 4) { ViewBag.BrandId = new SelectList(BrandBus.List(), "Id", "Name"); ViewBag.CateId = new SelectList(CategoryBus.List().Where(x => x.Status == true), "Id", "Name"); ViewBag.TypeId = new SelectList(TypeBus.List(), "Id", "Name"); if (SearchString != null) { page = 1; } else { SearchString = currentFilter; } ViewBag.CurrentFilter = SearchString; if (CateId != null) { page = 1; } else { CateId = currentCate; } ViewBag.CurrentCate = CateId; if (TypeId != null) { page = 1; } else { TypeId = currentType; } ViewBag.CurrentType = TypeId; if (BrandId != null) { page = 1; } else { BrandId = currentBrand; } ViewBag.CurrentBrand = BrandId; var model = ProductBus.List().Where(x => x.Status == true); if (!string.IsNullOrEmpty(SearchString)) { model = model.Where(x => x.Description.ToLower().Contains(SearchString.ToLower()) || x.Name.ToLower().Contains(SearchString.ToLower())); } if (BrandId != null) { model = model.Where(x => x.BrandId == BrandId); } ViewBag.CurrentBrand = BrandId; if (CateId != null) { model = model.Where(x => x.CateId == CateId); } if (TypeId != null) { model = model.Where(x => x.TypeId == TypeId); } return(View(model.ToPagedList(page, pageSize))); }
public void LoadDataListViewProducts() { lvProductsOrder.Items.Clear(); foreach (var item in ProductsBus.GetAllProducts()) { var row = new string[] { item.Name, string.Format("{0:#,##0}", item.Price), CategoryBus.GetCategoryById(item.IdCategory).Name }; var lvi = new ListViewItem(row); lvi.Tag = item; lvProductsOrder.Items.Add(lvi); } }