private void btnAddEntry_Click(object sender, EventArgs e)
        {
            findRaceStatus();
            try
            {
                if (RaceStatus == "Scheduled")
                {
                    DataRow newEntry = DM.dtEntry.NewRow();

                    int             selectedRaceRow = dgvRace.SelectedCells[0].RowIndex;
                    DataGridViewRow selectedRow1    = dgvRace.Rows[selectedRaceRow];
                    newEntry["RaceID"] = Convert.ToString(selectedRow1.Cells["RaceID"].Value);

                    int             selectedHorseRow = dgvHorse.SelectedCells[0].RowIndex;
                    DataGridViewRow selectedRow      = dgvHorse.Rows[selectedHorseRow];
                    newEntry["HorseID"] = Convert.ToString(selectedRow.Cells["HorseID"].Value);
                    newEntry["Status"]  = cmbStatus.Text;

                    DM.dsNorthIslandRacing.Tables["Entry"].Rows.Add(newEntry); //add a new row to dataset
                    DM.UpdateEntry();                                          //update database
                    MessageBox.Show("Entry added successfully", "Success");
                }
                else
                {
                    MessageBox.Show("Horses can only be entered to scheduled races", "Error");
                }
            }
            catch (ConstraintException)
            {
                MessageBox.Show("This horse has already been added to the race", "Error");
            }
        }
예제 #2
0
        //Function to add new record to Entry table
        private void btnAddEntry_Click(object sender, EventArgs e)
        {
            DataRow newEntry = DM.dtEntry.NewRow();

            try {
                if (DM.dtRace.Rows[cmRace.Position]["Status"].ToString() != "Scheduled")            //Check to see if the selected race in Race Grid View has a status of not equal to Scheduled
                {
                    MessageBox.Show("Horses can only be entered to scheduled races", "Error");
                }
                else
                {
                    //Set the new record to the new row
                    newEntry["HorseID"] = dgvHorseDetails["HorseID", cmHorse.Position].Value;       //Get the selected HorseID column in Horse Data Grid View and set it to the new HorseID column
                    newEntry["RaceID"]  = dgvRaceDetails["RaceID", cmRace.Position].Value;          //Get the selected RaceID column in Race Data Grid View and set it to the new RaceID column
                    newEntry["Status"]  = cboStatus.Text;                                           //Get the value from the status combo box and set it to the new Status column

                    DM.dsNorthIslandRacing.Tables["Entry"].Rows.Add(newEntry);
                    DM.UpdateEntry(); //Update database
                    MessageBox.Show("Entry added successfully.", "Success");
                }
            }
            catch (ConstraintException)
            {
                MessageBox.Show("This horse has already been scheduled with this race.", "Error");
            }
        }