diff --git a/at/at8800.cpp b/at/at8800.cpp new file mode 100755 index 000000000..1dc151f9f --- /dev/null +++ b/at/at8800.cpp @@ -0,0 +1,238 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "at8.h" +#include "at8800a.h" +#include "soggetti.h" +#include "donaz.h" + +#define ATFILENAME "ctbo2at.dat" + +class TCtbo2at_file; + +class TCtbo2at: public TSkeleton_application +{ + TMask* _msk; + TRelation* _rel; + TCursor* _cur; + TCtbo2at_file* _trasfile; + TRecord_array* _donazioni; + TLocalisamfile* _donaz; + TDate _data; + +protected: + virtual bool create(void); + virtual void main_loop(); + virtual bool destroy(void) ; + void transfer(void); + void inizializza_cur(void); + void inizializza_file(void); + void record(THash_object& lavoro); + static bool annulla_handler(TMask_field& f, KEY k); +public: + + const TMask& msk() const { return *_msk; } + const TRecord_array& donazioni() { return *_donazioni;} + const TDate data() { return _data;} + + TCtbo2at() {} + virtual ~TCtbo2at() {} +}; + +// restituisce un riferimento all' applicazione +inline TCtbo2at& app() { return (TCtbo2at&) main_app();} + +///////////////////////////////////////////////////// +// Classe TCtbo2at_file customizzata dalla TFile_text // +///////////////////////////////////////////////////// +class TCtbo2at_file: public TFile_text +{ +protected: + virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str); + +public: + TCtbo2at_file(const TString& file_name, const TString& config_name); + virtual ~TCtbo2at_file() { } +}; + +TCtbo2at_file::TCtbo2at_file(const TString& file_name, const TString& config_name) + : TFile_text(file_name, config_name) +{ +} + +// creazione dell'applicazione +bool TCtbo2at::create() +{ + _msk = new TMask("at8800a"); + _rel = new TRelation(LF_SOGGETTI); + _cur = NULL; + _msk->set(F_FILENAME,ATFILENAME); + _donaz = new TLocalisamfile(LF_DONAZ); + _donazioni = new TRecord_array(LF_DONAZ,DON_PROGDON); + + //_msk->set_handler(DLG_CANCEL, annulla_handler); + _trasfile = NULL; + return TSkeleton_application::create(); +} + +// distruzione dell'applicazione +bool TCtbo2at::destroy() +{ + delete _donazioni; + delete _donaz; + delete _cur; + delete _rel; + delete _msk; + + if (_trasfile) + delete _trasfile; + return TSkeleton_application::destroy(); +} + +// carica la maschera +void TCtbo2at::main_loop() +{ + // Preimposta gli eventuali valori specificati sulla riga di comando + KEY key = K_ENTER; + while (key != K_QUIT) + { + key = _msk->run(); + if (key == K_ENTER) + transfer(); + } +} + +// trasferimento dati da file CT su programma avis +void TCtbo2at::transfer() +{ + inizializza_cur(); + + TFilename ctboini = "ctbo2at.ini"; + + _trasfile = new TCtbo2at_file(_msk->get(F_FILENAME), ctboini); + inizializza_file(); + + long n_sog = _cur->items(); + if (n_sog > 0) + { + TProgind pi(n_sog,"Lettura dati da archivio CT...",FALSE,TRUE); + + TAssoc_array& tracciati = _trasfile->tracciati(); + //scandisco tutti i soggetti + for (*_cur = 0; _cur->pos() < n_sog; ++(*_cur)) + { + pi.addstatus(1L); + + TRectype* key = new TRectype(LF_DONAZ); + key->put(DON_CODICE,_cur->file().get(SOG_CODICE)); + _donazioni->read(key); + + THash_object* lavoro = tracciati.get_hashobj(); + //scandisco tutti i record di un effetto + for (int i = 0; lavoro != NULL; i++) + { + record(*lavoro);//emetto il record + lavoro = tracciati.get_hashobj(); + } + } + } + _trasfile->close(); + delete _trasfile; + _trasfile = NULL; + message_box("Operazione terminata"); +} + +//inizializza il cursore +void TCtbo2at::inizializza_cur() +{ + TProgind prg (1,"Preparazione archivio soggetti da trasferire\nPrego attendere...",FALSE, FALSE); + _cur = new TCursor(_rel); + _cur->freeze(); +} + +//inizializza il file di testo su cui emettere i dati +void TCtbo2at::inizializza_file() +{ + TFilename filect = _msk->get(F_FILENAME); + _trasfile->open(filect,'r'); + //_trasfile->force_record_separator(TRUE); + +} + +//emetto un record +void TCtbo2at::record(THash_object& lavoro) +{ + TTracciato_record& oggetto = (TTracciato_record&)lavoro.obj(); + const TString& tipo = oggetto.type(); + TRecord_text rec(tipo); + //carico il record da emettere + _trasfile->autoload(rec, *_cur, &tipo); + _trasfile->write(rec);//emetto i dati su file +} + +// handler per gestire la conferma dell'annullamento dei dati inseriti +// nella maschera +bool TCtbo2at::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; +} + +// gestione dei messaggi estesi nei campi +void TCtbo2at_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str) +{ + const TString code(s.get(0)); + TString valore; + if (code == "_TOTALE") + { + int totale = 0; + TString16 tipodon(s.get()); + CHECK(tipodon[0]=='!',"Macro _TOTALE senza carattere '!'"); + tipodon.ltrim(1); + for (int r=1; r<=app().donazioni().rows(); r++) + { + const TRectype& riga = app().donazioni().row(r); + const TDate datadon = riga.get(DON_DATADON); + if ((riga.get(DON_TIPODON)==tipodon) && (app().data().year() == datadon.year())) + totale++; + } + valore.cut(0); + valore << totale; + } + else if (code == "_ULTIMA") + { + valore.cut(0); + TString16 tipodon(s.get()); + CHECK(tipodon[0]=='!',"Macro _ULTIMA senza carattere '!'"); + tipodon.ltrim(1); + for (int r=1; r<=app().donazioni().rows(); r++) + { + const TRectype& riga = app().donazioni().row(r); + const TDate datadon = riga.get(DON_DATADON); + if ((riga.get(DON_TIPODON)==tipodon) && (app().data().year() == datadon.year())) + valore = riga.get(DON_DATADON); + } + } + else NFCHECK("Macro non definita: %s", (const char *)code); + str = valore; +} + +int at8800(int argc, char* argv[]) +{ + TCtbo2at a ; + a.run(argc, argv, "Acquisizione dati da CT Bologna"); + return 0; +} diff --git a/at/at8800a.h b/at/at8800a.h new file mode 100755 index 000000000..18a3f57a6 --- /dev/null +++ b/at/at8800a.h @@ -0,0 +1,4 @@ +// acquisizione dati da CT Bologna +// definizione campi per maschera di selezione + +#define F_FILENAME 102 // nome del file da cui scaricare i dati diff --git a/at/at8800a.uml b/at/at8800a.uml new file mode 100755 index 000000000..eb33d332b --- /dev/null +++ b/at/at8800a.uml @@ -0,0 +1,35 @@ +#include "at8800a.h" + +TOOLBAR "" 0 20 0 2 + +BUTTON DLG_OK 9 2 +BEGIN + PROMPT -12 -11 "" +END + +BUTTON DLG_QUIT 9 2 +BEGIN + PROMPT -22 -11 "" +END + +ENDPAGE + +PAGE "Acquisizione dati da CT Bologna" -1 -1 78 20 + +GROUPBOX DLG_NULL 77 9 +BEGIN + PROMPT 1 1 "Selezioni per il trasferimento" +END + +STRING F_FILENAME 52 +BEGIN + PROMPT 2 2 "Nome file " + CHECKTYPE REQUIRED + VALIDATE FILENAME_FUNC + FLAGS "A" + HELP "Nome del file da cui caricare i dati" + WARNING "E' necessario specificare un nome di file" +END + +ENDPAGE +ENDMASK