Modificate la TTrec::read_from e la TTrec::print_on per salvare/leggere

anche le descrizioni del tracciato record.


git-svn-id: svn://10.65.10.50/trunk@2904 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
angelo 1996-05-24 13:11:23 +00:00
parent 4aaf60f0c9
commit 6f7b90061e
2 changed files with 42 additions and 3 deletions

View File

@ -299,6 +299,8 @@ int TDir::items (
TTrec::TTrec ()
{
_des = NULL;
_tab = "";
_rec = new RecDes;
zero ();
_num = -1;
@ -483,7 +485,11 @@ void TTrec::update_keydef (int key, const char *desc)
void TTrec::print_on (ostream & out) const
{
out << num () << '\n';
const int n = num();
out << n;
if (_des && n>=3 && n<=5) // Solo se e' una tabella...
out << "|" << _tab;
out << '\n';
const int nfields = fields ();
TToken_string s (80);
@ -491,7 +497,10 @@ void TTrec::print_on (ostream & out) const
for (int i = 0; i < nfields; i++)
{
s = fielddef (i);
out << s << '\n';
out << s ;
if (_des)
out << "|" << _des->get(_rec->Fd[i].Name);
out << '\n';
}
const int nkeys = keys ();
@ -507,19 +516,38 @@ void TTrec::read_from (istream & in)
{
int ln;
const int n = num();
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
if (_des && n>=3 && n<=5)
{
TString t(_files_tmp_string);
if (t.find('|')>-1)
{
TString tabname(t.right(3));
strcpy(_files_tmp_string,t.left(t.len()-4)); // Toglie il nome della tabella
if (_tab != tabname && !yesno_box("Descrizione relativa alla tabella %s.\n Continuo ?",(const char*) tabname))
return;
}
}
ln = atoi (_files_tmp_string);
if (ln != num () && !yesno_box ("Descrizione relativa al file n.ro %d.\n Continuo ?", ln))
if (ln != n && !yesno_box ("Descrizione relativa al file n.ro %d.\n Continuo ?", ln))
return;
int nfields;
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
nfields = atoi (_files_tmp_string);
set_fields (nfields);
TToken_string t;
for (int i = 0; i < nfields; i++)
{
in.getline (_files_tmp_string, sizeof (_files_tmp_string), '\n');
t = _files_tmp_string;
const int itms = t.items();
if (_des && itms == 5) // La descrizione viene caricata solo se esiste
_des->set(_rec->Fd[i].Name, t.get(itms-1));
update_fielddef (i, _files_tmp_string);
}
int nkeys;
@ -533,6 +561,8 @@ void TTrec::read_from (istream & in)
update_keydef (i, _files_tmp_string);
}
rehash ();
_des = NULL;
_tab = "";
}
#endif // FOXPRO

View File

@ -13,6 +13,10 @@
#include <rectypes.h>
#endif
#ifndef __CONFIG_H
#include <config.h>
#endif
#define DESCPAR "FieldDescr"
#define DESCTAB "TabDescr"
#define DESCDIR "recdesc"
@ -181,6 +185,10 @@ class TTrec : public TSortable
RecDes* _rec;
// @cmember:(INTERNAL) Numero del file di appartenenza
int _num;
// @cmember:(INTERNAL) Puntatore al TConfig delle descrizioni
TConfig* _des;
// @cmember:(INTERNAL) Nome della tabella
TString _tab;
// @access Protected Member
protected:
@ -238,6 +246,7 @@ public:
virtual void print_on(ostream& out) const;
// @cmember Legge il tracciato record da input selezionato
virtual void read_from(istream& in);
void set_des(TConfig* c = NULL, const char* tab = "") { _des = c; _tab = tab;}
#endif
// @cmember Costruttore