Example #1
0
        private void golfToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            GolfTeamGenerator teamGenerator = (GolfTeamGenerator)parseFile(Sports.Golf);

            if (teamGenerator == null)
            {
                return;
            }

            GolfPlayerSelectorForm form = new GolfPlayerSelectorForm(teamGenerator.getGolfers(), Convert.ToInt32(salaryCapTextBox.Text),
                                                                     Convert.ToInt32(salaryThresholdTextBox.Text));

            form.Show();
        }
Example #2
0
        private GenerateTeams parseFile(Sports league)
        {
            startTime();

            workingProgressLabel.Text = "Starting Calculations";
            GenerateTeams teamGenerator;
            int salaryCap = Convert.ToInt32(salaryCapTextBox.Text);
            int threshold = Convert.ToInt32(salaryThresholdTextBox.Text);

            if (league == Sports.Football)
            {
                teamGenerator = new FootballTeamGenerator(salaryCap, threshold);
            }
            else if (league == Sports.Hockey) {
                teamGenerator = new NHLTeamGenerator(salaryCap, threshold);
            }
            else if (league == Sports.Basketball)
            {
                teamGenerator = new BasketballTeamGenerator(salaryCap, threshold);
            }
            else if (league == Sports.Golf)
            {
                teamGenerator = new GolfTeamGenerator(salaryCap, threshold);
            }
            else
            {
                throw new NotImplementedException();
            }

            OpenFileDialog file = new OpenFileDialog();
            file.Multiselect = false;

            if (file.ShowDialog() == DialogResult.OK)
            {
                Console.WriteLine(file.FileName);
                var reader = new StreamReader(File.OpenRead(file.FileName));

                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    String[] values = line.Split(',');
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = values[i].Replace("\"", String.Empty);
                    }

                    Player.Positions pos = Player.convertToEnum(values[0]);
                    if (pos == Player.Positions.INVALID)
                    {
                        continue;
                    }

                    int salary;
                    Int32.TryParse(values[2], out salary);
                    double points;
                    Double.TryParse(values[4], out points);

                    Player player = new Player(pos, values[1], uniqueID++, salary, points);
                    teamGenerator.addPlayer(player);
                }
                reader.Close();
                return teamGenerator;
            }

            return null;
        }
Example #3
0
        private GenerateTeams parseFile(Sports league)
        {
            startTime();

            workingProgressLabel.Text = "Starting Calculations";
            GenerateTeams teamGenerator;
            int           salaryCap = Convert.ToInt32(salaryCapTextBox.Text);
            int           threshold = Convert.ToInt32(salaryThresholdTextBox.Text);

            if (league == Sports.Football)
            {
                teamGenerator = new FootballTeamGenerator(salaryCap, threshold);
            }
            else if (league == Sports.Hockey)
            {
                teamGenerator = new NHLTeamGenerator(salaryCap, threshold);
            }
            else if (league == Sports.Basketball)
            {
                teamGenerator = new BasketballTeamGenerator(salaryCap, threshold);
            }
            else if (league == Sports.Golf)
            {
                teamGenerator = new GolfTeamGenerator(salaryCap, threshold);
            }
            else
            {
                throw new NotImplementedException();
            }

            OpenFileDialog file = new OpenFileDialog();

            file.Multiselect = false;

            if (file.ShowDialog() == DialogResult.OK)
            {
                Console.WriteLine(file.FileName);
                var reader = new StreamReader(File.OpenRead(file.FileName));

                while (!reader.EndOfStream)
                {
                    var      line   = reader.ReadLine();
                    String[] values = line.Split(',');
                    for (int i = 0; i < values.Length; i++)
                    {
                        values[i] = values[i].Replace("\"", String.Empty);
                    }


                    Player.Positions pos = Player.convertToEnum(values[0]);
                    if (pos == Player.Positions.INVALID)
                    {
                        continue;
                    }

                    int salary;
                    Int32.TryParse(values[5], out salary);
                    double points;
                    Double.TryParse(values[8], out points);

                    Player player = new Player(pos, values[2], uniqueID++, salary, points);
                    teamGenerator.addPlayer(player);
                }
                reader.Close();
                return(teamGenerator);
            }

            return(null);
        }