@@ -83,8 +103,11 @@
-
- checked id="available" />
+
+
+ checked id="isavailable" />
+
+ checked id="notavailable" />
diff --git a/src/java/DAO/MagasinHelper.java b/src/java/DAO/MagasinHelper.java
index 0c53b72..4518d86 100644
--- a/src/java/DAO/MagasinHelper.java
+++ b/src/java/DAO/MagasinHelper.java
@@ -407,6 +407,28 @@ public void insertCustomer (int _customerId, char _discountCode, String _zip) {
}
+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) {
+ e.printStackTrace();
+ tx.rollback();
+ throw e;
+ }
+ finally{
+ if (session.isOpen())session.close();
+ }
+
+}
+
public void updateCustomer (int _customerId,char _discountCode, String _name, String _adress, String _phone,String _email, String _zip){
Transaction tx=null;
diff --git a/src/java/controller/BddController.java b/src/java/controller/BddController.java
index 1da7ab9..b07c4b6 100644
--- a/src/java/controller/BddController.java
+++ b/src/java/controller/BddController.java
@@ -5,6 +5,8 @@
*/
package controller;
import DAO.*;
+import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
import service.User;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
@@ -203,8 +205,8 @@ public class BddController extends MultiActionController {
String param6 = request.getParameter("CP");
new MagasinHelper().insertCustomer(new MagasinHelper().getMaxId()+1, param5.charAt(0), param6);
return new ModelAndView("confirm").addObject("confirm","enregistrement effectué");
-
- }
+
+ }
public ModelAndView delete(HttpServletRequest request,
HttpServletResponse response) throws Exception {
sessionInit(request);
@@ -241,17 +243,71 @@ 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");
- String param4 = request.getParameter("adresse");
- String param5 = request.getParameter("telephone");
- String param6 = request.getParameter("email");
- String param7 = request.getParameter("CP");
- System.out.println(request.getParameter("CP"));
-
- new MagasinHelper().updateCustomer(Integer.valueOf(param1),param2.charAt(0),param3,param4,param5,param6,param7);
- return new ModelAndView("confirm").addObject("confirm","mise à jour effectuée");
+ String type = request.getParameter("type");
+ ModelAndView mv = new ModelAndView("confirm");
+ mv.addObject("user",session.getAttribute("user"));
+ mv.addObject("type", type);
+ Object data = null;
+
+ switch (type) {
+ case "customer":
+ int customerId = Integer.parseInt(request.getParameter("customerId"));
+ char discountCode = request.getParameter("discountCode").charAt(0);
+ String zip = request.getParameter("zip");
+ String name = request.getParameter("name");
+ String addressline1 = request.getParameter("addressline1");
+ String addressline2 = request.getParameter("addressline2");
+ String city = request.getParameter("city");
+ String state = request.getParameter("state");
+ String phone = request.getParameter("phone");
+ String fax = request.getParameter("fax");
+ String email = request.getParameter("email");
+ int creditLimit = Integer.parseInt(request.getParameter("creditLimit"));
+ data = new Customer(customerId, discountCode, zip, name, addressline1, addressline2, city, state, phone, fax, email, creditLimit);
+ break;
+ case "product":
+ int productId = Integer.parseInt(request.getParameter("productId"));
+ int manufacturerId = Integer.parseInt(request.getParameter("manufacturerId"));
+ String productCode = request.getParameter("productCode");
+ BigDecimal purchaseCost = BigDecimal.valueOf(Double.parseDouble(request.getParameter("purchaseCost")));
+ int quantityOnHand = Integer.parseInt(request.getParameter("quantityOnHand"));
+ BigDecimal markup = BigDecimal.valueOf(Double.parseDouble(request.getParameter("markup")));
+ String available = request.getParameter("available");
+ String description = request.getParameter("description");
+ data = new Product(productId, manufacturerId, productCode, purchaseCost, quantityOnHand, markup, available, description);
+ break;
+ case "purchase":
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+
+ int orderNum = Integer.parseInt(request.getParameter("orderNum"));
+ customerId = Integer.parseInt(request.getParameter("customerId"));
+ productId = Integer.parseInt(request.getParameter("productId"));
+ Short quantity = Short.parseShort(request.getParameter("quantity"));
+ BigDecimal shippingCost = BigDecimal.valueOf(Double.parseDouble(request.getParameter("shippingCost")));
+ Date salesDate = format.parse(request.getParameter("salesDate"));
+ Date shippingDate = format.parse(request.getParameter("shippingDate"));
+ String freightCompany = request.getParameter("freightCompany");
+ data = new PurchaseOrder(orderNum, customerId, productId, quantity, shippingCost, salesDate, shippingDate, freightCompany);
+ break;
+ case "discount":
+ discountCode = request.getParameter("discountCode").charAt(0);
+ BigDecimal rate = BigDecimal.valueOf(Double.parseDouble(request.getParameter("rate")));
+ data = new DiscountCode(discountCode, rate);
+ break;
+ case "prodCode":
+ productCode = request.getParameter("prodCode");
+ discountCode = request.getParameter("discountCode").charAt(0);
+ description = request.getParameter("description");
+ data = new ProductCode(productCode, discountCode, description);
+ break;
+ default:
+ mv.addObject("error", "Type not found");
+ return mv;
+ }
+
+ new MagasinHelper().update(data);
+ mv.addObject("confirm","Update completed");
+ return mv;
}
}
diff --git a/web/WEB-INF/jsp/detail.jsp b/web/WEB-INF/jsp/detail.jsp
index eb6d795..d5734c5 100644
--- a/web/WEB-INF/jsp/detail.jsp
+++ b/web/WEB-INF/jsp/detail.jsp
@@ -13,24 +13,48 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -41,12 +65,8 @@
-
-
+
+
@@ -83,8 +103,11 @@
-
- checked id="available" />
+
+
+ checked id="isavailable" />
+
+ checked id="notavailable" />