sdisM2/src/java/form/VentilForm.java
thomas.millot eae43733b0 Merge origin/master
Conflicts:
	src/java/bdd/PompierMysql.java
	web/WEB-INF/ProfilJSP.jsp
2021-12-14 08:44:24 +01:00

59 lines
1.7 KiB
Java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package form;
import bdd.VentilMysql;
import bean.Ventil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Map;
/**
*
* @author thomas.millot
*/
public class VentilForm {
public void verifVentil(HttpServletRequest request) {
//a.récupération de la collection des ventilation
HttpSession maSession = request.getSession();
ArrayList<Ventil> lesVentil
= (ArrayList<Ventil>) maSession.getAttribute("lesVentilInit");
//b.Créer un objet de type VentilMysql
VentilMysql vm = new VentilMysql();
//c.Récupérer les données du formulaire
Map<String, String[]> map = request.getParameterMap();
String[] lesNvVentil = map.get("lesActivites");
//d. Initialiser du compteur de boucle
int i = 0;
//e.Mise a jour des activité des salariés
for (Ventil uneVentil : lesVentil) {
int oldAct = uneVentil.getActivite();
int newAct = Integer.parseInt(lesNvVentil[i]);
if (oldAct != newAct) {
if (uneVentil.isIsInBD()) {
if(newAct == 0){
vm.delete(uneVentil);
} else {
uneVentil.setActivite(newAct);
vm.update(uneVentil);
}
} else {
uneVentil.setActivite(newAct);
vm.create(uneVentil);
}
}
i++;
}
}
}