Пример #1
0
        private void btnConfirmAddingPlayer_Click(object sender, RoutedEventArgs e)
        {
            ClearTeamsInterface();

            var               selectedTeam     = cbToEditOrAddTeams.SelectedItem;
            var               selectedPosition = cbToEditOrAddPositions.SelectedItem;
            Positions         position         = selectedPosition as Positions;
            Teams             team             = selectedTeam as Teams;
            BasketballPlayers player1          = new BasketballPlayers();

            GetPlayerFromForm(player1, team, position);

            var errMsg = CombinedPlayerCheck(player1);

            player1.CheckPlayerPicture(player1);

            if (!string.IsNullOrEmpty(errMsg))
            {
                ToLog(errMsg, MessageBoxImage.Error);
                UpdateInterface();
                return;
            }

            FilePath.Append(player1);

            UpdateInterface();
            ToLog($"{player1.Name} was successfully added", MessageBoxImage.Information);

            ClearPlayersInterface();
        }
Пример #2
0
        public MainWindow()
        {
            InitializeComponent();
            FilePath = new DBProcessing(_myConnectionString);
            var teams   = FilePath.GetTeams();
            var players = FilePath.GetBasketballPlayers();
            var image   = new MenuImagesProcessing();

            foreach (var item in teams)
            {
                item.BasketballPlayers = players;
            }
            var basketballPlayer = new BasketballPlayers();
            var team             = new Teams();

            foreach (var item in players)
            {
                basketballPlayer.CheckPlayerPicture(item);
            }
            foreach (var item in teams)
            {
                team.CheckTeamPicture(item);
            }
            foreach (var item in teams)
            {
                item.BasketballPlayers = basketballPlayer.RelatePlayerToATeam(item, players);;
            }
            _teamsList   = teams;
            _teamsToSort = teams;
            connection   = new MySqlConnection(_myConnectionString);
            _positions   = FilePath.GetPositions();

            //_menuImages = image.GetImagesFromFile();
        }
        public override BindingList <BasketballPlayers> GetBasketballPlayers()
        {
            _mysqlDataAdapter = new MySqlDataAdapter("SELECT id, picture, name, age, career_age, height, weight, (SELECT team_name FROM teams WHERE ID = id_team) AS team," +
                                                     " (SELECT position FROM positions WHERE ID = id_position) AS position FROM basketballplayers", sqlConnection);
            BindingList <BasketballPlayers> playersToReturn = new BindingList <BasketballPlayers>();

            _dataset = new DataSet();
            _mysqlDataAdapter.Fill(_dataset);
            DataTable dt = _dataset.Tables[0];

            foreach (DataRow item in dt.Rows)
            {
                BasketballPlayers player = new BasketballPlayers();
                player.ID           = Convert.ToInt32(item[0]);
                player.Picture      = Convert.ToString(item[1]);
                player.Name         = Convert.ToString(item[2]);
                player.Age          = Convert.ToInt32(item[3]);
                player.Career_age   = Convert.ToInt32(item[4]);
                player.Height       = Convert.ToDouble(item[5]);
                player.Weight       = Convert.ToInt32(item[6]);
                player.Current_team = Convert.ToString(item[7]);
                player.Position     = Convert.ToString(item[8]);
                playersToReturn.Add(player);
            }
            return(playersToReturn);
        }
Пример #4
0
        private void btnSortResults_Click(object sender, RoutedEventArgs e)
        {
            _toSort          = true;
            _toCompleteEvent = true;
            var team    = lvTeamsOutput.SelectedItem as Teams;
            var players = team.BasketballPlayers;
            BasketballPlayers player = new BasketballPlayers();
            Positions         temp   = new Positions();

            if (cbSortPosition.SelectedItem != null)
            {
                temp = cbSortPosition.SelectedItem as Positions;
            }

            var pos    = temp.Position;
            int toSort = 0;

            if (!string.IsNullOrEmpty(tbSortByAge.Text))
            {
                toSort = Convert.ToInt32(tbSortByAge.Text);
            }


            players = player.SortPlayers(players, pos, tbSortByName.Text, toSort);


            lvPlayers.ItemsSource = null;
            lvPlayers.ItemsSource = players;
            _toCompleteEvent      = false;
        }
