1
0
Fork 0

Add delete

This commit is contained in:
Ethanell 2022-06-29 22:48:35 +02:00
parent bdd9dba626
commit 538f00bef2
10 changed files with 140 additions and 12 deletions

View file

@ -16,7 +16,8 @@
<h1>${confirm} </h1>
<form action="list.htm" method="POST">
<input type="submit" value="Afficher tous les enregistrements" />
<input hidden type="text" name="type" value="${type}" />
<input type="submit" value="Afficher tous les enregistrements" />
</form>
</body>
</html>

View file

@ -13,8 +13,8 @@
<c:choose>
<c:when test="${type == 'customer'}">
<p>
<label for="numero">Numero</label>
<input type="text" name="numero" value="${result.customerId}" size="30" id="numero" />
<label for="customerId">Numero</label>
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
</p>
<p>
<label for="nom">Nom</label>

View file

@ -16,7 +16,8 @@
<h1>${confirm} </h1>
<form action="list.htm" method="POST">
<input type="submit" value="Afficher tous les enregistrements" />
<input hidden type="text" name="type" value="${type}" />
<input type="submit" value="Afficher tous les enregistrements" />
</form>
</body>
</html>

View file

@ -13,8 +13,8 @@
<c:choose>
<c:when test="${type == 'customer'}">
<p>
<label for="numero">Numero</label>
<input type="text" name="numero" value="${result.customerId}" size="30" id="numero" />
<label for="customerId">Numero</label>
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
</p>
<p>
<label for="nom">Nom</label>

View file

@ -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(){

View file

@ -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,

View file

@ -16,7 +16,8 @@
<h1>${confirm} </h1>
<form action="list.htm" method="POST">
<input type="submit" value="Afficher tous les enregistrements" />
<input hidden type="text" name="type" value="${type}" />
<input type="submit" value="Afficher tous les enregistrements" />
</form>
</body>
</html>

View file

@ -13,8 +13,8 @@
<c:choose>
<c:when test="${type == 'customer'}">
<p>
<label for="numero">Numero</label>
<input type="text" name="numero" value="${result.customerId}" size="30" id="numero" />
<label for="customerId">Numero</label>
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
</p>
<p>
<label for="nom">Nom</label>