private void button_Remove_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((gridTournaments.SelectedItem == null) && (gridTournaments.ItemsSource != null))
                {
                    MessageBox.Show("Choose a player that you want to remove", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                if (gridTournaments.ItemsSource == null)
                {
                    MessageBox.Show("List of players is empty! \nTry to load information from the file firstly.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);;
                }

                Tournaments selected_tournament = gridTournaments.SelectedItem as Tournaments;
                for (int i = TournamentsInfo.Count - 1; i >= 0; i--)
                {
                    if (TournamentsInfo[i] == selected_tournament)
                    {
                        TournamentsInfo.Remove(TournamentsInfo[i]);
                    }
                }
                gridTournaments.ItemsSource = TournamentsInfo;
            }
            catch
            {
                MessageBox.Show("Removing is impossible", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public void NewTournamentAdded(Tournaments newTournament)
        {
            TournamentsInfo.Add(newTournament);
            gridTournaments.ItemsSource = null;
            gridTournaments.Columns.Clear();
            gridTournaments.ItemsSource = TournamentsInfo;
            string[] names = new string[TournamentsInfo.Count];
            for (int i = 0; i < TournamentsInfo.Count; i++)
            {
                names[i] = TournamentsInfo[i].TName;
            }

            cbSearch.ItemsSource = names;
        }
        private void button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                gridTournaments.ItemsSource = null;
                gridTournaments.Columns.Clear();
                TournamentsInfo.Clear();
                string[] tournamentsMass = File.ReadAllLines(FileNameT, Encoding.GetEncoding(1251));
                for (int i = 0; i < 72; i++)
                {
                    string[]    TournamentsMass1 = tournamentsMass[i].Split(new char[] { ';' });
                    string[]    SupervisorsMass1 = tournamentsMass[i + 72].Split(new char[] { ';' });
                    Supervisors exampleS         = new Supervisors(SupervisorsMass1[0], SupervisorsMass1[1]);
                    Tournaments exampleT         = new Tournaments(TournamentsMass1[0], TournamentsMass1[1], TournamentsMass1[2], TournamentsMass1[3], TournamentsMass1[4], int.Parse(TournamentsMass1[5]), TournamentsMass1[6]);
                    exampleT.Supervisor = exampleS.Name.ToString();

                    TournamentsInfo.Add(exampleT);
                }

                gridTournaments.ItemsSource = TournamentsInfo;
                if (label_edit.Content.ToString() == "Edit mode")
                {
                    button_Remove.IsEnabled = true;
                }

                string[] names = new string[TournamentsInfo.Count];
                for (int i = 0; i < TournamentsInfo.Count; i++)
                {
                    names[i] = TournamentsInfo[i].TName;
                }

                cbSearch.ItemsSource = names;
            }
            catch
            {
                MessageBox.Show("File wasn't loaded", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #4
0
        private void button_AddNewTournament_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(textBox_City.Text))
                {
                    MessageBox.Show("Enter your tournament's city", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    textBox_City.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(textBox_Name.Text))
                {
                    MessageBox.Show("Enter your tournament's name", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    textBox_Name.Focus();
                    return;
                }

                if (string.IsNullOrWhiteSpace(textBox_Country.Text))
                {
                    MessageBox.Show("Enter your tournament's country", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    textBox_Country.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(textBox_PrizeMoney.Text))
                {
                    MessageBox.Show("Enter your tournament's prize money", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    textBox_PrizeMoney.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(textBox_Supervisor.Text))
                {
                    MessageBox.Show("Enter your tournament's supervisor", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    textBox_Supervisor.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(textBox_SupervisorNation.Text))
                {
                    MessageBox.Show("Enter your supervisor's native country", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    textBox_SupervisorNation.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(comboBoxDateMonth_1.Text))
                {
                    MessageBox.Show("Choose your tournament's date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBoxDateMonth_1.Focus();
                    return;
                }

                if (string.IsNullOrWhiteSpace(comboBox_DateDay2.Text))
                {
                    MessageBox.Show("Choose your tournament's date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBox_DateDay2.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(comboBox_DateDay_1.Text))
                {
                    MessageBox.Show("Choose your tournament's date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBox_DateDay_1.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(comboBox_DateMonth2.Text))
                {
                    MessageBox.Show("Choose your tournament's date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBox_DateMonth2.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(comboBox_PrizeMoney.Text))
                {
                    MessageBox.Show("Choose currency of your tournament's przie money", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBox_PrizeMoney.Focus();
                    return;
                }

                if (string.IsNullOrWhiteSpace(comboBox_Surface.Text))
                {
                    MessageBox.Show("Choose your tournament's surface", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBox_Surface.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(comboBox_Surface1.Text))
                {
                    MessageBox.Show("Choose your tournament's surface", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBox_Surface1.Focus();
                    return;
                }
                if (string.IsNullOrWhiteSpace(comboBox_Category.Text))
                {
                    MessageBox.Show("Choose your tournament's surface", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    comboBox_Surface1.Focus();
                    return;
                }
                if (((comboBox_DateDay_1.Text == "30") || (comboBox_DateDay_1.Text == "31")) && (comboBoxDateMonth_1.Text == "FEB"))
                {
                    MessageBox.Show("Incorrect date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if (((comboBox_DateDay2.Text == "30") || (comboBox_DateDay2.Text == "31")) && (comboBox_DateMonth2.Text == "FEB"))
                {
                    MessageBox.Show("Incorrect date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if ((comboBox_DateDay_1.Text == "31") && ((comboBoxDateMonth_1.Text == "APR") || (comboBoxDateMonth_1.Text == "JUN") || (comboBoxDateMonth_1.Text == "SEP") || (comboBoxDateMonth_1.Text == "NOV")))
                {
                    MessageBox.Show("Incorrect date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                if ((comboBox_DateDay2.Text == "31") && ((comboBox_DateMonth2.Text == "APR") || (comboBox_DateMonth2.Text == "JUN") || (comboBox_DateMonth2.Text == "SEP") || (comboBox_DateMonth2.Text == "NOV")))
                {
                    MessageBox.Show("Incorrect date", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
                _addedTournament = new Tournaments(comboBox_DateDay_1.Text + " " + comboBoxDateMonth_1.Text + " - " + comboBox_DateDay2.Text + " " + comboBox_DateMonth2.Text, textBox_Name.Text,
                                                   textBox_City.Text, textBox_Country.Text, comboBox_Surface.Text + " " + comboBox_Surface1.Text, int.Parse(comboBox_Category.Text), comboBox_PrizeMoney.Text + textBox_PrizeMoney.Text);
                _addedTournament.Supervisor = textBox_Supervisor.Text;


                string[] supervisorsMass = File.ReadAllLines(FileNameS, Encoding.GetEncoding(1251));
                for (int i = 0; i < supervisorsMass.Length; i++)
                {
                    string[]    SupervisorsMass1 = supervisorsMass[i].Split(new char[] { ';' });
                    Supervisors exampleS         = new Supervisors(SupervisorsMass1[0], SupervisorsMass1[1]);
                    SupervisorsInfo.Add(exampleS);
                }
                int count = 0;
                int Count = 0;
                for (int i = 0; i < SupervisorsInfo.Count; i++)
                {
                    if (textBox_Supervisor.Text == SupervisorsInfo[i].Name)
                    {
                        count += 1;
                    }
                    else
                    {
                        Count += 1;
                    }
                }

                if (Count == SupervisorsInfo.Count)
                {
                    Supervisors newsupervisor = new Supervisors(textBox_Supervisor.Text, textBox_SupervisorNation.Text);
                    SupervisorsInfo.Add(newsupervisor);
                }

                RegPages.TournamentPage.NewTournamentAdded(_addedTournament);
                NavigationService.GoBack();
            }
            catch
            {
                MessageBox.Show("Add function is impossible", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }