diff --git a/build/web/WEB-INF/classes/DAO/MagasinHelper.class b/build/web/WEB-INF/classes/DAO/MagasinHelper.class index 21edcfd..8ef5d0d 100644 Binary files a/build/web/WEB-INF/classes/DAO/MagasinHelper.class and b/build/web/WEB-INF/classes/DAO/MagasinHelper.class differ diff --git a/build/web/WEB-INF/classes/controller/BddController.class b/build/web/WEB-INF/classes/controller/BddController.class index a273922..646e32c 100644 Binary files a/build/web/WEB-INF/classes/controller/BddController.class and b/build/web/WEB-INF/classes/controller/BddController.class differ diff --git a/build/web/WEB-INF/classes/jsp/confirm.jsp b/build/web/WEB-INF/classes/jsp/confirm.jsp index df0c922..23837a2 100644 --- a/build/web/WEB-INF/classes/jsp/confirm.jsp +++ b/build/web/WEB-INF/classes/jsp/confirm.jsp @@ -16,7 +16,8 @@

${confirm}

- + +
diff --git a/build/web/WEB-INF/classes/jsp/detail.jsp b/build/web/WEB-INF/classes/jsp/detail.jsp index c7a0739..eb6d795 100644 --- a/build/web/WEB-INF/classes/jsp/detail.jsp +++ b/build/web/WEB-INF/classes/jsp/detail.jsp @@ -13,8 +13,8 @@

- - + +

diff --git a/build/web/WEB-INF/jsp/confirm.jsp b/build/web/WEB-INF/jsp/confirm.jsp index df0c922..23837a2 100644 --- a/build/web/WEB-INF/jsp/confirm.jsp +++ b/build/web/WEB-INF/jsp/confirm.jsp @@ -16,7 +16,8 @@

${confirm}

- + +
diff --git a/build/web/WEB-INF/jsp/detail.jsp b/build/web/WEB-INF/jsp/detail.jsp index c7a0739..eb6d795 100644 --- a/build/web/WEB-INF/jsp/detail.jsp +++ b/build/web/WEB-INF/jsp/detail.jsp @@ -13,8 +13,8 @@

- - + +

diff --git a/src/java/DAO/MagasinHelper.java b/src/java/DAO/MagasinHelper.java index 458a469..4e5e905 100644 --- a/src/java/DAO/MagasinHelper.java +++ b/src/java/DAO/MagasinHelper.java @@ -440,7 +440,11 @@ public void deleteCustomer (int _id) { session.flush(); tx=session.beginTransaction(); - Query q=session.createQuery(" from Customer a where a.customerId =:_id"); + Query q=session.createQuery(" from PurchaseOrder po where po.customerId =:_id"); + q.setInteger("_id",_id); + for (Object po : q.list()) + session.delete((PurchaseOrder) po); + q=session.createQuery(" from Customer a where a.customerId =:_id"); q.setInteger("_id",_id); session.delete((Customer)q.list().iterator().next()); tx.commit(); @@ -454,6 +458,102 @@ public void deleteCustomer (int _id) { if (session.isOpen())session.close(); } +} + +public void deleteProduct (int _id) { + + Transaction tx=null; + try{ + if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx=session.beginTransaction(); + Query q=session.createQuery(" from Product a where a.productId =:_id"); + q.setInteger("_id",_id); + session.delete((Product)q.list().iterator().next()); + tx.commit(); + } + catch (Exception e) { + e.printStackTrace(); + tx.rollback(); + throw e; + } + finally{ + if (session.isOpen())session.close(); + } + +} + +public void deletePurchase(int _id) { + + Transaction tx=null; + try{ + if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx=session.beginTransaction(); + Query q=session.createQuery(" from PurchaseOrder a where a.orderNum =:_id"); + q.setInteger("_id",_id); + session.delete((PurchaseOrder)q.list().iterator().next()); + tx.commit(); + } + catch (Exception e) { + e.printStackTrace(); + tx.rollback(); + throw e; + } + finally{ + if (session.isOpen())session.close(); + } + +} + +public void deleteDiscountCode (char _id) { + + Transaction tx=null; + try{ + if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx=session.beginTransaction(); + Query q=session.createQuery(" from DiscountCode a where a.discountCode =:_id"); + q.setCharacter("_id",_id); + session.delete((DiscountCode)q.list().iterator().next()); + tx.commit(); + } + catch (Exception e) { + e.printStackTrace(); + tx.rollback(); + throw e; + } + finally{ + if (session.isOpen())session.close(); + } + +} + +public void deleteProductCode(String _id) { + + Transaction tx=null; + try{ + if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx=session.beginTransaction(); + Query q=session.createQuery(" from ProductCode a where a.prodCode =:_id"); + q.setString("_id",_id); + session.delete((ProductCode)q.list().iterator().next()); + tx.commit(); + } + catch (Exception e) { + e.printStackTrace(); + tx.rollback(); + throw e; + } + finally{ + if (session.isOpen())session.close(); + } + } public List getPurchaseColums(){ diff --git a/src/java/controller/BddController.java b/src/java/controller/BddController.java index da41b5a..6d7116f 100644 --- a/src/java/controller/BddController.java +++ b/src/java/controller/BddController.java @@ -201,9 +201,34 @@ public class BddController extends MultiActionController { public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception { sessionInit(request); + String type = request.getParameter("type"); + ModelAndView mv = new ModelAndView("confirm"); + mv.addObject("user",session.getAttribute("user")); + mv.addObject("type", type); + + switch (type) { + case "customer": + new MagasinHelper().deleteCustomer(Integer.parseInt(request.getParameter("customerId"))); + break; + case "product": + new MagasinHelper().deleteProduct(Integer.parseInt(request.getParameter("productId"))); + break; + case "purchase": + new MagasinHelper().deletePurchase(Integer.parseInt(request.getParameter("orderNum"))); + break; + case "discount": + new MagasinHelper().deleteDiscountCode(request.getParameter("discountCode").charAt(0)); + break; + case "prodCode": + new MagasinHelper().deleteProductCode(request.getParameter("prodCode")); + break; + default: + mv.addObject("error", "Type not found"); + return mv; + } - new MagasinHelper().deleteCustomer(Integer.parseInt(request.getParameter("numero"))); - return new ModelAndView("confirm").addObject("confirm","suppression effectuée"); + mv.addObject("confirm","suppression effectuée"); + return mv; } public ModelAndView update(HttpServletRequest request, diff --git a/web/WEB-INF/jsp/confirm.jsp b/web/WEB-INF/jsp/confirm.jsp index df0c922..23837a2 100644 --- a/web/WEB-INF/jsp/confirm.jsp +++ b/web/WEB-INF/jsp/confirm.jsp @@ -16,7 +16,8 @@

${confirm}

- + +
diff --git a/web/WEB-INF/jsp/detail.jsp b/web/WEB-INF/jsp/detail.jsp index c7a0739..eb6d795 100644 --- a/web/WEB-INF/jsp/detail.jsp +++ b/web/WEB-INF/jsp/detail.jsp @@ -13,8 +13,8 @@

- - + +