046e2c06cb
Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 848 git-svn-id: svn://10.65.10.50/trunk@14993 c028cbd2-c16b-5b4b-a496-9718f37d4682
284 lines
5.6 KiB
C++
Executable File
284 lines
5.6 KiB
C++
Executable File
#include <execp.h>
|
|
#include <tabapp.h>
|
|
#include <tabutil.h>
|
|
|
|
// @cmember Costruttore
|
|
TTable_application::TTable_application()
|
|
: _msk(NULL), _rel(NULL)
|
|
{ }
|
|
|
|
// @cmember Distruttore
|
|
TTable_application::~TTable_application()
|
|
{ }
|
|
|
|
// @cmember Indica se la futura <mf TTable_application::get_mask> ritornera' una maschera diversa
|
|
// dalla corrente.
|
|
bool TTable_application::changing_mask(int mode)
|
|
{ return FALSE; }
|
|
|
|
// @cmember Richiede la maschera da usare
|
|
TMask* TTable_application::get_mask(int mode)
|
|
{
|
|
CHECK(_msk, "Null mask");
|
|
return _msk;
|
|
}
|
|
|
|
// @cmember Ritorna la relazione da modificare
|
|
TRelation* TTable_application::get_relation() const
|
|
{
|
|
CHECK(_rel, "Null relation");
|
|
return _rel;
|
|
}
|
|
|
|
void TTable_application::print()
|
|
{
|
|
TString16 cmd;
|
|
cmd << "ba3 -1 " << get_tabname();
|
|
TExternal_app stampa(cmd);
|
|
stampa.run();
|
|
}
|
|
|
|
void TTable_application::init_query_mode(TMask& m)
|
|
{
|
|
m.enable(-GR_MODIFY_PROTECTED);
|
|
m.enable(-GR_RECORD_PROTECTED);
|
|
}
|
|
|
|
void TTable_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_application::protected_record(TRectype& rec)
|
|
{
|
|
return rec.get_bool(FPC);
|
|
}
|
|
|
|
TString& TTable_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_application::set_mask(TMask* m)
|
|
{
|
|
if (_msk != NULL)
|
|
delete _msk;
|
|
|
|
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);
|
|
_msk = new TMask(name);
|
|
}
|
|
return _msk;
|
|
}
|
|
|
|
bool TTable_application::user_create()
|
|
{
|
|
if (argc() < 3)
|
|
return FALSE;
|
|
|
|
_tabname = argv(2);
|
|
_tabname.upper();
|
|
_rel = new TRelation(_tabname);
|
|
|
|
set_mask();
|
|
|
|
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.exist())
|
|
enable_menu_item(M_FILE_PRINT);
|
|
|
|
TString title;
|
|
_msk->get_caption(title);
|
|
set_title(title);
|
|
return TRUE;
|
|
}
|
|
|
|
bool TTable_application::user_destroy()
|
|
{
|
|
if (_msk) delete _msk;
|
|
if (_rel) delete _rel;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
///////////////////////////////////////////////////
|
|
// Tabelle Multirel
|
|
///////////////////////////////////////////////////
|
|
|
|
// @cmember Indica se la futura <mf TMultirel_application::get_mask> 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)
|
|
{
|
|
for (int i = m.fields() - 1; i >= 0; i--)
|
|
{
|
|
TMask_field& c = m.fld(i);
|
|
if (c.in_group(1) && c.is_edit())
|
|
{
|
|
TEdit_field& e = (TEdit_field&)c;
|
|
|
|
e.enable();
|
|
if (e.browse() != NULL)
|
|
e.enable_check();
|
|
_second = e.get();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
int TMultirel_application::rewrite(const TMask& m)
|
|
{
|
|
int err = TRelation_application::write(m);
|
|
|
|
if (err == NOERR)
|
|
{
|
|
TRelation & rel = *get_relation();
|
|
|
|
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))
|
|
{
|
|
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()
|
|
{ }
|