private void editToolStripMenuItem_Click(object sender, EventArgs e) { switch (uxTreeView.SelectedNode.Parent.Name) { case "rootPackages": // open AddEditPackage form with related Package object in Edit mode Package pkg = frmMain.packageList[frmMain.packageList.FindIndex(pk => pk.PkgName == uxTreeView.SelectedNode.Name)]; frmAddModifyPackages frmEditPackage = new frmAddModifyPackages(); frmEditPackage.add = false; frmEditPackage.package = pkg; if (frmEditPackage.ShowDialog() == DialogResult.OK) { RefreshPackages(); // Refresh the Package List and the TreeView Node frmMain.DisplayMessage("The package has been modified successfully."); } break; case "rootProducts": // open AddEditProduct form with related Product object in Edit mode Product prd = frmMain.productList[frmMain.productList.FindIndex(pr => pr.ProdName == uxTreeView.SelectedNode.Name)]; frmProductAddEdit frmEditProduct = new frmProductAddEdit(); frmEditProduct.xNewProduct = false; frmEditProduct.txbProductID.Text = prd.ProductId.ToString(); frmEditProduct.txbProductName.Text = prd.ProdName; if (frmEditProduct.ShowDialog() == DialogResult.OK) { RefreshProducts(); // Refresh the Product List and the TreeView Node frmMain.DisplayMessage("The product has been modified successfully."); } break; case "rootSuppliers": // open AddEditSupplier form with related Supplier object in Edit mode Supplier sp = frmMain.supplierList[frmMain.supplierList.FindIndex(s => s.SupName == uxTreeView.SelectedNode.Name)]; frmAddModifySupplier frmEditSupplier = new frmAddModifySupplier(); frmEditSupplier.add = false; frmEditSupplier.supplierContact = SupplierContactsDB.GetSupplierbySupID(sp.SupplierId); if (frmEditSupplier.ShowDialog() == DialogResult.OK) { RefreshSuppliers(); // Refresh the Supplier List and the TreeView Node frmMain.DisplayMessage("The supplier information have been modified successfully."); } break; default: break; } }
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(); } }