1
0
Fork 0

Add/fix update of datas

This commit is contained in:
Ethanell 2022-06-30 00:30:44 +02:00
parent c5fcc072cc
commit 1b2d645bf2
9 changed files with 204 additions and 60 deletions

View file

@ -10,7 +10,7 @@
<%@include file="header.jsp" %>
<H1>Achats du client n°<%=request.getParameter("numero")%></H1>
<H1>Achats du client n°<%=request.getParameter("customerId")%></H1>
<table border="1" cellpadding="10">

View file

@ -13,24 +13,48 @@
<c:choose>
<c:when test="${type == 'customer'}">
<p>
<label for="customerId">Numero</label>
<label for="customerId">ID</label>
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
</p>
<p>
<label for="nom">Nom</label>
<input type="text" name="nom" value="${result.name}" size="30" id="nom" />
<label for="name">Nom</label>
<input type="text" name="name" value="${result.name}" size="30" id="name" />
</p>
<p>
<label for="adresse">Adresse</label>
<input type="text" name="adresse" value="${result.addressline1}" size="30" id="adresse" />
<label for="addressline1">Adresse</label>
<input type="text" name="addressline1" value="${result.addressline1}" size="30" id="addressline1" />
</p>
<p>
<label for="telephone">Téléphone</label>
<input type="text" name="telephone" value="${result.phone}" size="30" id="tel" />
<label for="addressline2">Adresse 2</label>
<input type="text" name="addressline2" value="${result.addressline2}" size="30" id="addressline2" />
</p>
<p>
<label for="city">City</label>
<input type="text" name="city" value="${result.city}" size="25" id="city" />
</p>
<p>
<label for="zip">Code Postal</label>
<select name="zip" id="zip">
<c:forEach items="${cpostaux}" var="cp">
<option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
</c:forEach>
</select>
</p>
<p>
<label for="state">State</label>
<input type="text" name="state" value="${result.state}" size="2" id="state" />
</p>
<p>
<label for="phone">Phone</label>
<input type="text" name="phone" value="${result.phone}" size="12" id="phone" />
</p>
<p>
<label for="fax">Fax</label>
<input type="text" name="fax" value="${result.fax}" size="12" id="fax" />
</p>
<p>
<label for="email">E-mail</label>
<input type="text" name="email" value="${result.email}" size="30" id="email"/>
<input type="text" name="email" value="${result.email}" size="40" id="email"/>
</p>
<p>
<label for="discountCode">Remise</label>
@ -41,12 +65,8 @@
</select>
</p>
<p>
<label for="cp">Code Postal</label>
<select name="CP" id="cp">
<c:forEach items="${cpostaux}" var="cp">
<option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
</c:forEach>
</select>
<label for="creditLimit">Credit limit</label>
<input type="number" name="creditLimit" value="${result.creditLimit}" id="creditLimit"/>
</p>
</c:when>
<c:when test="${type == 'product'}">

View file

@ -13,24 +13,48 @@
<c:choose>
<c:when test="${type == 'customer'}">
<p>
<label for="customerId">Numero</label>
<label for="customerId">ID</label>
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
</p>
<p>
<label for="nom">Nom</label>
<input type="text" name="nom" value="${result.name}" size="30" id="nom" />
<label for="name">Nom</label>
<input type="text" name="name" value="${result.name}" size="30" id="name" />
</p>
<p>
<label for="adresse">Adresse</label>
<input type="text" name="adresse" value="${result.addressline1}" size="30" id="adresse" />
<label for="addressline1">Adresse</label>
<input type="text" name="addressline1" value="${result.addressline1}" size="30" id="addressline1" />
</p>
<p>
<label for="telephone">Téléphone</label>
<input type="text" name="telephone" value="${result.phone}" size="30" id="tel" />
<label for="addressline2">Adresse 2</label>
<input type="text" name="addressline2" value="${result.addressline2}" size="30" id="addressline2" />
</p>
<p>
<label for="city">City</label>
<input type="text" name="city" value="${result.city}" size="25" id="city" />
</p>
<p>
<label for="zip">Code Postal</label>
<select name="zip" id="zip">
<c:forEach items="${cpostaux}" var="cp">
<option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
</c:forEach>
</select>
</p>
<p>
<label for="state">State</label>
<input type="text" name="state" value="${result.state}" size="2" id="state" />
</p>
<p>
<label for="phone">Phone</label>
<input type="text" name="phone" value="${result.phone}" size="12" id="phone" />
</p>
<p>
<label for="fax">Fax</label>
<input type="text" name="fax" value="${result.fax}" size="12" id="fax" />
</p>
<p>
<label for="email">E-mail</label>
<input type="text" name="email" value="${result.email}" size="30" id="email"/>
<input type="text" name="email" value="${result.email}" size="40" id="email"/>
</p>
<p>
<label for="discountCode">Remise</label>
@ -41,12 +65,8 @@
</select>
</p>
<p>
<label for="cp">Code Postal</label>
<select name="CP" id="cp">
<c:forEach items="${cpostaux}" var="cp">
<option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
</c:forEach>
</select>
<label for="creditLimit">Credit limit</label>
<input type="number" name="creditLimit" value="${result.creditLimit}" id="creditLimit"/>
</p>
</c:when>
<c:when test="${type == 'product'}">
@ -83,8 +103,11 @@
<input type="number" step="0.0001" name="markup" value="${result.markup}" id="markup" />
</p>
<p>
<label for="markup">Available</label>
<input type="checkbox" name="available" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="available" />
<label for="available">Available</label>
<label for="isavailable">TRUE:</label>
<input type="radio" name="available" value="TRUE" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="isavailable" />
<label for="notavailable">FALSE:</label>
<input type="radio" name="available" value="FALSE" <c:if test="${result.available == 'FALSE'}">checked</c:if> id="notavailable" />
</p>
<p>
<label for="description">Description</label>

