Ejemplo n.º 1
0
  // Metodo para lista todos os cargos
  public List<Evento> listarTodos() {
    String sql = "select * from evento";
    Connection con = Conexao.abrirConexao();
    List<Evento> lista = new ArrayList<>();

    try {
      PreparedStatement pst = con.prepareStatement(sql);

      ResultSet rs = pst.executeQuery();
      if (rs != null) {
        while (rs.next()) {
          Evento e = new Evento();
          e.setDia(rs.getInt(1));
          e.setMes(rs.getInt(2));
          e.setAno(rs.getInt(3));
          e.setDescricao(rs.getString(4));

          lista.add(e);
        }

        Conexao.fecharConexao(con);
        return lista;

      } else {
        Conexao.fecharConexao(con);
        return null;
      }
    } catch (SQLException e) {
      Conexao.fecharConexao(con);
      return null;
    }
  }
Ejemplo n.º 2
0
  // Metodo para alteração de dados
  public String alterar(Evento evento) {
    String sql = "update evento set ";
    sql += " descricao=?";
    sql += " where dia=? and mes=? and ano=?";
    Connection con = Conexao.abrirConexao();

    try {
      PreparedStatement pst = con.prepareStatement(sql);
      pst.setString(1, evento.getDescricao());
      pst.setInt(2, evento.getDia());
      pst.setInt(3, evento.getMes());
      pst.setInt(4, evento.getAno());

      if ((pst.executeUpdate() > 0)) {
        Conexao.fecharConexao(con);
        return "Registro alterado com sucesso.";
      } else {
        Conexao.fecharConexao(con);
        return "Erro ao alterar registro";
      }

    } catch (SQLException e) {
      Conexao.fecharConexao(con);
      return e.getMessage();
    }
  }
Ejemplo n.º 3
0
  // Metodo para excluir dados
  public String excluir(Evento evento) {
    String sql = "delete from evento";
    sql += " where dia=? and mes=? and ano=?";
    Connection con = Conexao.abrirConexao();

    try {
      PreparedStatement pst = con.prepareStatement(sql);

      pst.setInt(1, evento.getDia());
      pst.setInt(2, evento.getMes());
      pst.setInt(3, evento.getAno());

      if (pst.executeUpdate() > 0) {
        Conexao.fecharConexao(con);
        return "Registro excluido com sucesso.";
      } else {
        Conexao.fecharConexao(con);
        return "Erro ao excluir registro.";
      }

    } catch (SQLException e) {
      Conexao.fecharConexao(con);
      return e.getMessage();
    }
  }
Ejemplo n.º 4
0
  public List<Map<String, Object>> getProgramacao(String url, Context context) {
    ArrayList<Map<String, String>> json = this.JSON(url, context);
    List<Map<String, Object>> programacao = new ArrayList<Map<String, Object>>();
    Map<String, Object> data;
    if (json.get(0).get("internet").equals("true")) {
      for (int i = 0; i < json.size(); i++) {
        try {
          data = new HashMap<String, Object>();
          Log.i("JSON Lista Recebida", i + " -> " + json.get(i).toString());
          Evento evento =
              new Evento(
                  json.get(i).get("title"),
                  json.get(i).get("text"),
                  json.get(i).get("local"),
                  json.get(i).get("datetime"));

          data.put("internet", true);
          data.put("title", evento.getTitle());
          data.put("local", evento.getLocal());
          data.put("description", evento.getDescription());
          data.put("datetime", evento.getDate());

          programacao.add(data);
        } catch (Exception e) {
          Log.e("JSON - Programação", e.getMessage() + " " + e.getStackTrace());
        }
      }
    } else {
      data = new HashMap<String, Object>();
      data.put("internet", false);
      programacao.add(data);
    }
    return programacao;
  }
Ejemplo n.º 5
0
  // Metodo que retorna um objeto, de acordo com o nome
  public Evento buscaPorDescricao(String descricao) {
    String sql = "select * from evento";
    sql += " where descricao=?";
    Connection con = Conexao.abrirConexao();

    try {
      PreparedStatement pst = con.prepareStatement(sql);
      pst.setString(1, descricao);
      ResultSet rs = pst.executeQuery();
      if (rs.next()) {
        Evento e = new Evento();
        e.setDia(rs.getInt(1));
        e.setMes(rs.getInt(2));
        e.setAno(rs.getInt(3));
        e.setDescricao(rs.getString(4));
        Conexao.fecharConexao(con);
        return e;

      } else {
        Conexao.fecharConexao(con);
        return null;
      }

    } catch (SQLException e) {
      Conexao.fecharConexao(con);
      return null;
    }
  }
