Package action

Source Code of action.BeneficiarActionBean

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package action;

import bo.Beneficiar;
import bo.GeologBeneficiar;
import dao.BeneficiarDao;
import daoI.IBeneficiarDao;
import daoI.IGeologBeneficiarDao;
import dao.GeologBeneficiarDao;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.ForwardResolution;
import net.sourceforge.stripes.action.Resolution;

public class BeneficiarActionBean extends BaseActionBean {

    private String nume;
    private String cnp;
    private String mentiuni;
    private String beneficiarFilter;// pentru editare beneficiar
    //editare beneficiar
    private String cnpEditare;
    private String mentiuniEditare;
    private Boolean beneficiarEditat = false;
    private Beneficiar beneficiar;
    private Boolean campuriNecompletate = false;
    //pentru pagina de adaugare beneficiar cand cream proiect
    private String selectBeneficiarFilter;
    private String btnRadio;
    private Boolean radioNeselectat = false;
    private Boolean beneficiarAdaugat = false;
    private Boolean cnpIncorect = false;

    @DefaultHandler
    public Resolution view() {
        setCnpEditare(getCnpBeneficiar());
        setMentiuniEditare(getMentiuniBeneficiar());
        return new ForwardResolution("/WEB-INF/jsp/editareBeneficiar.jsp");
    }

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

    public Resolution adaugaBeneficiar() {
        getContext().getRequest().getSession(true).setAttribute("creazaProiect", 0);
        return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
    }

    public Resolution creazaProiect() {
        getContext().getRequest().getSession(true).setAttribute("beneficiarProiect", null);
        getContext().getRequest().getSession(true).setAttribute("proiectInLucru", null);
        getContext().getRequest().getSession(true).setAttribute("repartizareAmplasamente", null);
        getContext().getRequest().getSession(true).setAttribute("creazaProiect", 1);
        return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
    }

    public Resolution submit() {
        int proiect = Integer.parseInt(getContext().getRequest().getSession().getAttribute("creazaProiect").toString());
        IBeneficiarDao beneficiarDao = new BeneficiarDao();
        if (proiect == 0) {
            if ((getNume() == null) || (getCnp() == null)) {
                setCampuriNecompletate(true);
                return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
            }
            if (cnp.length() != 13) {
                setCnpIncorect(true);
                return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
            } else if (!isNumeric(cnp)) {
                setCnpIncorect(true);
                return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
            }
            Beneficiar beneficiar = new Beneficiar(nume, cnp, mentiuni, null);
            beneficiarDao.saveOrUpdate(beneficiar);
            Beneficiar bAux = beneficiarDao.getBeneficiarCnp(cnp);
            int idGeolog = getIdGeologLogat();
            IGeologBeneficiarDao geologBeneficiarDao = new GeologBeneficiarDao();
            geologBeneficiarDao.saveOrUpdate(new GeologBeneficiar(idGeolog, bAux.getIdBeneficiar()));
            setBeneficiarAdaugat(true);
            return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
        } //daca cream un proiect
        else if (proiect == 1) {
            if (getBtnRadio() == null) {
                setRadioNeselectat(true);
                return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
            } else if (getBtnRadio().equals("1")) {
                Beneficiar beneficiarSelectat = beneficiarDao.getBeneficiarByID(Integer.parseInt(getSelectBeneficiarFilter()));
                IGeologBeneficiarDao geologBeneficiarDao = new GeologBeneficiarDao();
                int idGeolog = getIdGeologLogat();
                geologBeneficiarDao.saveOrUpdate(new GeologBeneficiar(idGeolog, beneficiarSelectat.getIdBeneficiar()));
                getContext().getRequest().getSession(true).setAttribute("beneficiarProiect", beneficiarSelectat);
                return new ForwardResolution("/WEB-INF/jsp/proiect.jsp");
            } else if (getBtnRadio().equals("2")) {
                if ((getNume() == null) || (getCnp() == null)) {
                    setCampuriNecompletate(true);
                    return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
                }
                if (cnp.length() != 13) {
                    setCnpIncorect(true);
                    return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
                } else if (!isNumeric(cnp)) {
                    setCnpIncorect(true);
                    return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
                }
                Beneficiar beneficiar = new Beneficiar(nume, cnp, mentiuni, null);
                beneficiarDao.saveOrUpdate(beneficiar);
                Beneficiar bAux = beneficiarDao.getBeneficiarCnp(cnp);
                int idGeolog = getIdGeologLogat();
                IGeologBeneficiarDao geologBeneficiarDao = new GeologBeneficiarDao();
                geologBeneficiarDao.saveOrUpdate(new GeologBeneficiar(idGeolog, bAux.getIdBeneficiar()));
                getContext().getRequest().getSession(true).setAttribute("beneficiarProiect", bAux);
                return new ForwardResolution("/WEB-INF/jsp/proiect.jsp");
            }


        }
        return new ForwardResolution("/WEB-INF/jsp/adaugaBeneficiar.jsp");
    }

