Esempio n. 1
0
        private void ShowdownToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <Player>  players = new List <Player>();
            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);
                    players.Add(player);
                }
                reader.Close();
            }

            if (players.Count < 6)
            {
                return;
            }

            Showdown_Player_Form form = new Showdown_Player_Form(players);

            form.Show();
        }
Esempio n. 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[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);
        }