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
                {
                }
            }
        }
        public static SkiRun Load(StreamReader inStream)                                     //Loads our competitors.
        {
            string skiName = inStream.ReadLine();                                            //Reads in the SkiRunLodge name.
            SkiRun result  = new SkiRun(skiName);                                            //Sets up our SkiRun inforamtion.

            newSkiNumber = int.Parse(inStream.ReadLine());                                   //Inputs our competitor numbers.
            int inIncome = int.Parse(inStream.ReadLine());                                   //Parses our income string into an int

            Income = inIncome;                                                               //Makes our Income value equal the original variable.
            int numberOfSkiers = int.Parse(inStream.ReadLine());                             //The dictionary count is used to recreate everyone.

            for (int i = 0; i < numberOfSkiers; i++)                                         //for loop goes round for every competitor.
            {
                string     ID = inStream.ReadLine();                                         //Reads in the competitor class.
                Competitor LoadCompetitors = CompetitorFactory.MakeCompetitor(ID, inStream); //Calls the CompetitorFactory class0.12
                skiCompetitors.Add(LoadCompetitors.GetNumber(), LoadCompetitors);            //Adds the competitors to the dictionary.
            }
            return(result);                                                                  //Returns the results.
        }
Пример #3
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.
                }
            }
        }