1
0
Fork 0

Add add data

This commit is contained in:
Ethanell 2022-06-30 20:48:39 +02:00
parent 1b2d645bf2
commit 6d977fc447
11 changed files with 124 additions and 81 deletions

View file

@ -103,8 +103,11 @@
<input type="number" step="0.0001" name="markup" value="${result.markup}" id="markup" />
</p>
<p>
<label for="markup">Available</label>
<input type="checkbox" name="available" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="available" />
<label for="available">Available</label>
<label for="isavailable">TRUE:</label>
<input type="radio" name="available" value="TRUE" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="isavailable" />
<label for="notavailable">FALSE:</label>
<input type="radio" name="available" value="FALSE" <c:if test="${result.available == 'FALSE'}">checked</c:if> id="notavailable" />
</p>
<p>
<label for="description">Description</label>
@ -184,11 +187,19 @@
</c:choose>
<input hidden type="text" name="type" value="${type}" />
<input type="submit" value="Modifier" formaction="update.htm" />
<input type="submit" value="Supprimer" formaction="delete.htm" />
<c:if test="${type == 'customer'}">
<input type="submit" value="Afficher les achats" formaction="achats.htm" />
</c:if>
<c:choose>
<c:when test="${save != null}">
<input type="submit" value="Add" formaction="add.htm" />
</c:when>
<c:otherwise>
<input type="submit" value="Edit" formaction="update.htm" />
<input type="submit" value="Delete" formaction="delete.htm" />
<c:if test="${type == 'customer'}">
<input type="submit" value="Afficher les achats" formaction="achats.htm" />
</c:if>
</c:otherwise>
</c:choose>
</form>
</body>

View file

@ -20,6 +20,10 @@
<h1>${error}</h1>
</c:when>
<c:otherwise>
<form name="Add" action="detail.htm" method="POST">
<input hidden type="text" name="type" value="${type}"/>
<input type=submit value="Add" />
</form>
<table border="1" cellpadding="10">
<TR>
<c:forEach items="${colonnes}" var="col">

View file

@ -187,12 +187,18 @@
</c:choose>
<input hidden type="text" name="type" value="${type}" />
<input type="submit" value="Modifier" formaction="update.htm" />
<input type="submit" value="Supprimer" formaction="delete.htm" />
<c:if test="${type == 'customer'}">
<input type="submit" value="Afficher les achats" formaction="achats.htm" />
</c:if>
<c:choose>
<c:when test="${save != null}">
<input type="submit" value="Add" formaction="save.htm" />
</c:when>
<c:otherwise>
<input type="submit" value="Edit" formaction="update.htm" />
<input type="submit" value="Delete" formaction="delete.htm" />
<c:if test="${type == 'customer'}">
<input type="submit" value="Afficher les achats" formaction="achats.htm" />
</c:if>
</c:otherwise>
</c:choose>
</form>
</body>
</html>

View file

@ -20,6 +20,10 @@
<h1>${error}</h1>
</c:when>
<c:otherwise>
<form name="Add" action="formAdd.htm" method="POST">
<input hidden type="text" name="type" value="${type}"/>
<input type=submit value="Add" />
</form>
<table border="1" cellpadding="10">
<TR>
<c:forEach items="${colonnes}" var="col">

View file

@ -3,8 +3,10 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/detail.jsp</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/resultat.jsp</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/PurchaseOrder.java</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/Product.java</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/ProductCode.java</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/DiscountCode.java</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/controller/BddController.java</file>
<file>file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/MagasinHelper.java</file>
</group>

View file

