af9ae417a7
git-svn-id: svn://10.65.10.50/trunk@146 c028cbd2-c16b-5b4b-a496-9718f37d4682
338 lines
7.5 KiB
C++
Executable File
338 lines
7.5 KiB
C++
Executable File
// ba3200 Stampa tabelle
|
|
//
|
|
// legge un file con estensione .rpt che descrive la stampa.
|
|
// Vedi file leggimi.txt per il formato del file
|
|
//
|
|
|
|
#include <mask.h>
|
|
#include <printapp.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
#include <utility.h>
|
|
|
|
#include "ba3.h"
|
|
#include "ba3200.h"
|
|
|
|
#define FOOTER_LEN 4 // se non ridefinito nel .rpt
|
|
|
|
class BA3200_application : public TPrintapp
|
|
{
|
|
TString _tabname;
|
|
TFilename _rptname;
|
|
TRelation* _rel;
|
|
TCursor *_cur;
|
|
TMask* _msk;
|
|
TString _maskname;
|
|
int _logicnum;
|
|
TArray _string_roman;
|
|
TArray _field_roman;
|
|
|
|
public:
|
|
|
|
virtual void user_create() ;
|
|
virtual void user_destroy() ;
|
|
virtual bool set_print(int) ;
|
|
|
|
virtual void set_page(int, int);
|
|
virtual bool preprocess_page (int, int);
|
|
|
|
void leggi_rpt();
|
|
void set_headers();
|
|
void set_rows();
|
|
void set_footers();
|
|
void set_translations();
|
|
void set_relations();
|
|
BA3200_application(const char * tabname) : _tabname(tabname) {}
|
|
virtual ~BA3200_application() {}
|
|
};
|
|
|
|
|
|
bool BA3200_application::set_print(int)
|
|
{
|
|
TRectype from(_rel->lfile()->curr()); from.zero();
|
|
TRectype to (from);
|
|
|
|
if (_msk->run() == K_ENTER)
|
|
{
|
|
const int campi_maschera = _msk->fields();
|
|
for (int i = 0; i < campi_maschera; i++)
|
|
{
|
|
const TMask_field& campo_maschera = _msk->fld(i);
|
|
const char* val = campo_maschera.get();
|
|
if (*val)
|
|
{
|
|
const TFieldref* campo_ref = campo_maschera.field();
|
|
|
|
if (campo_ref != NULL && campo_ref->ok())
|
|
{
|
|
if (campo_maschera.in_group(1)) campo_ref->write(val, from);
|
|
else
|
|
if (campo_maschera.in_group(2)) campo_ref->write(val, to);
|
|
}
|
|
}
|
|
}
|
|
|
|
_cur->setregion (from, to);
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void BA3200_application::set_page (int , int )
|
|
{
|
|
_string_roman.destroy();
|
|
_field_roman.destroy();
|
|
leggi_rpt();
|
|
}
|
|
|
|
bool BA3200_application::preprocess_page(int , int)
|
|
{
|
|
const int items = _field_roman.items();
|
|
|
|
if (items > 0)
|
|
{
|
|
for (int i = 0; i < items; i++)
|
|
{
|
|
TString& fn = (TString &) _field_roman[i];
|
|
TFieldref fld(fn, 0);
|
|
TString& s = (TString &) _string_roman[i];
|
|
|
|
const int n = atoi(fld.read(_rel));
|
|
s = itor(n);
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void BA3200_application::set_headers()
|
|
{
|
|
TString NomeTabella, sep, formato_intesta, testo_intesta;
|
|
int LungRiga, riga_intesta=0, last_riga=1;
|
|
TToken_string line;
|
|
|
|
reset_header ();
|
|
|
|
TScanner rpt(_rptname);
|
|
rpt.paragraph("Headers");
|
|
|
|
// Leggo la lunghezza della riga (usata per centrare l'intestazione)
|
|
line = rpt.line();
|
|
LungRiga = line.get_int();
|
|
|
|
// Leggo il nome della tabella
|
|
line = rpt.line();
|
|
NomeTabella = line.get();
|
|
|
|
// Centro il nome della tabella e aggiungo il numero di pagina
|
|
NomeTabella.center_just (LungRiga);
|
|
NomeTabella.overwrite ("Pag. @#", NomeTabella.len()-8);
|
|
set_header (last_riga, "%s", (const char *)NomeTabella);
|
|
last_riga++;
|
|
|
|
// Aggiungo una riga vuota per separare prima intestazione
|
|
sep.fill ('-', LungRiga);
|
|
set_header (last_riga, "%s", (const char *)sep);
|
|
|
|
line = rpt.line();
|
|
while ( (line != "") && (line[0] != '[') )
|
|
{
|
|
riga_intesta = atoi (line.get());
|
|
formato_intesta = line.get();
|
|
testo_intesta = (const char *) line.get();
|
|
if (riga_intesta)
|
|
set_header (last_riga+riga_intesta, (const char *)formato_intesta,
|
|
(const char *)testo_intesta);
|
|
line = rpt.line();
|
|
}
|
|
|
|
if (riga_intesta) last_riga += riga_intesta;
|
|
last_riga++;
|
|
set_header (last_riga, (const char *)sep);
|
|
last_riga++;
|
|
sep.fill(' ');
|
|
set_header (last_riga, (const char *)sep);
|
|
}
|
|
|
|
void BA3200_application::set_rows()
|
|
{
|
|
TToken_string line;
|
|
TFieldref campo;
|
|
int from, to, riga_record;
|
|
TString formato_campo, picture;
|
|
const char * name;
|
|
|
|
TScanner rpt(_rptname);
|
|
rpt.paragraph("Rows");
|
|
|
|
line = rpt.line();
|
|
while ( (line != "") && (line[0] != '[') )
|
|
{
|
|
riga_record = line.get_int();
|
|
|
|
TString s(line.get());
|
|
|
|
campo = s;
|
|
from = campo.from();
|
|
to = campo.to();
|
|
name = campo.name();
|
|
int logicnum = campo.file() == 0 ? _logicnum : campo.file();
|
|
|
|
formato_campo = line.get();
|
|
formato_campo.trim();
|
|
formato_campo.lower();
|
|
const int p = formato_campo.find("@m");
|
|
|
|
if (p != -1)
|
|
{
|
|
formato_campo.cut(p);
|
|
formato_campo << "#t";
|
|
_string_roman.add(new TString);
|
|
_field_roman.add(s);
|
|
const int last = _string_roman.items() - 1;
|
|
|
|
set_row (riga_record, formato_campo, _string_roman.objptr(last));
|
|
}
|
|
else
|
|
{
|
|
if (formato_campo.find("@pn"))
|
|
picture = line.get();
|
|
else
|
|
picture = "";
|
|
|
|
if (to == -1)
|
|
if (picture != "")
|
|
set_row (riga_record, formato_campo, FLD(logicnum,name,picture) );
|
|
else
|
|
set_row (riga_record, formato_campo, FLD(logicnum,name) );
|
|
else
|
|
set_row (riga_record, formato_campo, FLD(logicnum,name,from,to) );
|
|
}
|
|
|
|
line = (const char *) rpt.line();
|
|
}
|
|
}
|
|
|
|
void BA3200_application::set_footers()
|
|
{
|
|
TToken_string line;
|
|
int footer_len, riga;
|
|
TString formato, testo;
|
|
|
|
reset_footer();
|
|
|
|
TScanner rpt(_rptname);
|
|
rpt.paragraph("Footers");
|
|
|
|
line = rpt.line();
|
|
footer_len = line.get_int();
|
|
if (footer_len) printer().footerlen (footer_len);
|
|
|
|
line = rpt.line();
|
|
while ( (line != "") && (line[0] != '[') )
|
|
{
|
|
riga = line.get_int();
|
|
formato = line.get();
|
|
testo = line.get();
|
|
set_footer (riga, (const char *)formato, (const char*)testo);
|
|
line = rpt.line();
|
|
}
|
|
}
|
|
|
|
void BA3200_application::set_translations()
|
|
{
|
|
TString campo, from, to;
|
|
TToken_string line;
|
|
int logicnum;
|
|
|
|
TScanner rpt(_rptname);
|
|
rpt.paragraph("Translations");
|
|
|
|
line = rpt.line();
|
|
while ( (line != "") && (line[0] != '[') )
|
|
{
|
|
logicnum = line.get_int();
|
|
campo = line.get();
|
|
from = line.get();
|
|
to = line.get();
|
|
set_translation (logicnum, (char*)(const char *)campo, (char*)(const char *)from, (char*)(const char *)to);
|
|
line = rpt.line();
|
|
}
|
|
}
|
|
|
|
void BA3200_application::set_relations()
|
|
{
|
|
TToken_string line("", ',');
|
|
TString tab(16), expr(40);
|
|
int key, linkto, alias, logicnum;
|
|
|
|
TScanner rpt(_rptname);
|
|
rpt.paragraph("Relations");
|
|
|
|
line = rpt.line();
|
|
while ( (line != "") && (line[0] != '[') )
|
|
{
|
|
tab = line.get();
|
|
logicnum = atoi(tab);
|
|
expr = line.get();
|
|
key = line.get_int();
|
|
if (key == 0) key = 1;
|
|
linkto = line.get_int();
|
|
alias = line.get_int();
|
|
if (logicnum > 0)
|
|
_rel->add(logicnum, expr, key, linkto, alias);
|
|
else
|
|
_rel->add(tab, expr, key, linkto, alias);
|
|
|
|
line = rpt.line();
|
|
}
|
|
}
|
|
void BA3200_application::leggi_rpt()
|
|
{
|
|
set_rows();
|
|
}
|
|
|
|
void BA3200_application::user_create()
|
|
{
|
|
_rptname << "batb" << _tabname << ".rpt" ;
|
|
if (!fexist(_rptname))
|
|
fatal_box("Impossibile aprire il file '%s'", (const char*)_rptname);
|
|
|
|
|
|
// _tab = new TTable (_tabname);
|
|
_rel = new TRelation (_tabname);
|
|
_cur = new TCursor (_rel);
|
|
|
|
_maskname << "bast" << _tabname;
|
|
_msk = new TMask (_maskname) ;
|
|
|
|
add_cursor (_cur);
|
|
add_file (_tabname);
|
|
|
|
_logicnum = _cur->file()->num();
|
|
|
|
reset_print ();
|
|
|
|
printer().footerlen (FOOTER_LEN);
|
|
for (int i=1; i <= FOOTER_LEN; i++) set_footer(i, "%s", " ");
|
|
|
|
set_headers();
|
|
set_footers();
|
|
set_translations();
|
|
set_relations();
|
|
}
|
|
|
|
void BA3200_application::user_destroy()
|
|
{
|
|
delete _msk;
|
|
delete _cur;
|
|
delete _rel;
|
|
// delete _tab;
|
|
}
|
|
|
|
int ba3200(int argc, char* argv[])
|
|
{
|
|
BA3200_application a(argv[2]) ;
|
|
a.run(argc, argv, "Tabella");
|
|
return 0;
|
|
}
|