예제 #1
0
        /// <summary>
        /// Add button adds new products to the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// @Author - Rohit
        private void btnAddProducts_Click(object sender, EventArgs e)
        {
            products = ProductsDB.GetAllProducts();

            if (products.FindIndex(prod => prod.ProductName == txtProductName.Text) >= 0)
            {
                MessageBox.Show("That product is already added.");
            }
            else
            {
                try
                {
                    ComProductId.Enabled = false;                                               // disables the product id textbox (not required while adding products)
                    string ProdName = txtProductName.Text;
                    if (ProdName == "")                                                         // null value validation on product name
                    {
                        MessageBox.Show("Null and Dublicate values are not allowed.", "Error"); // message box pop uo
                    }
                    else // if product name is not null add the new product using Add product method
                    {
                        ProductsDB.AddProducts(ProdName);
                        ShowProductsInProductsTab();                                      // Updates data grid view
                        LoadComboBox();                                                   // updates combo box to view the added product immediately
                        MessageBox.Show("New product succesfully added.", "Add Product"); // message box pop up
                        clear();                                                          // clears the fields after adding new product
                    }
                    ComProductId.Enabled = true;                                          // After the product is added, enable the product id textbox
                }
                catch (FormatException)                                                   // catches any format issues and null value exceptions
                {
                    MessageBox.Show("Null values are not allowed, Type correct information.", "Null Value / Incorrect Format");
                }
            }
        }