// Adds product by name to the list of products and appends it to DB
 private void btnAddProducts_Click(object sender, EventArgs e)
 {
     if (Validator.IsProvided(txtProducts, "Product Name"))
     {
         string product = txtProducts.Text;
         bool   valid   = true;
         foreach (Product p in products)
         {
             if (p.ProdName == product)
             {
                 MessageBox.Show(product + " already exists");
                 valid = false;
                 break;
             }
         }
         if (valid)
         {
             Product pro = new Product();
             pro.ProdName  = product;
             pro.ProductId = ProductDB.AddProduct(pro);
             products      = ProductDB.GetProducts();
             displayProducts();
             listProducts();
             txtProducts.Clear();
             MessageBox.Show(product + " was added");
         }
     }
 }
Exemple #2
0
 private void btnDeleteProductClick_Click(object sender, EventArgs e)
 {
     if (delProduct != null)
     {
         DialogResult result = MessageBox.Show("Are you sure you want to delete " + delProduct.ProdName
                                               + " product ID " + delProduct.ProductID + "? ", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                               MessageBoxDefaultButton.Button2);
         if (result == DialogResult.Yes)
         {
             try
             {
                 ProductDB.DeleteProduct(delProduct);
                 products = ProductDB.GetProducts();
                 productDataGridView.DataSource = products;
                 delProduct = null;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
     else
     {
         MessageBox.Show("Please select a product to delete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 // Take all products in list and display them
 private void displayProducts()
 {
     products = ProductDB.GetProducts();
     lbProducts.Items.Clear();
     // take all the products from list and display it in the list box
     foreach (Product product in products)
     {
         lbProducts.Items.Add(product.ProdName);
     }
 }
Exemple #4
0
        private void btnEditProduct_Click(object sender, EventArgs e)
        {
            string pronameText = textBoxEditProName.Text;

            pronameText = pronameText.Trim();
            if (pronameText != "")
            {
                //Get the product to edit
                int     selectedIndex = productDataGridView.CurrentCell.RowIndex;
                Product oldProd       = products[selectedIndex];
                //Make a copy
                Product newProd = oldProd.GetCopy();
                //Update the copy with new data
                newProd.ProdName = textBoxEditProName.Text;

                if (newProd.ProdName != oldProd.ProdName) //Check if a change was made
                {
                    //Write to DB
                    try
                    {
                        bool result = ProductDB.UpdateProduct(oldProd, newProd);

                        if (result)
                        {
                            //Update the UI
                            products = ProductDB.GetProducts();
                            productDataGridView.DataSource = products;

                            MessageBox.Show("The new product name has been saved", "Product Updated",
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("The changes were not saved", "Updated Failed",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString(),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                //Hide the panel if updates were done
                panelProductEdit.Visible      = false;
                btnAddProductClick.Enabled    = true;
                btnDeleteProductClick.Enabled = true;
            }
            else //Display error message if Product name textbox was blank.
            {
                MessageBox.Show("Please provide product name.", "Missing Data",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //add panels in product tab
            listPanelProduct.Add(panelProductAdd);
            listPanelProduct.Add(panelProductEdit);

            //add panels of package tab
            listPanelPackage.Add(panelAddPkg);
            listPanelPackage.Add(panelEditPkg);

            //add panels of supplier tab
            listPanelSupplier.Add(panelAddSupplier);
            listPanelSupplier.Add(panelEditSupplier);

            //hide all panels when form loads
            panelProductAdd.Visible   = false;
            panelProductEdit.Visible  = false;
            panelAddPkg.Visible       = false;
            panelEditPkg.Visible      = false;
            panelAddSupplier.Visible  = false;
            panelEditSupplier.Visible = false;
            panelDetailPkg.Visible    = false;

            //Load products data in gridview from database
            try
            {
                products = ProductDB.GetProducts();

                productBindingSource.DataSource = products;

                //load supplier data
                suppliers = SupplierDB.GetAllSuppliers();
                //supplierNameComboBox.DataSource = suppliers;
                //comboBoxPEditSupID.DataSource = suppliers;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }

            //Load supplier data in gridview from database

            try
            {
                suppliers = SupplierDB.GetAllSuppliers();

                supplierDataGridView.DataSource = suppliers;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Exemple #6
0
        // on load check if supplier or product is being edited and display respective messages
        private void EditProdSup_Load(object sender, EventArgs e)
        {
            products  = ProductDB.GetProducts();
            suppliers = SupplierDB.GetSuppliers();

            if (SelectedProductName != null)
            {
                btnUpdate.Text       = "Update Product";
                lblProdSup.Text      = "Selected Product Name:";
                txtProdSup.Text      = SelectedProductName;
                txtProdSup.MaxLength = 50;
            }
            else
            {
                btnUpdate.Text       = "Update Supplier";
                lblProdSup.Text      = "Selected Supplier Name:";
                txtProdSup.Text      = SelectedSupplierName;
                txtProdSup.MaxLength = 255;
            }
        }
Exemple #7
0
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            string pronameText = textBoxAddProName.Text;

            pronameText = pronameText.Trim();
            if (pronameText != "")
            {
                panelProductAdd.Visible       = false;
                btnEditProductClick.Enabled   = true;
                btnDeleteProductClick.Enabled = true;
                //add product to the database

                //Get the data from the panel
                Product newProd = new Product();
                newProd.ProdName = textBoxAddProName.Text;
                // writing new Product and ProductSupplier tables
                try
                {
                    //Writing to Products Table
                    int newProdID = ProductDB.AddProducts(newProd);
                    products = ProductDB.GetProducts();
                    productDataGridView.DataSource = products;

                    //Writing to ProductSupplier table
                    //Supplier sup = suppliers[supplierNameComboBox.SelectedIndex];
                    //ProductsSuppliersDB.AddProductsSuppliers(newProdID, sup.SupplierID);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
            else
            {
                MessageBox.Show("Fill up all the required data");
            }
            textBoxAddProName.Text = "";
        }