Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();
     }
 }