int AveAgeCounter;                                      //Average age counter.

        public void LoadInAges()                                //Loads in the ages into the list.
        {
            for (int i = 1; i <= skiCompetitors.Count; i++)     //For loop to go around the dictionary to get the competitors. Starts at 1 because there is no competitor "0".
            {
                Competitor editSkier = FindSkier(i.ToString()); //Finds the competitors.

                try
                {
                    int Ages = int.Parse(editSkier.GetAge()); //Parses their age intop an integer.
                    CompetitorAges.Add(Ages);                 //Adds it to the list.
                    CompetitorAges.Sort();                    //Sorts the list.
                }
                catch
                {
                }
            }
        }
Example #2
0
        private void SaveByName()  //Method for saving by name instead of number.
        {
            if (SearchByName.Text == "")
            {
                MessageBox.Show("There is no competitor number or competitor name selected!");
                return;
            }

            Competitor editSkier = SkiRun.FindSkierByName(SearchByName.Text);      //Finds the competitor.

            string CompNumber = editSkier.GetNumber();                             //Gets the number becasue we are not saving the number in the box.

            if (NameTextBox.Text.Trim() == "" || AddressTextBox.Text.Trim() == "") //If the names text box and the address text box is empty when you save it will be rejected.
            {
                MessageBox.Show("Please re-enter your name and or address.");      //The error message.
                return;                                                            //Returns back to try again.
            }

            if (ScoreTextBox.Text.Trim() == "" || ScoreTextBox.Text.Trim() == "0") //If there is no score then it is rejected.
            {
                MessageBox.Show("Please enter a score.");                          //The error message.
            }

            else
            {
                try
                {
                    int Score = int.Parse(ScoreTextBox.Text);  //Turn the score text into an integer.


                    if (Score < 0 || Score > 100)                                   //If it's below 0 and above 100 it is rejected.
                    {
                        MessageBox.Show("Please enter a score between 0 and 100."); //The error message.
                    }
                    else

                    if (TagTextBox.Text == "Amateur" && Score > 0 && Score <= 100)                                                                                                                                            //If it is an amateur and the score is within range then it save the competitor.
                    {
                        activeSkiRun.EditAmateur(TagTextBox.Text, NameTextBox.Text.Trim(), CompNumber, AddressTextBox.Text.Trim(), editSkier.GetAge(), ScoreTextBox.Text);                                                    //Calls the EditAmateur method and saves all of the information.
                        activeSkiRun.TopAmateurScores(ScoreTextBox.Text.Trim(), NameTextBox.Text.Trim());                                                                                                                     //Adds the high scorers to the TopAmateurScores list.
                        activeSkiRun.Save("skiers.txt");                                                                                                                                                                      //Which file to save to.
                        MessageBox.Show("Sucessfully Saved!");                                                                                                                                                                //The success message.
                    }
                    else if (TagTextBox.Text == "Professional" && Score > 0 && Score <= 100)                                                                                                                                  //If it is an professional and the score is within range then it save the competitor.
                    {
                        activeSkiRun.EditProfessional(TagTextBox.Text, NameTextBox.Text.Trim(), CompNumber, AddressTextBox.Text.Trim(), editSkier.GetAge(), ScoreTextBox.Text.Trim(), editSkier.GetSponsor());                //Calls the EditAmateur method and saves all of the information.
                        activeSkiRun.TopProfessionalScores(ScoreTextBox.Text.Trim(), NameTextBox.Text.Trim());                                                                                                                //Adds the high scorers to the TopProfessionalScores list.
                        activeSkiRun.Save("skiers.txt");                                                                                                                                                                      //Which file to save to.
                        MessageBox.Show("Sucessfully Saved!");                                                                                                                                                                //The success message.
                    }
                    else if (TagTextBox.Text == "Celebrity" && Score > 0 && Score <= 100)                                                                                                                                     //If it is an celebrity and the score is within range then it save the competitor.
                    {
                        activeSkiRun.EditCelebrity(TagTextBox.Text, NameTextBox.Text.Trim(), CompNumber, AddressTextBox.Text.Trim(), editSkier.GetAge(), ScoreTextBox.Text.Trim(), editSkier.GetBlood(), editSkier.GetNoK()); //Calls the EditAmateur method and saves all of the information.
                        activeSkiRun.TopCelebrityScores(ScoreTextBox.Text.Trim(), NameTextBox.Text.Trim());                                                                                                                   //Adds the high scorers to the TopCelebrityScores list.
                        activeSkiRun.Save("skiers.txt");                                                                                                                                                                      //Which file to save to.
                        MessageBox.Show("Sucessfully Saved!");                                                                                                                                                                //The success message.
                    }
                }
                catch
                {
                    MessageBox.Show("Please enter a valid score number.");  //If the user enters anything but a number then it will be rejected.
                }
            }
        }