Search in sources :

Example 1 with Voo

use of br.senac.tads3.pi03b.gruposete.models.Voo in project Loja_Agencia_De_Viagens by ArtCouSan.

the class VooDAO method ListaVoo.

public List<Voo> ListaVoo() throws SQLException, ClassNotFoundException {
    List<Voo> ListaVoo = new ArrayList<>();
    connection = DbUtil.getConnection();
    String query = "SELECT * FROM Voo ORDER BY origem WHERE ativo=true";
    try {
        statement = connection.createStatement();
        resultSet = statement.executeQuery(query);
        while (resultSet.next()) {
            Voo voo = new Voo();
            voo.setId_voo(resultSet.getInt("id_voo"));
            voo.setData_ida(resultSet.getString("data_ida"));
            voo.setData_volta(resultSet.getString("data_volta"));
            voo.setDestino(resultSet.getString("destino"));
            voo.setOrigem(resultSet.getString("origem"));
            voo.setQuantidade_passagens(resultSet.getInt("quantidade_passagens"));
            voo.setPreco(resultSet.getFloat("preco"));
            ListaVoo.add(voo);
        }
    } catch (SQLException e) {
    }
    connection.close();
    return ListaVoo;
}
Also used : Voo(br.senac.tads3.pi03b.gruposete.models.Voo) ArrayList(java.util.ArrayList)

Example 2 with Voo

use of br.senac.tads3.pi03b.gruposete.models.Voo in project Loja_Agencia_De_Viagens by ArtCouSan.

the class BuscaVooVendaServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        String busca = request.getParameter("busca");
        VendaDAO dao = new VendaDAO();
        ArrayList<Voo> voo = dao.procurarVoo(busca);
        JSONArray jsonArray = new JSONArray();
        for (Voo voos : voo) {
            JSONObject json = new JSONObject();
            json.put("id_voo", voos.getId_voo());
            json.put("data_volta", voos.getData_volta());
            json.put("data_ida", voos.getData_ida());
            json.put("origem", voos.getOrigem());
            json.put("preco", voos.getPreco());
            json.put("quantidade_passagens", voos.getQuantidade_passagens());
            json.put("destino", voos.getDestino());
            jsonArray.add(json);
        }
        try (PrintWriter out = response.getWriter()) {
            out.println(jsonArray.toJSONString());
        }
    } catch (ClassNotFoundException | SQLException e) {
    }
}
Also used : JSONObject(org.json.simple.JSONObject) SQLException(java.sql.SQLException) Voo(br.senac.tads3.pi03b.gruposete.models.Voo) JSONArray(org.json.simple.JSONArray) VendaDAO(br.senac.tads3.pi03b.gruposete.dao.VendaDAO) PrintWriter(java.io.PrintWriter)

Example 3 with Voo

use of br.senac.tads3.pi03b.gruposete.models.Voo 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 4 with Voo

use of br.senac.tads3.pi03b.gruposete.models.Voo in project Loja_Agencia_De_Viagens by ArtCouSan.

the class BuscaVooVendaServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        String busca = request.getParameter("busca");
        VendaDAO dao = new VendaDAO();
        ArrayList<Voo> voo = dao.procurarVoo(busca);
        JSONArray jsonArray = new JSONArray();
        for (Voo voos : voo) {
            JSONObject json = new JSONObject();
            json.put("id_voo", voos.getId());
            json.put("data_volta", voos.getData_volta());
            json.put("data_ida", voos.getData_ida());
            json.put("origem", voos.getOrigem());
            json.put("preco", voos.getPreco());
            json.put("quantidade_passagens", voos.getQuantidade_passagens());
            json.put("destino", voos.getDestino());
            jsonArray.add(json);
        }
        response.setCharacterEncoding("UTF-8");
        try (PrintWriter out = response.getWriter()) {
            out.println(jsonArray.toJSONString());
        }
    } catch (ClassNotFoundException | SQLException e) {
    }
}
Also used : JSONObject(org.json.simple.JSONObject) SQLException(java.sql.SQLException) Voo(br.senac.tads3.pi03b.gruposete.models.Voo) JSONArray(org.json.simple.JSONArray) VendaDAO(br.senac.tads3.pi03b.gruposete.dao.VendaDAO) PrintWriter(java.io.PrintWriter)

Example 5 with Voo

use of br.senac.tads3.pi03b.gruposete.models.Voo in project Loja_Agencia_De_Viagens by ArtCouSan.

the class AlteraVooServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    int id = Integer.parseInt(request.getParameter("id"));
    VooDAO dao = new VooDAO();
    String action = request.getParameter("action");
    if ("edit".equalsIgnoreCase(action)) {
        try {
            Voo voos = dao.getVooById(id);
            request.setAttribute("voos", voos);
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(AlteraVooServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/EditarVoo.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : SQLException(java.sql.SQLException) Voo(br.senac.tads3.pi03b.gruposete.models.Voo) VooDAO(br.senac.tads3.pi03b.gruposete.dao.VooDAO) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

Voo (br.senac.tads3.pi03b.gruposete.models.Voo)12 SQLException (java.sql.SQLException)6 VooDAO (br.senac.tads3.pi03b.gruposete.dao.VooDAO)5 ArrayList (java.util.ArrayList)4 RequestDispatcher (javax.servlet.RequestDispatcher)4 RelatorioDAO (br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO)3 VendaDAO (br.senac.tads3.pi03b.gruposete.dao.VendaDAO)3 RelatorioMudancas (br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas)3 IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 HttpSession (javax.servlet.http.HttpSession)3 VooService (br.senac.tads3.pi03b.gruposete.services.VooService)2 PrintWriter (java.io.PrintWriter)2 JSONArray (org.json.simple.JSONArray)2 JSONObject (org.json.simple.JSONObject)2 ClienteDAO (br.senac.tads3.pi03b.gruposete.dao.ClienteDAO)1 HotelDAO (br.senac.tads3.pi03b.gruposete.dao.HotelDAO)1 Cliente (br.senac.tads3.pi03b.gruposete.models.Cliente)1 Hotel (br.senac.tads3.pi03b.gruposete.models.Hotel)1 Venda (br.senac.tads3.pi03b.gruposete.models.Venda)1