campo-sirio/ab/ab2100.cpp
alex 83dbe7df6e Modifche dalla vesrione Linux sulla 2.1
git-svn-id: svn://10.65.10.50/trunk@11856 c028cbd2-c16b-5b4b-a496-9718f37d4682
2004-03-13 09:03:18 +00:00

213 lines
4.7 KiB
C++
Executable File

//AB2100.CPP: Ricezione-Trasferimetno tabelle
#include <xvt.h>
#include <checks.h>
#include <string.h>
#include "ab2100a.h"
#include "ab2.h"
#include "ab2100.h"
#include "caradd.h"
#include "colldich.h"
/* ********************************************************************************************************* */
/* TTrasfer */
/*********************************************************************************************************** */
TObject_reception *TRicezione::set_transfer(int tipo_ricezione ,const TFilename & percorso, const TString & config_name)
{
if (_rice != NULL)
delete _rice;
switch (tipo_ricezione)
{
case RICEZIONE_INTERNA:
_rice = new TObject_reception(percorso);
break;
case RICEZIONE_AS400:
_rice = new TRicezione_AS400(percorso);
break;
case RICEZIONE_USER_DEFINED:
_rice = new TRicezione_userdef(config_name,percorso);
break;
}
return _rice;
}
int ab2100(int argc, char **argv)
{
char *rt = argv[2]+1; //Leggo se è richiesta la ricezine (r/R) o il trasferimento (t/T)
*rt=toupper(*rt);
switch (*rt)
{
case 'R': //Ricezione
{
ab2101(argc,argv);
break;
}
case 'T': //Trasferimento
{
ab2102(argc,argv);
break;
}
default:
error_box (TR("Sintassi: \n -0 -R -<utente> per ricezione \n -0 -T -<utente> per trasferimenTo"));
}
return 0;
}
TAdditional_car::TAdditional_car() :
TRectype(LF_CARADD)
{
}
void TAdditional_car::put_str(const char* fieldname, const char* val)
{
if (strcmp(fieldname,ABCA_ID)==0)
{
static TString16 id;
CHECK(length(ABCA_ID)<=16,"ID in CARADD deve essere max lungo 16");
id = val;
id.right_just(length(ABCA_ID));
TRectype::put_str(fieldname, (const char *)id);
} else
TRectype::put_str(fieldname, val);
}
bool TAdditional_car::same_as(real other_id)
{
bool r;
//TLocalisamfile ca(LF_CARADD);
TAdditional_cars ca;
ca.put(ABCA_ID,other_id);
ca.read();
real id = get_real(ABCA_ID);
put(ABCA_ID,ca.get(ABCA_ID));
r= (*this == ca.curr());
put(ABCA_ID,id);
return r;
}
TAdditional_cars::TAdditional_cars(TFilelock lockmode) :
TLocalisamfile (LF_CARADD)
{
set_curr(new TAdditional_car());
if (lockmode==_excllock)
{
lock(); //Il file è già aperto: gli faccio un lock
if (last()==NOERR)
_lastid=get_long(ABCA_ID);
else
_lastid=0;
} else
_lastid=-1;
}
long TAdditional_cars::lastid()
{
if (_lastid>=0)
{
return _lastid;
} else {
TLocalisamfile ca(LF_CARADD);
if (ca.last()==NOERR)
return atol(get(ABCA_ID));
else
return 0;
}
}
int TAdditional_cars::write()
{
int err;
if (_lastid>=0)
{
curr().put(ABCA_ID,++_lastid);
err=TLocalisamfile::write();
} else {
do {
curr().put(ABCA_ID,lastid()+1);
err=TLocalisamfile::write();
} while (err==_isdupkey);
}
return err;
}
/***********************/
TAdditional_col::TAdditional_col() :
TRectype(LF_COLLDICH)
{
}
long TAdditional_cols::_lastid = 0;
TAdditional_cols::TAdditional_cols() :
TLocalisamfile (LF_COLLDICH)
{
set_curr(new TAdditional_col());
if (_lastid == 0)
{
if (last()==NOERR)
_lastid=get_long(ABCD_ID);
}
}
/*long TAdditional_cols::lastid()
{
if (_lastid>=0)
{
return _lastid;
} else {
TLocalisamfile ca(LF_COLLDICH);
if (ca.last()==NOERR)
return atol(get(ABCD_ID));
else
return 0;
}
} */
int TAdditional_cols::write()
{
int err = NOERR;
bool scrivo = FALSE;
for (int i = curr().items(); (i > 1) && (!scrivo); i--) //Estraggo il campo
{
const char * name_field = curr().fieldname(i);
const char * str = "";
if (name_field) //Inizializzo la stringa solo se il puntatore non è nullo
str = curr().get(name_field);
if (strlen(str) > 0) //Se la stringa è stata inizilizzata a qualcosa entro per controllare
{
for (int ii = 0; str[ii]; ii++)
{//scorro il contenuto del campo per controllare se è vuoto
if ((str[ii] != ' ') && (str[ii] != '0'))
{
scrivo = TRUE; //se trovo qualcosa di "non vuoto" setto il flag di scrittura
break;
}
}
}
}
if (scrivo)
{
do {
curr().put(ABCD_ID,++_lastid);
err=TLocalisamfile::write();
} while (err==_isdupkey);
err=TLocalisamfile::write();
}
else
curr().put(ABCD_ID,0); //Il record non è stato scritto ma devo inserire nella chiave del rocord
//l'indice (=0) poichè questo andrà inserito in RELANA
return err;
}