Пример #5
0
        private void lvPlayers_MouseDoubleClickEditing(object sender, MouseButtonEventArgs e)
        {
            ClearTeamsInterface();
            var selectedPlayer       = lvPlayers.SelectedItem;
            BasketballPlayers player = selectedPlayer as BasketballPlayers;

            tbGetAge.Text       = player.Age.ToString();
            tbGetCareerAge.Text = player.Career_age.ToString();
            tbGetHeight.Text    = player.Height.ToString();
            tbGetWeight.Text    = player.Weight.ToString();
            tbGetName.Text      = player.Name;
            tbToShowPlayerPictureFilePath.Text = player.Picture;
            _playerIMG = player.Picture;
            int teamNameIndex = 0;
            int positionIndex = 0;

            for (int i = 0; i < _teamsList.Count; i++)
            {
                if (player.Current_team == _teamsList[i].TeamName)
                {
                    teamNameIndex = i;
                }
            }
            for (int i = 0; i < _positions.Count; i++)
            {
                if (player.Position == _positions[i].Position)
                {
                    positionIndex = i;
                }
            }
            cbToEditOrAddPositions.SelectedIndex       = positionIndex;
            cbToEditOrAddTeams.SelectedIndex           = teamNameIndex;
            gridEditingPlayers.Visibility              = Visibility.Visible;
            gridBtnsToConfirmEditingPlayers.Visibility = Visibility.Visible;
        }
Пример #6
0
        public XmlElement GetXMLPlayer(BasketballPlayers player, XmlDocument xdoc)
        {
            XmlElement xmlPlayer = xdoc.CreateElement("player");

            XmlElement positionElem = xdoc.CreateElement("position");

            xmlPlayer.AppendChild(positionElem);

            XmlElement nameElem = xdoc.CreateElement("name");

            xmlPlayer.AppendChild(nameElem);

            XmlElement teamElem = xdoc.CreateElement("current_team");

            xmlPlayer.AppendChild(teamElem);

            XmlElement ageElem = xdoc.CreateElement("age");

            xmlPlayer.AppendChild(ageElem);

            XmlElement careerElem = xdoc.CreateElement("career_age");

            xmlPlayer.AppendChild(careerElem);

            XmlElement heightElem = xdoc.CreateElement("height");

            xmlPlayer.AppendChild(heightElem);

            XmlElement weightElem = xdoc.CreateElement("weight");

            xmlPlayer.AppendChild(weightElem);

            XmlElement pictureElem = xdoc.CreateElement("picture");

            xmlPlayer.AppendChild(pictureElem);


            XmlText positionText = xdoc.CreateTextNode(player.Position);
            XmlText nameText     = xdoc.CreateTextNode(player.Name);
            XmlText teamText     = xdoc.CreateTextNode(player.Current_team);
            XmlText ageText      = xdoc.CreateTextNode(player.Age.ToString());
            XmlText careerText   = xdoc.CreateTextNode(player.Career_age.ToString());
            XmlText heightText   = xdoc.CreateTextNode(player.Height.ToString());
            XmlText weightText   = xdoc.CreateTextNode(player.Weight.ToString());
            XmlText pictureText  = xdoc.CreateTextNode(player.Picture);


            positionElem.AppendChild(positionText);
            nameElem.AppendChild(nameText);
            teamElem.AppendChild(teamText);
            ageElem.AppendChild(ageText);
            careerElem.AppendChild(careerText);
            heightElem.AppendChild(heightText);
            weightElem.AppendChild(weightText);
            pictureElem.AppendChild(pictureText);

            return(xmlPlayer);
        }
