1994-11-18 17:38:53 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <isam.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <prefix.h>
|
|
|
|
|
|
|
|
#include "cg4.h"
|
|
|
|
#include "cg4200.h"
|
|
|
|
|
1994-12-07 11:08:53 +00:00
|
|
|
#include <pconti.h>
|
|
|
|
|
1998-05-04 09:34:04 +00:00
|
|
|
class TCopia_archivi : public TSkeleton_application
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
|
|
|
TMask* _msk;
|
|
|
|
long _default_firm;
|
|
|
|
|
2003-05-08 14:42:58 +00:00
|
|
|
protected:
|
1994-11-18 17:38:53 +00:00
|
|
|
virtual bool create() ;
|
|
|
|
virtual bool destroy() ;
|
1998-05-04 09:34:04 +00:00
|
|
|
virtual void main_loop();
|
|
|
|
|
2003-05-08 14:42:58 +00:00
|
|
|
public:
|
1994-11-18 17:38:53 +00:00
|
|
|
bool copyfile(int logicnum, long from, long to);
|
1995-07-20 09:00:03 +00:00
|
|
|
bool check_comfile(int logicnum);
|
1994-11-18 17:38:53 +00:00
|
|
|
void clearivd(long to);
|
|
|
|
void copyivd(long from, long to);
|
|
|
|
|
|
|
|
TCopia_archivi() : _msk(NULL) {}
|
1995-07-20 09:00:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool TCopia_archivi::check_comfile(int logicnum)
|
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
TDir dir; dir.get(logicnum, _nolock, _comdir);
|
|
|
|
const TFilename name = dir.filename();
|
|
|
|
if (name.exist())
|
1995-07-20 09:00:03 +00:00
|
|
|
return TRUE;
|
|
|
|
else
|
2003-03-20 12:25:48 +00:00
|
|
|
return error_box(FR("Non esiste il file sorgente : archivi comuni - %s"), dir.filename());
|
1995-07-20 09:00:03 +00:00
|
|
|
}
|
1994-11-18 17:38:53 +00:00
|
|
|
|
|
|
|
bool TCopia_archivi::copyfile(int logicnum, long from, long to)
|
1995-06-26 16:53:50 +00:00
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
// Controllo che la destinazione non sia un file comune
|
1995-06-26 16:53:50 +00:00
|
|
|
set_firm(to);
|
2003-05-08 14:42:58 +00:00
|
|
|
TDir dir;
|
1995-06-26 16:53:50 +00:00
|
|
|
dir.get(logicnum, _nolock, _nordir, _sysdirop);
|
|
|
|
if (dir.is_com())
|
|
|
|
{
|
|
|
|
dir.get(logicnum);
|
2003-05-08 14:42:58 +00:00
|
|
|
return error_box(FR("Impossibile copiare su un'archivio comune : ditta %ld - archivio %s"), to, dir.filename());
|
1995-06-26 16:53:50 +00:00
|
|
|
}
|
2003-05-08 14:42:58 +00:00
|
|
|
|
|
|
|
// Scarico il file sorgente su un file di testo
|
|
|
|
if (from > 0)
|
|
|
|
set_firm(from);
|
1995-07-20 09:00:03 +00:00
|
|
|
else
|
|
|
|
prefix().set("com");
|
2003-05-08 14:42:58 +00:00
|
|
|
TFilename t; t.tempdir(); t << "/tr" << logicnum << ".txt";
|
|
|
|
if (t.not_empty()) // dummy test to ensure parenthesis
|
|
|
|
{
|
|
|
|
TSystemisamfile file(logicnum);
|
|
|
|
if (file.dump(t) != NOERR)
|
|
|
|
return error_box(FR("Impossibile leggere i dati da copiare errore n. %d"), file.status());
|
|
|
|
}
|
2002-07-30 14:11:47 +00:00
|
|
|
|
2003-05-08 14:42:58 +00:00
|
|
|
// Scarico il file destinazione su un file di testo
|
|
|
|
set_firm(to);
|
|
|
|
TFilename s; s.tempdir(); s << "/sv" << logicnum << ".txt";
|
1994-11-18 17:38:53 +00:00
|
|
|
|
2003-05-08 14:42:58 +00:00
|
|
|
TSystemisamfile file(logicnum);
|
1994-11-18 17:38:53 +00:00
|
|
|
if (file.dump(s) != NOERR)
|
2003-03-20 12:25:48 +00:00
|
|
|
return error_box(FR("Impossibile salvare i dati originali errore n. %d"), file.status());
|
2003-05-08 14:42:58 +00:00
|
|
|
// Azzero il file destinazione
|
|
|
|
file.zap();
|
1994-11-18 17:38:53 +00:00
|
|
|
|
2003-05-08 14:42:58 +00:00
|
|
|
// Carico nel file destinazione il file di testo precedente
|
1994-11-18 17:38:53 +00:00
|
|
|
if (file.load(t) != NOERR)
|
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
error_box(FR("Impossibile scrivere i dati errore n. %d. Ripristino dei dati originali."), file.status());
|
|
|
|
// Ripristino il backup
|
|
|
|
file.zap();
|
1994-11-18 17:38:53 +00:00
|
|
|
if (file.load(s))
|
2003-05-08 14:42:58 +00:00
|
|
|
error_box(FR("Impossibile ripristinare i dati originali errore n. %d"), file.status());
|
1994-11-18 17:38:53 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCopia_archivi::clearivd(long to)
|
|
|
|
{
|
|
|
|
TLocalisamfile pcon(LF_PCON);
|
|
|
|
|
|
|
|
for (pcon.first(); pcon.good(); pcon.next())
|
|
|
|
{
|
|
|
|
pcon.put(PCN_SEZIVD, "0");
|
|
|
|
pcon.zero(PCN_LETTIVD);
|
|
|
|
pcon.zero(PCN_NUMRIVD);
|
|
|
|
pcon.zero(PCN_NUMIVD);
|
|
|
|
pcon.put(PCN_SEZIVDOPP, "0");
|
|
|
|
pcon.zero(PCN_LETTIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMRIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMIVDOPP);
|
|
|
|
pcon.rewrite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TCopia_archivi::copyivd(long from, long to)
|
|
|
|
{
|
1995-03-01 15:19:25 +00:00
|
|
|
if (from > 0) set_firm(from);
|
1995-03-23 08:45:05 +00:00
|
|
|
else prefix().set("com");
|
1994-11-18 17:38:53 +00:00
|
|
|
TLocalisamfile pcon(LF_PCON);
|
|
|
|
TAssoc_array riclass;
|
|
|
|
|
|
|
|
for (pcon.first(); pcon.good(); pcon.next())
|
|
|
|
{
|
|
|
|
TString16 key;
|
|
|
|
TToken_string data;
|
|
|
|
|
|
|
|
key.format("%03d%03d%06ld", pcon.get_int(PCN_GRUPPO),
|
|
|
|
pcon.get_int(PCN_CONTO), pcon.get_long(PCN_SOTTOCONTO));
|
|
|
|
data.add(pcon.get(PCN_SEZIVD));
|
|
|
|
data.add(pcon.get(PCN_LETTIVD));
|
|
|
|
data.add(pcon.get(PCN_NUMRIVD));
|
|
|
|
data.add(pcon.get(PCN_NUMIVD));
|
|
|
|
data.add(pcon.get(PCN_SEZIVDOPP));
|
|
|
|
data.add(pcon.get(PCN_LETTIVDOPP));
|
|
|
|
data.add(pcon.get(PCN_NUMRIVDOPP));
|
|
|
|
data.add(pcon.get(PCN_NUMIVDOPP));
|
|
|
|
riclass.add(key, data);
|
|
|
|
}
|
|
|
|
set_firm(to);
|
|
|
|
for (pcon.first(); pcon.good(); pcon.next())
|
|
|
|
{
|
|
|
|
TString16 key;
|
|
|
|
|
|
|
|
key.format("%03d%03d%06ld", pcon.get_int(PCN_GRUPPO),
|
|
|
|
pcon.get_int(PCN_CONTO), pcon.get_long(PCN_SOTTOCONTO));
|
|
|
|
|
|
|
|
TToken_string * data = (TToken_string *) riclass.objptr(key);
|
|
|
|
|
|
|
|
if (data == NULL)
|
|
|
|
{
|
|
|
|
pcon.put(PCN_SEZIVD, "0");
|
|
|
|
pcon.zero(PCN_LETTIVD);
|
|
|
|
pcon.zero(PCN_NUMRIVD);
|
|
|
|
pcon.zero(PCN_NUMIVD);
|
|
|
|
pcon.put(PCN_SEZIVDOPP, "0");
|
|
|
|
pcon.zero(PCN_LETTIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMRIVDOPP);
|
|
|
|
pcon.zero(PCN_NUMIVDOPP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pcon.put(PCN_SEZIVD, data->get(0));
|
|
|
|
pcon.put(PCN_LETTIVD, data->get());
|
|
|
|
pcon.put(PCN_NUMRIVD, data->get());
|
|
|
|
pcon.put(PCN_NUMIVD, data->get());
|
|
|
|
pcon.put(PCN_SEZIVDOPP, data->get());
|
|
|
|
pcon.put(PCN_LETTIVDOPP, data->get());
|
|
|
|
pcon.put(PCN_NUMRIVDOPP, data->get());
|
|
|
|
pcon.put(PCN_NUMIVDOPP, data->get());
|
|
|
|
}
|
|
|
|
pcon.rewrite();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCopia_archivi::create()
|
|
|
|
{
|
|
|
|
_msk = new TMask("cg4200a") ;
|
|
|
|
_default_firm = get_firm();
|
1998-05-04 09:34:04 +00:00
|
|
|
return TSkeleton_application::create();
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TCopia_archivi::destroy()
|
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
if (_msk != NULL)
|
|
|
|
delete _msk;
|
1998-05-04 09:34:04 +00:00
|
|
|
return TSkeleton_application::destroy();
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
|
|
|
|
1998-05-04 09:34:04 +00:00
|
|
|
void TCopia_archivi::main_loop()
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
|
|
|
while (_msk->run() == K_ENTER)
|
|
|
|
{
|
|
|
|
const long from_firm = _msk->get_long(F_FROMFIRM);
|
|
|
|
const long to_firm = _msk->get_long(F_TOFIRM);
|
1994-12-14 11:10:15 +00:00
|
|
|
if (from_firm == to_firm)
|
2003-03-20 12:25:48 +00:00
|
|
|
error_box(TR("La copia si puo' effettuare solo tra due ditte diverse"));
|
1994-12-14 11:10:15 +00:00
|
|
|
else
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1994-12-14 11:10:15 +00:00
|
|
|
const bool copy_pcon = _msk->get_bool(F_PCON);
|
|
|
|
const bool copy_causali = _msk->get_bool(F_CAUS);
|
|
|
|
const bool copy_clifo = _msk->get_bool(F_CLIFO);
|
|
|
|
const bool copy_ivd = _msk->get_bool(F_IVD);
|
|
|
|
if (copy_pcon || copy_causali || copy_clifo || copy_ivd)
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1995-07-20 09:00:03 +00:00
|
|
|
bool ok = TRUE;
|
|
|
|
if (copy_pcon) ok = check_comfile(LF_PCON);
|
|
|
|
if (ok && copy_causali) ok = check_comfile(LF_CAUSALI) && check_comfile(LF_RCAUSALI);
|
|
|
|
if (ok && copy_clifo) ok = check_comfile(LF_CLIFO);
|
|
|
|
if (ok && prefix().exist(to_firm))
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1994-12-14 11:10:15 +00:00
|
|
|
set_firm(to_firm);
|
2003-03-20 12:25:48 +00:00
|
|
|
{
|
|
|
|
TLocalisamfile mov(LF_MOV);
|
|
|
|
ok = (mov.eod() == 0);
|
|
|
|
}
|
1994-11-18 17:38:53 +00:00
|
|
|
|
1995-07-20 09:00:03 +00:00
|
|
|
if (ok || (!copy_pcon && !copy_causali && !copy_clifo))
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
TString mess;
|
|
|
|
mess.format(FR("Attenzione! I seguenti archivi della ditta %ld verranno sovrascritti:\n"), to_firm);
|
|
|
|
|
1994-12-14 11:10:15 +00:00
|
|
|
int count = 0;
|
|
|
|
if (copy_pcon)
|
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
mess << TR("piano dei conti");
|
1994-12-14 11:10:15 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (copy_causali)
|
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
if (count > 0) mess << ", ";
|
|
|
|
mess << TR(" causali");
|
1994-12-14 11:10:15 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (copy_clifo)
|
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
if (count > 0) mess << ", ";
|
|
|
|
mess << TR("clienti e fornitori");
|
1994-12-14 11:10:15 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (copy_ivd)
|
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
if (count > 0) mess << ", ";
|
|
|
|
mess << TR("riclassificazione IV direttiva");
|
1994-12-14 11:10:15 +00:00
|
|
|
count++;
|
|
|
|
}
|
2003-05-08 14:42:58 +00:00
|
|
|
mess << ".\n" ;
|
|
|
|
|
|
|
|
TString msg1 = mess; msg1 << TR("Si desidera continuare?");
|
|
|
|
if (yesno_box(msg1))
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
2003-05-08 14:42:58 +00:00
|
|
|
msg1 = mess; msg1 << TR("Si desidera veramente continuare?");
|
|
|
|
if (yesno_box(msg1))
|
1994-11-18 17:38:53 +00:00
|
|
|
{
|
1994-12-14 11:10:15 +00:00
|
|
|
if (copy_pcon)
|
|
|
|
{
|
|
|
|
if (copyfile(LF_PCON, from_firm, to_firm) && !copy_ivd)
|
|
|
|
clearivd(to_firm);
|
|
|
|
}
|
|
|
|
if (copy_causali)
|
|
|
|
{
|
|
|
|
if (copyfile(LF_CAUSALI, from_firm, to_firm))
|
|
|
|
copyfile(LF_RCAUSALI, from_firm, to_firm);
|
|
|
|
}
|
|
|
|
if (copy_clifo)
|
|
|
|
copyfile(LF_CLIFO, from_firm, to_firm);
|
|
|
|
if (!copy_pcon && copy_ivd)
|
|
|
|
copyivd(from_firm, to_firm);
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-05-08 14:42:58 +00:00
|
|
|
else
|
|
|
|
error_box(TR("La copia si puo' effettuare solo se non sono stati registrati movimenti"));
|
1994-12-14 11:10:15 +00:00
|
|
|
set_firm(_default_firm);
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
2003-03-20 12:25:48 +00:00
|
|
|
else error_box(FR("Gli archivi della ditta %ld non sono stati ancora generati"),to_firm);
|
1994-12-14 11:10:15 +00:00
|
|
|
_msk->reset();
|
1994-11-18 17:38:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cg4200(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TCopia_archivi a ;
|
2003-03-20 12:25:48 +00:00
|
|
|
a.run(argc, argv, TR("Copia archivi"));
|
1994-11-18 17:38:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|