183 lines
4.4 KiB
C++
183 lines
4.4 KiB
C++
|
#include <applicat.h>
|
|||
|
#include <automask.h>
|
|||
|
#include <modaut.h>
|
|||
|
#include <progind.h>
|
|||
|
#include <reputils.h>
|
|||
|
#include <utility.h>
|
|||
|
|
|||
|
#include "pg0067100a.h"
|
|||
|
|
|||
|
|
|||
|
///////////////////////////////////////////////
|
|||
|
// MASCHERA
|
|||
|
///////////////////////////////////////////////
|
|||
|
class TDistribuzione_f24_mask : public TAutomask
|
|||
|
{
|
|||
|
protected:
|
|||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|||
|
public:
|
|||
|
TDistribuzione_f24_mask();
|
|||
|
};
|
|||
|
|
|||
|
TDistribuzione_f24_mask::TDistribuzione_f24_mask() : TAutomask("pg0067100a")
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
bool TDistribuzione_f24_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|||
|
{
|
|||
|
/*switch(o.dlg())
|
|||
|
{
|
|||
|
default:
|
|||
|
break;
|
|||
|
}*/
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//////////////////////////////////////////////
|
|||
|
// APPLICAZIONE
|
|||
|
/////////////////////////////////////////////
|
|||
|
//Ridistributore di F24 per il computer
|
|||
|
class TDistribuzione_f24 : public TSkeleton_application
|
|||
|
{
|
|||
|
TDistribuzione_f24_mask* _mask;
|
|||
|
|
|||
|
virtual bool check_autorization() const {return false;}
|
|||
|
|
|||
|
protected:
|
|||
|
virtual const char * extra_modules() const {return "cg";}
|
|||
|
virtual bool create();
|
|||
|
|
|||
|
void elabora();
|
|||
|
|
|||
|
public:
|
|||
|
virtual void main_loop();
|
|||
|
};
|
|||
|
|
|||
|
void TDistribuzione_f24::elabora()
|
|||
|
{
|
|||
|
TFilename src_files = _mask->get(F_PATH_SRC);
|
|||
|
src_files.add("*.pdf");
|
|||
|
TString_array src_files_list;
|
|||
|
//dalla cartella origine prende tutti i files .pdf e crea una simpatica lista
|
|||
|
const int n_files_pdf = list_files(src_files, src_files_list);
|
|||
|
|
|||
|
const TString& dst_root_path = _mask->get(F_PATH_DST);
|
|||
|
const bool delete_src_files = _mask->get_bool(F_ERASE_TRANSFERRED);
|
|||
|
|
|||
|
//scansione dello string_array per il trasferimento (con tanto di progind e log)
|
|||
|
TProgind pi(n_files_pdf, TR("Trasferimento F24 in corso..."), true, true);
|
|||
|
TLog_report log("ERRORI DI TRASFERIMENTO");
|
|||
|
|
|||
|
TToken_string curr_tok_file(_MAX_PATH, '_');
|
|||
|
|
|||
|
for (int i = 0; i < n_files_pdf; i++)
|
|||
|
{
|
|||
|
if (!pi.addstatus(1))
|
|||
|
break;
|
|||
|
|
|||
|
//file in formato filename e token_string (per prendere i pezzi)
|
|||
|
const TFilename curr_fname = src_files_list.row(i);
|
|||
|
curr_tok_file = curr_fname.name_only();
|
|||
|
|
|||
|
//anno e relativo controllo
|
|||
|
const int anno = curr_tok_file.get_int(0);
|
|||
|
if (anno < 2000)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("File %s ha ANNO errato", (const char*)curr_tok_file);
|
|||
|
log.log(1, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//piva e relativo controllo
|
|||
|
const TString16 piva = curr_tok_file.get(3);
|
|||
|
if (piva.len() < 11)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("File %s ha P.IVA o C.F. errato", (const char*)curr_tok_file);
|
|||
|
log.log(1, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//controllo della cartella di destinazione
|
|||
|
TFilename dst_file = dst_root_path;
|
|||
|
dst_file.add(piva);
|
|||
|
TString4 str_anno;
|
|||
|
str_anno << anno;
|
|||
|
dst_file.add(str_anno);
|
|||
|
const bool crea_dir = make_dir(dst_file);
|
|||
|
//non riesce a crearla! deve dare errore di grave livello!
|
|||
|
if (!crea_dir)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("Impossibile creare la cartella %s !", dst_file);
|
|||
|
log.log(2, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//se invece crea/trova la cartella -> copia il file
|
|||
|
dst_file.add(curr_fname.name());
|
|||
|
|
|||
|
const bool copia_riuscita = fcopy(curr_fname, dst_file);
|
|||
|
if (!copia_riuscita)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("Impossibile copiare il file %s !", curr_fname.name());
|
|||
|
log.log(2, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//controllo dell'avvenuta copia e della correttezza del file destinazione
|
|||
|
//controllo sulle dimensioni
|
|||
|
const long src_size = fsize(curr_fname);
|
|||
|
const long dst_size = fsize(dst_file);
|
|||
|
|
|||
|
if (src_size != dst_size)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("Copia del file %s non completata !", curr_fname.name());
|
|||
|
log.log(2, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
//eliminazione del file sorgente
|
|||
|
if (delete_src_files)
|
|||
|
{
|
|||
|
const bool src_file_removed = remove_file(curr_fname);
|
|||
|
if (!src_file_removed)
|
|||
|
{
|
|||
|
TString msg;
|
|||
|
msg.format("Impossibile eliminare il file origine %s ", curr_fname.name());
|
|||
|
log.log(1, msg);
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
bool TDistribuzione_f24::create()
|
|||
|
{
|
|||
|
//se non ha la CG non pu<70> proseguire
|
|||
|
if (!has_module(CGAUT))
|
|||
|
return error_box(TR("Modulo non autorizzato"));
|
|||
|
|
|||
|
return TSkeleton_application::create();
|
|||
|
}
|
|||
|
|
|||
|
void TDistribuzione_f24::main_loop()
|
|||
|
{
|
|||
|
_mask = new TDistribuzione_f24_mask;
|
|||
|
if (_mask->run() != K_QUIT)
|
|||
|
elabora();
|
|||
|
delete _mask;
|
|||
|
_mask = NULL;
|
|||
|
}
|
|||
|
|
|||
|
int pg0067100 (int argc, char **argv)
|
|||
|
{
|
|||
|
TDistribuzione_f24 a;
|
|||
|
a.run(argc,argv, TR("Spostamento F24"));
|
|||
|
return true;
|
|||
|
}
|