@ -384,16 +384,14 @@ List resultat=null;
}
return resultat;
}
public void insertCustomer (int _customerId, char _discountCode, String _zip) {
public void add (Object data) {
Transaction tx=null;
try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush();
tx=session.beginTransaction();
Customer a =new Customer(_customerId,_discountCode,_zip);
session.save(a);
session.save(data);
tx.commit();
}
catch (Exception e) {
@ -429,30 +427,6 @@ public void update (Object data) {
}
public void updateCustomer (int _customerId,char _discountCode, String _name, String _adress, String _phone,String _email, String _zip){
Transaction tx=null;
try{
if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession();
session.flush();
tx=session.beginTransaction();
Customer a =new Customer(_customerId,_discountCode,_name, _adress, _phone,_email, _zip);
session.update(a);
tx.commit();
}
catch (Exception e) {
e.printStackTrace();
tx.rollback();
throw e;
}
finally{
if (session.isOpen())session.close();
}
}
public Customer getClient(int id){

View file

@ -106,17 +106,41 @@ public class BddController extends MultiActionController {
return mv;
}
public ModelAndView add(HttpServletRequest request,
public ModelAndView formAdd(HttpServletRequest request,
HttpServletResponse response) throws Exception {
sessionInit(request);
sessionInit(request);
String type = request.getParameter("type");
ModelAndView mv = new ModelAndView("detail");
mv.addObject("user",session.getAttribute("user"));
mv.addObject("type", type);
mv.addObject("save", true);
ModelAndView mv = new ModelAndView("form_inscription");
switch (type) {
case "customer":
mv.addObject("code",new MagasinHelper().getDiscountCodes());
mv.addObject("cpostaux",new MagasinHelper().getZipCode());
break;
case "product":
mv.addObject("manufacturers", new MagasinHelper().getManufacturers());
mv.addObject("productCodes", new MagasinHelper().getProductCodes());
break;
case "purchase":
mv.addObject("customers", new MagasinHelper().getClients());
mv.addObject("products", new MagasinHelper().getProducts());
break;
case "discount":
break;
case "prodCode":
mv.addObject("code",new MagasinHelper().getDiscountCodes());
break;
default:
mv.addObject("error", "Type not found");
}
mv.addObject("user",session.getAttribute("user"));
mv.addObject("discount",new MagasinHelper().getDiscountCodesColums());
mv.addObject("code",new MagasinHelper().getZipCode());
return mv;
return mv;
}
public ModelAndView detail(HttpServletRequest request,
HttpServletResponse response) throws Exception {
sessionInit(request);
@ -194,19 +218,6 @@ public class BddController extends MultiActionController {
return mv;
}
public ModelAndView save(HttpServletRequest request,
HttpServletResponse response) throws Exception {
sessionInit(request);
String param1 = request.getParameter("nom");
String param2 = request.getParameter("adresse");
String param3 = request.getParameter("telephone");
String param4 = request.getParameter("email");
String param5 = request.getParameter("code_remise");
String param6 = request.getParameter("CP");
new MagasinHelper().insertCustomer(new MagasinHelper().getMaxId()+1, param5.charAt(0), param6);
return new ModelAndView("confirm").addObject("confirm","enregistrement effectué");
}
public ModelAndView delete(HttpServletRequest request,
HttpServletResponse response) throws Exception {
sessionInit(request);
@ -240,16 +251,12 @@ public class BddController extends MultiActionController {
return mv;
}
public ModelAndView update(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);
Object data = null;
switch (type) {
private Object fetchDetailsData(HttpServletRequest request, ModelAndView mv) throws Exception {
String type = request.getParameter("type");
Object data = null;
switch (type) {
case "customer":
int customerId = Integer.parseInt(request.getParameter("customerId"));
char discountCode = request.getParameter("discountCode").charAt(0);
@ -305,10 +312,35 @@ public class BddController extends MultiActionController {
return mv;
}
return data;
}
public ModelAndView save(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);
Object data = fetchDetailsData(request, mv);
new MagasinHelper().add(data);
mv.addObject("confirm","Save completed");
return mv;
}
public ModelAndView update(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);
Object data = fetchDetailsData(request, mv);
new MagasinHelper().update(data);
mv.addObject("confirm","Update completed");
return mv;
}
}

View file

@ -187,12 +187,18 @@
</c:choose>
<input hidden type="text" name="type" value="${type}" />
<input type="submit" value="Modifier" formaction="update.htm" />
<input type="submit" value="Supprimer" formaction="delete.htm" />
<c:if test="${type == 'customer'}">
<input type="submit" value="Afficher les achats" formaction="achats.htm" />
</c:if>
<c:choose>
<c:when test="${save != null}">
<input type="submit" value="Add" formaction="save.htm" />
</c:when>
<c:otherwise>
<input type="submit" value="Edit" formaction="update.htm" />
<input type="submit" value="Delete" formaction="delete.htm" />
<c:if test="${type == 'customer'}">
<input type="submit" value="Afficher les achats" formaction="achats.htm" />
</c:if>
</c:otherwise>
</c:choose>
</form>
</body>
</html>

View file

@ -20,6 +20,10 @@
<h1>${error}</h1>
</c:when>
<c:otherwise>
<form name="Add" action="formAdd.htm" method="POST">
<input hidden type="text" name="type" value="${type}"/>
<input type=submit value="Add" />
</form>
<table border="1" cellpadding="10">
<TR>
<c:forEach items="${colonnes}" var="col">