package it.acxent.tex.anag; import it.acxent.art.Componente; import it.acxent.db.ApplParmFull; import it.acxent.db.DBAdapter; import it.acxent.db.ResParm; import it.acxent.db.WcString; import it.acxent.util.DoubleOperator; import it.acxent.util.Vectumerator; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.StringTokenizer; public class ArticoloFilatoComponente extends DBAdapter implements Serializable { private static final long serialVersionUID = 1468228166523L; private long id_articoloFilatoComponente; private long id_componente; private long id_articoloFilato; private double percentuale; private Componente componente; private ArticoloFilato articoloFilato; public ArticoloFilatoComponente(ApplParmFull newApplParmFull) { super(newApplParmFull); } public ArticoloFilatoComponente() {} public void setId_articoloFilatoComponente(long newId_articoloFilatoComponente) { this.id_articoloFilatoComponente = newId_articoloFilatoComponente; } public void setId_componente(long newId_componente) { this.id_componente = newId_componente; setComponente(null); } public void setId_articoloFilato(long newId_articoloFilato) { this.id_articoloFilato = newId_articoloFilato; setArticoloFilato(null); } public void setPercentuale(double newPercentuale) { this.percentuale = newPercentuale; } public long getId_articoloFilatoComponente() { return this.id_articoloFilatoComponente; } public long getId_componente() { return this.id_componente; } public long getId_articoloFilato() { return this.id_articoloFilato; } public double getPercentuale() { return this.percentuale; } public void setComponente(Componente newComponente) { this.componente = newComponente; } public Componente getComponente() { this.componente = (Componente)getSecondaryObject(this.componente, Componente.class, getId_componente()); return this.componente; } public void setArticoloFilato(ArticoloFilato newArticoloFilato) { this.articoloFilato = newArticoloFilato; } public ArticoloFilato getArticoloFilato() { this.articoloFilato = (ArticoloFilato)getSecondaryObject(this.articoloFilato, ArticoloFilato.class, getId_articoloFilato()); return this.articoloFilato; } protected ResParm checkDeleteCascade() { return new ResParm(true); } protected void deleteCascade() {} public Vectumerator findByCR(ArticoloFilatoComponenteCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from ARTICOLO_FILATO_COMPONENTE AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); if (!CR.getSearchTxt().trim().isEmpty()) { StringTokenizer st = new StringTokenizer(CR.getSearchTxt().trim(), " "); StringBuffer txt = new StringBuffer("("); while (st.hasMoreTokens()) { String token = st.nextToken(); txt.append("(A.Cognome like '%" + token + "%' or A.Nome like '%" + token + "%')"); if (st.hasMoreTokens()) txt.append(" and "); } txt.append(")"); wc.addWc(txt.toString()); } try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); return findRows(stmt, pageNumber, pageRows); } catch (SQLException e) { removeCPConnection(); handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public Vectumerator findByArticoloFilato(long l_id_articoloFilato) { String s_Sql_Find = "select A.* from ARTICOLO_FILATO_COMPONENTE AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); wc.addWc(" A.id_articoloFilato = " + l_id_articoloFilato); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); return findRows(stmt, 0, 0); } catch (SQLException e) { removeCPConnection(); handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public ResParm save() { ResParm rp = isSalvabile(); if (rp.getStatus()) return super.save(); return rp; } private ResParm isSalvabile() { boolean checkComponente = false; DoubleOperator dop = new DoubleOperator(); ArticoloFilatoComponente afc = new ArticoloFilatoComponente(getApFull()); if (getId_articoloFilato() == 0L) return new ResParm(false, "ERRORE! Filato non valido!"); if (getPercentuale() == 0.0D) return new ResParm(false, "ERRORE! Percentuale non valida!"); Vectumerator vec = afc.findByArticoloFilato(getId_articoloFilato()); while (vec.hasMoreElements()) { afc = (ArticoloFilatoComponente)vec.nextElement(); if (afc.getId_componente() == getId_componente()) checkComponente = true; dop.add(afc.getPercentuale()); } dop.add(getPercentuale()); if (dop.getResult() <= 100.0D && !checkComponente) return new ResParm(true); if (dop.getResult() > 100.0D) return new ResParm(false, "Percentuale errata!"); return new ResParm(false, "Componente giĆ  selezionato!"); } }