// btn to delete a record private void btnDelete_Click(object sender, EventArgs e) { if (dgvSuppliers.SelectedRows.Count > 0) { // sets the object to delete int index = dgvSuppliers.SelectedRows[0].Index; suplierContact = suppliersContacts[index]; // asks user if they are sure DialogResult result = MessageBox.Show("Delete the supplier " + suplierContact.SupConCompany + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { // creates the other table objects Supplier supplier = new Supplier(); List <Products_Suppliers> products_suppliers = new List <Products_Suppliers>(); try // tries to delete the table records { // gets the data for the tasble records that need to be deleted supplier = SupplierDB.GetSupplier(suplierContact.SupplierId); products_suppliers = Products_SuppliersDB.GetAllProdSupOnID(suplierContact.SupplierId); // deletes each productsuppliers table record foreach (Products_Suppliers ps in products_suppliers) { Products_SuppliersDB.DeleteProdSup(ps); } // deltes the suppliercontacts record SupplierContactsDB.DeleteSup(suplierContact); // deltes the supplier record SupplierDB.DeleteSup(supplier); // redisplays the dgv suppliersContacts = SupplierContactsDB.listSuppliers(); refreshDGV(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } else { MessageBox.Show("Please select a Product"); } }
// button to delete fa product from the list of products private void btnDelete_Click(object sender, EventArgs e) { if (dgvProducts.SelectedRows.Count > 0) { // for adding if (add) { productSuppliers.RemoveAt(this.dgvProducts.SelectedRows[0].Index); RedisplayList(); } //for modifing else { DialogResult result = MessageBox.Show("Are you sure you want to delete this Product offered by Supplier?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { int index = this.dgvProducts.SelectedRows[0].Index; try { if (!Products_SuppliersDB.DeleteProdSup(productSuppliers[index])) { MessageBox.Show("That product has been updated or deleted already.", "Database Error"); } else { productSuppliers = Products_SuppliersDB.GetAllProdSupOnID(supplierContact.SupplierId); this.RedisplayList(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } } } else { MessageBox.Show("Please select a Product"); } }
private void DeleteSupplier(Supplier sp) { SupplierContacts suplierContact = SupplierContactsDB.GetSupplierbySupID(sp.SupplierId); // asks user if they are sure DialogResult result = MessageBox.Show("Delete the supplier " + suplierContact.SupConCompany + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { // creates the other table objects Supplier supplier = new Supplier(); List <Products_Suppliers> products_suppliers = new List <Products_Suppliers>(); try // tries to delete the table records { // gets the data for the tasble records that need to be deleted supplier = SupplierDB.GetSupplier(suplierContact.SupplierId); products_suppliers = Products_SuppliersDB.GetAllProdSupOnID(suplierContact.SupplierId); // deletes each productsuppliers table record foreach (Products_Suppliers ps in products_suppliers) { Products_SuppliersDB.DeleteProdSup(ps); } // deletes the suppliercontacts record SupplierContactsDB.DeleteSup(suplierContact); // deletes the supplier record SupplierDB.DeleteSup(supplier); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } RefreshSuppliers(); } }