diff --git a/include/modtbapp.cpp b/include/modtbapp.cpp new file mode 100755 index 000000000..a5fe541ab --- /dev/null +++ b/include/modtbapp.cpp @@ -0,0 +1,327 @@ +#include +#include +#include + +// @cmember Costruttore +TTable_module_application::TTable_module_application() + : _msk(NULL), _rel(NULL) +{ } + +// @cmember Distruttore +TTable_module_application::~TTable_module_application() +{ } + +// @cmember Indica se la futura ritornera' una maschera diversa +// dalla corrente. +bool TTable_module_application::changing_mask(int mode) +{ return FALSE; } + +// @cmember Richiede la maschera da usare +TMask* TTable_module_application::get_mask(int mode) +{ + CHECK(_msk, "Null mask"); + return _msk; +} + +// @cmember Ritorna la relazione da modificare +TRelation* TTable_module_application::get_relation() const +{ + CHECK(_rel, "Null relation"); + return _rel; +} + +void TTable_module_application::print() +{ + TString16 cmd; + cmd << "ba3 -1 " << get_tabname(); + TExternal_app stampa(cmd); + stampa.run(); +} + +void TTable_module_application::init_query_mode(TMask& m) +{ + m.enable(-GR_MODIFY_PROTECTED); + m.enable(-GR_RECORD_PROTECTED); +} + +void TTable_module_application::init_modify_mode(TMask& m) +{ + m.disable(-GR_MODIFY_PROTECTED); + const bool enable = !(_rel->curr().get_bool(FPC)); + m.enable(-GR_RECORD_PROTECTED,enable); +} + +bool TTable_module_application::protected_record(TRectype& rec) +{ + return rec.get_bool(FPC); +} + +TString& TTable_module_application::get_mask_name(TString& t) const +{ + CHECK(_rel,"Can't use a NULL relation to retrieve table module"); + TTable& tab = (TTable&) _rel->lfile(); + + TString16 m = _tabname; + if (m[0] == '%') m.ltrim(1); + + t = tab.module(); + t << "tb" << m; + t.lower(); + + TFilename n(t); n.ext("msk"); + if (!n.custom_path()) + t.overwrite("ba"); + return t; +} + +TMask* TTable_module_application::set_mask(TMask* m) +{ + if (_msk != NULL) + { + delete _msk; + _msk = NULL; + } + + if (m != NULL) + { + // imposta la maschera come maschera della applicazione + _msk = m; + } + else + { + // alloca la maschera standard come maschera della applicazione + TFilename name; get_mask_name(name); name.ext("msk"); + if (name.custom_path()) + _msk = new TMask(name); + else + error_box(FR("Impossibile trovare la maschera %s"), (const char*)name); + } + return _msk; +} + +bool TTable_module_application::user_create() +{ + if (argc() < 3) + return false; + + _tabname = argv(2); + _tabname.upper(); + _rel = new TRelation(_tabname); + + if (set_mask() == NULL) + return false; + + const int campi = _msk->fields(); + for (int i = 0; i < campi; i++) + { + const TMask_field& f = _msk->fld(i); + if (f.in_group(GR_SEARCH)) + { + set_search_field(f.dlg()); + break; + } + } + + TFilename rpt; get_mask_name(rpt); rpt.ext("rpt"); + if (rpt.custom_path()) + enable_menu_item(M_FILE_PRINT); + + TString title; + _msk->get_caption(title); + set_title(title); + return TRUE; +} + +bool TTable_module_application::user_destroy() +{ + if (_msk) delete _msk; + if (_rel) delete _rel; + + return TRUE; +} + +/////////////////////////////////////////////////// +// Tabelle Multirel +/////////////////////////////////////////////////// + +// @cmember Indica se la futura ritornera' una maschera diversa +// dalla corrente. +bool TMultirel_application::changing_mask(int mode) +{ return false; } + +// @cmember Richiede la maschera da usare +TMask* TMultirel_application::get_mask(int mode) +{ + CHECK(_msk, "Null mask"); + return _msk; +} + +// @cmember Ritorna la relazione da modificare +TRelation* TMultirel_application::get_relation() const +{ + CHECK(_rel, "Null relation"); + return _rel; +} + +void TMultirel_application::print() +{ + TString16 tabname; + get_mask_name(tabname); + TString cmd; + cmd << "ba8 -4 "<< tabname; + TExternal_app stampa(cmd); + stampa.run(); +} + +void TMultirel_application::get_mask_name(TString& tabname) const +{ + tabname = name().left(4); + tabname << _tabname; +} + +bool TMultirel_application::find(word k) +{ + bool ok = TRelation_application::find(k); + + if (!ok && k < 2) + { + file().setkey(1); + file().zero(); + for (TEditable_field* e = get_mask()->get_key_field(1, true); e; e = get_mask()->get_key_field(1, false)) + { + if (e->shown() || e->ghost()) // Ignora campi invisibili non ghost + e->autosave(*get_relation()); + } + + TRectype rec(file().curr()); + ok = file().read(_isequal) == NOERR; + } + + return ok; +} + +void TMultirel_application::init_insert_mode(TMask& m) +{ + TLocalisamfile multi(LF_MULTIREL); + + file().curr().zero(); + for (TEditable_field* e = get_mask()->get_key_field(1, true); e; e = get_mask()->get_key_field(1, false)) + { + if ((!e->in_group(1)) && (e->shown() || e->ghost())) + e->autosave(*get_relation()); + } + + multi.curr() = file().curr(); + if (multi.read(_isgteq) == NOERR && multi.curr() == file().curr()) + set_descr(m, multi.get("DATA")); + for (int i = m.fields() - 1; i >= 0; i--) + { + TMask_field& c = m.fld(i); + + if (c.in_group(1)) + { + c.enable(); + if (c.is_edit()) + { + TEdit_field& e = (TEdit_field&)c; + + if (e.browse() != NULL) + e.enable_check(); + } + } + } +} + +void TMultirel_application::init_modify_mode(TMask& m) +{ + for (int i = m.fields() - 1; i >= 0; i--) + { + TMask_field& c = m.fld(i); + + if (c.in_group(1)) + { + c.enable(); + _second = c.get(); + if (c.is_edit()) + { + TEdit_field& e = (TEdit_field&)c; + + if (e.browse() != NULL) + e.enable_check(); + } + } + } +} + +int TMultirel_application::rewrite(const TMask& m) +{ + int err = TRelation_application::rewrite(m); + + if (err != NOERR) + err = TRelation_application::write(m); + + TRelation & rel = *get_relation(); + const TString & second = rel.lfile().get("SECOND"); + + if (err == NOERR && second != _second) + { + + rel.save_status(); + rel.lfile().put("SECOND", _second); + rel.remove(); + rel.restore_status(); + } + return err; +} + +bool TMultirel_application::user_create() +{ + if (argc() < 3) + return false; + + _tabname = argv(2); + _tabname.upper(); + _rel = new TRelation(LF_MULTIREL); + + //costruisce il nome della maschera interessata + //nome modulo + 'ts' + nome tabella + TString16 tabname; + get_mask_name(tabname); + _msk = new TMask(tabname); + + FOR_EACH_MASK_FIELD((*_msk), i, f) + { + if (f->in_key(1) && !f->in_group(1)) + { + set_search_field(f->dlg()); + break; + } + } + + TFilename rep = tabname; + rep.ext("rep"); + if (rep.custom_path()) + enable_menu_item(M_FILE_PRINT); + + TString title; + _msk->get_caption(title); + set_title(title); + return true; +} + +bool TMultirel_application::user_destroy() +{ + if (_msk) delete _msk; + if (_rel) delete _rel; + + return true; +} + +// @cmember Costruttore +TMultirel_application::TMultirel_application() + : _msk(NULL), _rel(NULL) +{ } + +// @cmember Distruttore +TMultirel_application::~TMultirel_application() +{ } diff --git a/include/modtbapp.h b/include/modtbapp.h new file mode 100755 index 000000000..d6435a0de --- /dev/null +++ b/include/modtbapp.h @@ -0,0 +1,130 @@ +#ifndef __MODTBAPP_H +#define __MODTBAPP_H + +#ifndef __RELAPP_H +#include +#endif +#ifndef __DEFTABAP_H +#include +#endif + +#define FPC "FPC" + +// @doc EXTERNAL + +// @class Tab_application | Classe per la definizione della per le tabelle +// +// @base public | TRelation_application +class TTable_module_application : public TRelation_application + +// @author:(INTERNAL) Nicola +// @access:(INTERNAL) Private Member +{ + // @cmember:(INTERNAL) Maschera corrente dell'applicazione + TMask* _msk; + // @cmember:(INTERNAL) Relazione corrente dell'applicazione + TRelation* _rel; + // @cmember:(INTERNAL) Nome della tabella da utilizzare + TString _tabname; + +// @access Protected Member +protected: + + // @cmember Richiede se il record corrente e' protetto (non cancellabile) + virtual bool protected_record(TRectype& rec); + // @cmember Richiede la maschera da usare + virtual TMask* get_mask(int mode = MODE_QUERY); + // @cmember Indica se la futura ritornera' una maschera diversa + // dalla corrente. + virtual bool changing_mask(int mode); + // @cmember Ritorna la relazione da modificare + virtual TRelation* get_relation() const; + // @cmember Inizializza la maschera per il modo ricerca + virtual void init_query_mode(TMask& m); + // @cmember Inizializza la maschera per il modo modifica + virtual void init_modify_mode(TMask& m); + // @cmember Inizializzazione dei dati dell'utente + virtual bool user_create() ; + // @cmember Distruzione dei dati dell'utente + virtual bool user_destroy() ; + // @cmember Chiama il programma di stampa + virtual void print(); + // Nuovi membri: + // @cmember Ritorna il nome della maschera associata + virtual TString& get_mask_name(TString& name) const; + // @cmember imposta la maschera (se non indicata, usa le convenzioni di default) ed eventualmente disalloca quella usata in precedenza + virtual TMask* set_mask(TMask* mask = NULL); + +// @access Public Member +public: + // @cmember Ritorna il nome della tabella + const TString& get_tabname() const + { return _tabname; } + + // @cmember Costruttore + TTable_module_application(); + // @cmember Distruttore + virtual ~TTable_module_application(); +}; + +/////////////////////////////////////////////////////////////// +// Tabelle multirel +/////////////////////////////////////////////////////////////// +// @class TMultirel_application | Classe per la definizione della per le tabelle +// +// @base public | TRelation_application +class TMultirel_application : public TRelation_application + +// @author:(INTERNAL) Vari +// @access:(INTERNAL) Private Member +{ + // @cmember:(INTERNAL) Maschera corrente dell'applicazione + TMask* _msk; + // @cmember:(INTERNAL) Relazione corrente dell'applicazione + TRelation* _rel; + // @cmember:(INTERNAL) Nome della tabella da utilizzare + TString _tabname; + // @cmember:(INTERNAL) valore iniziale campo collegato + TString _second; + +// @access Protected Member +protected: + + virtual void get_mask_name(TString& tabname) const; + // @cmember Richiede la maschera da usare + virtual TMask* get_mask(int mode = MODE_QUERY); + // @cmember Indica se la futura ritornera' una maschera diversa + // dalla corrente. + virtual bool changing_mask(int mode); + // @cmember Ritorna la relazione da modificare + virtual TRelation* get_relation() const; + // @cmember Inizializza la maschera per il modo inserimento + virtual void init_insert_mode(TMask& m); + // @cmember Inizializza la maschera per il modo modifica + virtual void init_modify_mode(TMask& m); + // @cmember Inizializzazione dei dati dell'utente + virtual bool user_create() ; + // @cmember Distruzione dei dati dell'utente + virtual bool user_destroy() ; + // @cmember Chiama il programma di stampa + virtual void print(); + // @cmember Riscrive sulla relazione i valori dalla maschera

