private void btnDeleteSalesPerson_Click(object sender, EventArgs e) { if (txtEmployeeID.Text == "") { MessageBox.Show("Can't delete. No sales person selected. Please select a sale person from the grid below.", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } string msg = "Are you sure you want to delete " + cmbEmployeeName.Text + " from the sales person list.?"; if (MessageBox.Show(msg, "MICS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes) { SalesPerson sp = new SalesPerson(); SalesTerritoryHistory hist = new SalesTerritoryHistory(); try { sp.SalesPersonID = Int32.Parse(txtEmployeeID.Text); hist.SalesPersonID = sp.SalesPersonID; sp.RemoveSalesPerson(sp); hist.RemoveSalesTerritoryHistory(hist); MessageBox.Show("Record deleted successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information); RefreshForm(); } catch (Exception ex) { MessageBox.Show(ex.Message, "MICS", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sp = null; } } }