noemi
6 months ago
5 changed files with 213 additions and 170 deletions
@ -0,0 +1,176 @@ |
|||||
|
/* |
||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
|
||||
|
*/ |
||||
|
package mx.edu.tsj.chapala.sistemas.jin.servicios; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.io.PrintWriter; |
||||
|
import javax.ejb.EJB; |
||||
|
import javax.servlet.ServletException; |
||||
|
import javax.servlet.annotation.WebServlet; |
||||
|
import javax.servlet.http.HttpServlet; |
||||
|
import javax.servlet.http.HttpServletRequest; |
||||
|
import javax.servlet.http.HttpServletResponse; |
||||
|
import mx.edu.tsj.chapala.sistemas.jin.bl.UbicacionBLLocal; |
||||
|
import mx.edu.tsj.chapala.sistemas.jin.modelo.Ubicacion; |
||||
|
import mx.edu.tsj.chapala.sistemas.jin.msg.Mensajes; |
||||
|
|
||||
|
/** |
||||
|
* |
||||
|
* @author noemi |
||||
|
*/ |
||||
|
@WebServlet(name = "UbicacionServlet", urlPatterns = {"/UbicacionServlet"}) |
||||
|
public class UbicacionServlet extends HttpServlet { |
||||
|
|
||||
|
@EJB |
||||
|
private UbicacionBLLocal ubicacionBL; |
||||
|
private static final String TOKEN = "4j*Lz8&mQ1^sT2n@Ew7#Vb9X%Rp6Aa"; |
||||
|
Ubicacion u; |
||||
|
/** |
||||
|
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> |
||||
|
* methods. |
||||
|
* |
||||
|
* @param request servlet request |
||||
|
* @param response servlet response |
||||
|
* @throws ServletException if a servlet-specific error occurs |
||||
|
* @throws IOException if an I/O error occurs |
||||
|
*/ |
||||
|
protected void processRequest(HttpServletRequest request, HttpServletResponse response) |
||||
|
throws ServletException, IOException { |
||||
|
response.setContentType("text/html;charset=UTF-8"); |
||||
|
try (PrintWriter out = response.getWriter()) { |
||||
|
|
||||
|
String token = request.getParameter("token"); |
||||
|
if (!"4jLz8mQ1sT2nEw7Vb9XRp6Aa".equals(token)) { |
||||
|
out.print("Acceso Denegado ⚠️"); |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
String opcion = request.getParameter("Opc"); |
||||
|
|
||||
|
/* TODO output your page here. You may use following sample code. */ |
||||
|
switch(opcion){ |
||||
|
case "1": |
||||
|
try { |
||||
|
int id = Integer.parseInt(request.getParameter("id")); |
||||
|
Ubicacion u = ubicacionBL.buscarIdInt(id); |
||||
|
|
||||
|
if (u == null || u.getStatus() == 0) { |
||||
|
out.print("No existe la ubicación ⚠️"); |
||||
|
} else { |
||||
|
|
||||
|
out.print("<h1> Ubicación 📍</h1>"); |
||||
|
out.print("<h5> Pasillo: " + u.getPasillo() + "</h5>"); |
||||
|
out.print("<h5> Anaquel: " + u.getAnaquel() + "</h5>"); |
||||
|
out.print("<h5> Nivel: " + u.getNivel() + "</h5>"); |
||||
|
} |
||||
|
} catch (NumberFormatException e) { |
||||
|
out.print("ID inválido"); |
||||
|
} |
||||
|
|
||||
|
break; |
||||
|
case "2": |
||||
|
u = ubicacionBL.buscarIdInt(Integer.parseInt(request.getParameter("id"))); |
||||
|
if(u.getStatus() == 0){ |
||||
|
out.print("No existe el elemento ⚠"); |
||||
|
}else{ |
||||
|
Mensajes resultado = ubicacionBL.elimarId(u); |
||||
|
if (resultado == Mensajes.SIN_ERROR) { |
||||
|
out.print("Eliminado con éxito ✅"); |
||||
|
} else { |
||||
|
out.print("No se pudo eliminar la ubicación ⚠"); |
||||
|
} |
||||
|
} |
||||
|
break; |
||||
|
case "3": |
||||
|
Ubicacion agregar = new Ubicacion(); |
||||
|
agregar.setStatus((short) 1); |
||||
|
agregar.setPasillo(request.getParameter("pasillo")); |
||||
|
agregar.setAnaquel(request.getParameter("anaquel")); |
||||
|
agregar.setNivel(request.getParameter("nivel")); |
||||
|
|
||||
|
ubicacionBL.agregarUbic(agregar); |
||||
|
out.print("Agregado con éxito ✅"); |
||||
|
break; |
||||
|
case "4": |
||||
|
|
||||
|
try { |
||||
|
int id = Integer.parseInt(request.getParameter("id")); |
||||
|
Ubicacion ubicacionExiste = ubicacionBL.buscarIdInt(id); |
||||
|
|
||||
|
if (ubicacionExiste == null || ubicacionExiste.getStatus() == 0) { |
||||
|
out.print("No existe esa ubicacion"); |
||||
|
} else { |
||||
|
String nuevoPasillo = request.getParameter("nombre"); |
||||
|
|
||||
|
// Actualizar los campos necesarios
|
||||
|
if (nuevoPasillo != null && !nuevoPasillo.isEmpty()) { |
||||
|
ubicacionExiste.setPasillo(nuevoPasillo); |
||||
|
} |
||||
|
|
||||
|
// Aquí puedes agregar más campos si es necesario
|
||||
|
// marcaExistente.setOtroCampo(request.getParameter("otroCampo"));
|
||||
|
|
||||
|
ubicacionBL.editar(ubicacionExiste); |
||||
|
out.print("Editado con éxito"); |
||||
|
} |
||||
|
} catch (NumberFormatException e) { |
||||
|
out.print("ID no válido"); |
||||
|
} catch (Exception e) { |
||||
|
out.print("Ocurrió un error al editar la ubicacion"); |
||||
|
} |
||||
|
break; |
||||
|
|
||||
|
|
||||
|
default: |
||||
|
out.print("<h1> No existe esa opcion </h1>"); |
||||
|
break; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
|
||||
|
/** |
||||
|
* Handles the HTTP <code>GET</code> method. |
||||
|
* |
||||
|
* @param request servlet request |
||||
|
* @param response servlet response |
||||
|
* @throws ServletException if a servlet-specific error occurs |
||||
|
* @throws IOException if an I/O error occurs |
||||
|
*/ |
||||
|
@Override |
||||
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) |
||||
|
throws ServletException, IOException { |
||||
|
processRequest(request, response); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Handles the HTTP <code>POST</code> method. |
||||
|
* |
||||
|
* @param request servlet request |
||||
|
* @param response servlet response |
||||
|
* @throws ServletException if a servlet-specific error occurs |
||||
|
* @throws IOException if an I/O error occurs |
||||
|
*/ |
||||
|
@Override |
||||
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) |
||||
|
throws ServletException, IOException { |
||||
|
processRequest(request, response); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Returns a short description of the servlet. |
||||
|
* |
||||
|
* @return a String containing servlet description |
||||
|
*/ |
||||
|
@Override |
||||
|
public String getServletInfo() { |
||||
|
return "Short description"; |
||||
|
}// </editor-fold>
|
||||
|
|
||||
|
} |
@ -1,123 +0,0 @@ |
|||||
<?xml version='1.0' encoding='UTF-8' ?> |
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
|
||||
xmlns:ui="http://xmlns.jcp.org/jsf/facelets" |
|
||||
xmlns:h="http://xmlns.jcp.org/jsf/html" |
|
||||
xmlns:p="http://primefaces.org/ui" |
|
||||
xmlns:f="http://xmlns.jcp.org/jsf/core"> |
|
||||
<ui:composition template="./template/templatePlantilla.xhtml"> |
|
||||
|
|
||||
<ui:define name="top"> |
|
||||
INVENTARIO |
|
||||
</ui:define> |
|
||||
|
|
||||
<ui:define name="content"> |
|
||||
<div class="card crud-demo"> |
|
||||
<h:form id="form"> |
|
||||
<p:growl id="messages" showDetail="true" /> |
|
||||
|
|
||||
<p:toolbar> |
|
||||
<p:toolbarGroup> |
|
||||
<p:commandButton value="Nueva Ubicacion 📍" icon="pi pi-plus" actionListener="#{ubiBean.prepararNuevaUbicacion()}" |
|
||||
update=":dialogs:manage-product-content" oncomplete="PF('manageProductDialog').show()" |
|
||||
styleClass="ui-button-raised ui-button-flat" style="margin-right: 0.5rem"> |
|
||||
<p:resetInput target=":dialogs:manage-product-content" /> |
|
||||
</p:commandButton> |
|
||||
</p:toolbarGroup> |
|
||||
</p:toolbar> |
|
||||
|
|
||||
|
|
||||
<p:dataTable id="dt-ubi" widgetVar="dtUbi" var="ubicacion" value="#{ubiBean.ubicaciones}" |
|
||||
reflow="true" styleClass="products-table" |
|
||||
rowKey="#{ubiBean.ubicacion.idUbicacion}" paginator="true" rows="10" rowSelectMode="add" paginatorPosition="bottom"> |
|
||||
|
|
||||
<f:facet name="header"> |
|
||||
<div class="products-table-header"> |
|
||||
<span style="font-weight: bold">Ubicaciones</span> |
|
||||
<span class="filter-container ui-input-icon-left"> <i class="pi pi-search"></i> |
|
||||
<p:inputText id="globalFilter" onkeyup="PF('dtUbi').filter()" placeholder="Search" /> |
|
||||
</span> |
|
||||
</div> |
|
||||
</f:facet> |
|
||||
|
|
||||
<p:column headerText="No.°" sortBy="#{ubicacion.idUbicacion}" filterBy="#{ubicacion.idUbicacion}"> |
|
||||
<h:outputText value="#{ubicacion.idUbicacion}" /> |
|
||||
</p:column> |
|
||||
|
|
||||
<p:column headerText="Pasillo" sortBy="#{ubicacion.pasillo}" filterBy="#{ubicacion.pasillo}"> |
|
||||
<h:outputText value="#{ubicacion.pasillo}" /> |
|
||||
</p:column> |
|
||||
|
|
||||
<p:column headerText="Anaquel" sortBy="#{ubicacion.anaquel}" filterBy="#{ubicacion.anaquel}"> |
|
||||
<h:outputText value="#{ubicacion.anaquel}" /> |
|
||||
</p:column> |
|
||||
|
|
||||
<p:column headerText="Nivel" sortBy="#{ubicacion.nivel}" filterBy="#{ubicacion.nivel}"> |
|
||||
<h:outputText value="#{ubicacion.nivel}" /> |
|
||||
</p:column> |
|
||||
|
|
||||
<p:column headerText="Acciones"> |
|
||||
<p:commandButton icon="pi pi-pencil" update=":dialogs:manage-product-content" |
|
||||
oncomplete="PF('manageProductDialog').show()" |
|
||||
styleClass="rounded-button ui-button-info" process="@this" |
|
||||
actionListener="#{ubiBean.preparaEliminarUbicacion(ubicacion)}"> |
|
||||
<p:resetInput target=":dialogs:manage-product-content" /> |
|
||||
</p:commandButton> |
|
||||
|
|
||||
<p:commandButton styleClass="rounded-button ui-button-danger" icon="pi pi-trash" |
|
||||
process="@this" |
|
||||
actionListener="#{ubiBean.preparaEliminarUbicacion(ubicacion)}" |
|
||||
oncomplete="PF('deleteProductDialog').show()"> |
|
||||
</p:commandButton> |
|
||||
</p:column> |
|
||||
|
|
||||
</p:dataTable> |
|
||||
</h:form> |
|
||||
|
|
||||
<h:form id="dialogs"> |
|
||||
<p:dialog header="Detalles de ubicación" showEffect="fade" modal="true" widgetVar="manageProductDialog" |
|
||||
responsive="true"> |
|
||||
<p:outputPanel id="manage-product-content" styleClass="ui-fluid"> |
|
||||
<p:outputPanel> |
|
||||
<h:panelGrid columns="2"> |
|
||||
<h:outputLabel value="Pasillo" for="Pasillo" /> |
|
||||
<p:inputText id="Pasillo" value="#{ubiBean.ubicacion.pasillo}" title="Pasillo" |
|
||||
required="true" requiredMessage="El pasillo es requerido. ⚠️" /> |
|
||||
<h:outputLabel value="Anaquel" for="Anaquel" /> |
|
||||
<p:inputText id="Anaquel" value="#{ubiBean.ubicacion.anaquel}" title="Anaquel" |
|
||||
required="true" requiredMessage="El anaquel es requerido. ⚠️" /> |
|
||||
<h:outputLabel value="Nivel" for="Nivel" /> |
|
||||
<p:inputText id="Nivel" value="#{ubiBean.ubicacion.nivel}" title="Nivel" |
|
||||
required="true" requiredMessage="El nivel es requerido. ⚠️" /> |
|
||||
</h:panelGrid> |
|
||||
</p:outputPanel> |
|
||||
</p:outputPanel> |
|
||||
|
|
||||
<f:facet name="footer"> |
|
||||
<div style="text-align: center;"> |
|
||||
<p:commandButton value="Guardar" icon="pi pi-save" |
|
||||
styleClass="ui-button-raised ui-button-flat" actionListener="#{ubiBean.agregarU()}" |
|
||||
update="manage-product-content" process="manage-product-content @this" /> |
|
||||
</div> |
|
||||
</f:facet> |
|
||||
</p:dialog> |
|
||||
|
|
||||
<p:confirmDialog widgetVar="deleteProductDialog" showEffect="fade" width="300" |
|
||||
message="¿Deseas eliminar este elemento?" header="Eliminar" severity="warn"> |
|
||||
<div style="display: flex; justify-content: space-between;"> |
|
||||
<p:commandButton value="Eliminar" icon="pi pi-trash" |
|
||||
styleClass="ui-button-raised ui-button-danger ui-button-flat" |
|
||||
actionListener="#{ubiBean.eliminarUbicacion()}" process="@this" |
|
||||
oncomplete="PF('deleteProductDialog').hide()" /> |
|
||||
<p:commandButton value="Cancelar" type="button" |
|
||||
styleClass="ui-button-raised ui-button-danger-success ui-button-flat" icon="pi pi-times" |
|
||||
onclick="PF('deleteProductDialog').hide()" /> |
|
||||
</div> |
|
||||
</p:confirmDialog> |
|
||||
</h:form> |
|
||||
</div> |
|
||||
</ui:define> |
|
||||
|
|
||||
</ui:composition> |
|
||||
|
|
||||
</html> |
|
Loading…
Reference in new issue