Пример #7
0
        //private void UAErrorCallback(Control control)
        //{
        //    control.BorderBrush = Brushes.Red;
        //    control.Focus();
        //}


        private string CombinedPlayerCheck(BasketballPlayers player)
        {
            string check = null;

            if (string.IsNullOrEmpty(player.Name))
            {
                //UAErrorCallback(tbGetName);

                check = "Enter NAME, please!";
                return(check);
            }
            if (string.IsNullOrEmpty(player.Position))
            {
                check = "Select positon, please!";
                return(check);
            }
            if (string.IsNullOrEmpty(player.Current_team))
            {
                check = "Select team, please!";
                return(check);
            }
            if (string.IsNullOrEmpty(tbGetAge.Text))
            {
                check = "Enter the age, please!";
                return(check);
            }
            if (string.IsNullOrEmpty(tbGetCareerAge.Text))
            {
                check = "Enter the career age, please!";
                return(check);
            }
            if (string.IsNullOrEmpty(tbGetHeight.Text))
            {
                check = "Enter height, please!";
                return(check);
            }
            if (string.IsNullOrEmpty(tbGetWeight.Text))
            {
                check = "Select weight, please!";
                return(check);
            }

            if (player.Age == -1 || player.Career_age == -1 || player.Height == -1 || player.Weight == -1)
            {
                check = "Please, enter the number";
                ClearPlayersInterface();
                return(check);
            }
            if (player.PlayerAdequacyCheck())
            {
                check = "The parameters you've entered can not exist";
                ClearPlayersInterface();
                return(check);
            }

            return(check);
        }
Пример #8
0
        private void btnConfirmDeletingPlayer_Click(object sender, RoutedEventArgs e)
        {
            var player = lvPlayers.SelectedValue;
            BasketballPlayers player1 = player as BasketballPlayers;
            string            message = player1.Name;

            FilePath.Delete(player1);
            UpdateInterface();
            ToLog($"{message} was successfully removed", MessageBoxImage.Information);
            ClearPlayersInterface();
        }
Пример #9
0
        public override BindingList <BasketballPlayers> GetPlayersFromFile()
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.Load(FileProcessingPath);
            XmlElement root = xdoc.DocumentElement;
            BindingList <BasketballPlayers> playerToReturn = new BindingList <BasketballPlayers>();

            foreach (XmlNode item in root)
            {
                BasketballPlayers player = new BasketballPlayers();
                foreach (XmlNode node in item.ChildNodes)
                {
                    if (node.Name == "name")
                    {
                        player.Name = node.InnerText;
                    }
                    if (node.Name == "position")
                    {
                        player.Position = node.InnerText;
                    }
                    if (node.Name == "picture")
                    {
                        player.Picture = node.InnerText;
                    }
                    if (node.Name == "current_team")
                    {
                        player.Current_team = node.InnerText;
                    }
                    if (node.Name == "age")
                    {
                        player.Age = Convert.ToInt32(node.InnerText);
                    }
                    if (node.Name == "career_age")
                    {
                        player.Career_age = Convert.ToInt32(node.InnerText);
                    }
                    if (node.Name == "height")
                    {
                        player.Height = Convert.ToDouble(node.InnerText);
                    }
                    if (node.Name == "weight")
                    {
                        player.Weight = Convert.ToInt32(node.InnerText);
                    }
                }
                playerToReturn.Add(player);
            }
            return(playerToReturn);
        }
Пример #10
0
        public int GetPlayersPositionID(BasketballPlayers player)
        {
            BindingList <Positions> currentPositions = GetPositions();
            int id_position = 0;

            foreach (var position in currentPositions)
            {
                if (position.Position == player.Position)
                {
                    id_position = position.ID;
                    return(id_position);
                }
            }
            return(id_position);
        }
