/// <summary> /// Modify the current selected product in the database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// @Author - Rohit private void btnModifyProducts_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 { int ProdID = Convert.ToInt32(ComProductId.SelectedItem); string ProdName = txtProductName.Text; if (string.IsNullOrEmpty(ProdName) || ComProductId.SelectedItem == null) // validation for null product name { MessageBox.Show("Please enter product name and select product ID.", "Incorrect Value"); } else // if the product name is not null then use the modify method form database access class to modify the product { ProductsDB.ModifyProducts(ProdName, ProdID); MessageBox.Show("Product name updated successfully", "Update"); // message pop up clear(); // clears the fields after modifying ShowProductsInProductsTab(); // updates the datagridview after modifying the products } } catch (FormatException) // catches any format issues and null value exceptions { MessageBox.Show("Null values are not allowed", "Null Value Exception"); // message pop up } } }