2004-04-28 22:11:22 +00:00
|
|
|
#ifdef WIN32 //qui verificare
|
1996-09-04 07:34:26 +00:00
|
|
|
#include <direct.h>
|
2004-04-28 22:11:22 +00:00
|
|
|
#endif
|
1998-05-04 09:54:49 +00:00
|
|
|
|
1996-09-04 07:34:26 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <archives.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <tabutil.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#include "ve5100a.h"
|
|
|
|
|
1997-06-09 13:10:38 +00:00
|
|
|
#include "velib.h"
|
1996-09-04 07:34:26 +00:00
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
class TDeletedoc_app : public TSkeleton_application
|
1996-09-04 07:34:26 +00:00
|
|
|
{
|
|
|
|
TArchive _arc;
|
|
|
|
TString _desc, _last_std;
|
2003-01-28 13:33:45 +00:00
|
|
|
TString16 _num;
|
|
|
|
int _anno;
|
1996-09-04 07:34:26 +00:00
|
|
|
char _unit;
|
|
|
|
TFilename _tmp_dir;
|
|
|
|
TIsamtempfile *_tdoc,*_trdoc;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2003-01-28 13:33:45 +00:00
|
|
|
void backup_delete_doc(int op, int who, bool pack_rows); // Backup e cancellazione dei documenti da eliminare
|
1998-08-25 18:07:30 +00:00
|
|
|
void restore_doc(); // Ripristino documenti da disco
|
1996-09-04 07:34:26 +00:00
|
|
|
void create_tmp_files(bool create=TRUE);
|
|
|
|
void delete_tmp_files(bool remove=TRUE);
|
|
|
|
virtual bool create();
|
|
|
|
virtual bool destroy();
|
1999-04-06 15:34:39 +00:00
|
|
|
virtual void main_loop();
|
1996-09-07 10:57:42 +00:00
|
|
|
|
|
|
|
static bool state_handler(TMask& m, KEY k);
|
1996-09-04 07:34:26 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
TDeletedoc_app() {};
|
|
|
|
~TDeletedoc_app() {};
|
|
|
|
};
|
|
|
|
|
1996-09-07 10:57:42 +00:00
|
|
|
bool TDeletedoc_app::state_handler(TMask& m, KEY k)
|
|
|
|
{
|
|
|
|
if (k == K_SHIFT + K_F7)
|
|
|
|
m.enable(F_STATUS);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-01-28 13:33:45 +00:00
|
|
|
void TDeletedoc_app::backup_delete_doc(int op, int who, bool pack_rows)
|
1996-09-04 07:34:26 +00:00
|
|
|
{
|
1996-09-07 10:57:42 +00:00
|
|
|
|
1998-05-04 09:54:49 +00:00
|
|
|
TIsamfile doc(LF_DOC);
|
1998-11-04 18:04:26 +00:00
|
|
|
TIsamfile rdoc(LF_RIGHEDOC);
|
|
|
|
TIsamfile clifo(LF_CLIFO);
|
|
|
|
TIsamfile cfven(LF_CFVEN);
|
2003-01-28 13:33:45 +00:00
|
|
|
TIsamfile indsp(LF_INDSP);
|
1998-11-04 18:04:26 +00:00
|
|
|
TIsamfile tab(LF_TAB);
|
|
|
|
TIsamfile occas(LF_OCCAS);
|
|
|
|
TIsamfile movmag(LF_MOVMAG);
|
|
|
|
TIsamfile rmovmag(LF_RMOVMAG);
|
|
|
|
|
1996-09-04 07:34:26 +00:00
|
|
|
|
1996-09-07 10:57:42 +00:00
|
|
|
doc.open();
|
1998-11-04 18:04:26 +00:00
|
|
|
rdoc.open();
|
|
|
|
clifo.open();
|
|
|
|
cfven.open();
|
2003-01-28 13:33:45 +00:00
|
|
|
indsp.open();
|
1998-11-04 18:04:26 +00:00
|
|
|
tab.open();
|
|
|
|
occas.open();
|
|
|
|
movmag.open();
|
|
|
|
rmovmag.open();
|
|
|
|
|
2003-01-28 13:33:45 +00:00
|
|
|
int err= NOERR;
|
|
|
|
// int err = doc.lock();
|
1996-09-04 07:34:26 +00:00
|
|
|
if (err != NOERR)
|
|
|
|
{
|
1996-09-07 10:57:42 +00:00
|
|
|
error_box("Il file documenti non puo' essere bloccato in modo esclusivo."
|
|
|
|
" Nessun documento cancellato. Errore %d.",err);
|
1996-09-04 07:34:26 +00:00
|
|
|
return;
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
1998-11-04 18:04:26 +00:00
|
|
|
TDocumento documento;
|
1998-08-25 18:07:30 +00:00
|
|
|
if (op & 0x2)
|
|
|
|
create_tmp_files();
|
|
|
|
|
|
|
|
TString_array to_zap; // Array contenente le chiavi dei documenti da eliminare
|
2003-01-28 13:33:45 +00:00
|
|
|
TString_array to_pack; // Array contenente le chiavi dei documenti da compattare
|
1998-08-25 18:07:30 +00:00
|
|
|
TRecnotype total = 0;
|
|
|
|
|
1996-09-07 10:57:42 +00:00
|
|
|
doc.zero();
|
1996-09-04 07:34:26 +00:00
|
|
|
// Scorre il file dei documenti
|
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
TProgind p(doc.items(), "Ricerca dei documenti ...", TRUE, TRUE);
|
|
|
|
for (int scanerr = doc.first();
|
|
|
|
scanerr == NOERR && !p.iscancelled();
|
|
|
|
scanerr = doc.next())
|
2003-01-28 13:33:45 +00:00
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
p.addstatus(1);
|
2003-01-28 13:33:45 +00:00
|
|
|
if (_anno != 0 && _anno != doc.get_int(DOC_ANNO))
|
|
|
|
continue;
|
|
|
|
if (_num.not_empty() && _num != doc.get(DOC_CODNUM))
|
|
|
|
continue;
|
1996-09-07 10:57:42 +00:00
|
|
|
documento.read(doc.curr());
|
1996-09-04 07:34:26 +00:00
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
bool to_delete = FALSE;
|
|
|
|
|
|
|
|
if (who & 0x1)
|
|
|
|
{
|
|
|
|
if (doc.get(DOC_STATO) == _last_std)
|
|
|
|
to_delete = TRUE;
|
|
|
|
}
|
|
|
|
if (who & 0x2)
|
|
|
|
{
|
|
|
|
if (doc.get_bool(DOC_DOCEVASO))
|
|
|
|
to_delete = TRUE;
|
|
|
|
}
|
1996-09-04 07:34:26 +00:00
|
|
|
|
2003-01-28 13:33:45 +00:00
|
|
|
if (pack_rows && !to_delete && documento.tipo().is_ordine())
|
|
|
|
{
|
|
|
|
const int rows = documento.physical_rows();
|
|
|
|
for (int x = 1; x <= rows; x++)
|
|
|
|
{
|
2003-02-04 09:35:35 +00:00
|
|
|
if (documento[x].is_evasa())
|
2003-01-28 13:33:45 +00:00
|
|
|
{
|
|
|
|
TToken_string id(30);
|
|
|
|
id = doc.get(DOC_PROVV);
|
|
|
|
id.add(doc.get(DOC_ANNO));
|
|
|
|
id.add(doc.get(DOC_CODNUM));
|
|
|
|
id.add(doc.get(DOC_NDOC));
|
|
|
|
to_pack.add(id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
if (to_delete) // Se TRUE il puo' essere eliminato!
|
1996-09-04 07:34:26 +00:00
|
|
|
{ // Memorizza la chiave 1 del documento in un array
|
1998-08-25 18:07:30 +00:00
|
|
|
if (op & 0x1)
|
|
|
|
{
|
|
|
|
TToken_string id(30);
|
|
|
|
id = doc.get(DOC_PROVV);
|
|
|
|
id.add(doc.get(DOC_ANNO));
|
|
|
|
id.add(doc.get(DOC_CODNUM));
|
|
|
|
id.add(doc.get(DOC_NDOC));
|
|
|
|
to_zap.add(id);
|
|
|
|
}
|
|
|
|
if (op & 0x2)
|
|
|
|
{
|
|
|
|
err = _tdoc->write(doc.curr());
|
2000-10-03 13:45:12 +00:00
|
|
|
const int rows = documento.physical_rows();
|
1998-08-25 18:07:30 +00:00
|
|
|
// Memorizza le righe del documento sui file temporanei
|
|
|
|
for (int x = 1; err == NOERR && x <= rows; x++)
|
|
|
|
err = _trdoc->write(documento[x]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = NOERR;
|
1996-09-04 07:34:26 +00:00
|
|
|
total++;
|
|
|
|
}
|
|
|
|
} // end of for
|
1998-08-25 18:07:30 +00:00
|
|
|
if (p.iscancelled())
|
|
|
|
total = 0;
|
1996-09-04 07:34:26 +00:00
|
|
|
}
|
1998-11-04 18:04:26 +00:00
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
if (total != 0)
|
1996-09-04 07:34:26 +00:00
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
if (err==NOERR)
|
1996-09-04 07:34:26 +00:00
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
bool rt = TRUE;
|
|
|
|
if (op & 0x2)
|
1996-09-07 10:57:42 +00:00
|
|
|
{
|
1998-11-04 18:04:26 +00:00
|
|
|
doc.close(); rdoc.close(); clifo.close();
|
|
|
|
cfven.close(); tab.close(); occas.close();
|
|
|
|
movmag.close(); rmovmag.close();
|
1998-08-25 18:07:30 +00:00
|
|
|
const char * dir = &_tmp_dir[1];
|
|
|
|
delete_tmp_files(FALSE); //Close tmp files only
|
1998-11-04 18:04:26 +00:00
|
|
|
rt = _arc.backup(dir,_unit,_desc, FALSE);// Backup dei documenti da eliminare, prefix unnecessary
|
1998-08-25 18:07:30 +00:00
|
|
|
create_tmp_files(FALSE); // Reopen tmp files.
|
1998-11-04 18:04:26 +00:00
|
|
|
doc.open(_excllock); rdoc.open(); clifo.open();
|
|
|
|
cfven.open(); tab.open(); occas.open();
|
|
|
|
movmag.open(); rmovmag.open();
|
1996-09-07 10:57:42 +00:00
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
if (rt & (op & 0x1))
|
|
|
|
{
|
|
|
|
// Effettiva cancellazione dei documenti
|
|
|
|
TString caption("Confermare la cancellazione di ");
|
|
|
|
caption.add_plural(total, "documento");
|
|
|
|
if (yesno_box(caption))
|
2003-01-28 13:33:45 +00:00
|
|
|
{
|
|
|
|
{
|
|
|
|
TProgind pi(total, caption, FALSE, TRUE, 10);
|
|
|
|
for (int i = 0; i < to_zap.items(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& id = to_zap.row(i);
|
|
|
|
id.restart();
|
|
|
|
const char provv = id.get_char();
|
|
|
|
const int anno = id.get_int();
|
|
|
|
const TString16 codnum = id.get();
|
2003-02-25 14:39:02 +00:00
|
|
|
const long numdoc = id.get_long();
|
2003-01-28 13:33:45 +00:00
|
|
|
documento.read(provv,anno,codnum,numdoc);
|
|
|
|
documento.TMultiple_rectype::remove(doc);
|
|
|
|
pi.addstatus(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
TProgind pi1(to_pack.items(), "Compattamento documenti", FALSE, TRUE, 10);
|
|
|
|
for (int i = 0; i < to_pack.items(); i++)
|
|
|
|
{
|
|
|
|
TToken_string& id = to_pack.row(i);
|
|
|
|
id.restart();
|
|
|
|
const char provv = id.get_char();
|
|
|
|
const int anno = id.get_int();
|
|
|
|
const TString16 codnum = id.get();
|
2003-02-25 14:39:02 +00:00
|
|
|
const long numdoc = id.get_long();
|
2003-01-28 13:33:45 +00:00
|
|
|
documento.read(provv,anno,codnum,numdoc);
|
|
|
|
const int rows = documento.physical_rows();
|
|
|
|
// Memorizza le righe del documento sui file temporanei
|
|
|
|
for (int x = rows; x >= 1; x--)
|
|
|
|
if (documento[x].is_evasa())
|
|
|
|
documento.destroy_row(x, TRUE);
|
|
|
|
documento.rewrite(doc);
|
|
|
|
pi1.addstatus(1);
|
|
|
|
}
|
|
|
|
}
|
2003-02-25 14:39:02 +00:00
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error_box("Errore %d scrivendo sui files temporanei."
|
2000-10-03 13:45:12 +00:00
|
|
|
" La cancellazione dei documenti chiusi non verra' effettuata.",err);
|
1996-09-04 07:34:26 +00:00
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
if (op & 0x2)
|
|
|
|
delete_tmp_files(); // Physical remove of tmp files
|
|
|
|
|
1996-09-07 10:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TDeletedoc_app::restore_doc()
|
|
|
|
{
|
1998-05-04 09:54:49 +00:00
|
|
|
TIsamfile doc(LF_DOC);
|
1996-09-07 10:57:42 +00:00
|
|
|
TLocalisamfile rdoc(LF_RIGHEDOC);
|
|
|
|
|
|
|
|
doc.open();
|
|
|
|
int err = doc.lock();
|
|
|
|
if (err != NOERR)
|
|
|
|
{
|
|
|
|
error_box("Il file documenti non puo' essere bloccato in modo esclusivo."
|
|
|
|
" Nessuna documento ripristinato. Errore %d.",err);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
const char* dir =& _tmp_dir[1]; // Cut out % sign
|
1998-11-04 18:04:26 +00:00
|
|
|
if (_arc.restore(dir,_unit,FALSE, FALSE))
|
1996-09-07 10:57:42 +00:00
|
|
|
{
|
|
|
|
create_tmp_files(FALSE); // In realta' ci sono gia'
|
|
|
|
const TRecnotype items = _tdoc->items() + _trdoc->items();
|
1998-08-25 18:07:30 +00:00
|
|
|
TProgind pi(items, "Ripristino documenti archiviati", FALSE, TRUE, 10);
|
1996-09-07 10:57:42 +00:00
|
|
|
|
|
|
|
for (_tdoc->first();_tdoc->good() && err==NOERR;_tdoc->next())
|
|
|
|
{
|
|
|
|
if ((err=doc.write(_tdoc->curr())) == _isreinsert)
|
|
|
|
err=doc.rewrite(_tdoc->curr());
|
|
|
|
pi.addstatus(1);
|
|
|
|
}
|
|
|
|
if (err != NOERR)
|
|
|
|
error_box("Errore %d ripristinando il file DOCUMENTI.",err);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (_trdoc->first();_trdoc->good() && err==NOERR;_trdoc->next())
|
|
|
|
{
|
|
|
|
if ((err=rdoc.write(_trdoc->curr())) == _isreinsert)
|
|
|
|
err=rdoc.rewrite(_trdoc->curr());
|
|
|
|
pi.addstatus(1);
|
|
|
|
}
|
|
|
|
if (err != NOERR)
|
|
|
|
error_box("Errore %d ripristinando il file RIGHE DOCUMENTI.",err);
|
|
|
|
}
|
|
|
|
delete_tmp_files(); // Removes tmp files!
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error_box("Errore nel ripristino dei file da dischetto. Nessuna documento ripristinato.");
|
|
|
|
doc.close();
|
1996-09-04 07:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TDeletedoc_app::create_tmp_files(bool create)
|
|
|
|
{
|
|
|
|
TFilename tf(_tmp_dir);
|
1998-08-25 18:07:30 +00:00
|
|
|
tf.add("f1");
|
1996-09-04 07:34:26 +00:00
|
|
|
_tdoc = new TIsamtempfile(LF_DOC,tf,create);
|
1998-08-25 18:07:30 +00:00
|
|
|
tf.rtrim(1); tf << "2";
|
1996-09-04 07:34:26 +00:00
|
|
|
_trdoc = new TIsamtempfile(LF_RIGHEDOC,tf,create);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TDeletedoc_app::delete_tmp_files(bool remove)
|
|
|
|
{
|
|
|
|
if (remove) // Cosi' posso forzare la cancellazione in chiusura
|
|
|
|
{
|
|
|
|
_tdoc->set_autodel();
|
|
|
|
_trdoc->set_autodel();
|
|
|
|
}
|
|
|
|
delete _tdoc;
|
|
|
|
delete _trdoc;
|
1998-08-25 18:07:30 +00:00
|
|
|
_tdoc = NULL;
|
|
|
|
_trdoc = NULL;
|
1996-09-04 07:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TDeletedoc_app::create()
|
|
|
|
{
|
|
|
|
_tmp_dir.temp();
|
|
|
|
_tmp_dir = _tmp_dir.path();
|
|
|
|
_tmp_dir << "VE";
|
1999-04-06 15:34:39 +00:00
|
|
|
if (!_tmp_dir.exist())
|
|
|
|
make_dir(_tmp_dir);
|
1996-09-04 07:34:26 +00:00
|
|
|
_tmp_dir.insert("%"); // Add % sign
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
|
|
TTable std("%STD");
|
|
|
|
std.last(); // Reperisce lo stato eliminabile
|
|
|
|
_last_std = std.get("CODTAB");
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
return TSkeleton_application::create();
|
1996-09-04 07:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TDeletedoc_app::destroy()
|
|
|
|
{
|
|
|
|
_tmp_dir=_tmp_dir.sub(1); // Cut out % sign
|
1999-04-06 15:34:39 +00:00
|
|
|
if (_tmp_dir.exist())
|
|
|
|
rmdir(_tmp_dir);
|
|
|
|
return TSkeleton_application::destroy();
|
1996-09-04 07:34:26 +00:00
|
|
|
}
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
void TDeletedoc_app::main_loop()
|
1996-09-04 07:34:26 +00:00
|
|
|
{
|
|
|
|
TMask m("ve5100a");
|
1996-09-07 10:57:42 +00:00
|
|
|
m.set_handler(state_handler);
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
|
|
m.set(F_STATUS,_last_std);
|
1996-09-04 07:34:26 +00:00
|
|
|
|
|
|
|
while (m.run() != K_QUIT)
|
|
|
|
{
|
|
|
|
_unit = m.get(F_UNIT)[0];
|
|
|
|
_desc = m.get(F_DESC);
|
1996-09-07 10:57:42 +00:00
|
|
|
const int scelta = m.get_int(F_OPERAZIONE);
|
1998-08-25 18:07:30 +00:00
|
|
|
const int cosa = m.get_int(F_DOCUMENTI);
|
2003-01-28 13:33:45 +00:00
|
|
|
const bool pack_rows = m.get_bool(F_COMPATTA);
|
|
|
|
_anno = m.get_int(F_ANNO);
|
|
|
|
_num = m.get(F_CODNUM);
|
1998-08-25 18:07:30 +00:00
|
|
|
switch (scelta)
|
|
|
|
{
|
2003-01-28 13:33:45 +00:00
|
|
|
case 1 : backup_delete_doc(0x1, cosa, pack_rows); break;
|
|
|
|
case 2 : backup_delete_doc(0x2, cosa, pack_rows); break;
|
|
|
|
case 3 : backup_delete_doc(0x3, cosa, pack_rows); break;
|
1998-08-25 18:07:30 +00:00
|
|
|
default: restore_doc(); break;
|
|
|
|
}
|
1996-09-04 07:34:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
int ve5100(int argc, char* argv[])
|
1996-09-04 07:34:26 +00:00
|
|
|
{
|
|
|
|
TDeletedoc_app a;
|
|
|
|
a.run(argc, argv, "Eliminazione documenti");
|
|
|
|
return 0;
|
|
|
|
}
|