// 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");
            }
        }
示例#2
0
        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();
            }
        }