Ejemplo n.º 6
0
  public void realizarAposta(Evento event, double valor, String equipa) {

    if (valor < this.saldoBetCoins) {
      this.historicoEventos.add(event);
      Aposta novaAposta = new Aposta(valor, equipa); // Nova Aposta !!! ainda sem odd
      this.historicoApostas.add(novaAposta); // vai pró historico
      event.apostarAqui(
          this,
          novaAposta); // o Set da odd é feito aqui dentro - isto retorna Aposta ou null para quê?
      this.saldoBetCoins -= valor;
    }
  }
Ejemplo n.º 7
0
  /* toString(), equals() y hashCode() para Espectaculo, utilizando la identidad natural del objeto */
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Espectaculo espectaculo = (Espectaculo) o;

    if (evento != null ? !evento.equals(espectaculo.evento) : espectaculo.evento != null)
      return false;
    if (lugar != null ? !lugar.equals(espectaculo.lugar) : espectaculo.lugar != null) return false;

    return true;
  }
Ejemplo n.º 8
0
  // Metodo Para inserção de dados
  public String inserir(Evento evento) {
    String sql = "insert into evento";
    sql += " values (?,?,?,?) ";
    Connection con = Conexao.abrirConexao();

    try {
      PreparedStatement pst = con.prepareStatement(sql);
      pst.setInt(1, evento.getDia());
      pst.setInt(2, evento.getMes());
      pst.setInt(3, evento.getAno());
      pst.setString(4, evento.getDescricao());

      if ((pst.executeUpdate() > 0)) {
        Conexao.fecharConexao(con);
        return "Registro inserido com sucesso.";
      } else {
        Conexao.fecharConexao(con);
        return "Erro ao inserir registro";
      }
    } catch (SQLException e) {
      Conexao.fecharConexao(con);
      return e.getMessage();
    }
  }
  public void setEventsFields() {

    if (event != null) {
      if (event.getFecha() != null) tvFecha.setText(event.getFecha());
      if (event.getHora() != null) tvHora.setText(event.getHora());
      if (event.getTitulo() != null) tvTitulo.setText(event.getTitulo());
      if (event.getDescription() != null) tvDescription.setText(event.getDescription());

      // Puts the banner image
      // First we try to get the good resolution image (getCartel())
      // if is not available we get the thumb
      // if not we hide the picture and we don't show anything
      byte[] image = null;

      if (event.getCartel() != null) {
        loadingAnimation.setVisibility(View.GONE);
        image = event.getCartel();

      } else { // si no hay imagen tamaño completo lo conseguimos
        loadingAnimation.setVisibility(View.VISIBLE);
        new getImage().execute("cartel" + event.getId() + ".jpg");
        if (event.getThumb() != null) {
          image = event.getThumb();
        }
      }

      if (image != null) {
        ivCartel.setImageBitmap(BitmapFactory.decodeByteArray(image, 0, image.length));
        ivCartel.setVisibility(View.VISIBLE);
        tvCartel.setVisibility(View.VISIBLE);
      } else {
        ivCartel.setImageBitmap(null);
        ivCartel.setVisibility(View.GONE);
        tvCartel.setVisibility(View.GONE);
      }
    } else {
      loadingAnimation.setVisibility(View.VISIBLE);
    }
  }
Ejemplo n.º 10
0
 @Override
 public int hashCode() {
   int result = evento != null ? evento.hashCode() : 0;
   result = 31 * result + (lugar != null ? lugar.hashCode() : 0);
   return result;
 }
Ejemplo n.º 11
0
 public Evento filtraEvento(Evento evento) {
   if ("America/Sao_Paulo".equals(evento.getTimezone())) {
     return evento;
   }
   return null;
 }
