private void btnDelete_Click(object sender, EventArgs e) { if (loggedInAgt == null) { mainForm.btnSignIn_Click(null, null); } else { // create Supplier object to be deleted Supplier supplier = new Supplier(); supplier.SupplierId = Convert.ToInt32(txtSupplierId.Text); supplier.SupName = txtSupplierName.Text; if (SupplierDB.IsInProductsSuppliers(supplier)) { MessageBox.Show("This supplier is already being used in " + " the Products_Suppliers table and you may not delete it."); return; } bool result = SupplierDB.DeleteSupplier(supplier); DisplaySuppliers(cmbSuppliers.SelectedIndex - 1); } }
//clicks the button to delete the supplier from the batabase private void btnDeleteSup_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Are you sure?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { sup.SupplierId = Convert.ToInt32(txtSupplierId.Text); sup.SupName = cmbSupId.Text; try { if (!SupplierDB.DeleteSupplier(sup)) { MessageBox.Show("Another user has updated or deleted that supplier.", "Database Error"); } else { tabSuppliersDefaultStatus(); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } } }
private void btnDeleteSelected_Click(object sender, EventArgs e) { clearForm(); if (lstSuppliers.SelectedItems.Count == 1) { selectedSupplierID = lstSuppliers.Items[lstSuppliers.SelectedIndices[0]].Text.Trim(); //store selected supplier id if (SupplierDB.CheckDependency(Convert.ToInt32(selectedSupplierID))) { MessageBox.Show("Cannot delete. SupplierID exists in table Products_Suppliers"); } else { //confirm that user wants to delete DialogResult result = MessageBox.Show("Are you sure you want to delete this record?" + "\n\nSupplier ID: " + selectedSupplierID + "\nSupplier Name: " + selectedSupName, "Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { if (SupplierDB.DeleteSupplier(Convert.ToInt32(selectedSupplierID))) { //if delete is successful, display message and update list view MessageBox.Show("Delete successful!"); updateListView(SupplierDB.GetSuppliers()); clearForm(); this.lstSuppliers.SelectedIndices.Clear(); selectedSupName = ""; selectedSupplierID = ""; } else { //delete failed, display message MessageBox.Show("Delete was not successful."); } } else if (result == DialogResult.No) //if user confirms they do not want to delete, display cancel message { MessageBox.Show("Delete cancelled"); this.lstSuppliers.SelectedIndices.Clear(); selectedSupName = ""; selectedSupplierID = ""; clearForm(); } } } else { MessageBox.Show("Please select item to delete"); lstSuppliers.Focus(); } }//END OF DELETE BUTTON CLICK
// Delete Supplier handling - Quynh Nguyen private void btnDelete_Click(object sender, EventArgs e) { Supplier selectedSupplier = (Supplier)this.listSupplier.SelectedItem; if (selectedSupplier == null) { MessageBox.Show("Please select the supplier which you want to delete and try again.", "Not Select Supplier."); } else { DialogResult dialogResult = MessageBox.Show("Are you sure to delete the supplier with Name - \"" + selectedSupplier.SupName + "\"?", "Delete Confirmation", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) // user confirmed to delete supplier { SupplierDB ado = new SupplierDB(); try { if (ado.DeleteSupplier(selectedSupplier.SupplierId)) // delete successfully { MessageBox.Show("The supplier \"" + selectedSupplier.SupName + "\" was deleted sussccefully", "Deleting Supplier"); } else { MessageBox.Show("The supplier \"" + selectedSupplier.SupName + "\" was not deleted sussccefully", "Deleting Supplier"); } } catch (Exception ex) { Utils.ErrorManager(ex, "", "frmEditSuppliers.btnDelete_Click()"); } } this.Close(); } }
/// <summary> /// set the specified fields /// delete specified supplier /// check to see if the deleted supplier has been actually deleted from the database /// </summary> private void btnDeleteSupplier_Click(object sender, EventArgs e) { int supplierID = Convert.ToInt32(txtSupID.Text); string supName = txtSupName.Text; SupplierDB.DeleteSupplier(supplierID, supName); bool SupplierExists = SupplierDB.CheckDataBase(supplierID); if (SupplierExists == false) { txtSupID.Text = ""; txtSupName.Text = ""; RefreshRecords(supplierID + 2); MessageBox.Show("Supplier with ID: " + supplierID + " deleted"); } else { MessageBox.Show("Supplier with ID: " + supplierID + " was not deleted"); } DisplaySuppliers(); cmbSupplierID.SelectedItem = supplierIDs[supplierIDs.Count - 1]; }
// Supplier's Delete Button private void btnDeleteSupplier_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("DO you really want to delete this Supplier?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); SelectedRowSupplier(); //get user selected row values if (result == DialogResult.Yes) //if user clicks accept delete { try { if (!SupplierDB.DeleteSupplier(supplier)) //delete does not happen in database { MessageBox.Show("Another user has updated or deleted product" + supplier.SupName, "Datebase Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } this.DisplaySupplier(); this.DisplayPackages(); this.DisplayPackageProdSup(); } }