- bacnvid e' l'applicazione di conversione. - bacnv contiene l'applicazione di conversione a qualsiasi formato. git-svn-id: svn://10.65.10.50/trunk@1534 c028cbd2-c16b-5b4b-a496-9718f37d4682
389 lines
9.0 KiB
C++
Executable File
389 lines
9.0 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <isam.h>
|
|
#include <date.h>
|
|
#include <prefix.h>
|
|
#include <progind.h>
|
|
#include <urldefid.h>
|
|
#include <utility.h>
|
|
|
|
#define DAYBIAS 36525L
|
|
#define DAYYEAR 365
|
|
|
|
extern "C" {
|
|
int CGetFieldBuff(char *, RecDes *, char *, char *);
|
|
int findfld(RecDes *, const char *);
|
|
};
|
|
|
|
|
|
byte m1[12] = {31,28,31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
int m2[12] = {31,59,90,120,151,181,212,243,273,304,334,365};
|
|
|
|
enum what {_date,_isam};
|
|
|
|
HIDDEN int CGetField(const char *fieldname,RecDes* recd,RecType recin,long* d)
|
|
|
|
{
|
|
int p, i;
|
|
unsigned int off;
|
|
byte len;
|
|
char *s1, s[10];
|
|
|
|
if ((p = findfld(recd, fieldname)) != -1)
|
|
{
|
|
off = recd->Fd[p].RecOff;
|
|
len = recd->Fd[p].Len;
|
|
if (recd->Fd[p].TypeF != _datefld)
|
|
{
|
|
while ((recin[off] == ' ') && (len))
|
|
{
|
|
off++;
|
|
len--;
|
|
}
|
|
}
|
|
if (len)
|
|
{
|
|
s1 = recin + off;
|
|
for (i = 0; i < len; i++) s[i] = s1[i];
|
|
s[len] = '\0';
|
|
while ((len) && (s[len - 1] == ' ')) s[--len] = '\0';
|
|
}
|
|
else strcpy(s, "");
|
|
if (recd->Fd[p].TypeF == _datefld)
|
|
{
|
|
if (strlen(s)) *d=atol(s);
|
|
else *d=0;
|
|
}
|
|
return (0);
|
|
}
|
|
else
|
|
{
|
|
fatal_box("Non esiste il campo %s", fieldname);
|
|
return(-1);
|
|
}
|
|
}
|
|
|
|
|
|
class TIsam_date_converter : public TApplication
|
|
{
|
|
|
|
protected:
|
|
virtual bool create () ;
|
|
virtual bool destroy();
|
|
void update();
|
|
void Iupdate_dir();
|
|
void convert_dir(const what conversion);
|
|
int Iconvert_file(int logicnum);
|
|
void Dconvert_file(int logicnum);
|
|
|
|
public:
|
|
TIsam_date_converter() {}
|
|
~TIsam_date_converter() {}
|
|
|
|
};
|
|
|
|
bool TIsam_date_converter::create() // initvar e arrmask
|
|
|
|
{
|
|
TApplication::create();
|
|
|
|
update();
|
|
return FALSE;
|
|
}
|
|
|
|
bool TIsam_date_converter::destroy() // releasev e arrmask
|
|
|
|
{
|
|
return TApplication::destroy() ;
|
|
}
|
|
|
|
void TIsam_date_converter::update()
|
|
|
|
{
|
|
long firm = get_firm();
|
|
TString pref;
|
|
if (firm == 0) pref = prefix().name();
|
|
|
|
do_events();
|
|
begin_wait();
|
|
// Converte i files in formato DBIII, FOXPRO...
|
|
prefix().set("");
|
|
Iupdate_dir();
|
|
prefix().set("com");
|
|
Iupdate_dir();
|
|
convert_dir(_isam);
|
|
|
|
TLocalisamfile ditte(LF_NDITTE);
|
|
|
|
set_autoload_new_files(FALSE);
|
|
for (ditte.first(); !ditte.eof(); ditte.next())
|
|
{
|
|
const long codditta = ditte.get_long("CODDITTA");
|
|
const TRecnotype rec = ditte.recno();
|
|
|
|
if (prefix().exist(codditta))
|
|
{
|
|
set_firm(codditta);
|
|
Iupdate_dir();
|
|
convert_dir(_isam);
|
|
}
|
|
}
|
|
|
|
// Converte le date in ANSI.
|
|
prefix().set("com");
|
|
convert_dir(_date);
|
|
for (ditte.first(); !ditte.eof(); ditte.next())
|
|
{
|
|
const long codditta = ditte.get_long("CODDITTA");
|
|
const TRecnotype rec = ditte.recno();
|
|
|
|
if (prefix().exist(codditta))
|
|
{
|
|
set_firm(codditta);
|
|
convert_dir(_date);
|
|
}
|
|
}
|
|
|
|
if (firm > 0) set_firm(firm);
|
|
else prefix().set(pref);
|
|
set_autoload_new_files(TRUE);
|
|
end_wait();
|
|
}
|
|
|
|
void TIsam_date_converter::Iupdate_dir()
|
|
|
|
{
|
|
TDir d;
|
|
|
|
d.get(LF_DIR);
|
|
const int items = (int)d.eod();
|
|
TString80 s("Aggiornamento direttorio ");
|
|
TString pref(prefix().name());
|
|
|
|
if (pref.empty()) s << "standard";
|
|
else
|
|
if (pref == "com") s << "comune";
|
|
else s << " della ditta " << atol (pref);
|
|
|
|
TProgind p((long)(items ? items : 1), s, TRUE, TRUE, 70);
|
|
|
|
p.setstatus(1L);
|
|
for (int i = 2; i <= items; i++)
|
|
{
|
|
p.addstatus(1L);
|
|
d.get(i, _nolock, _nordir, _sysdirop);
|
|
|
|
TFilename s(d.name());
|
|
|
|
s.ext("");
|
|
strcpy((char *) d.name(), s);
|
|
d.put(i, _nordir, _sysdirop);
|
|
}
|
|
}
|
|
|
|
void TIsam_date_converter::convert_dir(const what conversion)
|
|
|
|
{
|
|
const TString pref(prefix().name());
|
|
const bool is_com = prefix().is_com();
|
|
TDir d;
|
|
|
|
d.get(LF_DIR);
|
|
const int items = (int)d.eod();
|
|
TString80 s("Aggiornamento archivi ");
|
|
|
|
if (pref == "com") s << "comuni";
|
|
else s << " della ditta " << atol (pref);
|
|
|
|
TProgind p((long)(items ? items : 1), s, TRUE, TRUE, 70);
|
|
|
|
p.setstatus(1L);
|
|
|
|
for (int i = 2; i <= items; i++)
|
|
{
|
|
p.setstatus((long)(i+1));
|
|
d.get(i, _nolock, _nordir, _sysdirop);
|
|
|
|
const bool to_convert = (is_com ? d.is_com() : d.is_firm());
|
|
|
|
if (to_convert)
|
|
{
|
|
if (conversion == _isam)
|
|
Iconvert_file(i);
|
|
else
|
|
Dconvert_file(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
int TIsam_date_converter::Iconvert_file(int logicnum)
|
|
|
|
{
|
|
TDir dir;
|
|
TTrec r;
|
|
int err = NOERR;
|
|
|
|
r.get(logicnum);
|
|
RecDes *rd=r.rec();
|
|
const int nflds = r.fields();
|
|
|
|
dir.get(logicnum);
|
|
if (dir.len() == 0) return 0;
|
|
const char * fp = dir.name();
|
|
TFilename old(fp);
|
|
const TRecnotype nitems = dir.eod();
|
|
TFile f(dir.len());
|
|
|
|
old.ext("dta");
|
|
if (fexist(old))
|
|
{
|
|
f.open(old);
|
|
{
|
|
TSystemisamfile newfile(logicnum);
|
|
|
|
if (newfile.build(10) != NOERR)
|
|
fatal_box("Non riesco a creare il file %s : errore n. %d", fp, newfile.status());
|
|
}
|
|
|
|
char * _field= new char [r.len()];
|
|
TString s(80);
|
|
TToken_string ts(128); // Build token_string with the names of date fields
|
|
for (int j=0; j<r.fields(); j++)
|
|
if (rd->Fd[j].TypeF == _datefld)
|
|
ts.add(rd->Fd[j].Name);
|
|
|
|
s.format("Aggiornamento archivio %s", fp);
|
|
TProgind p((long)(nitems ? nitems : 1), s, TRUE, TRUE, 70);
|
|
TLocalisamfile newfile(logicnum);
|
|
TRecnotype i;
|
|
for (i = 1; newfile.good() && i <= dir.eod(); i++)
|
|
{
|
|
f.read(newfile.curr().string(),i);
|
|
ts.restart();
|
|
if (newfile.curr().string()[0] == NULL)
|
|
{
|
|
for (int j=0; j<ts.items(); j++)
|
|
{
|
|
CGetFieldBuff((char*)ts.get(),rd,newfile.curr().string(),_field);
|
|
newfile.curr().put(ts.get(j),_field);
|
|
}
|
|
newfile.curr().recall();
|
|
}
|
|
else
|
|
newfile.curr().discard();
|
|
if ((i % 50) == 0) p.setstatus((long)(i + 1));
|
|
if (!newfile.curr().isdeleted())
|
|
newfile.write();
|
|
}
|
|
p.setstatus((long)nitems);
|
|
f.close();
|
|
if (_field != NULL)
|
|
delete _field;
|
|
if (newfile.good())
|
|
{
|
|
old.ext("dta");
|
|
::remove(old);
|
|
old.ext("ndx");
|
|
::remove(old);
|
|
}
|
|
else
|
|
error_box("Errore nella conversione dell' archivio %s : n.ro %d",
|
|
fp, newfile.status());
|
|
}
|
|
else
|
|
{
|
|
// Crea il file se non esiste il relativo .DTA.
|
|
const TString pref(prefix().name());
|
|
const bool is_com = prefix().is_com();
|
|
|
|
prefix().set("");
|
|
dir.get(logicnum);
|
|
const int module = abs((int)dir.flags());
|
|
prefix().set(pref);
|
|
dir.get(logicnum, _nolock, _nordir, _sysdirop);
|
|
bool to_create = (is_com ? dir.is_com() : dir.is_firm());
|
|
if (to_create && has_module(module, CHK_DONGLE))
|
|
{
|
|
dir.get(logicnum);
|
|
TFilename s(dir.name());
|
|
s.ext("dbf");
|
|
if (!fexist(s)) // Crea il file solo se non esiste il .DBF
|
|
{
|
|
TSystemisamfile f(logicnum);
|
|
f.build(10L);
|
|
}
|
|
}
|
|
}
|
|
return err;
|
|
}
|
|
|
|
void TIsam_date_converter::Dconvert_file(int logicnum)
|
|
|
|
{
|
|
TDir dir;
|
|
TTrec r;
|
|
int err = NOERR;
|
|
|
|
r.get(logicnum);
|
|
RecDes *rd=r.rec();
|
|
const int nflds = r.fields();
|
|
|
|
dir.get(logicnum);
|
|
if (dir.len() == 0) return;
|
|
const TRecnotype nitems = dir.eod();
|
|
const char* file_name = dir.name();
|
|
|
|
TToken_string ts(128); // Build token_string with the names of date fields and logical fields
|
|
TToken_string tslog(128);
|
|
for (int j=0; j<r.fields(); j++)
|
|
if (rd->Fd[j].TypeF == _datefld)
|
|
ts.add(rd->Fd[j].Name);
|
|
else
|
|
if (rd->Fd[j].TypeF == _boolfld)
|
|
tslog.add(rd->Fd[j].Name);
|
|
|
|
if (ts.items() > 0 || tslog.items() > 0)
|
|
{
|
|
TString s(80);
|
|
s.format("Aggiornamento archivio %s", file_name);
|
|
TProgind p((long)(nitems ? nitems : 1), s, TRUE, TRUE, 70);
|
|
TLocalisamfile ifile(logicnum);
|
|
ifile.readat(1);
|
|
for (TRecnotype i = 1; ifile.good() && i <= ifile.items(); i++)
|
|
{
|
|
ts.restart();
|
|
tslog.restart();
|
|
for (int j=1; j <= ts.items(); j++)
|
|
{
|
|
const char* field_name=ts.get();
|
|
long wd;
|
|
CGetField(field_name,rd,ifile.curr().string(),&wd);
|
|
TDate d(wd);
|
|
ifile.curr().put(field_name,d);
|
|
}
|
|
for (j=1; j<= tslog.items(); j++)
|
|
{
|
|
const char* field_name=tslog.get();
|
|
TString value;
|
|
value=ifile.curr().get_str(field_name);
|
|
ifile.curr().put(field_name,value == "X");
|
|
}
|
|
ifile.rewriteat(i);
|
|
if (i < ifile.items())
|
|
{
|
|
ifile.readat(i+1);
|
|
if ((i %50) == 0) p.setstatus(i+1);
|
|
}
|
|
}
|
|
p.setstatus(nitems);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char** argv)
|
|
{
|
|
TIsam_date_converter a;
|
|
|
|
a.run(argc, argv, "Conversione a CodeBase");
|
|
return 0;
|
|
}
|
|
|