316 lines
9.2 KiB
Java
316 lines
9.2 KiB
Java
package it.acxent.art;
|
|
|
|
import it.acxent.db.ApplParmFull;
|
|
import it.acxent.db.DBAdapter;
|
|
import it.acxent.db.DbInterface;
|
|
import it.acxent.db.ResParm;
|
|
import it.acxent.db.WcString;
|
|
import it.acxent.util.StringTokenizer;
|
|
import it.acxent.util.Vectumerator;
|
|
import java.io.Serializable;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.SQLException;
|
|
|
|
public class Caratteristica extends _ArtAdapter implements Serializable {
|
|
private static final long serialVersionUID = -3717919132443402126L;
|
|
|
|
private long id_caratteristica;
|
|
|
|
private long flgCR;
|
|
|
|
private String descrizione_it;
|
|
|
|
private String icecatDescs;
|
|
|
|
private long flgTipoVal;
|
|
|
|
private long ordine;
|
|
|
|
private long flgRicercaWeb;
|
|
|
|
private String descrizioneAggiuntiva;
|
|
|
|
public static final int TIPO_VAL_BOOLEANO = 4;
|
|
|
|
public static final int TIPO_VAL_DATA = 5;
|
|
|
|
public static final int TIPO_VAL_DOUBLE = 2;
|
|
|
|
public static final int TIPO_VAL_INTERO = 1;
|
|
|
|
public static final int TIPO_VAL_LISTA = 6;
|
|
|
|
public static final int TIPO_VAL_STRINGA = 3;
|
|
|
|
public ResParm addTipo(long l_id_tipo) {
|
|
CTipo bean = new CTipo(getApFull());
|
|
bean.findByPrimaryKey(new CTipoKey(l_id_tipo, getId_caratteristica()));
|
|
bean.setId_tipo(l_id_tipo);
|
|
bean.setId_caratteristica(getId_caratteristica());
|
|
return bean.save();
|
|
}
|
|
|
|
public ResParm delTipo(long l_id_tipo) {
|
|
CTipo bean = new CTipo(getApFull());
|
|
bean.findByPrimaryKey(new CTipoKey(l_id_tipo, getId_caratteristica()));
|
|
return bean.delete();
|
|
}
|
|
|
|
public Caratteristica(ApplParmFull newApplParmFull) {
|
|
super(newApplParmFull);
|
|
}
|
|
|
|
public Caratteristica() {}
|
|
|
|
public void setId_caratteristica(long newId_caratteristica) {
|
|
this.id_caratteristica = newId_caratteristica;
|
|
}
|
|
|
|
public void setFlgTipoVal(long newFlgTipoVal) {
|
|
this.flgTipoVal = newFlgTipoVal;
|
|
}
|
|
|
|
public long getId_caratteristica() {
|
|
return this.id_caratteristica;
|
|
}
|
|
|
|
public String getTipoVal() {
|
|
return getTipoVal(getFlgTipoVal());
|
|
}
|
|
|
|
public long getFlgTipoVal() {
|
|
return this.flgTipoVal;
|
|
}
|
|
|
|
protected void deleteCascade() {
|
|
Vectumerator<Lista> vec = new Lista(getApFull()).findLista(getId_caratteristica(), 0, 0);
|
|
while (vec.hasMoreElements())
|
|
((DbInterface)vec.nextElement()).delete();
|
|
}
|
|
|
|
public Vectumerator findByCR(CaratteristicaCR CR, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from CARATTERISTICA AS A";
|
|
String s_Sql_Order = " order by A.ordine, A.descrizione_it";
|
|
WcString wc = new WcString();
|
|
if (!CR.getDescrizione().isEmpty())
|
|
wc.addWc("A.descrizione_it like'%" + CR.getDescrizione() + "%'");
|
|
if (CR.getFlgTipoVal() > 0L)
|
|
wc.addWc("A.flgTipoVal=" + CR.getFlgTipoVal());
|
|
if (CR.getId_tipo() != 0L) {
|
|
s_Sql_Find = s_Sql_Find + ", C_TIPO as B";
|
|
wc.addWc("A.id_caratteristica=B.id_caratteristica");
|
|
wc.addWc("B.id_tipo=" + CR.getId_tipo());
|
|
}
|
|
if (CR.getFlgRicercaWeb() == 0L) {
|
|
wc.addWc("(A.flgRicercaWeb is null or A.flgRicercaWeb=0)");
|
|
} else if (CR.getFlgRicercaWeb() > 0L) {
|
|
wc.addWc("A.flgRicercaWeb =" + CR.getFlgRicercaWeb());
|
|
}
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public void findByDescrizione(String l_Descrizione) {
|
|
String s_Sql_Find = "select A.* from CARATTERISTICA AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.descrizione ='" + prepareSqlString(l_Descrizione) + "'");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
|
|
public Vectumerator findCaratteristicheByTipo(long l_id_tipo, int pageNumber, int pageRows) {
|
|
String s_Sql_Find = "select A.* from CARATTERISTICA AS A, C_TIPO as B, TIPO as C";
|
|
String s_Sql_Order = " order by A.ordine";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.id_caratteristica=B.id_caratteristica");
|
|
wc.addWc("B.id_tipo=C.id_tipo");
|
|
StringBuffer tipoWc = new StringBuffer("(");
|
|
Tipo tipo = new Tipo(getApFull());
|
|
tipo.findByPrimaryKey(l_id_tipo);
|
|
StringTokenizer st = new StringTokenizer("" + l_id_tipo + l_id_tipo, ":");
|
|
while (st.hasMoreTokens()) {
|
|
String currentId = st.nextToken();
|
|
if (tipoWc.length() > 1)
|
|
tipoWc.append(" or ");
|
|
tipoWc.append("B.id_tipo=" + currentId);
|
|
}
|
|
tipoWc.append(" )");
|
|
wc.addWc(tipoWc.toString());
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
|
|
return findRows(stmt, pageNumber, pageRows);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
return AB_EMPTY_VECTUMERATOR;
|
|
}
|
|
}
|
|
|
|
public Vectumerator findListe(int pageNumber, int pageRows) {
|
|
CaratteristicaCR CR = new CaratteristicaCR();
|
|
CR.setFlgTipoVal(6L);
|
|
return findByCR(CR, pageNumber, pageRows);
|
|
}
|
|
|
|
public long getFlgCR() {
|
|
return this.flgCR;
|
|
}
|
|
|
|
public void setFlgCR(long flgCR) {
|
|
this.flgCR = flgCR;
|
|
}
|
|
|
|
public long getOrdine() {
|
|
return this.ordine;
|
|
}
|
|
|
|
public void setOrdine(long ordine) {
|
|
this.ordine = ordine;
|
|
}
|
|
|
|
private long calcolaOrdine() {
|
|
try {
|
|
PreparedStatement ps = getConn()
|
|
.prepareStatement("select max(ordine) as _max from CARATTERISTICA WHERE id_caratteristica!=" + getId_caratteristica());
|
|
long res = (long)getMax(ps, true) + 1L;
|
|
long decine = res / 10L;
|
|
return (decine + 1L) * 10L;
|
|
} catch (Exception e) {
|
|
handleDebug(e);
|
|
return 0L;
|
|
}
|
|
}
|
|
|
|
protected void prepareSave(PreparedStatement ps) throws SQLException {
|
|
if (getOrdine() == 0L)
|
|
setOrdine(calcolaOrdine());
|
|
super.prepareSave(ps);
|
|
}
|
|
|
|
public String getDescrizioneAggiuntiva() {
|
|
return (this.descrizioneAggiuntiva == null) ? "" : this.descrizioneAggiuntiva;
|
|
}
|
|
|
|
public void setDescrizioneAggiuntiva(String descrizione_en) {
|
|
this.descrizioneAggiuntiva = descrizione_en;
|
|
}
|
|
|
|
public String getDescrizione_it() {
|
|
return getDescrizione("it");
|
|
}
|
|
|
|
public void setDescrizione_it(String descrizione) {
|
|
this.descrizione_it = descrizione;
|
|
}
|
|
|
|
public String getDescrizione() {
|
|
return getDescrizione("it");
|
|
}
|
|
|
|
public static final String getTipoVal(long l_flgTipoVal) {
|
|
if (l_flgTipoVal == 1L)
|
|
return "Intero";
|
|
if (l_flgTipoVal == 2L)
|
|
return "Double";
|
|
if (l_flgTipoVal == 3L)
|
|
return "Stringa";
|
|
if (l_flgTipoVal == 4L)
|
|
return "Booleano";
|
|
if (l_flgTipoVal == 5L)
|
|
return "Data";
|
|
if (l_flgTipoVal == 6L)
|
|
return "Lista";
|
|
return "??";
|
|
}
|
|
|
|
public long getFlgRicercaWeb() {
|
|
return this.flgRicercaWeb;
|
|
}
|
|
|
|
public void setFlgRicercaWeb(long flgRicercaWeb) {
|
|
this.flgRicercaWeb = flgRicercaWeb;
|
|
}
|
|
|
|
public boolean useDescLangTables() {
|
|
return true;
|
|
}
|
|
|
|
public String getDescrizione(String lang) {
|
|
if (lang.isEmpty())
|
|
lang = "it";
|
|
return getDescTxtLang("descrizione", lang);
|
|
}
|
|
|
|
public String getDescrizioneAggiuntiva(String lang) {
|
|
if (lang.isEmpty())
|
|
lang = "it";
|
|
return getDescTxtLang("descrizioneAggiuntiva", lang);
|
|
}
|
|
|
|
public String getDescrizioneTipoAssociati() {
|
|
if (getId_caratteristica() == 0L)
|
|
return "";
|
|
StringBuilder sb = new StringBuilder();
|
|
Vectumerator<CTipo> vec = new CTipo(getApFull()).findTipiByCaratteristica(getId_caratteristica(), 0, 0);
|
|
while (vec.hasMoreElements()) {
|
|
CTipo row = (CTipo)vec.nextElement();
|
|
sb.append(row.getTipo().getDescrizioneCompleta());
|
|
if (vec.hasMoreElements())
|
|
sb.append("\n");
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
public String getDescrizioneTipoAssociatiHtml() {
|
|
return DBAdapter.convertStringToHtml(getDescrizioneTipoAssociati(), true);
|
|
}
|
|
|
|
public String getOptionListaHtml(String lang) {
|
|
if (getFlgTipoVal() == 6L) {
|
|
if (lang == null || lang.isEmpty())
|
|
lang = "it";
|
|
Vectumerator<Lista> vec = new Lista(getApFull()).findLista(getId_caratteristica(), 0, 0);
|
|
StringBuilder sb = new StringBuilder();
|
|
while (vec.hasMoreElements()) {
|
|
Lista option = (Lista)vec.nextElement();
|
|
sb.append("<option value='");
|
|
sb.append(option.getId_lista());
|
|
sb.append("'>");
|
|
sb.append(option.getValore(lang));
|
|
sb.append("</option>");
|
|
}
|
|
return sb.toString();
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public String getIcecatDescs() {
|
|
return (this.icecatDescs == null) ? "" : this.icecatDescs.trim();
|
|
}
|
|
|
|
public void setIcecatDescs(String icecatDescs) {
|
|
this.icecatDescs = icecatDescs;
|
|
}
|
|
|
|
public void findByIcecatDesc(String l_icecatDesc) {
|
|
String s_Sql_Find = "select A.* from CARATTERISTICA AS A";
|
|
String s_Sql_Order = "";
|
|
WcString wc = new WcString();
|
|
wc.addWc("A.icecatDescs ='" + prepareSqlString(l_icecatDesc) + "'");
|
|
try {
|
|
PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + String.valueOf(wc));
|
|
findFirstRecord(stmt);
|
|
} catch (SQLException e) {
|
|
handleDebug(e);
|
|
}
|
|
}
|
|
}
|