Skip to content

Commit

Permalink
produto possui apenas uma filial
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgurian committed Oct 27, 2019
1 parent 2f2a663 commit 25109a5
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
request.setCharacterEncoding("UTF-8");

String nome = request.getParameter("nome");
String endereco = request.getParameter("endereco");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

try {
request.setCharacterEncoding("UTF-8");

String nome = request.getParameter("nome");
String endereco = request.getParameter("endereco");
String cep = request.getParameter("cep");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
import br.com.mileniumfalcon.dao.ClienteDAO;
import br.com.mileniumfalcon.models.PessoaJuridica;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand Down Expand Up @@ -37,29 +31,28 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String nome = request.getParameter("nome");
String endereco = request.getParameter("endereco");
String cep = request.getParameter("cep");
String cnpj = request.getParameter("cnpj");
String telefone = request.getParameter("telefone");
String email = request.getParameter("email");
request.setCharacterEncoding("UTF-8");

PessoaJuridica cliente = new PessoaJuridica(nome, endereco, cep, email,
cnpj, telefone);
boolean salvou = ClienteDAO.salvarJuridico(cliente);
String nome = request.getParameter("nome");
String endereco = request.getParameter("endereco");
String cep = request.getParameter("cep");
String cnpj = request.getParameter("cnpj");
String telefone = request.getParameter("telefone");
String email = request.getParameter("email");

if (salvou) {
request.setAttribute("criadoAttr", true);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/vendedor.jsp");
dispatcher.forward(request, response);
} else {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/cadastrar-fisico.jsp");
dispatcher.forward(request, response);
}

PessoaJuridica cliente = new PessoaJuridica(nome, endereco, cep, email,
cnpj, telefone);

boolean salvou = ClienteDAO.salvarJuridico(cliente);

if (salvou) {
request.setAttribute("criadoAttr", true);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/vendedor.jsp");
dispatcher.forward(request, response);
} else {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/cadastrar-fisico.jsp");
dispatcher.forward(request, response);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,42 @@
@WebServlet(name = "CadastrarProdutoServlet", urlPatterns = {"/backoffice/cadastrar-produto"})
public class CadastrarProdutoServlet extends HttpServlet {

@Override
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/cadastrar-produto.jsp");
ArrayList<String> filiais = FuncionarioDAO.getFiliais();

request.setAttribute("filiaisAttr", filiais);

dispatcher.forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String nome = request.getParameter("nome");
String tipo = request.getParameter("tipo");
double preco = Double.parseDouble(request.getParameter("preco"));
double quantidade = Double.parseDouble(request.getParameter("quantidade"));
String [] filiaisStr = request.getParameterValues("filial");

ArrayList<Filial> filiais = new ArrayList<Filial>();

for(String filialStr : filiaisStr) {
Filial filial = FuncionarioDAO.getFilial(filialStr);
filiais.add(filial);
}

Produto produto = new Produto(nome, tipo, quantidade, preco, filiais);
boolean salvou = ProdutoDAO.salvar(produto);

if (salvou) {
request.setAttribute("criadoAttr", true);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/backoffice.jsp");
dispatcher.forward(request, response);
} else {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/cadastrar-produto.jsp");
dispatcher.forward(request, response);
}
request.setCharacterEncoding("UTF-8");

String nome = request.getParameter("nome");
String tipo = request.getParameter("tipo");
double preco = Double.parseDouble(request.getParameter("preco"));
double quantidade = Double.parseDouble(request.getParameter("quantidade"));
String filialStr = request.getParameter("filial");

Filial filial = FuncionarioDAO.getFilial(filialStr);

Produto produto = new Produto(nome, tipo, quantidade, preco, filial);
boolean salvou = ProdutoDAO.salvar(produto);

if (salvou) {
request.setAttribute("criadoAttr", true);
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/backoffice.jsp");
dispatcher.forward(request, response);
} else {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/cadastrar-produto.jsp");
dispatcher.forward(request, response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import br.com.mileniumfalcon.dao.ClienteDAO;
import br.com.mileniumfalcon.models.PessoaFisica;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -50,6 +49,8 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
request.setCharacterEncoding("UTF-8");

int id = Integer.parseInt(request.getParameter("id"));

String nome = request.getParameter("nome");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

try {
request.setCharacterEncoding("UTF-8");

int id = Integer.parseInt(request.getParameter("id"));
String nome = request.getParameter("nome");
String endereco = request.getParameter("endereco");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");

int id = Integer.parseInt(request.getParameter("id"));
String nome = request.getParameter("nome");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)

try {
if (produto != null) {

request.setAttribute("idAttr", id);
request.setAttribute("nomeAttr", produto.getNome());
request.setAttribute("precoAttr", produto.getVlrUnitario());
request.setAttribute("qntAttr", produto.getQtdProduto());
request.setAttribute("tipoAttr", produto.getTipo());
request.setAttribute("filialAttr", produto.getFilial().getNome());
}

} catch (Exception ex) {
Expand All @@ -51,24 +53,20 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");

int id = Integer.parseInt(request.getParameter("id"));

String nome = request.getParameter("nome");
String tipo = request.getParameter("tipo");
double preco = Double.parseDouble(request.getParameter("preco"));
double quantidade = Double.parseDouble(request.getParameter("quantidade"));
String [] filiaisStr = request.getParameterValues("filial");

ArrayList<Filial> filiais = new ArrayList<Filial>();

for(String filialStr : filiaisStr) {
Filial filial = FuncionarioDAO.getFilial(filialStr);
filiais.add(filial);
}

Produto produto = new Produto(id, nome, tipo, quantidade, preco, filiais);

String filialStr = request.getParameter("filial");

Filial filial = FuncionarioDAO.getFilial(filialStr);

Produto produto = new Produto(id, nome, tipo, quantidade, preco, filial);

boolean editou = ProdutoDAO.editar(produto);

if (editou) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import br.com.mileniumfalcon.dao.ClienteDAO;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package br.com.mileniumfalcon.controllers;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/br/com/mileniumfalcon/dao/FuncionarioDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ public static Filial getFilial(String nome) {
return null;
}
}

public static Filial getFilialPorId(int id) {
Connection connection = null;

try {
connection = DbConnectionDAO.openConnection();
PreparedStatement comando = connection.prepareStatement("SELECT IdFilial, Nome, Estado, Endereco, CEP FROM Filial WHERE IdFilial = ?");
comando.setInt(1, id);
ResultSet rs = comando.executeQuery();

Filial filial = new Filial();

while (rs.next()) {
filial.setId(rs.getInt("IdFilial"));
filial.setNome(rs.getString("Nome"));
filial.setEstado(rs.getString("Estado"));
filial.setEndereco(rs.getString("Endereco"));
filial.setCep(rs.getString("Cep"));
}

DbConnectionDAO.closeConnection(connection);
return filial;

} catch (ClassNotFoundException ex) {
return null;
} catch (SQLException ex) {
System.out.println(ex);
return null;
}
}

public static boolean salvar(Funcionario funcionario) {
Connection connection = null;
Expand Down
Loading

0 comments on commit 25109a5

Please sign in to comment.