Пример #11
0
        public int GetPlayersTeamID(BasketballPlayers player)
        {
            BindingList <Teams> currentTeams = GetTeams();
            int id_team = 0;

            foreach (var currentTeam in currentTeams)
            {
                if (currentTeam.TeamName == player.Current_team)
                {
                    id_team = currentTeam.ID;
                    return(id_team);
                }
            }
            return(id_team);
        }
        public override BindingList <BasketballPlayers> GetPlayersFromFile()
        {
            BindingList <BasketballPlayers> playersToOutput = new BindingList <BasketballPlayers>();


            XSSFWorkbook workbook;

            using (FileStream fs = new FileStream(FileProcessingPath, FileMode.Open, FileAccess.Read))
            {
                workbook = new XSSFWorkbook(fs);
            }

            ISheet sheet = workbook.GetSheet("Sheet0");


            for (int row = 1; row <= sheet.LastRowNum; row++)
            {
                BasketballPlayers player = new BasketballPlayers();
                if (sheet.GetRow(row) != null)
                {
                    //if (sheet.GetRow(row).GetCell(1).ToString() != null && sheet.GetRow(row).GetCell(2).ToString() != null && sheet.GetRow(row).GetCell(7).ToString() != null &&
                    //    sheet.GetRow(row).GetCell(3).ToString() != null && sheet.GetRow(row).GetCell(5).ToString() != null && sheet.GetRow(row).GetCell(6).ToString() != null &&
                    //    sheet.GetRow(row).GetCell(4).ToString() != null && sheet.GetRow(row).GetCell(0).ToString() != null)
                    {
                        player.Picture  = sheet.GetRow(row).GetCell(0).ToString();
                        player.Name     = sheet.GetRow(row).GetCell(1).ToString();
                        player.Position = sheet.GetRow(row).GetCell(2).ToString();


                        player.Age = EditingInfo.ConvertNumber(sheet.GetRow(row).GetCell(3).ToString());

                        player.Career_age = EditingInfo.ConvertNumber(sheet.GetRow(row).GetCell(4).ToString());

                        player.Height = EditingInfo.ConvertNumberToDouble(sheet.GetRow(row).GetCell(5).ToString());

                        player.Weight = EditingInfo.ConvertNumber(sheet.GetRow(row).GetCell(6).ToString());

                        player.Current_team = sheet.GetRow(row).GetCell(7).ToString();

                        playersToOutput.Add(player);
                    }
                }
            }
            return(playersToOutput);
        }
Пример #13
0
        private void btnConfirmEditingPlayer_Click(object sender, RoutedEventArgs e)
        {
            var               selectedTeam                 = cbToEditOrAddTeams.SelectedItem;
            var               selectedPosition             = cbToEditOrAddPositions.SelectedItem;
            Positions         position                     = selectedPosition as Positions;
            Teams             team                         = selectedTeam as Teams;
            var               player                       = lvPlayers.SelectedValue;
            BasketballPlayers player1                      = player as BasketballPlayers;
            BindingList <BasketballPlayers> currentPlayers = FilePath.GetBasketballPlayers();
            string message = player1.Name;

            GetPlayerFromForm(player1, team, position);


            var errMsg = CombinedPlayerCheck(player1);

            if (!string.IsNullOrEmpty(errMsg))
            {
                ToLog(errMsg, MessageBoxImage.Error);
                UpdateInterface();
                return;
            }
            player1.CheckPlayerPicture(player1);
            foreach (var item in currentPlayers)
            {
                if (player1.ID == item.ID)
                {
                    currentPlayers.Remove(item);
                    currentPlayers.Add(player1);
                    break;
                }
            }

            FilePath.SaveData(currentPlayers);

            UpdateInterface();
            ToLog($"{message} was successfully edited", MessageBoxImage.Information);

            ClearPlayersInterface();
        }
Пример #14
0
        private void lvTeamsOutput_SelectionChanged(object sender, RoutedEventArgs e)
        {
            if (_toCompleteEvent)
            {
                return;
            }

            var str = lvTeamsOutput.SelectedValue;

            Teams str1    = str as Teams;
            var   players = str1.BasketballPlayers;

            if (_toSort)
            {
                BasketballPlayers player = new BasketballPlayers();
                Positions         temp   = new Positions();
                if (cbSortPosition.SelectedItem != null)
                {
                    temp = cbSortPosition.SelectedItem as Positions;
                }

                var pos    = temp.Position;
                int toSort = 0;
                if (!string.IsNullOrEmpty(tbSortByAge.Text))
                {
                    toSort = Convert.ToInt32(tbSortByAge.Text);
                }


                players = player.SortPlayers(players, pos, tbSortByName.Text, toSort);
            }
            lvPlayers.ItemsSource = players;

            lvPlayers.Visibility         = Visibility.Visible;
            gridPlayerButtons.Visibility = Visibility.Visible;
            ClearPlayersInterface();
            ClearTeamsInterface();
        }
