package action;
import bo.Proba;
import dao.ProbaDao;
import daoI.IProbaDao;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.stripes.action.ActionBean;
import net.sourceforge.stripes.action.ActionBeanContext;
public class BaseActionBean implements ActionBean {
private ActionBeanContext context;
private String selectedSubmenu;
public ActionBeanContext getContext() {
return context;
}
public void setContext(ActionBeanContext context) {
this.context = context;
}
public String getSelectedSubmenu() {
return selectedSubmenu;
}
public void setSelectedSubmenu(String selectedSubmenu) {
this.selectedSubmenu = selectedSubmenu;
}
public Integer getIdGeologLogat() {
if (getContext().getRequest().getSession().getAttribute("user") == null) {
return 0;
} else {
return Integer.parseInt(getContext().getRequest().getSession().getAttribute("user").toString());
}
}
public Integer getIdAdminLogat() {
if (getContext().getRequest().getSession().getAttribute("admin") == null) {
return 0;
} else {
return Integer.parseInt(getContext().getRequest().getSession().getAttribute("admin").toString());
}
}
public Integer getIdUserLogat() {
int id = 0;
int idGeolog = getIdGeologLogat();
int idAdmin = getIdAdminLogat();
if ((idGeolog> 0) || (idAdmin> 0)) {
id = 2;
}
else if (idAdmin==0) id=idGeolog;
else id=idAdmin;
return id;
}
//returneaza md pt proba curenta
public String getMd() {
IProbaDao probaDao = new ProbaDao();
Proba proba = new Proba();
proba = probaDao.geProbaByID(Integer.parseInt(getContext().getRequest().getSession().getAttribute("idProba").toString()));
if (proba.getMd() == null) {
return "0.0";
}
return proba.getMd().toString();
}
public String getRs() {
IProbaDao probaDao = new ProbaDao();
Proba proba = new Proba();
proba = probaDao.geProbaByID(Integer.parseInt(getContext().getRequest().getSession().getAttribute("idProba").toString()));
if (proba.getRs() == null) {
return "0.0";
}
return proba.getRs().toString();
}
public String getA() {
IProbaDao probaDao = new ProbaDao();
Proba proba = new Proba();
proba = probaDao.geProbaByID(Integer.parseInt(getContext().getRequest().getSession().getAttribute("idProba").toString()));
if (proba.getA() == null) {
return "0.0";
}
return proba.getA().toString();
}
public String getB() {
IProbaDao probaDao = new ProbaDao();
Proba proba = new Proba();
proba = probaDao.geProbaByID(Integer.parseInt(getContext().getRequest().getSession().getAttribute("idProba").toString()));
if (proba.getB() == null) {
return "0.0";
}
return proba.getB().toString();
}
public static Object zecimale(Object dataIn, int nrZecimale) {
Object dataOut = null;
Float dataF = (float) 0.0;
if (dataIn.toString().equals("")) {
dataF = (float) 0;
} else {
dataF = Float.valueOf((dataIn.toString()));
}
dataOut = (float) (Math.round(dataF * Math.pow(10, nrZecimale)) / Math.pow(10, nrZecimale));
return dataOut;
}
//verifica ca un string sa fie numar
public boolean isNumeric(String number) {
boolean isValid = false;
String expression = "[0-9]*";
CharSequence inputStr = number;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}
}