+ virtual int rewrite(const TMask& m); + // @cmember imposta sulla maschera la descrizione + virtual void set_descr(TMask & m, const TString & desc) {} + +// @access Public Member +public: + // @cmember Ritorna il nome della tabella + const TString& get_tabname() const + { return _tabname; } + virtual bool find(word key = 0); + + // @cmember Costruttore + TMultirel_application(); + // @cmember Distruttore + virtual ~TMultirel_application(); +}; + +#endif + diff --git a/include/tabmod.cpp b/include/tabmod.cpp new file mode 100755 index 000000000..f0d4bf276 --- /dev/null +++ b/include/tabmod.cpp @@ -0,0 +1,299 @@ +#include +#include +#include + +#include +#include +#include +#include + + +TModule_table::TModule_table(const char* tabname, const char * module, long customer) +: TLocalisamfile(LF_TABGEN), _tabname(tabname), _module(module), _customer(customer) +{ + TFilename app = main_app().argv(0); app.ext(""); + const TString16 appname = app.name(); + + if (_module.blank()) + _module = appname.left(2); + + _tabname.upper(); + _module.lower(); + if (_customer == 0L && real::is_natural(app.mid(3))) + _customer = atol(app.mid(2)); + + _des_mod_loaded = FALSE; +} + // @cmember Vuota tutto il record usando il carattere

