Package dao

Source Code of dao.AvaliacaoItemDAO

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package dao;

import controller.operating.Strings;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import model.AvaliacaoItem;

/**
*
* @author Consult
*/
public class AvaliacaoItemDAO {
    
    public boolean salvarItensFormularioAvaliacao(ArrayList<AvaliacaoItem> itens) {
       
        Connection conexao = Conexao.getSqlConnection();
        try {
            Statement statement = conexao.createStatement();
            for(int i = 0; i < itens.size(); i++){
                /*System.out.println("INSERT INTO avaliacaoItens " +
                "(codigoAvaliacaoItens, codigoFormularioAvaliacao, codigoAvaliacao, descricao, conceito, comentario) " +
                "VALUES(" + itens.get(i).getCodigoAvaliacaoItem() +
                ", " + itens.get(i).getCodigoFormularioAvaliacao() +
                ", " + itens.get(i).getCodigoAvaliacao() +
                ", '" + itens.get(i).getDescicao() +
                "', '" + itens.get(i).getConceito() +
                "', '" + itens.get(i).getComentario() + "')");*/
               
                statement.execute("INSERT INTO avaliacaoItens " +
                "(codigoAvaliacaoItens, codigoFormularioAvaliacao, codigoAvaliacao, descricao, conceito, comentario) " +
                "VALUES(" + itens.get(i).getCodigoAvaliacaoItem() +
                ", " + itens.get(i).getCodigoFormularioAvaliacao() +
                ", " + itens.get(i).getCodigoAvaliacao() +
                ", '" + itens.get(i).getDescicao() +
                "', '" + itens.get(i).getConceito() +
                "', '" + itens.get(i).getComentario() + "')");
            }
           
            statement.close();
       
            return true;
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, Strings.getMensagemErroPersitencia("Item da Avaliação", erro.getMessage()), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
           
            return false;
        }
    }
   
    public boolean atualizarItensFormularioAvaliacao(ArrayList<AvaliacaoItem> itens) {
       
        Connection conexao = Conexao.getSqlConnection();
        try {
            Statement statement = conexao.createStatement();
            for(int i = 0; i < itens.size(); i++){
                statement.execute(
                "UPDATE avaliacaoItens " +
                "SET descricao = '" + itens.get(i).getDescicao() +
                "', conceito = '" + itens.get(i).getConceito() +
                "', comentario = '" + itens.get(i).getComentario() +
                "' WHERE codigoAvaliacaoItens = " + itens.get(i).getCodigoAvaliacaoItem() +
                " AND codigoFormularioAvaliacao = " + itens.get(i).getCodigoFormularioAvaliacao() +
                " AND codigoAvaliacao = " + itens.get(i).getCodigoAvaliacao());
            }
           
            statement.close();
       
            return true;
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, Strings.getMensagemErroEdicao("Item da Avaliação", erro.getMessage()), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
           
            return false;
        }
    }
   
    public ArrayList<AvaliacaoItem> getItensFormularioAvaliacao(int codigoFormulario, int codigoAvaliacao){
       
        ArrayList<AvaliacaoItem> listaDeItens = new ArrayList<AvaliacaoItem>();
        Connection conexao = Conexao.getSqlConnection();
        AvaliacaoItem item;
        try {
            Statement statement = conexao.createStatement();
            statement.executeQuery("SELECT * FROM avaliacaoItens " +
                    "WHERE codigoFormularioAvaliacao = " + codigoFormulario +
                    " AND codigoAvaliacao = " + codigoAvaliacao);
            //JOptionPane.showMessageDialog(null, "SQL");
            ResultSet resultSet = statement.getResultSet();
            resultSet = statement.getResultSet();
            while (resultSet.next()) {
                item = new AvaliacaoItem(
                    resultSet.getInt("codigoAvaliacaoItens"),
                    resultSet.getInt("codigoFormularioAvaliacao"),
                    resultSet.getInt("codigoAvaliacao"),
                    resultSet.getString("descricao"),
                    resultSet.getString("conceito"),
                    resultSet.getString("comentario"));
               
                listaDeItens.add(item);
            }
            resultSet.close();
            statement.close();
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, Strings.getMensagemErroRecuperacao("Item da Avaliação", erro.getMessage()), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        }
        return listaDeItens;
    }
   
    public boolean excluirItensFormularioAvaliacao(String codigoFormulario, String codigoAvaliacao){
       
        Connection conexao = Conexao.getSqlConnection();
        try {
            conexao.setAutoCommit(false);
            Statement statement = conexao.createStatement()
            statement.execute("DELETE FROM avaliacaoItens " +
                    "WHERE codigoFormularioAvaliacao = " + codigoFormulario +
                    " AND codigoAvaliacao = " + codigoAvaliacao);
           
            conexao.commit();
            conexao.setAutoCommit(true);
            statement.close();
           
            return true;
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, Strings.getMensagemErroExclusao("Item da Avaliação", erro.getMessage()), Strings.tituloMessageErro, JOptionPane.ERROR_MESSAGE);
        }
        return false;
    }
}
TOP

Related Classes of dao.AvaliacaoItemDAO

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.