diff --git a/build/web/WEB-INF/classes/DAO/Customer.class b/build/web/WEB-INF/classes/DAO/Customer.class index e02a521..584c30e 100644 Binary files a/build/web/WEB-INF/classes/DAO/Customer.class and b/build/web/WEB-INF/classes/DAO/Customer.class differ diff --git a/build/web/WEB-INF/classes/DAO/DiscountCode.class b/build/web/WEB-INF/classes/DAO/DiscountCode.class index a5e517e..84c7077 100644 Binary files a/build/web/WEB-INF/classes/DAO/DiscountCode.class and b/build/web/WEB-INF/classes/DAO/DiscountCode.class differ diff --git a/build/web/WEB-INF/classes/DAO/HibernateUtil.class b/build/web/WEB-INF/classes/DAO/HibernateUtil.class index 1aadeb9..ba0f907 100644 Binary files a/build/web/WEB-INF/classes/DAO/HibernateUtil.class and b/build/web/WEB-INF/classes/DAO/HibernateUtil.class differ diff --git a/build/web/WEB-INF/classes/DAO/MagasinHelper.class b/build/web/WEB-INF/classes/DAO/MagasinHelper.class index 6acfb5c..a16c946 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/DAO/Manufacturer.class b/build/web/WEB-INF/classes/DAO/Manufacturer.class index e8c8db0..406e4e3 100644 Binary files a/build/web/WEB-INF/classes/DAO/Manufacturer.class and b/build/web/WEB-INF/classes/DAO/Manufacturer.class differ diff --git a/build/web/WEB-INF/classes/DAO/MicroMarket.class b/build/web/WEB-INF/classes/DAO/MicroMarket.class index 41fa13e..f9c220d 100644 Binary files a/build/web/WEB-INF/classes/DAO/MicroMarket.class and b/build/web/WEB-INF/classes/DAO/MicroMarket.class differ diff --git a/build/web/WEB-INF/classes/DAO/Product.class b/build/web/WEB-INF/classes/DAO/Product.class index a27863a..ab23df6 100644 Binary files a/build/web/WEB-INF/classes/DAO/Product.class and b/build/web/WEB-INF/classes/DAO/Product.class differ diff --git a/build/web/WEB-INF/classes/DAO/ProductCode.class b/build/web/WEB-INF/classes/DAO/ProductCode.class index efae21c..1b232d2 100644 Binary files a/build/web/WEB-INF/classes/DAO/ProductCode.class and b/build/web/WEB-INF/classes/DAO/ProductCode.class differ diff --git a/build/web/WEB-INF/classes/DAO/PurchaseOrder.class b/build/web/WEB-INF/classes/DAO/PurchaseOrder.class index 0e7f6b1..b475deb 100644 Binary files a/build/web/WEB-INF/classes/DAO/PurchaseOrder.class and b/build/web/WEB-INF/classes/DAO/PurchaseOrder.class differ diff --git a/build/web/WEB-INF/classes/controller/BddController$1.class b/build/web/WEB-INF/classes/controller/BddController$1.class index d02e32c..ea48cd6 100644 Binary files a/build/web/WEB-INF/classes/controller/BddController$1.class 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 6eb574a..e707350 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/achats.jsp b/build/web/WEB-INF/classes/jsp/achats.jsp index f285c3c..c71013a 100644 --- a/build/web/WEB-INF/classes/jsp/achats.jsp +++ b/build/web/WEB-INF/classes/jsp/achats.jsp @@ -8,27 +8,27 @@ <%@include file="header.jsp" %> - - + +

Achats du client n°<%=request.getParameter("customerId")%>

- - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
${cli.orderNum}${cli.customerId}${cli.productId}${cli.quantity}${cli.shippingCost}${cli.salesDate}${cli.shippingDate}${cli.freightCompany}
${cli.orderNum}${cli.customerId}${cli.productId}${cli.quantity}${cli.shippingCost}${cli.salesDate}${cli.shippingDate}${cli.freightCompany}
- - + + diff --git a/build/web/WEB-INF/classes/jsp/confirm.jsp b/build/web/WEB-INF/classes/jsp/confirm.jsp index 5233c5f..7440c6f 100644 --- a/build/web/WEB-INF/classes/jsp/confirm.jsp +++ b/build/web/WEB-INF/classes/jsp/confirm.jsp @@ -13,7 +13,7 @@ <%@include file="header.jsp" %> - +

${error != null ? error : confirm}

diff --git a/build/web/WEB-INF/classes/jsp/detail.jsp b/build/web/WEB-INF/classes/jsp/detail.jsp index 73ea3a9..ded1bf0 100644 --- a/build/web/WEB-INF/classes/jsp/detail.jsp +++ b/build/web/WEB-INF/classes/jsp/detail.jsp @@ -8,7 +8,7 @@ <%@include file="header.jsp" %> - + @@ -106,12 +106,12 @@ checked id="isavailable" /> - - checked id="notavailable" /> -

-

- - + + checked id="notavailable" /> +

+

+ +

@@ -185,7 +185,7 @@

- + diff --git a/build/web/WEB-INF/classes/jsp/form_inscription.jsp b/build/web/WEB-INF/classes/jsp/form_inscription.jsp index 4dbc842..3f86767 100644 --- a/build/web/WEB-INF/classes/jsp/form_inscription.jsp +++ b/build/web/WEB-INF/classes/jsp/form_inscription.jsp @@ -14,40 +14,40 @@ Bienvenue ${user.login} - +

- - + +

- - + +

- - + +

- +

- - - + + +

diff --git a/build/web/WEB-INF/classes/jsp/header.jsp b/build/web/WEB-INF/classes/jsp/header.jsp index 8b7579e..b8ff3d7 100644 --- a/build/web/WEB-INF/classes/jsp/header.jsp +++ b/build/web/WEB-INF/classes/jsp/header.jsp @@ -15,7 +15,7 @@
- + diff --git a/build/web/WEB-INF/classes/jsp/index.jsp b/build/web/WEB-INF/classes/jsp/index.jsp index 5ebe295..d74394b 100644 --- a/build/web/WEB-INF/classes/jsp/index.jsp +++ b/build/web/WEB-INF/classes/jsp/index.jsp @@ -2,5 +2,5 @@ -<% response.sendRedirect("menu.htm"); %> - +<% response.sendRedirect("menu.htm");%> + diff --git a/build/web/WEB-INF/classes/jsp/login.jsp b/build/web/WEB-INF/classes/jsp/login.jsp index bc11518..db636fd 100644 --- a/build/web/WEB-INF/classes/jsp/login.jsp +++ b/build/web/WEB-INF/classes/jsp/login.jsp @@ -13,20 +13,20 @@ - - - - - - - - - - - - - -
Utilisateur :
Mot de passe :
-
+ + + + + + + + + + + + + +
Utilisateur :
Mot de passe :
+ diff --git a/build/web/WEB-INF/classes/jsp/menu.jsp b/build/web/WEB-INF/classes/jsp/menu.jsp index ed702d7..855bcfe 100644 --- a/build/web/WEB-INF/classes/jsp/menu.jsp +++ b/build/web/WEB-INF/classes/jsp/menu.jsp @@ -14,7 +14,7 @@ <%@include file="header.jsp" %>

choisissez une opération dans la liste suivante

- +

diff --git a/build/web/WEB-INF/classes/jsp/recherche.jsp b/build/web/WEB-INF/classes/jsp/recherche.jsp index bc110dd..90e4c66 100644 --- a/build/web/WEB-INF/classes/jsp/recherche.jsp +++ b/build/web/WEB-INF/classes/jsp/recherche.jsp @@ -13,14 +13,14 @@ <%@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 bb96101..b76af35 100644 --- a/build/web/WEB-INF/classes/jsp/resultat.jsp +++ b/build/web/WEB-INF/classes/jsp/resultat.jsp @@ -14,7 +14,7 @@ <%@include file="header.jsp" %> - +

${error}

@@ -27,37 +27,37 @@ - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + +
${col}${col}
-
- - - -
-
${v} -
- - - -
-
+
+ + + +
+
${v} +
+ + + +
+
diff --git a/build/web/WEB-INF/classes/service/User.class b/build/web/WEB-INF/classes/service/User.class index d335310..0cd6d9a 100644 Binary files a/build/web/WEB-INF/classes/service/User.class and b/build/web/WEB-INF/classes/service/User.class differ diff --git a/build/web/WEB-INF/jsp/achats.jsp b/build/web/WEB-INF/jsp/achats.jsp index f285c3c..c71013a 100644 --- a/build/web/WEB-INF/jsp/achats.jsp +++ b/build/web/WEB-INF/jsp/achats.jsp @@ -8,27 +8,27 @@ <%@include file="header.jsp" %> - - + +

Achats du client n°<%=request.getParameter("customerId")%>

- - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
${cli.orderNum}${cli.customerId}${cli.productId}${cli.quantity}${cli.shippingCost}${cli.salesDate}${cli.shippingDate}${cli.freightCompany}
${cli.orderNum}${cli.customerId}${cli.productId}${cli.quantity}${cli.shippingCost}${cli.salesDate}${cli.shippingDate}${cli.freightCompany}
- - + + diff --git a/build/web/WEB-INF/jsp/confirm.jsp b/build/web/WEB-INF/jsp/confirm.jsp index 5233c5f..7440c6f 100644 --- a/build/web/WEB-INF/jsp/confirm.jsp +++ b/build/web/WEB-INF/jsp/confirm.jsp @@ -13,7 +13,7 @@ <%@include file="header.jsp" %> - +

${error != null ? error : confirm}

diff --git a/build/web/WEB-INF/jsp/detail.jsp b/build/web/WEB-INF/jsp/detail.jsp index 73ea3a9..ded1bf0 100644 --- a/build/web/WEB-INF/jsp/detail.jsp +++ b/build/web/WEB-INF/jsp/detail.jsp @@ -8,7 +8,7 @@ <%@include file="header.jsp" %> - + @@ -106,12 +106,12 @@ checked id="isavailable" /> - - checked id="notavailable" /> -

-

- - + + checked id="notavailable" /> +

+

+ +

@@ -185,7 +185,7 @@

- + diff --git a/build/web/WEB-INF/jsp/error.jsp b/build/web/WEB-INF/jsp/error.jsp deleted file mode 100644 index 14af0fd..0000000 --- a/build/web/WEB-INF/jsp/error.jsp +++ /dev/null @@ -1,18 +0,0 @@ -<%-- - Document : error - Created on : 4 mars 2018, 20:54:56 - Author : faycal ---%> - -<%@page contentType="text/html" pageEncoding="UTF-8"%> - - - - - Erreur - - - <%@include file="header.jsp" %> -

${erreur}

- - diff --git a/build/web/WEB-INF/jsp/form_inscription.jsp b/build/web/WEB-INF/jsp/form_inscription.jsp index 4dbc842..3f86767 100644 --- a/build/web/WEB-INF/jsp/form_inscription.jsp +++ b/build/web/WEB-INF/jsp/form_inscription.jsp @@ -14,40 +14,40 @@ Bienvenue ${user.login} - +

- - + +

- - + +

- - + +

- +

- - - + + +

diff --git a/build/web/WEB-INF/jsp/header.jsp b/build/web/WEB-INF/jsp/header.jsp index 8b7579e..b8ff3d7 100644 --- a/build/web/WEB-INF/jsp/header.jsp +++ b/build/web/WEB-INF/jsp/header.jsp @@ -15,7 +15,7 @@
- + diff --git a/build/web/WEB-INF/jsp/index.jsp b/build/web/WEB-INF/jsp/index.jsp index 5ebe295..d74394b 100644 --- a/build/web/WEB-INF/jsp/index.jsp +++ b/build/web/WEB-INF/jsp/index.jsp @@ -2,5 +2,5 @@ -<% response.sendRedirect("menu.htm"); %> - +<% response.sendRedirect("menu.htm");%> + diff --git a/build/web/WEB-INF/jsp/login.jsp b/build/web/WEB-INF/jsp/login.jsp index bc11518..db636fd 100644 --- a/build/web/WEB-INF/jsp/login.jsp +++ b/build/web/WEB-INF/jsp/login.jsp @@ -13,20 +13,20 @@ - - - - - - - - - - - - - -
Utilisateur :
Mot de passe :
-
+ + + + + + + + + + + + + +
Utilisateur :
Mot de passe :
+ diff --git a/build/web/WEB-INF/jsp/menu.jsp b/build/web/WEB-INF/jsp/menu.jsp index ed702d7..855bcfe 100644 --- a/build/web/WEB-INF/jsp/menu.jsp +++ b/build/web/WEB-INF/jsp/menu.jsp @@ -14,7 +14,7 @@ <%@include file="header.jsp" %>

choisissez une opération dans la liste suivante

- +

diff --git a/build/web/WEB-INF/jsp/recherche.jsp b/build/web/WEB-INF/jsp/recherche.jsp index bc110dd..90e4c66 100644 --- a/build/web/WEB-INF/jsp/recherche.jsp +++ b/build/web/WEB-INF/jsp/recherche.jsp @@ -13,14 +13,14 @@ <%@include file="header.jsp" %> - + -

+

- + diff --git a/build/web/WEB-INF/jsp/resultat.jsp b/build/web/WEB-INF/jsp/resultat.jsp index bb96101..b76af35 100644 --- a/build/web/WEB-INF/jsp/resultat.jsp +++ b/build/web/WEB-INF/jsp/resultat.jsp @@ -14,7 +14,7 @@ <%@include file="header.jsp" %> - +

${error}

