Пример #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();
                }
            }
        }
Пример #2
0
        private List <string> FillClubComboBox()
        {
            List <string> clubList = new List <string>();

            for (int i = 0; i < FootballClubInfo.Count; i++)
            {
                clubList.Add(FootballClubInfo.GetNazev(i));
            }
            return(clubList);
        }
Пример #3
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);
        }
Пример #4
0
 public void RefreshGridView()
 {
     playersGridView.Rows.Clear();
     for (int i = 0; i < players.Count; i++)
     {
         Player p = players[i];
         playersGridView.Rows.Add(p.Name, FootballClubInfo.GetNazev((int)p.Club), p.GoalCount);
         playersGridView.Update();
         playersGridView.Refresh();
     }
 }
Пример #5
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;
         }
     }
 }
Пример #6
0
 public PlayerForm(ChampionsLeagueForm ParentForm)
 {
     InitializeComponent();
     clubComboBox.DataSource = FillClubComboBox();
     this.MainForm           = ParentForm;
     if (!ParentForm.addingProcedure)
     {
         formerPlayer              = ParentForm.GetSelectedRow();
         nameTextBox.Text          = formerPlayer.Name;
         clubComboBox.SelectedItem = FootballClubInfo.GetNazev((int)formerPlayer.Club);
         goalCountUpDown.Value     = formerPlayer.GoalCount;
     }
 }
Пример #7
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;
             }
         }
     }
 }
Пример #8
0
        private void FillDialog()
        {
            if (MainForm.players[0] == null)
            {
                goalsCountTextBox.Text = "0";
                clubListBox.Items.Clear();
                return;
            }

            var bestClubs = MainForm.players.FindBestClubs();

            goalsCountTextBox.Text = bestClubs.Item2.ToString();
            foreach (FootballClub v in bestClubs.Item1)
            {
                clubListBox.Items.Add(FootballClubInfo.GetNazev((int)v));
            }
        }
Пример #9
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();
        }
Пример #10
0
 private void AddPlayer()
 {
     MainForm.players.Add(new Player(nameTextBox.Text, FootballClubInfo.GetEnumType(clubComboBox.Text), (int)goalCountUpDown.Value));
 }