97078c070d
Files correlati : Ricompilazione Demo : [ ] Commento : cancellazione convocazione se un soggetto ha donato git-svn-id: svn://10.65.10.50/trunk@6623 c028cbd2-c16b-5b4b-a496-9718f37d4682
811 lines
22 KiB
C++
Executable File
811 lines
22 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <execp.h>
|
||
#include <mask.h>
|
||
#include <msksheet.h>
|
||
#include <mailbox.h>
|
||
#include <prefix.h>
|
||
#include <progind.h>
|
||
#include <recarray.h>
|
||
#include <relation.h>
|
||
#include <tabutil.h>
|
||
#include <urldefid.h>
|
||
#include <validate.h>
|
||
#include <lffiles.h>
|
||
|
||
#include "at0.h"
|
||
|
||
// nomi campi maschera
|
||
#include "at0200a.h"
|
||
#include "atlib.h"
|
||
|
||
// nomi dei campi
|
||
#include "soggetti.h"
|
||
#include "donaz.h"
|
||
#include "contsan.h"
|
||
#include "idoneita.h"
|
||
#include "rconvoc.h"
|
||
|
||
#define ALIAS_CTD 700
|
||
|
||
class TGiornalieroDC : public TApplication
|
||
{
|
||
TMask* _msk;
|
||
TRelation* _rel;
|
||
|
||
TLocalisamfile* _soggetti;
|
||
TLocalisamfile* _donaz;
|
||
TLocalisamfile* _contsan;
|
||
TLocalisamfile* _idoneita;
|
||
TLocalisamfile* _rconvoc;
|
||
TRecord_array* _sdonazioni;
|
||
TRecord_array* _scontrolli;
|
||
TRecord_array* _sidoneita;
|
||
// array dei soggetti inseriti per controllare doppio inserimento
|
||
TAssoc_array* _asoggetti;
|
||
bool _modified, _ricerca;
|
||
long _progins;
|
||
TDate _datadon;
|
||
TString16 _tipodon, _luogodon;
|
||
// parametri di sezione
|
||
int _numdon1, _numdon2;
|
||
TString16 _catini1, _catfin1, _catini2, _catfin2;
|
||
bool _sttess2, _dataisc, _nomessage;
|
||
|
||
|
||
protected:
|
||
virtual bool create();
|
||
virtual bool destroy();
|
||
virtual bool menu(MENU_TAG m);
|
||
virtual TMask& get_mask() { return *_msk; }
|
||
virtual TRelation* get_relation() const { return _rel; }
|
||
|
||
TAssoc_array& get_array_sogg() { return *_asoggetti; }
|
||
int write(TSheet_field& s);
|
||
int read(TSheet_field& s);
|
||
bool check_sog_sheet(const char* codsog);
|
||
static bool nome_handler(TMask_field& f, KEY k);
|
||
static bool codice_handler(TMask_field& f, KEY k);
|
||
static bool soggetti_notify(TSheet_field& s, int r, KEY k);
|
||
void add_rows_soggetti(TSheet_field& s, int count = 20, int start = 0);
|
||
static bool ins_controlli_handler(TMask_field& f, KEY k);
|
||
|
||
public:
|
||
TGiornalieroDC() {}
|
||
|
||
};
|
||
|
||
HIDDEN inline TGiornalieroDC& app() { return (TGiornalieroDC&) main_app(); }
|
||
|
||
bool TGiornalieroDC::ins_controlli_handler(TMask_field& f, KEY k)
|
||
{
|
||
if (k == K_SPACE)
|
||
{
|
||
TMask& m = f.mask();
|
||
TSheet_field& s = (TSheet_field&)m.field(F_SOGGETTI);
|
||
const bool ins_controlli = m.get_bool(F_INS_CONTROLLI);
|
||
s.enable_column(4,ins_controlli);
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
void TGiornalieroDC::add_rows_soggetti(TSheet_field& s, int count, int start)
|
||
{
|
||
if (start == 0)
|
||
s.destroy();
|
||
for (int r=start; r<=start+count-1; r++)
|
||
s.row(r);
|
||
}
|
||
|
||
bool TGiornalieroDC::create()
|
||
{
|
||
TApplication::create();
|
||
_modified = FALSE;
|
||
_ricerca = FALSE;
|
||
_msk = new TMask("at0200a");
|
||
_rel = new TRelation(LF_SOGGETTI);
|
||
_rel->add("CTD", "CODTAB==CATDON",1,0,ALIAS_CTD);
|
||
_donaz = new TLocalisamfile(LF_DONAZ);
|
||
_contsan = new TLocalisamfile(LF_CONTSAN);
|
||
_idoneita = new TLocalisamfile(LF_IDONEITA);
|
||
_rconvoc = new TLocalisamfile(LF_RCONVOC);
|
||
_sdonazioni = new TRecord_array(LF_DONAZ,DON_PROGDON);
|
||
_scontrolli = new TRecord_array(LF_CONTSAN,CON_PROGCON);
|
||
_sidoneita = new TRecord_array(LF_IDONEITA,IDO_PROGIDO);
|
||
_asoggetti = new TAssoc_array();
|
||
_msk->set_handler(F_INS_CONTROLLI,ins_controlli_handler);
|
||
TSheet_field& ss = (TSheet_field&)_msk->field(F_SOGGETTI);
|
||
ss.set_notify(soggetti_notify);
|
||
ss.sheet_mask().set_handler(F_S_NOME,nome_handler);
|
||
ss.sheet_mask().set_handler(F_S_CODICE,codice_handler);
|
||
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");
|
||
_nomessage = config.get_bool("NoMessage");
|
||
_donaz->setkey(3);
|
||
_donaz->last();
|
||
_progins = _donaz->get_long(DON_PROGINS);
|
||
_donaz->setkey(1);
|
||
dispatch_e_menu(BAR_ITEM(1));
|
||
return TRUE;
|
||
}
|
||
|
||
bool TGiornalieroDC::destroy()
|
||
{
|
||
delete _rel;
|
||
delete _msk;
|
||
delete _donaz;
|
||
delete _contsan;
|
||
delete _idoneita;
|
||
delete _rconvoc;
|
||
delete _sdonazioni;
|
||
delete _scontrolli;
|
||
delete _sidoneita;
|
||
delete _asoggetti;
|
||
return TApplication::destroy();
|
||
}
|
||
|
||
bool TGiornalieroDC::menu(MENU_TAG m)
|
||
{
|
||
TMask& msk = get_mask();
|
||
const TDate oggi(TODAY);
|
||
KEY tasto;
|
||
do
|
||
{
|
||
TSheet_field& s = (TSheet_field&)msk.field(F_SOGGETTI);
|
||
if (s.items() == 0)
|
||
add_rows_soggetti(s);
|
||
_asoggetti->destroy();
|
||
_ricerca = FALSE;
|
||
tasto = msk.run();
|
||
_datadon = msk.get(F_DATADON);
|
||
_tipodon = msk.get(F_TIPODON);
|
||
_luogodon = msk.get(F_LUOGODON);
|
||
switch (tasto)
|
||
{
|
||
case K_F9: // ricerca
|
||
{
|
||
if (_modified)
|
||
if (yesno_box("Registrare le modifiche?"))
|
||
TGiornalieroDC::write(s);
|
||
_modified = FALSE;
|
||
if (_datadon.ok())
|
||
{
|
||
_ricerca = TRUE;
|
||
TGiornalieroDC::read(s);
|
||
}
|
||
else
|
||
message_box("Inserire almeno la data donazione per effettuare la ricerca");
|
||
}
|
||
break;
|
||
|
||
case K_ESC: // annulla
|
||
{
|
||
if (_modified)
|
||
if (yesno_box("Registrare le modifiche?"))
|
||
TGiornalieroDC::write(s);
|
||
_modified = FALSE;
|
||
msk.reset();
|
||
msk.field(DLG_SAVEREC).enable();
|
||
msk.field(DLG_FINDREC).enable();
|
||
msk.field(DLG_NEWREC).enable();
|
||
}
|
||
break;
|
||
case K_SAVE: // registra
|
||
{
|
||
TGiornalieroDC::write(s);
|
||
_modified = FALSE;
|
||
//msk.reset(); //verificare se va tolta
|
||
}
|
||
break;
|
||
case K_INS: // nuovo
|
||
{
|
||
if (_modified)
|
||
if (yesno_box("Registrare le modifiche?"))
|
||
TGiornalieroDC::write(s);
|
||
_modified = FALSE;
|
||
msk.reset();
|
||
}
|
||
break;
|
||
case K_QUIT: // fine
|
||
{
|
||
if (_modified)
|
||
if (yesno_box("Registrare le modifiche?"))
|
||
TGiornalieroDC::write(s);
|
||
msk.reset();
|
||
_modified = FALSE;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
while (tasto != K_QUIT);
|
||
return FALSE;
|
||
}
|
||
|
||
int TGiornalieroDC::read(TSheet_field& s)
|
||
{
|
||
s.destroy();
|
||
TLocalisamfile donaz(LF_DONAZ);
|
||
TLocalisamfile soggetti(LF_SOGGETTI);
|
||
soggetti.setkey(1);
|
||
donaz.setkey(4);
|
||
donaz.zero();
|
||
donaz.put(DON_DATADON, _datadon);
|
||
if (_tipodon.not_empty())
|
||
{
|
||
donaz.put(DON_TIPODON, _tipodon);
|
||
if (_luogodon.not_empty())
|
||
donaz.put(DON_LUOGODON, _luogodon);
|
||
}
|
||
TString16 luogodon;
|
||
bool leggi = TRUE;
|
||
TRectype r(donaz.curr());
|
||
int items = 0;
|
||
for(donaz.read(); !donaz.eof(); donaz.next())
|
||
{
|
||
if (donaz.curr() != r) break;
|
||
if (_tipodon.empty() && _luogodon.not_empty())
|
||
{
|
||
luogodon = donaz.get(DON_LUOGODON);
|
||
if (luogodon == _luogodon)
|
||
leggi = TRUE;
|
||
else
|
||
leggi = FALSE;
|
||
}
|
||
else
|
||
leggi = TRUE;
|
||
if (leggi)
|
||
{
|
||
TToken_string& row = s.row(items);
|
||
row.add(donaz.get(DON_CODICE));
|
||
soggetti.zero();
|
||
soggetti.put(SOG_CODICE,donaz.get(DON_CODICE));
|
||
int err = soggetti.read();
|
||
if (err == NOERR)
|
||
{
|
||
row.add(soggetti.get(SOG_COGNOME));
|
||
row.add(soggetti.get(SOG_NOME));
|
||
}
|
||
else
|
||
{
|
||
row.add("");
|
||
row.add("");
|
||
}
|
||
row.add(donaz.get(DON_TIPODON));
|
||
row.add("");
|
||
row.add(donaz.get(DON_ETICHETTA));
|
||
row.add(donaz.get(DON_PRIMADON));
|
||
if (err == NOERR)
|
||
{
|
||
row.add(soggetti.get(SOG_DATANASC));
|
||
row.add(soggetti.get(SOG_CODSEZ));
|
||
row.add(soggetti.get(SOG_CODSOT));
|
||
row.add(soggetti.get(SOG_CATDON));
|
||
row.add(soggetti.get(SOG_TESSAVIS));
|
||
row.add(soggetti.get(SOG_INTSI));
|
||
}
|
||
items++;
|
||
}
|
||
}
|
||
_msk->field(DLG_SAVEREC).disable();
|
||
_msk->field(DLG_FINDREC).disable();
|
||
_msk->field(DLG_NEWREC).disable();
|
||
return items;
|
||
}
|
||
|
||
int TGiornalieroDC::write(TSheet_field& s)
|
||
{
|
||
|
||
const TMask& m = s.mask();
|
||
int items = s.items();
|
||
TProgind *pi;
|
||
pi = new TProgind(items,"Registrazione donazioni e controlli", FALSE, TRUE, 10);
|
||
pi->setstatus(1);
|
||
TLocalisamfile& sog = get_relation()->lfile();
|
||
TLocalisamfile rconv(LF_RCONVOC);
|
||
for (int r=1; r<=s.items(); r++)
|
||
{
|
||
pi->addstatus(1);
|
||
TToken_string& row = s.row(r-1);
|
||
const long codsog = row.get_long(0);
|
||
if (codsog != 0)
|
||
{
|
||
sog.setkey(1);
|
||
sog.zero();
|
||
sog.put(SOG_CODICE, codsog);
|
||
int err = sog.read();
|
||
if (err == NOERR)
|
||
{
|
||
TString16 tipocon = row.get(4);
|
||
if (tipocon.blank())
|
||
tipocon = m.get(F_TIPOCON);
|
||
if (tipocon.not_empty())
|
||
{
|
||
TRectype* recc = new TRectype(LF_CONTSAN);
|
||
recc->put(CON_CODICE, row.get(0));
|
||
recc->put(CON_DATACON, _datadon);
|
||
recc->put(CON_TIPOCON, tipocon);
|
||
if (modstato_tcs(tipocon) == 'I')
|
||
{
|
||
recc->put(CON_IDON1,sog.get(SOG_IDON1));
|
||
recc->put(CON_IDON2,sog.get(SOG_IDON2));
|
||
recc->put(CON_IDON3,sog.get(SOG_IDON3));
|
||
recc->put(CON_IDON4,sog.get(SOG_IDON4));
|
||
recc->put(CON_INTSI,sog.get(SOG_INTSI));
|
||
recc->put(CON_INTAF,sog.get(SOG_INTAF));
|
||
}
|
||
bool insert = FALSE;
|
||
bool exist = FALSE;
|
||
TRectype* keyc = new TRectype(LF_CONTSAN);
|
||
keyc->put(CON_CODICE, row.get(0));
|
||
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 (_datadon==d) // esiste gi<67> un controllo in questa data
|
||
{
|
||
exist=TRUE;
|
||
r=0;
|
||
}
|
||
else
|
||
if (_datadon > 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);
|
||
}
|
||
}
|
||
else
|
||
if (err == _iseof || err == _isemptyfile)
|
||
{
|
||
recc->put(CON_PROGCON,1);
|
||
_scontrolli->insert_row(recc);
|
||
}
|
||
if (!exist)
|
||
{
|
||
_scontrolli->write(TRUE);
|
||
TRectype* keyc = new TRectype(LF_IDONEITA);
|
||
keyc->put(IDO_CODICE, row.get(0));
|
||
int err = _sidoneita->read(keyc);
|
||
con_reord(sog.curr(),_scontrolli,_sidoneita);
|
||
}
|
||
}
|
||
_progins++;
|
||
TRectype* rec = new TRectype(LF_DONAZ);
|
||
rec->put(DON_CODICE, row.get(0));
|
||
rec->put(DON_DATADON, _datadon);
|
||
TString16 tipodon = row.get(3);
|
||
if (tipodon.blank())
|
||
tipodon = _tipodon;
|
||
rec->put(DON_TIPODON, tipodon);
|
||
rec->put(DON_LUOGODON, _luogodon);
|
||
rec->put(DON_ETICHETTA, row.get(5));
|
||
rec->put(DON_PRIMADON, row.get(6));
|
||
|
||
rec->put(DON_CODSEZ,sog.get(SOG_CODSEZ));
|
||
rec->put(DON_CODSOT,sog.get(SOG_CODSOT));
|
||
rec->put(DON_PROGINS,_progins);
|
||
|
||
bool insert = FALSE;
|
||
bool exist = FALSE;
|
||
|
||
TRectype* key = new TRectype(LF_DONAZ);
|
||
key->put(DON_CODICE, row.get(0));
|
||
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;
|
||
}
|
||
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);
|
||
_sdonazioni->insert_row(rec);
|
||
}
|
||
}
|
||
else
|
||
if (err == _iseof || err == _isemptyfile)
|
||
{
|
||
rec->put(DON_PROGDON,1);
|
||
_sdonazioni->insert_row(rec);
|
||
}
|
||
if (!exist)
|
||
{
|
||
_sdonazioni->write(TRUE);
|
||
|
||
// controllo se <20> idoneo
|
||
|
||
int totdon = sog.get_int(SOG_TOTDON);
|
||
TDate dataultdon = sog.get_date(SOG_DATAULTDON);
|
||
sog.put(SOG_TOTDON,totdon+1);
|
||
if (_datadon > dataultdon)
|
||
{
|
||
sog.put(SOG_DATAULTDON,_datadon);
|
||
sog.put(SOG_TIPOULTDON,tipodon);
|
||
}
|
||
if (is_donaz(tipodon,IDON_SI))
|
||
{
|
||
totdon = sog.get_int(SOG_TOTDONSI);
|
||
sog.put(SOG_TOTDONSI,totdon+1);
|
||
dataultdon = sog.get_date(SOG_DATAULTSI);
|
||
if (_datadon>dataultdon)
|
||
sog.put(SOG_DATAULTSI,_datadon);
|
||
}
|
||
if (is_donaz(tipodon,IDON_AF))
|
||
{
|
||
totdon = sog.get_int(SOG_TOTDONAF);
|
||
sog.put(SOG_TOTDONAF,totdon+1);
|
||
dataultdon = sog.get_date(SOG_DATAULTAF);
|
||
if (_datadon>dataultdon)
|
||
sog.put(SOG_DATAULTAF,_datadon);
|
||
}
|
||
char modstato = ' ';
|
||
const TString16 stato = sog.get(SOG_STATO); // stato attuale
|
||
const TString16 id1 = sog.get(SOG_IDON1); // idon. 1
|
||
const TString16 id2 = sog.get(SOG_IDON2); // idon. 2
|
||
const TString16 id3 = sog.get(SOG_IDON3); // idon. 3
|
||
const TString16 id4 = sog.get(SOG_IDON4); // idon. 4
|
||
const int intsi = sog.get_int(SOG_INTSI); // intervallo per SI
|
||
const int intaf = sog.get_int(SOG_INTAF); // intervallo per AF
|
||
dataultdon = sog.get_date(SOG_DATAULTDON); // data ultima donazione
|
||
const TString16 tipoultdon(sog.get(SOG_TIPOULTDON)); // tipo ultima donazione
|
||
TDate datasi(NULLDATE); // data prossima si calcolata
|
||
TDate dataaf(NULLDATE); // data prossima af calcolata
|
||
TDate dataultsi(NULLDATE); // data ultima donazione si
|
||
|
||
bool id_si = FALSE; // il soggetto <20> idoneo per si?
|
||
bool id_af = FALSE; // il soggetto <20> idoneo per af?
|
||
|
||
modstato = modstato_tcs(stato);
|
||
if (modstato == 'I' || modstato == 'F') // il soggetto <20> idoneo
|
||
{
|
||
id_si = (is_idon(id1,id2,id3,id4,IDON_SI) && intsi != 0); // il soggetto <20> idoneo SI
|
||
id_af = (is_idon(id1,id2,id3,id4,IDON_AF) && intaf != 0); // il soggetto <20> idoneo AF
|
||
|
||
if (dataultdon.ok()) // se ha fatto almeno una donazione
|
||
{
|
||
if (is_donaz(tipoultdon,IDON_SI)) // se l'ultima donazione <20> una SI
|
||
{
|
||
if (id_si)
|
||
{
|
||
datasi=dataultdon;
|
||
datasi+=intsi;
|
||
}
|
||
if (id_af)
|
||
{
|
||
dataaf=dataultdon;
|
||
dataaf+=intaf;
|
||
}
|
||
}
|
||
if (is_donaz(tipoultdon,IDON_AF)) // se l'ultima donazione <20> una AF
|
||
{
|
||
dataultsi = sog.get_date(SOG_DATAULTSI);
|
||
if (id_si)
|
||
{
|
||
if (intaf != 0)
|
||
{
|
||
datasi=dataultdon;
|
||
datasi+=intaf;
|
||
}
|
||
else
|
||
{
|
||
datasi=dataultdon;
|
||
datasi+=intsi;
|
||
}
|
||
if (dataultsi.ok())
|
||
dataultsi+=intsi;
|
||
if (dataultsi > datasi)
|
||
datasi = dataultsi;
|
||
}
|
||
if (id_af)
|
||
{
|
||
dataaf=dataultdon;
|
||
dataaf+=intaf;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (id_si)
|
||
datasi=sog.get_date(SOG_DATAULTID);
|
||
if (id_af)
|
||
dataaf=sog.get_date(SOG_DATAULTID);
|
||
}
|
||
}
|
||
sog.put(SOG_DATAPROSSI,datasi);
|
||
sog.put(SOG_DATAPROSAF,dataaf);
|
||
|
||
// se la data prossima SI <20> superiore all'ultima convocazione
|
||
// va cancellata, anche dall'archivio convocazioni
|
||
TDate dataprossi = sog.get_date(SOG_DATAPROSSI);
|
||
TDate dataconv = sog.get_date(SOG_DATACONV);
|
||
if (dataprossi >= dataconv)
|
||
{
|
||
rconv.setkey(2);
|
||
rconv.zero();
|
||
rconv.put(RCV_DATACONV, dataconv);
|
||
rconv.put(RCV_CODICE, codsog);
|
||
int err = rconv.read();
|
||
if (err == NOERR)
|
||
{
|
||
rconv.put(RCV_ANNULLATO,TRUE);
|
||
rconv.rewrite();
|
||
}
|
||
sog.put(SOG_DATACONV, NULLDATE);
|
||
sog.put(SOG_DATAULTSOL, NULLDATE);
|
||
const int zeroconv = 0;
|
||
sog.put(SOG_NUMCONV, zeroconv);
|
||
}
|
||
|
||
|
||
// controllo la sua categoria
|
||
// se dimesso diventa della categoria collegata
|
||
// se non c'e' la categoria collegata ???
|
||
|
||
TTable ctd("CTD");
|
||
TString16 catdon = sog.get(SOG_CATDON);
|
||
ctd.put("CODTAB",catdon);
|
||
if (ctd.read() == NOERR)
|
||
{
|
||
bool dimissione = ctd.get_bool("B0");
|
||
if (dimissione)
|
||
sog.put(SOG_CATDON,ctd.get("S6"));
|
||
else
|
||
{
|
||
if ((catdon == _catini1 || _catini1.empty()) && (totdon+1>=_numdon1) && _catfin1.not_empty())
|
||
sog.put(SOG_CATDON, _catfin1);
|
||
if ((catdon == _catini2 || _catini2.empty()) && (totdon+1>=_numdon2) && _catfin2.not_empty() && !_sttess2)
|
||
sog.put(SOG_CATDON, _catfin2);
|
||
}
|
||
}
|
||
TDate dataisc = sog.get_date(SOG_DATAISC);
|
||
if (dataisc.empty() && _dataisc)
|
||
{
|
||
const TRectype& riga = _sdonazioni->row(1);
|
||
sog.put(SOG_DATAISC,riga.get(DON_DATADON));
|
||
}
|
||
|
||
// aggiorno data e utente ultimo aggiornamento
|
||
const TDate oggi(TODAY);
|
||
sog.put(SOG_DATAULTAGG,oggi);
|
||
sog.put(SOG_UTENULTAGG,user());
|
||
|
||
sog.rewrite();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
delete pi;
|
||
|
||
return NOERR;
|
||
}
|
||
|
||
bool TGiornalieroDC::check_sog_sheet(const char* codsog)
|
||
{
|
||
TAssoc_array& array_sogg = app().get_array_sogg();
|
||
if (array_sogg.is_key(codsog))
|
||
return FALSE;
|
||
else
|
||
return TRUE;
|
||
}
|
||
|
||
bool TGiornalieroDC::soggetti_notify(TSheet_field& s, int r, KEY k)
|
||
{
|
||
bool ok = TRUE;
|
||
switch (k)
|
||
{
|
||
case K_INS:
|
||
// richiesta inserimento riga
|
||
if (app()._ricerca)
|
||
{
|
||
s.message_box("Fase di ricerca: impossibile inserire donazioni");
|
||
ok = FALSE;
|
||
}
|
||
break;
|
||
case K_DEL:
|
||
case K_CTRL+K_DEL:
|
||
// avvenuta cancellazione riga
|
||
break;
|
||
case K_SPACE:
|
||
// inizio modifica riga
|
||
break;
|
||
case K_TAB:
|
||
// entrata riga
|
||
{
|
||
static bool entering = TRUE;
|
||
if (entering)
|
||
{
|
||
entering = FALSE;
|
||
if ((r == s.items()-1) && (r == s.first_empty()))
|
||
app().add_rows_soggetti(s,10,r+1);
|
||
TToken_string& row = s.row(r);
|
||
if (row.empty_items())
|
||
s.select(r);
|
||
entering = TRUE;
|
||
}
|
||
}
|
||
break;
|
||
case K_ENTER:
|
||
// uscita da riga modificata
|
||
case K_CTRL+K_TAB:
|
||
// uscita riga
|
||
{
|
||
TToken_string& row = s.row(r);
|
||
if (!row.empty_items())
|
||
app()._modified = TRUE;
|
||
const long codsog = row.get_long(0);
|
||
const long etichetta = row.get_long(5);
|
||
if (codsog != 0)
|
||
for (int i=s.items()-1; i>=0; i--)
|
||
{
|
||
if (i != r)
|
||
{
|
||
TToken_string& row = s.row(i);
|
||
if (codsog == row.get_long(0))
|
||
return s.sheet_mask().field(F_S_CODICE).error_box("Soggetto gia' inserito");
|
||
else
|
||
{
|
||
// controllo sull'etichetta
|
||
if (etichetta != 0)
|
||
{
|
||
if (etichetta == row.get_long(5))
|
||
return s.sheet_mask().field(F_S_ETICHETTA).error_box("Etichetta sacca gia' inserita");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (etichetta != 0)
|
||
{
|
||
TLocalisamfile donaz(LF_DONAZ);
|
||
donaz.setkey(5);
|
||
donaz.zero();
|
||
donaz.put(DON_ETICHETTA, etichetta);
|
||
int anno = s.mask().get_date(F_DATADON).year();
|
||
for(donaz.read(); !donaz.eof(); donaz.next())
|
||
{
|
||
const long etic = donaz.get_long(DON_ETICHETTA);
|
||
const TDate datadon = donaz.get_date(DON_DATADON);
|
||
if (etichetta!=etic) break;
|
||
if ((etichetta==etic) && (anno==datadon.year())) return s.sheet_mask().field(F_S_ETICHETTA).error_box("Etichetta sacca gia' inserita");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const char* cognome = row.get(1);
|
||
if ((cognome != NULL) && (cognome != "\0"))
|
||
s.sheet_mask().field(F_S_NOME).set_focusdirty();
|
||
//s.set_focus_cell(r,2);
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TGiornalieroDC::nome_handler(TMask_field& f, KEY k)
|
||
{
|
||
bool ok = TRUE;
|
||
if (f.to_check(k))
|
||
{
|
||
TMask& m = f.mask();
|
||
long codsog = m.get_long(F_S_CODICE);
|
||
if (codsog == 0)
|
||
f.on_key(K_F9);
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TGiornalieroDC::codice_handler(TMask_field& f, KEY k)
|
||
{
|
||
bool ok = TRUE;
|
||
if (f.to_check(k))
|
||
{
|
||
TString256 messaggio = "";
|
||
TMask& m = f.mask();
|
||
long codsog = m.get_long(F_S_CODICE);
|
||
if (codsog != 0)
|
||
{
|
||
TLocalisamfile& sog = app().get_relation()->lfile();
|
||
sog.setkey(1);
|
||
sog.zero();
|
||
sog.put(SOG_CODICE, codsog);
|
||
int err = sog.read();
|
||
if (err == NOERR)
|
||
{
|
||
m.set(F_S_COGNOME, sog.get(SOG_COGNOME));
|
||
m.set(F_S_NOME, sog.get(SOG_NOME));
|
||
m.set(F_S_DATANASC, sog.get(SOG_DATANASC));
|
||
m.set(F_S_TESSAVIS, sog.get(SOG_TESSAVIS));
|
||
m.set(F_S_CODSEZ, sog.get(SOG_CODSEZ));
|
||
m.set(F_S_CODSOT, sog.get(SOG_CODSOT));
|
||
m.set(F_S_CATDON, sog.get(SOG_CATDON));
|
||
if (!(app()._ricerca))
|
||
{
|
||
const int totdon = sog.get_int(SOG_TOTDON);
|
||
if (totdon == 0)
|
||
m.set(F_S_PRIMADON, 'X');
|
||
TTable ctd("CTD");
|
||
ctd.zero();
|
||
ctd.put("CODTAB", sog.get(SOG_CATDON));
|
||
if (ctd.read() == NOERR)
|
||
{
|
||
bool dimissione = ctd.get_bool("B0");
|
||
if (dimissione)
|
||
{
|
||
TString16 catcoll = ctd.get("S6");
|
||
if (catcoll.empty())
|
||
messaggio << "Soggetto dimesso senza categoria collegata\n";
|
||
else
|
||
messaggio << "Soggetto dimesso, cambio categoria automatico\n";
|
||
}
|
||
}
|
||
TString16 stato = sog.get(SOG_STATO);
|
||
char modstato = modstato_tcs(stato);
|
||
if (modstato == 'I' || modstato == 'F') // il soggetto <20> idoneo
|
||
{
|
||
TDate datapros(NULLDATE);
|
||
TString16 tipodon = app().get_mask().get(F_TIPODON);
|
||
TDate datadon = app().get_mask().get_date(F_DATADON);
|
||
if (is_donaz(tipodon,IDON_SI))
|
||
datapros = sog.get_date(SOG_DATAPROSSI);
|
||
else
|
||
datapros = sog.get_date(SOG_DATAPROSAF);
|
||
if (datapros.empty())
|
||
messaggio << "Soggetto non idoneo al tipo donazione\n";
|
||
else
|
||
if (datapros > datadon)
|
||
messaggio << "Il soggetto ha donato prima della scadenza\n";
|
||
}
|
||
else
|
||
messaggio << "Stato soggetto non compatibile con la donazione\n";
|
||
}
|
||
}
|
||
else
|
||
ok = FALSE; // codice non esistente
|
||
}
|
||
if (messaggio.not_empty() && !app()._ricerca && !app()._nomessage)
|
||
f.message_box(messaggio);
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
|
||
int at0200(int argc, char* argv[])
|
||
{
|
||
TGiornalieroDC a;
|
||
a.run(argc, argv, "Giornaliero donazioni/controlli");
|
||
return 0;
|
||
} |