Regalamiunsorriso/decompiled-libs/www/acxent-common-1.0.1/it/acxent/tex/anag/ArticoloTessutoComponente.java

179 lines
5.7 KiB
Java

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.StringTokenizer;
import it.acxent.util.Vectumerator;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ArticoloTessutoComponente extends DBAdapter implements Serializable {
private static final long serialVersionUID = 1468228166638L;
private long id_articoloTessutoComponente;
private long id_componente;
private long id_articoloTessuto;
private double percentuale;
private Componente componente;
private ArticoloTessuto articoloTessuto;
public ArticoloTessutoComponente(ApplParmFull newApplParmFull) {
super(newApplParmFull);
}
public ArticoloTessutoComponente() {}
public void setId_articoloTessutoComponente(long newId_articoloTessutoComponente) {
this.id_articoloTessutoComponente = newId_articoloTessutoComponente;
}
public void setId_componente(long newId_componente) {
this.id_componente = newId_componente;
setComponente(null);
}
public void setId_articoloTessuto(long newId_articoloTessuto) {
this.id_articoloTessuto = newId_articoloTessuto;
setArticoloTessuto(null);
}
public void setPercentuale(double newPercentuale) {
this.percentuale = newPercentuale;
}
public long getId_articoloTessutoComponente() {
return this.id_articoloTessutoComponente;
}
public long getId_componente() {
return this.id_componente;
}
public long getId_articoloTessuto() {
return this.id_articoloTessuto;
}
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 setArticoloTessuto(ArticoloTessuto newArticoloTessuto) {
this.articoloTessuto = newArticoloTessuto;
}
public ArticoloTessuto getArticoloTessuto() {
this.articoloTessuto = (ArticoloTessuto)getSecondaryObject(this.articoloTessuto, ArticoloTessuto.class, getId_articoloTessuto());
return this.articoloTessuto;
}
protected ResParm checkDeleteCascade() {
return new ResParm(true);
}
protected void deleteCascade() {}
public Vectumerator<ArticoloTessutoComponente> findByCR(ArticoloTessutoComponenteCR CR, int pageNumber, int pageRows) {
String s_Sql_Find = "select A.* from ARTICOLO_TESSUTO_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 double getTotPercentualeByArticoloTessuto(long l_id_articoloTessuto) {
String s_Sql_Find = "select sum(percentuale) as _sum from ARTICOLO_TESSUTO_COMPONENTE AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_articoloTessuto = " + l_id_articoloTessuto);
try {
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString());
return getSum(stmt);
} catch (SQLException e) {
removeCPConnection();
handleDebug(e);
return 0.0D;
}
}
public ResParm save() {
ResParm rp = isSalvabile();
if (rp.getStatus())
return super.save();
return rp;
}
private ResParm isSalvabile() {
boolean checkComponente = false;
DoubleOperator dop = new DoubleOperator();
ArticoloTessutoComponente afc = new ArticoloTessutoComponente(getApFull());
if (getId_articoloTessuto() == 0L)
return new ResParm(false, "ERRORE! Tessuto non valido!");
if (getPercentuale() == 0.0D)
return new ResParm(false, "ERRORE! Percentuale non valida!");
Vectumerator<ArticoloTessutoComponente> vec = afc.findByArticoloTessuto(getId_articoloTessuto());
while (vec.hasMoreElements()) {
afc = (ArticoloTessutoComponente)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, "ERRORE! Percentuale errata!");
return new ResParm(false, "ERRORE! Componente già selezionato!");
}
public Vectumerator<ArticoloTessutoComponente> findByArticoloTessuto(long l_id_articoloTessuto) {
String s_Sql_Find = "select A.* from ARTICOLO_TESSUTO_COMPONENTE AS A";
String s_Sql_Order = "";
WcString wc = new WcString();
wc.addWc(" A.id_articoloTessuto = " + l_id_articoloTessuto);
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;
}
}
}