示例#1
0
 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();
     }
 }
示例#2
0
        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();
            }
        }
示例#3
0
        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);
            }
        }
示例#4
0
 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();
     }
 }