// This button click method combines a Challenge ID and a Competitor ID together to create a new record in
        // the Entry table, unless the competitor is already entered into that particular challenge.
        private void btnAddEntry_Click(object sender, EventArgs e)
        {
            try
            {
                if (DM.dtChallenge.Rows[cmChallenge.Position]["Status"].ToString() == "Scheduled")
                {
                    DataRow newEntry = DM.dtEntry.NewRow();

                    newEntry["ChallengeID"]  = dgvChallenge["ChallengeID", cmChallenge.Position].Value;
                    newEntry["CompetitorID"] = dgvCompetitor["CompetitorID", cmCompetitor.Position].Value;
                    newEntry["Status"]       = comChallengeEventStatus.Text;

                    DM.dsNZESL.Tables["Entry"].Rows.Add(newEntry);
                    currencyManager.EndCurrentEdit();
                    DM.UpdateEntry();

                    MessageBox.Show("Entry added successfully", "Success");
                }

                else
                {
                    MessageBox.Show("Competitors can only be entered to scheduled challenges", "Error");
                }
            }
            catch (ConstraintException)
            {
                MessageBox.Show("This competitor has already been entered in this challenge", "Error");
            }
        }
Exemple #2
0
        // This button click method changes a challenge status to "Completed" if it was previously "Finished" and
        // deletes any entries it may have from the Entry table.
        private void btnMarkChallengeCompleted_Click(object sender, EventArgs e)
        {
            DataRow updateChallengeRow = DM.dtChallenge.Rows[currencyManager.Position];

            if (txtStatus.Text == "Finished")
            {
                updateChallengeRow["Status"] = "Completed";
                DataRow[] drChallengeEntries = DM.dtEntry.Select("ChallengeID = " + txtChallengeID.Text);

                // Deletes any entries for the challenge from the Entry table.
                foreach (DataRow competitorEntry in drChallengeEntries)
                {
                    competitorEntry.Delete();
                    DM.UpdateEntry();
                    cmEntry.EndCurrentEdit();
                }
                DM.UpdateChallenge();
                currencyManager.EndCurrentEdit();
                MessageBox.Show("Challenge marked as complete", "Success");
            }
            else
            {
                MessageBox.Show("Only finished challenges can be marked as completed", "Error");
            }
        }