Exemplo n.º 1
0
        private void LoadBtn_Click(object sender, EventArgs e)
        {
            var fileContent = string.Empty;
            var filePath    = string.Empty;

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Get the path of specified file
                filePath = openFileDialog.FileName;

                //Read the contents of the file into a stream
                var fileStream = openFileDialog.OpenFile();

                using (StreamReader reader = new StreamReader(fileStream))
                {
                    string row;
                    while ((row = reader.ReadLine()) != null)
                    {
                        string[] words = row.Split(' ');
                        int.TryParse(words[2], out int goalCount);
                        players.Add(new Player(words[0], FootballClubInfo.GetEnumType(words[1]), goalCount));
                        RefreshGridView();
                    }
                    fileContent = reader.ReadToEnd();
                }
            }
        }
Exemplo n.º 2
0
        public Player GetSelectedRow()
        {
            Player p = new Player
            {
                Name      = (string)playersGridView.CurrentRow.Cells[0].Value,
                Club      = FootballClubInfo.GetEnumType((string)playersGridView.CurrentRow.Cells[1].Value),
                GoalCount = (int)playersGridView.CurrentRow.Cells[2].Value
            };

            return(p);
        }
Exemplo n.º 3
0
 private void ModifyPlayer()
 {
     for (int i = 0; i < MainForm.players.Count; i++)
     {
         if (MainForm.players[i].Equals(formerPlayer))
         {
             MainForm.players[i].Name      = nameTextBox.Text;
             MainForm.players[i].Club      = FootballClubInfo.GetEnumType(clubComboBox.Text);
             MainForm.players[i].GoalCount = (int)goalCountUpDown.Value;
         }
     }
 }
Exemplo n.º 4
0
 private void GetAllClubsInList()
 {
     for (int i = 0; i < FootballClubInfo.Count; i++)
     {
         for (int j = 0; j < MainForm.players.Count; j++)
         {
             if (MainForm.players[j].Club.Equals(FootballClubInfo.GetEnumType(FootballClubInfo.GetNazev(i))))
             {
                 teamsToSaveListBox.Items.Add(FootballClubInfo.GetNazev(i));
                 break;
             }
         }
     }
 }
Exemplo n.º 5
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            if (teamsToSaveListBox.SelectedItems.Count == 0)
            {
                MessageBox.Show(
                    "Please select at least one team.", "Input Error", MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                return;
            }

            Stream         myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog
            {
                Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*",
                FilterIndex      = 2,
                RestoreDirectory = true
            };

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    StreamWriter wText = new StreamWriter(myStream);
                    for (int i = 0; i < teamsToSaveListBox.SelectedItems.Count; i++)
                    {
                        for (int j = 0; j < MainForm.players.Count; j++)
                        {
                            if (MainForm.players[j].Club.Equals(FootballClubInfo.GetEnumType((string)teamsToSaveListBox.SelectedItems[i])))
                            {
                                wText.WriteLine(MainForm.players[j].Name + " " + MainForm.players[j].Club + " " + MainForm.players[j].GoalCount);
                            }
                        }
                    }
                    wText.Close();
                    myStream.Close();
                }
            }
            this.Close();
        }
Exemplo n.º 6
0
 private void AddPlayer()
 {
     MainForm.players.Add(new Player(nameTextBox.Text, FootballClubInfo.GetEnumType(clubComboBox.Text), (int)goalCountUpDown.Value));
 }