Package action

Source Code of action.ForajActionBean

package action;

import bo.Amplasament;
import bo.Beneficiar;
import bo.Foraj;
import bo.Proba;
import bo.Strat;
import dao.AmplasamentDao;
import dao.BeneficiarDao;
import dao.ForajDao;
import dao.GeologBeneficiarDao;
import dao.ProbaDao;
import dao.StratDao;
import daoI.IAmplasamentDao;
import daoI.IBeneficiarDao;
import daoI.IForajDao;
import daoI.IGeologBeneficiarDao;
import daoI.IProbaDao;
import daoI.IStratDao;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

public class ForajActionBean extends BaseActionBean {

    private String beneficiarFilter;
    private String amplasamentFilter;
    private String forajFilter;
    private String nume;
    private String cota;
    private int idBeneficiarCurent;
    private int idAmplasamentCurent;
    private int idForajCurent;
    private String probaR;
    private String stratR;
    private String tipDeterminareR;
    private int selectedCombo;

    @DefaultHandler
    public Resolution view() {
        if (getSelectedCombo() == 1) {
            int beneficiarID = Integer.parseInt(getBeneficiarFilter());
            getContext().getRequest().getSession(true).setAttribute("idBeneficiarCurent", beneficiarID);
            getContext().getRequest().getSession(true).setAttribute("idAmplasamentCurent", 0);
            getContext().getRequest().getSession(true).setAttribute("idForajCurent", 0);
            return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
        } else if (getSelectedCombo() == 2) {
            int amplasamentID = Integer.parseInt(amplasamentFilter);
            getContext().getRequest().getSession(true).setAttribute("idAmplasamentCurent", amplasamentID);
            getContext().getRequest().getSession(true).setAttribute("idForajCurent", 0);
            return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
        } else if (getSelectedCombo() == 3) {
            int beneficiarID = Integer.parseInt(getBeneficiarFilter());
            getContext().getRequest().getSession(true).setAttribute("idBeneficiarCurent", beneficiarID);
            getContext().getRequest().getSession(true).setAttribute("idAmplasamentCurent", 0);
            getContext().getRequest().getSession(true).setAttribute("idForajCurent", 0);
            return new ForwardResolution("/WEB-INF/jsp/adaugaForaj.jsp");
        } else {
            Object b = getContext().getRequest().getSession(true).getAttribute("idBeneficiarCurent");
            if (b != null) {
                int bI = Integer.parseInt(b.toString());
                if (bI > 0) {
                    setIdBeneficiarCurent(bI);
                }
                Object a = getContext().getRequest().getSession(true).getAttribute("idAmplasamentCurent");
                if (a != null) {
                    int aI = Integer.parseInt(a.toString());
                    if (aI > 0) {
                        setIdAmplasamentCurent(aI);
                    }
                    Object f = getContext().getRequest().getSession(true).getAttribute("idForajCurent");
                    if (f != null) {
                        int fI = Integer.parseInt(f.toString());
                        if (fI > 0) {
                            setIdForajCurent(fI);
                        }
                    }
                }
            }
        }
        return new ForwardResolution("/WEB-INF/jsp/adaugaForaj.jsp");
    }

    public Resolution salveaza() {
        IAmplasamentDao amplasamentDao = new AmplasamentDao();
        Foraj foraj = new Foraj();
        try {
            float c = Float.valueOf(cota.trim()).floatValue();
            foraj.setCota(c);
            foraj.setNumeForaj(nume);
            try {
                int amplasamentID = Integer.parseInt(amplasamentFilter);
                Amplasament amplasament = amplasamentDao.getAmplasamentByID(amplasamentID);
                foraj.setAmplasament(amplasament);
                IForajDao forajDao = new ForajDao();
                forajDao.saveOrUpdate(foraj);
                setIdAmplasamentCurent(amplasamentID);
                getContext().getRequest().getSession(true).setAttribute("idAmplasamentCurent", amplasamentID);
            } catch (NumberFormatException nfe) {
                System.out.println("NumberFormatException: " + nfe.getMessage());
                return new ForwardResolution("/WEB-INF/jsp/adaugaForaj.jsp");
            }
        } catch (NumberFormatException nfe) {
            System.out.println("NumberFormatException: " + nfe.getMessage());
            return new ForwardResolution("/WEB-INF/jsp/adaugaForaj.jsp");
        }
        return new ForwardResolution("/WEB-INF/jsp/adaugaForaj.jsp");
    }

