Package action

Source Code of action.MetodaCerneriiActionBean

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

import auxiliar.MetodaCernerii;
import auxiliar.FormularMetodaCernerii;
import bo.MetCernerii;
import bo.Proba;
import dao.MetCerneriiDao;
import dao.ProbaDao;
import daoI.IProbaDao;
import daoI.IMetCerneriiDao;
import java.util.ArrayList;
import java.util.Arrays;
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 MetodaCerneriiActionBean extends BaseActionBean {

    private MetodaCernerii met_cernerii;
    private FormularMetodaCernerii formular = new FormularMetodaCernerii();
    private String rsInput;
    private String mdInput;

    @DefaultHandler
    public Resolution view() {
     
        //daca s-a mai facut metoda cernerii pt proba curenta,atunci se afiseaza valorile din BD
        met_cernerii = new MetodaCernerii();
        IMetCerneriiDao metCerneriiDao = new MetCerneriiDao();
        MetCernerii metCerneriiAuxiliar = metCerneriiDao.getMetCerneriiByIDProba(Integer.parseInt(getContext().getRequest().getSession().getAttribute("idProba").toString()));
        if (metCerneriiAuxiliar != null) {
            List<Float> valoriIntroduse = Arrays.asList(metCerneriiAuxiliar.getVal200(), metCerneriiAuxiliar.getVal150(), metCerneriiAuxiliar.getVal70(), metCerneriiAuxiliar.getVal40(), metCerneriiAuxiliar.getVal30(), metCerneriiAuxiliar.getVal20(), metCerneriiAuxiliar.getVal15(), metCerneriiAuxiliar.getVal10(), metCerneriiAuxiliar.getVal5(), metCerneriiAuxiliar.getVal2(), metCerneriiAuxiliar.getVal1(), metCerneriiAuxiliar.getVal05(), metCerneriiAuxiliar.getVal025(), metCerneriiAuxiliar.getVal01(), metCerneriiAuxiliar.getVal008(), metCerneriiAuxiliar.getVal0071(), metCerneriiAuxiliar.getVal005(), metCerneriiAuxiliar.getVal0());
            populeazaColoana2(metCerneriiAuxiliar);
            met_cernerii.setCantiateaRamasaPeSite1(valoriIntroduse);
            met_cernerii.setCantiateaRamasaPeSite2(formulaMetCerneriiCol3(valoriIntroduse, Float.parseFloat(getMd())));
            met_cernerii.setFractiuni(formulaMetCerneriiCol4(met_cernerii.getCantiateaRamasaPeSite2()));
            met_cernerii.setSuma2(getSuma(met_cernerii.getCantiateaRamasaPeSite1()));
            met_cernerii.setSuma3(getSuma(met_cernerii.getCantiateaRamasaPeSite2()));
            met_cernerii.setSumeCalculate(true);
            met_cernerii.setMaterialSpalat(Float.parseFloat(getMd()) - met_cernerii.getSuma2());
            met_cernerii.setMaterialCernut(met_cernerii.getSuma2());
        }

       
        getContext().getRequest().getSession(true).setAttribute("metC", met_cernerii);
        return new ForwardResolution("/WEB-INF/jsp/metoda_cernerii.jsp");
    }

    public Resolution submit() {
        IProbaDao probaDao = new ProbaDao();
        //proba curenta
        Proba proba = probaDao.geProbaByID(Integer.parseInt(getContext().getRequest().getSession().getAttribute("idProba").toString()));
        //valori introduse
        String x=getFormular().getVal0();
        List<Float> valoriIntroduse = Arrays.asList(Float.parseFloat(getFormular().getVal0()), Float.parseFloat(getFormular().getVal1()), Float.parseFloat(getFormular().getVal2()), Float.parseFloat(getFormular().getVal3()), Float.parseFloat(getFormular().getVal4()), Float.parseFloat(getFormular().getVal5()), Float.parseFloat(getFormular().getVal6()), Float.parseFloat(getFormular().getVal7()), Float.parseFloat(getFormular().getVal8()), Float.parseFloat(getFormular().getVal9()), Float.parseFloat(getFormular().getVal10()), Float.parseFloat(getFormular().getVal11()), Float.parseFloat(getFormular().getVal12()), Float.parseFloat(getFormular().getVal13()), Float.parseFloat(getFormular().getVal14()), Float.parseFloat(getFormular().getVal15()), Float.parseFloat(getFormular().getVal16()), Float.parseFloat(getFormular().getVal17()));

        //obiect format pt proba curenta cu valorile introduse pt introducere in BD
        MetCernerii metCerneriiBO = new MetCernerii(proba, valoriIntroduse.get(0), valoriIntroduse.get(1), valoriIntroduse.get(2), valoriIntroduse.get(3), valoriIntroduse.get(4), valoriIntroduse.get(5), valoriIntroduse.get(6), valoriIntroduse.get(7), valoriIntroduse.get(8), valoriIntroduse.get(9), valoriIntroduse.get(10), valoriIntroduse.get(11), valoriIntroduse.get(12), valoriIntroduse.get(13), valoriIntroduse.get(14), valoriIntroduse.get(15), valoriIntroduse.get(16), valoriIntroduse.get(17));
        IMetCerneriiDao metCerneriiDao = new MetCerneriiDao();

        //daca s-a mai facut metoda cernerii pt proba curenta, atunci se v-a face update la tupla corespunzatoare,altfel se introduce
        MetCernerii metCerneriiAuxiliar = metCerneriiDao.getMetCerneriiByIDProba(Integer.parseInt(getContext().getRequest().getSession().getAttribute("idProba").toString()));
        if (metCerneriiAuxiliar == null) {
            metCerneriiDao.saveOrUpdate(metCerneriiBO);
        } else {
            metCerneriiBO.setIdCernere(metCerneriiAuxiliar.getIdCernere());
            metCerneriiDao.saveOrUpdate(metCerneriiBO);
        }
        //update la proba pt parametrii md si rs

        proba.setMd(Float.parseFloat(getMdInput()));
        proba.setRs(Float.parseFloat(getRsInput()));
        probaDao.saveOrUpdate(proba);


        met_cernerii = new MetodaCernerii();
        //se modifica pt a afisa in pagina, noile valori introduse
        MetCernerii metCerneriiDinBd = metCerneriiDao.getMetCerneriiByIDProba(proba.getIdProba());
        List<Float> valoriDinBD = Arrays.asList(metCerneriiDinBd.getVal200(), metCerneriiDinBd.getVal150(), metCerneriiDinBd.getVal70(), metCerneriiDinBd.getVal40(), metCerneriiDinBd.getVal30(), metCerneriiDinBd.getVal20(), metCerneriiDinBd.getVal15(), metCerneriiDinBd.getVal10(), metCerneriiDinBd.getVal5(), metCerneriiDinBd.getVal2(), metCerneriiDinBd.getVal1(), metCerneriiDinBd.getVal05(), metCerneriiDinBd.getVal025(), metCerneriiDinBd.getVal01(), metCerneriiDinBd.getVal008(), metCerneriiDinBd.getVal0071(), metCerneriiDinBd.getVal005(), metCerneriiDinBd.getVal0());
        met_cernerii.setCantiateaRamasaPeSite1(valoriDinBD);
        //completam coloana3
        met_cernerii.setCantiateaRamasaPeSite2(formulaMetCerneriiCol3(valoriDinBD, Float.parseFloat(getMdInput())));
        //completam coloana4
        met_cernerii.setFractiuni(formulaMetCerneriiCol4(met_cernerii.getCantiateaRamasaPeSite2()));
        //Calculam suma pe coloana a 2-a
        met_cernerii.setSuma2(getSuma(met_cernerii.getCantiateaRamasaPeSite1()));
        //Calculam suma pe coloana a 3-a
        met_cernerii.setSuma3(getSuma(met_cernerii.getCantiateaRamasaPeSite2()));
        //setam variabila pt calcul suma
        met_cernerii.setSumeCalculate(true);
        //calculam material spalat
        met_cernerii.setMaterialSpalat(Float.parseFloat(getMd()) - met_cernerii.getSuma2());
        //calculam material cernut
        met_cernerii.setMaterialCernut(met_cernerii.getSuma2());
        getContext().getRequest().getSession(true).setAttribute("metC", met_cernerii);
        return new ForwardResolution("/WEB-INF/jsp/metoda_cernerii.jsp");

    }

    public MetodaCernerii getMet_cernerii() {
        return met_cernerii;
    }

    public FormularMetodaCernerii getFormular() {
        return formular;
    }

    public void setFormular(FormularMetodaCernerii formular) {
        this.formular = formular;
    }

    public String getMdInput() {
        return mdInput;
    }

    public void setMdInput(String mdInput) {
        this.mdInput = mdInput;
    }

    public String getRsInput() {
        return rsInput;
    }

    public void setRsInput(String rsInput) {
        this.rsInput = rsInput;
    }
    //returneaza suma pe o coloana data ca si parametru

    public Float getSuma(List<Float> coloana) {
        Float suma = (float) 0.0;
        Iterator it = coloana.iterator();
        while (it.hasNext()) {
            suma += Float.parseFloat(it.next().toString());
        }
        return suma;
    }

    //calculeaza coloana3
    private List<Float> formulaMetCerneriiCol3(List<Float> dateIn, Float param) {
        List<Float> dateOut = new ArrayList<Float>();
        for (int i = 0; i < dateIn.size(); i++) {
            Float formula = (float) dateIn.get(i) * 100 / param;
            dateOut.add(formula);

        }
        return dateOut;
    }

    //calculeaza coloana4
    private List<Float> formulaMetCerneriiCol4(List<Float> dateIn) {
        List<Float> dateOut = new ArrayList<Float>();
        dateOut.add(100 - dateIn.get(0));
        for (int i = 1; i < dateIn.size(); i++) {
            Float formula = dateOut.get(i - 1) - dateIn.get(i);
            dateOut.add(Float.parseFloat(zecimale(formula,3).toString()));
        }
        return dateOut;
    }

    public boolean getSumeCalculate() {
        MetodaCernerii met = (MetodaCernerii) (getContext().getRequest().getSession().getAttribute("metC"));
        return met.getSumeCalculate();
    }
     private void populeazaColoana2(MetCernerii metCerneriiAuxiliar) {
        formular.setVal0(metCerneriiAuxiliar.getVal200().toString());
        formular.setVal1(metCerneriiAuxiliar.getVal150().toString());
        formular.setVal2(metCerneriiAuxiliar.getVal70().toString());
        formular.setVal3(metCerneriiAuxiliar.getVal40().toString());
        formular.setVal4(metCerneriiAuxiliar.getVal30().toString());
        formular.setVal5(metCerneriiAuxiliar.getVal20().toString());
        formular.setVal6(metCerneriiAuxiliar.getVal15().toString());
        formular.setVal7(metCerneriiAuxiliar.getVal10().toString());
        formular.setVal8(metCerneriiAuxiliar.getVal2().toString());
        formular.setVal9(metCerneriiAuxiliar.getVal1().toString());
        formular.setVal10(metCerneriiAuxiliar.getVal05().toString());
        formular.setVal11(metCerneriiAuxiliar.getVal025().toString());
        formular.setVal12(metCerneriiAuxiliar.getVal01().toString());
        formular.setVal13(metCerneriiAuxiliar.getVal008().toString());
        formular.setVal14(metCerneriiAuxiliar.getVal0071().toString());
        formular.setVal15(metCerneriiAuxiliar.getVal005().toString());
        formular.setVal16(metCerneriiAuxiliar.getVal200().toString());
        formular.setVal17(metCerneriiAuxiliar.getVal200().toString());

     }
}
TOP

Related Classes of action.MetodaCerneriiActionBean

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.