    public Resolution editare() {
        Beneficiar beneficiar = new Beneficiar();
        IBeneficiarDao beneficiarDao = new BeneficiarDao();
        beneficiar.setIdBeneficiar(Integer.parseInt(getBeneficiarFilter()));
        beneficiar.setCuiBeneficiar(getCnpEditare());
        beneficiar.setMentiuniBeneficiar(getMentiuniEditare());
        String numeB = beneficiarDao.getBeneficiarByID(Integer.parseInt(getBeneficiarFilter())).getNumeBeneficiar();
        beneficiar.setNumeBeneficiar(numeB);
        beneficiarDao.saveOrUpdate(beneficiar);
        setBeneficiarEditat(true);
        return new ForwardResolution("/WEB-INF/jsp/editareBeneficiar.jsp");
    }

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

    public Boolean getBeneficiarEditat() {
        return beneficiarEditat;
    }

    public void setBeneficiarEditat(Boolean beneficiarEditat) {
        this.beneficiarEditat = beneficiarEditat;
    }

    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);
        }

        return beneficiari;
    }

    public Boolean getIsBeneficiarSelectat() {

        if (getBeneficiarFilter() != null) {
            return true;
        } else {
            return false;
        }
    }

    public String getMentiuniBeneficiar() {
        if (getBeneficiarFilter() == null) {
            return "";
        } else {
            IBeneficiarDao beneficiarDao = new BeneficiarDao();
            Beneficiar beneficiar = beneficiarDao.getBeneficiarByID(Integer.parseInt(getBeneficiarFilter()));
            return beneficiar.getMentiuniBeneficiar();
        }
    }

    public String getCnpBeneficiar() {
        if (getBeneficiarFilter() == null) {
            return "";
        } else {
            IBeneficiarDao beneficiarDao = new BeneficiarDao();
            Beneficiar beneficiar = beneficiarDao.getBeneficiarByID(Integer.parseInt(getBeneficiarFilter()));
            return beneficiar.getCuiBeneficiar();
        }
    }

    public String getCnp() {
        return cnp;
    }

    public void setCnp(String cnp) {
        this.cnp = cnp;
    }

    public String getMentiuni() {
        return mentiuni;
    }

    public void setMentiuni(String mentiuni) {
        this.mentiuni = mentiuni;
    }

    public String getNume() {
        return nume;
    }

    public void setNume(String nume) {
        this.nume = nume;
    }

    public String getBeneficiarFilter() {
        return beneficiarFilter;
    }

    public void setBeneficiarFilter(String beneficiarFilter) {
        this.beneficiarFilter = beneficiarFilter;
    }

    public String getCnpEditare() {
        return cnpEditare;
    }

    public void setCnpEditare(String cnpEditare) {
        this.cnpEditare = cnpEditare;
    }

    public String getMentiuniEditare() {
        return mentiuniEditare;
    }

    public void setMentiuniEditare(String mentiuniEditare) {
        this.mentiuniEditare = mentiuniEditare;
    }

    public Beneficiar getBeneficiar() {
        return beneficiar;
    }

    public void setBeneficiar(Beneficiar beneficiar) {
        this.beneficiar = beneficiar;
    }

    public String getBtnRadio() {
        return btnRadio;
    }

    public void setBtnRadio(String btnRadio) {
        this.btnRadio = btnRadio;
    }

    public String getSelectBeneficiarFilter() {
        return selectBeneficiarFilter;
    }

    public void setSelectBeneficiarFilter(String selectBeneficiarFilter) {
        this.selectBeneficiarFilter = selectBeneficiarFilter;
    }

    public Boolean getRadioNeselectat() {
        return radioNeselectat;
    }

    public void setRadioNeselectat(Boolean radioNeselectat) {
        this.radioNeselectat = radioNeselectat;
    }

    public Boolean getCampuriNecompletate() {
        return campuriNecompletate;
    }

    public void setCampuriNecompletate(Boolean campuriNecompletate) {
        this.campuriNecompletate = campuriNecompletate;
    }

    public Boolean getBeneficiarAdaugat() {
        return beneficiarAdaugat;
    }

    public void setBeneficiarAdaugat(Boolean beneficiarAdaugat) {
        this.beneficiarAdaugat = beneficiarAdaugat;
    }

    public Boolean getCnpIncorect() {
        return cnpIncorect;
    }

    public void setCnpIncorect(Boolean cnpIncorect) {
        this.cnpIncorect = cnpIncorect;
    }
}
TOP

Related Classes of action.BeneficiarActionBean

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.