116 lines
2.6 KiB
C++
Executable File
116 lines
2.6 KiB
C++
Executable File
#include <relapp.h>
|
|
#include <stdtypes.h>
|
|
#include <tabutil.h>
|
|
#include <execp.h>
|
|
#include <utility.h>
|
|
|
|
#include <tabapp.h>
|
|
|
|
#include "batbreg.h"
|
|
|
|
#define REG_JOURNAL 5
|
|
|
|
class BA3100_application : public Tab_application
|
|
{
|
|
TMask* _msk;
|
|
TRelation* _rel;
|
|
TString _tabname;
|
|
long _oldditta;
|
|
int _oldanno;
|
|
bool _exist_journal;
|
|
|
|
virtual bool user_create() ;
|
|
virtual bool user_destroy() ;
|
|
|
|
public:
|
|
virtual void init_insert_mode(TMask& m) ;
|
|
virtual bool protected_record(TRectype& rec) ;
|
|
|
|
bool exist_journal() {return _exist_journal;}
|
|
|
|
BA3100_application() {}
|
|
virtual ~BA3100_application() {}
|
|
};
|
|
|
|
HIDDEN inline BA3100_application& app() { return (BA3100_application&) main_app();}
|
|
|
|
|
|
void BA3100_application::init_insert_mode(TMask& m)
|
|
{
|
|
if (_tabname != "REG") return;
|
|
|
|
long ditta = get_firm();
|
|
int anno = atoi(m.get(F_ANNO));
|
|
|
|
if (ditta != _oldditta || anno != _oldanno)
|
|
{
|
|
_oldditta = ditta;
|
|
_oldanno = anno;
|
|
|
|
TTable reg(_tabname);
|
|
|
|
reg.zero();
|
|
reg.put("CODTAB", m.get(F_ANNO));
|
|
|
|
TRectype to(reg.curr());
|
|
_exist_journal = FALSE;
|
|
|
|
for (reg.read(_isgteq); !_exist_journal && reg.good() && reg.curr() <= to; reg.next())
|
|
_exist_journal = (reg.get_long("I0") == REG_JOURNAL);
|
|
}
|
|
}
|
|
|
|
bool BA3100_application::protected_record(TRectype& rec)
|
|
{
|
|
bool prot = rec.get_bool(FPC);
|
|
if (!prot)
|
|
{
|
|
if (_tabname == "%IVD") // Impedisce la cancellazione di una classe se ha sottoclassi
|
|
{
|
|
const TRecnotype pos = _rel->lfile().recno();
|
|
const TString cod(rec.get("CODTAB"));
|
|
const int err = _rel->lfile().next();
|
|
if (err == NOERR)
|
|
{
|
|
TString next(_rel->lfile().get("CODTAB")); next.cut(cod.len());
|
|
prot = cod == next;
|
|
}
|
|
_rel->lfile().readat(pos);
|
|
}
|
|
}
|
|
return prot;
|
|
}
|
|
|
|
HIDDEN bool tiporeg_handler(TMask_field& f, KEY k)
|
|
{
|
|
if ((k == K_TAB || k == K_ENTER) && app().exist_journal() &&
|
|
(atoi(f.get()) == REG_JOURNAL)
|
|
)
|
|
return error_box("Non e' possibile avere due registri giornale nello stesso anno");
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool BA3100_application::user_create()
|
|
{
|
|
Tab_application::user_create();
|
|
_msk = get_mask();
|
|
_tabname = get_tabname();
|
|
if (_tabname == "REG") _msk->set_handler(F_TIPO, tiporeg_handler);
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3100_application::user_destroy()
|
|
{
|
|
if (_msk) delete _msk;
|
|
if (_rel) delete _rel;
|
|
return TRUE;
|
|
}
|
|
|
|
int ba3100(int argc, char* argv[])
|
|
{
|
|
BA3100_application a ;
|
|
a.run(argc, argv, "Tabella");
|
|
return 0;
|
|
}
|