@Override
 public List<Ordine> getOrdiniPerCliente(Cliente cliente) throws PersistenceException { // ok
   Connection connection = this.datasource.getConnection();
   PreparedStatement statement = null;
   Ordine o = null;
   List<Ordine> lo = new LinkedList<Ordine>();
   try {
     String str = "select codice,data,stato,id from ordini where cliente=?";
     statement = connection.prepareStatement(str);
     statement.setInt(1, cliente.getId());
     ResultSet result = statement.executeQuery();
     while (result.next()) {
       o = new Ordine();
       o.setCliente(cliente);
       o.setCodiceOrdine(result.getString("codice"));
       o.setData(result.getDate("data"));
       o.setStato(result.getString("stato"));
       o.setId(result.getInt("id"));
       lo.add(o);
       // da completare per restituire ordine completo di righe
     }
   } catch (SQLException e) {
     throw new PersistenceException(e.getMessage());
   } finally {
     try {
       if (statement != null) statement.close();
       if (connection != null) connection.close();
     } catch (SQLException e) {
       throw new PersistenceException(e.getMessage());
     }
   }
   return lo;
 }
 @Override
 public Ordine getOrdineByCodice(String codice) throws PersistenceException {
   Ordine ordine = null;
   Connection connection = this.datasource.getConnection();
   PreparedStatement statement = null;
   try {
     String query =
         "select ordini.codice,ordini.id as id,data,stato,cliente,nome,partitaiva,indirizzo "
             + "from ordini LEFT OUTER JOIN clienti on cliente = clienti.id WHERE ordini.codice=?";
     statement = connection.prepareStatement(query);
     statement.setString(1, codice);
     ResultSet result = statement.executeQuery();
     if (result.next()) {
       ordine = new Ordine();
       ordine.setCodiceOrdine(codice);
       ordine.setStato(result.getString("stato"));
       ordine.setId(result.getInt("id"));
       ordine.setData(new java.util.Date(result.getDate("data").getTime()));
       Cliente cliente = new Cliente();
       cliente.setId(result.getInt("cliente"));
       cliente.setNome(result.getString("nome"));
       cliente.setIndirizzo(result.getString("indirizzo"));
       cliente.setPiva(result.getString("partitaiva"));
       ordine.setCliente(cliente);
     }
   } catch (SQLException e) {
     throw new PersistenceException(e.getMessage());
   } finally {
     try {
       if (statement != null) statement.close();
       if (connection != null) connection.close();
     } catch (SQLException e) {
       throw new PersistenceException(e.getMessage());
     }
   }
   return ordine;
 }
