Add delete
This commit is contained in:
parent
bdd9dba626
commit
538f00bef2
10 changed files with 140 additions and 12 deletions
Binary file not shown.
Binary file not shown.
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
<h1>${confirm} </h1>
|
<h1>${confirm} </h1>
|
||||||
<form action="list.htm" method="POST">
|
<form action="list.htm" method="POST">
|
||||||
|
<input hidden type="text" name="type" value="${type}" />
|
||||||
<input type="submit" value="Afficher tous les enregistrements" />
|
<input type="submit" value="Afficher tous les enregistrements" />
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
<c:choose>
|
<c:choose>
|
||||||
<c:when test="${type == 'customer'}">
|
<c:when test="${type == 'customer'}">
|
||||||
<p>
|
<p>
|
||||||
<label for="numero">Numero</label>
|
<label for="customerId">Numero</label>
|
||||||
<input type="text" name="numero" value="${result.customerId}" size="30" id="numero" />
|
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="nom">Nom</label>
|
<label for="nom">Nom</label>
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
<h1>${confirm} </h1>
|
<h1>${confirm} </h1>
|
||||||
<form action="list.htm" method="POST">
|
<form action="list.htm" method="POST">
|
||||||
|
<input hidden type="text" name="type" value="${type}" />
|
||||||
<input type="submit" value="Afficher tous les enregistrements" />
|
<input type="submit" value="Afficher tous les enregistrements" />
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
<c:choose>
|
<c:choose>
|
||||||
<c:when test="${type == 'customer'}">
|
<c:when test="${type == 'customer'}">
|
||||||
<p>
|
<p>
|
||||||
<label for="numero">Numero</label>
|
<label for="customerId">Numero</label>
|
||||||
<input type="text" name="numero" value="${result.customerId}" size="30" id="numero" />
|
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="nom">Nom</label>
|
<label for="nom">Nom</label>
|
||||||
|
|
|
@ -440,7 +440,11 @@ public void deleteCustomer (int _id) {
|
||||||
session.flush();
|
session.flush();
|
||||||
|
|
||||||
tx=session.beginTransaction();
|
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);
|
q.setInteger("_id",_id);
|
||||||
session.delete((Customer)q.list().iterator().next());
|
session.delete((Customer)q.list().iterator().next());
|
||||||
tx.commit();
|
tx.commit();
|
||||||
|
@ -454,6 +458,102 @@ public void deleteCustomer (int _id) {
|
||||||
if (session.isOpen())session.close();
|
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(){
|
public List getPurchaseColums(){
|
||||||
|
|
|
@ -201,9 +201,34 @@ public class BddController extends MultiActionController {
|
||||||
public ModelAndView delete(HttpServletRequest request,
|
public ModelAndView delete(HttpServletRequest request,
|
||||||
HttpServletResponse response) throws Exception {
|
HttpServletResponse response) throws Exception {
|
||||||
sessionInit(request);
|
sessionInit(request);
|
||||||
|
String type = request.getParameter("type");
|
||||||
|
ModelAndView mv = new ModelAndView("confirm");
|
||||||
|
mv.addObject("user",session.getAttribute("user"));
|
||||||
|
mv.addObject("type", type);
|
||||||
|
|
||||||
new MagasinHelper().deleteCustomer(Integer.parseInt(request.getParameter("numero")));
|
switch (type) {
|
||||||
return new ModelAndView("confirm").addObject("confirm","suppression effectuée");
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
mv.addObject("confirm","suppression effectuée");
|
||||||
|
return mv;
|
||||||
|
|
||||||
}
|
}
|
||||||
public ModelAndView update(HttpServletRequest request,
|
public ModelAndView update(HttpServletRequest request,
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
<h1>${confirm} </h1>
|
<h1>${confirm} </h1>
|
||||||
<form action="list.htm" method="POST">
|
<form action="list.htm" method="POST">
|
||||||
|
<input hidden type="text" name="type" value="${type}" />
|
||||||
<input type="submit" value="Afficher tous les enregistrements" />
|
<input type="submit" value="Afficher tous les enregistrements" />
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
<c:choose>
|
<c:choose>
|
||||||
<c:when test="${type == 'customer'}">
|
<c:when test="${type == 'customer'}">
|
||||||
<p>
|
<p>
|
||||||
<label for="numero">Numero</label>
|
<label for="customerId">Numero</label>
|
||||||
<input type="text" name="numero" value="${result.customerId}" size="30" id="numero" />
|
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="nom">Nom</label>
|
<label for="nom">Nom</label>
|
||||||
|
|
Reference in a new issue