153 lines
3.7 KiB
C++
Executable File
153 lines
3.7 KiB
C++
Executable File
#include <relapp.h>
|
|
#include <stdtypes.h>
|
|
#include <tabutil.h>
|
|
#include <execp.h>
|
|
#include <utility.h>
|
|
|
|
#include "ba3.h"
|
|
#include "ba3100.h"
|
|
#include "batbreg.h"
|
|
|
|
#define FPC "FPC"
|
|
#define REG_JOURNAL 5
|
|
|
|
class BA3100_application : public TRelation_application
|
|
{
|
|
TMask* _msk;
|
|
TRelation* _rel;
|
|
TString _tabname;
|
|
long _oldditta;
|
|
int _oldanno;
|
|
bool _exist_journal;
|
|
|
|
bool user_create() ;
|
|
bool user_destroy() ;
|
|
virtual bool protected_record(const TRectype& rec);
|
|
virtual TMask* get_mask( int mode) { return _msk;}
|
|
virtual bool changing_mask( int mode) { return FALSE;}
|
|
virtual TRelation* get_relation() const { return _rel;}
|
|
virtual void init_query_mode(TMask& m);
|
|
virtual void init_insert_mode(TMask& m);
|
|
virtual void init_modify_mode(TMask& m);
|
|
|
|
public:
|
|
BA3100_application(const char* tabname) : _tabname(tabname) , _oldditta(-1), _oldanno(-1), _exist_journal(FALSE) {}
|
|
virtual ~BA3100_application() {}
|
|
bool exist_journal() {return _exist_journal;}
|
|
void print();
|
|
};
|
|
|
|
void BA3100_application::print()
|
|
{
|
|
#if XVT_OS == XVT_OS_WIN
|
|
TExternal_app stampa(format("ba3a -1 %s", (const char *) _tabname));
|
|
#else
|
|
TExternal_app stampa(format("ba3 -1 %s", (const char *) _tabname));
|
|
#endif
|
|
stampa.run();
|
|
}
|
|
|
|
void BA3100_application::init_query_mode(TMask& m)
|
|
|
|
{
|
|
m.send_key(K_SHIFT + K_CTRL + 'e', -GR_MODIFY_PROTECTED);
|
|
m.send_key(K_SHIFT + K_CTRL + 'e', -GR_RECORD_PROTECTED);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
void BA3100_application::init_modify_mode(TMask& m)
|
|
|
|
{
|
|
m.send_key(K_SHIFT + K_CTRL + 'd', -GR_MODIFY_PROTECTED);
|
|
const bool enable = !(_rel->curr().get_bool(FPC));
|
|
|
|
m.send_key(K_SHIFT + K_CTRL + 'd' + enable, -GR_RECORD_PROTECTED);
|
|
}
|
|
|
|
bool BA3100_application::protected_record(const 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) &&
|
|
((BA3100_application*) MainApp())->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()
|
|
{
|
|
_tabname.upper();
|
|
TString m(16); m << "BATB" << _tabname;
|
|
_msk = new TMask(m) ;
|
|
for (int i = 0; i < _msk->fields(); i++)
|
|
if (_msk->fld(i).in_group(GR_SEARCH))
|
|
{
|
|
set_search_field(_msk->fld(i).dlg());
|
|
break;
|
|
}
|
|
_rel = new TRelation(_tabname);
|
|
set_title(_msk->get_caption());
|
|
if (_tabname == "REG") _msk->set_handler(F_TIPO, tiporeg_handler);
|
|
return TRUE;
|
|
}
|
|
|
|
bool BA3100_application::user_destroy()
|
|
{
|
|
delete _msk;
|
|
delete _rel;
|
|
return TRUE;
|
|
}
|
|
|
|
int ba3100(int argc, char* argv[])
|
|
{
|
|
BA3100_application a(argv[2]) ;
|
|
a.run(argc, argv, "Tabella");
|
|
return 0;
|
|
}
|