1998-05-11 09:54:51 +00:00
|
|
|
|
#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 "at1.h"
|
|
|
|
|
|
|
|
|
|
// nomi campi maschera
|
|
|
|
|
#include "at1600a.h"
|
|
|
|
|
|
|
|
|
|
// nomi dei campi
|
|
|
|
|
#include "soggetti.h"
|
|
|
|
|
#include "benem.h"
|
|
|
|
|
|
|
|
|
|
class TBenemVeloce : public TApplication
|
|
|
|
|
{
|
|
|
|
|
TMask* _msk;
|
|
|
|
|
TRelation* _rel;
|
|
|
|
|
|
|
|
|
|
TLocalisamfile* _soggetti;
|
|
|
|
|
TLocalisamfile* _benem;
|
|
|
|
|
TRecord_array* _sbenemerenze;
|
|
|
|
|
// array dei soggetti inseriti per controllare doppio inserimento
|
|
|
|
|
TAssoc_array* _asoggetti;
|
|
|
|
|
bool _modified, _ricerca;
|
|
|
|
|
TDate _databen, _datacon;
|
|
|
|
|
TString16 _tipoben;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TBenemVeloce() {}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
HIDDEN inline TBenemVeloce& app() { return (TBenemVeloce&) main_app(); }
|
|
|
|
|
|
|
|
|
|
void TBenemVeloce::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 TBenemVeloce::create()
|
|
|
|
|
{
|
|
|
|
|
TApplication::create();
|
|
|
|
|
_modified = FALSE;
|
|
|
|
|
_ricerca = FALSE;
|
|
|
|
|
_msk = new TMask("at1600a");
|
|
|
|
|
_rel = new TRelation(LF_SOGGETTI);
|
|
|
|
|
_benem = new TLocalisamfile(LF_BENEM);
|
|
|
|
|
_sbenemerenze = new TRecord_array(LF_BENEM,BEN_PROGBEN);
|
|
|
|
|
_asoggetti = new TAssoc_array();
|
|
|
|
|
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);
|
|
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TBenemVeloce::destroy()
|
|
|
|
|
{
|
1998-08-07 09:47:13 +00:00
|
|
|
|
delete _asoggetti;
|
|
|
|
|
delete _sbenemerenze;
|
|
|
|
|
delete _benem;
|
1998-05-11 09:54:51 +00:00
|
|
|
|
delete _rel;
|
|
|
|
|
delete _msk;
|
|
|
|
|
return TApplication::destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TBenemVeloce::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();
|
|
|
|
|
_databen = msk.get(F_DATABEN);
|
|
|
|
|
_datacon = msk.get(F_DATACON);
|
|
|
|
|
_tipoben = msk.get(F_TIPOBEN);
|
|
|
|
|
switch (tasto)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
case K_F9: // ricerca
|
|
|
|
|
{
|
|
|
|
|
if (_modified)
|
|
|
|
|
if (yesno_box("Registrare le modifiche?"))
|
|
|
|
|
TBenemVeloce::write(s);
|
|
|
|
|
_modified = FALSE;
|
|
|
|
|
// non dovrebbe servire la ricerca
|
|
|
|
|
if (_databen.ok())
|
|
|
|
|
{
|
|
|
|
|
_ricerca = TRUE;
|
|
|
|
|
TBenemVeloce::read(s);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
message_box("Inserire almeno la data attribuzione per effettuare la ricerca");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
case K_ESC: // annulla
|
|
|
|
|
{
|
|
|
|
|
if (_modified)
|
|
|
|
|
if (yesno_box("Registrare le modifiche?"))
|
|
|
|
|
TBenemVeloce::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
|
|
|
|
|
{
|
|
|
|
|
TBenemVeloce::write(s);
|
|
|
|
|
_modified = FALSE;
|
|
|
|
|
//msk.reset(); //verificare se va tolta
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case K_INS: // nuovo
|
|
|
|
|
{
|
|
|
|
|
if (_modified)
|
|
|
|
|
if (yesno_box("Registrare le modifiche?"))
|
|
|
|
|
TBenemVeloce::write(s);
|
|
|
|
|
_modified = FALSE;
|
|
|
|
|
msk.reset();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case K_QUIT: // fine
|
|
|
|
|
{
|
|
|
|
|
if (_modified)
|
|
|
|
|
if (yesno_box("Registrare le modifiche?"))
|
|
|
|
|
TBenemVeloce::write(s);
|
|
|
|
|
msk.reset();
|
|
|
|
|
_modified = FALSE;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (tasto != K_QUIT);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TBenemVeloce::write(TSheet_field& s)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
const TMask& m = s.mask();
|
|
|
|
|
int items = s.items();
|
|
|
|
|
TProgind *pi;
|
|
|
|
|
pi = new TProgind(items,"Registrazione benemerenze", FALSE, TRUE, 10);
|
|
|
|
|
pi->setstatus(1);
|
|
|
|
|
TLocalisamfile& sog = get_relation()->lfile();
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
TRectype* rec = new TRectype(LF_BENEM);
|
|
|
|
|
rec->put(BEN_CODICE, row.get(0));
|
|
|
|
|
TString16 tipoben = row.get(3);
|
|
|
|
|
if (tipoben.blank())
|
|
|
|
|
tipoben = _tipoben;
|
|
|
|
|
rec->put(BEN_TIPOBEN, tipoben);
|
|
|
|
|
rec->put(BEN_DATABEN, _databen);
|
|
|
|
|
rec->put(BEN_DATACON, _datacon);
|
|
|
|
|
rec->put(BEN_CODSEZ,sog.get(SOG_CODSEZ));
|
|
|
|
|
rec->put(BEN_CODSOT,sog.get(SOG_CODSOT));
|
|
|
|
|
bool insert = FALSE;
|
|
|
|
|
bool exist = FALSE;
|
|
|
|
|
TRectype* key = new TRectype(LF_BENEM);
|
|
|
|
|
key->put(BEN_CODICE, row.get(0));
|
|
|
|
|
err = _sbenemerenze->read(key);
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
int r=_sbenemerenze->rows();
|
|
|
|
|
while (r>=1 && !insert && !exist)
|
|
|
|
|
{
|
|
|
|
|
const TRectype& riga = _sbenemerenze->row(r);
|
|
|
|
|
const TString16 b = riga.get(BEN_TIPOBEN);
|
|
|
|
|
if (tipoben==b) // la benemerenza <20> gia' stata inserita
|
|
|
|
|
{
|
|
|
|
|
exist=TRUE;
|
|
|
|
|
r=0;
|
|
|
|
|
}
|
|
|
|
|
r--;
|
|
|
|
|
}
|
|
|
|
|
if (!exist && !insert)
|
|
|
|
|
{
|
|
|
|
|
rec->put(BEN_PROGBEN,_sbenemerenze->rows()+1);
|
|
|
|
|
_sbenemerenze->insert_row(rec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (err == _iseof || err == _isemptyfile)
|
|
|
|
|
{
|
|
|
|
|
rec->put(BEN_PROGBEN,1);
|
|
|
|
|
_sbenemerenze->insert_row(rec);
|
|
|
|
|
}
|
|
|
|
|
if (!exist)
|
|
|
|
|
{
|
|
|
|
|
_sbenemerenze->write(TRUE);
|
|
|
|
|
// 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 TBenemVeloce::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 TBenemVeloce::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);
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
const char* cognome = row.get(1);
|
|
|
|
|
if ((cognome != NULL) && (cognome != "\0"))
|
|
|
|
|
s.sheet_mask().field(F_S_NOME).set_focusdirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TBenemVeloce::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 TBenemVeloce::codice_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)
|
|
|
|
|
{
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ok = FALSE; // codice non esistente
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int at1600(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TBenemVeloce a;
|
|
|
|
|
a.run(argc, argv, "Inserimento veloce benemerenze");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|