private void btnSaveHorse1_Click(object sender, EventArgs e) { DataRow newHorseRow = DM.dtHorse.NewRow(); if ((txtName1.Text == "")) { MessageBox.Show("You must enter a value for each of the text fields", "Error"); } else { newHorseRow["HorseName"] = txtName1.Text; newHorseRow["Gender"] = cmbGender1.Text; newHorseRow["OwnerID"] = int.Parse(cmbOwnerID1.Text); newHorseRow["DateOfBirth"] = dtpDOB.Value.ToString(); //Add the new row to the Table DM.dtHorse.Rows.Add(newHorseRow); DM.UpdateHorse(); //Give the user a success message MessageBox.Show("Horse added successfully", "Success"); pnlAddHorse.Visible = false; lstHorse.Visible = true; btnPrevious.Enabled = true; btnNext.Enabled = true; btnUpdateHorse.Enabled = true; btnDeleteHorse.Enabled = true; btnReturn.Enabled = true; } }
//Function to delete the Horse record private void btnDeleteHorse_Click(object sender, EventArgs e) { DataRow deleteHorseRow = DM.dtHorse.Rows[currencyManager.Position]; DataRow[] EntryRow = DM.dtEntry.Select("HorseID = " + lblHorseID.Text); if (EntryRow.Length != 0) { MessageBox.Show("You may only delete horses that have no entries!", "Error"); } else { if (MessageBox.Show("Are you sure you want to delete this record?", "Warning", MessageBoxButtons.OKCancel) == DialogResult.OK) { deleteHorseRow.Delete(); DM.UpdateHorse(); //Update database MessageBox.Show("Horse deleted successfully!", "Success"); } } }