示例#1
0
  public static void eliminarjugador() {
    ncomienzo =
        Integer.parseInt((String) jugadorestorneo.getValueAt(jugadorestorneo.getSelectedRow(), 0));
    cedulaj = (String) jugadorestorneo.getValueAt(jugadorestorneo.getSelectedRow(), 1);
    id_torneo = Principal.labelserialtorneo.getText();
    id_hjugador = id_torneo + cedulaj;
    equipo = id_torneo + labelserial.getText();

    ctrn = 0;
    ctrn = ncomienzo;

    try {
      String sql =
          "Select hj.n_nomina ,j.cedula, j.nombre_j, j.apellido_j from jugador j, h_jugador hj where hj.cedula=j.cedula and hj.id_torneo='"
              + id_torneo
              + "' and hj.id_hequipo='"
              + equipo
              + "' order by hj.n_nomina;";
      Conexion parametros = new Conexion();
      Class.forName(parametros.getDriver());
      Connection con =
          DriverManager.getConnection(
              parametros.getURL(), parametros.getUsuario(), parametros.getPass());
      Statement st =
          con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = st.executeQuery(sql);
      while (rs.last()) {
        nfinal = rs.getInt("hj.n_nomina");
        break;
      }
    } catch (SQLException | ClassNotFoundException ex) {
      Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
      borrarjugadort user = new borrarjugadort(id_hjugador);
      torneojugador in = new torneojugador();
      boolean r;
      r = in.Eliminar(user);
      if (r == false) {
        limite = nfinal;

        while (ctrn < limite) {
          i = ctrn + 1;
          try {
            String sql =
                "Select hj.id_hjugador,j.cedula from jugador j, h_jugador hj where hj.cedula=j.cedula and hj.id_torneo='"
                    + id_torneo
                    + "' and hj.id_hequipo='"
                    + equipo
                    + "' and hj.n_nomina='"
                    + i
                    + "';";
            Conexion parametros = new Conexion();
            Class.forName(parametros.getDriver());
            Connection con =
                DriverManager.getConnection(
                    parametros.getURL(), parametros.getUsuario(), parametros.getPass());
            Statement st =
                con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet rs = st.executeQuery(sql);
            while (rs.last()) {
              id_hjugador = rs.getString("hj.id_hjugador");
              cedulaj = rs.getString("j.cedula");
              break;
            }
          } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, ex);
          }
          n_nomina = ctrn;
          try {
            actualizarnomina user1 = new actualizarnomina(id_hjugador, n_nomina);
            torneojugador in1 = new torneojugador();
            boolean re;
            re = in1.Modificar(user1);
          } catch (SQLException ex2) {
            JOptionPane.showMessageDialog(
                null, "Error " + ex2.getMessage(), "Informacion", JOptionPane.ERROR_MESSAGE);
          } catch (ClassNotFoundException e2) {
            Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, e2);
          }
          ctrn = ctrn + 1;
        }
        cargarjugadorestorneo();
      }
    } catch (SQLException ex) {
      JOptionPane.showMessageDialog(
          null, "Error " + ex.getMessage(), "Informacion", JOptionPane.ERROR_MESSAGE);
    } catch (ClassNotFoundException e) {
      Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, e);
    }
  }
