Пример #1
0
 public void Load()  //Calls the load method in the SkiRun class to load the data of the competitors.
 {
     try
     {
         SkiRun.Load("skiers.txt");           //Selects which file to load from.
         activeSkiRun.LoadScores();           //Loads in the scores
         MessageBox.Show("Load successful."); //Success message.
     }
     catch
     {
         MessageBox.Show("Something went wrong when try to load. Information was not loaded.");  //Error message.
     }
 }
        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 MakingCompetitors() //Makes our competitors.
        {
            if (AgeCheck() == true)      //If the AgeCheck method returns true then we don't do anything and the code continues.
            {
            }
            else                    //If AgeCheck returns false we return an error message and try again.
            {
                MessageBox.Show("Please enter a number between 12 and 70 for your age.");
                AgeTextBox.Clear();
                return;
            }


            if (NewNameTextBox.Text.Trim() == "")           //If there is no name entered when you're making a competitor then it will be rejected.
            {
                MessageBox.Show("Please enter your name."); //The error message.
            }

            else if (NewCompetitorAddressTextBox.Text.Trim() == "") //If there is no address entered when you're making a competitor then it will be rejected.
            {
                MessageBox.Show("Please enter your address.");      //The error message.
            }


            else if (AmateurRadioButton.IsChecked == false && ProfessionalRadioButton.IsChecked == false && CelebrityRadioButton.IsChecked == false) //If there is no class selected when you're making a competitor then it will be rejected.
            {
                MessageBox.Show("Please choose your class.");                                                                                        //The error message.
            }

            else if (AmateurRadioButton.IsChecked == true)                                                                                              //Makes an amateur competitor.
            {
                string ID = "Amateur";                                                                                                                  //Gives the competitor their class ID.
                SkiRun.AddAmateurCompetitor(ID, NewNameTextBox.Text.Trim(), NewCompetitorAddressTextBox.Text.Trim(), AgeTextBox.Text.Trim(), NewScore); //Calls the amateur creator method in the SkiRun class.
                CompetitorNumberTextBox.Text = activeSkiRun.GetSkiNumber().ToString();                                                                  //Gets the competitor number.
                MessageBox.Show("Competitor Created!");                                                                                                 //Message for when you have created your competitor.
                ClearText();                                                                                                                            //Calls the ClearText method which clears all of the text.
            }

            else if (ProfessionalRadioButton.IsChecked == true) //Makes a professional competitor.
            {
                if (SponsorTextBox.Text == "")                  //If no sponsor is selected it will be rejected.
                {
                    MessageBox.Show("Please enter a sponsor!"); //The error message.
                }

                else  //If there is a sponsor then we continue onto the creation.
                {
                    string ID = "Professional";  //Gives the competitor their class ID.
                    SkiRun.AddProfessionalCompetitor(ID, NewNameTextBox.Text.Trim(), NewCompetitorAddressTextBox.Text.Trim(), AgeTextBox.Text.Trim(), NewScore, SponsorTextBox.Text.Trim()); //Calls the professional creator method in the SkiRun class.
                    CompetitorNumberTextBox.Text = activeSkiRun.GetSkiNumber().ToString();                                                                                                   //Gets the competitor number.
                    MessageBox.Show("Competitor Created!");                                                                                                                                  //Message for when you have created your competitor.
                    ClearText();                                                                                                                                                             //Calls the ClearText method which clears all of the text.
                }
            }
            else if (CelebrityRadioButton.IsChecked == true)                                      //Makes a celebrity competitor.
            {
                if (BloodTypeTextBox.Text.Trim() == "" || NextOfKinTypeTextBox.Text.Trim() == "") //If there is no blood type and/or next of kin then the cpmpetitor will be rejected.
                {
                    MessageBox.Show("Please enter a blood type, next of kin or both!");           //The error message.
                }

                else
                {
                    string ID = "Celebrity";                                                                                                                                                                                  //Gives the competitor their class ID.
                    SkiRun.AddCelebrityCompetitor(ID, NewNameTextBox.Text.Trim(), NewCompetitorAddressTextBox.Text.Trim(), AgeTextBox.Text.Trim(), NewScore, BloodTypeTextBox.Text.Trim(), NextOfKinTypeTextBox.Text.Trim()); //Calls the celebrity creator method in the SkiRun class.
                    CompetitorNumberTextBox.Text = activeSkiRun.GetSkiNumber().ToString();                                                                                                                                    //Gets the competitor number.
                    MessageBox.Show("Competitor Created!");                                                                                                                                                                   //Message for when you have created your competitor.
                    ClearText();                                                                                                                                                                                              //Calls the ClearText method which clears all of the text.
                }
            }
        }
Пример #4
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.
                }
            }
        }
