diff --git a/ef/ef0100.cpp b/ef/ef0100.cpp index 658841585..6a5b97136 100755 --- a/ef/ef0100.cpp +++ b/ef/ef0100.cpp @@ -110,19 +110,17 @@ void TVariazione_effetti::common_f(const TMask& m) for (int i = 0; i < items; i++) { TToken_string& row = shcess.row(i); - if ( row.items()!= 0 ) - { - TRectype& rec = _effetto->row_c(ii+1, TRUE); - row.restart(); - rec.zero(); - rec.put(CES_NPROGTR, nprogtr); - rec.put(CES_NRIGA, ii+1); - rec.put(CES_RAGSOC, row.get()); - rec.put(CES_LOCALITA, row.get()); - rec.put(CES_STATO, row.get_int()); - rec.put(CES_COM, row.get()); - ii++; - } + if ( row.items()== 0 ) continue; + TRectype& rec = _effetto->row_c(ii+1, TRUE); + row.restart(); + rec.zero(); + rec.put(CES_NPROGTR, nprogtr); + rec.put(CES_NRIGA, ii+1); + rec.put(CES_RAGSOC, row.get()); + rec.put(CES_LOCALITA, row.get()); + rec.put(CES_STATO, row.get_int()); + rec.put(CES_COM, row.get()); + ii++; } items = shrighe.items(); diff --git a/ef/ef0101.cpp b/ef/ef0101.cpp index 6d72cdc0d..b0d63cf34 100755 --- a/ef/ef0101.cpp +++ b/ef/ef0101.cpp @@ -3,22 +3,6 @@ #include "cession.h" #include "ef0101.h" -///////////////////////////////////////////////////////////// -//////// Riga Effetto -///////////////////////////////////////////////////////////// -TRiga_effetto::TRiga_effetto(TEffetto* eff) - : TRectype(LF_REFFETTI), _eff(eff) -{ -} - -TRiga_effetto::TRiga_effetto(const TRiga_effetto& rec, TEffetto* eff) - : TRectype(rec), _eff(eff) -{ -} - -///////////////////////////////////////////////////////////// -////////// Effetto -///////////////////////////////////////////////////////////// TEffetto::TEffetto() : TRectype(LF_EFFETTI), _righe(LF_REFFETTI, "NRIGATR"), _cess(LF_CESS, "NRIGA") { @@ -30,13 +14,13 @@ TEffetto::TEffetto(TRectype& rec) read(rec); } -void TEffetto::set_key(TRectype& rec, long numeff) const +void TEffetto::put_key(TRectype& rec, long numeff) const { CHECKD(numeff >= 0, "Numero effetto non valido ", numeff); rec.put("NPROGTR",numeff); } -void TEffetto::set_key4(TRectype& rec,char tipodist, long ndist, long nrigadist) +void TEffetto::put_key(TRectype& rec,char tipodist, long ndist, long nrigadist) { CHECK(tipodist == 'I' || tipodist == 'S' || tipodist == 'B', "Tipo distinta"); CHECKD(ndist >= 0, "Numero distinta non valido ", ndist); @@ -54,7 +38,7 @@ long TEffetto::get_next_key(const long codcf) const { TLocalisamfile eff(LF_EFFETTI); TRectype& curr = eff.curr(); - set_key(curr, 9999999L); + put_key(curr, 9999999L); const int err = eff.read(_isgreat); @@ -84,17 +68,14 @@ long TEffetto::renum(long numeff) return numeff; } -int TEffetto::read(const TRectype& rec) -{ - head() = rec; - TRectype *k_reff = new TRectype(LF_REFFETTI), *k_cess= new TRectype(LF_CESS); +int TEffetto::read(TLocalisamfile &f, const TRectype& r) +{ + int err = TRectype::read(f); const long nu = numero(); - CHECK(nu > 0, "Numero effetto nullo."); - set_key(*k_reff, nu); - set_key(*k_cess, nu); - - TLocalisamfile eff(LF_EFFETTI); - int err = TRectype::read(eff); + TRectype *k_reff = new TRectype(LF_REFFETTI), + *k_cess = new TRectype(LF_CESS); + put_key(*k_reff, nu); + put_key(*k_cess, nu); if (err == NOERR) { _righe.read(k_reff); @@ -102,33 +83,51 @@ int TEffetto::read(const TRectype& rec) } else { - head() = rec; - destroy_rows_r(); - destroy_rows_c(); - _cess.set_key(k_cess); - _righe.set_key(k_reff); - } - return err; + head() = r; + const long nu = numero(); + put_key(*k_reff, nu); + put_key(*k_cess, nu); + if (nu !=0) + { + destroy_rows_r(); + destroy_rows_c(); + _cess.set_key(k_cess); + _righe.set_key(k_reff); + } + } + return err; +} + +int TEffetto::read(const TRectype& rec) +{ + TLocalisamfile eff(LF_EFFETTI); + head() = rec; + return read(eff, rec); } int TEffetto::read(char tipodist, long ndist, long nrigadist) -{ +{ + TLocalisamfile eff(LF_EFFETTI); + eff.setkey(4); TRectype rec(LF_EFFETTI); - set_key4(rec, tipodist,ndist, nrigadist); - return read(rec); + put_key(rec, tipodist,ndist, nrigadist); + head() = rec; + int err = read(eff, rec); + return err; } int TEffetto::write(bool force) { - const bool nuovo = numero() <= 0; // E' nuovo di zecca! + const bool nuovo = numero() <= 0; // E' nuovo! if (nuovo && force) // quindi ... force = FALSE; // ... non fare la rewrite TLocalisamfile eff(LF_EFFETTI); + eff.setkey(1); int err = NOERR; if (force) { - if ((err=_righe.write(force)) == NOERR) err = _cess.write(force); + if ((err=_righe.write(force)) == NOERR) err= _cess.write(force); if (err == NOERR) { err = TRectype::rewrite(eff); diff --git a/ef/ef0101.h b/ef/ef0101.h index 7124e187f..162038ee0 100755 --- a/ef/ef0101.h +++ b/ef/ef0101.h @@ -2,78 +2,57 @@ #include #endif -class TEffetto; - -///////////////////////////////////////////////// -// classe per gestire le righe di un effetto -//////////////////////////////////////////////// -class TRiga_effetto : public TRectype -{ - TEffetto * _eff; -protected: - TObject* dup() const // duplica l'oggetto corrente - { return new TRiga_effetto(*this); } -public: - int numeror() const // restituisce il numero della riga - { return get_int("NRIGATR");} - void set_numeror(int numero) // setta il valore del numero di riga con quello passato - { put("NRIGATR", numero);} - void set_eff(TEffetto * eff) // setta l'effetto con quello passato - { _eff = eff; } - const TEffetto & eff() const - { CHECK(_eff, "Effetto nullo"); return *_eff;} - TRiga_effetto(TEffetto* eff); - TRiga_effetto(const TRiga_effetto& rec, TEffetto* eff); - virtual ~TRiga_effetto() {} -}; - -///////////////////////////////////////////////// -// classe per gestire gli effetti -//////////////////////////////////////////////// class TEffetto:public TRectype { TRecord_array _righe,_cess; protected: - - long get_next_key(const long codcf) const; // ritorna la prossima chiave + // ritorna la prossima chiave + long get_next_key(const long codcf) const; + int read(TLocalisamfile& f, const TRectype& rec); -public: - long renum(long numeff = 0); // rinumera le chiavi - +public: + // rinumera le chiavi + long renum(long numeff = 0); + // ritorna la testata dell'effetto const TRectype& head() const - { return *this; } // Ritorna la testata dell'effetto + { return *this; } + // ritorna la testata dell'effetto TRectype& head() - { return *this; } - - TRecord_array& righe() {return _righe;} - TRecord_array& cess() {return _cess;} - TRectype& row_c(int i, bool create=FALSE) - { return _cess.row(i,create); } // ritorna la riga i dei cessionari - TRectype& row_r(int i, bool create=FALSE) - { return _righe.row(i,create); } // ritorna la riga i delle righe - - int rows_r() const // ritorna il numero delle righe presenti - { return _righe.rows(); } // nelle righe effetto - int rows_c() const // ritorna il numero delle righe presenti - { return _cess.rows(); } // nei cessionari - - bool destroy_row_r(int n, bool pack = FALSE) // elimina l'elemento riga nella posizione n - { return _righe.destroy_row(n, pack); } // nelle righe effetto - void destroy_rows_r() // elimina tutti gli elementi riga - { _righe.destroy_rows(); } // nelle righe effetto - - bool destroy_row_c(int n, bool pack = FALSE) // elimina l'elemento riga nella posizione n - { return _cess.destroy_row(n, pack); } // nei cessionari - void destroy_rows_c() // elimina tutti gli elementi riga - { _cess.destroy_rows(); } // nei cessionari + { return *this; } + TRecord_array& righe() {return _righe;} + TRecord_array& cess() {return _cess;} + // ritorna la riga i_esima dei cessionari + TRectype& row_c(int i, bool create=FALSE) + { return _cess.row(i,create); } + // ritorna la riga i delle righe + TRectype& row_r(int i, bool create=FALSE) + { return _righe.row(i,create); } + // ritorna il numero delle righe presenti nelle righe effetto + int rows_r() const + { return _righe.rows(); } + // ritorna il numero delle righe presenti nei cessionari + int rows_c() const + { return _cess.rows(); } + // elimina l'elemento riga nella posizione n nelle righe effetto + bool destroy_row_r(int n, bool pack = FALSE) + { return _righe.destroy_row(n, pack); } + // elimina tutti gli elementi riga nelle righe effetto + void destroy_rows_r() + { _righe.destroy_rows(); } + // elimina l'elemento riga nella posizione n nei cessionari + bool destroy_row_c(int n, bool pack = FALSE) + { return _cess.destroy_row(n, pack); } + // elimina tutti gli elementi riga nei cessionari + void destroy_rows_c() + { _cess.destroy_rows(); } int read(const TRectype& rec); int read(char tipodist, long ndist, long nrigadist); int write(bool force=FALSE); int rewrite() { return write(TRUE); } int remove()const; - long numero() const // metodi per ritornare i campi chiave - { return get_long("NPROGTR"); } // del file EFFETTI + long numero() const + { return get_long("NPROGTR"); } long codicec() const { return get_long("CODCF"); } TDate datasc() const @@ -83,9 +62,12 @@ public: long ndist() const { return get_long("NDIST"); } long nrgdist() const - { return get_long("NRIGADIST"); } - void set_key4(TRectype& rec,char tipodist, long ndist, long nrigadist); //setta i campi per la quarta chiave del file - void set_key(TRectype& rec,long numeff) const; //setta i campi per la chiave + { return get_long("NRIGADIST"); } + //setta i campi per la quarta chiave del file + void put_key(TRectype& rec,char tipodist, long ndist, long nrigadist = 0); + //setta i campi per la prima chiave del file + void put_key(TRectype& rec,long numeff) const; + TEffetto(); TEffetto(TRectype& rec); virtual ~TEffetto() {}