Search in sources :

Example 1 with ClienteDAO

use of br.senac.tads3.pi03b.gruposete.dao.ClienteDAO in project Loja_Agencia_De_Viagens by ArtCouSan.

the class VendaServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, FileNotFoundException {
    double totalP = Double.parseDouble(request.getParameter("totalP"));
    if (totalP != 0) {
        String cpf = request.getParameter("cpf");
        ClienteDAO clienteData = new ClienteDAO();
        Cliente cliente = null;
        try {
            cliente = clienteData.getClienteByCPF(cpf);
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        HttpSession sessao = request.getSession();
        int identificacaoF = (int) sessao.getAttribute("id_func");
        Venda venda = new Venda(cliente.getId(), identificacaoF, totalP);
        VendaDAO vendaData = new VendaDAO();
        try {
            vendaData.inserir(venda);
            RelatorioDAO relatorioDAO = new RelatorioDAO();
            RelatorioMudancas relatorio = new RelatorioMudancas();
            relatorio.setId_func(identificacaoF);
            relatorio.setMudanca("Venda efetuada!");
            relatorioDAO.inserir(relatorio);
        } catch (SQLException | ClassNotFoundException | ParseException ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        int idLista = 0;
        try {
            idLista = vendaData.maiorIdVenda();
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        String idsVoos = request.getParameter("idsVoos");
        String idsHoteis = request.getParameter("idsHoteis");
        String precosVoos = request.getParameter("precosVoos");
        String precosHoteis = request.getParameter("precosHoteis");
        String quantidadeVoos = request.getParameter("quantidadeVoos");
        String quantidadeHoteis = request.getParameter("quantidadeHoteis");
        if (idsVoos.length() != 0) {
            String[] idsV = idsVoos.split(",");
            String[] precosV = precosVoos.split(",");
            String[] quantidadesV = quantidadeVoos.split(",");
            for (int i = 0; i < idsV.length; i++) {
                try {
                    VooDAO voo = new VooDAO();
                    int idV = Integer.parseInt(idsV[i]);
                    Voo vooEncontrado = voo.getVooById(idV);
                    int qtd_encontradaV = vooEncontrado.getQuantidade_passagens();
                    int quantidadeV = Integer.parseInt(quantidadesV[i]);
                    float precoV = Float.parseFloat(precosV[i]);
                    int novaQtdVoo = qtd_encontradaV - quantidadeV;
                    vendaData.inserirLista(idV, quantidadeV, precoV, idLista, "V");
                    vendaData.removerEstoqueVoo(idV, novaQtdVoo);
                } catch (SQLException | ClassNotFoundException ex) {
                    Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        if (idsHoteis.length() != 0) {
            String[] idsH = idsHoteis.split(",");
            String[] precosH = precosHoteis.split(",");
            String[] quantidadesH = quantidadeHoteis.split(",");
            for (int i = 0; i < idsH.length; i++) {
                try {
                    HotelDAO hotel = new HotelDAO();
                    int idH = Integer.parseInt(idsH[i]);
                    Hotel hotelEncontrado = hotel.getHotelById(idH);
                    int qtd_encontradaH = hotelEncontrado.getQuantidade_quartos();
                    int quantidadeH = Integer.parseInt(quantidadesH[i]);
                    float precoH = Float.parseFloat(precosH[i]);
                    int novaQtdHotel = qtd_encontradaH - quantidadeH;
                    vendaData.inserirLista(idH, quantidadeH, precoH, idLista, "H");
                    vendaData.removerEstoqueHotel(idH, novaQtdHotel);
                } catch (SQLException | ClassNotFoundException ex) {
                    Logger.getLogger(VendaServlet.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
        response.sendRedirect(request.getContextPath() + "/inicio");
    } else {
        response.sendRedirect(request.getContextPath() + "/inicio");
    }
}
Also used : SQLException(java.sql.SQLException) HotelDAO(br.senac.tads3.pi03b.gruposete.dao.HotelDAO) HttpSession(javax.servlet.http.HttpSession) VendaDAO(br.senac.tads3.pi03b.gruposete.dao.VendaDAO) VooDAO(br.senac.tads3.pi03b.gruposete.dao.VooDAO) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) Venda(br.senac.tads3.pi03b.gruposete.models.Venda) RelatorioDAO(br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO) Voo(br.senac.tads3.pi03b.gruposete.models.Voo) RelatorioMudancas(br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas) ParseException(java.text.ParseException) Cliente(br.senac.tads3.pi03b.gruposete.models.Cliente) Hotel(br.senac.tads3.pi03b.gruposete.models.Hotel)

Example 2 with ClienteDAO

use of br.senac.tads3.pi03b.gruposete.dao.ClienteDAO in project Loja_Agencia_De_Viagens by ArtCouSan.

the class PreVendaServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    boolean erro = false;
    ClienteDAO cliente = new ClienteDAO();
    String cpf = request.getParameter("cpf");
    boolean verificaCPF = false;
    try {
        verificaCPF = cliente.verificarCPF(cpf);
    } catch (SQLException | ClassNotFoundException ex) {
        Logger.getLogger(PreVendaServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (verificaCPF) {
        erro = true;
    } else {
        request.setAttribute("erroCpf", true);
    }
    if (erro) {
        request.setAttribute("cpf", cpf);
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/Venda.jsp");
        dispatcher.forward(request, response);
    } else {
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/PreVenda.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : SQLException(java.sql.SQLException) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 3 with ClienteDAO

use of br.senac.tads3.pi03b.gruposete.dao.ClienteDAO in project Loja_Agencia_De_Viagens by ArtCouSan.

the class BuscaClienteServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ClienteDAO dao = new ClienteDAO();
    String pesquisa = request.getParameter("pesquisa");
    try {
        if ("".equals(pesquisa.trim())) {
            List<Cliente> encontrados = dao.ListarCliente();
            request.setAttribute("encontrados", encontrados);
            request.setAttribute("pesquisa", pesquisa);
        } else {
            List<Cliente> encontrados = dao.procurarCliente(pesquisa);
            request.setAttribute("encontrados", encontrados);
            request.setAttribute("pesquisa", pesquisa);
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/ListaCliente.jsp");
        dispatcher.forward(request, response);
    } catch (IOException | SQLException | ClassNotFoundException ex) {
        Logger.getLogger(BuscaClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : SQLException(java.sql.SQLException) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) IOException(java.io.IOException) Cliente(br.senac.tads3.pi03b.gruposete.models.Cliente) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 4 with ClienteDAO

use of br.senac.tads3.pi03b.gruposete.dao.ClienteDAO in project Loja_Agencia_De_Viagens by ArtCouSan.

the class ClienteService method validaCpf.

public boolean validaCpf(String cpf) throws SQLException, ClassNotFoundException {
    ClienteDAO verificacao = new ClienteDAO();
    ValidaCPF validador = new ValidaCPF();
    return verificacao.verificarCPF(cpf) || validador.isCPF(cpf);
}
Also used : ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO)

Example 5 with ClienteDAO

use of br.senac.tads3.pi03b.gruposete.dao.ClienteDAO in project Loja_Agencia_De_Viagens by ArtCouSan.

the class BuscaUsuarioServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    boolean erro = false;
    String pesquisa = request.getParameter("pesquisa");
    if (!erro) {
        try {
            ClienteDAO dao = new ClienteDAO();
            List<Cliente> encontrados = dao.procurarCliente(pesquisa);
            request.setAttribute("encontrados", encontrados);
            request.setAttribute("pesquisa", pesquisa);
            RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/Listar/ListaUsuario.jsp");
            dispatcher.forward(request, response);
        } catch (IOException | SQLException | ClassNotFoundException ex) {
            Logger.getLogger(BuscaClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/Listar/ListarUsuario.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : SQLException(java.sql.SQLException) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) IOException(java.io.IOException) Cliente(br.senac.tads3.pi03b.gruposete.models.Cliente) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

ClienteDAO (br.senac.tads3.pi03b.gruposete.dao.ClienteDAO)10 SQLException (java.sql.SQLException)9 Cliente (br.senac.tads3.pi03b.gruposete.models.Cliente)7 RequestDispatcher (javax.servlet.RequestDispatcher)7 IOException (java.io.IOException)6 RelatorioDAO (br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO)4 RelatorioMudancas (br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas)4 ServletException (javax.servlet.ServletException)4 HttpSession (javax.servlet.http.HttpSession)4 VendaDAO (br.senac.tads3.pi03b.gruposete.dao.VendaDAO)2 Venda (br.senac.tads3.pi03b.gruposete.models.Venda)2 ClienteService (br.senac.tads3.pi03b.gruposete.services.ClienteService)2 FuncionarioDAO (br.senac.tads3.pi03b.gruposete.dao.FuncionarioDAO)1 HotelDAO (br.senac.tads3.pi03b.gruposete.dao.HotelDAO)1 VooDAO (br.senac.tads3.pi03b.gruposete.dao.VooDAO)1 Funcionario (br.senac.tads3.pi03b.gruposete.models.Funcionario)1 Hotel (br.senac.tads3.pi03b.gruposete.models.Hotel)1 Voo (br.senac.tads3.pi03b.gruposete.models.Voo)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1