示例#2
0
  public void agregarjugador() {
    idcategoria = null;
    id_equipo = null;
    id_hjugador = null;
    ctrl = 0;
    id_torneo = null;
    n_nomina = 0;
    ctrn = 0;
    idcategoria = labelcategoria.getText();
    equipo = labelserial.getText();
    cedulaj = (String) jugadores.getValueAt(jugadores.getSelectedRow(), 0);
    id_torneo = Principal.labelserialtorneo.getText();
    id_hjugador = id_torneo + cedulaj;
    id_equipo = id_torneo + equipo;
    int goles = 0;
    int tarjetas_a = 0;
    int tarjetas_r = 0;
    try {
      String sql = "Select bloqueo_j from jugador where cedula='" + cedulaj + "';";
      Conexion parametros = new Conexion();
      Class.forName(parametros.getDriver());
      Connection con =
          DriverManager.getConnection(
              parametros.getURL(), parametros.getUsuario(), parametros.getPass());
      Statement st =
          con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = st.executeQuery(sql);
      while (rs.last()) {
        bloqueo = rs.getString("bloqueo_j");
        break;
      }
    } catch (SQLException | ClassNotFoundException ex) {
      Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
      String sql =
          "Select hj.n_nomina ,j.cedula, j.nombre_j, j.apellido_j from jugador j, h_jugador hj where hj.cedula=j.cedula and hj.id_torneo='"
              + id_torneo
              + "' and hj.id_hequipo='"
              + id_equipo
              + "' order by hj.n_nomina;";
      Conexion parametros = new Conexion();
      Class.forName(parametros.getDriver());
      Connection con =
          DriverManager.getConnection(
              parametros.getURL(), parametros.getUsuario(), parametros.getPass());
      Statement st =
          con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = st.executeQuery(sql);
      while (rs.last()) {
        n_nomina = Integer.parseInt(rs.getString("n_nomina"));
        break;
      }
    } catch (SQLException | ClassNotFoundException ex) {
      Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
      String sql = "Select numero_j from n_jugadores where id_torneo='" + id_torneo + "';";
      Conexion parametros = new Conexion();
      Class.forName(parametros.getDriver());
      Connection con =
          DriverManager.getConnection(
              parametros.getURL(), parametros.getUsuario(), parametros.getPass());
      Statement st =
          con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = st.executeQuery(sql);
      while (rs.first()) {
        ctrn = Integer.parseInt(rs.getString("numero_j"));
        break;
      }
    } catch (SQLException | ClassNotFoundException ex) {
      Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, ex);
    }

    n_nomina = n_nomina + 1;
    ctrn = ctrn + 1;
    try {
      String sql = "Select id_hjugador from h_jugador where id_hjugador='" + id_hjugador + "';";
      Conexion parametros = new Conexion();
      Class.forName(parametros.getDriver());
      Connection con =
          DriverManager.getConnection(
              parametros.getURL(), parametros.getUsuario(), parametros.getPass());
      Statement st =
          con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = st.executeQuery(sql);
      while (rs.first()) {
        ctrl = 2;
        break;
      }
    } catch (SQLException | ClassNotFoundException ex) {
      Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (bloqueo.equals("Si")) {
      JOptionPane.showMessageDialog(
          this,
          "El jugador se encuentra bloqueado, por lo cual no puede agregarlo a ningun torneo",
          "Informacion",
          JOptionPane.INFORMATION_MESSAGE);
    } else if (ctrl == 2) {
      JOptionPane.showMessageDialog(
          null,
          "El jugador ya esta registrado en el torneo",
          "Informacion",
          JOptionPane.INFORMATION_MESSAGE);
    } else if (n_nomina == ctrn) {
      JOptionPane.showMessageDialog(
          null,
          "Ya Posee el limite de jugadores en nomina en el torneo ",
          "Informacion",
          JOptionPane.INFORMATION_MESSAGE);
    } else {
      try {
        datosjugadort user =
            new datosjugadort(
                id_hjugador,
                cedulaj,
                idcategoria,
                n_nomina,
                goles,
                tarjetas_a,
                tarjetas_r,
                id_equipo,
                id_torneo);
        torneojugador in = new torneojugador();
        boolean r;
        r = in.Insertar(user);
        if (r == false) {
          JOptionPane.showMessageDialog(
              null, "Jugador agregado al torneo.", "Informacion", JOptionPane.INFORMATION_MESSAGE);
          cargarjugadorestorneo();
        }
      } catch (SQLException ex) {
        JOptionPane.showMessageDialog(
            null, "Error " + ex.getMessage(), "Informacion", JOptionPane.ERROR_MESSAGE);
      } catch (ClassNotFoundException e) {
        Logger.getLogger(jugadoresequipot.class.getName()).log(Level.SEVERE, null, e);
      }
    }
  }