diff --git a/build/web/WEB-INF/classes/DAO/MagasinHelper.class b/build/web/WEB-INF/classes/DAO/MagasinHelper.class index 054b522..9e73c1a 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$1.class b/build/web/WEB-INF/classes/controller/BddController$1.class new file mode 100644 index 0000000..a6a8dcc Binary files /dev/null and b/build/web/WEB-INF/classes/controller/BddController$1.class differ diff --git a/build/web/WEB-INF/classes/controller/BddController.class b/build/web/WEB-INF/classes/controller/BddController.class index 8a66b70..d297444 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/detail.jsp b/build/web/WEB-INF/classes/jsp/detail.jsp index 6f8c5aa..398d510 100644 --- a/build/web/WEB-INF/classes/jsp/detail.jsp +++ b/build/web/WEB-INF/classes/jsp/detail.jsp @@ -9,47 +9,89 @@ <%@include file="header.jsp" %> -
-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

+ + +

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+
+ +

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+
+
+ + - + + + +
diff --git a/build/web/WEB-INF/classes/jsp/resultat.jsp b/build/web/WEB-INF/classes/jsp/resultat.jsp index 3e70189..e3b1710 100644 --- a/build/web/WEB-INF/classes/jsp/resultat.jsp +++ b/build/web/WEB-INF/classes/jsp/resultat.jsp @@ -15,42 +15,47 @@ <%@include file="header.jsp" %> - - - - - - - - - - - - - - - -
${col}
${v} - -
- - - -
+ + +

${error}

+
+ + + + + + + - - + + + + + + + + + + + + + + - <%-- - - - - - - - --%> - -
${col}
+
+ + + +
+
${v} +
+ + + +
+
${client.customerId}${client.discountCode}${client.zip}${client.name}
- +
+ + diff --git a/build/web/WEB-INF/jsp/detail.jsp b/build/web/WEB-INF/jsp/detail.jsp index 6f8c5aa..398d510 100644 --- a/build/web/WEB-INF/jsp/detail.jsp +++ b/build/web/WEB-INF/jsp/detail.jsp @@ -9,47 +9,89 @@ <%@include file="header.jsp" %> -
-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

+ + +

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+
+ +

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+
+
+ + - + + + +
diff --git a/build/web/WEB-INF/jsp/resultat.jsp b/build/web/WEB-INF/jsp/resultat.jsp index 3e70189..e3b1710 100644 --- a/build/web/WEB-INF/jsp/resultat.jsp +++ b/build/web/WEB-INF/jsp/resultat.jsp @@ -15,42 +15,47 @@ <%@include file="header.jsp" %> - - - - - - - - - - - - - - - -
${col}
${v} - -
- - - -
+ + +

${error}

