59 lines
1.7 KiB
Java
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++;
|
|
}
|
|
}
|
|
}
|