    public Resolution calculeazaIpIc() {
        // pentru fiecare proba se calculeaza Ip si Ic
        IProbaDao probaDao = new ProbaDao();
        float ip, ic;
        String s;
        int p, i;
        List<Proba> probe = probaDao.getAll(getIdForajCurent());
        int nrProbe = probe.size();
        Proba probaCurenta;
        for (i = 0; i < nrProbe; i++) {
            probaCurenta = probe.get(i);
            ip = probaCurenta.getWl() - probaCurenta.getWp();
            s = Double.toString(ip);
            p = s.indexOf('.');
            if (p >= 1) {
                s = s.substring(0, p + 2);
            }
            ip = Float.valueOf(s.trim()).floatValue();
            probaDao.addIp(probaCurenta.getIdProba(), ip);
            ic = (probaCurenta.getWl() - probaCurenta.getW()) / ip;
            s = Double.toString(ic);
            p = s.indexOf('.');
            if (p >= 1) {
                s = s.substring(0, p + 2);
            }
            ic = Float.valueOf(s.trim()).floatValue();
            probaDao.addIc(probaCurenta.getIdProba(), ic);
        }
        return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
    }

    public boolean getIsBeneficiarSelectat() {
        if (getIdBeneficiarCurent() > 0) {
            return true;
        } else {
            Object b = getContext().getRequest().getSession(true).getAttribute("idBeneficiarCurent");
            if (b != null) {
                int idB = Integer.parseInt(b.toString());
                if (idB > 0) {
                    setIdBeneficiarCurent(idB);
                    return true;
                }
            }
        }
        return false;
    }

    public String getBeneficiarSelectat() {
        if (getIdBeneficiarCurent() > 0) {
            BeneficiarDao beneficiarDao = new BeneficiarDao();
            String b = beneficiarDao.getPersonByID(getIdBeneficiarCurent());
            return b;
        }
        return "";
    }

    public boolean getIsAmplasamentSelectat() {
        if (getIdAmplasamentCurent() > 0) {
            return true;
        } else {
            Object a = getContext().getRequest().getSession(true).getAttribute("idAmplasamentCurent");
            if (a != null) {
                int idA = Integer.parseInt(a.toString());
                if (idA > 0) {
                    setIdAmplasamentCurent(idA);
                    return true;
                }
            }
        }
        return false;
    }

    public String getAmplasamentSelectat() {
        if (getIdAmplasamentCurent() > 0) {
            AmplasamentDao amplasamentDao = new AmplasamentDao();
            Amplasament a = amplasamentDao.getAmplasamentByID(getIdAmplasamentCurent());
            return a.getLocatie();
        }
        return "";
    }

    public boolean getIsForajSelectat() {
        if (getIdForajCurent() > 0) {
            return true;
        } else {
            Object f = getContext().getRequest().getSession(true).getAttribute("idForajCurent");
            if (f != null) {
                int idF = Integer.parseInt(f.toString());
                if (idF > 0) {
                    setIdForajCurent(idF);
                    return true;
                }
            }
        }
        return false;
    }

    public String getForajSelectat() {
        if (getIdForajCurent() > 0) {
            ForajDao forajDao = new ForajDao();
            Foraj f = forajDao.getForajByID(getIdForajCurent());
            return f.getNumeForaj();
        }
        return "";
    }

    public List<Beneficiar> getBeneficiari() {
        List<Beneficiar> beneficiari = new ArrayList<Beneficiar>();
        int idGeolog = getIdGeologLogat();
        IGeologBeneficiarDao geologBeneficiarDao = new GeologBeneficiarDao();
        List<Integer> idBeneficiari = geologBeneficiarDao.getGeologBeneficiariByGeologId(idGeolog);
        IBeneficiarDao beneficiarDao = new BeneficiarDao();
        Iterator it = idBeneficiari.iterator();
        while (it.hasNext()) {
            Integer idBeneficiar = (Integer) it.next();
            Beneficiar beneficiar = beneficiarDao.getBeneficiarByID(idBeneficiar);
            beneficiari.add(beneficiar);
        }
        if (getIdBeneficiarCurent() == 0) {
            setIdBeneficiarCurent(
                    beneficiari.get(0).getIdBeneficiar());
            getContext().getRequest().getSession(true).setAttribute("idBeneficiarCurent", getIdBeneficiarCurent());
        }
        return beneficiari;
    }