Example #3
0
  // manejo de eventos de turno y los mapas
  public void actionPerformed(ActionEvent e) {
    if (estad == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      // IUpanel02.mainAE();   -----------------------------------------------
      /// setVisible(false);
    }
    if (registrar == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      OpcionesPerfiles.perfiles.mainAE();
      setVisible(false);
    }
    if (facil == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      String nomb = "";
      PerfilesBD coleccion = new PerfilesBD();
      int numPer = 0;
      numPer = coleccion.numeroDePerfiles();
      Perfil perfilesMostrar[] = null;

      if (numPer == 0) {
        perfilesMostrar = new Perfil[4];

        for (int idx = 0; idx < 4; idx++) {
          perfilesMostrar[idx] =
              new Perfil("Asesinator" + (idx + 1), "predt" + (idx + 1) + ".jpg", "123" + idx);
          coleccion.agregarPerfil(perfilesMostrar[idx]);
        }
      }

      try {
        do {
          nomb =
              JOptionPane.showInputDialog(null, "Ingrese Nombre de Jugador Humano", "Asesinator1");

        } while (nomb.length() == 0);

        if (nomb.equals("Asesinator1")
            || nomb.equals("Asesinator2")
            || nomb.equals("Asesinator3")
            || nomb.equals("Asesinator4")) {
          MenuCrearJuego.menu.mainAE(1, nomb, "PC");
          setVisible(false);
          return;
        }

        JLabel jPassword = new JLabel("porfavor ingrese la contraseña ");
        JTextField password = new JPasswordField();
        Object[] ob = {jPassword, password};

        int result =
            JOptionPane.showConfirmDialog(null, ob, "Contraseña", JOptionPane.OK_CANCEL_OPTION);

        String contraseNa = "";
        if (result == JOptionPane.OK_OPTION) {
          contraseNa = password.getText();
        }
        if (result == JOptionPane.CANCEL_OPTION) {
          return;
        }

        if (coleccion.estaRegistrado(contraseNa)) {
          MenuCrearJuego.menu.mainAE(1, nomb, "PC");
          setVisible(false);
        } else {
          JOptionPane.showMessageDialog(
              this,
              "No esta Registrado, usted debe registrarse previamente!",
              "ERROR",
              JOptionPane.ERROR_MESSAGE);
        }
      } catch (Exception exp) {
      }
      return;
    }
    if (dific == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      String nomb = "";
      PerfilesBD coleccion = new PerfilesBD();
      int numPer = 0;
      numPer = coleccion.numeroDePerfiles();
      Perfil perfilesMostrar[] = null;

      if (numPer == 0) {
        perfilesMostrar = new Perfil[4];

        for (int idx = 0; idx < 4; idx++) {
          perfilesMostrar[idx] =
              new Perfil("Asesinator" + (idx + 1), "predt" + (idx + 1) + ".jpg", "123" + idx);
          coleccion.agregarPerfil(perfilesMostrar[idx]);
        }
      }

      try {
        do {
          nomb =
              JOptionPane.showInputDialog(null, "Ingrese Nombre de Jugador Humano", "Asesinator1");

        } while (nomb.length() == 0);

        if (nomb.equals("Asesinator1")
            || nomb.equals("Asesinator2")
            || nomb.equals("Asesinator3")
            || nomb.equals("Asesinator4")) {
          MenuCrearJuego.menu.mainAE(2, nomb, "PC");
          setVisible(false);
          return;
        }

        JLabel jPassword = new JLabel("porfavor ingrese la contraseña ");
        JTextField password = new JPasswordField();
        Object[] ob = {jPassword, password};

        int result =
            JOptionPane.showConfirmDialog(null, ob, "Contraseña", JOptionPane.OK_CANCEL_OPTION);

        String contraseNa = "";
        if (result == JOptionPane.OK_OPTION) {
          contraseNa = password.getText();
        }
        if (result == JOptionPane.CANCEL_OPTION) {
          return;
        }

        if (coleccion.estaRegistrado(contraseNa)) {
          MenuCrearJuego.menu.mainAE(2, nomb, "PC");
          setVisible(false);
        } else {
          JOptionPane.showMessageDialog(
              this,
              "No esta Registrado, usted debe registrarse previamente!",
              "ERROR",
              JOptionPane.ERROR_MESSAGE);
        }
      } catch (Exception exp) {
      }
      return;
    }

    if (red == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      String nomb = "";
      PerfilesBD coleccion = new PerfilesBD();
      final PerfilesBD perfilesDB = coleccion;
      int numPer = 0;
      numPer = coleccion.numeroDePerfiles();
      Perfil perfilesMostrar[] = null;

      if (numPer == 0) {
        perfilesMostrar = new Perfil[4];

        for (int idx = 0; idx < 4; idx++) {
          perfilesMostrar[idx] =
              new Perfil("Asesinator" + (idx + 1), "predt" + (idx + 1) + ".jpg", "123" + idx);
          coleccion.agregarPerfil(perfilesMostrar[idx]);
        }
      }

      try {
        do {
          nomb =
              JOptionPane.showInputDialog(null, "Ingrese Nombre de Jugador Humano", "Asesinator1");

        } while (nomb.length() == 0);
        final String nomb2 = nomb;
        Perfil perfil = null;
        if (nomb.equals("Asesinator1")
            || nomb.equals("Asesinator2")
            || nomb.equals("Asesinator3")
            || nomb.equals("Asesinator4")) {
          if (nomb.equals("Asesinator1")) {
            if (coleccion.estaConectado("1230")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }
          if (nomb.equals("Asesinator2")) {
            if (coleccion.estaConectado("1231")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }
          if (nomb.equals("Asesinator3")) {
            if (coleccion.estaConectado("1232")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }
          if (nomb.equals("Asesinator4")) {
            if (coleccion.estaConectado("1233")) {
              JOptionPane.showMessageDialog(
                  this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
              return;
            }
          }

          if (nomb.equals("Asesinator1")) {
            coleccion.agregarConectado("1230");
          }
          if (nomb.equals("Asesinator2")) {
            coleccion.agregarConectado("1231");
          }
          if (nomb.equals("Asesinator3")) {
            coleccion.agregarConectado("1232");
          }
          if (nomb.equals("Asesinator4")) {
            coleccion.agregarConectado("1233");
          }

          if (!coleccion.estaMontadoServidor()) {

            int numJugadores = 2;
            boolean siga = false;
            do {
              try {
                numJugadores =
                    Integer.parseInt(
                        JOptionPane.showInputDialog(
                            this,
                            "señor jugador, por ser el primero en elegir juego en red,\n"
                                + " ha sido elegido como administrador de la partida,\n"
                                + " `por favor ingrese el numero de jugadores [2,50]"));
              } catch (Exception exp) {
                continue;
              }
              if ((numJugadores >= 2) && (numJugadores < 50)) {
                siga = true;
              }

            } while (!siga);

            cliente.enviarAdmi(numJugadores);
            coleccion.conectar_desconectarServidor(true, ipServer);
            JOptionPane.showMessageDialog(
                this,
                "se modifica el numero de jugadores de la clase Administrador : " + numJugadores);
          }
          MenuCrearJuego.menu.mainAE(1, nomb, "Red");
          MenuCrearJuego.menu.setCliente(cliente);
          setVisible(false);

          return;
        }

        JLabel jPassword = new JLabel("porfavor ingrese la contraseña ");
        JTextField password = new JPasswordField();
        Object[] ob = {jPassword, password};

        int result =
            JOptionPane.showConfirmDialog(null, ob, "Contraseña", JOptionPane.OK_CANCEL_OPTION);

        String contraseNa = "";
        if (result == JOptionPane.OK_OPTION) {
          contraseNa = password.getText();
        }
        if (result == JOptionPane.CANCEL_OPTION) {
          return;
        }

        if (coleccion.estaRegistrado(contraseNa)) {
          if (coleccion.estaConectado(contraseNa)) {
            JOptionPane.showMessageDialog(
                this, "El perfil ya se encuentra en uso!", "ERROR", JOptionPane.ERROR_MESSAGE);
            return;
          }

          coleccion.agregarConectado(contraseNa);

          if (!coleccion.estaMontadoServidor()) {

            int numJugadores = 2;
            boolean siga = false;
            do {
              try {
                numJugadores =
                    Integer.parseInt(
                        JOptionPane.showInputDialog(
                            this,
                            "señor jugador, por ser el primero en elegir juego en red,\n"
                                + " ha sido elegido como administrador de la partida,\n"
                                + " `por favor ingrese el numero de jugadores [2,50]"));
              } catch (Exception exp) {
                JOptionPane.showMessageDialog(
                    this, "Error de datos ", "Error", JOptionPane.ERROR_MESSAGE);
                continue;
              }
              if ((numJugadores >= 2) && (numJugadores < 50)) {
                siga = true;
              } else
                JOptionPane.showMessageDialog(
                    this, "Error de datos ", "Error", JOptionPane.ERROR_MESSAGE);

            } while (!siga);
            cliente.enviarAdmi(numJugadores);
            coleccion.conectar_desconectarServidor(true, ipServer);
          }
          MenuCrearJuego.menu.mainAE(1, nomb, "Red");
          MenuCrearJuego.menu.setCliente(cliente);
          setVisible(false);
        } else {
          JOptionPane.showMessageDialog(
              this,
              "No esta Registrado, usted debe registrarse previamente!",
              "ERROR",
              JOptionPane.ERROR_MESSAGE);
        }
      } catch (Exception exp) {
      }
      return;
    }

    if (salir == e.getSource()) {
      efectos.reproducirEfectoSonido("Klick");
      PerfilesBD coleccion = new PerfilesBD();
      // pregunta si de verdad se desea salir del juego
      int n =
          JOptionPane.showConfirmDialog(
              null,
              "Seguro que deseas SALIR?",
              "END GAME",
              JOptionPane.YES_NO_OPTION,
              JOptionPane.QUESTION_MESSAGE);

      if (n == JOptionPane.YES_OPTION) {
        System.exit(12);
      }
    }
  }