Пример #15
0
        private BasketballPlayers GetPlayerFromForm(BasketballPlayers player, Teams team, Positions position)
        {
            //if (!string.IsNullOrEmpty(team.TeamName))
            //{
            player.Current_team = team.TeamName;
            //}
            //if (!string.IsNullOrEmpty(tbGetName.Text))
            //{
            player.Name = tbGetName.Text;
            //}
            //if (!string.IsNullOrEmpty(tbGetAge.Text))
            //{
            player.Age = EditingInfo.ConvertNumber(tbGetAge.Text);
            //}
            //if (!string.IsNullOrEmpty(tbGetCareerAge.Text))
            //{
            player.Career_age = EditingInfo.ConvertNumber(tbGetCareerAge.Text);
            //}
            //if (!string.IsNullOrEmpty(tbGetHeight.Text))
            //{
            player.Height = EditingInfo.ConvertNumberToDouble(tbGetHeight.Text);
            //}
            //if (!string.IsNullOrEmpty(tbGetWeight.Text))
            //{
            player.Weight = EditingInfo.ConvertNumber(tbGetWeight.Text);
            //}
            //if (!string.IsNullOrEmpty(position.Position))
            //{
            player.Position = position.Position;
            //}
            //if (!string.IsNullOrEmpty(_playerIMG))
            //{
            player.Picture = tbToShowPlayerPictureFilePath.Text;
            //}

            return(player);
        }
Пример #16
0
        public override BindingList <BasketballPlayers> GetPlayersFromFile()
        {
            BindingList <BasketballPlayers> players = new BindingList <BasketballPlayers>();
            List <string> fileContent = new List <string>();

            using (StreamReader sr = new StreamReader(FileProcessingPath))
            {
                string line = null;
                while ((line = sr.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    fileContent.Add(line);
                }
            }
            for (int i = 1; i < fileContent.Count; i++)
            {
                var array = fileContent[i].Split(",");
                BasketballPlayers player = new BasketballPlayers();
                //if (!string.IsNullOrEmpty(array[0]) || !string.IsNullOrEmpty(array[1]) || !string.IsNullOrEmpty(array[2]) ||
                //    !string.IsNullOrEmpty(array[3]) || !string.IsNullOrEmpty(array[4]) || !string.IsNullOrEmpty(array[5]) ||
                //    !string.IsNullOrEmpty(array[6]) || !string.IsNullOrEmpty(array[7])) {
                player.Name         = array[0];
                player.Current_team = array[1];
                player.Picture      = array[2];
                player.Age          = Convert.ToInt32(array[3]);
                player.Career_age   = Convert.ToInt32(array[4]);
                player.Height       = Convert.ToDouble(array[5]);
                player.Weight       = Convert.ToInt32(array[6]);
                player.Position     = array[7];
                players.Add(player);
                //}
            }
            return(players);
        }
Пример #17
0
        private void UpdateInterface()
        {
            _toCompleteEvent = true;
            var teams   = FilePath.GetTeams();
            var players = FilePath.GetBasketballPlayers();

            foreach (var item in players)
            {
                item.CheckPlayerPicture(item);
            }
            foreach (var item in teams)
            {
                item.BasketballPlayers = players;
            }
            var basketballPlayer = new BasketballPlayers();

            foreach (var item in teams)
            {
                item.BasketballPlayers = basketballPlayer.RelatePlayerToATeam(item, players);;
            }
            lvTeamsOutput.ItemsSource = null;
            lvTeamsOutput.ItemsSource = teams;
            _toCompleteEvent          = false;
        }