1995-01-12 18:36:44 +00:00
|
|
|
#include <execp.h>
|
|
|
|
#include <tabapp.h>
|
1996-11-12 14:53:09 +00:00
|
|
|
#include <tabutil.h>
|
|
|
|
|
|
|
|
// @cmember Costruttore
|
1999-02-02 08:43:43 +00:00
|
|
|
TTable_application::TTable_application()
|
1996-11-12 14:53:09 +00:00
|
|
|
: _msk(NULL), _rel(NULL)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// @cmember Distruttore
|
1999-02-02 08:43:43 +00:00
|
|
|
TTable_application::~TTable_application()
|
1996-11-12 14:53:09 +00:00
|
|
|
{ }
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
// @cmember Indica se la futura <mf TTable_application::get_mask> ritornera' una maschera diversa
|
1996-11-12 14:53:09 +00:00
|
|
|
// dalla corrente.
|
1999-02-02 08:43:43 +00:00
|
|
|
bool TTable_application::changing_mask(int mode)
|
1996-11-12 14:53:09 +00:00
|
|
|
{ return FALSE; }
|
|
|
|
|
|
|
|
// @cmember Richiede la maschera da usare
|
1999-02-02 08:43:43 +00:00
|
|
|
TMask* TTable_application::get_mask(int mode)
|
1996-11-12 14:53:09 +00:00
|
|
|
{
|
|
|
|
CHECK(_msk, "Null mask");
|
|
|
|
return _msk;
|
|
|
|
}
|
|
|
|
|
|
|
|
// @cmember Ritorna la relazione da modificare
|
1999-02-02 08:43:43 +00:00
|
|
|
TRelation* TTable_application::get_relation() const
|
1996-11-12 14:53:09 +00:00
|
|
|
{
|
|
|
|
CHECK(_rel, "Null relation");
|
|
|
|
return _rel;
|
|
|
|
}
|
1995-01-12 18:36:44 +00:00
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
void TTable_application::print()
|
1995-01-12 18:36:44 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
TString16 cmd;
|
|
|
|
cmd << "ba3 -1 " << get_tabname();
|
|
|
|
TExternal_app stampa(cmd);
|
1995-01-12 18:36:44 +00:00
|
|
|
stampa.run();
|
|
|
|
}
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
void TTable_application::init_query_mode(TMask& m)
|
1995-01-12 18:36:44 +00:00
|
|
|
{
|
1996-05-24 13:16:57 +00:00
|
|
|
m.enable(-GR_MODIFY_PROTECTED);
|
|
|
|
m.enable(-GR_RECORD_PROTECTED);
|
1995-01-12 18:36:44 +00:00
|
|
|
}
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
void TTable_application::init_modify_mode(TMask& m)
|
1995-01-12 18:36:44 +00:00
|
|
|
{
|
1996-05-24 13:16:57 +00:00
|
|
|
m.disable(-GR_MODIFY_PROTECTED);
|
1995-01-12 18:36:44 +00:00
|
|
|
const bool enable = !(_rel->curr().get_bool(FPC));
|
1996-05-24 13:16:57 +00:00
|
|
|
m.enable(-GR_RECORD_PROTECTED,enable);
|
1995-01-12 18:36:44 +00:00
|
|
|
}
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
bool TTable_application::protected_record(TRectype& rec)
|
1995-01-12 18:36:44 +00:00
|
|
|
{
|
|
|
|
return rec.get_bool(FPC);
|
|
|
|
}
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
TString& TTable_application::get_mask_name(TString& t) const
|
1997-03-19 08:18:54 +00:00
|
|
|
{
|
1997-08-27 09:53:29 +00:00
|
|
|
CHECK(_rel,"Can't use a NULL relation to retrieve table module");
|
1999-02-02 08:43:43 +00:00
|
|
|
TTable& tab = (TTable&) _rel->lfile();
|
1997-08-29 10:32:49 +00:00
|
|
|
|
|
|
|
TString16 m = _tabname;
|
|
|
|
if (m[0] == '%') m.ltrim(1);
|
1997-08-27 09:53:29 +00:00
|
|
|
|
1997-08-29 10:32:49 +00:00
|
|
|
t = tab.module();
|
|
|
|
t << "tb" << m;
|
2005-04-21 11:08:06 +00:00
|
|
|
t.lower();
|
2001-04-30 15:04:10 +00:00
|
|
|
|
|
|
|
TFilename n(t); n.ext("msk");
|
2005-04-21 11:08:06 +00:00
|
|
|
if (!n.custom_path())
|
2000-05-05 15:25:49 +00:00
|
|
|
t.overwrite("ba");
|
1997-08-29 10:32:49 +00:00
|
|
|
return t;
|
1997-03-19 08:18:54 +00:00
|
|
|
}
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
TMask* TTable_application::set_mask(TMask* m)
|
1997-03-19 08:18:54 +00:00
|
|
|
{
|
1997-08-26 13:56:55 +00:00
|
|
|
if (_msk != NULL)
|
2007-03-16 13:33:09 +00:00
|
|
|
{
|
1997-08-26 13:56:55 +00:00
|
|
|
delete _msk;
|
2007-03-16 13:33:09 +00:00
|
|
|
_msk = NULL;
|
|
|
|
}
|
1997-08-26 13:56:55 +00:00
|
|
|
|
|
|
|
if (m != NULL)
|
|
|
|
{
|
|
|
|
// imposta la maschera come maschera della applicazione
|
|
|
|
_msk = m;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// alloca la maschera standard come maschera della applicazione
|
2007-03-16 13:33:09 +00:00
|
|
|
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);
|
1997-08-26 13:56:55 +00:00
|
|
|
}
|
|
|
|
return _msk;
|
1997-03-19 08:18:54 +00:00
|
|
|
}
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
bool TTable_application::user_create()
|
1995-01-12 18:36:44 +00:00
|
|
|
{
|
|
|
|
if (argc() < 3)
|
2007-03-16 13:33:09 +00:00
|
|
|
return false;
|
1995-01-12 18:36:44 +00:00
|
|
|
|
|
|
|
_tabname = argv(2);
|
|
|
|
_tabname.upper();
|
1996-11-12 14:53:09 +00:00
|
|
|
_rel = new TRelation(_tabname);
|
1997-03-19 08:18:54 +00:00
|
|
|
|
2007-03-16 13:33:09 +00:00
|
|
|
if (set_mask() == NULL)
|
|
|
|
return false;
|
1996-11-12 14:53:09 +00:00
|
|
|
|
|
|
|
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))
|
1995-01-12 18:36:44 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
set_search_field(f.dlg());
|
1995-01-12 18:36:44 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-11-12 14:53:09 +00:00
|
|
|
}
|
1995-01-30 13:46:06 +00:00
|
|
|
|
2007-03-16 13:33:09 +00:00
|
|
|
TFilename rpt; get_mask_name(rpt); rpt.ext("rpt");
|
|
|
|
if (rpt.custom_path())
|
1996-11-12 14:53:09 +00:00
|
|
|
enable_menu_item(M_FILE_PRINT);
|
|
|
|
|
1998-02-24 10:37:28 +00:00
|
|
|
TString title;
|
|
|
|
_msk->get_caption(title);
|
1996-11-12 14:53:09 +00:00
|
|
|
set_title(title);
|
1995-01-12 18:36:44 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
bool TTable_application::user_destroy()
|
1995-01-12 18:36:44 +00:00
|
|
|
{
|
1996-11-12 14:53:09 +00:00
|
|
|
if (_msk) delete _msk;
|
|
|
|
if (_rel) delete _rel;
|
|
|
|
|
1995-01-12 18:36:44 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-01-31 16:16:58 +00:00
|
|
|
///////////////////////////////////////////////////
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2007-03-06 16:37:44 +00:00
|
|
|
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)
|
|
|
|
{
|
2007-03-16 13:33:09 +00:00
|
|
|
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"));
|
2007-03-06 16:37:44 +00:00
|
|
|
for (int i = m.fields() - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
TMask_field& c = m.fld(i);
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
if (c.in_group(1))
|
|
|
|
{
|
|
|
|
c.enable();
|
|
|
|
if (c.is_edit())
|
|
|
|
{
|
|
|
|
TEdit_field& e = (TEdit_field&)c;
|
|
|
|
|
|
|
|
if (e.browse() != NULL)
|
|
|
|
e.enable_check();
|
|
|
|
}
|
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
}
|
2007-03-16 13:33:09 +00:00
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
|
2007-03-16 13:33:09 +00:00
|
|
|
void TMultirel_application::init_modify_mode(TMask& m)
|
|
|
|
{
|
|
|
|
for (int i = m.fields() - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
TMask_field& c = m.fld(i);
|
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2007-03-16 13:33:09 +00:00
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int TMultirel_application::rewrite(const TMask& m)
|
|
|
|
{
|
2007-03-30 13:51:17 +00:00
|
|
|
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");
|
2007-03-06 16:37:44 +00:00
|
|
|
|
2007-03-30 13:51:17 +00:00
|
|
|
if (err == NOERR && second != _second)
|
2007-03-06 16:37:44 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
rel.save_status();
|
|
|
|
rel.lfile().put("SECOND", _second);
|
|
|
|
rel.remove();
|
|
|
|
rel.restore_status();
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
2007-01-31 16:16:58 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2007-03-16 13:33:09 +00:00
|
|
|
if (f->in_key(1) && !f->in_group(1))
|
2007-01-31 16:16:58 +00:00
|
|
|
{
|
|
|
|
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()
|
|
|
|
{ }
|