|
@ -6,19 +6,48 @@ package mx.edu.tsj.chapala.sistemas.jin.servicios; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.PrintWriter; |
|
|
import java.io.PrintWriter; |
|
|
|
|
|
import javax.ejb.EJB; |
|
|
import javax.servlet.ServletException; |
|
|
import javax.servlet.ServletException; |
|
|
import javax.servlet.annotation.WebServlet; |
|
|
import javax.servlet.annotation.WebServlet; |
|
|
import javax.servlet.http.HttpServlet; |
|
|
import javax.servlet.http.HttpServlet; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.bl.CategoriaBLLocal; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.bl.MarcaBLLocal; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.bl.ProductoBLLocal; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.bl.ProveedorBLLocal; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.bl.UbicacionBLLocal; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.modelo.Categoria; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.modelo.Marca; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.modelo.Producto; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.modelo.Proovedor; |
|
|
|
|
|
import mx.edu.tsj.chapala.sistemas.jin.modelo.Ubicacion; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* |
|
|
* @author estra |
|
|
* @author estra |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@WebServlet(name = "ProductosServlet", urlPatterns = {"/ProductosServlet"}) |
|
|
@WebServlet(name = "ProductosServlet", urlPatterns = {"/ProductosServlet"}) |
|
|
public class ProductosServlet extends HttpServlet { |
|
|
public class ProductosServlet extends HttpServlet { |
|
|
|
|
|
|
|
|
|
|
|
@EJB |
|
|
|
|
|
private UbicacionBLLocal ubicacionBL; |
|
|
|
|
|
|
|
|
|
|
|
@EJB |
|
|
|
|
|
private ProveedorBLLocal proveedorBL; |
|
|
|
|
|
|
|
|
|
|
|
@EJB |
|
|
|
|
|
private MarcaBLLocal marcaBL; |
|
|
|
|
|
|
|
|
|
|
|
@EJB |
|
|
|
|
|
private CategoriaBLLocal categoriaBL; |
|
|
|
|
|
|
|
|
|
|
|
@EJB |
|
|
|
|
|
private ProductoBLLocal productoBL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> |
|
|
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> |
|
|
* methods. |
|
|
* methods. |
|
@ -33,15 +62,63 @@ public class ProductosServlet extends HttpServlet { |
|
|
response.setContentType("text/html;charset=UTF-8"); |
|
|
response.setContentType("text/html;charset=UTF-8"); |
|
|
try (PrintWriter out = response.getWriter()) { |
|
|
try (PrintWriter out = response.getWriter()) { |
|
|
/* TODO output your page here. You may use following sample code. */ |
|
|
/* TODO output your page here. You may use following sample code. */ |
|
|
out.println("<!DOCTYPE html>"); |
|
|
String opcion = request.getParameter("Opc"); |
|
|
out.println("<html>"); |
|
|
|
|
|
out.println("<head>"); |
|
|
|
|
|
out.println("<title>Servlet ProductosServlet</title>"); |
|
|
switch(opcion){ |
|
|
out.println("</head>"); |
|
|
case "1": |
|
|
out.println("<body>"); |
|
|
Producto p = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id"))); |
|
|
out.println("<h1>Servlet ProductosServlet at " + request.getContextPath() + "</h1>"); |
|
|
if(p.getStatus() == 0){ |
|
|
out.println("</body>"); |
|
|
out.print("No existe ese producto"); |
|
|
out.println("</html>"); |
|
|
}else{ |
|
|
|
|
|
out.print("<h1>"+p.getNombre()+"</h1>"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case "2": |
|
|
|
|
|
Producto pE = productoBL.buscarPorIdInt(Integer.parseInt(request.getParameter("id"))); |
|
|
|
|
|
if(pE.getStatus() == 0){ |
|
|
|
|
|
out.print("No existe ese elemento"); |
|
|
|
|
|
}else{ |
|
|
|
|
|
productoBL.eliminar(pE); |
|
|
|
|
|
out.print("Eliminado con éxito"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case "3": |
|
|
|
|
|
Producto nuevo = new Producto(); |
|
|
|
|
|
Marca m = marcaBL.buscarIdInt(Integer.parseInt(request.getParameter("idMarca"))); |
|
|
|
|
|
Ubicacion u = ubicacionBL.buscarIdInt(Integer.parseInt(request.getParameter("idUbi"))); |
|
|
|
|
|
Categoria c = categoriaBL.buscarIdInt(Integer.parseInt(request.getParameter("idCat"))); |
|
|
|
|
|
Proovedor prov = proveedorBL.buscarIdInt(Integer.parseInt(request.getParameter("idProv"))); |
|
|
|
|
|
|
|
|
|
|
|
if (m == null || u == null || c == null || prov == null) { |
|
|
|
|
|
out.print("Ocurrió un error con éxito"); |
|
|
|
|
|
} else { |
|
|
|
|
|
nuevo.setMarcaidMarca(m); |
|
|
|
|
|
nuevo.setCategoriaidCategoria(c); |
|
|
|
|
|
nuevo.setUbicacionidUbicacion(u); |
|
|
|
|
|
nuevo.setProovedoridProovedor(prov); |
|
|
|
|
|
nuevo.setCodigo(request.getParameter("codigo")); |
|
|
|
|
|
nuevo.setDescripcion(request.getParameter("descrip")); |
|
|
|
|
|
nuevo.setPrecio(Double.parseDouble(request.getParameter("precio"))); |
|
|
|
|
|
nuevo.setCantidadTotal(Integer.parseInt(request.getParameter("cant"))); |
|
|
|
|
|
nuevo.setStatus((short) 1); |
|
|
|
|
|
nuevo.setNombre(request.getParameter("nombre")); |
|
|
|
|
|
|
|
|
|
|
|
productoBL.agregar(nuevo); |
|
|
|
|
|
out.print("Agregado con éxito"); |
|
|
|
|
|
} |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
|
|
out.print("<h1> No existe esa opcion </h1>"); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -57,6 +134,7 @@ public class ProductosServlet extends HttpServlet { |
|
|
@Override |
|
|
@Override |
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) |
|
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) |
|
|
throws ServletException, IOException { |
|
|
throws ServletException, IOException { |
|
|
|
|
|
|
|
|
processRequest(request, response); |
|
|
processRequest(request, response); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|