private void frmProduct_Supplier_Activated(object sender, EventArgs e) { products = ProductsDB.GetProducts(); //All the products are retreived using ProductsDB.GetProducts() suppliers = SuppliersDB.GetSuppliers(); //All the suppliers are retreived using SuppliersDB.GetSuppliers() ReloadListboxes(); }
//* Overall button controls *// //This method controls the show all button. When this button is clicked all the products and suppliers will be shown in the //listboxes private void btnShowAll_Click(object sender, EventArgs e) { products = ProductsDB.GetProducts(); //All the products are retreived using ProductsDB.GetProducts() suppliers = SuppliersDB.GetSuppliers(); //All the suppliers are retreived using SuppliersDB.GetSuppliers() ReloadListboxes(); }
//update the information private void btnUpdate_Click(object sender, EventArgs e) { if (Validator.IsPresent(txtProductName)) { //if the information is correct, check if the information is in the list string prodName = txtProductName.Text; bool exists = false; bool attempt = false; List <Products> products = ProductsDB.GetProducts(); foreach (Products product in products) { if (product.ProdName == prodName) { exists = true; } } if (!exists) { try { //if the name is unique , replace the other one attempt = ProductsDB.updateProduct(prodName, oldprodName); } catch (SqlException ex) { MessageBox.Show("Error modifying product\n" + ex); } if (attempt) { MessageBox.Show("Successfully modified"); this.Close(); } } else { MessageBox.Show("Product name is already in the database"); } } }
private void btnAdd_Click_1(object sender, EventArgs e) { //if the add button is pressed and the text is valid if (Validator.IsPresent(txtAddProd)) { // create a list List <Products> products = ProductsDB.GetProducts(); //add the products information to the list bool exists = false; String newProdName = txtAddProd.Text; foreach (Products product in products) //for product in list, check if theres the same name in the list { if (product.ProdName == newProdName) { exists = true; } } if (!exists) { MessageBox.Show("Successfully added " + newProdName + " to the database"); ProductsDB.addProduct(newProdName); } this.Close(); } }