/// <summary>
        /// 
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static void InsertGameData(XmlNode node, Player player)
        {
            if (node.ChildNodes.Count != 19) throw new ArgumentException("Invalid number of childred in node. Maybe json has been updated");
            PlayerGameData gameData = new PlayerGameData();
            gameData.player = player.ID;
            gameData.gameweek = int.Parse(node.ChildNodes[1].InnerText);
            int otherTeam = new Team(node.ChildNodes[2].InnerText.Substring(0, 3)).teamID;

            if ((gameData.game = DataAccess.Instance.GetGameIDByTeams(otherTeam, Form1.SEASON, gameData.gameweek, out gameData.team)) == 0)
            {
                throw new ArgumentOutOfRangeException("Game could not be found");
            }
            gameData.played = int.Parse(node.ChildNodes[3].InnerText);
            gameData.goals = int.Parse(node.ChildNodes[4].InnerText);
            gameData.assist = int.Parse(node.ChildNodes[5].InnerText);
            gameData.cleansheets = int.Parse(node.ChildNodes[6].InnerText);
            gameData.conceded = int.Parse(node.ChildNodes[7].InnerText);
            gameData.ownGoal = int.Parse(node.ChildNodes[8].InnerText);
            gameData.pensave = int.Parse(node.ChildNodes[9].InnerText);
            gameData.penmiss = int.Parse(node.ChildNodes[10].InnerText);
            gameData.yellow = int.Parse(node.ChildNodes[11].InnerText);
            gameData.red = int.Parse(node.ChildNodes[12].InnerText);
            gameData.saves = int.Parse(node.ChildNodes[13].InnerText);
            gameData.bonus = int.Parse(node.ChildNodes[14].InnerText);
            gameData.EAsports = int.Parse(node.ChildNodes[15].InnerText);
            gameData.transfer = int.Parse(node.ChildNodes[16].InnerText);
            gameData.value = double.Parse(node.ChildNodes[17].InnerText);
            gameData.total = int.Parse(node.ChildNodes[18].InnerText);

            if(gameData.played>0)gameData.Insert();
        }
        public Boolean AddPlayer(Player player)
        {
            if (m_price + player.Price <= TEAMPRICE)
            {

                if (IsValidFormation(player.Position))
                {
                    m_form += player.Form;
                    m_price += player.Price;
                    m_points += player.Points;
                    m_PositionCounts[(int)player.Position]++;
                    m_Players.Add(player);
                    return true;
                }
                return false;
            }
            return false;
        }
 public void RemovePlayer(Player p)
 {
     m_Players.Remove(p);
     m_form -= p.Form;
     m_price -= p.Price;
     m_points -= p.Points;
     m_PositionCounts[(int)p.Position]--;
 }
        public Boolean IsValidFormation(Player.Positions position)
        {
            int positionIndex = (int) position;
            if (m_PositionCounts[positionIndex] + 1 <= m_PositionMax[positionIndex])
            {
                int playersNeededNotInThisPosition = 0;
                for (int x = 0; x < 4; x++)
                {
                    if (x != positionIndex) playersNeededNotInThisPosition += Math.Max(m_PositionMin[x] - m_PositionCounts[x],0);

                }
                return (PlayersNeeded - 1) >= playersNeededNotInThisPosition;
            }
            else return false;
        }
        public bool UpdatePlayer(Player P)
        {
            SqlCommand cmd = MyConnection.CreateCommand();

            cmd.CommandText = "UPDATE Players SET Team = @Team, LastName = @LastName, Position = @Position, FLID = @FLID, Active = @Active, Price = @Price, FirstName = @FirstName, PhotoURL = @PhotoURL WHERE ID = @ID";

            cmd.Parameters.Add(new SqlParameter("@Team", P.TeamID));
            cmd.Parameters.Add(new SqlParameter("@LastName", P.PlayerName));
            cmd.Parameters.Add(new SqlParameter("@Position", System.Enum.GetName(typeof(Player.Positions), P.Position)));
            cmd.Parameters.Add(new SqlParameter("@FLID", P.FLID));
            cmd.Parameters.Add(new SqlParameter("@Active", P.Active ? 1 : 0));
            cmd.Parameters.Add(new SqlParameter("@Price", P.Price));
            cmd.Parameters.Add(new SqlParameter("@ID", P.ID));
            cmd.Parameters.AddWithValue("@FirstName", P.FirstName);
            cmd.Parameters.AddWithValue("@PhotoURL", P.PhotoURL);

            MyConnection.Open();
            int result = cmd.ExecuteNonQuery();
            MyConnection.Close();
            return result == 1;
        }
        public List<Player> GetPlayers(params string[] parameters)
        {
            SqlCommand cmd = MyConnection.CreateCommand();
            List<Player> players = new List<Player>();
            cmd.CommandText = "SELECT * FROM Players";
            cmd.CommandText += WhereClauseInterpreter(parameters);
            MyConnection.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                Player player = new Player()
                {
                    Price = GetDBDouble(reader, "Price"),
                    ID = GetDBInt(reader, "ID"),
                    PlayerName = GetDBString(reader, "LastName"),
                    TeamID = GetDBInt(reader, "Team"),
                    Active = GetDBBool(reader, "Active"),
                    FLID = GetDBInt(reader, "FLID"),
                    Points = GetDBDouble(reader, "TotalPredicted"),
                    FirstName = GetDBString (reader, "FirstName"),
                    PhotoURL = GetDBString(reader, "PhotoURL"),
                    Position = Player.GetPositionFromString(GetDBString(reader, "Position")),
                };
                players.Add(player);
            }
            MyConnection.Close();
            return players;
        }