diff --git a/src/main/java/com/casaculturaqxd/sgec/DAO/EventoDAO.java b/src/main/java/com/casaculturaqxd/sgec/DAO/EventoDAO.java index c2ef636a..467bc0a1 100644 --- a/src/main/java/com/casaculturaqxd/sgec/DAO/EventoDAO.java +++ b/src/main/java/com/casaculturaqxd/sgec/DAO/EventoDAO.java @@ -46,9 +46,13 @@ public boolean inserirEvento(Evento evento) { } try { - String sql = "INSERT INTO evento (nome_evento, publico_esperado, publico_alcancado, descricao, data_inicial, data_final, horario, classificacao_etaria, certificavel, carga_horaria, acessivel_em_libras, num_participantes_esperado, num_municipios_esperado) VALUES (?, ?, ?, ?, ?, ?, ?, ?::faixa_etaria, ?, ?, ?, ?, ?) RETURNING id_evento"; + String sql = "INSERT INTO evento (nome_evento, publico_esperado, publico_alcancado, descricao, data_inicial, data_final, horario, classificacao_etaria, certificavel, carga_horaria, acessivel_em_libras, num_participantes_esperado, num_municipios_esperado, id_service_file) VALUES (?, ?, ?, ?, ?, ?, ?, ?::faixa_etaria, ?, ?, ?, ?, ?, ?) RETURNING id_evento"; PreparedStatement stmt = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); + Integer idServiceFile = null; + if (evento.getImagemCapa() != null) { + idServiceFile = evento.getImagemCapa().getServiceFileId(); + } stmt.setString(1, evento.getNome()); stmt.setInt(2, evento.getPublicoEsperado()); @@ -63,6 +67,7 @@ public boolean inserirEvento(Evento evento) { stmt.setBoolean(11, evento.isAcessivelEmLibras()); stmt.setInt(12, evento.getNumParticipantesEsperado()); stmt.setInt(13, evento.getNumMunicipiosEsperado()); + stmt.setObject(14, idServiceFile, Types.INTEGER); stmt.executeUpdate(); diff --git a/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java b/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java index f94dc24e..948cb8c5 100644 --- a/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java +++ b/src/main/java/com/casaculturaqxd/sgec/controller/CadastrarEventoController.java @@ -1,7 +1,10 @@ package com.casaculturaqxd.sgec.controller; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.sql.Date; import java.sql.SQLException; import java.sql.Time; @@ -51,6 +54,8 @@ import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonBar.ButtonData; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; import javafx.scene.control.CheckBox; import javafx.scene.control.ChoiceBox; import javafx.scene.control.DateCell; @@ -65,6 +70,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.FileChooser; +import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; import javafx.util.converter.LocalTimeStringConverter; @@ -121,11 +127,14 @@ public class CadastrarEventoController implements ControllerServiceFile, Control ObservableList participantes = FXCollections .observableList(new ArrayList<>()); private Alert mensagem = new Alert(AlertType.NONE); + @FXML + ImageView capaEvento; + File file = null; public void initialize() throws IOException { eventoDAO = new EventoDAO(db.getConnection()); participanteDAO.setConnection(db.getConnection()); - serviceFileDAO = new ServiceFileDAO(eventoDAO.getConnection()); + serviceFileDAO = new ServiceFileDAO(db.getConnection()); formatterHorario = new SimpleDateFormat("HH:mm"); addListenersServiceFile(mapServiceFiles); @@ -303,6 +312,20 @@ private Evento getTargetEvento() throws SQLException { builderEvento.setListaArquivos(listaArquivos); builderEvento.setLocalizacoes(locais); builderEvento.setListaMetas(getMetasSelecionadas()); + if(file != null){ + ServiceFile serviceFileTemp = new ServiceFile(file); + try { + if(serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).isEmpty()){ + serviceFileDAO.inserirArquivo(serviceFileTemp); + serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get(); + } else { + serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + builderEvento.setImagemCapa(serviceFileTemp); + } return builderEvento.getEvento(); } @@ -669,32 +692,29 @@ public boolean camposObrigatoriosPreenchidos() { public void addListenersParticipante(ObservableList observableList) { CadastrarEventoController superController = this; - observableList.addListener(new ListChangeListener() { - @Override - public void onChanged(ListChangeListener.Change change) { - - while (change.next()) { - if (change.wasAdded()) { + observableList.addListener((ListChangeListener) change -> { - for (PreviewParticipanteController addedController : change.getAddedSubList()) { - addedController.setParentController(superController); + while (change.next()) { + if (change.wasAdded()) { - secaoParticipantes.getChildren().add(addedController.getContainer()); - } + for (PreviewParticipanteController addedController : change.getAddedSubList()) { + addedController.setParentController(superController); + secaoParticipantes.getChildren().add(addedController.getContainer()); } - if (change.wasRemoved()) { + } - for (PreviewParticipanteController removedController : change.getRemoved()) { - secaoParticipantes.getChildren().remove(removedController.getContainer()); - } + if (change.wasRemoved()) { + for (PreviewParticipanteController removedController : change.getRemoved()) { + secaoParticipantes.getChildren().remove(removedController.getContainer()); } - } } - }); + + } + }); } public void addListenersOrganizador(ObservableList observableList) { @@ -923,4 +943,21 @@ public void removerLocalizacao(Localizacao localizacao) { botaoNovaLocalizacao.setDisable(false); } + + public void loadImagem(){ + InputStream fileAsStream; + FileChooser fileChooser = new FileChooser(); + fileChooser.setTitle("Alterar foto do evento"); + ExtensionFilter filterImagens = new ExtensionFilter("imagem", "*.jpeg", "*.jpg", "*.png", "*.bmp"); + fileChooser.getExtensionFilters().add(filterImagens); + try { + file = fileChooser.showOpenDialog(stage); + fileAsStream = new FileInputStream(file); + capaEvento.setImage(new Image(fileAsStream)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (NullPointerException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/com/casaculturaqxd/sgec/controller/LoginController.java b/src/main/java/com/casaculturaqxd/sgec/controller/LoginController.java index b3eecbad..beec1704 100644 --- a/src/main/java/com/casaculturaqxd/sgec/controller/LoginController.java +++ b/src/main/java/com/casaculturaqxd/sgec/controller/LoginController.java @@ -29,8 +29,8 @@ public class LoginController { private User usuario; private UserDAO userDAO; - private final Database userConnection = DatabasePostgres.getInstance("URL", "USER_NAME", - "PASSWORD"); + + private final Database userConnection = DatabasePostgres.getInstance("URL", "USER_NAME", "PASSWORD"); /** * Carrega a página com o botão de login desabilitado diff --git a/src/main/java/com/casaculturaqxd/sgec/controller/VisualizarEventoController.java b/src/main/java/com/casaculturaqxd/sgec/controller/VisualizarEventoController.java index 0143cf88..aaa1df81 100644 --- a/src/main/java/com/casaculturaqxd/sgec/controller/VisualizarEventoController.java +++ b/src/main/java/com/casaculturaqxd/sgec/controller/VisualizarEventoController.java @@ -1,7 +1,10 @@ package com.casaculturaqxd.sgec.controller; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.sql.Date; import java.sql.SQLException; import java.sql.Time; @@ -70,6 +73,7 @@ import javafx.scene.control.Tooltip; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.TextFieldTableCell; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.Clipboard; import javafx.scene.input.ClipboardContent; @@ -78,6 +82,7 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.FileChooser; +import javafx.stage.FileChooser.ExtensionFilter; import javafx.stage.Stage; import javafx.util.Duration; import javafx.util.converter.IntegerStringConverter; @@ -88,6 +93,7 @@ public class VisualizarEventoController implements ControllerServiceFile, Contro private DatabasePostgres db = DatabasePostgres.getInstance("URL", "USER_NAME", "PASSWORD"); private EventoDAO eventoDAO = new EventoDAO(); private LocalizacaoDAO localizacaoDAO = new LocalizacaoDAO(); + private ServiceFileDAO serviceFileDAO; private File lastDirectoryOpen; private ArrayList removedFiles; private DateFormat formatterHorario; @@ -134,8 +140,11 @@ public class VisualizarEventoController implements ControllerServiceFile, Contro @FXML private ImageView copiaCola; @FXML + ImageView capaEvento; + @FXML private Tooltip tooltipCliboard; private Alert mensagem = new Alert(AlertType.NONE); + File file = null; public void initialize() throws IOException { formatterHorario = new SimpleDateFormat("HH:mm"); @@ -155,6 +164,7 @@ public void initialize() throws IOException { removedFiles = new ArrayList<>(); eventoDAO.setConnection(db.getConnection()); localizacaoDAO.setConnection(db.getConnection()); + serviceFileDAO = new ServiceFileDAO(db.getConnection()); compararDatas(); } @@ -253,6 +263,21 @@ private void loadContent() throws IOException, SQLException { addIndicador(tabelaIndicadoresGerais, numeroPublico); addIndicador(tabelaIndicadoresMeta1, numeroMestres); addIndicador(tabelaIndicadoresMeta2, numeroMunicipios); + + if(evento.getImagemCapa() != null){ + InputStream fileAsStream; + try { + file = serviceFileDAO.getContent(evento.getImagemCapa()); + fileAsStream = new FileInputStream(file); + this.capaEvento.setImage(new Image(fileAsStream)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (NullPointerException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + } } private void loadInstituicoes() { @@ -319,6 +344,20 @@ private Evento getTargetEvento() { .setHorario(formatTimeInputField(horario)).setCargaHoraria(formatTimeInputField(cargaHoraria)) .setNumParticipantesEsperado(numeroMestres.getValorEsperado()) .setMunicipiosEsperado(numeroMunicipios.getValorEsperado()); + if(file != null){ + ServiceFile serviceFileTemp = new ServiceFile(file); + try { + if(serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).isEmpty()){ + serviceFileDAO.inserirArquivo(serviceFileTemp); + serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get(); + } else { + serviceFileTemp = serviceFileDAO.getArquivo(serviceFileTemp.getFileKey()).get(); + } + } catch (SQLException e) { + e.printStackTrace(); + } + eventoBuilder.setImagemCapa(serviceFileTemp); + } return eventoBuilder.getEvento(); } @@ -983,4 +1022,21 @@ public void onChanged(ListChangeListener.Change + @@ -24,13 +25,26 @@ - + + + + + + + + +