    public List<Amplasament> getAmplasamente() {
        int idB = getIdBeneficiarCurent();
        List<Amplasament> amplasamente;
        IAmplasamentDao amplasamentDao = new AmplasamentDao();
        amplasamente = amplasamentDao.getAmplasamenteByBeneficiarIdAndGeologId(idB, getIdGeologLogat());
        if (getIdAmplasamentCurent() == 0 && amplasamente != null && amplasamente.size() > 0) {
            setIdAmplasamentCurent(
                    amplasamente.get(0).getIdAmplasament());
            getContext().getRequest().getSession(true).setAttribute("idAmplasamentCurent", getIdAmplasamentCurent());
        }
        return amplasamente;
    }

    public List<Foraj> getForaje() {
        List<Foraj> foraje;
        IForajDao forajDao = new ForajDao();
        foraje = forajDao.getAll(getIdAmplasamentCurent());
        if (getIdForajCurent() == 0) {
            if (foraje != null && foraje.size() > 0) {
                setIdForajCurent(foraje.get(0).getIdForaj());
            }
            getContext().getRequest().getSession(true).setAttribute("idForajCurent", getIdForajCurent());
        }
        return foraje;
    }

    public Resolution reset() {
        return new ForwardResolution("/WEB-INF/jsp/adaugaForaj.jsp");
    }

    public Resolution editareForaj() {
        return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
    }

    public Resolution vizualizareForaj() {
        getContext().getRequest().getSession(true).setAttribute("vizualizareForaj", "proiectePrivate");
        return new ForwardResolution(action.VizualizareForajActionBean.class);
    }

    public Resolution adaugareProba() {
        return new ForwardResolution("/WEB-INF/jsp/adaugaProba.jsp");
    }

    public Resolution modificaProba() {
        if (getTipDeterminareR() != null) {
            String idProba = getProbaR();
            getContext().getRequest().getSession(true).setAttribute("idProbaCurenta", idProba);
            String td = getTipDeterminareR();
            if (td.equals("granulozitate")) {
                if (idProba != null) {
                    getContext().getRequest().getSession(true).setAttribute("idProba", Integer.parseInt(idProba));
                    return new ForwardResolution(action.MetodaCerneriiActionBean.class);
                } else {
                    return new ForwardResolution("editareForaj.jsp");
                }
            } else if (td.equals("wp")) {
                return new ForwardResolution(action.WPActionBean.class);
            } else if (td.equals("compresibilitate")) {
                if (idProba != null) {
                    getContext().getRequest().getSession(true).setAttribute("idProba", Integer.parseInt(idProba));
                    return new ForwardResolution(action.StantaActionBean.class);
                } else {
                    return new ForwardResolution("editareForaj.jsp");
                }
            } else if (td.equals("w")) {
                return new ForwardResolution(action.WActionBean.class);
            } else if (td.equals("densitatea pamanturilor")) {
                return new ForwardResolution(action.DensitateaPamanturilor.class);
            } else if (td.equals("wl")) {
                return new ForwardResolution(action.WLActionBean.class);
            } else {
                return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
            }
        } else {
            return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
        }
    }

    public Resolution stergereProba() {
        if (getProbaR() != null) {
            String idProba = getProbaR();
            IProbaDao probaDao = new ProbaDao();
            probaDao.delete(Integer.parseInt(idProba));
        }
        return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
    }

    public Resolution adaugareStrat() {
        return new ForwardResolution(action.StratActionBean.class);
    }

    public Resolution stergereStrat() {
        if (getStratR() != null) {
            String idStrat = getStratR();
            IStratDao stratDao = new StratDao();
            stratDao.delete(Integer.parseInt(idStrat));
        }
        return new ForwardResolution("/WEB-INF/jsp/editareForaj.jsp");
    }

