package it.acxent.tarop; import it.acxent.db.ApplParmFull; import it.acxent.db.DBAdapter; 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.net.URLEncoder; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.SQLException; public class Tariffa extends DBAdapter implements Serializable { private long id_tariffa; private long flgFM; private long flgPA; private long flgAR; private long flgTablet; private String descrizione; private String titolo; private String sottotitolo; private String costo; private String costoScontato; private String descrizioneSconto; private Date dataScadenza; public Tariffa(ApplParmFull newApplParmFull) { super(newApplParmFull); } public Tariffa() {} public void setId_tariffa(long newId_tipoTariffa) { this.id_tariffa = newId_tipoTariffa; } public void setFlgFM(long newFlgFM) { this.flgFM = newFlgFM; } public void setFlgPA(long newFlgPA) { this.flgPA = newFlgPA; } public void setFlgAR(long newFlgAR) { this.flgAR = newFlgAR; } public void setFlgTablet(long newFlgTablet) { this.flgTablet = newFlgTablet; } public void setDescrizione(String newDescrizione) { this.descrizione = newDescrizione; } public void setTitolo(String newTitolo) { this.titolo = newTitolo; } public void setSottotitolo(String newSottotitolo) { this.sottotitolo = newSottotitolo; } public void setCosto(String newCosto) { this.costo = newCosto; } public void setCostoScontato(String newCostoScontato) { this.costoScontato = newCostoScontato; } public void setDescrizioneSconto(String newDescrizioneSconto) { this.descrizioneSconto = newDescrizioneSconto; } public void setDataScadenza(Date newDataScadenza) { this.dataScadenza = newDataScadenza; } public long getId_tariffa() { return this.id_tariffa; } public long getFlgFM() { return this.flgFM; } public long getFlgPA() { return this.flgPA; } public long getFlgAR() { return this.flgAR; } public long getFlgTablet() { return this.flgTablet; } public String getDescrizione() { return (this.descrizione == null) ? "" : this.descrizione.trim(); } public String getTitolo() { return (this.titolo == null) ? "" : this.titolo.trim(); } public String getSottotitolo() { return (this.sottotitolo == null) ? "" : this.sottotitolo.trim(); } public String getCosto() { return (this.costo == null) ? "" : this.costo.trim(); } public String getCostoScontato() { return (this.costoScontato == null) ? "" : this.costoScontato.trim(); } public String getDescrizioneSconto() { return (this.descrizioneSconto == null) ? "" : this.descrizioneSconto.trim(); } public Date getDataScadenza() { return this.dataScadenza; } protected ResParm checkDeleteCascade() { return new ResParm(true); } protected void deleteCascade() {} public Vectumerator getOpzioni(int pageNumber, int pageRows) { OpzioneCR CR = new OpzioneCR(); CR.setFlgAR(getFlgAR()); CR.setFlgFM(getFlgFM()); CR.setFlgPA(getFlgPA()); return new Opzione(getApFull()).findWebByCR(CR, 0, 0); } public static String getAR(long l_flgAR) { if (l_flgAR == 0L) return "Abbonamento"; if (l_flgAR == 1L) return "Ricaricabile"; if (l_flgAR == 2L) return "Abb. e Ric."; return "??"; } public static String getPA(long l_flgPA) { if (l_flgPA == 0L) return "Privati"; if (l_flgPA == 1L) return "Aziende"; return "??"; } public String getAR() { return getAR(getFlgAR()); } public String getFM() { return getFM(getFlgFM()); } public String getPA() { return getPA(getFlgPA()); } public Vectumerator findWebByCR(TariffaCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from TARIFFA 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.titolo like '%" + token + "%' or A.sottoTitolo like '%" + token + "%')"); if (st.hasMoreTokens()) txt.append(" and "); } txt.append(")"); wc.addWc(txt.toString()); } if (CR.getFlgAR() == 0L) { wc.addWc("(A.flgAR is null or A.flgAR=0 or A.flgAR=2)"); } else if (CR.getFlgAR() == 1L) { wc.addWc("(A.flgAR =1 or A.flgAR=2)"); } if (CR.getFlgFM() == 0L) { wc.addWc("(A.flgFM is null or A.flgFM=0)"); } else if (CR.getFlgFM() > 0L) { wc.addWc("A.flgFM =" + CR.getFlgFM()); } if (CR.getFlgPA() == 0L) { wc.addWc("(A.flgPA is null or A.flgPA=0)"); } else if (CR.getFlgPA() > 0L) { wc.addWc("A.flgPA =" + CR.getFlgPA()); } 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 String getTitoloUrl() { try { return URLEncoder.encode(getTitolo().replace("/", "-"), "utf-8"); } catch (Exception e) { return getTitolo(); } } public Vectumerator findByCR(TariffaCR CR, int pageNumber, int pageRows) { String s_Sql_Find = "select A.* from TARIFFA AS A"; String s_Sql_Order = ""; WcString wc = new WcString(); if (CR.getFlgAR() == 0L) { wc.addWc("(A.flgAR is null or A.flgAR=0)"); } else if (CR.getFlgAR() > 0L) { wc.addWc("A.flgAR =" + CR.getFlgAR()); } if (CR.getFlgFM() == 0L) { wc.addWc("(A.flgFM is null or A.flgFM=0)"); } else if (CR.getFlgFM() > 0L) { wc.addWc("A.flgFM =" + CR.getFlgFM()); } if (CR.getFlgPA() == 0L) { wc.addWc("(A.flgPA is null or A.flgPA=0)"); } else if (CR.getFlgPA() > 0L) { wc.addWc("A.flgPA =" + CR.getFlgPA()); } if (CR.getDataScadenzaDa() != null) wc.addWc("A.dataScadenza>=?"); if (CR.getDataScadenzaA() != null) wc.addWc("A.dataScadenza<=?"); try { PreparedStatement stmt = getConn().prepareStatement(s_Sql_Find + s_Sql_Find + wc.toString()); int dataCount = 0; if (CR.getDataScadenzaDa() != null) { dataCount++; stmt.setDate(dataCount, CR.getDataScadenzaDa()); } if (CR.getDataScadenzaA() != null) { dataCount++; stmt.setDate(dataCount, CR.getDataScadenzaA()); } return findRows(stmt, pageNumber, pageRows); } catch (SQLException e) { removeCPConnection(); handleDebug(e); return AB_EMPTY_VECTUMERATOR; } } public static String getFM(long l_flgFM) { if (l_flgFM == 0L) return "Mobile"; if (l_flgFM == 1L) return "Fisso solo tel."; if (l_flgFM == 2L) return "Fisso tel+internet"; if (l_flgFM == 3L) return "Internet e Tablet"; return "??"; } }