From 538f00bef24b0103c74a437b09571d79270763ef Mon Sep 17 00:00:00 2001 From: Ethanell Date: Wed, 29 Jun 2022 22:48:35 +0200 Subject: [PATCH] Add delete --- .../WEB-INF/classes/DAO/MagasinHelper.class | Bin 12856 -> 14920 bytes .../classes/controller/BddController.class | Bin 8124 -> 8710 bytes build/web/WEB-INF/classes/jsp/confirm.jsp | 3 +- build/web/WEB-INF/classes/jsp/detail.jsp | 4 +- build/web/WEB-INF/jsp/confirm.jsp | 3 +- build/web/WEB-INF/jsp/detail.jsp | 4 +- src/java/DAO/MagasinHelper.java | 102 +++++++++++++++++- src/java/controller/BddController.java | 29 ++++- web/WEB-INF/jsp/confirm.jsp | 3 +- web/WEB-INF/jsp/detail.jsp | 4 +- 10 files changed, 140 insertions(+), 12 deletions(-) diff --git a/build/web/WEB-INF/classes/DAO/MagasinHelper.class b/build/web/WEB-INF/classes/DAO/MagasinHelper.class index 21edcfdb8d89bae4c4ee281b97266fc6addb5fa7..8ef5d0d44a725e258d9b82f21f9939e964c3a22a 100644 GIT binary patch literal 14920 zcmd6tdtg-6oyWiDW|EmCgFtv02s#L82zkgulmw_4RI=oO@=^iA&E%2{nam9H0D>&E zx>_E(Z53*fzE%XPMGIXOBUWgubnC8NUv0Ivx@*^NtrknyminOV_ndq0F&JU_q3`JLaLXa4^9lK>`(bF(o6-_612uvgwa=*B}iaA9u_zK4Ce*pKh$;$QKw z{P&3b_oxR4Vs z{>_6s5~}&4btFDF5Zgf6JmbJov2#|Kq`%9{kRO|MlSa9=zqoA964aZ@cl1 z8-EmV$BbAk5Dp0ps}4t-%9;ZWMl__yjk0;>iwXgcKO78)LPktrNc9SRm0p&J2ZCiY zqfx!BIuMJqO7^@!6I&&shQPRVb*7nxK|Rz|HZL9xgqkX5uw8DG5wA@4o>%B>Yjy3a z3^%gZ{?&nyQJZMx^ycdgL6+oIhy8kRp&kv$XRFW^Zw_#tgQ{oEtShV0oAg*9G}{P9 zj3`IDuuK2lOem?>tc>mI%i6xWE7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z7GLt5aKC=7f_OC8&%O>+5Ax5x$@a5vqW$a}|Jd0lp1owo_Jzz3~43$oK%dZ>Z+x`=_*e;^_203(|uI27t{_#55932 zZ-X@(Evv?+M7%EQr7kuUooelHVx2PxLx!6s9^3 z>}mMG#@7JCE&Rz~{C2|zJf)sLYryB#Gw}P3nn|L2Y=N@8jKRke!?IyyTQQpDz`{0R z4BL!JYzwB)++wy}?Jh+V7=!>@6KJ7sGd~eB>{MrvuvYZxwnPx&rwZ()0*)iLB8v(< zLvK&TC{ch|L%!Q*tVK)80u5;+u$|DbUC^=J@Me2ZlkJ6p?W3O+`w_;Dq9;3uUhEKh zlbyH^%!@g#r zK8@Ey(V%_Z^>AZYj|yV&WXM62wP?!g2aQy{vMP~FUfm|I?vhvc$g4c^>H&f&y*p`~ zF+ih1qDG6sWG~XV6jGw1EpQSGRnW!u3c5%Q7xC+10Tsv?@~Ds!i1KB*XkT2Z{E*nz H;G@3)p0~@W diff --git a/build/web/WEB-INF/classes/controller/BddController.class b/build/web/WEB-INF/classes/controller/BddController.class index a273922326ed75ce758c3267bf86b22c548307ae..646e32cbb7ca7a3603856e3fc84945d4d7c1b90b 100644 GIT binary patch delta 2994 zcma)833yc175>l6WZs?0O+p4pGJ!xq1+oaSF<7u5B?)S%q5)Ygl1v6jAu}N}V*)`( zP*B$QA;8_FDDctEt5grrrM{$vSUf~6W zyTt9E6kZhFOMX=2&k8RKe?{R{h1V2bSNMy<8wL*hF%APl-cCZBEOv> z6ck?SN3xoRi8x$HnW7QGN9IyFjZ!pP(OHVlR&_#e zj2ALNQH`SWMEsnPS|R5PsS`3$(FKz0=Y>oX&16LvdJX!5K~we}rIoHSmZlnX5x11L zio4L*6AE|6+oO?~LDS4`&ty7m?)B_gxEWhCZo&pO*Yri2Zcx3Z25Qu}8MhF0EZlW% zdni2NDi$<0(+rJUu}Ra#bP2(eV68!yYHFgH8n?qV=u4U|qss}!W{obcAQ+KWv6`Z3 z7G0s~N@^Bqwx&7MXwX%f=F$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AAnFq1x%gdwTfPwj|VPx_GaZ96=+eB6iog&19Fd!(O02!??N3_NJyAp;K^ctlp=JX3yDi=*g$6oZbU zxJ`$D;KZYHD@96rOnx87Qr*sl<{|emNvEiB^Fp0YzBoX>d$E3KEuM~Ov2-%gC7Oi& z6u4#a>Q*#vrmNfHnKa^Lb?FH>TY3Ucw0L!NB2gV3{$JIZi*vFYCYSO=EVj8e=N1Xw zuZcHGY)_f99x`8=Fx~l@L=vJUYO0ARF+@J{F~1Cy<4HUfr Wn2dsf<&91t7pX~9 z3(w01H93!`V|f7P!6wZH=$Ugx2lZKL@rtB5$+R-bv@*$zXOfKfOuVk)O@o@!rpX-| zXJL%9FveLO8giNrJsU@BlRI0`p3jZ3G+M?22v}$V3oVdn5K1I_J$~63j^{*6K?`|u z&x@8Sf0_&Nf@ltzif&jbnt_Yum8}wuPhsc91Ur}_SkjRQy!qaGsP$+)vL5Gov&z>Z z*M>E?st(iE!#y%9T#xLma8`94JS!zj8&1CCEfV{E+1dr-W~dGzqv(!f%&P$_^oAr_ixWh}bO@ z?2+O>K@mR12<*jl?2D#XCW8P;KJlm)S?Nt#WU)NMV!6s${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 @@

- - + +