diff --git a/at/at9300.cpp b/at/at9300.cpp index f36ab4a0a..30b7c8199 100755 --- a/at/at9300.cpp +++ b/at/at9300.cpp @@ -11,6 +11,7 @@ #include "at9.h" #include "at9300a.h" +#include "atlib.h" #include "soggetti.h" #include "donaz.h" @@ -38,13 +39,15 @@ class TProv2com: public TSkeleton_application TIsamtempfile* _fileben; TIsamtempfile* _filesto; TLocalisamfile* _soggetti; + TRecord_array* _sdonazioni; // sheet donazioni long _lastcod; protected: virtual bool create(void); virtual void main_loop(); virtual bool destroy(void) ; - void agg_anagrafica(const TRectype& recsog); + void agg_anagrafica(const TRectype& recsog, const bool aggiorna); + void agg_donazione(const TRectype& recsog, const TRectype& recdon); void transfer(); void print_line(const TString& message=""); @@ -63,12 +66,14 @@ bool TProv2com::create() _msk = new TMask("at9300a"); _configfile = new TConfig("at9300a.ini"); _soggetti = new TLocalisamfile(LF_SOGGETTI); + _sdonazioni = new TRecord_array(LF_DONAZ,DON_PROGDON); return TSkeleton_application::create(); } // distruzione dell'applicazione bool TProv2com::destroy() { + delete _sdonazioni; delete _soggetti; delete _configfile; delete _msk; @@ -123,33 +128,33 @@ void TProv2com::transfer() _fileben = new TIsamtempfile(LF_BENEM, (const char*) nomeben, FALSE); _filesto = new TIsamtempfile(LF_STORICO, (const char*) nomesto, FALSE); _rel = new TRelation(LF_SOGGETTI); - if (donazioni) - { - _rel->add(LF_DONAZ, "CODICE==CODICE"); - } - if (controlli) - { - _rel->add(LF_CONTSAN, "CODICE==CODICE"); - _rel->add(LF_IDONEITA, "CODICE==CODICE"); - } - if (benemerenze) - _rel->add(LF_BENEM, "CODICE==CODICE"); - if (storico) - _rel->add(LF_STORICO, "CODICE==CODICE"); - + _reltmp = new TRelation(LF_SOGGETTI); _reltmp->lfile().last(); _lastcod = _reltmp->lfile().get_long(SOG_CODICE); - //_reltmp->add(LF_DONAZ, "CODICE==CODICE"); - //_reltmp->add(LF_CONTSAN, "CODICE==CODICE"); - //_reltmp->add(LF_IDONEITA, "CODICE==CODICE"); - //_reltmp->add(LF_BENEM, "CODICE==CODICE"); - //_reltmp->add(LF_STORICO, "CODICE==CODICE"); - _reltmp->replace(_filesog); - - anagrafica = (anagrafica || donazioni || controlli || benemerenze || storico); + + _rel->add(LF_DONAZ, "CODICE==CODICE"); + _reltmp->add(LF_DONAZ, "CODICE==CODICE"); + _reltmp->replace(_filedon, 1); + + _rel->add(LF_CONTSAN, "CODICE==CODICE"); + _rel->add(LF_IDONEITA, "CODICE==CODICE"); + _reltmp->add(LF_CONTSAN, "CODICE==CODICE"); + _reltmp->add(LF_IDONEITA, "CODICE==CODICE"); + _reltmp->replace(_filecon, 2); + _reltmp->replace(_fileido, 3); + + _rel->add(LF_BENEM, "CODICE==CODICE"); + _reltmp->add(LF_BENEM, "CODICE==CODICE"); + _reltmp->replace(_fileben, 4); + + _rel->add(LF_STORICO, "CODICE==CODICE"); + _reltmp->add(LF_STORICO, "CODICE==CODICE"); + _reltmp->replace(_filesto, 5); + + //anagrafica = (anagrafica || donazioni || controlli || benemerenze || storico); TCursor cursore(_reltmp); long records = cursore.items(); TProgind pi(records,"Aggiornamento archivi", TRUE, TRUE); @@ -159,8 +164,7 @@ void TProv2com::transfer() const long codsog = cursore.curr().get_long(SOG_CODICE); pi.addstatus(1); if (pi.iscancelled()) break; - if (anagrafica) - agg_anagrafica(cursore.curr()); + agg_anagrafica(cursore.curr(), anagrafica); if (donazioni) { bool continua = TRUE; @@ -168,7 +172,7 @@ void TProv2com::transfer() { const long codice = cursore.curr(LF_DONAZ).get_long(DON_CODICE); if (codice == codsog) - //filedon.write(cursore.curr(LF_DONAZ)); + agg_donazione(cursore.curr(), cursore.curr(LF_DONAZ)); continua = cursore.next_match(LF_DONAZ, "CODICE"); } } @@ -225,7 +229,122 @@ void TProv2com::print_line(const TString& message) } -void TProv2com::agg_anagrafica(const TRectype& recsog) +void TProv2com::agg_anagrafica(const TRectype& recsog, const bool aggiorna) +{ + bool print_intest = FALSE; + TString intestazione = ""; + TString message = ""; + const TString80 cognome = recsog.get(SOG_COGNOME); + const TString80 nome = recsog.get(SOG_NOME); + const TDate datanasc = recsog.get_date(SOG_DATANASC); + _soggetti->setkey(2); + TRectype& rec = _rel->curr(); + rec.zero(); + rec.put(SOG_COGNOME, cognome); + rec.put(SOG_NOME, nome); + rec.put(SOG_DATANASC, datanasc); + intestazione = cognome; + intestazione << " "; + intestazione << nome; + intestazione << " "; + intestazione << datanasc.string(); + bool confronta = TRUE; + if (!aggiorna) + { + _soggetti->read(rec); + return; + } + if (_soggetti->read(rec)==NOERR) + { + TString16 catdon = recsog.get(SOG_CATDON); + TString16 catorig = rec.get(SOG_CATDON); + if (catdon == catorig) + { + const char xcatdon = _configfile->get(catdon, "CATDON")[0]; + if (xcatdon != X_SOS_CONAVVISO) + confronta = FALSE; + } + if (confronta) + { + for (int i=1;iget(campo, "SOGGETTI")[0]; + TString esterno = recsog.get(campo); + TString interno = rec.get(campo); + if (esterno != interno) + { + if (!print_intest) + { + print_line(); + print_line(intestazione); + print_intest = TRUE; + } + switch (operazione) + { + case X_SOS_CONAVVISO: + { + rec.put(campo, esterno); + message << campo; + message << " da "; + message << interno; + message << " a "; + message << esterno; + print_line(message); + } + break; + case X_SOS_NONAVVISO: + { + rec.put(campo, esterno); + } + break; + case X_INS_SEVUOTO: + { + if (interno.empty()) + rec.put(campo, esterno); + } + break; + case X_VIS_SEDIVERSO: + { + message << campo; + message << " originale "; + message << interno; + message << " aggiornamento "; + message << esterno; + print_line(message); + } + break; + case X_IGNORA: + default: + break; + } + } + } + } + _soggetti->rewrite(rec); + } + } + else + { + TString16 catdon = recsog.get(SOG_CATDON); + const char xcatdon = _configfile->get(catdon, "CATDON")[0]; + if (xcatdon == X_SOS_CONAVVISO) + { + _lastcod = _lastcod + 1; + rec = recsog; + rec.put(SOG_CODICE, _lastcod); + _soggetti->write(rec); + message << " INSERITO con codice "; + message << _lastcod; + print_line(message); + } + } +} + +void TProv2com::agg_donazione(const TRectype& recsog, const TRectype& recdon) { bool print_intest = FALSE; TString intestazione = ""; @@ -245,82 +364,36 @@ void TProv2com::agg_anagrafica(const TRectype& recsog) intestazione << " "; intestazione << datanasc.string(); if (_soggetti->read(rec)==NOERR) - { - for (int i=1;i dataultdon) + { + TRectype* key = new TRectype(LF_DONAZ); + key->put(DON_CODICE, rec.get(SOG_CODICE)); + int err = _sdonazioni->read(key); + if (err == NOERR) { - const char operazione = _configfile->get(campo, "SOGGETTI")[0]; - TString esterno = recsog.get(campo); - TString interno = rec.get(campo); - if (esterno != interno) - { - if (!print_intest) - { - print_line(); - print_line(intestazione); - print_intest = TRUE; - } - switch (operazione) - { - case X_SOS_CONAVVISO: - { - rec.put(campo, esterno); - message << campo; - message << " da "; - message << interno; - message << " a "; - message << esterno; - print_line(message); - } - break; - case X_SOS_NONAVVISO: - { - rec.put(campo, esterno); - } - break; - case X_INS_SEVUOTO: - { - if (interno.empty()) - rec.put(campo, esterno); - } - break; - case X_VIS_SEDIVERSO: - { - message << campo; - message << " originale "; - message << interno; - message << " aggiornamento "; - message << esterno; - print_line(message); - } - break; - case X_IGNORA: - default: - break; - } - } + TRectype recnew(recdon); + recnew.put(DON_CODICE, rec.get_long(SOG_CODICE)); + recnew.put(DON_PROGDON, _sdonazioni->rows()+1); + _sdonazioni->add_row(recnew); + _sdonazioni->rewrite(); + calcola_donazioni_lib(rec, _sdonazioni); + TDate oggi(TODAY); + rec.put(SOG_DATAULTAGG, oggi); + rec.put(SOG_UTENULTAGG, "PROV"); + _soggetti->rewrite(rec); + print_line(intestazione); + message = " INSERITA DONAZIONE in data "; + message << datadon.string(); + print_line(message); } } - } - else - { - TString16 catdon = recsog.get(SOG_CATDON); - const char xcatdon = _configfile->get(catdon, "CATDON")[0]; - if (xcatdon == X_SOS_CONAVVISO) - { - _lastcod = _lastcod + 1; - rec = recsog; - rec.put(SOG_CODICE, _lastcod); - _soggetti->write(rec); - message << " INSERITO "; - print_line(message); - } - } + } } + int at9300(int argc, char* argv[]) { TProv2com a;