797e8900fb
Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 873 git-svn-id: svn://10.65.10.50/trunk@15151 c028cbd2-c16b-5b4b-a496-9718f37d4682
1763 lines
50 KiB
C++
Executable File
1763 lines
50 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <filetext.h>
|
||
#include <mask.h>
|
||
#include <tabutil.h>
|
||
|
||
#include "at8.h"
|
||
#include "at8900a.h"
|
||
#include "atlib.h"
|
||
|
||
#include "contsan.h"
|
||
#include "donaz.h"
|
||
#include "idoneita.h"
|
||
#include "soggetti.h"
|
||
#include "convoc.h"
|
||
#include "rconvoc.h"
|
||
#include "storico.h"
|
||
#include "comuni.h"
|
||
#include "medici.h"
|
||
|
||
////////////////////////////////////////////////////////
|
||
// Classe TCtpr2at_file customizzata dalla TFile_text //
|
||
////////////////////////////////////////////////////////
|
||
|
||
/////////////////////////////////////////////////////
|
||
// Classe TCtpr2at: applicazione principale //
|
||
/////////////////////////////////////////////////////
|
||
|
||
class TCtpr2at: public TSkeleton_application
|
||
{
|
||
TMask* _msk;
|
||
TRelation* _rel;
|
||
TRelation* _relcom;
|
||
TLocalisamfile* _soggetti;
|
||
TLocalisamfile* _donaz;
|
||
TLocalisamfile* _contsan;
|
||
TLocalisamfile* _idoneita;
|
||
TRecord_array* _sdonazioni;
|
||
TRecord_array* _scontrolli;
|
||
TRecord_array* _sidoneita;
|
||
TAssoc_array* _array_comuni;
|
||
TAssoc_array* _array_donaz;
|
||
TAssoc_array* _array_sospesi;
|
||
|
||
int _numdon1, _numdon2;
|
||
TString4 _catini1, _catfin1, _catini2, _catfin2;
|
||
bool _sttess2, _dataisc;
|
||
TConfig* _configfile;
|
||
|
||
TDate _dataagg;
|
||
long _progins;
|
||
bool _message;
|
||
TString80 _intestazione;
|
||
|
||
protected:
|
||
virtual bool create(void);
|
||
virtual void main_loop();
|
||
virtual bool destroy(void) ;
|
||
void transfer();
|
||
void transfer_file(const bool prima = TRUE);
|
||
static bool annulla_handler(TMask_field& f, KEY k);
|
||
bool test_donation(TRectype& recsog, const char* tipo, const TDate& datadon, const TString& luogodon);
|
||
void calcola_categoria(TRectype& recsog);
|
||
bool print_header();
|
||
void print_line(const TString& rigastampa = "");
|
||
void print_footer();
|
||
bool build_record(TAssoc_array& record, const TString& istruzione);
|
||
bool update_record(TRectype& recsog, TAssoc_array& record);
|
||
bool soggetto(const TString& istruzione);
|
||
bool accesso(const TString& istruzione);
|
||
bool sacca(const TString& istruzione);
|
||
bool analisi(const TString& istruzione);
|
||
bool intervalli(const TString& istruzione);
|
||
bool esclusione(const TString& istruzione);
|
||
long get_next_key();
|
||
public:
|
||
const TMask& msk() const { return *_msk; }
|
||
TCtpr2at() {}
|
||
virtual ~TCtpr2at() {}
|
||
};
|
||
|
||
// restituisce un riferimento all' applicazione
|
||
inline TCtpr2at& app() { return (TCtpr2at&) main_app();}
|
||
|
||
// creazione dell'applicazione
|
||
bool TCtpr2at::create()
|
||
{
|
||
open_files(LF_SOGGETTI, LF_DONAZ, LF_CONTSAN, LF_IDONEITA, LF_CONVOC, LF_RCONVOC, LF_STORICO, 0);
|
||
_msk = new TMask("at8900a");
|
||
_rel = new TRelation(LF_SOGGETTI);
|
||
_relcom = new TRelation(LF_COMUNI);
|
||
_donaz = new TLocalisamfile(LF_DONAZ);
|
||
_contsan = new TLocalisamfile(LF_CONTSAN);
|
||
_idoneita = new TLocalisamfile(LF_IDONEITA);
|
||
_sdonazioni = new TRecord_array(LF_DONAZ,DON_PROGDON);
|
||
_scontrolli = new TRecord_array(LF_CONTSAN,CON_PROGCON);
|
||
_sidoneita = new TRecord_array(LF_IDONEITA,IDO_PROGIDO);
|
||
_array_comuni = new TAssoc_array();
|
||
_array_donaz = new TAssoc_array();
|
||
_array_sospesi = new TAssoc_array();
|
||
TConfig config(CONFIG_STUDIO);
|
||
_numdon1 = config.get_int("NumDon1");
|
||
_numdon2 = config.get_int("NumDon2");
|
||
_catini1 = config.get("CatIni1");
|
||
_catfin1 = config.get("CatFin1");
|
||
_catini2 = config.get("CatIni2");
|
||
_catfin2 = config.get("CatFin2");
|
||
_sttess2 = config.get_bool("StTess2");
|
||
_dataisc = config.get_bool("DataIsc");
|
||
_configfile = new TConfig("at8900a.ini");
|
||
_donaz->setkey(3);
|
||
_donaz->last();
|
||
_progins = _donaz->get_long(DON_PROGINS);
|
||
_donaz->setkey(1);
|
||
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
// distruzione dell'applicazione
|
||
bool TCtpr2at::destroy()
|
||
{
|
||
delete _array_sospesi;
|
||
delete _array_donaz;
|
||
delete _array_comuni;
|
||
delete _sidoneita;
|
||
delete _scontrolli;
|
||
delete _sdonazioni;
|
||
delete _idoneita;
|
||
delete _contsan;
|
||
delete _donaz;
|
||
delete _rel;
|
||
delete _msk;
|
||
delete _configfile;
|
||
return TSkeleton_application::destroy();
|
||
}
|
||
|
||
// carica la maschera
|
||
void TCtpr2at::main_loop()
|
||
{
|
||
_intestazione = "";
|
||
_message = FALSE;
|
||
_msk->set(F_FILENAME,_configfile->get("PERCORSO", "ARCHIVIO"));
|
||
KEY key = _msk->run();
|
||
if (key == K_ENTER)
|
||
{
|
||
transfer();
|
||
_configfile->set("PERCORSO", _msk->get(F_FILENAME), "ARCHIVIO");
|
||
}
|
||
}
|
||
|
||
void TCtpr2at::calcola_categoria(TRectype& recsog)
|
||
{
|
||
TString256 stampa;
|
||
TTable ctd("CTD");
|
||
TString4 catdon = recsog.get(SOG_CATDON);
|
||
const int totdon = recsog.get_int(SOG_TOTDON);
|
||
ctd.put("CODTAB",catdon);
|
||
if (ctd.read() == NOERR)
|
||
{
|
||
bool dimissione = ctd.get_bool("B0");
|
||
if (dimissione)
|
||
{
|
||
const TString& cat_coll = ctd.get("S6");
|
||
if (cat_coll.not_empty())
|
||
{
|
||
stampa = "Il soggetto <20> dimesso, non effettuato cambio di categoria ";
|
||
stampa << cat_coll;
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if ((catdon == _catini1 || _catini1.empty()) && (totdon>=_numdon1) && _catfin1.not_empty())
|
||
{
|
||
recsog.put(SOG_CATDON, _catfin1);
|
||
catdon = _catfin1;
|
||
}
|
||
bool tstampata = recsog.get_bool(SOG_T_STAMPATA);
|
||
if ((catdon == _catini2 || _catini2.empty()) && (totdon>=_numdon2) && _catfin2.not_empty() && (!_sttess2 || tstampata))
|
||
{
|
||
recsog.put(SOG_CATDON, _catfin2);
|
||
catdon = _catfin2;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
bool TCtpr2at::print_header()
|
||
{
|
||
if (printer().open())
|
||
{
|
||
TDate oggi(TODAY);
|
||
TPrintrow row;
|
||
TString256 rigastampa;
|
||
rigastampa = "TRASFERIMENTO DATI DA CETRAPLUS";
|
||
rigastampa.center_just(132);
|
||
row.put(rigastampa);
|
||
row.put("@>", 1);
|
||
row.put("Pag. @#", 115);
|
||
printer().setheaderline(2, row);
|
||
rigastampa = "";
|
||
rigastampa.fill('-',132);
|
||
row.reset();
|
||
row.put(rigastampa);
|
||
printer().setheaderline(3, row);
|
||
return TRUE;
|
||
}
|
||
else
|
||
return error_box("Errore in apertura stampante.");
|
||
}
|
||
|
||
void TCtpr2at::print_line(const TString& rigastampa)
|
||
{
|
||
TPrintrow row;
|
||
row.reset();
|
||
if (rigastampa.not_empty())
|
||
if (_intestazione.not_empty())
|
||
{
|
||
printer().print(row);
|
||
row.reset();
|
||
row.put((const char*) _intestazione);
|
||
printer().print(row);
|
||
_intestazione = "";
|
||
row.reset();
|
||
}
|
||
row.put((const char*) rigastampa);
|
||
printer().print(row);
|
||
}
|
||
|
||
void TCtpr2at::print_footer()
|
||
{
|
||
printer().formfeed();
|
||
printer().close();
|
||
}
|
||
|
||
void TCtpr2at::transfer_file(const bool prima)
|
||
{
|
||
_dataagg = TODAY;
|
||
TString256 rigastampa;
|
||
TScanner s(_msk->get(F_FILENAME));
|
||
TString16 key, archivio;
|
||
TString istruzione;
|
||
while (s.ok())
|
||
{
|
||
const TString& line = s.line();
|
||
if (line.find("UPDATE") != -1)
|
||
istruzione = line;
|
||
else
|
||
{
|
||
if (line.find("INSERT") == -1)
|
||
istruzione << line;
|
||
if (istruzione.not_empty())
|
||
{
|
||
TToken_string* record = new TToken_string(istruzione);
|
||
archivio = record->get(0);
|
||
archivio.trim(); archivio.upper();
|
||
int n = _configfile->get_int(archivio, "ARCHIVIO");
|
||
_configfile->set_paragraph(archivio);
|
||
if (prima)
|
||
{
|
||
switch (n)
|
||
{
|
||
case 1:
|
||
soggetto(record->get(1));
|
||
break;
|
||
case 2:
|
||
sacca(record->get(1));
|
||
break;
|
||
case 4:
|
||
intervalli(record->get(1));
|
||
break;
|
||
case 5:
|
||
esclusione(record->get(1));
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
switch (n)
|
||
{
|
||
case 3:
|
||
analisi(record->get(1));
|
||
break;
|
||
case 6:
|
||
accesso(record->get(1));
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
istruzione = "";
|
||
}
|
||
}
|
||
}
|
||
s.close();
|
||
}
|
||
|
||
|
||
// trasferimento dati da file CT su programma avis
|
||
void TCtpr2at::transfer()
|
||
{
|
||
if (print_header())
|
||
{
|
||
transfer_file();
|
||
transfer_file(FALSE);
|
||
print_footer();
|
||
}
|
||
else
|
||
error_box("Errore in apertura stampante.");
|
||
}
|
||
|
||
bool TCtpr2at::build_record(TAssoc_array& record, const TString& istruzione)
|
||
{
|
||
bool ok = TRUE;
|
||
record.destroy();
|
||
TString lavoro = istruzione;
|
||
TString80 campo;
|
||
TString valore;
|
||
int indice1 = lavoro.find(" SET ");
|
||
int indice2 = lavoro.find(" WHERE ");
|
||
if ((indice1 != -1) && (indice2 != -1))
|
||
{
|
||
lavoro = lavoro.sub(indice1+5,indice2);
|
||
lavoro.trim();
|
||
int i = lavoro.find("''");
|
||
if (i != -1)
|
||
{
|
||
TString aiuto = lavoro.sub(0,i);
|
||
aiuto << '~';
|
||
aiuto << lavoro.sub(i+2);
|
||
lavoro = aiuto;
|
||
}
|
||
while (lavoro.not_empty())
|
||
{
|
||
indice1 = lavoro.find('=');
|
||
if (indice1 != -1)
|
||
{
|
||
campo = lavoro.sub(0, indice1-1);
|
||
campo.trim();
|
||
lavoro = lavoro.sub(indice1+1);
|
||
lavoro.trim();
|
||
indice1 = lavoro.find(',');
|
||
if (indice1 != -1)
|
||
{
|
||
valore = lavoro.sub(0,indice1);
|
||
valore.trim();
|
||
if ((valore[0] == '\'') && (valore[valore.len()-1] == '\''))
|
||
{
|
||
// e' una stringa: tolgo le virgolette
|
||
valore = valore.sub(1,valore.len()-1);
|
||
lavoro = lavoro.sub(indice1+1);
|
||
}
|
||
else
|
||
{
|
||
if ((valore[0] != '\'') && (valore[valore.len()-1] != '\''))
|
||
// e' un numero oppure null (in questo caso vuoto il valore
|
||
{
|
||
if (valore == "null")
|
||
valore = "";
|
||
lavoro = lavoro.sub(indice1+1);
|
||
}
|
||
else
|
||
// e' una stringa dove c'<27> una virgola, quindi elaboro diversamente per trovare il vero valore
|
||
{
|
||
indice1 = lavoro.find("\',");
|
||
indice2 = lavoro.find("\' ,");
|
||
if (indice1 != 1 && indice2 != -1)
|
||
{
|
||
if (indice2 > indice1)
|
||
{
|
||
valore = lavoro.sub(0,indice1+1);
|
||
lavoro = lavoro.sub(indice1+2);
|
||
}
|
||
else
|
||
{
|
||
valore = lavoro.sub(0,indice2+1);
|
||
lavoro = lavoro.sub(indice2+3);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (indice1 != 0)
|
||
{
|
||
valore = lavoro.sub(0,indice1+1);
|
||
lavoro = lavoro.sub(indice1+2);
|
||
}
|
||
else
|
||
{
|
||
if (indice2 != 0)
|
||
{
|
||
valore = lavoro.sub(0,indice2-1);
|
||
lavoro = lavoro.sub(indice2+3);
|
||
}
|
||
else
|
||
{
|
||
// e' l'ultimo campo della lista, quindi non trova la virgola
|
||
valore = lavoro.trim();
|
||
lavoro = "";
|
||
}
|
||
}
|
||
}
|
||
valore = valore.sub(1,valore.len()-1);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
valore = lavoro.trim();
|
||
lavoro = "";
|
||
}
|
||
}
|
||
else
|
||
lavoro = "";
|
||
if ((valore[0] == '\'') && (valore[valore.len()-1] == '\''))
|
||
// e' una stringa: tolgo le virgolette
|
||
valore = valore.sub(1,valore.len()-1);
|
||
else if (valore == "null")
|
||
valore = "";
|
||
campo.upper();
|
||
int doppie = valore.find("'");
|
||
while (doppie != -1)
|
||
{
|
||
if (valore[doppie+1] == '\'')
|
||
{
|
||
TString str = valore;
|
||
valore = str.sub(0,doppie);
|
||
valore << str.sub(doppie+1);
|
||
}
|
||
doppie = valore.find("'", doppie+1);
|
||
}
|
||
i = valore.find('~');
|
||
if (i != -1)
|
||
valore.replace('~','\'');
|
||
record.add(campo, valore);
|
||
}
|
||
}
|
||
else
|
||
ok = FALSE;
|
||
return ok;
|
||
}
|
||
|
||
bool TCtpr2at::soggetto(const TString& istruzione)
|
||
{
|
||
const TDate oggi(TODAY);
|
||
int error = NOERR;
|
||
TAssoc_array record;
|
||
if (build_record(record, istruzione))
|
||
{
|
||
// ricerca del soggetto per cognome, nome e data di nascita
|
||
TString80& cognome = (TString80&) record["COGNOME"];
|
||
TString80& nome = (TString80&) record["NOME"];
|
||
TString16& str = (TString16&) record["DT_NASCITA"];
|
||
TDate datanasc = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
// codice centro trasfusionale per verifica cognome, nome, data di nascita
|
||
TString16& codct = (TString16&) record["ID_ANAGRAFICA"];
|
||
|
||
_rel->lfile().setkey(2);
|
||
TRectype& recsog = _rel->curr();
|
||
recsog.zero();
|
||
recsog.put(SOG_COGNOME, cognome);
|
||
recsog.put(SOG_NOME, nome);
|
||
recsog.put(SOG_DATANASC, datanasc);
|
||
error = recsog.read(_rel->lfile());
|
||
TString80 stampa = "";
|
||
_intestazione = "";
|
||
_intestazione << cognome << " " << nome << " " << datanasc;
|
||
if (error != NOERR)
|
||
{
|
||
// non ho trovato il donatore, cerco per cognome nome e codicesit
|
||
recsog.zero();
|
||
recsog.put(SOG_COGNOME, cognome);
|
||
recsog.put(SOG_NOME, nome);
|
||
error = recsog.read(_rel->lfile());
|
||
bool trovato = FALSE;
|
||
while ((!trovato) && (cognome == recsog.get(SOG_COGNOME)) && (nome == recsog.get(SOG_NOME)) && (!_rel->lfile().eof()))
|
||
{
|
||
TString16 codicesit = recsog.get(SOG_CODCT);
|
||
if ((codicesit == codct) && (codicesit.not_empty()) && codct.not_empty())
|
||
{
|
||
datanasc = recsog.get_date(SOG_DATANASC);
|
||
trovato = TRUE;
|
||
}
|
||
else
|
||
_rel->lfile().next();
|
||
}
|
||
if (trovato)
|
||
{
|
||
recsog.put(SOG_COGNOME, cognome);
|
||
recsog.put(SOG_NOME, nome);
|
||
recsog.put(SOG_DATANASC, datanasc);
|
||
error = recsog.read(_rel->lfile());
|
||
if (error == NOERR)
|
||
{
|
||
stampa = "Verificare la data di nascita: AVIS ";
|
||
stampa << datanasc;
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
}
|
||
if (error != NOERR)
|
||
{
|
||
bool inserisci = TRUE;
|
||
const long eta = oggi - datanasc;
|
||
if (eta > 71)
|
||
{
|
||
const TString16& stato = (TString16&) record["DT_NASCITA"];
|
||
TRectype recpr1 = cache().get("PR1", stato);
|
||
TString16 catdon = recpr1.get("S6");
|
||
if (catdon.not_empty())
|
||
inserisci = !(cache().get("CTD", catdon).get_bool("B0"));
|
||
}
|
||
if (inserisci)
|
||
{
|
||
recsog.zero();
|
||
recsog.put(SOG_COGNOME, cognome);
|
||
recsog.put(SOG_NOME, nome);
|
||
recsog.put(SOG_DATANASC, datanasc);
|
||
recsog.put(SOG_NOTIZIARIO, 'X');
|
||
recsog.put(SOG_BENEM, 'X');
|
||
recsog.put(SOG_CODICE, get_next_key());
|
||
error = recsog.write(_rel->lfile());
|
||
stampa = "Inserito da CETRAPLUS";
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
if (error == NOERR)
|
||
{
|
||
if (update_record(recsog, record))
|
||
{
|
||
recsog.put(SOG_DATAULTAGG, oggi);
|
||
recsog.put(SOG_UTENULTAGG, "CETRAPLUS");
|
||
error = recsog.rewrite(_rel->lfile());
|
||
}
|
||
}
|
||
return (error == NOERR);
|
||
}
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
bool TCtpr2at::update_record(TRectype& record_at, TAssoc_array& record_ct)
|
||
{
|
||
TString256 stampa = "";
|
||
TString field, str;
|
||
bool update = FALSE;
|
||
FOR_EACH_ASSOC_STRING(record_ct, obj, key, val)
|
||
{
|
||
field = _configfile->get(key);
|
||
if (field.not_empty())
|
||
{
|
||
update = TRUE;
|
||
if (field.sub(0,2) == "!_")
|
||
{
|
||
TString80 elab = field.sub(2);
|
||
TString16 campo = "";
|
||
const int virgola = elab.find(',');
|
||
if (virgola != -1)
|
||
{
|
||
campo = elab.sub(virgola+1);
|
||
elab = elab.sub(0,virgola);
|
||
}
|
||
if (elab == "STATO") // stato sanitario
|
||
{
|
||
TRectype recpr1 = cache().get("PR1", val);
|
||
TString16 catdon = recpr1.get("S6");
|
||
TString16 catsog = record_at.get(SOG_CATDON);
|
||
if ((catdon.not_empty()) && (catdon != catsog))
|
||
{
|
||
bool dimissione = cache().get("CTD", catdon).get_bool("B0");
|
||
if (dimissione)
|
||
{
|
||
if (catsog == "NU")
|
||
catdon = "DN";
|
||
dimissione = cache().get("CTD", catsog).get_bool("B0");
|
||
}
|
||
if (!dimissione)
|
||
{
|
||
if (!(cache().get("CTD", catdon).get_bool("B0")) && (cache().get("CTD", catsog).get_bool("B0")))
|
||
{
|
||
stampa = "CATEGORIA diversa: avis ";
|
||
stampa << catsog << " sit " << catdon;
|
||
print_line(stampa);
|
||
}
|
||
else
|
||
{
|
||
if ((catdon == "NU") && (catsog == "AV"))
|
||
{
|
||
stampa = "CATEGORIA diversa: avis ";
|
||
stampa << catsog << " sit " << catdon;
|
||
print_line(stampa);
|
||
}
|
||
else if ((catsog == "SM") && (catdon == "AV"))
|
||
{
|
||
stampa = "CATEGORIA diversa: avis ";
|
||
stampa << catsog << " sit " << catdon;
|
||
print_line(stampa);
|
||
}
|
||
else
|
||
{
|
||
bool cambia = TRUE;
|
||
if ((catdon == "AV") && (catsog == "NU"))
|
||
{
|
||
const int totdon = record_at.get_int(SOG_TOTDON);
|
||
if (totdon < 1)
|
||
{
|
||
cambia = FALSE;
|
||
//stampa = "CATEGORIA diversa: avis ";
|
||
//stampa << catsog << " sit " << catdon << ", soggetto senza donazioni";
|
||
//print_line(stampa);
|
||
}
|
||
}
|
||
if (cambia)
|
||
{
|
||
stampa = "Cambio categoria: da ";
|
||
stampa << catsog << " a " << catdon;
|
||
print_line(stampa);
|
||
record_at.put(SOG_CATDON, catdon);
|
||
if (cache().get("CTD", catdon).get_bool("B0"))
|
||
{
|
||
TString16 data = record_at.get(SOG_DATADIM);
|
||
if (data.empty())
|
||
{
|
||
record_at.put(SOG_DATADIM, _dataagg);
|
||
stampa = "Inserita data dimissione ";
|
||
stampa << _dataagg.string();
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
}
|
||
//aggiorna_storico();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
TString16 tipocontrollo = recpr1.get("S7");
|
||
if (tipocontrollo.not_empty())
|
||
{
|
||
TString16 finesosp = (TString4&) _configfile->get(val,"FINESOSPENSIONE");
|
||
if (finesosp == tipocontrollo)
|
||
{
|
||
TString16& str = (TString16&) record_ct["ID_ANAGRAFICA"];
|
||
if (!_array_sospesi->is_key(str))
|
||
_array_sospesi->add(str, record_ct["ID_ANAGRAFICA"]) ;
|
||
}
|
||
//aggiorna_controlli();
|
||
}
|
||
}
|
||
else if (elab == "DISPONIBILE") // disponibilita
|
||
{
|
||
str = val;
|
||
if (str == "NO")
|
||
{
|
||
record_at.put(SOG_DISP_AF_1, "");
|
||
record_at.put(SOG_DISP_AF_2, "");
|
||
}
|
||
else if (str == "PLA")
|
||
{
|
||
record_at.put(SOG_DISP_AF_1, "PL");
|
||
record_at.put(SOG_DISP_AF_2, "");
|
||
}
|
||
else if (str == "PLT")
|
||
{
|
||
record_at.put(SOG_DISP_AF_1, "PT");
|
||
record_at.put(SOG_DISP_AF_2, "");
|
||
}
|
||
else if (str == "SI")
|
||
{
|
||
record_at.put(SOG_DISP_AF_1, "PL");
|
||
record_at.put(SOG_DISP_AF_2, "PT");
|
||
}
|
||
}
|
||
else if (elab == "SESSO") // sesso
|
||
{
|
||
if (val[0] == 'M')
|
||
record_at.put(SOG_SESSO, "1"); // maschio
|
||
else if (val[0] == 'F')
|
||
record_at.put(SOG_SESSO, "2"); // femmina
|
||
else record_at.put(SOG_SESSO, "0"); // non specificato
|
||
}
|
||
else if (elab == "SEZIONE") // sezione/sottogruppo
|
||
{
|
||
str = val;
|
||
if (str[0] == '0')
|
||
str = str.sub(1);
|
||
if ((record_at.get(SOG_CODSEZ) != str.sub(0,2)) || (record_at.get(SOG_CODSOT) != str.sub(2,4)))
|
||
{
|
||
stampa << "SEZIONE diversa: avis " << record_at.get(SOG_CODSEZ);
|
||
stampa << record_at.get(SOG_CODSOT) << " sit " << str;
|
||
print_line(stampa);
|
||
if (record_at.get(SOG_CODSEZ).empty())
|
||
{
|
||
record_at.put(SOG_CODSEZ, str.sub(0,2));
|
||
record_at.put(SOG_CODSOT, str.sub(2,4));
|
||
}
|
||
}
|
||
}
|
||
else if (elab == "GIORNOPREF") // giorno preferito donazione
|
||
{
|
||
str = val;
|
||
if (!str.empty())
|
||
{
|
||
str << "XXXXXXX";
|
||
str = str.sub(0,7);
|
||
for (int i = 0; i< 7; i++)
|
||
{
|
||
if (str[i] != 'X')
|
||
str[i] = 'X';
|
||
else
|
||
str[i] = ' ';
|
||
}
|
||
record_at.put(SOG_GIOPREDON, str);
|
||
}
|
||
}
|
||
else if (elab == "DATA") // data
|
||
{
|
||
str = val;
|
||
TDate data = TDate(atoi(str.sub(8,10)), atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
if (campo.not_empty())
|
||
record_at.put(campo, data);
|
||
}
|
||
else if (elab == "COMUNE") // comune nascita o domicilio
|
||
{
|
||
update = FALSE;
|
||
TString16 codcom = "";
|
||
str = val;
|
||
if (str.not_empty())
|
||
{
|
||
if (_array_comuni->is_key(str))
|
||
{
|
||
codcom = (TString16&) _array_comuni->find(str);
|
||
update = (codcom != record_at.get(campo));
|
||
}
|
||
else
|
||
{
|
||
codcom = record_at.get(campo);
|
||
if (codcom.not_empty())
|
||
{
|
||
codcom = " |";
|
||
codcom << record_at.get(campo);
|
||
TRectype reccom = cache().get(LF_COMUNI, codcom);
|
||
if (reccom.get_long(COM_CODISTAT) != atol(str))
|
||
update = TRUE;
|
||
else
|
||
_array_comuni->add(str, reccom.get(COM_COM)) ;
|
||
}
|
||
else
|
||
update = TRUE;
|
||
if (update)
|
||
{
|
||
TString80 filtro = "";
|
||
filtro.format("%s == %ld", COM_CODISTAT, atol(str));
|
||
TCursor cur(_relcom, filtro);
|
||
if (cur.items() == 1)
|
||
{
|
||
cur.next_match(LF_COMUNI);
|
||
codcom = cur.curr().get(COM_COM);
|
||
_array_comuni->add(str, codcom);
|
||
}
|
||
else
|
||
update = FALSE;
|
||
}
|
||
}
|
||
}
|
||
if (campo.not_empty() && update)
|
||
record_at.put(campo, codcom);
|
||
}
|
||
else if (elab == "POSNEG") // positivo e negativo (rh, du)
|
||
{
|
||
if (val[0] == '+')
|
||
record_at.put(campo, "POS");
|
||
else if (val[0] == '-')
|
||
record_at.put(campo, "NEG");
|
||
else record_at.put(campo, "");
|
||
}
|
||
else if (elab == "KELL") // kell (vuoto = vuoto, presenza di K maiuscola = POS, altrimenti = NEG)
|
||
{
|
||
str = val;
|
||
if (str.empty())
|
||
record_at.put(SOG_KELL, "");
|
||
else if (str.find('K') != -1)
|
||
record_at.put(SOG_KELL, "POS");
|
||
else record_at.put(SOG_KELL, "NEG");
|
||
}
|
||
else if ((elab == "TELEFONO") || (elab == "CELLULARE")) // toglie barre e altre cose inutili dal numero di telefono
|
||
{
|
||
str = val;
|
||
str.trim();
|
||
if (str.not_empty())
|
||
{
|
||
str.strip_spaces();
|
||
str.strip("/");
|
||
str.strip("\\");
|
||
if (elab == "TELEFONO")
|
||
record_at.put(campo, str);
|
||
else
|
||
{
|
||
TString80 campo1, campo2;
|
||
const int pipe = campo.find('|');
|
||
if (pipe != -1)
|
||
{
|
||
campo2 = campo.sub(pipe+1);
|
||
campo1 = campo.sub(0,pipe);
|
||
}
|
||
if ((elab == "CELLULARE") && ((str[0]!='0') && (str.len()>9)))
|
||
record_at.put(campo1, str);
|
||
else
|
||
record_at.put(campo2, str);
|
||
}
|
||
}
|
||
}
|
||
else if (elab == "SENUMERO") // campo da caricare solo se numerico (nello specifico tess. ssn)
|
||
{
|
||
long numero = atol(val);
|
||
if (numero != 0)
|
||
record_at.put(campo, val);
|
||
}
|
||
else if (elab == "MEDICO") // medico (solo confronto)
|
||
{
|
||
str = val;
|
||
TRectype recmed = cache().get(LF_MEDICI, record_at.get(SOG_CODMED));
|
||
TString80 medico = recmed.get(MED_COGNOME);
|
||
medico.trim();
|
||
medico << ' ';
|
||
medico << recmed.get(MED_NOME);
|
||
medico.trim();
|
||
str.trim();
|
||
if ((medico != str) && (medico.not_empty() || str.not_empty()))
|
||
{
|
||
bool segnala = TRUE;
|
||
int i = medico.len();
|
||
int j = str.len();
|
||
if (i != j)
|
||
{
|
||
if ((i < j) && i > 0) j = i;
|
||
if ((j > 0) && (i > 0))
|
||
segnala = (medico.sub(0,j-1) != str.sub(0,j-1));
|
||
else
|
||
segnala = TRUE;
|
||
}
|
||
if (segnala)
|
||
{
|
||
TString256 stampa = "";
|
||
stampa << "MEDICO diverso: " << " avis " << medico << " sit " << str;
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
}
|
||
else if (elab == "INDIRIZZO") // indirizzo (per vedere di isolare la localita)
|
||
{
|
||
TString80 localita = "";
|
||
str = val;
|
||
const int i = str.find('-');
|
||
if (i > 0)
|
||
{
|
||
localita = str.sub(i+1);
|
||
str = str.sub(0,i);
|
||
str.trim();
|
||
localita.trim();
|
||
localita.upper();
|
||
}
|
||
TString tmp = record_at.get(SOG_DOM_INDIR);
|
||
str.trim();
|
||
str = str.upper();
|
||
tmp.trim();
|
||
tmp = tmp.upper();
|
||
if (tmp != str)
|
||
{
|
||
TString256 stampa = "";
|
||
stampa << "INDIRIZZO ";
|
||
if (tmp.empty())
|
||
{
|
||
record_at.put(SOG_DOM_INDIR, str);
|
||
stampa << " inserito da CETRAPLUS: " << str;
|
||
}
|
||
else
|
||
stampa << " diverso: avis " << tmp << " sit " << str;
|
||
print_line(stampa);
|
||
stampa = "";
|
||
}
|
||
tmp = record_at.get(SOG_DOM_CODLOC);
|
||
TString80 desloc = cache().get("LCP",tmp).get("S0");
|
||
desloc.trim();
|
||
if (localita != desloc)
|
||
{
|
||
stampa << "LOCALITA ";
|
||
if (desloc.empty())
|
||
{
|
||
TTable lcp("LCP");
|
||
lcp.setkey(2);
|
||
lcp.put("S0", localita);
|
||
if (lcp.read() == NOERR)
|
||
{
|
||
tmp = lcp.get("CODTAB");
|
||
record_at.put(SOG_DOM_CODLOC, tmp);
|
||
stampa << " inserito da CETRAPLUS: " << tmp << " " << localita;
|
||
tmp = lcp.get("S6");
|
||
record_at.put(SOG_DOM_CAP, tmp);
|
||
}
|
||
else
|
||
stampa << " non presente in tabella avis " << localita;
|
||
}
|
||
else
|
||
stampa << " diverso: avis " << desloc << " sit " << localita;
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
else if (elab == "CAP") // cap
|
||
{
|
||
str = val;
|
||
TString tmp = record_at.get(SOG_DOM_CAP);
|
||
str.trim();
|
||
tmp.trim();
|
||
if (tmp != str)
|
||
{
|
||
TString256 stampa = "";
|
||
stampa << "CAP ";
|
||
if (tmp.empty())
|
||
{
|
||
record_at.put(SOG_DOM_CAP, str);
|
||
stampa << " inserito da CETRAPLUS: " << str;
|
||
}
|
||
else
|
||
stampa << " diverso: avis " << tmp << " sit " << str;
|
||
print_line(stampa);
|
||
stampa = "";
|
||
}
|
||
}
|
||
else if ((elab == "CONFRONTA") || (elab == "SEGNALA")) // SEGNALA = solo segnalazione, CONFRONTA = segnala e modifica
|
||
{
|
||
if (campo.not_empty())
|
||
{
|
||
str = val;
|
||
TString tmp = record_at.get(campo);
|
||
str.trim();
|
||
str = str.upper();
|
||
tmp.trim();
|
||
tmp = tmp.upper();
|
||
if (tmp != str)
|
||
{
|
||
TString256 stampa = "";
|
||
if (elab == "CONFRONTA")
|
||
{
|
||
stampa << "Cambio " << campo << ": da " << tmp << " a " << str;
|
||
print_line(stampa);
|
||
record_at.put(campo, str);
|
||
}
|
||
else
|
||
{
|
||
stampa << campo << " diverso: avis " << tmp << " sit " << str;
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else if (elab == "SEVUOTO") // segnala differenza, e modifica solo se vuoto
|
||
{
|
||
if (campo.not_empty())
|
||
{
|
||
str = val;
|
||
TString tmp = record_at.get(campo);
|
||
str.trim();
|
||
str = str.upper();
|
||
tmp.trim();
|
||
tmp = tmp.upper();
|
||
if (tmp != str)
|
||
{
|
||
TString256 stampa = "";
|
||
stampa << campo;
|
||
if (tmp.empty())
|
||
{
|
||
record_at.put(campo, str);
|
||
stampa << " inserito da CETRAPLUS: " << str;
|
||
}
|
||
else
|
||
stampa << " diverso: avis " << tmp << " sit " << str;
|
||
print_line(stampa);
|
||
|
||
}
|
||
}
|
||
}
|
||
else if ((elab == "CONFRONTADATA") || (elab == "SEGNALADATA")) // come sopra ma per campi data
|
||
{
|
||
if (campo.not_empty())
|
||
{
|
||
str = val;
|
||
TDate tmp = record_at.get_date(campo);
|
||
TDate data = TDate(atoi(str.sub(8,10)), atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
if (tmp != data)
|
||
{
|
||
TString256 stampa = "";
|
||
stampa << campo << " diverso: avis " << tmp.string();
|
||
stampa << " sit " << data.string();
|
||
print_line(stampa);
|
||
if (elab == "CONFRONTA")
|
||
record_at.put(campo, data);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
record_at.put(field, val); // campi da passare semplicemente!
|
||
}
|
||
}
|
||
return update;
|
||
}
|
||
|
||
long TCtpr2at::get_next_key()
|
||
{
|
||
TLocalisamfile soggetti(LF_SOGGETTI);
|
||
soggetti.setkey(1);
|
||
soggetti.last();
|
||
long codice = soggetti.get_long(SOG_CODICE);
|
||
return codice+1;
|
||
}
|
||
|
||
bool TCtpr2at::accesso(const TString& istruzione)
|
||
{
|
||
TString256 stampa = "";
|
||
int error = NOERR;
|
||
TAssoc_array record;
|
||
if (build_record(record, istruzione))
|
||
{
|
||
// Se DT_CANCEL non vuota il record e`stato cancellato
|
||
// quindi: verifico DT_ACCESSO, se uguale, non inserisco per niente il record
|
||
// se diversa devo andare a cercare quell'accesso e cancellarlo
|
||
TString16& strc = (TString16&) record["DT_CANCEL"];
|
||
const TDate dt_cancel = TDate(atoi(strc.sub(8,10)) ,atoi(strc.sub(5,7)), atoi(strc.sub(0,4)));
|
||
if (dt_cancel.empty())
|
||
{
|
||
// ricerca del soggetto per codice SIT
|
||
TString16& id_anagrafica = (TString16&) record["ID_ANAGRAFICA"];
|
||
_rel->lfile().setkey(7);
|
||
TRectype& recsog = _rel->curr();
|
||
recsog.zero();
|
||
recsog.put(SOG_CODCT, id_anagrafica);
|
||
error = recsog.read(_rel->lfile());
|
||
if (error == NOERR)
|
||
{
|
||
stampa = recsog.get(SOG_COGNOME);
|
||
stampa << " " << recsog.get(SOG_NOME);
|
||
stampa << " " << recsog.get(SOG_DATANASC);
|
||
// ho trovato il soggetto, ora verifico che tipo di accesso <20>
|
||
TString8& tp_accesso = (TString8&)record["TP_ACCESSO"];
|
||
if (tp_accesso[0] == 'D')
|
||
{
|
||
// trattasi di donazione
|
||
// mi serve solo il codabar per decidere il punto di prelievo (la donazione c'<27> gi<67>)
|
||
TString8 luogodon_at;
|
||
TString16& str = (TString16&) record["DT_ACCESSO"];
|
||
const TDate datadon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
TDate datanulla(NULLDATE);
|
||
if (datadon != datanulla)
|
||
{
|
||
TString16& codabar = (TString16&) record["CODABAR"];
|
||
_donaz->setkey(2);
|
||
TRectype& recdon = _donaz->curr();
|
||
recdon.zero();
|
||
recdon.put(DON_CODICE, recsog.get(SOG_CODICE));
|
||
recdon.put(DON_DATADON, datadon);
|
||
if (_donaz->read() == NOERR)
|
||
{
|
||
if ((codabar.left(2) == "52") || (codabar.left(2) == "53") || (codabar.left(2) == "54") || (codabar.left(2) == "55") || (codabar.left(2) == "56") || (codabar.left(2) == "57"))
|
||
luogodon_at = "0001";
|
||
else
|
||
{
|
||
if (recsog.get(SOG_CODSEZ) == "13")
|
||
luogodon_at = "1301";
|
||
else
|
||
luogodon_at = "0000";
|
||
}
|
||
recdon.put(DON_LUOGODON, luogodon_at);
|
||
_donaz->rewrite();
|
||
TString16& prog = (TString16&) record["PROG_GIORNAL"];
|
||
TString80 chiave = str;
|
||
chiave << prog;
|
||
if (!_array_donaz->is_key(chiave))
|
||
_array_donaz->add(chiave, record["ID_ANAGRAFICA"]) ;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// trattasi di controllo o visita
|
||
TString4 tipocon = _configfile->get(tp_accesso, "ACCESSI");
|
||
TString16& str = (TString16&) record["DT_ACCESSO"];
|
||
TDate datacon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
TDate datanulla(NULLDATE);
|
||
if (datacon != datanulla)
|
||
{
|
||
TString16& prog = (TString16&) record["PROG_GIORNAL"];
|
||
TString80 chiave = str;
|
||
chiave << prog;
|
||
if (!_array_donaz->is_key(chiave))
|
||
_array_donaz->add(chiave, record["ID_ANAGRAFICA"]) ;
|
||
if (tipocon.empty() && _message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "Tipo accesso ";
|
||
stampa << tp_accesso[0] << " del ";
|
||
stampa << datacon.string() << " senza corrispondenza. Non inserito.";
|
||
print_line(stampa);
|
||
tipocon = "VS";
|
||
}
|
||
else
|
||
{
|
||
TRectype* recc = new TRectype(LF_CONTSAN);
|
||
recc->put(CON_CODICE, recsog.get(SOG_CODICE));
|
||
recc->put(CON_DATACON, datacon);
|
||
recc->put(CON_TIPOCON, tipocon);
|
||
recc->put(CON_RESPONSAB, "CETRAPLUS");
|
||
|
||
bool insert = FALSE;
|
||
bool exist = FALSE;
|
||
TRectype* keyc = new TRectype(LF_CONTSAN);
|
||
keyc->put(CON_CODICE, recsog.get(SOG_CODICE));
|
||
int err = _scontrolli->read(keyc);
|
||
if (err == NOERR)
|
||
{
|
||
int r=_scontrolli->rows();
|
||
while (r>=1 && !insert && !exist)
|
||
{
|
||
const TRectype& riga = _scontrolli->row(r);
|
||
const TDate d = riga.get(CON_DATACON);
|
||
if (datacon==d) // esiste gia' un controllo in questa data
|
||
{
|
||
// verifico la priorita
|
||
TString4 tipoes = riga.get(CON_TIPOCON);
|
||
if (tipoes != tipocon)
|
||
{
|
||
int p_tipocon = _configfile->get_int(tipocon, "PRIORITA");
|
||
int p_tipoes = _configfile->get_int(tipoes, "PRIORITA");
|
||
if (p_tipocon == 999)
|
||
{
|
||
++datacon;
|
||
recc->put(CON_DATACON, datacon);
|
||
recc->put(CON_RESPONSAB, "CETRAPLUS ieri");
|
||
recc->put(CON_PROGCON,r+1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
else
|
||
{
|
||
if (p_tipocon > p_tipoes)
|
||
{
|
||
recc->put(CON_PROGCON,riga.get(CON_PROGCON));
|
||
_scontrolli->add_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
else
|
||
{
|
||
exist=TRUE;
|
||
r=0;
|
||
if (_message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Controllo gi<67> esistente in data " << datacon.string();
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
exist=TRUE;
|
||
}
|
||
else
|
||
if (datacon > d)
|
||
{
|
||
recc->put(CON_PROGCON,r+1);
|
||
_scontrolli->insert_row(recc);
|
||
insert=TRUE;
|
||
}
|
||
r--;
|
||
}
|
||
if (!exist && !insert)
|
||
{
|
||
recc->put(CON_PROGCON,1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
}
|
||
else
|
||
if (err == _iseof || err == _isemptyfile)
|
||
{
|
||
recc->put(CON_PROGCON,1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
if (!exist)
|
||
{
|
||
_scontrolli->write(TRUE);
|
||
if (_message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Inserito controllo " << tipocon << " del " << datacon.string();
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
// aggiorno data e utente ultimo aggiornamento
|
||
TDate oggi(TODAY);
|
||
recsog.put(SOG_DATAULTAGG, oggi);
|
||
recsog.put(SOG_UTENULTAGG, "CETRAPLUS");
|
||
err = recsog.rewrite(_rel->lfile());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// soggetto non trovato
|
||
stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile aggiornare accesso ";
|
||
stampa << record["TP_ACCESSO"] << " del ";
|
||
stampa << record["DT_ACCESSO"];
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TString16& stra = (TString16&) record["DT_ACCESSO"];
|
||
const TDate dt_accesso = TDate(atoi(stra.sub(8,10)) ,atoi(stra.sub(5,7)), atoi(stra.sub(0,4)));
|
||
if (dt_cancel != dt_accesso)
|
||
{
|
||
// cercare il donatore ed eliminare l'accesso
|
||
}
|
||
}
|
||
return (error == NOERR);
|
||
}
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
bool TCtpr2at::sacca(const TString& istruzione)
|
||
{
|
||
TString256 stampa = "";
|
||
int err = NOERR;
|
||
TAssoc_array record;
|
||
if (build_record(record, istruzione))
|
||
{
|
||
TString16& strc = (TString16&) record["DT_CANCEL"];
|
||
const TDate dt_cancel = TDate(atoi(strc.sub(8,10)) ,atoi(strc.sub(5,7)), atoi(strc.sub(0,4)));
|
||
if (dt_cancel.empty())
|
||
{
|
||
// ricerca del soggetto per codice SIT
|
||
TString16& id_anagrafica = (TString16&) record["ID_ANAGRAFICA"];
|
||
_rel->lfile().setkey(7);
|
||
TRectype& recsog = _rel->curr();
|
||
recsog.zero();
|
||
recsog.put(SOG_CODCT, id_anagrafica);
|
||
err = recsog.read(_rel->lfile());
|
||
if (err == NOERR)
|
||
{
|
||
stampa = recsog.get(SOG_COGNOME);
|
||
stampa << " " << recsog.get(SOG_NOME);
|
||
stampa << " " << recsog.get(SOG_DATANASC);
|
||
// ho trovato il soggetto, ora verifico la donazione
|
||
TString16& str = (TString16&) record["DT_PRELIEVO"];
|
||
const TDate datadon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
TDate datanulla(NULLDATE);
|
||
if (datadon != datanulla)
|
||
{
|
||
_progins++;
|
||
TRectype* rec = new TRectype(LF_DONAZ);
|
||
rec->put(DON_CODICE, recsog.get(SOG_CODICE));
|
||
rec->put(DON_DATADON, datadon);
|
||
str = (TString16&) record["TP_DONAZIONE"];
|
||
TRectype recpr2 = cache().get("PR2", str);
|
||
TString16 tipodon = recpr2.get("S6");
|
||
if (tipodon.empty())
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Tipo donazione SIT " << str << " senza corrispondenza: non inserita";
|
||
print_line(stampa);
|
||
stampa = "";
|
||
}
|
||
else
|
||
{
|
||
rec->put(DON_TIPODON, tipodon);
|
||
TString16& etichetta = (TString16&) record["ID_SACCA"];
|
||
rec->put(DON_ETICHETTA, etichetta);
|
||
rec->put(DON_CODSEZ, recsog.get(SOG_CODSEZ));
|
||
rec->put(DON_CODSOT, recsog.get(SOG_CODSOT));
|
||
rec->put(DON_PROGINS, _progins);
|
||
|
||
bool insert = FALSE;
|
||
bool exist = FALSE;
|
||
TRectype* key = new TRectype(LF_DONAZ);
|
||
key->put(DON_CODICE, recsog.get(SOG_CODICE));
|
||
err = _sdonazioni->read(key);
|
||
if (err == NOERR)
|
||
{
|
||
int r=_sdonazioni->rows();
|
||
while (r>=1 && !insert && !exist)
|
||
{
|
||
const TRectype& riga = _sdonazioni->row(r);
|
||
const TDate d = riga.get(DON_DATADON);
|
||
if (datadon==d) // esiste gia' una donazione in questa data
|
||
{
|
||
exist=TRUE;
|
||
r=0;
|
||
if (_message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Donazione gi<67> esistente in data " << datadon.string();
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
}
|
||
else
|
||
if (datadon > d)
|
||
{
|
||
rec->put(DON_PROGDON,r+1);
|
||
_sdonazioni->insert_row(rec);
|
||
insert=TRUE;
|
||
}
|
||
r--;
|
||
}
|
||
if (!exist && !insert)
|
||
{
|
||
rec->put(DON_PROGDON,1);
|
||
rec->put(DON_PRIMADON,'X');
|
||
_sdonazioni->insert_row(rec);
|
||
}
|
||
}
|
||
else
|
||
if (err == _iseof || err == _isemptyfile)
|
||
{
|
||
rec->put(DON_PROGDON,1);
|
||
rec->put(DON_PRIMADON,'X');
|
||
_sdonazioni->insert_row(rec);
|
||
}
|
||
if (!exist)
|
||
{
|
||
err = _sdonazioni->write(TRUE);
|
||
if (err == NOERR)
|
||
{
|
||
if (_message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Inserita donazione del " << datadon;
|
||
print_line(stampa);
|
||
if (modstato_tcs(recsog.get(SOG_STATO)) == 'S')
|
||
{
|
||
stampa = "** ATTENZIONE ** il soggetto e' sospeso";
|
||
print_line(stampa);
|
||
}
|
||
}
|
||
calcola_donazioni_lib(recsog, _sdonazioni); // questo metodo sistema tutto!!!
|
||
calcola_categoria(recsog); // modificato per dare i messaggi al posto dei veri cambiamenti
|
||
//print_line(); // tolto perch<63> altrimenti stampa alcuni fogli vuoti
|
||
// aggiorno data e utente ultimo aggiornamento
|
||
TDate oggi(TODAY);
|
||
recsog.put(SOG_DATAULTAGG, oggi);
|
||
recsog.put(SOG_UTENULTAGG, "CETRAPLUS");
|
||
err = recsog.rewrite(_rel->lfile());
|
||
}
|
||
//else
|
||
//error_box("Errore %d in scrittura archivio donazioni, riga %d", err, rigasog);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// soggetto non trovato
|
||
stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile inserire donazione ";
|
||
stampa << record["TP_DONAZIONE"] << " del ";
|
||
stampa << record["DT_PRELIEVO"];
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TString16& stra = (TString16&) record["DT_ACCESSO"];
|
||
const TDate dt_accesso = TDate(atoi(stra.sub(8,10)) ,atoi(stra.sub(5,7)), atoi(stra.sub(0,4)));
|
||
if (dt_cancel != dt_accesso)
|
||
{
|
||
// cercare il donatore ed eliminare la donazione
|
||
}
|
||
}
|
||
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TCtpr2at::analisi(const TString& istruzione)
|
||
{
|
||
TString256 stampa = "";
|
||
int error = NOERR;
|
||
TAssoc_array record;
|
||
if (build_record(record, istruzione))
|
||
{
|
||
TString16& strc = (TString16&) record["DT_CANCEL"];
|
||
const TDate dt_cancel = TDate(atoi(strc.sub(8,10)) ,atoi(strc.sub(5,7)), atoi(strc.sub(0,4)));
|
||
if (dt_cancel.empty())
|
||
{
|
||
TString16& id_analisi = (TString16&) record["ID_ANALISI"];
|
||
TString4 tipocon = _configfile->get(id_analisi, "ANALISI");
|
||
if (!tipocon.empty())
|
||
{
|
||
TString16& prog = (TString16&) record["PROG_GIORNAL"];
|
||
TString16& str = (TString16&) record["DT_ACCESSO"];
|
||
TString80 chiave = str;
|
||
chiave << prog;
|
||
if (_array_donaz->is_key(chiave))
|
||
{
|
||
// ricerca del soggetto per codice SIT
|
||
TString16& id_anagrafica = (TString16&) _array_donaz->find(chiave);
|
||
_rel->lfile().setkey(7);
|
||
TRectype& recsog = _rel->curr();
|
||
recsog.zero();
|
||
recsog.put(SOG_CODCT, id_anagrafica);
|
||
error = recsog.read(_rel->lfile());
|
||
if (error == NOERR)
|
||
{
|
||
stampa = recsog.get(SOG_COGNOME);
|
||
stampa << " " << recsog.get(SOG_NOME);
|
||
stampa << " " << recsog.get(SOG_DATANASC);
|
||
TDate datacon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
TDate datanulla(NULLDATE);
|
||
if (datacon != datanulla)
|
||
{
|
||
TRectype* recc = new TRectype(LF_CONTSAN);
|
||
recc->put(CON_CODICE, recsog.get(SOG_CODICE));
|
||
recc->put(CON_DATACON, datacon);
|
||
recc->put(CON_TIPOCON, tipocon);
|
||
recc->put(CON_RESPONSAB, "CETRAPLUS");
|
||
|
||
bool insert = FALSE;
|
||
bool exist = FALSE;
|
||
TRectype* keyc = new TRectype(LF_CONTSAN);
|
||
keyc->put(CON_CODICE, recsog.get(SOG_CODICE));
|
||
int err = _scontrolli->read(keyc);
|
||
if (err == NOERR)
|
||
{
|
||
int r=_scontrolli->rows();
|
||
while (r>=1 && !insert && !exist)
|
||
{
|
||
const TRectype& riga = _scontrolli->row(r);
|
||
const TDate d = riga.get(CON_DATACON);
|
||
if (datacon==d) // esiste gia' un controllo in questa data
|
||
{
|
||
// verifico la priorita
|
||
TString4 tipoes = riga.get(CON_TIPOCON);
|
||
if (tipoes != tipocon)
|
||
{
|
||
int p_tipocon = _configfile->get_int(tipocon, "PRIORITA");
|
||
int p_tipoes = _configfile->get_int(tipoes, "PRIORITA");
|
||
if (p_tipocon == 999)
|
||
{
|
||
++datacon;
|
||
recc->put(CON_DATACON, datacon);
|
||
recc->put(CON_RESPONSAB, "CETRAPLUS ieri");
|
||
recc->put(CON_PROGCON,r+1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
else
|
||
{
|
||
if (p_tipocon > p_tipoes)
|
||
{
|
||
|
||
recc->put(CON_PROGCON,riga.get(CON_PROGCON));
|
||
_scontrolli->add_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
else
|
||
{
|
||
exist=TRUE;
|
||
r=0;
|
||
if (_message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Controllo gi<67> esistente in data " << datacon.string();
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
exist=TRUE;
|
||
}
|
||
else
|
||
if (datacon > d)
|
||
{
|
||
recc->put(CON_PROGCON,r+1);
|
||
_scontrolli->insert_row(recc);
|
||
insert=TRUE;
|
||
}
|
||
r--;
|
||
}
|
||
if (!exist && !insert)
|
||
{
|
||
recc->put(CON_PROGCON,1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
}
|
||
else
|
||
if (err == _iseof || err == _isemptyfile)
|
||
{
|
||
recc->put(CON_PROGCON,1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
if (!exist)
|
||
{
|
||
_scontrolli->write(TRUE);
|
||
if (_message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Inserito controllo " << tipocon << " del " << datacon.string();
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
// aggiorno data e utente ultimo aggiornamento
|
||
TDate oggi(TODAY);
|
||
recsog.put(SOG_DATAULTAGG, oggi);
|
||
recsog.put(SOG_UTENULTAGG, "CETRAPLUS");
|
||
err = recsog.rewrite(_rel->lfile());
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// soggetto non trovato
|
||
stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile inserire controllo ";
|
||
stampa << record["ID_ANALISI"] << " del ";
|
||
stampa << record["DT_ACCESSO"];
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
return (error == NOERR);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TString16& stra = (TString16&) record["DT_ACCESSO"];
|
||
const TDate dt_accesso = TDate(atoi(stra.sub(8,10)) ,atoi(stra.sub(5,7)), atoi(stra.sub(0,4)));
|
||
if (dt_cancel != dt_accesso)
|
||
{
|
||
// cercare il donatore ed eliminare il controllo
|
||
}
|
||
}
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
bool TCtpr2at::intervalli(const TString& istruzione)
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
bool TCtpr2at::esclusione(const TString& istruzione)
|
||
{
|
||
int error = NOERR;
|
||
TAssoc_array record;
|
||
if (build_record(record, istruzione))
|
||
{
|
||
TString16& strc = (TString16&) record["DT_CANCEL"];
|
||
const TDate dt_cancel = TDate(atoi(strc.sub(8,10)) ,atoi(strc.sub(5,7)), atoi(strc.sub(0,4)));
|
||
if (dt_cancel.empty())
|
||
{
|
||
TString16& tp_esclusione = (TString16&) record["TP_ESCLUSIONE"];
|
||
TString4 tipocon = _configfile->get(tp_esclusione, "ESCLUSIONI");
|
||
if (!tipocon.empty())
|
||
{
|
||
// ricerca del soggetto per codice SIT
|
||
TString16& id_anagrafica = (TString16&) record["ID_ANAGRAFICA"];
|
||
_rel->lfile().setkey(7);
|
||
TRectype& recsog = _rel->curr();
|
||
recsog.zero();
|
||
recsog.put(SOG_CODCT, id_anagrafica);
|
||
error = recsog.read(_rel->lfile());
|
||
TString256 stampa = "";
|
||
if (error == NOERR)
|
||
{
|
||
stampa = recsog.get(SOG_COGNOME);
|
||
stampa << " " << recsog.get(SOG_NOME);
|
||
stampa << " " << recsog.get(SOG_DATANASC);
|
||
// ho trovato il soggetto
|
||
const long codsog = recsog.get_long(SOG_CODICE);
|
||
//TString16& str = (TString16&) record["DA_DATA"];
|
||
//const TDate datacon = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
TDate datacon(TODAY);
|
||
TString16& str = (TString16&) record["A_DATA"];
|
||
const TDate datapross = TDate(atoi(str.sub(8,10)) ,atoi(str.sub(5,7)), atoi(str.sub(0,4)));
|
||
TDate datanulla(NULLDATE);
|
||
if ((datacon < datapross) || (datapross == datanulla))
|
||
{
|
||
TRectype* recc = new TRectype(LF_CONTSAN);
|
||
recc->put(CON_CODICE, recsog.get(SOG_CODICE));
|
||
recc->put(CON_DATACON, datacon);
|
||
recc->put(CON_TIPOCON, tipocon);
|
||
recc->put(CON_PROSSDATA, datapross);
|
||
if (_array_sospesi->is_key(id_anagrafica))
|
||
recc->put(CON_PROSSTIPO, "FS");
|
||
else
|
||
recc->put(CON_PROSSTIPO, tipocon);
|
||
recc->put(CON_RESPONSAB, "CETRAPLUS");
|
||
|
||
bool insert = FALSE;
|
||
bool exist = FALSE;
|
||
TRectype* keyc = new TRectype(LF_CONTSAN);
|
||
keyc->put(CON_CODICE, recsog.get(SOG_CODICE));
|
||
int err = _scontrolli->read(keyc);
|
||
if (err == NOERR)
|
||
{
|
||
int r=_scontrolli->rows();
|
||
while (r>=1 && !insert && !exist)
|
||
{
|
||
const TRectype& riga = _scontrolli->row(r);
|
||
const TDate d = riga.get(CON_DATACON);
|
||
if (datacon==d) // esiste gia' un controllo in questa data
|
||
{
|
||
// verifico la priorita
|
||
TString4 tipoes = riga.get(CON_TIPOCON);
|
||
if (tipoes != tipocon)
|
||
{
|
||
int p_tipocon = _configfile->get_int(tipocon, "PRIORITA");
|
||
int p_tipoes = _configfile->get_int(tipoes, "PRIORITA");
|
||
if (p_tipocon == 999)
|
||
{
|
||
++datacon;
|
||
recc->put(CON_DATACON, datacon);
|
||
recc->put(CON_RESPONSAB, "CETRAPLUS ieri");
|
||
recc->put(CON_PROGCON,r+1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
else
|
||
{
|
||
if (p_tipocon > p_tipoes)
|
||
{
|
||
|
||
recc->put(CON_PROGCON,riga.get(CON_PROGCON));
|
||
_scontrolli->add_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
else
|
||
{
|
||
exist=TRUE;
|
||
r=0;
|
||
if (_message)
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Controllo gi<67> esistente in data " << datacon.string();
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
exist=TRUE;
|
||
}
|
||
else
|
||
if (datacon > d)
|
||
{
|
||
recc->put(CON_PROGCON,r+1);
|
||
_scontrolli->insert_row(recc);
|
||
insert=TRUE;
|
||
}
|
||
r--;
|
||
}
|
||
if (!exist && !insert)
|
||
{
|
||
recc->put(CON_PROGCON,1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
}
|
||
else
|
||
if (err == _iseof || err == _isemptyfile)
|
||
{
|
||
recc->put(CON_PROGCON,1);
|
||
_scontrolli->insert_row(recc);
|
||
insert = TRUE;
|
||
}
|
||
if (!exist)
|
||
{
|
||
_scontrolli->write(TRUE);
|
||
TRectype* key = new TRectype(LF_IDONEITA);
|
||
key->put(IDO_CODICE, recsog.get(SOG_CODICE));
|
||
_sidoneita->read(key);
|
||
con_reord(recsog, _scontrolli, _sidoneita);
|
||
if (datapross.empty())
|
||
{
|
||
print_line(stampa);
|
||
stampa = "";
|
||
stampa << "Inserita sospensione " << tipocon << " dal " << datacon.string();
|
||
stampa << " al " << datapross.string();
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
// aggiorno data e utente ultimo aggiornamento
|
||
TDate oggi(TODAY);
|
||
recsog.put(SOG_DATAULTAGG, oggi);
|
||
recsog.put(SOG_UTENULTAGG, "CETRAPLUS");
|
||
err = recsog.rewrite(_rel->lfile());
|
||
}
|
||
}
|
||
//else
|
||
//{
|
||
// print_line(stampa);
|
||
// stampa = "";
|
||
// stampa << "Sospensione " << tipocon << " dal " << datacon.string();
|
||
// stampa << " al " << datapross.string();
|
||
// stampa << " non inserita perch<63> gi<67> scaduta";
|
||
// print_line(stampa);
|
||
// print_line();
|
||
//}
|
||
}
|
||
else
|
||
{
|
||
// soggetto non trovato
|
||
stampa << "Codice SIT " << id_anagrafica << " non trovato. Impossibile inserire sospensione ";
|
||
stampa << record["TP_ESCLUSIONE"] << " dal ";
|
||
stampa << record["DA_DATA"];
|
||
stampa << " al " << record["A_DATA"];
|
||
print_line(stampa);
|
||
print_line();
|
||
}
|
||
return (error == NOERR);
|
||
}
|
||
}
|
||
}
|
||
return FALSE;
|
||
|
||
}
|
||
|
||
// handler per gestire la conferma dell'annullamento dei dati inseriti
|
||
// nella maschera
|
||
bool TCtpr2at::annulla_handler(TMask_field& f, KEY k)
|
||
{
|
||
TMask &m = f.mask();
|
||
if (k == K_SPACE)
|
||
{
|
||
if (yesno_box("Vuoi veramente annullare i dati inseriti"))
|
||
m.reset();
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
int at8900(int argc, char* argv[])
|
||
{
|
||
TCtpr2at a;
|
||
a.run(argc, argv, "Acquisizione dati da SIT Parma");
|
||
return 0;
|
||
}
|