    /* public List<Amplasament> getAmplasamente() {
    List<Amplasament> amplasamente;
    IAmplasamentDao amplasamentDao = new AmplasamentDao();
    amplasamente = amplasamentDao.getAll();
    setIdAmplasamentCurent(amplasamente.get(0).getIdAmplasament());
    return amplasamente;
    }

    public List<Foraj> getForaje() {
    int idA = getIdAmplasamentCurent();
    List<Foraj> foraje;
    IForajDao forajDao = new ForajDao();
    Object a = getContext().getRequest().getSession(true).getAttribute("idAmplasamentCurent");
    if (a != null) {
    idA = Integer.parseInt(a.toString());
    if (idA > 0) {
    setIdAmplasamentCurent(idA);
    }
    }
    foraje = forajDao.getAll(idA);
    setIdForajCurent(foraje.get(0).getIdForaj());
    return foraje;
    }
     */
    public List<Proba> getProbe() {
        List<Proba> probe = null;
        IProbaDao probaDao = new ProbaDao();
        probe = probaDao.getAll(getIdForajCurent());
        return probe;
    }

    public List<Strat> getStraturi() {
        List<Strat> straturi = null;
        IStratDao stratDao = new StratDao();
        straturi = stratDao.getAll(getIdForajCurent());
        return straturi;
    }

    /**
     * @return the
     */
    public String getAmplasamentFilter() {
        return amplasamentFilter;
    }

    /**
     * @param amplasamentFilter the amplasamentFilter to set
     */
    public void setAmplasamentFilter(String amplasamentFilter) {
        this.amplasamentFilter = amplasamentFilter;
    }

    /**
     * @return the nume
     */
    public String getNume() {
        return nume;
    }

    /**
     * @param nume the nume to set
     */
    public void setNume(String nume) {
        this.nume = nume;
    }

    /**
     * @return the cota
     */
    public String getCota() {
        return cota;
    }

    /**
     * @param cota the cota to set
     */
    public void setCota(String cota) {
        this.cota = cota;
    }

    /**
     * @return the idAmplasamentCurent
     */
    public int getIdAmplasamentCurent() {
        return idAmplasamentCurent;
    }

    /**
     * @param idAmplasamentCurent the idAmplasamentCurent to set
     */
    public void setIdAmplasamentCurent(int idAmplasamentCurent) {
        this.idAmplasamentCurent = idAmplasamentCurent;
    }

    /**
     * @return the forajFilter
     */
    public String getForajFilter() {
        return forajFilter;
    }

    /**
     * @param forajFilter the forajFilter to set
     */
    public void setForajFilter(String forajFilter) {
        this.forajFilter = forajFilter;
    }

    /**
     * @return the idForajCurent
     */
    public int getIdForajCurent() {
        return idForajCurent;
    }

    /**
     * @param idForajCurent the idForajCurent to set
     */
    public void setIdForajCurent(int idForajCurent) {
        this.idForajCurent = idForajCurent;
    }

    /**
     * @return the probaR
     */
    public String getProbaR() {
        return probaR;
    }

    /**
     * @param probaR the probaR to set
     */
    public void setProbaR(String probaR) {
        this.probaR = probaR;
    }

    /**
     * @return the stratR
     */
    public String getStratR() {
        return stratR;
    }

    /**
     * @param stratR the stratR to set
     */
    public void setStratR(String stratR) {
        this.stratR = stratR;
    }

    /**
     * @return the tipDeterminareR
     */
    public String getTipDeterminareR() {
        return tipDeterminareR;
    }

    /**
     * @param tipDeterminareR the tipDeterminareR to set
     */
    public void setTipDeterminareR(String tipDeterminareR) {
        this.tipDeterminareR = tipDeterminareR;
    }

    /**
     * @return the selectedCombo
     */
    public int getSelectedCombo() {
        return selectedCombo;
    }

    /**
     * @param selectedCombo the selectedCombo to set
     */
    public void setSelectedCombo(int selectedCombo) {
        this.selectedCombo = selectedCombo;
    }

    /**
     * @return the beneficiarFilter
     */
    public String getBeneficiarFilter() {
        return beneficiarFilter;
    }

    /**
     * @param beneficiarFilter the beneficiarFilter to set
     */
    public void setBeneficiarFilter(String beneficiarFilter) {
        this.beneficiarFilter = beneficiarFilter;
    }

    /**
     * @return the idBeneficiarCurent
     */
    public int getIdBeneficiarCurent() {
        return idBeneficiarCurent;
    }

    /**
     * @param idBeneficiarCurent the idBeneficiarCurent to set
     */
    public void setIdBeneficiarCurent(int idBeneficiarCurent) {
        this.idBeneficiarCurent = idBeneficiarCurent;
    }
}
TOP

Related Classes of action.ForajActionBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.