Пример #5
0
        private void FindCompetitor()                                                                  //Set up to find the competitors by their number.
        {
            DetailsTextBox.Clear();                                                                    //Clears the details textbox.
            Competitor editSkier;                                                                      //Makes aninstance of the Competitor class.

            if (SearchTextBox.Text.Trim() != "" && NumberTextBox.Text.Trim() != "")                    //You can only use on search method so if there is text in both it will be rejected.
            {
                MessageBox.Show("Please use only one search method!");                                 //The error message.
            }
            else if (SearchByName.Text.Trim() == "" && NumberTextBox.Text.Trim() == "")                //If there is no text in either search methods then the search will fail.
            {
                editSkier = null;                                                                      //There's no competitor.
                MessageBox.Show("There is no competitor with that number or name! Please try again."); //The error message.
                NameTextBox.Clear();                                                                   //Clears the name text box.
                AddressTextBox.Clear();                                                                //Clears the address text box.
                ScoreTextBox.Clear();                                                                  //Clears the score text box.
                NumberTextBox.Clear();                                                                 //Clears number text box.
                TagTextBox.Clear();                                                                    //Clears the tag text box.
            }

            //***NOTE*** - This is a very inefficient way to seach. I have the same code twice for each search method because I didn't know how to differentiate between the two.

            else if (SearchByName.Text.Trim() != "")                          //If search by name has some text in it then it will make a competitor.
            {
                editSkier = SkiRun.FindSkierByName(SearchByName.Text.Trim()); //Calls the find competitor by name in the SkiRun class.
                try
                {
                    NameTextBox.Text    = editSkier.GetName().Trim();                                                                                                                                                                                                                                    //Sets the competitor name.
                    AddressTextBox.Text = editSkier.GetAddress().Trim();                                                                                                                                                                                                                                 //Sets the competitor address.
                    ScoreTextBox.Text   = editSkier.GetScore().Trim();                                                                                                                                                                                                                                   //Sets the competitor score.

                    if (editSkier.GetSponsor() == null && editSkier.GetBlood() == null && editSkier.GetNoK() == null)                                                                                                                                                                                    //If there's no sponsor, no blood type and no next of kin then it must be an amateur.
                    {
                        DetailsTextBox.Text = "Class: Amatuer" + Environment.NewLine + "Your age: " + editSkier.GetAge() + Environment.NewLine + "You have paid £100";                                                                                                                                   //Information show in details text box.
                        TagTextBox.Text     = "Amateur";                                                                                                                                                                                                                                                 //Displays the tag in the tag text box.
                    }
                    else if (editSkier.GetSponsor() != null)                                                                                                                                                                                                                                             //If the sponsor does no equal null then it must be a professional.
                    {
                        DetailsTextBox.Text = "Class: Professional" + Environment.NewLine + "Your age: " + editSkier.GetAge() + Environment.NewLine + "You have paid £200" + Environment.NewLine + "Sponsor: " + editSkier.GetSponsor();                                                                 //Information show in details text box.
                        TagTextBox.Text     = "Professional";                                                                                                                                                                                                                                            //Displays the tag in the tag text box.
                    }
                    else if (editSkier.GetBlood() != null)                                                                                                                                                                                                                                               //If blood type does not equal null then is must be a celebrity.
                    {
                        DetailsTextBox.Text = "Class: Celebrity" + Environment.NewLine + "Your age: " + editSkier.GetAge() + Environment.NewLine + "You do not have to pay." + Environment.NewLine + "Blood Type: " + editSkier.GetBlood() + Environment.NewLine + "Next of Kin: " + editSkier.GetNoK(); //Information show in details text box.
                        TagTextBox.Text     = "Celebrity";                                                                                                                                                                                                                                               //Displays the tag in the tag text box.
                    }
                }
                catch
                {
                    MessageBox.Show("Could not find competitor!");  //If the user types a name it cannot find then it will display this.
                }
            }
            else if (NumberTextBox.Text.Trim() != "")                    //If the number text box has something in it then it will use this method.
            {
                editSkier = SkiRun.FindSkier(NumberTextBox.Text.Trim()); //Calls the find competitor in the SkiRun class.
                try
                {
                    NameTextBox.Text    = editSkier.GetName();                                                                                                                                                                                                                                           //Sets the competitor name.
                    AddressTextBox.Text = editSkier.GetAddress();                                                                                                                                                                                                                                        //Sets the competitor address.
                    ScoreTextBox.Text   = editSkier.GetScore();                                                                                                                                                                                                                                          //Sets the competitor score.

                    if (editSkier.GetSponsor() == null && editSkier.GetBlood() == null && editSkier.GetNoK() == null)                                                                                                                                                                                    //If there's no sponsor, no blood type and no next of kin then it must be an amateur.
                    {
                        DetailsTextBox.Text = "Class: Amatuer" + Environment.NewLine + "Your age: " + editSkier.GetAge() + Environment.NewLine + "You have paid £100";                                                                                                                                   //Information show in details text box.
                        TagTextBox.Text     = "Amateur";                                                                                                                                                                                                                                                 //Displays the tag in the tag text box.
                    }
                    else if (editSkier.GetSponsor() != null)                                                                                                                                                                                                                                             //If the sponsor does no equal null then it must be a professional.
                    {
                        DetailsTextBox.Text = "Class: Professional" + Environment.NewLine + "Your age: " + editSkier.GetAge() + Environment.NewLine + "You have paid £200" + Environment.NewLine + "Sponsor: " + editSkier.GetSponsor();                                                                 //Information show in details text box.
                        TagTextBox.Text     = "Professional";                                                                                                                                                                                                                                            //Displays the tag in the tag text box.
                    }
                    else if (editSkier.GetBlood() != null)                                                                                                                                                                                                                                               //If blood type does not equal null then is must be a celebrity.
                    {
                        DetailsTextBox.Text = "Class: Celebrity" + Environment.NewLine + "Your age: " + editSkier.GetAge() + Environment.NewLine + "You do not have to pay." + Environment.NewLine + "Blood Type: " + editSkier.GetBlood() + Environment.NewLine + "Next of Kin: " + editSkier.GetNoK(); //Information show in details text box.
                        TagTextBox.Text     = "Celebrity";                                                                                                                                                                                                                                               //Displays the tag in the tag text box.
                    }
                }
                catch
                {
                    MessageBox.Show("Could not find competitor!");  //If the user types a name it cannot find then it will display this.
                }
            }
            //NumberTextBox.Clear();
            //SearchByName.Items.Clear();
            //SearchTextBox.Clear();
        }