View file

@ -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;

View file

@ -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;
@ -204,7 +206,7 @@ public class BddController extends MultiActionController {
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"));
String type = request.getParameter("type");
ModelAndView mv = new ModelAndView("confirm");
mv.addObject("user",session.getAttribute("user"));
mv.addObject("type", type);
Object data = null;
new MagasinHelper().updateCustomer(Integer.valueOf(param1),param2.charAt(0),param3,param4,param5,param6,param7);
return new ModelAndView("confirm").addObject("confirm","mise à jour effectuée");
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;
}
}

View file

@ -13,24 +13,48 @@
<c:choose>
<c:when test="${type == 'customer'}">
<p>
<label for="customerId">Numero</label>
<label for="customerId">ID</label>
<input type="text" name="customerId" value="${result.customerId}" size="30" id="customerId" />
</p>
<p>
<label for="nom">Nom</label>
<input type="text" name="nom" value="${result.name}" size="30" id="nom" />
<label for="name">Nom</label>
<input type="text" name="name" value="${result.name}" size="30" id="name" />
</p>
<p>
<label for="adresse">Adresse</label>
<input type="text" name="adresse" value="${result.addressline1}" size="30" id="adresse" />
<label for="addressline1">Adresse</label>
<input type="text" name="addressline1" value="${result.addressline1}" size="30" id="addressline1" />
</p>
<p>
<label for="telephone">Téléphone</label>
<input type="text" name="telephone" value="${result.phone}" size="30" id="tel" />
<label for="addressline2">Adresse 2</label>
<input type="text" name="addressline2" value="${result.addressline2}" size="30" id="addressline2" />
</p>
<p>
<label for="city">City</label>
<input type="text" name="city" value="${result.city}" size="25" id="city" />
</p>
<p>
<label for="zip">Code Postal</label>
<select name="zip" id="zip">
<c:forEach items="${cpostaux}" var="cp">
<option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
</c:forEach>
</select>
</p>
<p>
<label for="state">State</label>
<input type="text" name="state" value="${result.state}" size="2" id="state" />
</p>
<p>
<label for="phone">Phone</label>
<input type="text" name="phone" value="${result.phone}" size="12" id="phone" />
</p>
<p>
<label for="fax">Fax</label>
<input type="text" name="fax" value="${result.fax}" size="12" id="fax" />
</p>
<p>
<label for="email">E-mail</label>
<input type="text" name="email" value="${result.email}" size="30" id="email"/>
<input type="text" name="email" value="${result.email}" size="40" id="email"/>
</p>
<p>
<label for="discountCode">Remise</label>
@ -41,12 +65,8 @@
</select>
</p>
<p>
<label for="cp">Code Postal</label>
<select name="CP" id="cp">
<c:forEach items="${cpostaux}" var="cp">
<option <c:if test="${cp==result.zip}"> selected </c:if>>${cp}</option>
</c:forEach>
</select>
<label for="creditLimit">Credit limit</label>
<input type="number" name="creditLimit" value="${result.creditLimit}" id="creditLimit"/>
</p>
</c:when>
<c:when test="${type == 'product'}">
@ -83,8 +103,11 @@
<input type="number" step="0.0001" name="markup" value="${result.markup}" id="markup" />
</p>
<p>
<label for="markup">Available</label>
<input type="checkbox" name="available" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="available" />
<label for="available">Available</label>
<label for="isavailable">TRUE:</label>
<input type="radio" name="available" value="TRUE" <c:if test="${result.available == 'TRUE'}">checked</c:if> id="isavailable" />
<label for="notavailable">FALSE:</label>
<input type="radio" name="available" value="FALSE" <c:if test="${result.available == 'FALSE'}">checked</c:if> id="notavailable" />
</p>
<p>
<label for="description">Description</label>