package it.acxent.art; import it.acxent.db.ApplParmFull; import it.acxent.db.WcString; import it.acxent.util.StringTokenizer; import it.acxent.util.Vectumerator; import java.io.File; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.SQLException; public class AllegatoArticolo extends _ArtAdapter implements Serializable { private long id_allegatoArticolo; private String nomeFile; private long id_articolo; private Articolo articolo; private long id_tipoAllegatoArticolo; private TipoAllegatoArticolo tipoAllegatoArticolo; private String descrizioneAllegato; public AllegatoArticolo(ApplParmFull newApplParmFull) { super(newApplParmFull); } public AllegatoArticolo() {} public void setId_allegatoArticolo(long newId_allegato) { this.id_allegatoArticolo = newId_allegato; } public void setNomeFile(String newNomeFile) { this.nomeFile = newNomeFile; } public void setId_articolo(long newId_articolo) { this.id_articolo = newId_articolo; setArticolo(null); } public long getId_allegatoArticolo() { return this.id_allegatoArticolo; } public String getNomeFile() { return (this.nomeFile == null) ? "" : this.nomeFile; } public long getId_articolo() { return this.id_articolo; } public void setArticolo(Articolo newArticolo) { this.articolo = newArticolo; } public Articolo getArticolo() { this.articolo = (Articolo)getSecondaryObject(this.articolo, Articolo.class, getId_articolo()); return this.articolo; } protected void deleteCascade() { new File(getNomeFileCompleto()).delete(); } public Vectumerator findByCR(AllegatoArticoloCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from ALLEGATO_ARTICOLO 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) { handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public Vectumerator findByArticoloTipo(long l_id_articolo, long l_id_tipoAllegatoDocumento, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from ALLEGATO_ARTICOLO AS A"; String s_Sql_Order = " order by A.nomeFile"; WcString wc = new WcString(); wc.addWc("A.id_articolo=" + l_id_articolo); if (l_id_tipoAllegatoDocumento > 0L) wc.addWc("A.id_tipoAllegatoDocumento=" + l_id_tipoAllegatoDocumento); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); return findRows(stmt, pageNumber, pageRows); } catch (SQLException e) { handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public void findByArticoloNomeFile(long l_id_articolo, String l_id_nomeFile) { String s_Sql_Find = "select A.* from ALLEGATO_ARTICOLO AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); wc.addWc("A.id_articolo=" + l_id_articolo); wc.addWc("A.nomeFile='" + l_id_nomeFile + "'"); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); findFirstRecord(stmt); } catch (SQLException e) { handleDebug(e); } } public String getNomeFileCompleto() { return getNomeFileCompleto(getArticolo().getPathAllegato()); } public String getNomeFileCompleto(String l_path) { return l_path + l_path + "_" + getId_articolo(); } public long getId_tipoAllegatoArticolo() { return this.id_tipoAllegatoArticolo; } public TipoAllegatoArticolo getTipoAllegatoArticolo() { this.tipoAllegatoArticolo = (TipoAllegatoArticolo)getSecondaryObject(this.tipoAllegatoArticolo, TipoAllegatoArticolo.class, getId_tipoAllegatoArticolo()); return this.tipoAllegatoArticolo; } public void setId_tipoAllegatoArticolo(long newId_tipoAllegatoArticolo) { this.id_tipoAllegatoArticolo = newId_tipoAllegatoArticolo; setTipoAllegatoArticolo(null); } public void setTipoAllegatoArticolo(TipoAllegatoArticolo newTipoAllegatoArticolo) { this.tipoAllegatoArticolo = newTipoAllegatoArticolo; } public String getNomeFileSuDisco() { return "" + getId_articolo() + "_" + getId_articolo(); } public String getDescrizioneAllegato() { return (this.descrizioneAllegato == null) ? "" : this.descrizioneAllegato; } public void setDescrizioneAllegato(String descrizioneAllegato) { this.descrizioneAllegato = descrizioneAllegato; } protected int getStringValueCase(String l_colomnName) { return 0; } }