Ejemplo n.º 12
0
  @Override
  public void procesarEvento(Evento evento) {
    Evento eventoRespuesta = null;

    switch (evento.getTipoEvento()) {
      case SALIR:
        System.out.println("Saliendo");
        System.exit(1);
        break;
      case LOGIN:
        if (!evento.getInfo().getClass().getName().equals("Modelo.Login")) {
          assert false : evento.getInfo().getClass().getName() + " clase invalida";
        } else {
          Login login = (Login) evento.getInfo();
          System.out.println("Intento acceso para: " + login.toString());
          Usuario usuario;
          try {
            usuario = biblioteca.login(login.getNombre(), login.getClave());
            ((Usuario) usuario).setLookAndFeel(login.getLookAndFeel());
            // System.out.println("---"+usuario.getClass().getSimpleName()+"-");
            eventoRespuesta = new Evento(TipoEvento.LOGIN_OK, usuario);
          } catch (Exception ex) {
            // Logger.getLogger(Controlador.class.getName()).log(Level.SEVERE, null, ex);
            System.err.println("ERROR");
            eventoRespuesta = new Evento(TipoEvento.LOGIN_FALLO);
          }
          evento.getDestinoRespueta().procesarEvento(eventoRespuesta);
        }

        break;
      case LOGOUT:
        evento.getDestinoRespueta().procesarEvento(new Evento(TipoEvento.LOGOUT));
        break;
      case OBTENER_CAT_DEWEY:
        evento
            .getDestinoRespueta()
            .procesarEvento(
                new Evento(TipoEvento.OBTENER_CAT_DEWEY, biblioteca.getCategoriasDewey()));
        break;

      case CONSULTA_CATALOGO_GENERAL:
        System.out.println("CONSULTA_CATALOGO_GENERAL");
        try {

          Catalogo catalogo = biblioteca.getAlberga();
          eventoRespuesta = new Evento(TipoEvento.CONSULTA_CATALOGO_GENERAL, catalogo);

        } catch (Exception ex) {
          Logger.getLogger(Controlador.class.getName()).log(Level.SEVERE, null, ex);
          System.err.println("CONSULTA_CATALOGO_GENERAL: ERROR");
          eventoRespuesta = new Evento(TipoEvento.ERROR);
        }
        evento.getDestinoRespueta().procesarEvento(eventoRespuesta);
        break;
      case CONSULTA_CATALOGO_CONCRETA:
        System.out.println("CONSULTA_CATALOGO_CONCRETA" + evento.getInfo().getClass().getName());
        if (!evento.getInfo().getClass().getName().startsWith("HBM.TituloId")) {
          assert false : evento.getInfo().getClass().getName() + " clase invalida";
        }

        try {
          TituloId tituloId = (TituloId) evento.getInfo();

          Titulo titulo = biblioteca.getAlberga().getCatalogo().get(tituloId);
          eventoRespuesta = new Evento(TipoEvento.CONSULTA_CATALOGO_CONCRETA, titulo);

        } catch (Exception ex) {
          Logger.getLogger(Controlador.class.getName()).log(Level.SEVERE, null, ex);
          System.err.println("CONSULTA_CATALOGO_CONCRETA: ERROR");
          eventoRespuesta = new Evento(TipoEvento.ERROR);
        }
        evento.getDestinoRespueta().procesarEvento(eventoRespuesta);
        break;

      case LISTADO_USUARIOS:
        System.out.println("Listado de usuarios");
        try {

          GestorUsuarios gestorUsuarios = biblioteca.getUsuarios();
          eventoRespuesta = new Evento(TipoEvento.LISTADO_USUARIOS, gestorUsuarios);

        } catch (Exception ex) {
          Logger.getLogger(Controlador.class.getName()).log(Level.SEVERE, null, ex);
          System.err.println("LISTADO_USUARIOS: ERROR");
          eventoRespuesta = new Evento(TipoEvento.LISTADO_USUARIOS_ERROR);
        }
        evento.getDestinoRespueta().procesarEvento(eventoRespuesta);
        break;
      case ALTA_USUARIO:
        Usuario usuario = (Usuario) evento.getInfo();
        try {
          biblioteca.altaUsuario(usuario);
          eventoRespuesta = new Evento(TipoEvento.ALTA_USUARIO_OK);

        } catch (Exception ex) {
          eventoRespuesta = new Evento(TipoEvento.ALTA_USUARIO_ERROR);
        }
        evento.getDestinoRespueta().procesarEvento(eventoRespuesta);
        break;

      case MODIFICACION_TITULO:
        Titulo titulo = (Titulo) evento.getInfo();
        try {
          biblioteca.modificacionTitulo(titulo);
          eventoRespuesta = new Evento(TipoEvento.MODIFICACION_TITULO_OK, titulo.getId());

        } catch (Exception ex) {
          eventoRespuesta = new Evento(TipoEvento.MODIFICACION_TITULO_ERROR, titulo.getId());
          System.out.println("Error en modificacion de título");
        }
        evento.getDestinoRespueta().procesarEvento(eventoRespuesta);

        break;
      case BAJA_TITULO:
        System.out.println("Controlador BAJA_TITULO");

        TituloId tituloId = ((Titulo) evento.getInfo()).getId();
        try {
          biblioteca.bajaTitulo(tituloId);
          eventoRespuesta = new Evento(TipoEvento.BAJA_TITULO_OK, tituloId);
        } catch (Exception ex) {
          eventoRespuesta = new Evento(TipoEvento.BAJA_TITULO_ERROR, tituloId);
        }
        evento.getDestinoRespueta().procesarEvento(eventoRespuesta);
    }
  }