@@ -27,37 +27,37 @@ - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + +
${col}${col}
-
- - - -
-
${v} -
- - - -
-
+
+ + + +
+
${v} +
+ + + +
+
diff --git a/src/java/DAO/Customer.java b/src/java/DAO/Customer.java index b18c73b..dddc9e6 100644 --- a/src/java/DAO/Customer.java +++ b/src/java/DAO/Customer.java @@ -1,149 +1,152 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - - /** * Customer generated by hbm2java */ -public class Customer implements java.io.Serializable { +public class Customer implements java.io.Serializable { - - private int customerId; - private char discountCode; - private String zip; - private String name; - private String addressline1; - private String addressline2; - private String city; - private String state; - private String phone; - private String fax; - private String email; - private Integer creditLimit; + private int customerId; + private char discountCode; + private String zip; + private String name; + private String addressline1; + private String addressline2; + private String city; + private String state; + private String phone; + private String fax; + private String email; + private Integer creditLimit; public Customer() { } - public Customer(int customerId, char discountCode, String zip) { this.customerId = customerId; this.discountCode = discountCode; this.zip = zip; } - public Customer(int customerId, char discountCode,String _name, String _adress, String _phone,String _email, String _zip) { + + public Customer(int customerId, char discountCode, String _name, String _adress, String _phone, String _email, String _zip) { this.customerId = customerId; this.discountCode = discountCode; - this.name=_name; - this.addressline1=_adress; - this.phone=_phone; - this.email=_email; + this.name = _name; + this.addressline1 = _adress; + this.phone = _phone; + this.email = _email; this.zip = _zip; } - + public Customer(int customerId, char discountCode, String zip, String name, String addressline1, String addressline2, String city, String state, String phone, String fax, String email, Integer creditLimit) { - this.customerId = customerId; - this.discountCode = discountCode; - this.zip = zip; - this.name = name; - this.addressline1 = addressline1; - this.addressline2 = addressline2; - this.city = city; - this.state = state; - this.phone = phone; - this.fax = fax; - this.email = email; - this.creditLimit = creditLimit; + this.customerId = customerId; + this.discountCode = discountCode; + this.zip = zip; + this.name = name; + this.addressline1 = addressline1; + this.addressline2 = addressline2; + this.city = city; + this.state = state; + this.phone = phone; + this.fax = fax; + this.email = email; + this.creditLimit = creditLimit; } - + public int getCustomerId() { return this.customerId; } - + public void setCustomerId(int customerId) { this.customerId = customerId; } + public char getDiscountCode() { return this.discountCode; } - + public void setDiscountCode(char discountCode) { this.discountCode = discountCode; } + public String getZip() { return this.zip; } - + public void setZip(String zip) { this.zip = zip; } + public String getName() { return this.name; } - + public void setName(String name) { this.name = name; } + public String getAddressline1() { return this.addressline1; } - + public void setAddressline1(String addressline1) { this.addressline1 = addressline1; } + public String getAddressline2() { return this.addressline2; } - + public void setAddressline2(String addressline2) { this.addressline2 = addressline2; } + public String getCity() { return this.city; } - + public void setCity(String city) { this.city = city; } + public String getState() { return this.state; } - + public void setState(String state) { this.state = state; } + public String getPhone() { return this.phone; } - + public void setPhone(String phone) { this.phone = phone; } + public String getFax() { return this.fax; } - + public void setFax(String fax) { this.fax = fax; } + public String getEmail() { return this.email; } - + public void setEmail(String email) { this.email = email; } + public Integer getCreditLimit() { return this.creditLimit; } - + public void setCreditLimit(Integer creditLimit) { this.creditLimit = creditLimit; } - - - } - - diff --git a/src/java/DAO/DiscountCode.java b/src/java/DAO/DiscountCode.java index ee0f264..e640e3a 100644 --- a/src/java/DAO/DiscountCode.java +++ b/src/java/DAO/DiscountCode.java @@ -1,48 +1,42 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - import java.math.BigDecimal; /** * DiscountCode generated by hbm2java */ -public class DiscountCode implements java.io.Serializable { +public class DiscountCode implements java.io.Serializable { - - private char discountCode; - private BigDecimal rate; + private char discountCode; + private BigDecimal rate; public DiscountCode() { } - public DiscountCode(char discountCode) { this.discountCode = discountCode; } + public DiscountCode(char discountCode, BigDecimal rate) { - this.discountCode = discountCode; - this.rate = rate; + this.discountCode = discountCode; + this.rate = rate; } - + public char getDiscountCode() { return this.discountCode; } - + public void setDiscountCode(char discountCode) { this.discountCode = discountCode; } + public BigDecimal getRate() { return this.rate; } - + public void setRate(BigDecimal rate) { this.rate = rate; } - - - } - - diff --git a/src/java/DAO/HibernateUtil.java b/src/java/DAO/HibernateUtil.java index 9eff547..7fded0c 100644 --- a/src/java/DAO/HibernateUtil.java +++ b/src/java/DAO/HibernateUtil.java @@ -8,7 +8,6 @@ package DAO; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.SessionFactory; - /** * Hibernate Utility class with a convenient method to get Session Factory * object. @@ -18,21 +17,20 @@ import org.hibernate.SessionFactory; public class HibernateUtil { private static final SessionFactory sessionFactory; - + static { try { // Create the SessionFactory from standard (hibernate.cfg.xml) // config file. - sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); - - + sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); + } catch (Throwable ex) { // Log the exception. System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } - + public static SessionFactory getSessionFactory() { return sessionFactory; } diff --git a/src/java/DAO/MagasinHelper.java b/src/java/DAO/MagasinHelper.java index 75dea46..bcd10ff 100644 --- a/src/java/DAO/MagasinHelper.java +++ b/src/java/DAO/MagasinHelper.java @@ -4,6 +4,7 @@ * and open the template in the editor. */ package DAO; + import org.hibernate.*; import org.hibernate.cfg.Configuration; import java.util.*; @@ -15,650 +16,705 @@ import org.hibernate.exception.ConstraintViolationException; * @author faycal */ public class MagasinHelper { + Session session = null; public List getColonnes() { return colonnes; } - ArrayList colonnes=new ArrayList(); + ArrayList colonnes = new ArrayList(); public MagasinHelper() { this.session = HibernateUtil.getSessionFactory().openSession(); } - - public List getProductsColums(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public List getProductsColums() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select p.productId, p.manufacturerId, p.productCode, p.purchaseCost, p.quantityOnHand, p.markup, p.available, p.description from Product p"); - resultat=q.list(); - - + + tx = session.beginTransaction(); + Query q = session.createQuery("select p.productId, p.manufacturerId, p.productCode, p.purchaseCost, p.quantityOnHand, p.markup, p.available, p.description from Product p"); + resultat = q.list(); + } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) { + session.close(); + } } return resultat; } - - public List getProducts(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public List getProducts() { + List 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"); - resultat=q.list(); - - + + tx = session.beginTransaction(); + Query q = session.createQuery("from Product p"); + resultat = q.list(); + } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) { + session.close(); + } } return resultat; } - - public Product getProduct(int id){ - Product resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + 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"); + + tx = session.beginTransaction(); + Query q = session.createQuery("from Product p where p.productId = :_id"); q.setInteger("_id", id); - resultat=(Product)q.list().iterator().next(); - - + resultat = (Product) q.list().iterator().next(); + } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) { + session.close(); + } } return resultat; } - - public List getClientsColums(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public List getClientsColums() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode"); + + tx = session.beginTransaction(); + Query q = session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode"); //Query q=session.createQuery("from Customer"); - resultat=q.list(); - - + resultat = q.list(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} - - public List getClients(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("from Customer c"); - resultat=q.list(); - - - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - + return resultat; -} - - public List getClientsColums(String name){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + public List getClients() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode and a.name like :_name"); + + tx = session.beginTransaction(); + Query q = session.createQuery("from Customer c"); + resultat = q.list(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } + } + + return resultat; + } + + public List getClientsColums(String name) { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } + session.flush(); + + tx = session.beginTransaction(); + Query q = session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip,b.rate from Customer a, DiscountCode b where a.discountCode=b.discountCode and a.name like :_name"); //Query q=session.createQuery("from Customer"); - q.setString("_name",name); - resultat=q.list(); + q.setString("_name", name); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} - - public List getClientsColums(int _id){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + return resultat; + } + + public List getClientsColums(int _id) { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip from Customer a where a.customerId = :_id"); + + tx = session.beginTransaction(); + Query q = session.createQuery("select a.customerId, a.name, a.addressline1,a.addressline2,a.zip from Customer a where a.customerId = :_id"); q.setInteger("_id", _id); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} - - public List getManufacturers(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("from Manufacturer m"); - resultat=q.list(); - - + resultat = q.list(); } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) { + session.close(); + } } return resultat; } - - public List getProductCodesColums(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public List getManufacturers() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select p.prodCode, p.discountCode, p.description from ProductCode p"); - resultat=q.list(); - - + + tx = session.beginTransaction(); + Query q = session.createQuery("from Manufacturer m"); + resultat = q.list(); + } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) { + session.close(); + } } return resultat; } - - public List getProductCodes(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public List getProductCodesColums() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("from ProductCode p"); - resultat=q.list(); - - + + tx = session.beginTransaction(); + Query q = session.createQuery("select p.prodCode, p.discountCode, p.description from ProductCode p"); + resultat = q.list(); + } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) { + session.close(); + } } return resultat; } - - public ProductCode getProductCode(String id){ - ProductCode resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + + public List getProductCodes() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("from ProductCode p where p.prodCode = :_id"); + + tx = session.beginTransaction(); + Query q = session.createQuery("from ProductCode p"); + resultat = q.list(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } + } + + return resultat; + } + + public ProductCode getProductCode(String id) { + ProductCode resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } + session.flush(); + + tx = session.beginTransaction(); + Query q = session.createQuery("from ProductCode p where p.prodCode = :_id"); q.setString("_id", id); - resultat=(ProductCode)q.list().iterator().next(); - - + resultat = (ProductCode) q.list().iterator().next(); + } catch (Exception e) { e.printStackTrace(); - } finally{ - if (session.isOpen())session.close(); + } finally { + if (session.isOpen()) { + session.close(); + } } return resultat; } -public List getDiscountCodesColums(){ -List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); + public List getDiscountCodesColums() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select dc.discountCode, dc.rate from DiscountCode dc"); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - - } - - return resultat; + tx = session.beginTransaction(); + Query q = session.createQuery("select dc.discountCode, dc.rate from DiscountCode dc"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } -} + } -public List getDiscountCodes(){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); + return resultat; + + } + + public List getDiscountCodes() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery(" from DiscountCode dc"); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - - } - - return resultat; + tx = session.beginTransaction(); + Query q = session.createQuery(" from DiscountCode dc"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } -} + } -public DiscountCode getDiscountCode(char c){ - DiscountCode resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); + return resultat; + + } + + public DiscountCode getDiscountCode(char c) { + DiscountCode resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery(" from DiscountCode dc where dc.discountCode = :_id"); + + tx = session.beginTransaction(); + Query q = session.createQuery(" from DiscountCode dc where dc.discountCode = :_id"); q.setCharacter("_id", c); - resultat=(DiscountCode)q.list().iterator().next(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - - } - - return resultat; + resultat = (DiscountCode) q.list().iterator().next(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } + } -} + return resultat; -public List getMicroMarket(){ -List resultat=null; - Transaction tx=null; - try{ + } + + public List getMicroMarket() { + List resultat = null; + Transaction tx = null; + try { //if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); + session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("from MicroMarket"); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - + + tx = session.beginTransaction(); + Query q = session.createQuery("from MicroMarket"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } + } return resultat; -} -public List getZipCode(){ -List resultat=null; - Transaction tx=null; - try{ + } + + public List getZipCode() { + List resultat = null; + Transaction tx = null; + try { //if(!session.isOpen()) - session=HibernateUtil.getSessionFactory().openSession(); + session = HibernateUtil.getSessionFactory().openSession(); session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select a.zipCode from MicroMarket a"); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - + + tx = session.beginTransaction(); + Query q = session.createQuery("select a.zipCode from MicroMarket a"); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } + } return resultat; -} -public void add (Object data) { - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + public void add(Object data) { + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - session.save(data); - tx.commit(); + + tx = session.beginTransaction(); + session.save(data); + tx.commit(); } catch (Exception e) { e.printStackTrace(); tx.rollback(); throw e; + } finally { + if (session.isOpen()) { + session.close(); + } } - finally{ - if (session.isOpen())session.close(); - } - -} -public void update (Object data) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + public void update(Object data) { + + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - session.update(data); - tx.commit(); - } - catch (Exception e) { + + tx = session.beginTransaction(); + session.update(data); + tx.commit(); + } catch (Exception e) { e.printStackTrace(); tx.rollback(); throw e; + } finally { + if (session.isOpen()) { + session.close(); + } } - finally{ - if (session.isOpen())session.close(); - } - -} -public Customer getClient(int id){ - - - 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 =:_id"); - q.setInteger("_id", id); - client=(Customer)q.list().iterator().next(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return client; -} + } -public void deleteCustomer (int _id) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + public Customer getClient(int id) { + + Customer client = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - 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(); + tx = session.beginTransaction(); + Query q = session.createQuery(" from Customer a where a.customerId =:_id"); + q.setInteger("_id", id); + client = (Customer) q.list().iterator().next(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } } - catch (Exception e) { + + return client; + } + + public void deleteCustomer(int _id) { + + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } + session.flush(); + + tx = session.beginTransaction(); + 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(); + } catch (Exception e) { e.printStackTrace(); tx.rollback(); throw e; + } finally { + if (session.isOpen()) { + session.close(); + } } - finally{ - if (session.isOpen())session.close(); - } - -} -public void deleteProduct (int _id) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + 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) { + + 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(); + } } - finally{ - if (session.isOpen())session.close(); - } - -} -public void deletePurchase(int _id) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + 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) { + + 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(); + } } - finally{ - if (session.isOpen())session.close(); - } - -} -public void deleteDiscountCode (char _id) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + 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) { + + 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(); + } } - finally{ - if (session.isOpen())session.close(); - } - -} -public void deleteProductCode(String _id) { - - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + } + + 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) { + + 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(); + } } - finally{ - if (session.isOpen())session.close(); - } - -} - public List getPurchaseColums(){ - 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.orderNum, 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 PurchaseOrder getPurchase(int id){ - PurchaseOrder resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + public List getPurchaseColums() { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery(" from PurchaseOrder p where p.orderNum = :_id"); - q.setInteger("_id", id); - resultat=(PurchaseOrder)q.list().iterator().next(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} - - public List getPurchases(int id){ - List resultat=null; - Transaction tx=null; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); - session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery(" from PurchaseOrder po where po.customerId = :_id"); - q.setInteger("_id", id); - resultat=q.list(); - } - catch (Exception e) { - e.printStackTrace(); - } - finally{ - if (session.isOpen())session.close(); - } - - return resultat; -} -public int getMaxId(){ - Transaction tx=null; - int resultat=-1; - try{ - if(!session.isOpen())session=HibernateUtil.getSessionFactory().openSession(); + tx = session.beginTransaction(); + Query q = session.createQuery("select po.orderNum, 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 PurchaseOrder getPurchase(int id) { + PurchaseOrder resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } session.flush(); - - tx=session.beginTransaction(); - Query q=session.createQuery("select MAX(a.customerId) from Customer a"); - - resultat=(int)q.list().iterator().next(); + + tx = session.beginTransaction(); + Query q = session.createQuery(" from PurchaseOrder p where p.orderNum = :_id"); + q.setInteger("_id", id); + resultat = (PurchaseOrder) q.list().iterator().next(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } } - catch (Exception e) { - e.printStackTrace(); + + return resultat; + } + + public List getPurchases(int id) { + List resultat = null; + Transaction tx = null; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } + session.flush(); + + tx = session.beginTransaction(); + Query q = session.createQuery(" from PurchaseOrder po where po.customerId = :_id"); + q.setInteger("_id", id); + resultat = q.list(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } } - finally{ - if (session.isOpen())session.close(); + + return resultat; + } + + public int getMaxId() { + Transaction tx = null; + int resultat = -1; + try { + if (!session.isOpen()) { + session = HibernateUtil.getSessionFactory().openSession(); + } + session.flush(); + + tx = session.beginTransaction(); + Query q = session.createQuery("select MAX(a.customerId) from Customer a"); + + resultat = (int) q.list().iterator().next(); + } catch (Exception e) { + e.printStackTrace(); + } finally { + if (session.isOpen()) { + session.close(); + } } - - return resultat; - -} + + return resultat; + + } } diff --git a/src/java/DAO/Manufacturer.java b/src/java/DAO/Manufacturer.java index c8ff5a5..82d8acb 100644 --- a/src/java/DAO/Manufacturer.java +++ b/src/java/DAO/Manufacturer.java @@ -1,128 +1,130 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - - /** * Manufacturer generated by hbm2java */ -public class Manufacturer implements java.io.Serializable { +public class Manufacturer implements java.io.Serializable { - - private int manufacturerId; - private String name; - private String addressline1; - private String addressline2; - private String city; - private String state; - private String zip; - private String phone; - private String fax; - private String email; - private String rep; + private int manufacturerId; + private String name; + private String addressline1; + private String addressline2; + private String city; + private String state; + private String zip; + private String phone; + private String fax; + private String email; + private String rep; public Manufacturer() { } - public Manufacturer(int manufacturerId) { this.manufacturerId = manufacturerId; } + public Manufacturer(int manufacturerId, String name, String addressline1, String addressline2, String city, String state, String zip, String phone, String fax, String email, String rep) { - this.manufacturerId = manufacturerId; - this.name = name; - this.addressline1 = addressline1; - this.addressline2 = addressline2; - this.city = city; - this.state = state; - this.zip = zip; - this.phone = phone; - this.fax = fax; - this.email = email; - this.rep = rep; + this.manufacturerId = manufacturerId; + this.name = name; + this.addressline1 = addressline1; + this.addressline2 = addressline2; + this.city = city; + this.state = state; + this.zip = zip; + this.phone = phone; + this.fax = fax; + this.email = email; + this.rep = rep; } - + public int getManufacturerId() { return this.manufacturerId; } - + public void setManufacturerId(int manufacturerId) { this.manufacturerId = manufacturerId; } + public String getName() { return this.name; } - + public void setName(String name) { this.name = name; } + public String getAddressline1() { return this.addressline1; } - + public void setAddressline1(String addressline1) { this.addressline1 = addressline1; } + public String getAddressline2() { return this.addressline2; } - + public void setAddressline2(String addressline2) { this.addressline2 = addressline2; } + public String getCity() { return this.city; } - + public void setCity(String city) { this.city = city; } + public String getState() { return this.state; } - + public void setState(String state) { this.state = state; } + public String getZip() { return this.zip; } - + public void setZip(String zip) { this.zip = zip; } + public String getPhone() { return this.phone; } - + public void setPhone(String phone) { this.phone = phone; } + public String getFax() { return this.fax; } - + public void setFax(String fax) { this.fax = fax; } + public String getEmail() { return this.email; } - + public void setEmail(String email) { this.email = email; } + public String getRep() { return this.rep; } - + public void setRep(String rep) { this.rep = rep; } - - - } - - diff --git a/src/java/DAO/MicroMarket.java b/src/java/DAO/MicroMarket.java index 9538bbd..7a725c4 100644 --- a/src/java/DAO/MicroMarket.java +++ b/src/java/DAO/MicroMarket.java @@ -1,65 +1,60 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - - /** * MicroMarket generated by hbm2java */ -public class MicroMarket implements java.io.Serializable { +public class MicroMarket implements java.io.Serializable { - - private String zipCode; - private Double radius; - private Double areaLength; - private Double areaWidth; + private String zipCode; + private Double radius; + private Double areaLength; + private Double areaWidth; public MicroMarket() { } - public MicroMarket(String zipCode) { this.zipCode = zipCode; } + public MicroMarket(String zipCode, Double radius, Double areaLength, Double areaWidth) { - this.zipCode = zipCode; - this.radius = radius; - this.areaLength = areaLength; - this.areaWidth = areaWidth; + this.zipCode = zipCode; + this.radius = radius; + this.areaLength = areaLength; + this.areaWidth = areaWidth; } - + public String getZipCode() { return this.zipCode; } - + public void setZipCode(String zipCode) { this.zipCode = zipCode; } + public Double getRadius() { return this.radius; } - + public void setRadius(Double radius) { this.radius = radius; } + public Double getAreaLength() { return this.areaLength; } - + public void setAreaLength(Double areaLength) { this.areaLength = areaLength; } + public Double getAreaWidth() { return this.areaWidth; } - + public void setAreaWidth(Double areaWidth) { this.areaWidth = areaWidth; } - - - } - - diff --git a/src/java/DAO/Product.java b/src/java/DAO/Product.java index 5b86a98..03c14a1 100644 --- a/src/java/DAO/Product.java +++ b/src/java/DAO/Product.java @@ -1,104 +1,104 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - import java.math.BigDecimal; /** * Product generated by hbm2java */ -public class Product implements java.io.Serializable { +public class Product implements java.io.Serializable { - - private int productId; - private int manufacturerId; - private String productCode; - private BigDecimal purchaseCost; - private Integer quantityOnHand; - private BigDecimal markup; - private String available; - private String description; + private int productId; + private int manufacturerId; + private String productCode; + private BigDecimal purchaseCost; + private Integer quantityOnHand; + private BigDecimal markup; + private String available; + private String description; public Product() { } - public Product(int productId, int manufacturerId, String productCode) { this.productId = productId; this.manufacturerId = manufacturerId; this.productCode = productCode; } + public Product(int productId, int manufacturerId, String productCode, BigDecimal purchaseCost, Integer quantityOnHand, BigDecimal markup, String available, String description) { - this.productId = productId; - this.manufacturerId = manufacturerId; - this.productCode = productCode; - this.purchaseCost = purchaseCost; - this.quantityOnHand = quantityOnHand; - this.markup = markup; - this.available = available; - this.description = description; + this.productId = productId; + this.manufacturerId = manufacturerId; + this.productCode = productCode; + this.purchaseCost = purchaseCost; + this.quantityOnHand = quantityOnHand; + this.markup = markup; + this.available = available; + this.description = description; } - + public int getProductId() { return this.productId; } - + public void setProductId(int productId) { this.productId = productId; } + public int getManufacturerId() { return this.manufacturerId; } - + public void setManufacturerId(int manufacturerId) { this.manufacturerId = manufacturerId; } + public String getProductCode() { return this.productCode; } - + public void setProductCode(String productCode) { this.productCode = productCode; } + public BigDecimal getPurchaseCost() { return this.purchaseCost; } - + public void setPurchaseCost(BigDecimal purchaseCost) { this.purchaseCost = purchaseCost; } + public Integer getQuantityOnHand() { return this.quantityOnHand; } - + public void setQuantityOnHand(Integer quantityOnHand) { this.quantityOnHand = quantityOnHand; } + public BigDecimal getMarkup() { return this.markup; } - + public void setMarkup(BigDecimal markup) { this.markup = markup; } + public String getAvailable() { return this.available; } - + public void setAvailable(String available) { this.available = available; } + public String getDescription() { return this.description; } - + public void setDescription(String description) { this.description = description; } - - - } - - diff --git a/src/java/DAO/ProductCode.java b/src/java/DAO/ProductCode.java index 905cb38..4de2f19 100644 --- a/src/java/DAO/ProductCode.java +++ b/src/java/DAO/ProductCode.java @@ -1,57 +1,51 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - - /** * ProductCode generated by hbm2java */ -public class ProductCode implements java.io.Serializable { +public class ProductCode implements java.io.Serializable { - - private String prodCode; - private char discountCode; - private String description; + private String prodCode; + private char discountCode; + private String description; public ProductCode() { } - public ProductCode(String prodCode, char discountCode) { this.prodCode = prodCode; this.discountCode = discountCode; } + public ProductCode(String prodCode, char discountCode, String description) { - this.prodCode = prodCode; - this.discountCode = discountCode; - this.description = description; + this.prodCode = prodCode; + this.discountCode = discountCode; + this.description = description; } - + public String getProdCode() { return this.prodCode; } - + public void setProdCode(String prodCode) { this.prodCode = prodCode; } + public char getDiscountCode() { return this.discountCode; } - + public void setDiscountCode(char discountCode) { this.discountCode = discountCode; } + public String getDescription() { return this.description; } - + public void setDescription(String description) { this.description = description; } - - - } - - diff --git a/src/java/DAO/PurchaseOrder.java b/src/java/DAO/PurchaseOrder.java index 849a4f3..79eb769 100644 --- a/src/java/DAO/PurchaseOrder.java +++ b/src/java/DAO/PurchaseOrder.java @@ -1,105 +1,105 @@ package DAO; // Generated 8 avr. 2022 15:30:27 by Hibernate Tools 4.3.1 - import java.math.BigDecimal; import java.util.Date; /** * PurchaseOrder generated by hbm2java */ -public class PurchaseOrder implements java.io.Serializable { +public class PurchaseOrder implements java.io.Serializable { - - private int orderNum; - private int customerId; - private int productId; - private Short quantity; - private BigDecimal shippingCost; - private Date salesDate; - private Date shippingDate; - private String freightCompany; + private int orderNum; + private int customerId; + private int productId; + private Short quantity; + private BigDecimal shippingCost; + private Date salesDate; + private Date shippingDate; + private String freightCompany; public PurchaseOrder() { } - public PurchaseOrder(int orderNum, int customerId, int productId) { this.orderNum = orderNum; this.customerId = customerId; this.productId = productId; } + public PurchaseOrder(int orderNum, int customerId, int productId, Short quantity, BigDecimal shippingCost, Date salesDate, Date shippingDate, String freightCompany) { - this.orderNum = orderNum; - this.customerId = customerId; - this.productId = productId; - this.quantity = quantity; - this.shippingCost = shippingCost; - this.salesDate = salesDate; - this.shippingDate = shippingDate; - this.freightCompany = freightCompany; + this.orderNum = orderNum; + this.customerId = customerId; + this.productId = productId; + this.quantity = quantity; + this.shippingCost = shippingCost; + this.salesDate = salesDate; + this.shippingDate = shippingDate; + this.freightCompany = freightCompany; } - + public int getOrderNum() { return this.orderNum; } - + public void setOrderNum(int orderNum) { this.orderNum = orderNum; } + public int getCustomerId() { return this.customerId; } - + public void setCustomerId(int customerId) { this.customerId = customerId; } + public int getProductId() { return this.productId; } - + public void setProductId(int productId) { this.productId = productId; } + public Short getQuantity() { return this.quantity; } - + public void setQuantity(Short quantity) { this.quantity = quantity; } + public BigDecimal getShippingCost() { return this.shippingCost; } - + public void setShippingCost(BigDecimal shippingCost) { this.shippingCost = shippingCost; } + public Date getSalesDate() { return this.salesDate; } - + public void setSalesDate(Date salesDate) { this.salesDate = salesDate; } + public Date getShippingDate() { return this.shippingDate; } - + public void setShippingDate(Date shippingDate) { this.shippingDate = shippingDate; } + public String getFreightCompany() { return this.freightCompany; } - + public void setFreightCompany(String freightCompany) { this.freightCompany = freightCompany; } - - - } - - diff --git a/src/java/Exceptions/InvalidParameter.java b/src/java/Exceptions/InvalidParameter.java index 41c0691..8b0e24e 100644 --- a/src/java/Exceptions/InvalidParameter.java +++ b/src/java/Exceptions/InvalidParameter.java @@ -10,6 +10,7 @@ package Exceptions; * @author flifloo */ public class InvalidParameter extends Exception { + public InvalidParameter(String message) { super(message); } diff --git a/src/java/controller/BddController.java b/src/java/controller/BddController.java index 6d49517..246b8df 100644 --- a/src/java/controller/BddController.java +++ b/src/java/controller/BddController.java @@ -4,6 +4,7 @@ * and open the template in the editor. */ package controller; + import DAO.*; import Exceptions.InvalidParameter; import java.math.BigDecimal; @@ -20,424 +21,439 @@ import javax.servlet.http.*; import javax.servlet.*; import org.hibernate.exception.ConstraintViolationException; - - - /** * * @author faycal */ -public class BddController extends MultiActionController { +public class BddController extends MultiActionController { + private String login; private String pwd; private User utilisateur; private HttpSession session; - public BddController() {} - + + public BddController() { + } + private void sessionInit(HttpServletRequest request) { - if (login == null) - login=request.getUserPrincipal().getName(); - if (utilisateur == null) - utilisateur =new User(login); - + if (login == null) { + login = request.getUserPrincipal().getName(); + } + if (utilisateur == null) { + utilisateur = new User(login); + } + if (session == null) { - session=request.getSession(); + session = request.getSession(); session.setAttribute("user", utilisateur); } } - - public ModelAndView menu(HttpServletRequest request, - HttpServletResponse response){ + + public ModelAndView menu(HttpServletRequest request, + HttpServletResponse response) { sessionInit(request); - System.out.println ("nbuser="+User.getCompteur()); - return new ModelAndView("menu").addObject("user",utilisateur); - + System.out.println("nbuser=" + User.getCompteur()); + return new ModelAndView("menu").addObject("user", utilisateur); + } - public ModelAndView logout(HttpServletRequest request, - HttpServletResponse response){ - sessionInit(request); + + public ModelAndView logout(HttpServletRequest request, + HttpServletResponse response) { request.getSession().invalidate(); - - - return new ModelAndView("deconnexion"); - + + return new ModelAndView("logout"); + } - - 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": + + 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().getClientsColums()); mv.addObject("colonnes", Arrays.asList("customerId", "name", "addressline1", "addressline2", "zip", "rate")); - break; - case "product": - mv.addObject("results", new MagasinHelper().getProductsColums()); - mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); - mv.addObject("relation", new HashMap() {{ - put("productCode", "prodCode"); - }}); - break; - case "purchase": + break; + case "product": + mv.addObject("results", new MagasinHelper().getProductsColums()); + mv.addObject("colonnes", Arrays.asList("productId", "manufacturerId", "productCode", "purchaseCost", "quantityOnHand", "markup", "available", "description")); + mv.addObject("relation", new HashMap() { + { + put("productCode", "prodCode"); + } + }); + break; + case "purchase": mv.addObject("results", new MagasinHelper().getPurchaseColums()); mv.addObject("colonnes", Arrays.asList("orderNum", "customerId", "productId", "quantity", "shippingCost", "salesDate", "shippingDate", "freightCompany")); - mv.addObject("relation", new HashMap() {{ - put("customerId", "customer"); - put("productId", "product"); - }}); + mv.addObject("relation", new HashMap() { + { + put("customerId", "customer"); + put("productId", "product"); + } + }); break; - case "discount": - mv.addObject("results", new MagasinHelper().getDiscountCodesColums()); - mv.addObject("colonnes", Arrays.asList("discountCode", "rate")); - break; - case "prodCode": - mv.addObject("results", new MagasinHelper().getProductCodesColums()); - mv.addObject("colonnes", Arrays.asList("prodCode", "discountCode", "description")); - mv.addObject("relation", new HashMap() {{ - put("discountCode", "discount"); - }}); - break; - default: - mv.addObject("error", "Type not found"); - } - - return mv; - } - - public ModelAndView formAdd(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("type", type); - mv.addObject("save", true); - - 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": + case "discount": + mv.addObject("results", new MagasinHelper().getDiscountCodesColums()); + mv.addObject("colonnes", Arrays.asList("discountCode", "rate")); + break; + case "prodCode": + mv.addObject("results", new MagasinHelper().getProductCodesColums()); + mv.addObject("colonnes", Arrays.asList("prodCode", "discountCode", "description")); + mv.addObject("relation", new HashMap() { + { + put("discountCode", "discount"); + } + }); + break; + default: + mv.addObject("error", "Type not found"); + } + + return mv; + } + + public ModelAndView formAdd(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("type", type); + mv.addObject("save", true); + + 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"); - } + case "discount": + break; + case "prodCode": + mv.addObject("code", new MagasinHelper().getDiscountCodes()); + break; + default: + mv.addObject("error", "Type not found"); + } - 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("type", type); - - switch (type) { - case "customer": + 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("type", type); + + switch (type) { + case "customer": mv.addObject("result", new MagasinHelper().getClient(Integer.parseInt(request.getParameter("num")))); - mv.addObject("code",new MagasinHelper().getDiscountCodes()); - mv.addObject("cpostaux",new MagasinHelper().getZipCode()); - break; - case "product": - mv.addObject("result", new MagasinHelper().getProduct(Integer.parseInt(request.getParameter("num")))); - mv.addObject("manufacturers", new MagasinHelper().getManufacturers()); - mv.addObject("productCodes", new MagasinHelper().getProductCodes()); - break; - case "purchase": + mv.addObject("code", new MagasinHelper().getDiscountCodes()); + mv.addObject("cpostaux", new MagasinHelper().getZipCode()); + break; + case "product": + mv.addObject("result", new MagasinHelper().getProduct(Integer.parseInt(request.getParameter("num")))); + mv.addObject("manufacturers", new MagasinHelper().getManufacturers()); + mv.addObject("productCodes", new MagasinHelper().getProductCodes()); + break; + case "purchase": mv.addObject("result", new MagasinHelper().getPurchase(Integer.parseInt(request.getParameter("num")))); mv.addObject("customers", new MagasinHelper().getClients()); mv.addObject("products", new MagasinHelper().getProducts()); break; - case "discount": - mv.addObject("result", new MagasinHelper().getDiscountCode(request.getParameter("num").charAt(0))); - break; - case "prodCode": - mv.addObject("result", new MagasinHelper().getProductCode(request.getParameter("num"))); - mv.addObject("code",new MagasinHelper().getDiscountCodes()); - break; - default: - mv.addObject("error", "Type not found"); - } - - return mv; - } - public ModelAndView find(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); - - String query = request.getParameter("query"); - if (query == null || query.isEmpty()) - mv.addObject("error", "No query"); - else { - List customers = new ArrayList(); - try { - customers.addAll(new MagasinHelper().getClientsColums(Integer.parseInt(query))); - } catch (NumberFormatException exception) { - - } - - query = "%".concat(query.concat("%")); - customers.addAll(new MagasinHelper().getClientsColums(query)); - - if (customers.size() == 0) - mv.addObject("error", "No user found :/"); - else - mv.addObject("results", customers); - } - MagasinHelper helper = new MagasinHelper(); - return mv; - } - - public ModelAndView achats(HttpServletRequest request, - HttpServletResponse response) throws Exception { - sessionInit(request); - ModelAndView mv = new ModelAndView("achats"); - mv.addObject("user",session.getAttribute("user")); - mv.addObject("achats",new MagasinHelper().getPurchases(Integer.parseInt(request.getParameter("customerId")))); - return mv; - } - - 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; - } - - mv.addObject("confirm","suppression effectuée"); - return mv; - - } - - private char paramChar(HttpServletRequest request, String name) throws InvalidParameter { - String param = paramNotNull(request, name); - if (param.length() > 1) - throw new InvalidParameter("Invalid ".concat(name)); - return param.charAt(0); - } - - private int parseParamInt(HttpServletRequest request, String name) throws InvalidParameter { - try { - return Integer.parseInt(request.getParameter(name)); - } catch (Exception e) { - throw new InvalidParameter("Invalid numer for ".concat(name)); - } - } - - private int parseParamInt(String param, String name) throws InvalidParameter { - try { - return Integer.parseInt(param); - } catch (Exception e) { - throw new InvalidParameter("Invalid numer for ".concat(name)); - } - } - - private BigDecimal parseParamBigDecimal(HttpServletRequest request, String name, int precision) throws InvalidParameter { - BigDecimal bc; - try { - bc = BigDecimal.valueOf(Long.parseLong(request.getParameter("rate"))); - } catch (Exception e) { - throw new InvalidParameter("Invalid big int for ".concat(name)); - } - - if (bc.precision() > precision) - throw new InvalidParameter("Precision for ".concat(name).concat(" shounld be over ".concat(String.valueOf(precision)))); - return bc; - } - - private Short parseParamShort(HttpServletRequest request, String name) throws InvalidParameter { - try { - return Short.valueOf(request.getParameter("rate")); - } catch (Exception e) { - throw new InvalidParameter("Invalid short number for ".concat(name)); - } - } - - private String paramNotNull(HttpServletRequest request, String name) throws InvalidParameter { - String param = request.getParameter(name); - if (param == null || param.isEmpty()) - throw new InvalidParameter(name.concat(" should not be empty")); - return param; - } - - private String paramLength(HttpServletRequest request, String name, int length) throws InvalidParameter { - String param = request.getParameter(name); - if (param.length() > length) - throw new InvalidParameter(name.concat(" should not be more than ".concat(String.valueOf(length)).concat(" characters"))); - return param; - } - - private String paramLength(String param, String name, int length) throws InvalidParameter { - if (param.length() > length) - throw new InvalidParameter(name.concat(" should not be more than ".concat(String.valueOf(length)).concat(" characters"))); - return param; - } - - private String paramAvailable(HttpServletRequest request, String name) throws InvalidParameter { - String param = request.getParameter(name).toUpperCase(); - if (!param.equals("TRUE") && !param.equals("FALSE")) - throw new InvalidParameter("It's true or false for ".concat(name)); - return param; - } - - private Date paramDate(HttpServletRequest request, String name) throws InvalidParameter { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); - try { - return format.parse(request.getParameter(name)); - } catch(Exception e) { - throw new InvalidParameter("Invalid date for ".concat(name)); - } - } - - private Object fetchDetailsData(HttpServletRequest request, ModelAndView mv) throws Exception { - String type = request.getParameter("type"); - Object data = null; - - try { - switch (type) { - case "customer": - int customerId = parseParamInt(request, "customerId"); - char discountCode = paramChar(request, "discountCode"); - String zip = paramLength(paramNotNull(request, "zip"), "zip", 10); - String name = paramLength(request, "name", 30); - String addressline1 = paramLength(request, "addressline1", 30); - String addressline2 = paramLength(request, "addressline2", 30); - String city = paramLength(request, "city", 25); - String state = paramLength(request, "state", 2); - String phone = paramLength(request, "phone", 12); - String fax = paramLength(request, "fax", 12); - String email = paramLength(request, "email", 40); - int creditLimit = parseParamInt(request, "creditLimit"); - data = new Customer(customerId, discountCode, zip, name, addressline1, addressline2, city, state, phone, fax, email, creditLimit); - break; - case "product": - int productId = parseParamInt(request, "productId"); - int manufacturerId = parseParamInt(paramNotNull(request, "manufacturerId"), "manufacturerId"); - String productCode = paramLength(paramNotNull(request, "productCode"), "productCode", 2); - BigDecimal purchaseCost = parseParamBigDecimal(request, "purchaseCost", 12); - int quantityOnHand = parseParamInt(request, "quantityOnHand"); - BigDecimal markup = parseParamBigDecimal(request, "markup", 12); - String available = paramAvailable(request, "available"); - String description = paramLength(request, "description", 50); - data = new Product(productId, manufacturerId, productCode, purchaseCost, quantityOnHand, markup, available, description); - break; - case "purchase": - int orderNum = parseParamInt(request, "orderNum"); - customerId = parseParamInt(paramNotNull(request, "customerId"), "customerId"); - productId = parseParamInt(paramNotNull(request, "productId"), "productId"); - Short quantity = parseParamShort(request, "quantity"); - BigDecimal shippingCost = parseParamBigDecimal(request, "shippingCost", 12); - Date salesDate = paramDate(request, "salesDate"); - Date shippingDate = paramDate(request, "shippingDate"); - String freightCompany = paramLength(request, "freightCompany", 30); - data = new PurchaseOrder(orderNum, customerId, productId, quantity, shippingCost, salesDate, shippingDate, freightCompany); - break; case "discount": - discountCode = paramChar(request, "discountCode"); - BigDecimal rate = parseParamBigDecimal(request, "rate", 4); - data = new DiscountCode(discountCode, rate); + mv.addObject("result", new MagasinHelper().getDiscountCode(request.getParameter("num").charAt(0))); break; case "prodCode": - productCode = paramLength(request, "prodCode", 2); - discountCode = paramChar(request, "discountCode"); - description = paramLength(request, "description", 10); - data = new ProductCode(productCode, discountCode, description); + mv.addObject("result", new MagasinHelper().getProductCode(request.getParameter("num"))); + mv.addObject("code", new MagasinHelper().getDiscountCodes()); + break; + default: + mv.addObject("error", "Type not found"); + } + + return mv; + } + + public ModelAndView find(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); + + String query = request.getParameter("query"); + if (query == null || query.isEmpty()) { + mv.addObject("error", "No query"); + } else { + List customers = new ArrayList(); + try { + customers.addAll(new MagasinHelper().getClientsColums(Integer.parseInt(query))); + } catch (NumberFormatException exception) { + + } + + query = "%".concat(query.concat("%")); + customers.addAll(new MagasinHelper().getClientsColums(query)); + + if (customers.size() == 0) { + mv.addObject("error", "No user found :/"); + } else { + mv.addObject("results", customers); + } + } + MagasinHelper helper = new MagasinHelper(); + return mv; + } + + public ModelAndView achats(HttpServletRequest request, + HttpServletResponse response) throws Exception { + sessionInit(request); + ModelAndView mv = new ModelAndView("achats"); + mv.addObject("user", session.getAttribute("user")); + mv.addObject("achats", new MagasinHelper().getPurchases(Integer.parseInt(request.getParameter("customerId")))); + return mv; + } + + 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; } - } catch (InvalidParameter e) { - mv.addObject("error", e.getMessage()); - } - - 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); - - if (data != null) { - try { - new MagasinHelper().add(data); - mv.addObject("confirm","Save completed"); - } catch (ConstraintViolationException e) { - mv.addObject("error", e.getSQLException().getMessage()); - } catch (Exception e) { - mv.addObject("error", e.getMessage()); + + mv.addObject("confirm", "suppression effectuée"); + return mv; + + } + + private char paramChar(HttpServletRequest request, String name) throws InvalidParameter { + String param = paramNotNull(request, name); + if (param.length() > 1) { + throw new InvalidParameter("Invalid ".concat(name)); } - } - 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); - - if (data != null) { + return param.charAt(0); + } + + private int parseParamInt(HttpServletRequest request, String name) throws InvalidParameter { try { - new MagasinHelper().update(data); - mv.addObject("confirm","Update completed"); + return Integer.parseInt(request.getParameter(name)); } catch (Exception e) { - mv.addObject("error", e.getMessage()); + throw new InvalidParameter("Invalid numer for ".concat(name)); } } - return mv; - } + + private int parseParamInt(String param, String name) throws InvalidParameter { + try { + return Integer.parseInt(param); + } catch (Exception e) { + throw new InvalidParameter("Invalid numer for ".concat(name)); + } + } + + private BigDecimal parseParamBigDecimal(HttpServletRequest request, String name, int precision) throws InvalidParameter { + BigDecimal bc; + try { + bc = BigDecimal.valueOf(Long.parseLong(request.getParameter("rate"))); + } catch (Exception e) { + throw new InvalidParameter("Invalid big int for ".concat(name)); + } + + if (bc.precision() > precision) { + throw new InvalidParameter("Precision for ".concat(name).concat(" shounld be over ".concat(String.valueOf(precision)))); + } + return bc; + } + + private Short parseParamShort(HttpServletRequest request, String name) throws InvalidParameter { + try { + return Short.valueOf(request.getParameter("rate")); + } catch (Exception e) { + throw new InvalidParameter("Invalid short number for ".concat(name)); + } + } + + private String paramNotNull(HttpServletRequest request, String name) throws InvalidParameter { + String param = request.getParameter(name); + if (param == null || param.isEmpty()) { + throw new InvalidParameter(name.concat(" should not be empty")); + } + return param; + } + + private String paramLength(HttpServletRequest request, String name, int length) throws InvalidParameter { + String param = request.getParameter(name); + if (param.length() > length) { + throw new InvalidParameter(name.concat(" should not be more than ".concat(String.valueOf(length)).concat(" characters"))); + } + return param; + } + + private String paramLength(String param, String name, int length) throws InvalidParameter { + if (param.length() > length) { + throw new InvalidParameter(name.concat(" should not be more than ".concat(String.valueOf(length)).concat(" characters"))); + } + return param; + } + + private String paramAvailable(HttpServletRequest request, String name) throws InvalidParameter { + String param = request.getParameter(name).toUpperCase(); + if (!param.equals("TRUE") && !param.equals("FALSE")) { + throw new InvalidParameter("It's true or false for ".concat(name)); + } + return param; + } + + private Date paramDate(HttpServletRequest request, String name) throws InvalidParameter { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); + try { + return format.parse(request.getParameter(name)); + } catch (Exception e) { + throw new InvalidParameter("Invalid date for ".concat(name)); + } + } + + private Object fetchDetailsData(HttpServletRequest request, ModelAndView mv) throws Exception { + String type = request.getParameter("type"); + Object data = null; + + try { + switch (type) { + case "customer": + int customerId = parseParamInt(request, "customerId"); + char discountCode = paramChar(request, "discountCode"); + String zip = paramLength(paramNotNull(request, "zip"), "zip", 10); + String name = paramLength(request, "name", 30); + String addressline1 = paramLength(request, "addressline1", 30); + String addressline2 = paramLength(request, "addressline2", 30); + String city = paramLength(request, "city", 25); + String state = paramLength(request, "state", 2); + String phone = paramLength(request, "phone", 12); + String fax = paramLength(request, "fax", 12); + String email = paramLength(request, "email", 40); + int creditLimit = parseParamInt(request, "creditLimit"); + data = new Customer(customerId, discountCode, zip, name, addressline1, addressline2, city, state, phone, fax, email, creditLimit); + break; + case "product": + int productId = parseParamInt(request, "productId"); + int manufacturerId = parseParamInt(paramNotNull(request, "manufacturerId"), "manufacturerId"); + String productCode = paramLength(paramNotNull(request, "productCode"), "productCode", 2); + BigDecimal purchaseCost = parseParamBigDecimal(request, "purchaseCost", 12); + int quantityOnHand = parseParamInt(request, "quantityOnHand"); + BigDecimal markup = parseParamBigDecimal(request, "markup", 12); + String available = paramAvailable(request, "available"); + String description = paramLength(request, "description", 50); + data = new Product(productId, manufacturerId, productCode, purchaseCost, quantityOnHand, markup, available, description); + break; + case "purchase": + int orderNum = parseParamInt(request, "orderNum"); + customerId = parseParamInt(paramNotNull(request, "customerId"), "customerId"); + productId = parseParamInt(paramNotNull(request, "productId"), "productId"); + Short quantity = parseParamShort(request, "quantity"); + BigDecimal shippingCost = parseParamBigDecimal(request, "shippingCost", 12); + Date salesDate = paramDate(request, "salesDate"); + Date shippingDate = paramDate(request, "shippingDate"); + String freightCompany = paramLength(request, "freightCompany", 30); + data = new PurchaseOrder(orderNum, customerId, productId, quantity, shippingCost, salesDate, shippingDate, freightCompany); + break; + case "discount": + discountCode = paramChar(request, "discountCode"); + BigDecimal rate = parseParamBigDecimal(request, "rate", 4); + data = new DiscountCode(discountCode, rate); + break; + case "prodCode": + productCode = paramLength(request, "prodCode", 2); + discountCode = paramChar(request, "discountCode"); + description = paramLength(request, "description", 10); + data = new ProductCode(productCode, discountCode, description); + break; + default: + mv.addObject("error", "Type not found"); + return mv; + } + } catch (InvalidParameter e) { + mv.addObject("error", e.getMessage()); + } + + 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); + + if (data != null) { + try { + new MagasinHelper().add(data); + mv.addObject("confirm", "Save completed"); + } catch (ConstraintViolationException e) { + mv.addObject("error", e.getSQLException().getMessage()); + } catch (Exception e) { + mv.addObject("error", e.getMessage()); + } + } + 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); + + if (data != null) { + try { + new MagasinHelper().update(data); + mv.addObject("confirm", "Update completed"); + } catch (Exception e) { + mv.addObject("error", e.getMessage()); + } + } + return mv; + } } diff --git a/src/java/service/User.java b/src/java/service/User.java index 55f3825..f8bd8ed 100644 --- a/src/java/service/User.java +++ b/src/java/service/User.java @@ -4,16 +4,19 @@ * and open the template in the editor. */ package service; + import java.io.Serializable; + /** * * @author faycal */ public class User implements Serializable { + private String login; private String pwd; private int userId; - static private int compteur=0; + static private int compteur = 0; public static int getCompteur() { return compteur; @@ -21,22 +24,24 @@ public class User implements Serializable { public User() { super(); - userId=compteur++; + userId = compteur++; } - public void finalize(){ - + + public void finalize() { + compteur--; } - public User(String login) { + + public User(String login) { this.login = login; - userId=compteur++; - + userId = compteur++; + } public User(String login, String pwd) { this.login = login; this.pwd = pwd; - userId=compteur++; + userId = compteur++; } public String getLogin() { @@ -54,5 +59,5 @@ public class User implements Serializable { public void setPwd(String pwd) { this.pwd = pwd; } - + } diff --git a/web/WEB-INF/jsp/achats.jsp b/web/WEB-INF/jsp/achats.jsp index f285c3c..c71013a 100644 --- a/web/WEB-INF/jsp/achats.jsp +++ b/web/WEB-INF/jsp/achats.jsp @@ -8,27 +8,27 @@ <%@include file="header.jsp" %> - - + +

Achats du client n°<%=request.getParameter("customerId")%>

- - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
${cli.orderNum}${cli.customerId}${cli.productId}${cli.quantity}${cli.shippingCost}${cli.salesDate}${cli.shippingDate}${cli.freightCompany}
${cli.orderNum}${cli.customerId}${cli.productId}${cli.quantity}${cli.shippingCost}${cli.salesDate}${cli.shippingDate}${cli.freightCompany}
- - + + diff --git a/web/WEB-INF/jsp/confirm.jsp b/web/WEB-INF/jsp/confirm.jsp index 5233c5f..7440c6f 100644 --- a/web/WEB-INF/jsp/confirm.jsp +++ b/web/WEB-INF/jsp/confirm.jsp @@ -13,7 +13,7 @@ <%@include file="header.jsp" %> - +

${error != null ? error : confirm}

diff --git a/web/WEB-INF/jsp/deconnexion.jsp b/web/WEB-INF/jsp/deconnexion.jsp deleted file mode 100644 index 582931e..0000000 --- a/web/WEB-INF/jsp/deconnexion.jsp +++ /dev/null @@ -1,18 +0,0 @@ -<%-- - Document : deconnexion - Created on : 1 juin 2020, 17:09:38 - Author : faycal ---%> - -<%@page contentType="text/html" pageEncoding="UTF-8"%> - - - - - Deconnexion - - -

Vous etes deconnecte

- <%response.sendRedirect("/Bdd_Spring_HI/");%> - - diff --git a/web/WEB-INF/jsp/detail.jsp b/web/WEB-INF/jsp/detail.jsp index 73ea3a9..ded1bf0 100644 --- a/web/WEB-INF/jsp/detail.jsp +++ b/web/WEB-INF/jsp/detail.jsp @@ -8,7 +8,7 @@ <%@include file="header.jsp" %> - + @@ -106,12 +106,12 @@ checked id="isavailable" /> - - checked id="notavailable" /> -

-

- - + + checked id="notavailable" /> +

+

+ +

@@ -185,7 +185,7 @@

- + diff --git a/web/WEB-INF/jsp/error.jsp b/web/WEB-INF/jsp/error.jsp deleted file mode 100644 index 14af0fd..0000000 --- a/web/WEB-INF/jsp/error.jsp +++ /dev/null @@ -1,18 +0,0 @@ -<%-- - Document : error - Created on : 4 mars 2018, 20:54:56 - Author : faycal ---%> - -<%@page contentType="text/html" pageEncoding="UTF-8"%> - - - - - Erreur - - - <%@include file="header.jsp" %> -

${erreur}

- - diff --git a/web/WEB-INF/jsp/form_inscription.jsp b/web/WEB-INF/jsp/form_inscription.jsp index 4dbc842..3f86767 100644 --- a/web/WEB-INF/jsp/form_inscription.jsp +++ b/web/WEB-INF/jsp/form_inscription.jsp @@ -14,40 +14,40 @@ Bienvenue ${user.login} - +

- - + +

- - + +

- - + +

- +

- - - + + +

diff --git a/web/WEB-INF/jsp/header.jsp b/web/WEB-INF/jsp/header.jsp index 8b7579e..b8ff3d7 100644 --- a/web/WEB-INF/jsp/header.jsp +++ b/web/WEB-INF/jsp/header.jsp @@ -15,7 +15,7 @@
- + diff --git a/web/WEB-INF/jsp/index.jsp b/web/WEB-INF/jsp/index.jsp index 5ebe295..d74394b 100644 --- a/web/WEB-INF/jsp/index.jsp +++ b/web/WEB-INF/jsp/index.jsp @@ -2,5 +2,5 @@ -<% response.sendRedirect("menu.htm"); %> - +<% response.sendRedirect("menu.htm");%> + diff --git a/web/WEB-INF/jsp/login.jsp b/web/WEB-INF/jsp/login.jsp index bc11518..db636fd 100644 --- a/web/WEB-INF/jsp/login.jsp +++ b/web/WEB-INF/jsp/login.jsp @@ -13,20 +13,20 @@ - - - - - - - - - - - - - -
Utilisateur :
Mot de passe :
-
+ + + + + + + + + + + + + +
Utilisateur :
Mot de passe :
+ diff --git a/build/web/WEB-INF/jsp/deconnexion.jsp b/web/WEB-INF/jsp/logout.jsp similarity index 79% rename from build/web/WEB-INF/jsp/deconnexion.jsp rename to web/WEB-INF/jsp/logout.jsp index 582931e..369d703 100644 --- a/build/web/WEB-INF/jsp/deconnexion.jsp +++ b/web/WEB-INF/jsp/logout.jsp @@ -12,7 +12,7 @@ Deconnexion -

Vous etes deconnecte

- <%response.sendRedirect("/Bdd_Spring_HI/");%> +

You are logout

+ <%response.sendRedirect("");%> diff --git a/web/WEB-INF/jsp/menu.jsp b/web/WEB-INF/jsp/menu.jsp index ed702d7..855bcfe 100644 --- a/web/WEB-INF/jsp/menu.jsp +++ b/web/WEB-INF/jsp/menu.jsp @@ -14,7 +14,7 @@ <%@include file="header.jsp" %>

choisissez une opération dans la liste suivante

- +

diff --git a/web/WEB-INF/jsp/recherche.jsp b/web/WEB-INF/jsp/recherche.jsp index bc110dd..90e4c66 100644 --- a/web/WEB-INF/jsp/recherche.jsp +++ b/web/WEB-INF/jsp/recherche.jsp @@ -13,14 +13,14 @@ <%@include file="header.jsp" %> - + -

+

- + diff --git a/web/WEB-INF/jsp/resultat.jsp b/web/WEB-INF/jsp/resultat.jsp index bb96101..b76af35 100644 --- a/web/WEB-INF/jsp/resultat.jsp +++ b/web/WEB-INF/jsp/resultat.jsp @@ -14,7 +14,7 @@ <%@include file="header.jsp" %> - +

${error}

@@ -27,37 +27,37 @@ - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + +
${col}${col}
-
- - - -
-
${v} -
- - - -
-
+
+ + + +
+
${v} +
+ + + +
+