Patch level : 12.0 1040
Files correlati : tutto in Commento : Aggiornato il modulo intra Interno : Primo rilascio mancano la generazione riepiloghi e l'invio delle righe di servizio
This commit is contained in:
parent
a1e246518e
commit
800cf412cf
@ -1069,41 +1069,54 @@ TTextfile::~TTextfile ()
|
||||
// TTracciatoInvio
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
void TTracciatoInvio::add_field(const char* name, InvioFieldType type, int pos, int len, int dec, int fldno)
|
||||
void TTracciatoInvio::add_field(const char* name, InvioFieldType type, int len, int dec)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AN:
|
||||
break;
|
||||
case CB:
|
||||
CHECKD(len == 1, "Booleano di lunghezza sospetta ", len);
|
||||
// type = NU;
|
||||
if (len == 0)
|
||||
len = 1;
|
||||
type = NU;
|
||||
break;
|
||||
case CF:
|
||||
CHECKD(len == 16, "Codice fiscale di lunghezza sospetta ", len);
|
||||
type = AN;
|
||||
len = 16;
|
||||
break;
|
||||
case PI:
|
||||
case CN:
|
||||
CHECKD(len == 11, "Codice fiscale numerico di lunghezza sospetta ", len);
|
||||
type = NU;
|
||||
len = 11;
|
||||
break;
|
||||
case DA:
|
||||
CHECKD(len == 6, "Mese+Anno di lunghezza sospetta ", len);
|
||||
type = NU;
|
||||
len = 4;
|
||||
break;
|
||||
case D6:
|
||||
type = NU;
|
||||
len = 6;
|
||||
break;
|
||||
case DT:
|
||||
CHECKD(len == 8, "Data di lunghezza sospetta ", len);
|
||||
type = NU;
|
||||
len = 8;
|
||||
break;
|
||||
case NP:
|
||||
type = NU;
|
||||
case NU:
|
||||
break;
|
||||
case PN:
|
||||
case PR:
|
||||
CHECKD(len == 2, "provincia di lunghezza sospetta ", len);
|
||||
type = AN;
|
||||
len = 2;
|
||||
break;
|
||||
case QU:
|
||||
CHECK(len > dec + 1, "numero di decimali incoerente");
|
||||
break;
|
||||
case FV:
|
||||
len = strlen(name);
|
||||
// CHECK(strlen(name) == len, "lunghezza campo fisso incoerente");
|
||||
break;
|
||||
default:
|
||||
CHECK(false, "tipo campo sospetto");
|
||||
break;
|
||||
@ -1112,127 +1125,106 @@ void TTracciatoInvio::add_field(const char* name, InvioFieldType type, int pos,
|
||||
TFieldInvio* info = new TFieldInvio;
|
||||
info->_desc = name;
|
||||
info->_type = type;
|
||||
info->_pos = pos;
|
||||
info->_pos = _len + 1;
|
||||
info->_len = len;
|
||||
info->_dec = dec;
|
||||
|
||||
if (fldno <= 0)
|
||||
fldno = _fields.add(info) + 1;
|
||||
else
|
||||
_fields.add(info, fldno - 1);
|
||||
_len += len;
|
||||
_fields.add(name, info);
|
||||
}
|
||||
|
||||
const TFieldInvio& TTracciatoInvio::field(int pos) const
|
||||
const TFieldInvio& TTracciatoInvio::field(const char * name) const
|
||||
{
|
||||
TFieldInvio* info = (TFieldInvio*)_fields.objptr(pos - 1);
|
||||
TFieldInvio* info = (TFieldInvio*)_fields.objptr(name);
|
||||
|
||||
#ifdef DBG
|
||||
if (info == NULL)
|
||||
fatal_box("Non esiste il campo %d sul tipo record %c", pos, _tipo);
|
||||
if (info == nullptr)
|
||||
fatal_box("Non esiste il campo %s sul tipo record %c", name, _tipo);
|
||||
#endif
|
||||
return *info;
|
||||
}
|
||||
|
||||
void TTracciatoInvio::auto_fill(TString& buffer) const
|
||||
void TTracciatoInvio::zero(TString& buffer)
|
||||
{
|
||||
buffer.fill(' ', TOTAL_SIZE);
|
||||
char* ptr = buffer.get_buffer();
|
||||
for (int f = _fields.last(); f >= 0; f = _fields.pred(f))
|
||||
|
||||
FOR_EACH_ASSOC_OBJECT( _fields, hash, name, obj)
|
||||
{
|
||||
const TFieldInvio& info = (const TFieldInvio&)_fields[f];
|
||||
const TFieldInvio& info = (const TFieldInvio&)_fields[name];
|
||||
if (info._type == NU || info._type == CB || info._type == DA || info._type == DT || info._type == CN)
|
||||
memset(ptr + info._pos - 1, '0', info._len);
|
||||
else
|
||||
if (info._type == FV)
|
||||
buffer.overwrite(info._desc, info._pos -1, info._len);
|
||||
}
|
||||
buffer[0] = _tipo;
|
||||
buffer.overwrite("A\r\n", TOTAL_SIZE - 3);
|
||||
}
|
||||
|
||||
TTracciatoInvio::TTracciatoInvio(char tipo) : _tipo(tipo)
|
||||
TTracciatoInvio::TTracciatoInvio(char tipo) : _tipo(tipo), _len(0)
|
||||
{
|
||||
if (strchr("ABCEFHJZ[", tipo) == NULL)
|
||||
NFCHECK("Tipo record non valido: %c", tipo);
|
||||
|
||||
add_field("Tipo record", AN, 1, 1); // 1
|
||||
add_field("Tipo record", AN, 1); // 1
|
||||
}
|
||||
|
||||
TTracciatoInvio::~TTracciatoInvio()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
///////////////////////////////////////////////////////////
|
||||
// TTracciatiInvio
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TTracciatiInvio _trcInvio;
|
||||
|
||||
const TTracciatoInvio& TTracciatiInvio::add_tracciato(TTracciatoInvio * tracciato)
|
||||
{
|
||||
int pos = tracciato->tipo() - 'A';
|
||||
const TTracciatoInvio* trc = (TTracciatoInvio*)_trc.objptr(pos);
|
||||
TTracciatiInvio & tracciati() { return _trcInvio; }
|
||||
|
||||
if (trc == nullptr)
|
||||
_trc.add(tracciato, pos);
|
||||
return *tracciato;
|
||||
}
|
||||
|
||||
class TTracciatoInvioFileDati : public TTracciatoInvio
|
||||
class TTracciatiInvio : public TObject
|
||||
{
|
||||
TArray _trc;
|
||||
|
||||
public:
|
||||
TTracciatoInvioFileDati(const TRectype& rec);
|
||||
virtual ~TTracciatoInvioFileDati() {}
|
||||
const TTracciatoInvio* tracciato(TTracciatoInvio * trc);
|
||||
const TTracciatoInvio& tracciato(TRecordInvio & rec);
|
||||
|
||||
int tipo2pos(int tipo) const;
|
||||
bool exist(int tipo) const { return _trc.objptr(tipo2pos(tipo)) != nullptr; }
|
||||
|
||||
void destroy();
|
||||
|
||||
TTracciatiInvio();
|
||||
virtual ~TTracciatiInvio();
|
||||
};
|
||||
|
||||
TTracciatoInvioFileDati::TTracciatoInvioFileDati(const TRectype& rec)
|
||||
{
|
||||
for (int i = 0; i < rec.items(); i++)
|
||||
{
|
||||
const TString16 fieldname(rec.rec_des().Fd[i].Name);
|
||||
TFieldtypes t = rec.type(fieldname);
|
||||
int pos = 0;
|
||||
TTracciatiInvio & tracciati();
|
||||
|
||||
switch (t)
|
||||
{
|
||||
case _nullfld:
|
||||
break;
|
||||
case _alfafld: // @emem Campo di tipo alfanumerico
|
||||
add_field(fieldname, AN, pos++, rec.length(fieldname));
|
||||
break;
|
||||
case _intfld: // @emem Campo di tipo intero
|
||||
case _longfld: // @emem Campo di tipo intero lungo
|
||||
add_field(fieldname, NU, pos++, rec.length(fieldname));
|
||||
break;
|
||||
case _realfld: // @emem Campo di tipo reale (vedi <c real>)
|
||||
add_field(fieldname, NU/*QU*/, pos++, rec.length(fieldname));
|
||||
break;
|
||||
case _datefld: // @emem Campo di tipo data (vedi <c TDate>)
|
||||
add_field(fieldname, DT, pos++, rec.length(fieldname));
|
||||
break;
|
||||
case _wordfld: // @emem Campo di tipo intero senza segno
|
||||
add_field(fieldname, NU, pos++, rec.length(fieldname));
|
||||
break;
|
||||
case _charfld: // @emem Campo di tipo carattere
|
||||
add_field(fieldname, AN, pos++, 1);
|
||||
break;
|
||||
case _boolfld: // @emem Campo di tipo booleano
|
||||
add_field(fieldname, CB, pos++, rec.length(fieldname));
|
||||
break;
|
||||
case _intzerofld: // @emem Campo di tipo intero zero filled
|
||||
case _longzerofld: // @emem Campo di tipo intero lungo zero filled
|
||||
add_field(fieldname, NU, pos++, rec.length(fieldname));
|
||||
break;
|
||||
case _memofld:
|
||||
add_field(fieldname, AN, pos++, rec.length(fieldname));
|
||||
break;
|
||||
}
|
||||
}
|
||||
const TTracciatoInvio * TTracciatiInvio::tracciato(TTracciatoInvio * trc)
|
||||
{
|
||||
char tipo = trc->tipo();
|
||||
int pos = tipo2pos(tipo);
|
||||
|
||||
if (!exist(tipo))
|
||||
_trc.add(trc, pos);
|
||||
return (const TTracciatoInvio*)_trc.objptr(pos);
|
||||
}
|
||||
|
||||
TTracciatiInvio & tracciati() {return _trcInvio;}
|
||||
const TTracciatoInvio& TTracciatiInvio::tracciato(TRecordInvio & rec)
|
||||
{
|
||||
char tipo = rec.tipo_record();
|
||||
int pos = tipo2pos(tipo);
|
||||
|
||||
const TTracciatoInvio& TTracciatiInvio::tracciato(char tipo)
|
||||
if (!exist(tipo))
|
||||
_trc.add(rec.add_tracciato(), pos);
|
||||
return *(const TTracciatoInvio*)_trc.objptr(pos);
|
||||
}
|
||||
|
||||
int TTracciatiInvio::tipo2pos(int tipo) const
|
||||
{
|
||||
CHECK((tipo >= 'A' && tipo <= 'Z') || tipo == '[', "Tipo record non valido");
|
||||
const int pos = tipo - 'A';
|
||||
const TTracciatoInvio* trc = (TTracciatoInvio*)_trc.objptr(pos);
|
||||
|
||||
if (trc == NULL)
|
||||
trc = &tracciati().add_tracciato(new TTracciatoInvio(tipo));
|
||||
return *trc;
|
||||
return tipo - 'A';
|
||||
}
|
||||
|
||||
void TTracciatiInvio::destroy()
|
||||
@ -1248,20 +1240,56 @@ TTracciatiInvio::~TTracciatiInvio()
|
||||
{
|
||||
destroy(); // Non viene mai chiamato!
|
||||
}
|
||||
*/
|
||||
|
||||
TTracciatoInvioFileDati::TTracciatoInvioFileDati(const TRectype& rec)
|
||||
{
|
||||
for (int i = 0; i < rec.items(); i++)
|
||||
{
|
||||
const TString16 fieldname(rec.rec_des().Fd[i].Name);
|
||||
TFieldtypes t = rec.type(fieldname);
|
||||
|
||||
switch (t)
|
||||
{
|
||||
case _nullfld:
|
||||
break;
|
||||
case _alfafld: // @emem Campo di tipo alfanumerico
|
||||
add_field(fieldname, AN, rec.length(fieldname));
|
||||
break;
|
||||
case _intfld: // @emem Campo di tipo intero
|
||||
case _longfld: // @emem Campo di tipo intero lungo
|
||||
add_field(fieldname, NU, rec.length(fieldname));
|
||||
break;
|
||||
case _realfld: // @emem Campo di tipo reale (vedi <c real>)
|
||||
add_field(fieldname, QU, rec.length(fieldname), rec.ndec(fieldname));
|
||||
break;
|
||||
case _datefld: // @emem Campo di tipo data (vedi <c TDate>)
|
||||
add_field(fieldname, DT, rec.length(fieldname));
|
||||
break;
|
||||
case _wordfld: // @emem Campo di tipo intero senza segno
|
||||
add_field(fieldname, NU, rec.length(fieldname));
|
||||
break;
|
||||
case _charfld: // @emem Campo di tipo carattere
|
||||
add_field(fieldname, AN, 1);
|
||||
break;
|
||||
case _boolfld: // @emem Campo di tipo booleano
|
||||
add_field(fieldname, CB, rec.length(fieldname));
|
||||
break;
|
||||
case _intzerofld: // @emem Campo di tipo intero zero filled
|
||||
case _longzerofld: // @emem Campo di tipo intero lungo zero filled
|
||||
add_field(fieldname, NU, rec.length(fieldname));
|
||||
break;
|
||||
case _memofld:
|
||||
add_field(fieldname, AN, 512);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TRecordInvio
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
const TTracciatoInvio& TRecordInvio::tracciato() const
|
||||
{
|
||||
return _trcInvio.tracciato(tipo_record());
|
||||
}
|
||||
|
||||
void TRecordInvio::print_on(ostream& outs) const
|
||||
{
|
||||
outs.write(_buffer, TOTAL_SIZE);
|
||||
}
|
||||
|
||||
void TRecordInvio::read_from(istream& ins)
|
||||
{
|
||||
@ -1269,14 +1297,11 @@ void TRecordInvio::read_from(istream& ins)
|
||||
ins.read(_buffer.get_buffer(), TOTAL_SIZE);
|
||||
}
|
||||
|
||||
const TFieldInvio& TRecordInvio::get_field(int pos) const
|
||||
{
|
||||
return tracciato().field(pos);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(const TFieldInvio& fld, const char* val)
|
||||
{
|
||||
TString256 str(val); // Ci sono campi di 100 caratteri!
|
||||
TString str(val); // Ci sono campi di 100 caratteri!
|
||||
|
||||
if (fld._type == AN)
|
||||
str.upper();
|
||||
if (fld._type == QU)
|
||||
@ -1317,42 +1342,55 @@ void TRecordInvio::set(const TFieldInvio& fld, const char* val)
|
||||
_buffer.overwrite(str, fld._pos - 1);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(int pos, const char* val)
|
||||
void TRecordInvio::set(const char* name, const char* val)
|
||||
{
|
||||
const TFieldInvio& fld = tracciato().field(pos);
|
||||
const TFieldInvio& fld = tracciato().field(name);
|
||||
|
||||
set(fld, val);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(int pos, int val)
|
||||
void TRecordInvio::set(const char* name, int val)
|
||||
{
|
||||
const TFieldInvio& fld = tracciato().field(pos);
|
||||
CHECKD(fld._type == NU, "Invalid numeric field ", pos);
|
||||
const TFieldInvio& fld = tracciato().field(name);
|
||||
|
||||
CHECKS(fld._type == NU, "Invalid numeric field ", name);
|
||||
|
||||
TString16 str; str.format("%d", val);
|
||||
|
||||
set(fld, str);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(int pos, long val)
|
||||
void TRecordInvio::set(const char* name, long val)
|
||||
{
|
||||
const TFieldInvio& fld = tracciato().field(pos);
|
||||
CHECKD(fld._type == NU, "Invalid numeric field ", pos);
|
||||
const TFieldInvio& fld = tracciato().field(name);
|
||||
|
||||
CHECKS(fld._type == NU, "Invalid numeric field ", name);
|
||||
|
||||
TString16 str; str.format("%ld", val);
|
||||
|
||||
set(fld, str);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(int pos, const real& val)
|
||||
void TRecordInvio::set(const char* name, const real& val)
|
||||
{
|
||||
const TFieldInvio& fld = tracciato().field(pos);
|
||||
CHECKD(fld._type == NU, "Invalid numeric field ", pos);
|
||||
const TFieldInvio& fld = tracciato().field(name);
|
||||
|
||||
CHECKS(fld._type == NU, "Invalid numeric field ", name);
|
||||
|
||||
const char* str = val.string(fld._len, 0);
|
||||
|
||||
set(fld, str);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(int pos, const TDate& val)
|
||||
void TRecordInvio::set(const char* name, const TDate& val)
|
||||
{
|
||||
const TFieldInvio& fld = tracciato().field(pos);
|
||||
CHECKD(fld._type == NU && (fld._len == 6 || fld._len == 8),
|
||||
"Invalid date field ", pos);
|
||||
const TFieldInvio& fld = tracciato().field(name);
|
||||
|
||||
CHECKS(fld._type == NU && (fld._len == 6 || fld._len == 8),
|
||||
"Invalid date field ", name);
|
||||
|
||||
const char* str;
|
||||
|
||||
if (fld._len == 8)
|
||||
str = val.string(full, '\0', full, full, gma_date);
|
||||
else
|
||||
@ -1360,38 +1398,47 @@ void TRecordInvio::set(int pos, const TDate& val)
|
||||
set(fld, str);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(int pos, char val)
|
||||
void TRecordInvio::set(const char* name, char val)
|
||||
{
|
||||
const TFieldInvio& fld = get_field(pos);
|
||||
CHECKD(fld._type == AN && fld._len == 1, "Invalid char field ", pos);
|
||||
const TFieldInvio& fld = get_field(name);
|
||||
|
||||
CHECKS(fld._type == AN && fld._len == 1, "Invalid char field ", name);
|
||||
|
||||
const char str[2] = { val, '\0' };
|
||||
|
||||
set(fld, str);
|
||||
}
|
||||
|
||||
void TRecordInvio::set(int pos, bool val)
|
||||
void TRecordInvio::set(const char* name, bool val)
|
||||
{
|
||||
const TFieldInvio& fld = get_field(pos);
|
||||
CHECKD((fld._type == CB || fld._type == NU) && fld._len == 1, "Invalid boolean field ", pos);
|
||||
const TFieldInvio& fld = get_field(name);
|
||||
|
||||
CHECKS((fld._type == CB || fld._type == NU) && fld._len == 1, "Invalid boolean field ", name);
|
||||
|
||||
set(fld, val ? "1" : "0");
|
||||
}
|
||||
|
||||
const char* TRecordInvio::get(int pos, TString& str) const
|
||||
const char* TRecordInvio::get(const char* name, TString& str) const
|
||||
{
|
||||
const TFieldInvio& fld = get_field(pos);
|
||||
const TFieldInvio& fld = get_field(name);
|
||||
|
||||
str = _buffer.mid(fld._pos - 1, fld._len);
|
||||
return str.trim();
|
||||
}
|
||||
|
||||
int TRecordInvio::get_int(int pos) const
|
||||
int TRecordInvio::get_int(const char* name) const
|
||||
{
|
||||
TString16 str; get(pos, str);
|
||||
TString16 str; get(name, str);
|
||||
|
||||
return atoi(str);
|
||||
}
|
||||
|
||||
char TRecordInvio::get_char(int pos) const
|
||||
char TRecordInvio::get_char(const char* name) const
|
||||
{
|
||||
const TFieldInvio& fld = get_field(pos);
|
||||
CHECKD(fld._type == AN, "Invalid char field ", pos);
|
||||
const TFieldInvio& fld = get_field(name);
|
||||
|
||||
CHECKS(fld._type == AN, "Invalid char field ", name);
|
||||
|
||||
return _buffer[fld._pos - 1];
|
||||
}
|
||||
|
||||
@ -1411,10 +1458,21 @@ int TRecordInvio::calculate_blocks(const char* val) const
|
||||
|
||||
void TRecordInvio::tipo_record(char tipo)
|
||||
{
|
||||
_buffer[0] = tipo; tracciato().auto_fill(_buffer);
|
||||
_buffer[0] = tipo;
|
||||
}
|
||||
|
||||
// Azzera tutti i campi non posizionali dei record di tipo E
|
||||
const TRecordInvio& TRecordInvio::operator = (const TRecordInvio& rec)
|
||||
{
|
||||
_buffer = rec._buffer;
|
||||
if (tipo_record() != rec.tipo_record())
|
||||
{
|
||||
safe_delete(_tracciato);
|
||||
tracciato();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Azzera tutti i campi non posizionali
|
||||
void TRecordInvio::azzera_campi_non_posizionali()
|
||||
{
|
||||
CHECK(ha_campi_non_posizionali(), "Impossibile azzerare un record senza campi non posizionali");
|
||||
@ -1422,30 +1480,41 @@ void TRecordInvio::azzera_campi_non_posizionali()
|
||||
memset(buf, ' ', USEABLE_SIZE);
|
||||
}
|
||||
|
||||
// Aggiunge un campo non posizionale ai record di tipo E,F,G,H,J
|
||||
// Aggiunge un campo non posizionale ai record
|
||||
bool TRecordInvio::np_put(const char* code, const char* val)
|
||||
{
|
||||
CHECK(ha_campi_non_posizionali(), "Impossibile aggiungere campi non posizionali");
|
||||
CHECKS(code && strlen(code) == CODE_SIZE, "Invalid field code ", code);
|
||||
//CHECKS(val && *val, "Can't add empty field ", code);
|
||||
if (!(val && *val))
|
||||
return false;
|
||||
|
||||
// Cerca il primo posto libero
|
||||
int pos;
|
||||
for (pos = HEADER_SIZE; pos < HEADER_SIZE + USEABLE_SIZE; pos += BLOCK_SIZE)
|
||||
{
|
||||
if (_buffer[pos] == ' ')
|
||||
break;
|
||||
}
|
||||
const int free_blocks = (USEABLE_SIZE - pos) / BLOCK_SIZE;
|
||||
const int needed_blocks = calculate_blocks(val);
|
||||
const bool ok = free_blocks >= needed_blocks;
|
||||
bool ok = true;
|
||||
|
||||
if (ok) // Se ci sono abbastanza blocchi liberi
|
||||
if (val && *val)
|
||||
{
|
||||
// Cerca il primo posto libero
|
||||
int pos;
|
||||
|
||||
for (pos = HEADER_SIZE; pos < HEADER_SIZE + USEABLE_SIZE; pos += BLOCK_SIZE)
|
||||
{
|
||||
if (_buffer[pos] == ' ')
|
||||
break;
|
||||
}
|
||||
const int free_blocks = (USEABLE_SIZE - pos) / BLOCK_SIZE;
|
||||
const int needed_blocks = calculate_blocks(val);
|
||||
bool ok = free_blocks >= needed_blocks;
|
||||
TString80 str(val); str.upper();
|
||||
const int lenstr = str.len();
|
||||
|
||||
if (!ok) // Se non ci sono abbastanza blocchi liberi
|
||||
{
|
||||
ok = true;
|
||||
change_record();
|
||||
pos = HEADER_SIZE;
|
||||
if (str.len() > USEABLE_SIZE)
|
||||
str.cut(USEABLE_SIZE);
|
||||
}
|
||||
|
||||
int lenstr = str.len();
|
||||
|
||||
for (int i = 0; i < lenstr; )
|
||||
{
|
||||
_buffer.overwrite(code, pos);
|
||||
@ -1468,53 +1537,53 @@ bool TRecordInvio::np_put(const char* code, const char* val)
|
||||
|
||||
bool TRecordInvio::np_put(const char* code, long val)
|
||||
{
|
||||
TString16 str; str.format("%16ld", val);
|
||||
TString16 str;
|
||||
|
||||
str.format("%16ld", val);
|
||||
return np_put(code, str);
|
||||
}
|
||||
|
||||
bool TRecordInvio::np_put(const char* code, const real& val)
|
||||
{
|
||||
bool done = !val.is_zero();
|
||||
if (done)
|
||||
if (!val.is_zero())
|
||||
{
|
||||
const TString& str = val.stringa(16, 2);
|
||||
done = np_put(code, str);
|
||||
|
||||
return np_put(code, str);
|
||||
}
|
||||
return done;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TRecordInvio::np_put(const char* code, char val)
|
||||
{
|
||||
bool done = val > ' ';
|
||||
if (done)
|
||||
if (val > ' ')
|
||||
{
|
||||
const char str[2] = { val, '\0' };
|
||||
done = np_put(code, str);
|
||||
|
||||
return np_put(code, str);
|
||||
}
|
||||
return done;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TRecordInvio::np_put(const char* code, const TDate& date)
|
||||
{
|
||||
bool done = date.ok();
|
||||
if (done)
|
||||
if (date.ok())
|
||||
{
|
||||
TString16 str;
|
||||
str.format("%8s%02d%02d%04d", "", date.day(), date.month(), date.year());
|
||||
done = np_put(code, str);
|
||||
return np_put(code, str);
|
||||
}
|
||||
return done;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TRecordInvio::np_put(const char* code, bool cb)
|
||||
{
|
||||
bool done = false;
|
||||
if (cb)
|
||||
{
|
||||
TString16 str; str.format("%16d", 1);
|
||||
done = np_put(code, str);
|
||||
return np_put(code, str);
|
||||
}
|
||||
return done;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TRecordInvio::np_get(int pos, TString& key, TString& val) const
|
||||
@ -1561,9 +1630,6 @@ bool TRecordInvio::valid() const
|
||||
return ok;
|
||||
}
|
||||
|
||||
TRecordInvio::TRecordInvio(const TRectype& rec) : _buffer(TOTAL_SIZE, ' ')
|
||||
TRecordInvio::TRecordInvio(const TRectype& rec) : _buffer(TOTAL_SIZE, ' '), _tracciato(nullptr)
|
||||
{
|
||||
tracciati().add_tracciato(new TTracciatoInvioFileDati(rec));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -216,7 +216,7 @@ enum { CODE_SIZE = 8, FIELD_SIZE = 16, BLOCK_SIZE = 24, HEADER_SIZE = 89, USEABL
|
||||
// TRecordInvio
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
enum InvioFieldType { AN, CF, CN, PI, DA, DT, NU, PN, PR, CB, VP, VN, QU };
|
||||
enum InvioFieldType { AN, CF, CN, PI, DA, D6, DT, NU, NP, PN, PR, CB, VP, VN, QU, FV /* FixVal */};
|
||||
|
||||
struct TFieldInvio : public TObject
|
||||
{
|
||||
@ -230,71 +230,55 @@ struct TFieldInvio : public TObject
|
||||
class TTracciatoInvio : public TObject
|
||||
{
|
||||
char _tipo;
|
||||
TArray _fields;
|
||||
int _len;
|
||||
TAssoc_array _fields;
|
||||
|
||||
protected:
|
||||
void add_field(const char* name, InvioFieldType tipo, int pos, int len, int dec = 0, int filedno = 0);
|
||||
void add_filler(int pos, int len, InvioFieldType tipo = AN) { add_field("Filler", tipo, pos, len); }
|
||||
void add_field(const char* name, InvioFieldType tipo, int len = 0, int dec = 0);
|
||||
void add_fixedval(const char* name, int len, int filedno = 0) { add_field(name, FV, len); }
|
||||
void add_filler(int len, InvioFieldType tipo = AN) { add_field("Filler", tipo, len); }
|
||||
|
||||
TTracciatoInvio() {}
|
||||
void set_tipo(char t) { _tipo = t; }
|
||||
|
||||
public:
|
||||
bool exists(int pos) const { return _fields.objptr(pos - 1) != NULL; }
|
||||
const TFieldInvio& field(int pos) const;
|
||||
void auto_fill(TString& buffer) const;
|
||||
int campi_posizionali() const { return _fields.last() + 1; }
|
||||
bool exists(const char * name) const { return _fields.objptr(name) != nullptr; }
|
||||
const TFieldInvio& field(const char *name) const;
|
||||
void zero(TString& buffer);
|
||||
int campi_posizionali() const { return _fields.items() + 1; }
|
||||
char tipo() const { return _tipo; }
|
||||
int len() const { return _len; }
|
||||
|
||||
TTracciatoInvio(char tipo);
|
||||
virtual ~TTracciatoInvio();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TTracciatiInvio
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
class TTracciatiInvio : public TObject
|
||||
{
|
||||
TArray _trc;
|
||||
|
||||
public:
|
||||
const TTracciatoInvio& tracciato(char tipo);
|
||||
const TTracciatoInvio& add_tracciato(TTracciatoInvio * tracciato);
|
||||
|
||||
void destroy();
|
||||
|
||||
TTracciatiInvio();
|
||||
virtual ~TTracciatiInvio();
|
||||
};
|
||||
|
||||
TTracciatiInvio & tracciati();
|
||||
|
||||
class TRecordInvio : public TObject
|
||||
{
|
||||
TString _buffer;
|
||||
TTracciatoInvio * _tracciato ;
|
||||
|
||||
protected: // TObject
|
||||
virtual TObject* dup() const { return new TRecordInvio(*this); }
|
||||
virtual void print_on(ostream& outs) const;
|
||||
virtual void print_on(ostream& outs) const { outs.write(_buffer, TOTAL_SIZE); }
|
||||
virtual void read_from(istream& ins);
|
||||
|
||||
protected: // TObject
|
||||
//virtual const TTracciatoInvio& add_tracciato(char tipo);
|
||||
virtual const TTracciatoInvio& tracciato() const;
|
||||
|
||||
const TFieldInvio& get_field(int pos) const;
|
||||
virtual const TTracciatoInvio& tracciato() const { return *_tracciato; }
|
||||
const TFieldInvio& get_field(const char* name) const { return tracciato().field(name); }
|
||||
void set(const TFieldInvio& fld, const char* val);
|
||||
int calculate_blocks(const char* val) const;
|
||||
|
||||
public:
|
||||
void set(int pos, const char* val);
|
||||
void set(int pos, int val);
|
||||
void set(int pos, long val);
|
||||
void set(int pos, const real& val);
|
||||
void set(int pos, const TDate& val);
|
||||
void set(int pos, char val);
|
||||
void set(int pos, bool val);
|
||||
void zero() { ((TTracciatoInvio &)tracciato()).zero(_buffer); }
|
||||
|
||||
void set(const char* name, const char* val);
|
||||
void set(const char* name, int val);
|
||||
void set(const char* name, long val);
|
||||
void set(const char* name, const real& val);
|
||||
void set(const char* name, const TDate& val);
|
||||
void set(const char* name, char val);
|
||||
void set(const char* name, bool val);
|
||||
bool np_put(const char* code, const char* val);
|
||||
bool np_put(const char* code, const real& val);
|
||||
bool np_put(const char* code, long val);
|
||||
@ -302,20 +286,20 @@ public:
|
||||
bool np_put(const char* code, const TDate& date);
|
||||
bool np_put(const char* code, bool cb);
|
||||
|
||||
const char* get(int pos, TString& str) const;
|
||||
int get_int(int pos) const;
|
||||
char get_char(int pos) const;
|
||||
virtual bool change_record() { return false; }
|
||||
|
||||
const char* get(const char* name, TString& str) const;
|
||||
int get_int(const char* name) const;
|
||||
char get_char(const char* name) const;
|
||||
|
||||
bool np_get(int pos, TString& key, TString& val) const;
|
||||
bool np_get_real(int pos, TString& key, real& val) const;
|
||||
|
||||
const TRecordInvio& operator=(const TRecordInvio& rec)
|
||||
{
|
||||
_buffer = rec._buffer; return *this;
|
||||
}
|
||||
const TRecordInvio& operator = (const TRecordInvio& rec);
|
||||
|
||||
char tipo_record() const { return _buffer[0]; }
|
||||
void tipo_record(char tipo);
|
||||
int len() const { return tracciato().len(); }
|
||||
|
||||
int campi_posizionali() const { return tracciato().campi_posizionali(); }
|
||||
void azzera_campi_non_posizionali();
|
||||
@ -324,12 +308,27 @@ public:
|
||||
|
||||
virtual bool valid() const;
|
||||
|
||||
TRecordInvio() : _buffer(TOTAL_SIZE, ' ') {}
|
||||
TRecordInvio(char tipo) : _buffer(TOTAL_SIZE, ' ') { tipo_record(tipo); }
|
||||
TRecordInvio(const TRecordInvio& rec) : _buffer(rec._buffer) { }
|
||||
TRecordInvio(char tipo) : _buffer(TOTAL_SIZE, ' '), _tracciato(nullptr) { tipo_record(tipo); }
|
||||
TRecordInvio(const TRecordInvio& rec) : _buffer(rec._buffer), _tracciato(nullptr) { tracciato(); }
|
||||
TRecordInvio(const TRectype& rec);
|
||||
virtual ~TRecordInvio() { }
|
||||
};
|
||||
|
||||
class TTracciatoInvioFileDati : public TTracciatoInvio
|
||||
{
|
||||
public:
|
||||
TTracciatoInvioFileDati(const TRectype& rec);
|
||||
virtual ~TTracciatoInvioFileDati() {}
|
||||
};
|
||||
|
||||
class TRecordInvioFileDati : public TRecordInvio
|
||||
{
|
||||
protected: // TObject
|
||||
virtual TObject* dup() const { return new TRecordInvioFileDati(*this); }
|
||||
|
||||
public:
|
||||
TRecordInvioFileDati(const TRectype& rec) : TRecordInvio('[') { }
|
||||
virtual ~TRecordInvioFileDati() { }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user