Estesa gestione form e descrizione relazioni

git-svn-id: svn://10.65.10.50/trunk@1404 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 1995-05-29 10:25:10 +00:00
parent e945ac1a8d
commit 2a1027fb60
11 changed files with 790 additions and 651 deletions

View File

@ -38,8 +38,8 @@ ITEM M_EDIT_CUT "~Collega...\tCtrl+C" DISABLED
ITEM M_EDIT_PASTE "~Esporta...\tCtrl+E" ITEM M_EDIT_PASTE "~Esporta...\tCtrl+E"
ITEM M_EDIT_SEL_ALL "~Stampa... \tCtrl+S" DISABLED ITEM M_EDIT_SEL_ALL "~Stampa... \tCtrl+S" DISABLED
SEPARATOR SEPARATOR
ITEM M_FONT "Mostra ~righelli" CHECKABLE ITEM M_SHOW_RULERS "Mostra ~righelli" CHECKABLE
ITEM M_STYLE "Mostra ~bottoni" CHECKABLE ITEM M_SHOW_BUTTONS "Mostra ~bottoni" CHECKABLE
ITEM M_EDIT_UNDO "Ri~disegna" ITEM M_EDIT_UNDO "Ri~disegna"
SEPARATOR SEPARATOR
ITEM M_EDIT_QUIT "Chiudi\tESC+ESC" ITEM M_EDIT_QUIT "Chiudi\tESC+ESC"

View File

@ -76,7 +76,11 @@ int TExternal_app::run(
if (!async) if (!async)
{ {
TTemp_window tw(TASK_WIN); TTemp_window tw(TASK_WIN);
if (utente) tw.iconize(); if (utente)
{
tw.iconize();
tw.deactivate();
}
HTASK child = NULL; HTASK child = NULL;
TASKENTRY te; te.dwSize = sizeof(TASKENTRY); TASKENTRY te; te.dwSize = sizeof(TASKENTRY);
@ -97,7 +101,11 @@ int TExternal_app::run(
xvt_app_process_pending_events(); xvt_app_process_pending_events();
} }
if (utente) tw.maximize(); if (utente)
{
tw.maximize();
tw.activate();
}
} }
xvt_statbar_refresh(); xvt_statbar_refresh();
} }

View File

@ -107,37 +107,31 @@ TDir::TDir () : _num(-1), _com(FALSE)
} }
TDir::~TDir () TDir::~TDir ()
{ {
delete _dir; delete _dir;
} }
const char *TDir::name () const const char *TDir::name () const
{ {
return _dir->SysName; return _dir->SysName;
} }
const char *TDir::des () const const char *TDir::des () const
{ {
return _dir->Des; return _dir->Des;
} }
const char *TDir::tab_des (const char* tab) const const char* TDir::tab_des(const char* tab)
{ {
CHECK (_num > 3 && _num < 7, "Non e' una tabella! Cojon!"); const char* t = tab; if (t[0] == '$' || t[0] == '%') t++;
TString dfile(36); TString256 tmp;
int ind = (tab[0] == '$' || tab[0] == '%') ? 1 : 0; tmp << DESCDIR << "/d" << t << ".des";
dfile << DESCDIR << "/d" << tab+ind << ".des";
if (!fexist(dfile))
return "";
TConfig cnf(dfile, DESCTAB); TConfig cnf(tmp, DESCTAB);
dfile = cnf.get("Description"); t = cnf.get("Description", NULL, -1, tab);
return strcpy(__tmp_string, dfile); return strcpy(__tmp_string, t);
} }

View File

