// Save button for the suppliers tab private void btnSaveSupplier_Click(object sender, EventArgs e) { string selectedSup = lstSupplierList.GetItemText(lstSupplierList.SelectedItem); string editedSup = txtModifySupplier.Text; // Validation to see if the typed item is already in the list int index = lstSupplierList.FindString(editedSup, -1); if (editedSup != "" && index != -1) { MessageBox.Show("Warning: Supplier already exists.", "Duplicate Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { // Test for saving or editing if (lstSupplierList.Enabled == false && editedSup != "") { DialogResult result = MessageBox.Show("Save '" + editedSup + "' as a new supplier?", "Confirm Add", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.OK) { SupplierDB.AddSupplierName(editedSup); this.frmModifyProductSupplier_Load(this, null); // Select the item that was just saved SelectItem(editedSup, lstSupplierList); } } else if (lstSupplierList.Enabled == false && editedSup == "") { MessageBox.Show("Please enter a new supplier name.", "Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtModifySupplier.Focus(); } else if (lstSupplierList.Enabled == true && selectedSup != editedSup) { DialogResult update = MessageBox.Show("Change '" + selectedSup + "' to '" + editedSup + "'?" , "Confirm Change", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (update == DialogResult.OK) { SupplierDB.UpdateSupplier(selectedSup, editedSup); // Refresh table adapter to display updated list this.frmModifyProductSupplier_Load(this, null); lstSupplierList.GetItemText(lstSupplierList.SelectedItem); // Select the item that was just updated SelectItem(editedSup, lstSupplierList); } } else if (lstSupplierList.Enabled == true && selectedSup == "") { MessageBox.Show("Please select a supplier name to edit.", "Item Not Selected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtModifySupplier.Focus(); } } }