1999-04-06 15:34:39 +00:00
# include <applicat.h>
# include <isam.h>
# include <progind.h>
# include <prefix.h>
1999-04-16 12:02:04 +00:00
# include <utility.h>
1999-04-06 15:34:39 +00:00
// prototipi
# include "bainsta.h"
# include "bainst.h"
// ********************************
// classe TSystemtempfile
// ********************************
// classe provvisoria per i system file temporanei, ovvero file temporanei con
// caricamento/scaricamento
// @doc EXTERNAL
// @mfunc Importa un file ascii
//
// @rdesc Ritorna NOERR se l'operazione di lettura e' riuscita, altrimenti il codice di
// di errore generato (vedi <t TIsamerr>).
int TSystemtempfile : : load (
const char * from , // @parm Nome del file da importare
char fs , // @parm Carattere separatore di campo (default <pipe>)
char fd , // @parm Carattere delimitatore di campi (default '\\0')
char rs , // @parm Carattere separatore di record (default '\\n')
bool vis , // @parm Indica se visualizzare lo stato dell'operazione (default TRUE)
bool extended ) // @parm Indica se interpretare alcune stringhe come macro (default FALSE)
// @comm Se <p extended> e' TRUE e trova alcune stringhe col formato %stringa% (es. %frm%)
// ne sostituisce i valori (es. ditta corrente).
// @xref <mf TSystemisamfile::dump>
{
FILE * fl = fopen ( from , " r " ) ;
int err = NOERR ;
if ( fl = = NULL )
{
error_box ( " Non riesco ad aprire il file %s " , from ) ;
1999-04-16 12:02:04 +00:00
clearerr ( fl ) ;
setstatus ( 2 ) ;
1999-04-06 15:34:39 +00:00
return 2 ;
}
TRecnotype r = 0 , e = 0 , nitems = 0 , nread = 0 ;
TString16 firm , year , attprev ( " 00000 " ) ;
if ( extended )
{
TDate d ( TODAY ) ;
TLocalisamfile ditte ( LF_NDITTE ) ;
firm . format ( " %05ld " , prefix ( ) . get_codditta ( ) ) ;
year . format ( " %04d " , d . year ( ) ) ;
ditte . zero ( ) ;
ditte . put ( " CODDITTA " , firm ) ;
if ( ditte . read ( ) = = NOERR )
attprev = ditte . get ( " CODATTPREV " ) ;
}
fseek ( fl , 0L , SEEK_END ) ;
1999-04-16 12:02:04 +00:00
nitems = ftell ( fl ) ;
1999-04-06 15:34:39 +00:00
fclose ( fl ) ;
1999-04-16 12:02:04 +00:00
1999-04-06 15:34:39 +00:00
TScanner f ( from ) ;
//open();
TToken_string s ( 1024 , fs ) ;
bool fixedlen = ( fs = = ' \0 ' ) ;
int nflds = curr ( ) . items ( ) ;
1999-04-16 12:02:04 +00:00
TString_array fld ( nflds ) ;
1999-04-06 15:34:39 +00:00
int len [ MaxFields ] ;
TString sfd ( 3 ) ;
TString s1 ( 64 ) ;
//bool lcf = FALSE;
if ( f . paragraph ( " Header " ) )
{
1999-04-16 12:02:04 +00:00
int equal ;
TString key ;
1999-04-06 15:34:39 +00:00
nflds = 0 ;
1999-04-16 12:02:04 +00:00
while ( ( equal = f . line ( ) . find ( ' = ' ) ) > 0 )
1999-04-06 15:34:39 +00:00
{
1999-04-16 12:02:04 +00:00
key = f . token ( ) . left ( equal ) ;
key . trim ( ) ;
if ( key = = " Version " )
1999-04-06 15:34:39 +00:00
{
1999-04-16 12:02:04 +00:00
const long level = atol ( f . token ( ) . mid ( equal + 1 ) ) ;
if ( level > prefix ( ) . filelevel ( ) )
error_box ( " L'archivio %s e' stato generato con gli archivi di livello %ld%/%ld. \n Il livello attuale e' %ld/%ld. \n Convertire gli archivi e ripetere l' operazione. " ,
from , level / 100 , level % 100 , get_std_level ( ) / 100 , get_std_level ( ) % 100 ) ;
// lcf = getlcf(level);
} else
if ( key = = " File " )
1999-04-06 15:34:39 +00:00
{
1999-04-16 12:02:04 +00:00
const int logic = atoi ( f . token ( ) . mid ( equal + 1 ) ) ;
if ( logic ! = num ( ) )
error_box ( " L'archivio %s e' stato generato dal file %d " ,
from , logic ) ;
} else
if ( key = = " Fields " )
{
TToken_string riga = f . token ( ) . mid ( equal + 1 ) ;
TToken_string wfd ( 32 , ' , ' ) ;
FOR_EACH_TOKEN ( riga , fd )
{
wfd = fd ; wfd . strip_spaces ( ) ;
fld . add ( wfd . get ( 0 ) ) ;
len [ nflds ] = wfd . get_int ( ) ;
nflds + + ;
}
}
1999-04-06 15:34:39 +00:00
}
}
1999-04-16 12:02:04 +00:00
if ( nflds = = 0 | | fld . items ( ) = = 0 )
{
nflds = curr ( ) . items ( ) ;
1999-04-06 15:34:39 +00:00
for ( int j = 0 ; j < nflds ; j + + )
{
1999-04-16 12:02:04 +00:00
fld . add ( curr ( ) . fieldname ( j ) , j ) ;
1999-04-06 15:34:39 +00:00
const TString & wfld = ( const TString & ) fld [ j ] ;
len [ j ] = ( curr ( ) . type ( wfld ) = = _datefld ) ? 10 : curr ( ) . length ( wfld ) ;
}
}
1999-04-16 12:02:04 +00:00
1999-04-06 15:34:39 +00:00
if ( ! f . paragraph ( " Data " ) )
{
error_box ( " Formato dei dati non valido " ) ;
//close();
err = 1 ;
setstatus ( err ) ;
return err ;
}
if ( fd ) sfd < < fd ;
int last = NOERR ;
s1 . format ( " Imp. archivio %s \n %6ld records %6ld errori - %3d " , filename ( ) , r , e , last ) ;
TProgind p ( nitems , s1 , TRUE , TRUE , 70 ) ;
s = f . line ( ) ;
while ( s . not_empty ( ) & & ! p . iscancelled ( ) )
{
if ( extended )
{
int p , i ;
while ( ( p = s . find ( " %yr% " ) ) > = 0 )
for ( i = 0 ; i < 4 ; i + + ) s [ p + i ] = year [ i ] ;
while ( ( p = s . find ( " %frm% " ) ) > = 0 )
for ( i = 0 ; i < 5 ; i + + ) s [ p + i ] = firm [ i ] ;
while ( ( p = s . find ( " %att% " ) ) > = 0 )
for ( i = 0 ; i < 5 ; i + + ) s [ p + i ] = attprev [ i ] ;
}
if ( ( r + e ) % 50 = = 0 )
{
1999-04-16 12:02:04 +00:00
s1 . format ( " Imp. archivio %d \n %6ld records %6ld errori - %3d " , _logicnum , r , e , last ) ;
1999-04-06 15:34:39 +00:00
p . set_text ( s1 ) ;
}
p . setstatus ( nread + 1 ) ;
nread + = s . len ( ) + 1 ;
zero ( ) ;
if ( fixedlen )
{
int pos = 0 ;
for ( int j = 0 ; j < nflds ; j + + )
{
s1 = s . mid ( pos , len [ j ] ) ;
s1 . rtrim ( ) ;
put ( ( const TString & ) fld [ j ] , s1 ) ;
pos + = len [ j ] ;
}
}
else
{
s . restart ( ) ;
for ( int j = 0 ; j < nflds ; j + + )
{
char * s2 = ( char * ) s . get ( ) ;
if ( fd )
{
s2 + + ;
s2 [ strlen ( s2 ) - 1 ] = ' \0 ' ;
}
1999-04-16 12:02:04 +00:00
if ( curr ( ) . type ( ( const TString & ) fld [ j ] ) = = _memofld )
s1 = esc ( s2 ) ;
else
s1 = s2 ;
1999-04-06 15:34:39 +00:00
put ( ( const TString & ) fld [ j ] , s2 ) ;
}
}
1999-04-16 12:02:04 +00:00
int err = write ( ) ;
if ( err = = _isreinsert )
err = rewrite ( ) ;
if ( err = = NOERR )
r + + ;
1999-04-06 15:34:39 +00:00
else
{
1999-04-16 12:02:04 +00:00
error_box ( " Errore di scrittura alla riga %ld " , r + e + 1 ) ;
1999-04-06 15:34:39 +00:00
e + + ;
last = status ( ) ;
1999-04-16 12:02:04 +00:00
break ;
1999-04-06 15:34:39 +00:00
}
s = f . line ( ) ;
}
1999-04-16 12:02:04 +00:00
s1 . format ( " Imp. archivio %d \n %6ld records %6ld errori - %3d " , _logicnum , r , e , last ) ;
1999-04-06 15:34:39 +00:00
p . set_text ( s1 ) ;
//close();
setstatus ( err ) ;
return err ;
}
// @doc EXTERNAL
// @mfunc Esporta VERSO un file ascii.
//
// @rdesc Ritorna NOERR se l'operazione di esportazione e' riuscita, altrimenti il codice di
// di errore generato (vedi <t TIsamerr>).
int TSystemtempfile : : dump (
const char * to , // @parm Nome del file verso quale esportare
int nkey , // @parm Numero della chiave di ordinamento con cui scaricare i dati (defualt 1)
char fs , // @parm Carattere seperatore di campo (defualt <pipe>)
char fd , // @parm Carattere delimitatore di campo (default '\\0')
char rs , // @parm Carattere separatore di record (default '\\n')
bool vis , // @parm Indica se visualizzare lo stato dell'operazione (defualt TRUE)
bool withdeleted ) // @parm Indica se scaricare anche i record cancellati (dafault FALSE)
// @xref <mf TSystemisamfile::load>
{
FILE * f = fopen ( to , " w " ) ;
if ( f = = NULL )
{
setstatus ( 2 ) ;
return 2 ;
}
if ( withdeleted ) nkey = 0 ;
int err = ferror ( f ) ;
//open(FALSE, nkey ? TRUE : FALSE);
TString s ( 512 ) ;
bool fixedlen = ( fs = = ' \0 ' ) ;
int nflds = curr ( ) . items ( ) ;
TArray fld ( nflds ) ;
TBit_array rjust ( nflds ) ;
int len [ MaxFields ] ;
for ( int j = 0 ; j < nflds ; j + + )
{
fld . add ( TString ( curr ( ) . fieldname ( j ) ) , j ) ;
const TString & wfld = ( const TString & ) fld [ j ] ;
const TFieldtypes t = curr ( ) . type ( wfld ) ;
rjust . set ( j , t = = _intfld | | t = = _longfld | | t = = _realfld | |
t = = _wordfld | | t = = _intzerofld | | t = = _longzerofld ) ;
len [ j ] = ( t = = _datefld ) ? 10 : curr ( ) . length ( wfld ) ;
}
TRecnotype i = 0 ;
1999-04-16 12:02:04 +00:00
const TRecnotype nitems = items ( ) ;
s . format ( " Esportazione archivio %s " , filename ( ) ) ;
1999-04-06 15:34:39 +00:00
TProgind p ( nitems , s , TRUE , TRUE , 70 ) ;
1999-04-16 12:02:04 +00:00
TString s1 , sfld ;
1999-04-06 15:34:39 +00:00
1999-04-16 12:02:04 +00:00
fprintf ( f , " [Header] \n Version=%ld \n File=%d " ,
prefix ( ) . filelevel ( ) , num ( ) ) ;
1999-04-06 15:34:39 +00:00
for ( int k = 0 ; k < nflds ; k + + )
{
if ( ( k % 10 ) = = 0 ) fprintf ( f , " \n Fields= " ) ;
else fprintf ( f , " | " ) ;
fprintf ( f , " %s,%d " , ( const char * ) ( const TString & ) fld [ k ] , len [ k ] ) ;
}
fprintf ( f , " \n \n [Data] \n " ) ;
if ( nkey )
{
setkey ( nkey ) ;
for ( first ( ) ; status ( ) = = NOERR & & ! p . iscancelled ( ) ; next ( ) , i + + )
{
p . setstatus ( i + 1 ) ;
s = " " ;
for ( j = 0 ; j < nflds ; j + + )
{
if ( fixedlen )
{
s1 = get ( ( const TString & ) fld [ j ] ) ;
if ( rjust [ j ] ) s1 . right_just ( len [ j ] ) ;
else s1 . left_just ( len [ j ] ) ;
}
else
{
s1 = " " ;
if ( j & & fs ) s1 < < fs ;
if ( fd ) s1 < < fd ;
1999-04-16 12:02:04 +00:00
sfld = get ( ( const TString & ) fld [ j ] ) ;
if ( curr ( ) . type ( ( const TString & ) fld [ j ] ) = = _memofld )
{
int p = 0 ;
while ( ( p = sfld . find ( ' \n ' , 0 ) ) > = 0 )
{
sfld . overwrite ( " \\ " , p ) ;
sfld . insert ( " n " , p + 1 ) ;
}
}
s1 < < sfld ;
1999-04-06 15:34:39 +00:00
if ( fd ) s1 < < fd ;
}
s < < s1 ;
}
fprintf ( f , " %s%c " , ( const char * ) s , rs ) ;
}
}
else
{
for ( i = 0 ; i < nitems & & ! p . iscancelled ( ) ; i + + )
{
zero ( ) ;
p . setstatus ( i + 1 ) ;
readat ( i + 1 ) ;
s = " " ;
if ( withdeleted | | curr ( ) . valid ( ) )
{
for ( j = 0 ; j < nflds ; j + + )
{
if ( fixedlen )
{
s1 = get ( ( const TString & ) fld [ j ] ) ;
if ( rjust [ j ] ) s1 . right_just ( len [ j ] ) ;
else s1 . left_just ( len [ j ] ) ;
}
else
{
s1 = " " ;
if ( j & & fs ) s1 < < fs ;
if ( fd ) s1 < < fd ;
1999-04-16 12:02:04 +00:00
s1 = get ( ( const TString & ) fld [ j ] ) ;
if ( curr ( ) . type ( ( const TString & ) fld [ j ] ) = = _memofld )
{
int p = 0 ;
while ( ( p = sfld . find ( ' \n ' , 0 ) ) > = 0 )
{
sfld . overwrite ( " \\ " , p ) ;
sfld . insert ( " n " , p + 1 ) ;
}
}
s1 < < sfld ;
if ( fd ) s1 < < fd ;
1999-04-06 15:34:39 +00:00
}
s < < s1 ;
}
fprintf ( f , " %s%c " , ( const char * ) s , rs ) ;
}
}
}
p . setstatus ( nitems ) ;
//close();
fclose ( f ) ;
setstatus ( err ) ;
return err ;
}
// ********************************
// classe TStd_filename
// ********************************
bool TStd_filename : : check ( bool verbose , const char * n )
{
if ( n & & * n )
set ( n ) ;
insert ( " STD \\ " ) ;
if ( ! exist ( ) )
{
* this = name ( ) ;
if ( ! exist ( ) )
{
insert ( " STD \\ " ) ;
insert ( prefix ( ) . get_studio ( ) ) ;
if ( ! exist ( ) )
{
if ( verbose )
error_box ( " Non riesco a trovare il file: %s " , ( const char * ) name ( ) ) ;
cut ( 0 ) ;
return FALSE ;
}
}
}
return TRUE ;
}
bool TInstallmodule_app : : create ( )
{
TScanner scanner ( " prassi.aut " ) ;
bool ok = FALSE ;
for ( int aut = 0 ; aut < = module_number ( ) ; aut + + )
{
scanner . line ( ) ;
}
_modcode = scanner . token ( ) . left ( 2 ) ;
_modname = scanner . token ( ) . mid ( 3 ) ;
if ( modal ( ) )
{
TString16 maskname ;
maskname . format ( " bainst%02d " , module_number ( ) ) ;
_m = new TMask ( maskname ) ;
}
else
_m = NULL ;
TConfig ini ( " install.ini " ) ;
TConfig praw ( CONFIG_INSTALL ) ;
_test_database = praw . get ( " TestDatabase " , " Main " , - 1 , " Y " ) ! = " N " ;
return TSkeleton_application : : create ( ) ;
}
bool TInstallmodule_app : : destroy ( )
{
if ( _m ) delete _m ;
return TSkeleton_application : : destroy ( ) ;
}
bool TInstallmodule_app : : preload_mask ( )
{
if ( ! test_database ( ) )
{
_m - > set ( F_DEFAULTSDATA , " " ) ;
_m - > disable ( F_DEFAULTSDATA ) ;
}
else
{
if ( load_default_data ( ) )
_m - > set ( F_DEFAULTSDATA , " X " ) ;
}
return TRUE ;
}
2001-07-24 13:28:55 +00:00
bool TInstallmodule_app : : some_to_load ( )
{
return _m - > get_bool ( F_DEFAULTSDATA ) ;
}
1999-04-06 15:34:39 +00:00
void TInstallmodule_app : : main_loop ( )
{
bool ok = TRUE ;
if ( modal ( ) )
{
preload_mask ( ) ;
if ( _m - > run ( ) ! = K_QUIT )
{
2001-07-24 13:28:55 +00:00
if ( some_to_load ( ) )
1999-04-06 15:34:39 +00:00
{
install_firm ( ) ;
install_com ( ) ;
}
}
else
ok = FALSE ;
}
if ( ok )
post_installer ( ) ;
}
bool TInstallmodule_app : : install_firm ( )
{
// ciclo su ogni ditta
TStd_filename txtfile ( module_code ( ) ) ;
txtfile < < " tab.txt " ;
if ( txtfile . check ( ) )
{
TLocalisamfile ditte ( LF_NDITTE ) ;
for ( ditte . first ( ) ; ! ditte . eof ( ) ; ditte . next ( ) )
{
const int newditta = ditte . get_int ( " CODDITTA " ) ;
if ( prefix ( ) . exist ( newditta ) )
{
set_firm ( newditta ) ;
TSystemisamfile tab ( LF_TAB ) ;
tab . load ( txtfile ) ;
}
}
// carica le tabelle nei file di default
TLocalisamfile tampone ( LF_TAB ) ;
TSystemtempfile tabstd ( LF_TAB ) ;
TFilename stdtabname ( prefix ( ) . get_studio ( ) ) ;
stdtabname < < " STD \\ lf0005.txt " ;
tabstd . load ( txtfile ) ;
tabstd . load ( stdtabname ) ;
tabstd . set_autodel ( ) ;
TFilename tempfile ;
tempfile . temp ( ) ;
// riconverte le macro delle date
tabstd . dump ( tempfile ) ;
TScanner scan ( tempfile ) ;
FILE * dest = fopen ( ( const char * ) stdtabname , " w " ) ;
while ( TRUE ) {
TString & line = scan . line ( ) ;
if ( line . empty ( ) ) break ;
int pos = ( line . find ( " -0000 " ) ) ;
while ( pos > = 0 )
{
line . overwrite ( " %yr% " , pos + 1 ) ;
pos = ( line . find ( " -0000 " ) ) ;
}
line < < ' \n ' ;
fputs ( ( const char * ) line , dest ) ;
}
fclose ( dest ) ;
}
return TRUE ;
}
bool TInstallmodule_app : : install_com ( )
{
bool ok = TRUE ;
TStd_filename txtfile ( module_code ( ) ) ;
txtfile < < " tabcom.txt " ;
if ( txtfile . check ( ) )
{
TSystemisamfile tabcom ( LF_TABCOM ) ;
tabcom . load ( txtfile ) ;
}
return ok ;
}
void TInstallmodule_app : : run ( int argc , char * argv [ ] )
{
TString title ( " Installazione " ) ;
title < < module_name ( ) ;
TSkeleton_application : : run ( argc , argv , ( const char * ) title ) ;
}
1999-10-22 10:00:18 +00:00
void TInstallmodule_app : : set_tab_app ( const char * appname )
{
TConfig ditta ( CONFIG_DITTA ) ;
ditta . set_paragraph ( module_code ( ) ) ;
ditta . set ( " TabApp " , appname ) ;
}
1999-04-06 15:34:39 +00:00
int main ( int argc , char * * argv )
{
TApplication : : check_parameters ( argc , argv ) ;
int r = 0 ;
if ( argc < 2 ) return 0 ;
TFixed_string mod ( argv [ 2 ] ) ;
mod . lower ( ) ;
if ( mod = = " cg " )
r = bainst07 ( argc , argv ) ; // pre/post installazione contabilit<69> generale:
else if ( mod = = " at " )
r = bainst17 ( argc , argv ) ; // pre/post installazione avis
2001-07-24 13:28:55 +00:00
else if ( mod = = " in " )
r = bainst18 ( argc , argv ) ; // pre/post installazione intra
1999-04-06 15:34:39 +00:00
else if ( mod = = " ve " )
r = bainst31 ( argc , argv ) ; // pre/post installazione vendite:
else if ( mod = = " mg " )
r = bainst32 ( argc , argv ) ; // pre/post installazione magazzino:
2000-10-03 13:45:12 +00:00
else if ( mod = = " ef " )
r = bainst34 ( argc , argv ) ; // pre/post installazione effetti:
1999-04-06 15:34:39 +00:00
else if ( mod = = " sv " )
r = bainst38 ( argc , argv ) ; // pre/post installazione statistiche:
1999-10-22 10:00:18 +00:00
else if ( mod = = " db " )
2000-10-03 13:45:12 +00:00
r = bainst35 ( argc , argv ) ; // pre/post installazione distinta base:
1999-10-22 10:00:18 +00:00
else if ( mod = = " mr " )
r = bainst39 ( argc , argv ) ; // pre/post installazione MRP
1999-04-06 15:34:39 +00:00
else
r = bainst00 ( argc , argv ) ; // pre/post installazione base
exit ( r ) ;
return 0 ;
}