@ -75,7 +75,6 @@ public:
const char* name() const; const char* name() const;
const char* des() const; const char* des() const;
const char* tab_des(const char* tabname) const;
const char* expr() const; const char* expr() const;
TRecnotype& eod() const; TRecnotype& eod() const;
TRecnotype& eox() const; TRecnotype& eox() const;
@ -90,6 +89,8 @@ public:
bool is_valid() {return name()[0] > ' ' && len() > 0;} bool is_valid() {return name()[0] > ' ' && len() > 0;}
bool is_active() const; // valido solo se prefhnd e settato a "" bool is_active() const; // valido solo se prefhnd e settato a ""
static const char* tab_des(const char* tabname);
TDir(); TDir();
virtual ~TDir(); virtual ~TDir();
}; };

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,17 @@
#ifndef __FORM_H #ifndef __FORM_H
#define __FORM_H #define __FORM_H
#ifndef __STRINGS_H
#include <strings.h>
#endif
#ifndef __PRINTER_H #ifndef __PRINTER_H
#include <printer.h> class TPrinter;
class TPrintrow;
#endif #endif
#ifndef __SCANNER_H #ifndef __SCANNER_H
#include <scanner.h> class TScanner;
#endif #endif
#ifndef __MASK_H #ifndef __MASK_H
@ -14,7 +19,7 @@ class TMask;
#endif #endif
#ifndef __ISAM_H #ifndef __ISAM_H
#include <isam.h> class TRectype;
#endif #endif
#ifndef __RELATION_H #ifndef __RELATION_H
@ -28,12 +33,14 @@ enum pagetype { odd_page, even_page, first_page, last_page };
class TForm; class TForm;
class TForm_item; class TForm_item;
class TPrint_section : public TArray class TPrint_section : public TArray
{ {
static TMask* _msk; static TMask* _msk;
word _height; // Altezza della sezione word _height; // Altezza della sezione
int _x, _y; // Offset di stampa int _x, _y; // Offset di stampa
bool _dirty; // Flag di modifica parametri
TForm* _form; // Form cui appartiene alla sezione TForm* _form; // Form cui appartiene alla sezione
pagetype _page_type; // Tipo della pagina pagetype _page_type; // Tipo della pagina
@ -66,9 +73,15 @@ public:
virtual bool update(); virtual bool update();
bool parse(TScanner& scanner); bool parse(TScanner& scanner);
bool edit(const char* title, bool all); bool read_from(const TRectype& rec);
void print_on(TRectype& rec);
bool edit(const char* title);
pagetype page_type() const { return _page_type; } pagetype page_type() const { return _page_type; }
bool dirty() const { return _dirty; }
void set_dirty(bool d = TRUE) { _dirty = d; }
const TPrint_section& operator=(const TPrint_section& ps) { return copy(ps); } const TPrint_section& operator=(const TPrint_section& ps) { return copy(ps); }
TPrint_section(TForm* parent, pagetype pt); TPrint_section(TForm* parent, pagetype pt);
TPrint_section(const TPrint_section& ps) { copy(ps); } TPrint_section(const TPrint_section& ps) { copy(ps); }
@ -80,26 +93,23 @@ class TForm : public TObject
{ {
friend class TForm_editor; friend class TForm_editor;
TFilename _name; // Profile name TString16 _name; // Profile name
TString16 _code; // Profile code long _code; // Profile code
TLocalisamfile _forms; // forms names file
TLocalisamfile _prof; // profile definition file
TRelation* _relation; // Can be NULL TRelation* _relation; // Can be NULL
TCursor* _cursor; // Can be NULL TCursor* _cursor; // Can be NULL
TRelation_description* _reldef; // pure TRelation_description* _rel_desc; // Can be NULL
TArray _head; // Headers TArray _head; // Headers
TArray _body; // Bodies TArray _body; // Bodies
TArray _foot; // Footers TArray _foot; // Footers
TArray _back; // Graphic background TArray _back; // Graphic backgrounds
char _permissions[9]; // user permissions
bool _lastpage; // I am about to print the last page? bool _lastpage; // I am about to print the last page?
bool _isnew; // new form bool _isnew; // new form
bool _isbase; // base form (.frm file) bool _isbase; // base form (.frm file)
int _editlevel; // Edit permission
TString _desc; // form description TString _desc; // form description
TPrint_section* exist(char s, pagetype t, bool create = FALSE); // Can be NULL TPrint_section* exist(char s, pagetype t, bool create = FALSE); // Can be NULL
@ -114,12 +124,12 @@ protected:
void print_section(ostream& out, char s) const; void print_section(ostream& out, char s) const;
virtual void print_on(ostream& out) const; virtual void print_on(ostream& out) const;
bool edit_relation();
bool parse_use(TScanner&); bool parse_use(TScanner&);
bool parse_join(TScanner&); bool parse_join(TScanner&);
bool parse_permissions(TScanner&);
bool parse_descfield(TScanner&); bool parse_description(TScanner&);
void print_description(ostream& out) const;
bool read_profile(); bool read_profile();
bool write_profile(); bool write_profile();
@ -133,18 +143,15 @@ protected:
virtual word set_footer(word p, bool u); virtual word set_footer(word p, bool u);
public: public:
bool has_add_permission() const { return _permissions[0] == 'A'; }
bool has_remove_permission() const { return _permissions[1] == 'R'; }
bool has_modify_permission() const { return _permissions[2] == 'M'; }
bool has_relation_permission() const { return _permissions[3] == 'L'; }
bool print(long from = 0L, long to = -1L); bool print(long from = 0L, long to = -1L);
const TFilename& name() const { return _name; } const TString& name() const { return _name; }
long code() const { return _code; }
bool edit_level() const { return _editlevel; }
TRelation* relation() const { return _relation; } TRelation* relation() const { return _relation; }
TRelation_description* reldef() const { return _reldef; } TRelation_description& rel_desc() const;
TCursor* cursor() const { return _cursor; } TCursor* cursor() const { return _cursor; }
virtual const char* validate(const char* cur, TToken_string& val); virtual const char* validate(const char* cur, TToken_string& val);
@ -153,7 +160,7 @@ public:
// if code == NULL it's a base form // if code == NULL it's a base form
// otherwise it's integrated by a file definition // otherwise it's integrated by a file definition
TForm(const char* form, const char* code = NULL); TForm(const char* form, long code = 0L, int editlevel = 0);
virtual ~TForm(); virtual ~TForm();
}; };

View File

@ -49,11 +49,11 @@
#define LF_QUAA 44 #define LF_QUAA 44
#define LF_DIPEND 45 #define LF_DIPEND 45
#define LF_DETH 46 #define LF_DETH 46
#define LF_PROF 50 #define LF_RFORM 50
#define LF_DESLIN 51 #define LF_DESLIN 51
#define LF_CONTR 52 #define LF_CONTR 52
#define LF_RCONT 53 #define LF_RCONT 53
#define LF_FORMS 54 #define LF_FORM 54
#define LF_GOLEM 55 #define LF_GOLEM 55
#define CNF_GENERAL 10000 #define CNF_GENERAL 10000

View File

@ -1,4 +1,4 @@
// $Id: relation.cpp,v 1.41 1995-05-18 14:17:58 guy Exp $ // $Id: relation.cpp,v 1.42 1995-05-29 10:24:58 guy Exp $
// relation.cpp // relation.cpp
// fv 12/8/93 // fv 12/8/93
// relation class for isam files // relation class for isam files
@ -12,10 +12,10 @@
#include <extcdecl.h> #include <extcdecl.h>
#include <prefix.h> #include <prefix.h>
#include <relation.h> #include <relation.h>
#include <sheet.h>
#include <tabutil.h> #include <tabutil.h>
#include <utility.h> #include <utility.h>
#include <xvtility.h> #include <xvtility.h>
#include <sheet.h>
// *** check if not already defined // *** check if not already defined
#define NOTFOUND (-1) #define NOTFOUND (-1)
@ -30,16 +30,21 @@ HIDDEN const char* field_type_str(TFieldtypes f)
const char* c = ""; const char* c = "";
switch(f) switch(f)
{ {
case _realfld: c = "Reale"; break; case _charfld:
case _datefld: c = "Data"; break; c = "Carattere"; break;
case _charfld: c = "Carattere"; break; case _realfld:
case _boolfld: c = "Logico"; break; c = "Reale"; break;
case _wordfld: case _datefld:
case _intzerofld: c = "Data"; break;
case _longzerofld: case _boolfld:
case _intfld: c = "Logico"; break;
case _longfld: c = "Intero"; break; // case _wordfld:
default: break; // case _intzerofld:
// case _longzerofld:
// case _intfld:
// case _longfld:
default:
c = "Intero"; break;
} }
return c; return c;
} }
@ -62,17 +67,14 @@ class TRelationdef : public TObject
TArray _exprs; // Condizioni di uguaglianza TArray _exprs; // Condizioni di uguaglianza
TArray _altexprs; // Condizioni di uguaglianza alternative TArray _altexprs; // Condizioni di uguaglianza alternative
TBit_array _forced; TBit_array _forced;
TString _description;
bool _first_match : 1; // primo match (ed esiste) bool _first_match : 1; // primo match (ed esiste)
bool _allow_lock : 1; // ????? bool _allow_lock : 1; // ?????
bool _write_enable : 1; bool _write_enable : 1;
protected: public: // TObject
virtual void print_on(ostream& out) const; virtual void print_on(ostream& out) const;
void print_on(TToken_string& out) const;
public: public:
// @FPUB
int num() const { return _num; } int num() const { return _num; }
int link() const { return _numto; } int link() const { return _numto; }
int alias() const { return _alias; } int alias() const { return _alias; }
@ -80,14 +82,14 @@ public:
void write_enable(bool we) { _write_enable = we; } void write_enable(bool we) { _write_enable = we; }
TRectype& load_rec(TRectype& r, const TBaseisamfile& from) const; TRectype& load_rec(TRectype& r, const TBaseisamfile& from) const;
const char* evaluate_expr(int j, const TLocalisamfile& to); const char* evaluate_expr(int j, const TLocalisamfile& to);
void set_description(const char* s) { _description = s; }
void print_on(TToken_string& out) const;
TRelationdef(const TRelation* rel, int file, byte key, TRelationdef(const TRelation* rel, int file, byte key,
int linkto, const char* relexprs, int alias, int linkto, const char* relexprs, int alias,
bool allow_lock, bool write_enable = FALSE); bool allow_lock, bool write_enable = FALSE);
virtual ~TRelationdef() {} virtual ~TRelationdef() {}
}; };
// @END
TRelationdef::TRelationdef(const TRelation* rel, int idx_file, byte key, TRelationdef::TRelationdef(const TRelation* rel, int idx_file, byte key,
@ -141,18 +143,6 @@ TRelationdef::TRelationdef(const TRelation* rel, int idx_file, byte key,
else else
_exprs.add(new TExpression(s, _strexpr), i); _exprs.add(new TExpression(s, _strexpr), i);
} }
// add description
TString16 name = _rel->file(_num).name();
if (_rel->file(_num).tab())
{
// tabella
TDir dir;
dir.get(TTable::name2log(name), _nolock, _nordir, _sysdirop);
_description = dir.tab_des(name);
}
else _description = prefix().description(name);
} }
@ -197,7 +187,15 @@ void TRelationdef::print_on(TToken_string& out) const
out = ""; out = "";
print_name(out, f); print_name(out, f);
out.add(_description);
// add description
const char* name = f.name();
if (f.tab())
name = TDir::tab_des(name);
else
name = prefix().description(name);
out.add(name);
out << '|'; out << '|';
if (_numto > 0) if (_numto > 0)
@ -250,37 +248,29 @@ const char* TRelationdef::evaluate_expr(int j, const TLocalisamfile& to)
// TRelation // TRelation
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
TRelation::TRelation(int logicnum, bool linkrecinst) TRelation::TRelation(int logicnum)
: _files(4) , _reldefs(4), _errors(NOERR) : _files(4) , _reldefs(4), _errors(NOERR)
{ {
TLocalisamfile* f = new TLocalisamfile(logicnum, linkrecinst); TLocalisamfile* f = new TLocalisamfile(logicnum);
_files.add(f); _files.add(f);
} }
TRelation::TRelation(const char* tabname, bool linkrecinst) TRelation::TRelation(const char* tabname)
: _files(4) , _reldefs(4), _errors(NOERR) : _files(4) , _reldefs(4), _errors(NOERR)
{ {
TTable* t = new TTable(tabname, linkrecinst); TTable* t = new TTable(tabname);
_files.add(t); _files.add(t);
} }
TRelation::TRelation(TLocalisamfile* f) TRelation::TRelation(TLocalisamfile* l)
: _files(4) , _reldefs(4), _errors(NOERR) : _files(4) , _reldefs(4), _errors(NOERR)
{ {
_files.add(f); _files.add(l);
} }
TRelation::~TRelation() TRelation::~TRelation()
{} {}
void TRelation::set_description(const char* d, int index)
{
if (index == -1) _main_desc = d == NULL ? "" : d;
else reldef(index)._description = d == NULL ? "" : d;
}
void TRelation::print_on(ostream& out) const void TRelation::print_on(ostream& out) const
{ {
const TLocalisamfile& f = file(); const TLocalisamfile& f = file();
@ -295,47 +285,20 @@ void TRelation::print_on(ostream& out) const
out << _reldefs[r] << endl; out << _reldefs[r] << endl;
} }
void TRelation::print_on(TArray& a) const
{
const TLocalisamfile& f = file();
TToken_string s(128);
print_name(s, f);
if (f.tab())
{
// tabella
TDir dir;
dir.get(TTable::name2log(f.name()), _nolock, _nordir, _sysdirop);
s.add(dir.tab_des(f.name()));
}
else s.add(prefix().description(f.name()));
s.add("");
s.add(f.getkey());
s.add(" | ");
a.destroy();
a.add(s);
for (int i = 0; i < _reldefs.items(); i++)
{
((TRelationdef&)_reldefs[i]).print_on(s);
a.add(s);
}
}
void TRelation::restore_status() void TRelation::restore_status()
{ {
_status.restart(); _status.restart();
for (int i = 0; i < _files.items(); i++) for (int i = 0; i < _files.items(); i++)
{ {
int err = _status.get_int(); const int err = _status.get_int();
int recno = _status.get_int(); const int recno = _status.get_int();
if (recno >= 0l) file(i).readat(recno); if (recno >= 0l) file(i).readat(recno);
else file(i).curr().zero(); else file(i).curr().zero();
file(i).setstatus(err); file(i).setstatus(err);
} }
for (i = 0; i < _reldefs.items(); i++) for (i = 0; i < _reldefs.items(); i++)
{ {
bool first_match = _status.get_int (); const bool first_match = _status.get_int() ? TRUE : FALSE;
reldef(i)._first_match = first_match; reldef(i)._first_match = first_match;
} }
} }
@ -1196,6 +1159,9 @@ int name2log(const char* name)
{ {
int log = 0; int log = 0;
if (name)
while (*name == ' ') name++;
if (name && *name) if (name && *name)
{ {
if (isdigit(*name) || *name == '-') if (isdigit(*name) || *name == '-')
@ -1237,7 +1203,12 @@ TFieldref& TFieldref::operator =(const TString& s)
_id = s.left(pos); _id.strip(" "); _id = s.left(pos); _id.strip(" ");
_fileid = name2log(_id); _fileid = name2log(_id);
pos += 2; pos += 2;
} else _fileid = pos = 0; }
else
{
_id.cut(0);
_fileid = pos = 0;
}
int par = s.find('[', pos); int par = s.find('[', pos);
_name = s.sub(pos, par); _name.strip(" "); _name = s.sub(pos, par); _name.strip(" ");
@ -1245,20 +1216,32 @@ TFieldref& TFieldref::operator =(const TString& s)
if (par > 0) if (par > 0)
{ {
pos = par+1; pos = par+1;
_from = atoi(s.mid(pos)); set_from(atoi(s.mid(pos)));
if (_from > 0) _from--; else _from = 0;
par = s.find(',', pos); par = s.find(',', pos);
if (par > 0) _to = atoi(s.mid(par+1)); else _to = -1; if (par > 0) set_to(atoi(s.mid(par+1)));
else set_to(from()+1);
} }
else else
{ {
_from = 0; set_from(0);
_to = -1; set_to(-1);
} }
return *this; return *this;
} }
void TFieldref::set_file(int f)
{
_id.cut(0);
if (f != 0)
{
_fileid = f;
_id << abs(f);
if (f < 0) _id << '@';
}
else _fileid = 0;
}
void TFieldref::print_on(ostream& out) const void TFieldref::print_on(ostream& out) const
{ {
if (_id.not_empty()) out << _id << "->"; if (_id.not_empty()) out << _id << "->";
@ -1266,14 +1249,13 @@ void TFieldref::print_on(ostream& out) const
if (_from > 0 || _to > 0) if (_from > 0 || _to > 0)
{ {
out << '[' << (_from+1); out << '[' << (_from+1);
if (_to) out << ',' << _to; out << ',' << _to << ']';
out << ']';
} }
} }
const char* TFieldref::read(const TRectype& rec) const const char* TFieldref::read(const TRectype& rec) const
{ {
static TString80 buffer; static TString256 buffer;
if (_fileid >= CNF_GENERAL) if (_fileid >= CNF_GENERAL)
{ {
@ -1287,10 +1269,13 @@ const char* TFieldref::read(const TRectype& rec) const
if (_from > 0 || _to > 0) if (_from > 0 || _to > 0)
{ {
const int l = buffer.len(); const int l = buffer.len();
const int from = (_from > l) ? l : _from; // const int from = (_from > l) ? l : _from;
const int to = (_to > l || _to < 1) ? l : _to; // const int to = (_to > l || _to < 1) ? l : _to;
if (to < l) buffer.cut(to); // if (to < l) buffer.cut(to);
if (from > 0) buffer.ltrim(from); if (_to < l && _to > 0) buffer.cut(_to);
// if (from > 0) buffer.ltrim(from);
if (_from > 0) buffer.ltrim(_from);
} }
} }
return buffer; return buffer;
@ -1534,28 +1519,52 @@ int TRecord_array::remove()
// TRelation_description // TRelation_description
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
void TRelation_description::init_files_array()
{
const TLocalisamfile& f = _rel->file();
TToken_string s(128);
print_name(s, f); // Logic number
const char* name = f.name();
if (f.tab())
name = TDir::tab_des(name);
else
name = prefix().description(name);
s.add(name); // Description
s.add(" "); // No join
s.add(f.getkey()); // Key
s.add(" | "); // No Alias nor expression
_files.destroy();
_files.add(s); // Main file
for (int i = 0; i < _rel->items(); i++)
{
_rel->reldef(i).print_on(s);
_files.add(s);
}
}
void TRelation_description::read_rel() void TRelation_description::read_rel()
{ {
int which_file;
// scan files and build description arrays // scan files and build description arrays
_rel->print_on(_files); init_files_array();
TString tn;
_fields.destroy();
for (int i = 0; i < _files.items(); i++) for (int i = 0; i < _files.items(); i++)
{ {
TToken_string& tt = (TToken_string&)_files[i]; TToken_string& tt = (TToken_string&)_files[i];
TFilename descfname; descfname << DESCDIR << "/d"; TFilename descfname; descfname << DESCDIR << "/d";
tn = tt.get(0); const char* tn = tt.get(0);
if (tn[0] == '%' || tn[0] == '$') if (tn[0] == '%' || tn[0] == '$')
descfname << tn.mid(1); descfname << (tn+1);
else else
descfname << tn; descfname << tn;
descfname << ".des"; descfname << ".des";
which_file = atoi(tn); int which_file = atoi(tn);
if (which_file == 0) if (which_file == 0)
which_file = TTable::name2log(tn); which_file = TTable::name2log(tn);
@ -1579,38 +1588,66 @@ void TRelation_description::read_rel()
if (!dfld.blank() && dfld[0] != '#') if (!dfld.blank() && dfld[0] != '#')
{ {
ttmp.add(dfld,4); ttmp.add(dfld,4);
// contiene: nome campo, tipo, lunghezza, // contiene: nome campo, tipo, lunghezza, decimali, descrizione
// decimali, descrizione
rdesc->add(ttmp); rdesc->add(ttmp);
} }
} }
} }
if (rdesc->items() > 0) if (rdesc->items() > 0)
_fields.add(rdesc); _fields.add(rdesc);
else
{
_files.destroy(i);
delete rdesc;
} }
} }
else _files.destroy(i);
}
_files.pack();
} }
bool TRelation_description::choose_file (int file) void TRelation_description::change_relation(TRelation& r, TString_array& a)
{
_rel = &r;
read_rel();
if (a.items() > 0)
_files = a;
}
void TRelation_description::print_on(ostream& out) const
{
for (int i = 0; i < _files.items(); i++)
{
TToken_string& r = ((TRelation_description*)this)->_files.row(i);
out << " " << r.get(0) << "->* ";
out << "\"" << r.get(1) << "\"\n";
}
}
bool TRelation_description::choose_file(int file)
{ {
TArray_sheet sht(-1,-1,0,0,"Selezione archivio", "Codice|Descrizione archivio@70"); TArray_sheet sht(-1,-1,0,0,"Selezione archivio", "Codice|Descrizione archivio@70");
TToken_string tt(80); TToken_string tt(80);
int sel = 0;
for (int i = 0; i < _files.items(); i++) for (int i = 0; i < _files.items(); i++)
{ {
TToken_string& tf = _files.row(i); TToken_string& tf = _files.row(i);
tt = tf.get(4);
if (tt.blank())
{
tt = tf.get(0); tt = tf.get(0);
tt.add(tf.get()); if (sel == 0 && file > 0 && atoi(tt) == file)
sel = i;
}
else
{
if (sel == 0 && file < 0 && atoi(tt) == -file)
sel = i;
tt << '@';
}
tt.add(tf.get(1));
sht.add(tt); sht.add(tt);
} }
sht.select(sel);
if (sht.run() == K_ENTER) if (sht.run() == K_ENTER)
{ {
_cur_file = (int)sht.selected(); _cur_file = (int)sht.selected();
@ -1623,18 +1660,24 @@ bool TRelation_description::choose_file (int file)
bool TRelation_description::choose_field(const char* fld) bool TRelation_description::choose_field(const char* fld)
{ {
TArray_sheet sht(-1,-1,0,0,"Selezione campo", TArray_sheet sht(-1,-1,0,0,"Selezione campo",
"Descrizione campo@50|Tipo@10|Dim."); "Campo@10|Descrizione@50|Tipo@10|Dim.");
TString_array& fd = (TString_array&)_fields[_cur_file]; TString_array& fd = (TString_array&)_fields[_cur_file];
TToken_string tt(80); TToken_string tt(80);
int sel = 0;
for (int i = 0; i < fd.items(); i++) for (int i = 0; i < fd.items(); i++)
{ {
TToken_string& tf = fd.row(i); TToken_string& tf = fd.row(i);
tt = tf.get(4); tt.cut(50); tt = tf.get(0);
if (sel == 0 && tt == fld)
sel = i;
tt.add(tf.get(4));
tt.add(field_type_str((TFieldtypes)tf.get_int(1))); tt.add(field_type_str((TFieldtypes)tf.get_int(1)));
tt.add(tf.get(2)); tt.add(tf.get(2));
sht.add(tt); sht.add(tt);
} }
sht.select(sel);
if (sht.run() == K_ENTER) if (sht.run() == K_ENTER)
{ {
_cur_field = (int)sht.selected(); _cur_field = (int)sht.selected();
@ -1654,19 +1697,23 @@ bool TRelation_description::remove_menu()
return FALSE; return FALSE;
} }
bool TRelation_description::is_table() bool TRelation_description::set_cur_file(int id)
{ {
return _cfile.get_int(0) == 0; const int n = _rel->log2ind(id);
if (n >= 0 && n != _cur_file)
{
_cur_file = n;
_cfile = _files.row(n);
}
return n >= 0;
} }
int TRelation_description::file() int TRelation_description::file_num()
{ {
return _cfile.get_int(0); int n = -_cfile.get_int(4);
} if (n == 0)
n = _cfile.get_int(0);
const char* TRelation_description::table() return n;
{
return _cfile.get(0);
} }
const char* TRelation_description::file_desc() const char* TRelation_description::file_desc()
@ -1674,12 +1721,19 @@ const char* TRelation_description::file_desc()
return _cfile.get(1); return _cfile.get(1);
} }
void TRelation_description::file_desc(const char* desc)
{
_cfile.add(desc, 1);
_files.row(_cur_file) = _cfile;
}
const char* TRelation_description::field_desc() const char* TRelation_description::field_desc()
{ {
return _cfield.get(4); return _cfield.get(4);
} }
const char* TRelation_description::field() const char* TRelation_description::field_name()
{ {
return _cfield.get(0); return _cfield.get(0);
} }
@ -1694,64 +1748,49 @@ TFieldtypes TRelation_description::field_type()
return (TFieldtypes)_cfield.get_int(1); return (TFieldtypes)_cfield.get_int(1);
} }
bool TRelation_description::set_field_description(int id, const char* field, const char* des) bool TRelation_description::set_field_description(const char* field, const char* des)
{ {
for (int i = 0; i < _files.items(); i++) TString_array& fld = (TString_array&)_fields[_cur_file];
{
TToken_string& tt = _files.row(i);
if (tt.get_int(0) == id || tt.get_int(4) == id)
break;
}
if (i == _files.items()) return FALSE;
TString_array& fld = (TString_array&)_fields[i]; for (int i = 0; i < fld.items(); i++)
for (i = 0; i < fld.items(); i++)
{ {
TToken_string& tt = fld.row(i); TToken_string& tt = fld.row(i);
if (strcmp(tt.get(0),field) == 0) if (strcmp(tt.get(0),field) == 0)
{ {
if (*des) tt.add(des,4); if (des && *des)
tt.add(des, 4);
else else
{ {
fld.destroy(i); fld.destroy(i);
fld.pack(); fld.pack();
} }
break; return TRUE;
} }
} }
return i < fld.items(); if (des && *des)
{
TToken_string tt(80);
tt.add(field);
tt.add(des, 4);
fld.add(tt);
return TRUE;
}
return FALSE;
} }
bool TRelation_description::set_field_description(const char* id, const char* field, const char* des) const char* TRelation_description::get_field_description(const char* field)
{ {
for (int i = 0; i < _files.items(); i++) TString_array& fld = (TString_array&)_fields[_cur_file];
{
TToken_string& tt = _files.row(i);
if (tt.get(0) == id)
break;
}
if (i == _files.items()) return FALSE;
TString_array& fld = (TString_array&)_fields[i]; for (int i = 0; i < fld.items(); i++)
for (i = 0; i < fld.items(); i++)
{ {
TToken_string& tt = fld.row(i); TToken_string& tt = fld.row(i);
if (strcmp(tt.get(0),field) == 0) if (strcmp(tt.get(0),field) == 0)
{ return tt.get(1);
if (*des) tt.add(des,4);
else
{
fld.destroy(i);
fld.pack();
} }
break; return "";
}
}
return i < fld.items();
} }

View File

@ -1,4 +1,4 @@
/* $Id: relation.h,v 1.17 1995-05-09 09:12:26 villa Exp $ */ /* $Id: relation.h,v 1.18 1995-05-29 10:25:02 guy Exp $ */
// join.h // join.h
// fv 12/8/93 // fv 12/8/93
// join class for isam files // join class for isam files
@ -10,29 +10,18 @@
#include <isam.h> #include <isam.h>
#endif #endif
// @C
class TRelation : public TObject class TRelation : public TObject
{ {
friend class TRelationdef; friend class TRelationdef;
friend class TRelation_description; friend class TRelation_description;
friend class TCursor; friend class TCursor;
// class TRelation : public TLocalisamfile
// @END
// @DPRIV
TToken_string _status; // stato della relazione TToken_string _status; // stato della relazione
TString _main_desc; // descrizione file principale
TArray _files; // file descriptors TArray _files; // file descriptors
TArray _reldefs; // TRelationdef array TArray _reldefs; // TRelationdef array
int _errors; int _errors;
// @END
// @FPROT
protected: protected:
virtual void print_on(ostream& out) const;
int log2ind(int logicnum) const; int log2ind(int logicnum) const;
int alias2ind(int alias) const; int alias2ind(int alias) const;
int name2ind(const char* name) const; int name2ind(const char* name) const;
@ -40,16 +29,16 @@ protected:
TRelationdef& reldef(int i) const { return (TRelationdef&)_reldefs[i]; } TRelationdef& reldef(int i) const { return (TRelationdef&)_reldefs[i]; }
TLocalisamfile& file(int i = 0) const { return (TLocalisamfile&)_files[i]; } TLocalisamfile& file(int i = 0) const { return (TLocalisamfile&)_files[i]; }
// @LONGDES
// position_rels fa tutto il lavoro: se non trova un record // position_rels fa tutto il lavoro: se non trova un record
// adatto su un file, svuota il record corrente e non ritorna errore. // adatto su un file, svuota il record corrente e non ritorna errore.
// write etc. poi procedono normalmente // write etc. poi procedono normalmente
// @END
int position_rels(TIsamop op = _isequal, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime, int first = 0); int position_rels(TIsamop op = _isequal, TReclock lockop = _nolock, TDate& atdate = (TDate&)botime, int first = 0);
public: // TObject
virtual bool ok() const { return good(); }
virtual void print_on(ostream& out) const;
public: public:
// @FPUB
int update() { return position_rels(_isequal, _nolock);} int update() { return position_rels(_isequal, _nolock);}
void zero(); void zero();
virtual int next(TReclock lockop = _nolock) { return file().next(lockop) == NOERR ? position_rels(_isequal, lockop) : file().status(); } virtual int next(TReclock lockop = _nolock) { return file().next(lockop) == NOERR ? position_rels(_isequal, lockop) : file().status(); }
@ -75,9 +64,6 @@ public:
// first place // first place
bool next_match(int logicnum, const char* fieldlist = NULL, int nkey = 0); bool next_match(int logicnum, const char* fieldlist = NULL, int nkey = 0);
// @DES add relation
// @FPUB
bool add(TLocalisamfile* f, const char* relexprs, int key, bool add(TLocalisamfile* f, const char* relexprs, int key,
int linkto, int alias, bool allow_lock); int linkto, int alias, bool allow_lock);
bool add(int logicnum, const char* relexprs, int key = 1, bool add(int logicnum, const char* relexprs, int key = 1,
@ -86,37 +72,29 @@ public:
int linkto = 0, int alias = 0, bool allow_lock = FALSE); int linkto = 0, int alias = 0, bool allow_lock = FALSE);
void replace(TLocalisamfile* f, int index = 0); void replace(TLocalisamfile* f, int index = 0);
// @DES write methods // write methods
// @FPUB
virtual int write (bool force = TRUE, TDate& atdate = (TDate&)botime); virtual int write (bool force = TRUE, TDate& atdate = (TDate&)botime);
virtual int rewrite(bool force = TRUE, TDate& atdate = (TDate&)botime); virtual int rewrite(bool force = TRUE, TDate& atdate = (TDate&)botime);
virtual int remove (TDate& atdate = (TDate&)botime); virtual int remove (TDate& atdate = (TDate&)botime);
// @DES checking methods // status methods
// @FPUB // return the status of the relation when called
bool eof( int logicnum = 0) { return lfile(logicnum).eof(); }
bool bof( int logicnum = 0) { return lfile(logicnum).bof(); }
// @N
// status(), good() and bad() return the status of the relation when called
// with no args, or the status of the file when called with // with no args, or the status of the file when called with
// a logical number // a logical number
// @END
bool status(int logicnum = 0) { return lfile(logicnum).status(); } bool eof( int logicnum = 0) const { return lfile(logicnum).eof(); }
bool good( int logicnum = 0) { return lfile(logicnum).good(); } bool bof( int logicnum = 0) const { return lfile(logicnum).bof(); }
bool bad( int logicnum = 0) { return lfile(logicnum).bad(); } bool status(int logicnum = 0) const { return lfile(logicnum).status(); }
bool empty( int logicnum = 0) { return lfile(logicnum).empty(); } bool good( int logicnum = 0) const { return lfile(logicnum).good(); }
// @END bool bad( int logicnum = 0) const { return lfile(logicnum).bad(); }
bool empty( int logicnum = 0) const { return lfile(logicnum).empty(); }
// @LONGDES
// isconsistent() returns TRUE if every file in the relation is // isconsistent() returns TRUE if every file in the relation is
// OK, current record is non-empty, and relation is consistent. // OK, current record is non-empty, and relation is consistent.
// If it's not and reset is TRUE, it tries to reset the relation // If it's not and reset is TRUE, it tries to reset the relation
// to a consistent state (based on main record) -- no further check // to a consistent state (based on main record) -- no further check
// is done. // is done.
// Also called internally by update and remove. // Also called internally by update and remove.
// @END
bool isconsistent(bool reset = FALSE); bool isconsistent(bool reset = FALSE);
// TRUE se c'e' un record ed e' il primo match (non si e' mai fatta // TRUE se c'e' un record ed e' il primo match (non si e' mai fatta
@ -126,25 +104,17 @@ public:
// items() ritorna il numero di files collegati // items() ritorna il numero di files collegati
int items() { return _reldefs.items(); } int items() { return _reldefs.items(); }
// set_description modifica la descrizione del file passato (per indice)
// o del principale
void set_description(const char* d, int index = -1);
void save_status () ; void save_status () ;
void restore_status () ; void restore_status () ;
// @DES positioning operators. return status // positioning operators. return status
// @FPUB
TRecnotype operator +=(const TRecnotype npos) { return skip(npos); } TRecnotype operator +=(const TRecnotype npos) { return skip(npos); }
TRecnotype operator -=(const TRecnotype npos) { return skip(-npos); } TRecnotype operator -=(const TRecnotype npos) { return skip(-npos); }
TRecnotype operator ++() { return next(); } TRecnotype operator ++() { return next(); }
TRecnotype operator --() { return prev(); } TRecnotype operator --() { return prev(); }
void print_on(TArray& a) const; // Mette la descrizione in un array di TToken_string TRelation(int logicnum);
TRelation(const char* tabname);
TRelation(int logicnum, bool linkrecinst = FALSE);
TRelation(const char* tabname, bool linkrecinst = FALSE);
TRelation(TLocalisamfile* f); TRelation(TLocalisamfile* f);
virtual ~TRelation(); virtual ~TRelation();
@ -193,18 +163,13 @@ public:
}; };
// @C
// Classe TCursor : public TObject // Classe TCursor : public TObject
//
// @END
class TExpression; class TExpression;
typedef bool (*FILTERFUNCTION)(const TRelation* r); typedef bool (*FILTERFUNCTION)(const TRelation* r);
class TCursor : public TObject class TCursor : public TObject
{ {
// @DPRIV
TRelation* _if; TRelation* _if;
int _nkey; int _nkey;
TRecnotype _pos; // Posizione corrente TRecnotype _pos; // Posizione corrente
@ -219,9 +184,7 @@ class TCursor : public TObject
bool _frozen; bool _frozen;
FILTERFUNCTION _filterfunction; FILTERFUNCTION _filterfunction;
TFilename _indexname; TFilename _indexname;
// @END
// @FPRIV
virtual TRecnotype buildcursor(TRecnotype rp); virtual TRecnotype buildcursor(TRecnotype rp);
int filtercursor(int pagecnt, TRecnotype* page); int filtercursor(int pagecnt, TRecnotype* page);
bool changed(); bool changed();
@ -287,23 +250,19 @@ public:
}; };
// @C
// Classe TFieldref : public TObject // Classe TFieldref : public TObject
// @END
class TFieldref : public TObject class TFieldref : public TObject
{ {
// @DPRIV
short _fileid; // Numero del file short _fileid; // Numero del file
TString16 _id; // Nome tabella o stringa col numero del file TString _id; // Nome tabella o stringa col numero del file
TString80 _name; // Nome del campo TString _name; // Nome del campo
int _from, _to; // Substring int _from, _to; // Substring
protected: protected:
virtual void print_on(ostream& out) const; virtual void print_on(ostream& out) const;
public: public:
// @FPUB
TFieldref(); TFieldref();
TFieldref(const TString&, short defid); TFieldref(const TString&, short defid);
@ -312,7 +271,13 @@ public:
virtual bool ok() const { return _name.not_empty(); } // Vero se il numero del file e' valido virtual bool ok() const { return _name.not_empty(); } // Vero se il numero del file e' valido
int file() const { return _fileid; } // ritorna il file int file() const { return _fileid; } // ritorna il file
void set_file(int f);
const char* name() const { return (const char*) _name; } // ritorna il nome del campo const char* name() const { return (const char*) _name; } // ritorna il nome del campo
void set_name(const char* n) { _name = n; }
void set_from(int f) { if (f > 0) f--; else f = 0; _from = f; }
void set_to(int t) { _to = t; }
int from() const { return _from; } int from() const { return _from; }
int to() const { return _to; } int to() const { return _to; }
int len(TRectype &rec) const; int len(TRectype &rec) const;
@ -330,7 +295,7 @@ class TRelation_description : public TObject
// gestisce l'uso interattivo di una relazione (scelta campi, descrizione) // gestisce l'uso interattivo di una relazione (scelta campi, descrizione)
// domani o doman l'altro gestira' l'editing interattivo e grafico // domani o doman l'altro gestira' l'editing interattivo e grafico
TRelation* _rel; TRelation* _rel; // relation described
TString_array _files; TString_array _files;
TArray _fields; TArray _fields;
int _cur_file; int _cur_file;
@ -338,14 +303,20 @@ class TRelation_description : public TObject
bool _menu; bool _menu;
TToken_string _cfile, _cfield; TToken_string _cfile, _cfield;
protected:
void init_files_array();
void read_rel(); void read_rel();
public: // TObject
virtual bool ok() const { return _files.items() > 0; }
public: public:
// "choose" interface: after choosing a field (must return TRUE) // "choose" interface: after choosing a field (must return TRUE)
// methods allow to know all data concerning the field // methods allow to know all data concerning the field
// parameters set the one initially selected // parameters set the one initially selected
bool choose_file (int file = -1); bool choose_file (int id = 0);
bool set_cur_file(int id = 0);
// file must have been chosen: first file in list if called // file must have been chosen: first file in list if called
// before choose_file // before choose_file
@ -356,22 +327,24 @@ public:
bool build_menu(const char* title = "Database"); bool build_menu(const char* title = "Database");
bool remove_menu(); bool remove_menu();
bool set_field_description(int id, const char* field, const char* des); // if choose_file == TRUE or menu has been used these return valid data
bool set_field_description(const char* tab, const char* field, const char* des); int file_num();
// if choose_field == TRUE or menu has been used
// these return valid data
bool is_table();
int file();
const char* table();
const char* field();
const char* file_desc(); const char* file_desc();
void file_desc(const char* desc);
bool set_field_description(const char* field, const char* des);
const char* get_field_description(const char* field);
// if choose_field == TRUE or menu has been used these return valid data
const char* field_desc(); const char* field_desc();
void field_desc(const char* desc);
const char* field_name(); const char* field_name();
int field_len(); int field_len();
TFieldtypes field_type(); TFieldtypes field_type();
virtual bool ok() { return _files.items() > 0; } const TString_array& get_all_desc() const { return _files; }
void change_relation(TRelation& rel, TString_array& arr);
virtual void print_on(ostream& out) const;
TRelation_description(TRelation& r); TRelation_description(TRelation& r);
virtual ~TRelation_description(); virtual ~TRelation_description();

View File

@ -22,6 +22,9 @@
#define M_EDIT_DELETE (M_EDIT+9) #define M_EDIT_DELETE (M_EDIT+9)
#define M_EDIT_QUIT (M_EDIT+10) #define M_EDIT_QUIT (M_EDIT+10)
#define M_SHOW_RULERS (M_EDIT+20)
#define M_SHOW_BUTTONS (M_EDIT+21)
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
#define ICO_SEARCH 109 #define ICO_SEARCH 109

View File

@ -1175,13 +1175,13 @@ void TViswin::handler (WINDOW win, EVENT * ep)
stop_run(CTRL_S); stop_run(CTRL_S);
#endif #endif
break; break;
case M_FONT: // mostra righelli case M_SHOW_RULERS: // mostra righelli
show_rulers(!_rulers); show_rulers(!_rulers);
check_menu_item(M_FONT, _rulers); check_menu_item(M_SHOW_RULERS, _rulers);
break; break;
case M_STYLE: // mostra bottoni case M_SHOW_BUTTONS: // mostra bottoni
show_buttons(!_showbuts); show_buttons(!_showbuts);
check_menu_item(M_STYLE, _showbuts); check_menu_item(M_SHOW_BUTTONS, _showbuts);
break; break;
case M_EDIT_QUIT: // chiudi case M_EDIT_QUIT: // chiudi
#if XVT_OS == XVT_OS_WIN #if XVT_OS == XVT_OS_WIN
@ -2325,10 +2325,10 @@ TViswin::TViswin(const char *fname,
if (_toplevel) if (_toplevel)
{ {
enable_menu_item(M_FONT, TRUE); enable_menu_item(M_SHOW_RULERS, TRUE);
enable_menu_item(M_STYLE, TRUE); enable_menu_item(M_SHOW_BUTTONS, TRUE);
check_menu_item(M_FONT, _rulers); check_menu_item(M_SHOW_RULERS, _rulers);
check_menu_item(M_STYLE, _showbuts); check_menu_item(M_SHOW_BUTTONS, _showbuts);
enable_menu_item(M_EDIT_SEL_ALL, FALSE); enable_menu_item(M_EDIT_SEL_ALL, FALSE);
} }