public void updatePlayerPosition(Player player) throws SQLException {
   PreparedStatement pstm =
       connection.prepareStatement("UPDATE player SET id_position = ? WHERE id_player = ?");
   pstm.setInt(1, player.getPosition());
   pstm.setInt(2, player.getId());
   pstm.executeUpdate();
   pstm.close();
 }
 public void updatePlayerSoldPrice(Player player) throws SQLException {
   PreparedStatement pstm =
       connection.prepareStatement("UPDATE player SET sold_price = ? WHERE id_player = ?");
   pstm.setDouble(1, player.getSoldPrice().getDoubleValue());
   pstm.setInt(2, player.getId());
   pstm.executeUpdate();
   pstm.close();
 }
 public void updatePlayer(Player player) throws SQLException {
   PreparedStatement pstm =
       connection.prepareStatement(
           "UPDATE player SET transfer_list = ?, national = ? WHERE id_player = ?");
   pstm.setInt(1, player.getTransferList());
   pstm.setInt(2, player.getNational());
   pstm.setInt(3, player.getId());
   pstm.executeUpdate();
   pstm.close();
 }
 public void updateUncompletedPlayer(Player player) throws SQLException {
   PreparedStatement pstm =
       connection.prepareStatement(
           "UPDATE player SET height = ?, youth_team_id = ?, exists_in_sokker = ? WHERE id_player = ?");
   pstm.setInt(1, player.getHeight());
   pstm.setInt(2, player.getYouthTeamId());
   pstm.setInt(3, Player.EXISTS_IN_SOKKER_TRUE);
   pstm.setInt(4, player.getId());
   pstm.executeUpdate();
   pstm.close();
 }
  public PlayerSkills getPlayerSkills(Player player, Training training) throws SQLException {
    PreparedStatement ps =
        connection.prepareStatement(
            "select * from player_skills where ((day >= 5 and week = ?) or (day < 5 and week = ?)) and id_player_fk = ?");
    // SokkerDate sokkerDate = null;
    PlayerSkills playerSkills = null;
    int week = training.getDate().getSokkerDate().getWeek();
    int day = training.getDate().getSokkerDate().getDay();
    if (day >= SokkerDate.THURSDAY) {
      ps.setInt(1, week);
      ps.setInt(2, week + 1);

    } else {
      ps.setInt(1, week - 1);
      ps.setInt(2, week);
    }
    ps.setInt(3, player.getId());
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
      // sokkerDate = new SokkerDate(rs.getInt("day"), rs.getInt("week"));
      playerSkills = new PlayerSkillsDto(rs).getPlayerSkills();
    }

    rs.close();
    ps.close();

    return playerSkills;
  }
 public void addPlayer(Player player) throws SQLException {
   PreparedStatement pstm =
       connection.prepareStatement(
           "INSERT INTO player(id_player,name,surname,countryfrom, id_club_fk, status, national, transfer_list, youth_team_id, height) VALUES (?, ?, ?, ?, ?, 0, ?, ?, ?, ?)");
   pstm.setInt(1, player.getId());
   pstm.setString(2, player.getName());
   pstm.setString(3, player.getSurname());
   pstm.setInt(4, player.getCountryfrom());
   pstm.setInt(5, player.getTeamId());
   pstm.setInt(6, player.getNational());
   pstm.setInt(7, player.getTransferList());
   pstm.setInt(8, player.getYouthTeamId());
   pstm.setInt(9, player.getHeight());
   pstm.executeUpdate();
   pstm.close();
 }
  public NtSkills[] getPlayerNtSkills(Player player) throws SQLException {
    List<NtSkills> listNtSkills = new ArrayList<NtSkills>();

    PreparedStatement ps;
    ps =
        connection.prepareStatement(
            "SELECT * FROM nt_player_skills WHERE id_player_fk = ? order by week, day");
    ps.setInt(1, player.getId());
    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
      NtSkills ntSkills = new PlayerNtSkillsDto(rs).getNtSkill();
      listNtSkills.add(ntSkills);
    }
    rs.close();
    ps.close();
    return listNtSkills.toArray(new NtSkills[listNtSkills.size()]);
  }
 public PlayerSkills[] getPlayerSkills(Player player, Map<Integer, Training> trainingMap)
     throws SQLException {
   List<PlayerSkills> alPlayerSkills = new ArrayList<PlayerSkills>();
   PreparedStatement ps =
       connection.prepareStatement(
           "SELECT * FROM player_skills WHERE id_player_fk = ? order by week, day");
   ps.setInt(1, player.getId());
   ResultSet rs = ps.executeQuery();
   while (rs.next()) {
     PlayerSkills playerSkills = new PlayerSkillsDto(rs).getPlayerSkills();
     playerSkills.setTraining(trainingMap.get(playerSkills.getTrainingId()));
     if (trainingMap.get(playerSkills.getTrainingId()) != null) {
       trainingMap.get(playerSkills.getTrainingId()).getPlayers().add(player);
     }
     alPlayerSkills.add(playerSkills);
   }
   rs.close();
   ps.close();
   return alPlayerSkills.toArray(new PlayerSkills[alPlayerSkills.size()]);
 }
  public void fill(List<PlayerStats> alPlayerStats) {
    this.alPlayersStats = alPlayerStats;
    this.setRedraw(false);
    this.remove(0, this.getItemCount() - 1);
    if (alPlayerStats == null) {
      this.setRedraw(true);
      return;
    }
    for (PlayerStats playerStats : alPlayerStats) {
      TableItem item = new TableItem(this, SWT.NONE);
      if (playerStats.getFormation() == PlayerStats.GK) {
        item.setBackground(Colors.getPositionGK());
      } else if (playerStats.getFormation() == PlayerStats.DEF) {
        item.setBackground(Colors.getPositionDEF());
      } else if (playerStats.getFormation() == PlayerStats.MID) {
        item.setBackground(Colors.getPositionMID());
      } else if (playerStats.getFormation() == PlayerStats.ATT) {
        item.setBackground(Colors.getPositionATT());
      }
      int i = 0;
      if (playerStats.getTimeOut() > 0 && playerStats.getTimeIn() == 0) {
        item.setImage(i++, ImageResources.getImageResources("down_icon.png"));
      } else if (playerStats.getTimeIn() > 0 && playerStats.getTimeOut() == 0) {
        item.setImage(i++, ImageResources.getImageResources("up_icon.png"));
      } else if (playerStats.getTimeIn() > 0 && playerStats.getTimeOut() > 0) {
        item.setImage(i++, ImageResources.getImageResources("in_out.png"));
      } else {
        i++;
      }

      if (playerStats.getTimeIn() > 0) {
        item.setText(i++, "R" + playerStats.getNumber());
      } else if (playerStats.getTimePlayed() == 0) {
        item.setText(i++, "R");
      } else {
        item.setText(i++, String.valueOf(playerStats.getNumber()));
      }

      Player player = playerStats.getPlayer();
      if (player != null && player.getExistsInSokker() != Player.EXISTS_IN_SOKKER_UNCHECKED) {
        if (player.getExistsInSokker() == Player.EXISTS_IN_SOKKER_TRUE
            || player.getExistsInSokker() == Player.EXISTS_IN_SOKKER_COMPLETED) {
          item.setImage(i, FlagsResources.getFlag(player.getCountryfrom()));
          if (player.getName() == null
              || player.getSurname() == null
              || (player.getName().isEmpty() && player.getSurname().isEmpty())) {
            item.setText(i++, String.valueOf(playerStats.getPlayerId()));
          } else {
            if (player.getName().isEmpty()) {
              item.setText(i++, String.format("%s", player.getSurname()));
            } else {
              item.setText(
                  i++,
                  String.format("%s %s.", player.getSurname(), player.getName().substring(0, 1)));
            }
          }
        } else {
          item.setImage(i, FlagsResources.getFlag(FlagsResources.EMPTY_FLAG));
          item.setText(i++, String.valueOf(playerStats.getPlayerId() + " (n/a)"));
        }
      } else {
        item.setImage(i, FlagsResources.getFlag(FlagsResources.QUESTION_FLAG));
        item.setText(i++, String.valueOf(playerStats.getPlayerId() + " (n/d)"));
      }

      if (playerStats.getFormation() >= 0 && playerStats.getFormation() <= 4) {
        item.setText(i++, Messages.getString("formation." + playerStats.getFormation()));
      } else {
        item.setText(i++, "");
      }

      if (playerStats.getTimePlayed() == 0) {
        item.setForeground(ColorResources.getDarkGray());
        item.setBackground(ColorResources.getWhite());
      }
      item.setText(i++, playerStats.getTimePlayed() + "'");

      item.setText(i++, playerStats.getRating() + "%");
      item.setText(i++, String.valueOf(playerStats.getGoals()));
      item.setText(i++, String.valueOf(playerStats.getShoots()));
      item.setText(i++, String.valueOf(playerStats.getAssists()));
      item.setText(i++, String.valueOf(playerStats.getFouls()));

      item.setText(i, "");
      if (SettingsHandler.IS_WINDOWS) {
        item.setBackground(i, this.getBackground());
      }

      if (playerStats.getIsInjured() == PlayerStats.INJURED) {
        item.setImage(i++, ImageResources.getImageResources("injury.png"));
      } else {
        i++;
      }

      item.setText(i, "");
      if (SettingsHandler.IS_WINDOWS) {
        item.setBackground(i, this.getBackground());
      }
      if (playerStats.getYellowCards() < 2 && playerStats.getRedCards() > 0) {
        item.setImage(i++, ImageResources.getImageResources("red_card.png"));
      } else if (playerStats.getYellowCards() > 1 && playerStats.getRedCards() > 0) {
        item.setImage(i++, ImageResources.getImageResources("2_yellow_cards_1_red_card.png"));
      } else if (playerStats.getYellowCards() == 1 && playerStats.getRedCards() < 1) {
        item.setImage(i++, ImageResources.getImageResources("yellow_card.png"));
      } else if (playerStats.getYellowCards() > 1 && playerStats.getRedCards() < 1) {
        item.setImage(i++, ImageResources.getImageResources("2_yellow_cards.png"));
      } else {
        i++;
      }
      // item.setText(i++, String.valueOf(playerStats.getYellowCards() + "
      // " +
      // playerStats.getRedCards()));
    }
    for (int i = 0; i < this.getColumnCount() - 1; i++) {

      if (i == 0) {
        this.getColumn(i).setWidth(25);
      } else {
        this.getColumn(i).pack();
      }
      // else {
      // this.getColumn(i).setWidth(this.getColumn(i).getWidth() + 3);
      // }
    }

    // for (int i = 0; i < this.getItemCount(); i++) {
    // if ((i % 2) == 1) {
    // this.getItem(i).setBackground(this.getDisplay().getSystemColor(SWT.COLOR_GRAY));
    // }
    // }
    this.setRedraw(true);
    // table.pack();
    // table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
  }