campo-sirio/ba/ba3100.cpp
guy 55394b9fac ba1301 Tolta cgettime da programma di test isam
ba3100 Corretta gestione bottone di configurazione stampa registri
bacnvid Aggiunti controlli sui files senza tracciato
batbreg Aggiunto acceleratore alt-s sul bottone di configurazione stampante


git-svn-id: svn://10.65.10.50/trunk@1546 c028cbd2-c16b-5b4b-a496-9718f37d4682
1995-07-03 16:16:48 +00:00

200 lines
5.0 KiB
C++
Executable File

#include <config.h>
#include <printer.h>
#include <tabapp.h>
#include <tabutil.h>
#include "batbreg.h"
#define F_TIPODEL 133 // attenzione estratto da batbdel.h . Tenerlo aggiornato !!!!
#define F_IMPORTO 140 // attenzione estratto da batbdel.h . Tenerlo aggiornato !!!!
#define REG_JOURNAL 5
class TGeneric_table_app : public Tab_application
{
long _oldditta;
int _oldanno;
bool _exist_journal;
bool _stampa_intest;
protected: // TRelation_application
virtual bool user_create() ;
virtual bool protected_record(TRectype& rec) ;
virtual void init_insert_mode(TMask& m) ;
virtual void init_modify_mode(TMask& m);
virtual int write(TMask& m);
public:
bool exist_journal() {return _exist_journal;}
TGeneric_table_app() : _exist_journal(FALSE), _stampa_intest(FALSE) {}
virtual ~TGeneric_table_app() {}
};
HIDDEN inline TGeneric_table_app& app() { return (TGeneric_table_app&) main_app();}
void TGeneric_table_app::init_insert_mode(TMask& m)
{
if (get_tabname() == "REG")
{
const long ditta = get_firm();
const int anno = atoi(m.get(F_ANNO));
m.set(F_STAMPA_INTESTAZIONE, _stampa_intest ? "X" : "");
if (ditta != _oldditta || anno != _oldanno)
{
_oldditta = ditta;
_oldanno = anno;
TTable reg(get_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 TGeneric_table_app::init_modify_mode(TMask& m)
{
Tab_application::init_modify_mode(m);
if (get_tabname() == "REG")
{
TString16 config;
config.format("REG%05ld", m.get_long(F_CODDITTA));
config << m.get(F_CODICE);
TConfig ini(CONFIG_STAMPE, config);
const int what = ini.get_int("Type", NULL, -1, -1);
m.set(F_CONFIG, what >= 0 ? "X" : "");
m.enable(F_CONFIG, what >= 0);
}
}
bool TGeneric_table_app::protected_record(TRectype& rec)
{
bool prot = rec.get_bool(FPC);
if (!prot)
{
if (get_tabname() == "%IVD") // Impedisce la cancellazione di una classe se ha sottoclassi
{
TLocalisamfile& f = get_relation()->lfile();
const TRecnotype pos = f.recno();
const TString16 cod(rec.get("CODTAB"));
const int err = f.next();
if (err == NOERR)
{
TString16 next(f.get("CODTAB")); next.cut(cod.len());
prot = cod == next;
}
f.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;
}
HIDDEN bool printer_handler(TMask_field& f, KEY k)
{
if (k == K_SPACE)
{
TMask& m = f.mask();
TString16 config;
config.format("REG%05ld", m.get_long(F_CODDITTA));
config << m.get(F_CODICE);
if (config.len() == 11)
{
TPrinter& p = printer();
p.set_printtype(normprinter); // Force configuration update
p.read_configuration(config);
if (p.set())
{
m.enable(F_CONFIG);
m.set(F_CONFIG, "X");
}
p.read_configuration();
}
else
return error_box("Nessun registro selezionato");
}
return TRUE;
}
HIDDEN bool impdel_handler(TMask_field& f, KEY k)
{
const TMask & m = f.mask();
if (!m.query_mode() && k == K_ENTER)
{
const int tipo_del = m.get_int(F_TIPODEL);
if (tipo_del == 1 || tipo_del == 7)
{
const double lim[2] = { 50000.0, 200000.0};
const int t = tipo_del == 1 ? 0 : 1;
const real imp(m.get(F_IMPORTO));
if (imp < lim[t])
return yesno_box("Importo inferiore a Lit. %s. Registrare ugualmente?", real(lim[t]).string("."));
}
}
return TRUE;
}
bool TGeneric_table_app::user_create()
{
Tab_application::user_create();
const TString& name = get_tabname();
TMask& mask = *get_mask();
if (name == "REG")
{
mask.set_handler(F_TIPO, tiporeg_handler);
mask.set_handler(F_PRINTER, printer_handler);
TConfig st(CONFIG_STUDIO, "cg");
_stampa_intest = st.get_bool("StiReg");
}
if (name == "%DEL")
mask.set_handler(F_IMPORTO, impdel_handler);
return TRUE;
}
int TGeneric_table_app::write(TMask& m)
{
if (get_tabname() == "REG" && !m.get_bool(F_CONFIG))
{
TString16 config;
config.format("REG%05ld", m.get_long(F_CODDITTA));
config << m.get(F_CODICE);
TConfig ini(CONFIG_STAMPE, config);
const int what = ini.get_int("Type", NULL, -1, -1);
if (what >= 0)
ini.set("Type", -1);
}
return Tab_application::write(m);
}
int ba3100(int argc, char* argv[])
{
TGeneric_table_app a ;
a.run(argc, argv, "Tabella");
return 0;
}