/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package action;
import dao.ProbaDao;
import daoI.IProbaDao;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;
public class WActionBean extends BaseActionBean {
private String amplasament;
private String foraj;
private String masaTara;
private String masaTaraProbaUmeda;
private String masaTaraProbaUscata;
private String amplasamentCurent;
private String forajCurent;
private int idAmplasamentCurent;
private int idForajCurent;
private int idProbaCurenta;
private List rezultatePartiale;
private String rezultatePartialeR;
private String umiditate;
@DefaultHandler
public Resolution view() {
/* idAmplasamentCurent = Integer.parseInt(getContext().getRequest().getSession(true).getAttribute("idAmplasamentCurent").toString());
idForajCurent = Integer.parseInt(getContext().getRequest().getSession(true).getAttribute("idForajCurent").toString());
IAmplasamentDao amplasamentDao= new AmplasamentDao();
amplasamentCurent = amplasamentDao.getAmplasamentByID(idAmplasamentCurent).toString();
IForajDao forajDao= new ForajDao();
forajCurent = forajDao.getForajByID(idForajCurent).toString();*/
idProbaCurenta = Integer.parseInt(getContext().getRequest().getSession(true).getAttribute("idProbaCurenta").toString());
return new ForwardResolution("/WEB-INF/jsp/w.jsp");
}
public Resolution adauga() {
float mc = Float.valueOf(masaTara.trim()).floatValue();
float mu = Float.valueOf(masaTaraProbaUmeda.trim()).floatValue();
float md = Float.valueOf(masaTaraProbaUscata.trim()).floatValue();
float rez = (mu - md) / (md - mc) * 100;
String r = Float.toString(rez);
int p = r.indexOf('.');
if (p >= 1) {
r = r.substring(0, p + 3);
}
if (getContext().getRequest().getSession(true).getAttribute("WrezultatePartiale") != null) {
rezultatePartiale = (List) getContext().getRequest().getSession(true).getAttribute("WrezultatePartiale");
} else {
rezultatePartiale = new ArrayList();
}
rezultatePartiale.add(r);
getContext().getRequest().getSession(true).setAttribute("WrezultatePartiale", rezultatePartiale);
return new ForwardResolution("/WEB-INF/jsp/w.jsp");
}
public Resolution sterge() {
rezultatePartiale = (List) getContext().getRequest().getSession(true).getAttribute("WrezultatePartiale");
if (rezultatePartiale != null && rezultatePartiale.size() > 0) {
rezultatePartiale.remove(getRezultatePartialeR());
getContext().getRequest().getSession(true).setAttribute("WrezultatePartiale", rezultatePartiale);
}
return new ForwardResolution("/WEB-INF/jsp/w.jsp");
}
public Resolution calculeaza() {
rezultatePartiale = (List) getContext().getRequest().getSession(true).getAttribute("WrezultatePartiale");
int nr = rezultatePartiale.size();
float suma = 0;
for (int i = 0; i < nr; i++) {
suma += Float.valueOf(rezultatePartiale.get(i).toString().trim()).floatValue();
}
float media = suma / nr;
IProbaDao probaDao = new ProbaDao();
idProbaCurenta = Integer.parseInt(getContext().getRequest().getSession(true).getAttribute("idProbaCurenta").toString());
probaDao.addW(idProbaCurenta, media);
String mediaS = Float.toString(media);
int p = mediaS.indexOf('.');
if (p > 1) {
mediaS = mediaS.substring(0, p + 2);
}
setUmiditate(mediaS);
getContext().getRequest().getSession(true).setAttribute("WrezultatePartiale", null);
return new ForwardResolution("/WEB-INF/jsp/w.jsp");
}
/**
* @return the amplasament
*/
public String getAmplasament() {
return amplasament;
}
/**
* @param amplasament the amplasament to set
*/
public void setAmplasament(String amplasament) {
this.amplasament = amplasament;
}
/**
* @return the foraj
*/
public String getForaj() {
return foraj;
}
/**
* @param foraj the foraj to set
*/
public void setForaj(String foraj) {
this.foraj = foraj;
}
/**
* @return the masaTara
*/
public String getMasaTara() {
return masaTara;
}
/**
* @param masaTara the masaTara to set
*/
public void setMasaTara(String masaTara) {
this.masaTara = masaTara;
}
/**
* @return the masaTaraProbaUmeda
*/
public String getMasaTaraProbaUmeda() {
return masaTaraProbaUmeda;
}
/**
* @param masaTaraProbaUmeda the masaTaraProbaUmeda to set
*/
public void setMasaTaraProbaUmeda(String masaTaraProbaUmeda) {
this.masaTaraProbaUmeda = masaTaraProbaUmeda;
}
/**
* @return the masaTaraProbaUscata
*/
public String getMasaTaraProbaUscata() {
return masaTaraProbaUscata;
}
/**
* @param masaTaraProbaUscata the masaTaraProbaUscata to set
*/
public void setMasaTaraProbaUscata(String masaTaraProbaUscata) {
this.masaTaraProbaUscata = masaTaraProbaUscata;
}
/**
* @return the amplasamentCurent
*/
public String getAmplasamentCurent() {
return amplasamentCurent;
}
/**
* @param amplasamentCurent the amplasamentCurent to set
*/
public void setAmplasamentCurent(String amplasamentCurent) {
this.amplasamentCurent = amplasamentCurent;
}
/**
* @return the forajCurent
*/
public String getForajCurent() {
return forajCurent;
}
/**
* @param forajCurent the forajCurent to set
*/
public void setForajCurent(String forajCurent) {
this.forajCurent = forajCurent;
}
/**
* @return the rezultatePartiale
*/
public List getRezultatePartiale() {
return rezultatePartiale;
}
/**
* @param rezultatePartiale the rezultatePartiale to set
*/
public void setRezultatePartiale(List rezultatePartiale) {
this.rezultatePartiale = rezultatePartiale;
}
/**
* @return the masuratoriR
*/
public String getMasuratoriR() {
return getRezultatePartialeR();
}
/**
* @param masuratoriR the masuratoriR to set
*/
public void setMasuratoriR(String masuratoriR) {
this.setRezultatePartialeR(masuratoriR);
}
/**
* @return the rezultatePartialeR
*/
public String getRezultatePartialeR() {
return rezultatePartialeR;
}
/**
* @param rezultatePartialeR the rezultatePartialeR to set
*/
public void setRezultatePartialeR(String rezultatePartialeR) {
this.rezultatePartialeR = rezultatePartialeR;
}
/**
* @return the umiditate
*/
public String getUmiditate() {
if (umiditate == null) {
umiditate = "0";
}
return umiditate;
}
/**
* @param umiditate the umiditate to set
*/
public void setUmiditate(String umiditate) {
this.umiditate = umiditate;
}
}