+void TModule_table::zero(char c) +{ + zero(curr(), c); +} + +void TModule_table::zero(TRectype & rec, char c) +{ + rec.zero(c); + rec.put("COD", _tabname); + rec.put("MOD", _module); + rec.put("CUST", _customer); +} + +bool TModule_table::in_table() const +{ + const TRectype & rec = curr(); + return _tabname == rec.get("COD") && _module == rec.get("MOD") && _customer == rec.get_long("CUST"); +} + +int TModule_table::skip(TRecnotype nrec, word lockop) + +{ + if (!nrec) return NOERR; + TBaseisamfile::skip(nrec, lockop); + if (not_in_table()) + { + if (nrec > 0) + { + if (lockop == _lock) + TBaseisamfile::reread(_unlock); + last(lockop); + setstatus(_iseof); + } + else + { + if (lockop == _lock) + TBaseisamfile::reread(_unlock); + first(lockop); + setstatus(_isbof); + } + } + return status(); +} + + +int TModule_table::_read(TRectype& rec, word op, word lockop) + +{ + + if (op == _isfirst) + { + zero(rec); + TBaseisamfile::_read(rec, _isgteq, lockop); + + if (not_in_table()) + setstatus(_isemptyfile); + if (bad()) + zero(rec); + } + else + if (op == _islast) + { + zero(rec); + put("CODTAB", "\xFF"); + TBaseisamfile::_read(rec, _isgteq); + if (!eof()) + TBaseisamfile::_read(rec, _isprev, lockop); + else + setstatus(NOERR); + if (bof()) + setstatus(NOERR); + if (not_in_table()) + setstatus(_isemptyfile); + if (bad()) + zero(rec); + } + else + if (op == _isprev) + { + const TRecnotype nrec = recno(); + + TBaseisamfile::_read(rec, _isprev, lockop); + if (not_in_table()) + { + if (lockop == _lock) reread(_unlock); + readat(rec, nrec, lockop); + setstatus(_isbof); + } + } + else + if (op == _isnext) + { + const TRecnotype nrec = recno(); + + TBaseisamfile::_read(rec, _isnext, lockop); + if (not_in_table()) + { + if (lockop == _lock) reread(_unlock); + readat(rec, nrec, lockop); + setstatus(_iseof); + } + } + else + { + rec.put("COD", _tabname); + rec.put("MOD", _module); + rec.put("CUST", _customer); + TBaseisamfile::_read(rec, op, lockop); + if (not_in_table()) + { + if (lockop == _lock) reread(_unlock); + last(lockop); + setstatus(_iseof); + } + } + return status(); +} + +int TModule_table::_readat(TRectype& rec ,TRecnotype nrec, word lockop) +{ + TBaseisamfile::_readat(rec, nrec, lockop); + CHECKS(in_table(), "Invalid position : Table ", (const char *)_tabname); + return status(); +} + +bool TModule_table::empty() +{ + return read(_isfirst) != NOERR; +} + +void TModule_table::load_module_description() +{ + // Setta il modulo al quale appartiene la tabella e la relativa descrizione. + // Cerca prima in RECDESC il relativo file di descrizione: D.DES + // Se il file esiste, se il paragrafo [TabDescr] esiste e se esiste la + // variabile Module ne prende il valore. + // Se non si verificano le suddette condizioni procede come segue: + // cerca se esiste il file ??.MSK tramite la funzione list_files(), + // ne estrae il module dai primi 2 caratteri e la descrizione dalla intestazione + // della prima pagina. + _des_mod_loaded = TRUE; + TFilename n; + n << "recdesc/d" << _tabname; + n.ext("des"); + n.lower(); + if (n.exist()) + { + TConfig des(n, "TabDescr"); + _module = des.get("Module"); + } + n = "??tb"; + n << _tabname; + n.ext("msk"); + n.lower(); + + TString_array f; + if (list_files(n, f) == 1) + { + n = f.row(0); + if (!n.exist()) + n.overwrite("ba",0); + if (n.exist()) + { + if (_module.empty()) + { + _module = n.left(2); + _module.lower(); + } + TScanner m(n); + bool ok = TRUE; + while (ok) + { + const TString& l2 = m.line().left(2); + if (l2.empty()) + ok = FALSE; + else + if (l2 == "PA") + break; + } + if (ok) + { + const int apicia = m.token().find('"')+1; + const int apicic = m.token().find('"', apicia); + _description = m.token().sub(apicia, apicic); + } + } + else + _module = "ba"; + } + else + _module = "ba"; +} + +const char* TModule_table::module() +{ + if (!_des_mod_loaded) + load_module_description(); + return _module; +} + +const char* TModule_table::description() +{ + if (!_des_mod_loaded) + load_module_description(); + return _description; +} + +struct TCallbackTableinfo +{ + TString16 _var1, _var2, _var3; + TString4 _module; + TFilename _tabapp, _relapp; +}; + +HIDDEN int find_relapp(TConfig& cfg, void* jolly) +{ + TCallbackTableinfo& info = *((TCallbackTableinfo*)jolly); + + if (cfg.exist(info._var1)) + { + info._tabapp = cfg.get(info._var1); + if (info._tabapp.not_empty()) + return 1; + } + if (cfg.get_paragraph().compare(info._module, 2, TRUE) == 0) + { + if (cfg.exist(info._var2)) + { + info._relapp = cfg.get(info._var2); + if (info._relapp.not_empty()) + return 2; + } + if (cfg.exist(info._var3)) + { + info._relapp = cfg.get(info._var3); + if (info._relapp.not_empty()) + return 3; + } + } + return 0; +} + +bool TModule_table::get_relapp(TString& app) const +{ + TConfig ini("install.ini"); + TCallbackTableinfo fi; + fi._var1.format("Edit_%s", (const char*)_tabname); + fi._var2.format("Edit_%d", num()); + fi._var3.format("Edit_%d", num() == LF_TAB ? LF_TABCOM : LF_TAB); + fi._module = ((TModule_table*)this)->module(); + ini.for_each_paragraph(find_relapp, &fi); + + app = fi._tabapp; + if (app.empty()) + app = fi._relapp; + if (app.empty()) + { + app = "ba3 -0"; + if (fi._module.compare("ba", 2, TRUE) != 0) + { + TConfig c(CONFIG_STUDIO, fi._module); + if (c.exist("TabPrg")) + app = c.get("TabPrg"); + } + } + app << ' '; + if (num() == LF_TABCOM) + app << '%'; + app << _tabname; + return app.not_empty(); +} + diff --git a/include/tabmod.h b/include/tabmod.h new file mode 100755 index 000000000..81081cd46 --- /dev/null +++ b/include/tabmod.h @@ -0,0 +1,74 @@ +#ifndef __TABMOD_H +#define __TABMOD_H + +#ifndef __ISAM_H +#include +#endif + +// @doc EXTERNAL + +// @class TModule_table | Classe per la descrizione delle tabelle +// +// @base public | TLocalisamfile +class TModule_table : public TLocalisamfile + +// @author:(INTERNAL) Alex + +// @access:(INTERNAL) Private Member +{ + // @cmember:(INTERNAL) Nome della tabella + TString4 _tabname; + // @cmember:(INTERNAL) Modulo della tabella + TString4 _module; + // @cmember:(INTERNAL) cliente + long _customer; + // @cmember:(INTERNAL) Descrizione della tabella + TString _description; + // @cmember:(INTERNAL) Flag che indica l'avvenuto caricamento di descrizione e modulo + bool _des_mod_loaded; + +// @access Protected Member +protected: + void load_module_description(); + // @cmember Legge il record e lo copia in

(vedi e ) + virtual int _read(TRectype& rec, word op = _isequal, word lockop = _nolock); + // @cmember Legge il record alla posizione

e lo copia in

(vedi ) + virtual int _readat(TRectype& rec, TRecnotype nrec, word lockop = _nolock); + // @cmember Testa se il record fa parte della tabella + bool in_table() const ; + // @cmember Testa se il record fa non parte della tabella + bool not_in_table() const { return !in_table(); } + + // @access Public Member +public: + // @cmember Salta

record dalla posizione corrente + virtual int skip(TRecnotype nrec, word lockop = _nolock); + // @cmember Controlla se si tratta di una tabella (ritorna sempre TRUE) + virtual bool tab() const { return true; } + // @cmember Ritorna il nome della tabella + virtual const char* name() const { return _tabname;} + // @cmember Ritorna il modulo al quale appartiene la tabella + const char* module(); + // @cmember Ritorna la descrizione della tabella + virtual const char* description(); + // @controlla se la tabella e' vuota + virtual bool empty(); + // @cmember Ritorna la relapp che gestisce la tabella + virtual bool get_relapp(TString& app) const; + // @cmember Vuota tutto il record usando il carattere

+ virtual void zero(char c = '\0'); + // @cmember Vuota tutto il record passato usando il carattere

+ void zero(TRectype & rec, char c = '\0'); + + + // @cmember Ritorna il numero logico della tabella

+ static int name2log(const char* tabname) { return LF_TABGEN;} + + // @cmember Costruttore + TModule_table(const char* tabname, const char * module = NULL, long customer = 0L); + // @cmember Distruttore + virtual ~TModule_table() {} +}; + + +#endif // __TABUTIL_H