Search in sources :

Example 6 with ClienteDAO

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

the class CadastroClienteServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ClienteService service = new ClienteService();
    ClienteDAO dao = new ClienteDAO();
    RelatorioDAO relatorioDAO = new RelatorioDAO();
    RelatorioMudancas relatorio = new RelatorioMudancas();
    String nome = request.getParameter("nome");
    String cpf = request.getParameter("cpf");
    String sexo = request.getParameter("sexo");
    String data_nasc = request.getParameter("nascimento");
    String telefone = request.getParameter("telefone");
    String celular = request.getParameter("celular");
    String email = request.getParameter("email");
    int numero = Integer.parseInt(request.getParameter("numero"));
    String cep = request.getParameter("cep");
    String rua = request.getParameter("rua");
    String estado = request.getParameter("estado");
    String cidade = request.getParameter("cidade");
    String complemento = request.getParameter("complemento");
    request.setAttribute("erroNome", service.validaNome(nome));
    try {
        request.setAttribute("erroCpf", service.validaCpf(cpf));
    } catch (SQLException | ClassNotFoundException ex) {
        Logger.getLogger(CadastroClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    request.setAttribute("erroNascimento", service.validaNascimento(data_nasc));
    request.setAttribute("erroRua", service.validaRua(rua));
    request.setAttribute("erroNumero", service.validaNumero(numero));
    request.setAttribute("erroCep", service.validaCep(cep));
    request.setAttribute("erroCidade", service.validaCidade(cidade));
    request.setAttribute("erroEmail", service.validaEmail(email));
    Cliente cliente = new Cliente(nome.trim(), cpf.trim(), sexo.trim(), data_nasc.trim(), numero, cep.trim(), rua.trim(), estado.trim(), cidade.trim(), complemento.trim(), celular.trim(), telefone.trim(), email.trim(), true);
    try {
        if (service.validaCliente(nome, cpf, data_nasc, rua, numero, cep, cidade, email)) {
            RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/CadastroCliente.jsp");
            dispatcher.forward(request, response);
        } else {
            try {
                HttpSession sessao = request.getSession();
                int identificacaoF = (int) sessao.getAttribute("id_func");
                dao.inserir(cliente);
                relatorio.setId_func(identificacaoF);
                relatorio.setMudanca("Cadastro de cliente efetuado!");
                relatorioDAO.inserir(relatorio);
                response.sendRedirect(request.getContextPath() + "/inicio");
            } catch (Exception ex) {
                Logger.getLogger(CadastroClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    } catch (SQLException | ClassNotFoundException ex) {
        Logger.getLogger(CadastroClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : SQLException(java.sql.SQLException) HttpSession(javax.servlet.http.HttpSession) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ClienteService(br.senac.tads3.pi03b.gruposete.services.ClienteService) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) RelatorioDAO(br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO) RelatorioMudancas(br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas) Cliente(br.senac.tads3.pi03b.gruposete.models.Cliente)

Example 7 with ClienteDAO

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

the class BuscarRelatorio method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    VendaDAO venda = new VendaDAO();
    String inicio = request.getParameter("inicio");
    String fim = request.getParameter("fim");
    try {
        JSONArray jsonArray = new JSONArray();
        ArrayList<Venda> procurarVendas;
        if (inicio.length() != 0 && fim.length() != 0) {
            procurarVendas = venda.procurarVendas(inicio, fim);
        } else if (inicio.length() != 0) {
            procurarVendas = venda.procurarVendas2(inicio);
        } else if (fim.length() != 0) {
            procurarVendas = venda.procurarVendas2(fim);
        } else {
            procurarVendas = venda.procurarVendas3();
        }
        for (Venda procurarVenda : procurarVendas) {
            JSONObject json = new JSONObject();
            ClienteDAO clente = new ClienteDAO();
            FuncionarioDAO func = new FuncionarioDAO();
            Funcionario funcionarioById = func.getFuncionarioById(procurarVenda.getId_func());
            Cliente clienteById = clente.getClienteById(procurarVenda.getId_cliente());
            json.put("filial", funcionarioById.getFilial());
            json.put("funcionario", funcionarioById.getNome());
            json.put("cliente", clienteById.getNome());
            json.put("id_venda", procurarVenda.getId_venda());
            json.put("preco", procurarVenda.getPreco());
            json.put("data", procurarVenda.getData());
            jsonArray.add(json);
        }
        response.setCharacterEncoding("UTF-8");
        try (PrintWriter out = response.getWriter()) {
            out.println(jsonArray.toJSONString());
        }
    } catch (SQLException | ClassNotFoundException ex) {
        Logger.getLogger(BuscarRelatorio.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : SQLException(java.sql.SQLException) JSONArray(org.json.simple.JSONArray) VendaDAO(br.senac.tads3.pi03b.gruposete.dao.VendaDAO) FuncionarioDAO(br.senac.tads3.pi03b.gruposete.dao.FuncionarioDAO) Funcionario(br.senac.tads3.pi03b.gruposete.models.Funcionario) JSONObject(org.json.simple.JSONObject) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) Venda(br.senac.tads3.pi03b.gruposete.models.Venda) Cliente(br.senac.tads3.pi03b.gruposete.models.Cliente) PrintWriter(java.io.PrintWriter)

Example 8 with ClienteDAO

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

the class AlteraClienteServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ClienteService service = new ClienteService();
    ClienteDAO dao = new ClienteDAO();
    RelatorioDAO relatorioDAO = new RelatorioDAO();
    RelatorioMudancas relatorio = new RelatorioMudancas();
    String nome = request.getParameter("nome");
    String sexo = request.getParameter("sexo");
    String data_nasc = request.getParameter("nascimento");
    String telefone = request.getParameter("telefone");
    String celular = request.getParameter("celular");
    String email = request.getParameter("email");
    int numero = Integer.parseInt(request.getParameter("numero"));
    String cep = request.getParameter("cep");
    String rua = request.getParameter("rua");
    String estado = request.getParameter("estado");
    String cidade = request.getParameter("cidade");
    String complemento = request.getParameter("complemento");
    int id = Integer.parseInt(request.getParameter("identificacao"));
    request.setAttribute("erroNome", service.validaNome(nome));
    request.setAttribute("erroNascimento", service.validaNascimento(data_nasc));
    request.setAttribute("erroRua", service.validaRua(rua));
    request.setAttribute("erroNumero", service.validaNumero(numero));
    request.setAttribute("erroCep", service.validaCep(cep));
    request.setAttribute("erroCidade", service.validaCidade(cidade));
    request.setAttribute("erroEmail", service.validaEmail(email));
    Cliente cliente = new Cliente(nome.trim(), sexo.trim(), data_nasc.trim(), numero, cep.trim(), rua.trim(), estado.trim(), cidade.trim(), complemento.trim(), celular.trim(), telefone.trim(), email.trim(), true);
    cliente.setId(id);
    try {
        if (service.validaCliente(nome, sexo, rua, numero, cep, cidade, email)) {
            try {
                Cliente clientes = dao.getClienteById(id);
                request.setAttribute("clientes", clientes);
            } catch (ClassNotFoundException | SQLException e) {
            }
            RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/EditarCliente.jsp");
            dispatcher.forward(request, response);
        } else {
            try {
                dao.alterar(cliente);
                HttpSession sessao = request.getSession();
                int identificacaoF = (int) sessao.getAttribute("id_func");
                relatorio.setId_func(identificacaoF);
                relatorio.setMudanca("Alteração de cliente efetuada!");
                relatorioDAO.inserir(relatorio);
                response.sendRedirect(request.getContextPath() + "/inicio");
            } catch (Exception ex) {
                Logger.getLogger(AlteraClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    } catch (SQLException | ClassNotFoundException ex) {
        Logger.getLogger(AlteraClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}
Also used : SQLException(java.sql.SQLException) HttpSession(javax.servlet.http.HttpSession) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SQLException(java.sql.SQLException) ClienteService(br.senac.tads3.pi03b.gruposete.services.ClienteService) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) RelatorioDAO(br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO) RelatorioMudancas(br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas) Cliente(br.senac.tads3.pi03b.gruposete.models.Cliente)

Example 9 with ClienteDAO

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

the class AlteraClienteServlet method doGet.

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

Example 10 with ClienteDAO

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

the class ExcluiClienteServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String action = request.getParameter("action");
    ClienteDAO daoCliente = new ClienteDAO();
    RelatorioDAO relatorioDAO = new RelatorioDAO();
    RelatorioMudancas relatorio = new RelatorioMudancas();
    if ("delete".equalsIgnoreCase(action)) {
        int id = Integer.parseInt(request.getParameter("id"));
        try {
            daoCliente.excluir(id);
            HttpSession sessao = request.getSession();
            int identificacaoF = (int) sessao.getAttribute("id_func");
            relatorio.setId_func(identificacaoF);
            relatorio.setMudanca("Exclusão de cliente efetuada!");
            relatorioDAO.inserir(relatorio);
            RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/BuscaCliente.jsp");
            dispatcher.forward(request, response);
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(ExcluiClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(ExcluiClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : SQLException(java.sql.SQLException) ClienteDAO(br.senac.tads3.pi03b.gruposete.dao.ClienteDAO) HttpSession(javax.servlet.http.HttpSession) RelatorioDAO(br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO) RelatorioMudancas(br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas) RequestDispatcher(javax.servlet.RequestDispatcher) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SQLException(java.sql.SQLException)

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