+
+ + + + + + + - - + + + + + + + + + + + + + + - <%-- - - - - - - - --%> - -
${col}
+
+ + + +
+
${v} +
+ + + +
+
${client.customerId}${client.discountCode}${client.zip}${client.name}
- +
+ + diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index 6807a2b..e9dbd15 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -2,6 +2,12 @@ - + + file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/Product.hbm.xml + file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/menu.jsp + file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/web/WEB-INF/jsp/resultat.jsp + file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/controller/BddController.java + file:/C:/Users/flifloo/Nextcloud/IUT/JEE/JEE%20Project/Code/src/java/DAO/MagasinHelper.java + diff --git a/src/java/DAO/MagasinHelper.java b/src/java/DAO/MagasinHelper.java index 3745e72..a0066e0 100644 --- a/src/java/DAO/MagasinHelper.java +++ b/src/java/DAO/MagasinHelper.java @@ -46,6 +46,28 @@ public class MagasinHelper { return resultat; } + public Product getProduct(int id){ + Product resultat=null; + Transaction tx=null; + try{ + if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx=session.beginTransaction(); + Query q=session.createQuery("from Product p where p.productId = :_id"); + q.setInteger("_id", id); + resultat=(Product)q.list().iterator().next(); + + + } catch (Exception e) { + e.printStackTrace(); + } finally{ + if (session.isOpen())session.close(); + } + + return resultat; + } + public List getClients(){ List resultat=null; Transaction tx=null; @@ -227,29 +249,7 @@ public Customer getClient(int id){ return client; } -public Customer getClient(String name){ - - - Customer client=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - tx=session.beginTransaction(); - Query q=session.createQuery(" from Customer a where a.customerId =:_name"); - q.setString("_name", name); - client=(Customer)q.list().iterator().next(); - } - catch (Exception e) { - System.out.println("erreur"+e); - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return client; -} + public void deleteCustomer (int _id) { Transaction tx=null; @@ -273,7 +273,29 @@ public void deleteCustomer (int _id) { } } - public List getAchats(int id){ + + public List getPurchase(){ + List resultat=null; + Transaction tx=null; + try{ + if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + session.flush(); + + tx=session.beginTransaction(); + Query q=session.createQuery("select po.customerId, po.productId, po.quantity, po.shippingCost, po.salesDate, po.shippingDate, po.freightCompany from PurchaseOrder po"); + resultat=(List)q.list(); + } + catch (Exception e) { + e.printStackTrace(); + } + finally{ + if (session.isOpen())session.close(); + } + + return resultat; +} + + public List getPurchase(int id){ List resultat=null; Transaction tx=null; try{ diff --git a/src/java/controller/BddController.java b/src/java/controller/BddController.java index ee6de7b..1ead67a 100644 --- a/src/java/controller/BddController.java +++ b/src/java/controller/BddController.java @@ -29,26 +29,29 @@ public class BddController extends MultiActionController { private User utilisateur; private HttpSession session; public BddController() {} + + private void sessionInit(HttpServletRequest request) { + if (login == null) + login=request.getUserPrincipal().getName(); + if (utilisateur == null) + utilisateur =new User(login); + + if (session == null) { + session=request.getSession(); + session.setAttribute("user", utilisateur); + } + } public ModelAndView menu(HttpServletRequest request, HttpServletResponse response){ - - login=request.getUserPrincipal().getName(); - - //pwd=request.getParameter("password"); - - utilisateur =new User(login); - - session=request.getSession(); - session.setAttribute("user", utilisateur); + sessionInit(request); System.out.println ("nbuser="+User.getCompteur()); return new ModelAndView("menu").addObject("user",utilisateur); } public ModelAndView logout(HttpServletRequest request, HttpServletResponse response){ - - + sessionInit(request); request.getSession().invalidate(); @@ -58,46 +61,78 @@ public class BddController extends MultiActionController { public ModelAndView list(HttpServletRequest request, HttpServletResponse response) throws Exception { - + sessionInit(request); String type = request.getParameter("type"); ModelAndView mv = new ModelAndView("resultat"); - + mv.addObject("user",session.getAttribute("user")); mv.addObject("type", type); switch (type) { case "customer": mv.addObject("results", new MagasinHelper().getClients()); + mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate")); break; case "product": mv.addObject("results", new MagasinHelper().getProducts()); + mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); break; + case "purchase": + mv.addObject("results", new MagasinHelper().getPurchase()); + mv.addObject("colonnes", Arrays.asList("customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany")); + mv.addObject("relation", new HashMap() {{ + put("customerId", "customer"); + put("productId", "product"); + }}); + break; + default: + mv.addObject("error", "Type not found"); } return mv; } public ModelAndView add(HttpServletRequest request, HttpServletResponse response) throws Exception { - + sessionInit(request); ModelAndView mv = new ModelAndView("form_inscription"); - mv.addObject("user",session.getAttribute("user")); + mv.addObject("user",session.getAttribute("user")); mv.addObject("discount",new MagasinHelper().getDiscountCode()); mv.addObject("code",new MagasinHelper().getZipCode()); return mv; } public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); + String type = request.getParameter("type"); ModelAndView mv = new ModelAndView("detail"); mv.addObject("user",session.getAttribute("user")); - mv.addObject("code",new MagasinHelper().getDiscountCode()); - mv.addObject("cpostaux",new MagasinHelper().getZipCode()); - mv.addObject("client",new MagasinHelper().getClient(request.getParameter("num"))); + mv.addObject("type", type); + + switch (type) { + case "customer": + mv.addObject("result", new MagasinHelper().getClient(Integer.parseInt(request.getParameter("num")))); + mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate")); + mv.addObject("code",new MagasinHelper().getDiscountCode()); + mv.addObject("cpostaux",new MagasinHelper().getZipCode()); + break; + case "product": + mv.addObject("result", new MagasinHelper().getProduct(Integer.parseInt(request.getParameter("num")))); + mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); + break; + case "purchase": + mv.addObject("result", new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("num")))); + mv.addObject("colonnes", Arrays.asList("customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany")); + break; + default: + mv.addObject("error", "Type not found"); + } + return mv; } public ModelAndView find(HttpServletRequest request, HttpServletResponse response) throws Exception { - + sessionInit(request); ModelAndView mv ; MagasinHelper requeteur = new MagasinHelper(); @@ -117,10 +152,12 @@ public class BddController extends MultiActionController { } public ModelAndView formfind(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); return new ModelAndView("recherche"); } public ModelAndView achats(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); ModelAndView mv = new ModelAndView("achats"); @@ -128,12 +165,13 @@ public class BddController extends MultiActionController { mv.addObject("user",session.getAttribute("user")); System.out.println("num "+Integer.parseInt(request.getParameter("numero"))); - mv.addObject("achats",new MagasinHelper().getAchats(Integer.parseInt(request.getParameter("numero")))); + mv.addObject("achats",new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("numero")))); 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"); @@ -146,6 +184,7 @@ public class BddController extends MultiActionController { } public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); new MagasinHelper().deleteCustomer(Integer.parseInt(request.getParameter("numero"))); return new ModelAndView("confirm").addObject("confirm","suppression effectuée"); @@ -153,6 +192,7 @@ public class BddController extends MultiActionController { } public ModelAndView update(HttpServletRequest request, HttpServletResponse response) throws Exception { + sessionInit(request); String param1 = request.getParameter("numero"); String param2 = request.getParameter("code_remise"); String param3 = request.getParameter("nom"); diff --git a/web/WEB-INF/jsp/detail.jsp b/web/WEB-INF/jsp/detail.jsp index 6f8c5aa..398d510 100644 --- a/web/WEB-INF/jsp/detail.jsp +++ b/web/WEB-INF/jsp/detail.jsp @@ -9,47 +9,89 @@ <%@include file="header.jsp" %> -
-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

-

- - -

+ + +

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+
+ +

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+
+
+ + - + + + +
diff --git a/web/WEB-INF/jsp/resultat.jsp b/web/WEB-INF/jsp/resultat.jsp index 3e70189..e3b1710 100644 --- a/web/WEB-INF/jsp/resultat.jsp +++ b/web/WEB-INF/jsp/resultat.jsp @@ -15,42 +15,47 @@ <%@include file="header.jsp" %> - - - - - - - - - - - - - - - -
${col}
${v} - -
- - - -
+ + +

${error}

+
+ + + + + + + - - + + + + + + + + + + + + + + - <%-- - - - - - - - --%> - -
${col}
+
+ + + +
+
${v} +
+ + + +
+
${client.customerId}${client.discountCode}${client.zip}${client.name}
- +
+ +