2020-04-21 18:53:15 +02:00
# include "f90.h"
2020-05-14 23:38:30 +02:00
# include <Windows.h>
# include <set>
# include <map>
2020-05-25 11:53:18 +02:00
# include "annessif9.h"
2020-04-21 18:53:15 +02:00
# include "applicat.h"
# include "automask.h"
2020-05-25 11:53:18 +02:00
# include "docf9.h"
# include "sheet.h"
2020-04-22 18:38:55 +02:00
# include "urldefid.h"
# include "utility.h"
2020-05-14 23:38:30 +02:00
# include "mov.h"
# include "isam.h"
2020-05-18 11:00:06 +02:00
# include "f9lib01.h"
2020-05-25 11:53:18 +02:00
# include "f90300a.h"
# include "f90300b.h"
2020-04-22 18:38:55 +02:00
2020-05-14 23:38:30 +02:00
# define TABMOD_CARTDIR "S0"
2020-04-22 18:38:55 +02:00
///////////////////////////////////////////////////////////////////////////////
2020-05-14 23:38:30 +02:00
// TImport_msk
2020-04-22 18:38:55 +02:00
2020-05-25 11:53:18 +02:00
class TImport_msk : public TAutomask
2020-04-22 18:38:55 +02:00
{
friend class TGestione_doc_cartacei_f9_msk ;
2020-05-25 11:53:18 +02:00
std : : shared_ptr < TArray_sheet > _catdocs ;
map < TString , unique_ptr < TArray_sheet > > _annessi ;
bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) override ;
static bool catdocann_handler ( TMask_field & field , KEY key ) ;
static bool catannpadre_handler ( TMask_field & field , KEY key ) ;
static bool ok_handler ( TMask_field & field , KEY key ) ;
const char * select_catdoc ( ) ;
2020-05-14 23:38:30 +02:00
2020-04-22 18:38:55 +02:00
public :
2020-05-28 16:33:29 +02:00
void set_fields ( const TString & impaddress , const TString & impnumreg , bool isannesso = false , const TString & catannpadre = " " ,
const TString & catdocann = " " ) ;
2020-05-25 11:53:18 +02:00
TImport_msk ( ) ;
2020-04-22 18:38:55 +02:00
} ;
2020-05-25 11:53:18 +02:00
bool TImport_msk : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
switch ( o . dlg ( ) )
{
case F_ISANNESSO :
if ( e = = fe_modify )
{
const bool on = o . mask ( ) . get_bool ( F_ISANNESSO ) ;
o . mask ( ) . enable ( F_CATDOCANN , on ) ;
}
2020-05-28 16:33:29 +02:00
break ;
case F_IMPNUMREG :
if ( e = = fe_modify )
{
const std : : shared_ptr < TCategorie_doc : : classe_doc > c = categorie_doc ( ) . mov2cat ( o . get_int ( ) ) ;
if ( c ! = nullptr )
{
set ( F_CATANNPADRE , c - > catdoc ) ;
set ( F_CATDOCANN , " " ) ;
}
else
{
message_box ( " Questo tipo di registrazione non corrisponde a nessuna delle categorie documentali inserite. " ) ;
set ( F_CATANNPADRE , " " ) ;
set ( F_CATDOCANN , " " ) ;
}
}
2020-05-25 11:53:18 +02:00
default : break ;
}
return true ;
}
bool TImport_msk : : catdocann_handler ( TMask_field & field , KEY key )
{
static const char * msg_notexist = " Non esistono tipologie di annessi per questa categoria documentale. " ;
2020-05-28 16:33:29 +02:00
static const char * msg_inspadre = " Questa registrazione non e' riconosciuta in nessuna categoria documentale. \n Impossible inserire un annesso. \n "
" Si prega di inserire prima una cat. documentale che comprenda questo tipo di registrazione \n aggiungendo anche eventuali tipologie di annessi. " ;
2020-05-25 11:53:18 +02:00
TImport_msk & msk = ( TImport_msk & ) field . mask ( ) ;
if ( key = = K_TAB & & field . dirty ( ) & & field . full ( ) )
{
if ( msk . get ( F_CATANNPADRE ) . full ( ) )
{
const TString_array names_ann = categorie_doc ( ) . get_array_ann ( msk . get ( F_CATANNPADRE ) ) ;
if ( names_ann . items ( ) > 0 )
{
bool ok = false ;
FOR_EACH_ARRAY_ITEM ( names_ann , nr , ann )
{
if ( field . get ( ) = = ( * ( TToken_string * ) ann ) . get ( 0 ) )
ok = true ;
}
if ( ! ok )
{
msk . error_box ( " La categoria inserita e' inesistente " ) ;
field . set ( " " ) ;
}
}
else
warning_box ( msg_notexist ) ;
}
else
{
warning_box ( msg_inspadre ) ;
field . set ( " " ) ;
}
}
if ( key = = K_F9 )
{
if ( msk . get ( F_CATANNPADRE ) . full ( ) )
{
TArray_sheet * annessi = categorie_doc ( ) . get_sheet_ann ( msk . get ( F_CATANNPADRE ) ) . get ( ) ;
if ( annessi & & annessi - > items ( ) > 0 )
{
if ( annessi - > run ( ) = = K_ENTER )
2020-06-09 17:24:14 +02:00
{
const char * s = annessi - > row ( annessi - > selected ( ) ) . get ( 0 ) ;
TCategorie_doc : : annesso annesso ;
2020-06-15 20:33:02 +02:00
if ( categorie_doc ( ) . get_ann ( s , annesso ) )
{
if ( annesso . opcee ! = " RC " )
msk . set ( F_CATDOCANN , annesso . catdoc ) ;
else
warning_box ( " Impossibile importare un annesso cartaceo per un prospetto integrativo per Reverse Charge. " ) ;
}
2020-06-09 17:24:14 +02:00
else
2020-06-15 20:33:02 +02:00
warning_box ( " Errore nell'acquisire la categoria annesso " ) ;
2020-06-09 17:24:14 +02:00
}
2020-05-25 11:53:18 +02:00
}
else
warning_box ( msg_notexist ) ;
}
else
warning_box ( msg_inspadre ) ;
}
return true ;
}
bool TImport_msk : : catannpadre_handler ( TMask_field & field , KEY key )
{
TImport_msk & msk = ( TImport_msk & ) field . mask ( ) ;
if ( key = = K_TAB & & field . dirty ( ) & & field . full ( ) )
{
std : : set < TString > & name_cats = categorie_doc ( ) . get_name_catdocs ( ) ;
const bool ok = name_cats . find ( field . get ( ) ) ! = name_cats . end ( ) ;
if ( ! ok )
{
msk . error_box ( " La categoria inserita e' inesistente " ) ;
field . set ( " " ) ;
}
}
if ( key = = K_F9 )
{
field . set ( msk . select_catdoc ( ) ) ;
msk . set ( F_CATDOCANN , " " ) ;
}
return true ;
}
bool TImport_msk : : ok_handler ( TMask_field & field , KEY key )
{
field . mask ( ) . send_key ( K_ENTER , DLG_OK ) ;
return true ;
}
const char * TImport_msk : : select_catdoc ( )
{
if ( _catdocs = = nullptr )
_catdocs = categorie_doc ( ) . get_sheet_catdocs ( ) ;
if ( _catdocs - > run ( ) = = K_ENTER )
return _catdocs - > row ( ) . get ( 0 ) ;
return " " ;
}
2020-05-28 16:33:29 +02:00
void TImport_msk : : set_fields ( const TString & impaddress , const TString & impnumreg , const bool isannesso ,
const TString & catannpadre , const TString & catdocann )
{
set ( F_IMPADDRESS , impaddress ) ;
set ( F_IMPNUMREG , impnumreg ) ;
set ( F_ISANNESSO , isannesso ) ;
set ( F_CATANNPADRE , catannpadre ) ;
set ( F_CATDOCANN , catdocann ) ;
}
2020-05-25 11:53:18 +02:00
TImport_msk : : TImport_msk ( ) : TAutomask ( " f90300b " )
{
TMask : : set_handler ( F_CATANNPADRE , catannpadre_handler ) ;
TMask : : set_handler ( F_CATDOCANN , catdocann_handler ) ;
}
2020-04-22 18:38:55 +02:00
2020-04-21 18:53:15 +02:00
///////////////////////////////////////////////////////////////////////////////
// TGestione_doc_cartacei_f9_msk
///////////////////////////////////////////////////////////////////////////////
class TGestione_doc_cartacei_f9_msk : public TAutomask
{
2020-05-14 23:38:30 +02:00
struct doc_cart_t
{
TString filename ;
TString loaddate ;
TString numreg ;
TString user ;
} ;
2020-05-28 16:33:29 +02:00
struct ann_cart_t
{
TString numreg ;
TString filename ;
TString catdocpad ;
TString catdocann ;
TString loaddate ;
TString user ;
} ;
2020-05-18 11:00:06 +02:00
const TString & _addr_cart ; // Indirizzo cartella doc. cartacei F9
2020-06-09 17:24:14 +02:00
std : : unique_ptr < TMask > _config_msk ;
2020-05-14 23:38:30 +02:00
std : : unique_ptr < std : : set < TString > > _extensions ; // todo: controllare che con TString funzioni l'ordinamento, quindi la find
std : : unique_ptr < TImport_msk > _import_msk ;
std : : map < TString , doc_cart_t > _list_file ;
2020-05-28 16:33:29 +02:00
std : : map < TString , ann_cart_t > _list_ann ;
2020-04-22 18:38:55 +02:00
2020-04-21 18:53:15 +02:00
bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) override ;
2020-04-22 18:38:55 +02:00
2020-06-09 17:24:14 +02:00
void check_addr_cart ( ) ;
2020-05-14 23:38:30 +02:00
static void check_deleted ( ) ;
bool check_file_exist ( const TString & file ) const ;
void delete_file ( ) ;
2020-05-28 16:33:29 +02:00
void edit_ann ( ) ;
void edit_file ( ) ;
2020-05-14 23:38:30 +02:00
void fill ( ) ;
2020-05-28 16:33:29 +02:00
void fill_annessi ( ) ;
2020-05-25 11:53:18 +02:00
void fill_docs ( ) ;
2020-05-14 23:38:30 +02:00
static TToken_string & get_valid_extensions ( ) ;
void load_extensions ( ) ;
2020-06-09 17:24:14 +02:00
static bool load_file ( const TFilename & file , const TString & numreg , bool is_annesso , const TString & catannpadre , const TString & catdocann ) ;
void open_config_win ( ) ;
2020-05-14 23:38:30 +02:00
void open_import_win ( ) ;
2020-05-18 11:00:06 +02:00
static void remove_file_from_f9cart ( const std : : set < TString > & files ) ;
2020-05-14 23:38:30 +02:00
bool verify_extension ( const TFilename & file ) ;
2020-04-22 18:38:55 +02:00
2020-04-21 18:53:15 +02:00
public :
2020-05-14 23:38:30 +02:00
TGestione_doc_cartacei_f9_msk ( ) ;
2020-04-21 18:53:15 +02:00
} ;
bool TGestione_doc_cartacei_f9_msk : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
{
if ( e = = se_query_add | | e = = se_query_del | | e = = se_query_modify )
return false ;
2020-05-14 23:38:30 +02:00
switch ( o . dlg ( ) )
{
case B_IMPORT :
if ( e = = fe_button )
open_import_win ( ) ;
break ;
case B_DELETE :
if ( e = = fe_button )
delete_file ( ) ;
break ;
case B_CONFIG :
if ( e = = fe_button )
open_config_win ( ) ;
2020-05-28 16:33:29 +02:00
break ;
case DLG_USER :
if ( e = = fe_button )
{
2020-06-09 17:24:14 +02:00
const int page = curr_page ( ) ;
2020-05-28 16:33:29 +02:00
if ( ! page )
edit_file ( ) ;
else
edit_ann ( ) ;
}
2020-05-14 23:38:30 +02:00
default : break ;
}
2020-04-22 18:38:55 +02:00
return true ;
}
2020-06-09 17:24:14 +02:00
void TGestione_doc_cartacei_f9_msk : : check_addr_cart ( )
2020-05-18 11:00:06 +02:00
{
const TFilename f ( _addr_cart ) ;
if ( f . full ( ) & & ! f . exist ( ) )
{
warning_box ( " Cartella documenti cartacei non trovata. \n Salvare nuovamente le impostazioni. " ) ;
open_config_win ( ) ;
}
}
2020-05-14 23:38:30 +02:00
void TGestione_doc_cartacei_f9_msk : : check_deleted ( )
{
// Controllo che non ci siano file nella cartella eliminati da piu' di un mese, altrimenti li elimino
TString_array result ;
2020-05-18 11:00:06 +02:00
TFilename s ; s < < TFilename ( F9CONF . get_addr_cart ( ) ) . slash_terminate ( ) < < " eliminati \\ " ;
if ( s . exist ( ) )
2020-05-14 23:38:30 +02:00
{
2020-05-18 11:00:06 +02:00
list_files ( s , result ) ;
FOR_EACH_ARRAY_ITEM ( result , nr , file )
2020-05-14 23:38:30 +02:00
{
2020-05-18 11:00:06 +02:00
const char * deletedfile = * ( TString * ) ( file ) ;
HANDLE h_file = CreateFile ( deletedfile , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL ) ;
FILETIME last_access_time ;
SYSTEMTIME time ;
bool flag = false ;
if ( h_file ! = INVALID_HANDLE_VALUE )
2020-05-14 23:38:30 +02:00
{
2020-05-18 11:00:06 +02:00
if ( GetFileTime ( h_file , NULL , & last_access_time , NULL ) )
2020-05-14 23:38:30 +02:00
{
2020-05-18 11:00:06 +02:00
FileTimeToSystemTime ( & last_access_time , & time ) ;
TDate today = TDate ( TODAY ) ;
if ( time . wMonth < ( unsigned short ) today . month ( ) - 1 | |
time . wMonth = = ( unsigned short ) today . month ( ) - 1 & & time . wDay < = ( unsigned short ) today . day ( ) )
{
flag = true ;
CloseHandle ( h_file ) ;
DeleteFile ( deletedfile ) ;
}
2020-05-14 23:38:30 +02:00
}
}
2020-05-18 11:00:06 +02:00
if ( ! flag )
CloseHandle ( h_file ) ;
2020-05-14 23:38:30 +02:00
}
}
}
bool TGestione_doc_cartacei_f9_msk : : check_file_exist ( const TString & file ) const
{
TFilename path ( _addr_cart ) ;
path . slash_terminate ( ) < < file ;
return path . exist ( ) ;
}
void TGestione_doc_cartacei_f9_msk : : delete_file ( )
{
2020-05-25 11:53:18 +02:00
int p = curr_page ( ) ;
TSheet_field & sf = p = = 0 ? sfield ( S_IMPORTED ) : sfield ( S_ANNESSI ) ;
2020-05-14 23:38:30 +02:00
FOR_EACH_SHEET_ROW ( sf , nr , row )
{
if ( row - > starts_with ( " X " ) )
{
2020-05-25 11:53:18 +02:00
TLocalisamfile f9cart ( LF_F9DOCS ) ;
TLocalisamfile f9annessi ( LF_F9ANNESSI ) ;
const char * filename = row - > get ( cid2index ( F_FILENAME ) ) ;
const char * numreg = row - > get ( p = = 0 ? cid2index ( F_NUMREG ) : cid2index ( F_ANUMREG ) ) ;
if ( p = = 0 )
{
f9cart . put ( F9C_FILENAME , filename ) ;
f9cart . put ( F9C_NUMREG , numreg ) ;
f9cart . read ( ) ;
}
else
{
f9annessi . put ( F9A_NUMREG , numreg ) ;
f9annessi . put ( F9A_FILENAME , filename ) ;
f9annessi . read ( ) ;
}
2020-05-18 11:00:06 +02:00
TFilename filecart ( F9CONF . get_addr_cart ( ) ) ;
filecart . slash_terminate ( ) ;
TFilename deleted ( filecart ) ;
filecart < < filename ;
deleted < < " eliminati " < < SLASH ;
2020-05-14 23:38:30 +02:00
if ( ! deleted . exist ( ) )
make_dir ( deleted ) ;
deleted < < filename ;
if ( deleted . exist ( ) )
DeleteFile ( deleted ) ;
if ( ! MoveFile ( filecart , deleted ) )
warning_box ( TString ( " Attenzione: " ) < < " non e' stato possibile rimuovere questo file: " < < filecart ) ;
else
2020-05-25 11:53:18 +02:00
{
if ( p = = 0 )
f9cart . remove ( ) ;
else
f9annessi . remove ( ) ;
}
2020-05-14 23:38:30 +02:00
}
}
fill ( ) ;
}
2020-05-28 16:33:29 +02:00
void TGestione_doc_cartacei_f9_msk : : edit_ann ( )
{
TToken_string & row = sfield ( S_ANNESSI ) . row ( sfield ( S_ANNESSI ) . selected ( ) ) ;
TImport_msk win ;
win . set_caption ( " Modifica annesso " ) ;
TLocalisamfile f9ann ( LF_F9ANNESSI ) ;
const char * numreg = row . get ( 4 ) ;
const char * filename = row . get ( 1 ) ;
f9ann . put ( F9A_NUMREG , numreg ) ;
f9ann . put ( F9A_FILENAME , filename ) ;
f9ann . read ( ) ;
win . set_fields ( TF9_doccart : : get_full_path_file_cartaceo ( filename ) , numreg , true , f9ann . get ( F9A_CATDOCPAD ) , f9ann . get ( F9A_CATDOCANN ) ) ;
win . disable ( F_IMPADDRESS ) ;
win . disable ( F_ISANNESSO ) ;
win . enable ( F_CATDOCANN ) ;
if ( win . run ( ) = = K_ENTER )
{
if ( win . get ( F_IMPNUMREG ) = = numreg )
{
f9ann . put ( F9A_CATDOCPAD , win . get ( F_CATANNPADRE ) ) ;
f9ann . put ( F9A_CATDOCANN , win . get ( F_CATDOCANN ) ) ;
f9ann . write ( ) ;
f9ann . rewrite ( ) ;
}
else
{
f9ann . remove ( ) ;
f9ann . put ( F9A_NUMREG , win . get ( F_IMPNUMREG ) ) ;
f9ann . put ( F9A_CATDOCPAD , win . get ( F_CATANNPADRE ) ) ;
f9ann . put ( F9A_CATDOCANN , win . get ( F_CATDOCANN ) ) ;
f9ann . write ( ) ;
f9ann . rewrite ( ) ;
}
message_box ( " Annesso modificato! " ) ;
}
fill_annessi ( ) ;
}
void TGestione_doc_cartacei_f9_msk : : edit_file ( )
{
TToken_string & row = sfield ( S_IMPORTED ) . row ( sfield ( S_IMPORTED ) . selected ( ) ) ;
TImport_msk win ;
win . set_caption ( " Modifica documento cartaceo " ) ;
TLocalisamfile f9docs ( LF_F9DOCS ) ;
const char * numreg = row . get ( 2 ) ;
const char * filename = row . get ( 1 ) ;
f9docs . put ( F9C_NUMREG , numreg ) ;
f9docs . read ( ) ;
win . set_fields ( TF9_doccart : : get_full_path_file_cartaceo ( filename ) , numreg ) ;
win . disable ( F_IMPADDRESS ) ;
win . disable ( F_ISANNESSO ) ;
if ( win . run ( ) = = K_ENTER & & win . get ( F_IMPNUMREG ) ! = numreg )
{
f9docs . remove ( ) ;
f9docs . put ( F9C_NUMREG , win . get ( F_IMPNUMREG ) ) ;
f9docs . write ( ) ;
f9docs . rewrite ( ) ;
message_box ( " Documento modificato! " ) ;
}
fill_docs ( ) ;
}
2020-05-25 11:53:18 +02:00
void TGestione_doc_cartacei_f9_msk : : fill ( )
{
fill_docs ( ) ;
fill_annessi ( ) ;
}
2020-05-28 16:33:29 +02:00
void TGestione_doc_cartacei_f9_msk : : fill_annessi ( )
2020-05-14 23:38:30 +02:00
{
2020-05-28 16:33:29 +02:00
std : : set < TString > file_err ;
2020-06-23 17:33:42 +02:00
TSheet_field & sf = sfield ( S_ANNESSI ) ;
sf . hide ( ) ;
sf . destroy ( ) ;
2020-05-25 11:53:18 +02:00
TLocalisamfile ann ( LF_F9ANNESSI ) ;
if ( ann . first ( ) = = NOERR )
2020-05-14 23:38:30 +02:00
{
2020-05-28 16:33:29 +02:00
const TString & namefile = ann . get ( F9A_FILENAME ) ;
const bool not_exist = ! check_file_exist ( namefile ) ;
if ( not_exist )
file_err . insert ( namefile ) ;
2020-05-25 11:53:18 +02:00
TLocalisamfile mov ( LF_MOV ) ;
do
{
TToken_string & row = sf . row ( - 1 ) ;
const TString & numreg = ann . get ( F9A_NUMREG ) ;
mov . put ( MOV_NUMREG , numreg ) ;
mov . read ( ) ;
2020-05-28 16:33:29 +02:00
row . add ( ann . get ( F9A_FILENAME ) , 1 ) ; // ITEM "Nome File@25"
row . add ( ann . get ( F9A_CATDOCPAD ) ) ; // ITEM "Categoria di\nappartenenza@7"
row . add ( ann . get ( F9A_CATDOCANN ) ) ; // ITEM "Classe doc.\nannesso@7"
row . add ( numreg ) ; // ITEM "Movimento\nContabile N.@7"
row . add ( mov . get ( MOV_DATAREG ) ) ; // ITEM "Data\nMovimento@10"
row . add ( mov . get ( MOV_CODCAUS ) ) ; // ITEM "Causale@7"
row . add ( mov . get ( MOV_NUMDOC ) ) ; // ITEM "Num. Doc.@7"
2020-05-25 11:53:18 +02:00
row . add ( TString ( mov . get ( MOV_REG ) ) < < " / " < < mov . get ( MOV_PROTIVA ) ) ; // ITEM "Reg./Prot. IVA@10"
2020-05-28 16:33:29 +02:00
row . add ( mov . get ( MOV_DESCR ) ) ; // ITEM "Descrizione@20"
row . add ( ann . get ( F9A_LOADDATE ) ) ; // ITEM "Data\nCaricamento@10"
row . add ( not_exist ? " IL FILE NON E' PRESENTE IN ARCHIVIO. " : " " ) ; // ITEM "Info (Errori)@25"
_list_ann . insert ( { namefile , { numreg , namefile , ann . get ( F9A_CATDOCPAD ) , ann . get ( F9A_CATDOCANN ) , ann . get ( F9C_LOADDATE ) , ann . get ( F9C_USER ) } } ) ;
2020-05-25 11:53:18 +02:00
} while ( ann . next ( ) = = NOERR ) ;
2020-05-14 23:38:30 +02:00
}
2020-06-23 17:33:42 +02:00
sf . force_update ( ) ;
sf . show ( ) ;
2020-05-28 16:33:29 +02:00
if ( ! file_err . empty ( ) )
{
int count = 0 ;
const bool m = ( int ) file_err . size ( ) = = 1 ;
const char p = m ? ' o ' : ' i ' ;
TString msg ; msg < < ( int ) file_err . size ( ) < < " file non " < < ( m ? " e' " : " sono " ) < < " stat " < < p < <
" trovat " < < p < < " . \n Si prega di rimuoverl " < < p < < " dall'elenco \n \n File non trovat " < < p < < " : " ;
for ( auto it = file_err . begin ( ) ; it ! = file_err . end ( ) ; + + it )
{
if ( count + + = = 10 )
{
msg < < " \n " < < " ... " ;
break ;
}
msg < < " \n " < < * it < < " [Num. Reg.: " < < _list_ann . find ( * it ) - > second . numreg < < " ] " ;
}
2020-06-09 17:24:14 +02:00
warning_box ( msg ) ;
2020-05-28 16:33:29 +02:00
}
2020-05-14 23:38:30 +02:00
}
2020-05-25 11:53:18 +02:00
void TGestione_doc_cartacei_f9_msk : : fill_docs ( )
2020-04-22 18:38:55 +02:00
{
2020-05-25 11:53:18 +02:00
TLocalisamfile files ( LF_F9DOCS ) ;
2020-05-14 23:38:30 +02:00
TLocalisamfile mov ( LF_MOV ) ;
TSheet_field & sf = sfield ( S_IMPORTED ) ;
sf . hide ( ) ;
sf . destroy ( ) ;
_list_file . clear ( ) ;
2020-05-18 11:00:06 +02:00
std : : set < TString > file_err ;
2020-05-25 11:53:18 +02:00
if ( files . first ( ) = = NOERR )
2020-05-14 23:38:30 +02:00
{
do
{
2020-05-25 11:53:18 +02:00
const TString & namefile = files . get ( F9C_FILENAME ) ;
const bool not_exist = ! check_file_exist ( namefile ) ;
if ( not_exist )
2020-05-18 11:00:06 +02:00
file_err . insert ( namefile ) ;
2020-05-25 11:53:18 +02:00
const TString & numreg = files . get ( F9C_NUMREG ) ;
2020-05-14 23:38:30 +02:00
TString datamov , caus , numdoc , nprot , descrmov ;
mov . zero ( ) ;
mov . put ( MOV_NUMREG , numreg ) ;
2020-05-25 11:53:18 +02:00
if ( mov . read ( ) = = NOERR )
2020-05-14 23:38:30 +02:00
{
2020-05-25 11:53:18 +02:00
datamov = mov . get ( MOV_DATAREG ) ;
caus = mov . get ( MOV_CODCAUS ) ;
numdoc = mov . get ( MOV_NUMDOCEXT ) ;
if ( numdoc . empty ( ) ) numdoc = mov . get ( MOV_NUMDOC ) ;
2020-05-18 11:00:06 +02:00
nprot < < mov . get ( MOV_REG ) < < " / " < < mov . get ( MOV_PROTIVA ) ;
2020-05-25 11:53:18 +02:00
descrmov = mov . get ( MOV_DESCR ) ;
2020-05-14 23:38:30 +02:00
}
TToken_string & r = sf . row ( - 1 ) ;
2020-05-18 11:00:06 +02:00
r . add ( " " , 0 ) ; // F_SEL
r . add ( namefile ) ; // F_FILENAME
r . add ( numreg ) ; // F_NUMREG
r . add ( datamov ) ; // F_DATAMOV
r . add ( caus ) ; // F_CAUS
r . add ( numdoc ) ; // F_NUMDOC
r . add ( nprot ) ; // F_NPROTOCOL
r . add ( descrmov ) ; // F_DESCRMOV
2020-05-25 11:53:18 +02:00
r . add ( files . get ( F9C_LOADDATE ) ) ; // F_DATACARIC
2020-05-18 11:00:06 +02:00
r . add ( not_exist ? " IL FILE NON E' PRESENTE IN ARCHIVIO. " : " " ) ; // F_INFO
2020-05-14 23:38:30 +02:00
_list_file . insert ( { namefile , { namefile , files . get ( F9C_LOADDATE ) , numreg , files . get ( F9C_USER ) } } ) ;
} while ( files . next ( ) = = NOERR ) ;
2020-06-23 17:33:42 +02:00
2020-05-14 23:38:30 +02:00
}
2020-06-23 17:33:42 +02:00
sf . force_update ( ) ;
2020-05-14 23:38:30 +02:00
sf . show ( ) ;
2020-06-23 17:33:42 +02:00
2020-05-25 11:53:18 +02:00
if ( ! file_err . empty ( ) )
2020-05-18 11:00:06 +02:00
{
int count = 0 ;
const bool m = ( int ) file_err . size ( ) = = 1 ;
const char p = m ? ' o ' : ' i ' ;
TString msg ; msg < < ( int ) file_err . size ( ) < < " file non " < < ( m ? " e' " : " sono " ) < < " stat " < < p < <
" trovat " < < p < < " . \n Si prega di rimuoverl " < < p < < " dall'elenco \n \n File non trovat " < < p < < " : " ;
2020-05-14 23:38:30 +02:00
2020-05-25 11:53:18 +02:00
for ( auto it = file_err . begin ( ) ; it ! = file_err . end ( ) ; + + it )
2020-05-18 11:00:06 +02:00
{
if ( count + + = = 10 )
{
msg < < " \n " < < " ... " ;
break ;
}
msg < < " \n " < < * it < < " [Num. Reg.: " < < _list_file . find ( * it ) - > second . numreg < < " ] " ;
2020-05-25 11:53:18 +02:00
}
2020-05-18 11:00:06 +02:00
# ifndef DBG
2020-05-28 16:33:29 +02:00
const bool del = warning_box ( msg ) ;
2020-05-18 11:00:06 +02:00
# else
2020-05-28 16:33:29 +02:00
if ( yesno_box ( msg ) )
{
remove_file_from_f9cart ( file_err ) ;
fill ( ) ;
}
2020-05-18 11:00:06 +02:00
# endif
2020-05-25 11:53:18 +02:00
}
2020-04-22 18:38:55 +02:00
}
TToken_string & TGestione_doc_cartacei_f9_msk : : get_valid_extensions ( )
{
2020-05-18 11:00:06 +02:00
static TToken_string ext ( F9CONF . get_estensioni ( ) , ' , ' ) ;
2020-04-22 18:38:55 +02:00
if ( ext . items ( ) = = 0 )
2020-04-21 18:53:15 +02:00
{
2020-04-22 18:38:55 +02:00
ext = " .pdf, .doc, .docx, .xls, .xlsx, .jpg, .jpeg, .png " ;
2020-05-18 11:00:06 +02:00
F9CONF . set_estensioni ( ext ) ;
2020-04-21 18:53:15 +02:00
}
2020-04-22 18:38:55 +02:00
ext . replace ( " " , " " ) ;
return ext ;
}
void TGestione_doc_cartacei_f9_msk : : load_extensions ( )
{
if ( _extensions = = nullptr )
{
2020-05-14 23:38:30 +02:00
_extensions = std : : make_unique < std : : set < TString > > ( ) ;
2020-04-22 18:38:55 +02:00
TToken_string & ext = get_valid_extensions ( ) ;
for ( int i = 0 ; i < ext . items ( ) ; + + i )
{
TString e = ext . get ( i ) ;
if ( ! e . empty ( ) )
{
if ( e . starts_with ( " . " ) )
e . ltrim ( 1 ) ;
2020-05-14 23:38:30 +02:00
_extensions - > insert ( e ) ;
2020-04-22 18:38:55 +02:00
}
}
}
}
2020-05-25 11:53:18 +02:00
bool TGestione_doc_cartacei_f9_msk : : load_file ( const TFilename & file , const TString & numreg , const bool is_annesso ,
const TString & catannpadre , const TString & catdocann )
2020-04-22 18:38:55 +02:00
{
2020-05-25 11:53:18 +02:00
TString numreg_old ;
bool annesso ;
TF9_doccart f9cart ;
TLocalisamfile f9docs ( LF_F9DOCS ) ;
TLocalisamfile f9annessi ( LF_F9ANNESSI ) ;
if ( f9cart . doc_already_exists ( file , numreg_old , annesso ) )
2020-05-14 23:38:30 +02:00
{
2020-05-25 11:53:18 +02:00
warning_box ( " Attenzione: esiste gia' un %s con questo nome associato al num. di registrazione %s " , annesso ? " annesso " : " documento " , ( const char * ) numreg_old ) ;
2020-05-14 23:38:30 +02:00
return false ;
}
2020-05-25 11:53:18 +02:00
if ( ! is_annesso )
{
TFilename doc ;
if ( f9cart . mov2doc ( numreg , doc ) & & ! doc . empty ( ) )
{
warning_box ( " Attenzione: la registrazione num. %s ha gia' un documento associato: %s. \n "
" Se si tratta di un annesso inserire le informazioni per la cat. documentale. " , ( const char * ) numreg , ( const char * ) doc ) ;
return false ;
}
f9docs . zero ( ) ;
f9docs . put ( F9C_FILENAME , file . name ( ) ) ;
f9docs . put ( F9C_NUMREG , numreg ) ;
f9docs . put ( F9C_LOADDATE , TDate ( TODAY ) ) ;
f9docs . put ( F9C_USER , user ( ) ) ;
}
else
{
2020-06-08 10:57:35 +02:00
// Controllo che non sto gia' utilizzando questa categoria di annesso per questa registrazione
// Prendo la lista degli annessi per questa registrazione e li controllo in cerca della categoria
TF9_doccart doccart ;
vector < annesso_t > list_annessi ;
doccart . mov2listann_vect ( numreg , list_annessi ) ;
bool exist = false ;
for ( auto it = list_annessi . begin ( ) ; it ! = list_annessi . end ( ) ; + + it )
{
if ( it - > catdocann = = catdocann )
exist = true ;
}
if ( exist )
{
message_box ( " Attenzione: la registrazione num. %s ha gia' un annesso associato con questo tipo di annesso. " , ( const char * ) numreg ) ;
return false ;
}
2020-05-25 11:53:18 +02:00
f9annessi . zero ( ) ;
f9annessi . put ( F9A_NUMREG , numreg ) ;
f9annessi . put ( F9A_FILENAME , file . name ( ) ) ;
f9annessi . put ( F9A_CATDOCPAD , catannpadre ) ;
f9annessi . put ( F9A_CATDOCANN , catdocann ) ;
f9annessi . put ( F9C_LOADDATE , TDate ( TODAY ) ) ;
f9annessi . put ( F9C_USER , user ( ) ) ;
}
2020-05-18 11:00:06 +02:00
TFilename fdestin = F9CONF . get_addr_cart ( ) ;
2020-05-14 23:38:30 +02:00
const TString filename = file . name ( ) ;
fdestin < < filename ;
const bool ok = CopyFile ( file , fdestin , true ) ;
if ( ! ok )
{
2020-05-25 11:53:18 +02:00
if ( fdestin . exist ( ) )
2020-05-14 23:38:30 +02:00
warning_box ( " Errore nel copiare il file nella cartella di destinazione. \n Esiste gia' un file con questo nome. " ) ;
else
warning_box ( " Errore nel copiare il file nella cartella di destinazione. Ritentare. " ) ;
2020-05-25 11:53:18 +02:00
f9docs . zero ( ) ;
2020-05-14 23:38:30 +02:00
return false ;
}
2020-05-25 11:53:18 +02:00
if ( ! is_annesso )
{
f9docs . write ( ) ;
f9docs . rewrite ( ) ;
}
else
{
f9annessi . write ( ) ;
f9annessi . rewrite ( ) ;
}
2020-05-14 23:38:30 +02:00
return true ;
}
2020-06-09 17:24:14 +02:00
void TGestione_doc_cartacei_f9_msk : : open_config_win ( )
2020-05-14 23:38:30 +02:00
{
2020-06-09 17:24:14 +02:00
if ( _config_msk = = nullptr )
2020-05-14 23:38:30 +02:00
{
2020-06-09 17:24:14 +02:00
_config_msk = std : : make_unique < TMask > ( " Configurazione " , 1 , 78 , 14 ) ;
_config_msk - > add_button_tool ( DLG_OK , " Conferma " , TOOL_OK ) ;
_config_msk - > add_button_tool ( DLG_NULL , " " , 0 ) ;
_config_msk - > add_button_tool ( DLG_QUIT , " Esci " , TOOL_QUIT ) ;
_config_msk - > add_groupbox ( DLG_NULL , 0 , " " , 1 , 0 , 76 , 4 , " " ) ;
_config_msk - > add_static ( DLG_NULL , 0 , " @BInserire estensioni file riconosciute, separate da virgola. " , 2 , 1 ) ;
_config_msk - > add_string ( 101 , 0 , " Estensioni: " , 2 , 2 , 255 , " " , 60 ) ;
_config_msk - > add_groupbox ( DLG_NULL , 0 , " @BCartella documenti cartacei " , 1 , 4 , 76 , 4 ) ;
_config_msk - > add_static ( DLG_NULL , 0 , " @BInserire nome cartella, all'interno della area dati della ditta " , 2 , 5 ) ;
_config_msk - > add_string ( 102 , 0 , " " , 2 , 6 , 64 , " " , 30 ) ;
_config_msk - > set ( 101 , F9CONF . get_estensioni ( ) ) ;
2020-05-18 11:00:06 +02:00
TString s = F9CONF . get_addr_cart ( ) ;
2020-05-14 23:38:30 +02:00
s . rtrim ( 1 ) ;
s . ltrim ( s . rfind ( ' \\ ' ) + 1 ) ;
2020-06-09 17:24:14 +02:00
_config_msk - > set ( 102 , s ) ;
2020-05-14 23:38:30 +02:00
}
while ( true )
{
2020-06-09 17:24:14 +02:00
if ( _config_msk - > run ( ) ! = K_ENTER )
2020-05-14 23:38:30 +02:00
{
2020-06-09 17:24:14 +02:00
if ( _config_msk - > get ( 102 ) . empty ( ) )
2020-05-14 23:38:30 +02:00
{
warning_box ( " Si prega di inserire il nome della cartella per i documenti cartacei. " ) ;
continue ;
}
2020-05-18 11:00:06 +02:00
break ;
2020-05-14 23:38:30 +02:00
}
2020-06-09 17:24:14 +02:00
F9CONF . set_estensioni ( _config_msk - > get ( 101 ) ) ;
TString dir = _config_msk - > get ( 102 ) ;
2020-05-14 23:38:30 +02:00
if ( dir . empty ( ) )
{
if ( yesno_box ( " Nome cartella vuoto. \n Creare cartella con nome 'Cartacei_F9'? " ) )
2020-06-09 17:24:14 +02:00
_config_msk - > set ( 102 , dir = " Cartacei_F9 " ) ;
2020-05-14 23:38:30 +02:00
else continue ;
}
TFilename path ( prefix ( ) . get_studio ( ) ) ;
path . slash_terminate ( ) < < dir ;
path . slash_terminate ( ) ;
if ( ! path . exist ( ) )
{
if ( dir = = " Cartacei_F9 " | | yesno_box ( " Il percorso indicato e' inesistente. \n Creare la cartella con questo nome? " ) )
{
if ( ! make_dir ( path ) )
{
warning_box ( " Impossibile creare il percorso specificato. " ) ;
continue ;
}
}
else continue ;
}
2020-05-18 11:00:06 +02:00
F9CONF . set_addr_cart ( path ) ;
2020-05-14 23:38:30 +02:00
break ;
}
2020-04-22 18:38:55 +02:00
}
void TGestione_doc_cartacei_f9_msk : : open_import_win ( )
{
if ( _import_msk = = nullptr )
_import_msk = make_unique < TImport_msk > ( ) ;
while ( _import_msk - > run ( ) = = K_ENTER )
{
2020-05-25 11:53:18 +02:00
const TString & file = _import_msk - > get ( F_IMPADDRESS ) ;
const TString & numreg = _import_msk - > get ( F_IMPNUMREG ) ;
const bool is_annesso = _import_msk - > get_bool ( F_ISANNESSO ) ;
const TString & catannpadre = _import_msk - > get ( F_CATANNPADRE ) ;
const TString & catdocann = _import_msk - > get ( F_CATDOCANN ) ;
2020-05-14 23:38:30 +02:00
if ( ! file . empty ( ) )
2020-04-22 18:38:55 +02:00
{
TFilename f ( file ) ;
if ( verify_extension ( f ) )
2020-05-14 23:38:30 +02:00
{
2020-05-25 11:53:18 +02:00
if ( ! numreg . empty ( ) )
{
if ( ! is_annesso | | catannpadre . full ( ) & & catdocann . full ( ) )
{
if ( load_file ( f , numreg , is_annesso , catannpadre , catdocann ) )
2020-06-08 10:57:35 +02:00
{
2020-05-25 11:53:18 +02:00
message_box ( " File caricato. " ) ;
2020-06-08 10:57:35 +02:00
fill ( ) ;
}
2020-05-25 11:53:18 +02:00
}
else
warning_box ( " Se il documento e' un annesso, si prega di inserire le \n informazioni per la categoria documentale dell'annesso. " ) ;
}
else
warning_box ( " Si prega di inserire il numero di registrazione. " ) ;
2020-05-14 23:38:30 +02:00
}
2020-04-22 18:38:55 +02:00
else
warning_box ( " Questo file e' in un formato non accettato. " ) ;
}
2020-05-25 11:53:18 +02:00
else
warning_box ( " Si prega di inserire il nome del file. " ) ;
2020-04-22 18:38:55 +02:00
}
2020-05-14 23:38:30 +02:00
fill ( ) ;
2020-04-22 18:38:55 +02:00
}
2020-05-18 11:00:06 +02:00
void TGestione_doc_cartacei_f9_msk : : remove_file_from_f9cart ( const std : : set < TString > & files )
{
2020-05-25 11:53:18 +02:00
TLocalisamfile f9cart ( LF_F9DOCS ) ;
2020-05-18 11:00:06 +02:00
for ( auto it = files . begin ( ) ; it ! = files . end ( ) ; + + it )
{
f9cart . zero ( ) ;
f9cart . put ( F9C_FILENAME , * it ) ;
f9cart . read ( ) ;
f9cart . remove ( ) ;
}
}
2020-04-22 18:38:55 +02:00
bool TGestione_doc_cartacei_f9_msk : : verify_extension ( const TFilename & file )
{
load_extensions ( ) ;
return _extensions - > find ( file . ext ( ) ) ! = _extensions - > end ( ) ;
2020-04-21 18:53:15 +02:00
}
2020-05-18 11:00:06 +02:00
TGestione_doc_cartacei_f9_msk : : TGestione_doc_cartacei_f9_msk ( ) : TAutomask ( " f90300a " ) , _addr_cart ( F9CONF . get_addr_cart ( ) )
2020-05-14 23:38:30 +02:00
{
if ( _addr_cart . empty ( ) )
{
message_box ( " Inserire nome cartella documenti cartacei. " ) ;
open_config_win ( ) ;
}
2020-05-18 11:00:06 +02:00
else
check_addr_cart ( ) ;
2020-05-14 23:38:30 +02:00
check_deleted ( ) ;
fill ( ) ;
}
2020-04-22 18:38:55 +02:00
2020-05-18 11:00:06 +02:00
2020-04-21 18:53:15 +02:00
///////////////////////////////////////////////////////////////////////////////
// TGestione_doc_cartacei_f9_app
///////////////////////////////////////////////////////////////////////////////
class TGestione_doc_cartacei_f9_app : public TSkeleton_application
{
2020-04-22 18:38:55 +02:00
void main_loop ( ) override
{
TGestione_doc_cartacei_f9_msk msk ;
while ( msk . run ( ) = = K_ENTER )
{ }
}
2020-04-21 18:53:15 +02:00
} ;
int f90300 ( const int argc , char * argv [ ] )
{
TGestione_doc_cartacei_f9_app app ;
app . run ( argc , argv , " Gestione documenti cartacei " ) ;
return 0 ;
}