From 0a2b57b22506eb47706a165fbbdc1d763accfc7f Mon Sep 17 00:00:00 2001 From: matteo Date: Wed, 6 Sep 1995 13:53:23 +0000 Subject: [PATCH] Modifiche varie ed eventuali. Iniziato l'oggetto cliente git-svn-id: svn://10.65.10.50/trunk@1787 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- ve/ve0100.cpp | 1970 ++++++++++++++++++++--------------------- ve/ve0300.cpp | 2308 +++++++++++++++++++++++++------------------------ 2 files changed, 2159 insertions(+), 2119 deletions(-) diff --git a/ve/ve0100.cpp b/ve/ve0100.cpp index e73c8c74b..9bb38d19d 100755 --- a/ve/ve0100.cpp +++ b/ve/ve0100.cpp @@ -1,981 +1,989 @@ -#include - -#ifndef __CHECKS_H -#include -#endif - -#ifndef __TABUTIL_H -#include -#endif - -#ifndef __BRWAPP_H -#include -#endif - -#ifndef __RELAPP_H -#include -#endif - -#ifndef __CONFIG_H -#include -#endif - -#ifndef __LFFILES_H -#include -#endif - -#ifndef __DEFMASK_H -#include "defmask.h" -#endif - -#ifndef __VEUML_H -#include "VEUML.H" -#endif - -#ifndef __SHEET_H -#include -#endif - -#ifndef __REAL_H -#include -#endif - -#ifndef __MSKSHEET_H -#include -#endif - -#ifndef __VE0100_H -#include "VE0100.H" -#endif - -#ifndef __VE0100C_H -#include "VE0100C.H" -#endif - -#ifndef __VE0100D_H -#include "VE0100D.H" -#endif - -// Numero di colonne presenti sullo sheet totale -#define MAX_COLUMNS 22 - -#define F_LBTIPORIGA 175 - -// Definizione della classe dell'applicazione motore -class TMotore_application : public TRelation_application -{ - // Array di totalizzatori - real _piedi[79]; - - // Record array per la gestione delle righe - TRecord_array* _righe_rec; - - // Puntatore al profilo del documento caricato - TConfig* _pro; - - // Puntatore al nome, per evitare di ricrearlo se è uguale - TFilename* _proname; - - // Puntatore alla maschera di ricerca - TMask* _msk; - - // Puntatore alla maschera di modifica/inserimento ( dipende dal profilo ) - TMask* _msk1; - - // puntatore alla relazione - TRelation* _rel; - - // Puntatore allo sheet delle righe documento - TSheet_field* _sheet; - - - // Posizione delle colonne nello sheet - int _pos_cols[ MAX_COLUMNS ]; - // Numero di colonne realmente presenti sullo sheet - int _realcols; - - // Ridefinizione dei metodi virtuali - virtual bool user_create( ); - virtual bool user_destroy( ); - virtual TMask* get_mask(int mode); - virtual bool changing_mask(int mode); - virtual TRelation* get_relation( ) const { return _rel;} - - virtual int read( TMask& m ); - virtual bool remove( void ); - virtual int write(const TMask& m); - virtual int rewrite(const TMask& m); - - // Punti di ingresso per le funzioni utente - - // Funzioni da associare ad ogni procedura - int user_function( int index ); - - // Funzioni per il calcolo delle righe - real user_row_calculate( TRectype& row, int index ); - - void user_set_handler( int fieldid, int index ); - - long prossimo_numero( bool provv ); - int avanza_numero( bool provv ); - void get_edit_mask( void ); - void azzera_piedi( ); - - // Esegue, se c'è, la procedura utente relativa ad una certa operazione - int esegui_procedura( int operazione ); - -protected: - - // Procedure e funzioni per la gestione della maschera e dei files - void read_rdoc(TMask& m); - - // formato dipendente dallo sheet (sono le varie colonne) - void load_riga( TSheet_field& f, int numrig, TRectype& r ); - void store_riga( TSheet_field& f, int numrig, TRectype& r ); - - void save(TRelation* r) const; - void set_descr (int numrig, const char* descr); - void carica_righe_libere(int from = -1); - bool check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 _anno, TString16 _ndoc ); - - // Procedure e funzioni per la gestione degli stati - void setta_stato_corrente( int nuovostato ); - const char* nome_sezione( int op ); - int stato_corrente( ); - int stato_finale( int operazione ); - bool stato_valido( int stato, int operazione ); - void segnala_stato_non_valido( int operazione ); - TString& stati_validi( int operazione ){ return ( pro( ).get( "STATIVALIDI", nome_sezione( operazione ) ) );}; - - void calcola_riga( TRectype& rdoc ); - - // Handle che ritorna la maschera per le righe - static TMask * ss_getmask( int numriga, TMask& fullmask, bool destroy ); - - // Handler che gestisce la richiesta del tipo riga in inserimento - static bool ss_handler( TSheet_field& ss, int r, KEY key ); - - // Handler per la maschera di ricerca - static bool ndoc_handler(TMask_field& f, KEY key); - static bool num_handler(TMask_field& f, KEY key); - static bool tip_handler(TMask_field& f, KEY key); - - // Configurazione dello sheet dato il profilo - void configura_sheet( TSheet_field& sheet, TConfig& config ); - -public: - - // Funzioni di accesso alle variabili privste - - TRecord_array& righe_rec( ) { CHECK( _righe_rec, "Record array delle righe nullo!" ); return * _righe_rec; }; - TConfig& pro( ) { CHECK( _pro, "Profilo del documento nullo!" ); return *_pro; }; - TFilename& proname( ) { CHECK( _proname, "Nome del profilo nullo!" ); return *_proname; }; - TMask& query_mask( ) { CHECK( _msk, "Maschera di ricerca nulla!" ); return *_msk; }; - TMask& edit_mask( ) { CHECK( _msk1, "Maschera di modifica nulla!" ); return *_msk1; }; - TRelation& rel( ) { CHECK( _rel, "Relazione nulla!" ); return *_rel; }; - TSheet_field& sheet( ) { CHECK( _sheet, "Sheet nullo!" ); return *_sheet; }; - - // Operazione - - bool valida_operazione( int operazione ); - - TSheet_field& ss( ) const { return *_sheet; } - TMotore_application( ) { _pro = NULL; } - virtual ~TMotore_application( ) { if ( _pro ) delete _pro; } - virtual const char* get_next_key( ); - - int numero_colonne( ){ return _realcols; } - int posizione_colonna( int index ){ return _pos_cols[ index ]; } -}; - -HIDDEN TMotore_application& app( ) { return (TMotore_application&) main_app( ); } - - -int TMotore_application::user_function( int index ) -{ - switch( index ) - { - case 1: - break; - default: - yesnofatal_box( "Chiamata ad una procedura utente non definita: %d", index ); - return FALSE; - break; - }; - return NOERR; -}; - -// Funzione che dato il profilo di riga ottiene la maschera -// Serve per ottenere una maschera diversa per ogni riga -// Da migliorare, mettendo una cache - -TMask *TMotore_application::ss_getmask( int numriga, TMask& fullmask, bool destroy ) -{ - static TMask* m; - - if ( destroy ) - { - delete m; - return( NULL ); - } - else - { - TFilename nome_proriga( fullmask.get( 103 ) ); - nome_proriga.ext( "ini" ); - TConfig proriga( nome_proriga ); - m = new TMask( proriga.get( "MSK", "MAIN" ) ); - int numhandler = proriga.get_int( "NHANDLER", "HANDLERS" ); - for( int i = 1; i <= numhandler; i ++ ) - { - TString chiave; - chiave.format( "%d", i ); - TToken_string riga = proriga.get( chiave, "HANDLERS" ); - app().user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) ); - }; - return( m ); - } -} - -real TMotore_application::user_row_calculate( TRectype& r, int index ) -{ - switch( index ) - { - case 100 : - return ( f100( r ) ); - break; - default: - CHECK( FALSE, "Tentativo di chiamare una funzione di calcolo riga inesistente!" ); - return 0.0; - } -}; - -void TMotore_application::user_set_handler( int fieldid, int index ) -{ - switch( index ) - { - case 1: - edit_mask( ).set_handler( fieldid, ora_hndl ); - break; - case 2: - edit_mask( ).set_handler( fieldid, codcli_hndl ); - break; - case 3: - edit_mask( ).set_handler( fieldid, dummy_hndl ); - break; - default: - CHECK( FALSE, "Tentativo di installare un handler non definito" ); - break; - } - -}; - -bool TMotore_application::ss_handler( TSheet_field& ss, int r, KEY key ) -{ - if ( key == K_INS ) - { - TMask& m = *app( )._msk1; - TTable tabtr( "%TRI" ); - tabtr.zero( ); - tabtr.put( "CODTAB", m.get( F_LBTIPORIGA ) ); - tabtr.read( ); - TToken_string& riga = ss.row( r ); - riga.add( 1, 0 ); - riga.add( m.get( F_LBTIPORIGA ), 1 ); - TFilename nome_proriga( tabtr.get( "S4" ) ); - riga.add( nome_proriga, 2 ); - nome_proriga.ext( "ini" ); - TConfig pro( nome_proriga ); - int ncols = pro.get_int( "NCOLS", "COLUMNS" ); - // Disabilita tutte le colonne - for( int i = 1; i < app( ).numero_colonne( ); i ++ ) - ss.disable_cell ( ss.items( ) - 1, i ); - for( i = 1; i < ncols; i ++ ) - { - TString16 chiave; - chiave.format( "%d", i ); - int coltoenable = pro.get_int( chiave, "COLUMNS" ); - ss.enable_cell ( ss.items( ) - 1, app().posizione_colonna( coltoenable ) ); - }; - ss.force_update( ); - app( ).curr_mask( ).send_key( K_ROWEDIT, F_SHEET ); - // ss.on_key( K_SPACE ); - // ss.edit( ss.items( ) ); - /* - nome_proriga.ext( "ini" ); - TConfig proriga( nome_proriga ); - TMask *sm = new TMask( proriga.get( "MSK", "MAIN" ) ); - // int numhandler = proriga.get_int( "NHANDLER", "HANDLERS" ); - // for( int i = 1; i <= numhandler; i ++ ) - // { - // TString chiave; - // chiave.format( "%d", i ); - // TToken_string riga = proriga.get( chiave, "HANDLERS" ); - // app().user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) ); - // }; - sm->disable( DLG_DELREC ); - if ( sm->run( ) == K_ENTER ) - { - // Riga inserita, vai col disabilitare le colonne - delete sm; - ss.force_update( ); */ - return TRUE; - }; - return TRUE; -}; - -bool TMotore_application::num_handler( TMask_field& f, KEY key ) -{ - // Ottengo la maschera - TMask& m = f.mask( ); - - if (key == K_TAB && m.is_running( ) ) - { - // Se la numerazione non è specificata, - const TString16 value( m.get( F_CODNUM ) ); - if ( value.blank( ) ) - { - // Pulisce la descrizione - m.set(F_DESNUM, "" ); - // Pulisce i tipi di documento consentiti - m.set(F_TIPIDOCS, "" ); - // Pulisce il tipo di documento - m.set(F_TIPODOC, "" ); - return TRUE; - } - // Apro la tabella numerazioni - TTable tabnum( "NUM" ); - tabnum.zero( ); - tabnum.put( "CODTAB", value ); - if( tabnum.read( ) == NOERR ) - { - // Copio la descriozione della numerazione - m.set(F_DESNUM, tabnum.get("S0") ); - // Copio i tipi di documento validi per la numerazione - m.set(F_TIPIDOCS, tabnum.get("S2") ); - // Se per questa numerazione è abilitata le numerazione provvisoria - if ( tabnum.get_bool ( "B0" ) ) - { - // Setta di default la numerazione provvisoria - m.set( F_PROVV, "P" ); - // Abilita il campo per la selezione della numerazione - m.enable( F_PROVV ); - } - else // Altrimenti ... - { - // Setta la numerazione a definitiva - m.set( F_PROVV, "D" ); - // Disabilita il campo per la selezione della numerazione - m.disable( F_PROVV ); - }; - return TRUE; - } - message_box( "Numerazione non valida!" ); - return FALSE; - } - if (key == K_ENTER && m.is_running( ) ) - { // Se la numerazione non è specificata, - const TString16 value( m.get( F_CODNUM ) ); - if ( value.blank( ) ) - { - message_box( "Occorre una numerazione per inserire un documento!" ); - m.first_focus( F_NDOC ); - return FALSE; - } - } - return TRUE; -} - -bool TMotore_application::tip_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask( ); - if (key == K_TAB && m.is_running( ) ) - { - const TString16 value( m.get( F_TIPODOC ) ); - if ( value.blank( ) ) - { - // Pulisce il profilo - m.set(F_PROFILO, "" ); - return TRUE; - } - TString tipi_consentiti( m.get( F_TIPIDOCS ) ); - TString tipo( f.get( ) ); - if( tipi_consentiti.find( tipo ) % 4 ) - { message_box( "Tipo non valido per la numerazione selezionata!" ); - f.set( "" ); - return FALSE; } - TTable tabtip( "%TIP" ); - tabtip.read( ); - m.set(F_DESTIPODOC, tabtip.get("S0") ); - m.set(F_PROFILO, tabtip.get("S4") ); - }; - if (key == K_ENTER && m.is_running( ) ) - { TString tipo( f.get( ) ); - if ( ! tipo.blank( ) ) - { TTable tabtip( "%TIP" ); - tabtip.read( ); - m.set(F_PROFILO, tabtip.get("S4") ); - } - else - { message_box( "Occorre un tipo documento per inserire un documento!" ); - m.first_focus( F_TIPODOC ); - return FALSE; - } - } - return TRUE; -} - -bool TMotore_application::ndoc_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask( ); - if (key == K_TAB && m.is_running( ) ) - { TLocalisamfile& doc = app( ).rel( ).lfile( ); - doc.zero( ); - doc.put("CODNUM", m.get( F_CODNUM ) ); - doc.put("PROVV", m.get( F_PROVV ) ); - doc.put("ANNO", m.get( F_ANNO ) ); - doc.put("NDOC", f.get( ) ); - if ( doc.read( ) == NOERR ) - { m.set(F_TIPODOC, doc.get( "TIPODOC" ) ); - TTable tabtip( "%TIP" ); - tabtip.put( "CODTAB", doc.get( "TIPODOC" ) ); - tabtip.read( ); - m.set(F_PROFILO, tabtip.get("S4") ); - m.stop_run( K_AUTO_ENTER ); - } - } - return TRUE; -} - - -void TMotore_application::azzera_piedi( ) -{ - for ( int i = 0; i < 40; i++ ) - _piedi[ i ] = 0.0; -} -bool TMotore_application::changing_mask(int mode) -{ - static int lastmode = NO_MODE; - - const bool change = ( mode != lastmode ); - lastmode = mode; - return change; - -} - -void TMotore_application::configura_sheet( TSheet_field& sheet, TConfig& config ) -{ - _realcols = config.get_int( "NCOLS", "SHEET" ); - for( int i = 1; i <= _realcols; i ++ ) - { - TString col; - col.format( "%d", i ); - TToken_string sheet_col( config.get( col, "SHEET" ) ); - const TString descr( sheet_col.get( 1 ) ); - if ( ! descr.blank( ) ) - sheet.set_column_header( i, descr ); - TString size( sheet_col.get( 2 ) ); - if ( ! size.blank( ) ) - sheet.set_column_width( i, sheet_col.get_int( 2 ) ); - int coltomove = sheet_col.get_int( 0 ) - 1; - sheet.move_column( coltomove, i ); - _pos_cols[ coltomove ] = i; - }; - for ( int j = MAX_COLUMNS; j >= i - 1; j -- ) - sheet.delete_column( j ); -}; - -void TMotore_application::get_edit_mask( void ) -{ - TFilename fn; - - fn = query_mask( ).get( F_PROFILO ); - // query_mask( ).enable(DLG_NEWREC); - fn.ext( "ini" ); - fn.upper( ); - if ( _pro ) - { - if( (*_proname) == fn ) - return; - delete _pro; - }; - _pro = new TConfig( fn ); - _proname = new TFilename( fn ); - _proname->upper( ); - if ( _msk1 ) delete _msk1; - _msk1 = new TMask( pro( ).get( "MSKFILE", "MAIN" ) ); - // edit_mask( ).set( F_PROFILO, query_mask( ).get( F_PROFILO ) ); - edit_mask( ).set( F_DESNUM, query_mask( ).get( F_DESNUM ) ); - _sheet = &(TSheet_field &)edit_mask( ).field(F_SHEET); - sheet( ).set_notify( ss_handler ); - configura_sheet( *_sheet, *_pro ); - TList_field& listbox = ( TList_field& ) _msk1->field( F_LBTIPORIGA ); - const int numtr = app( ).pro( ).get_int( "NTIPIRIGA", "RIGHE" ); - TTable tabtr( "%TRI" ); - TToken_string keys( "" ), descrs( "" ); - for ( int i = 1; i <= numtr; i ++ ) - { - TString chiave; - TToken_string item; - chiave.format( "%d", i ); - tabtr.zero( ); - TString tiporiga( app( ).pro( ).get( chiave, "RIGHE" ) ); - tabtr.put( "CODTAB", tiporiga ); - if ( tabtr.read( ) == NOERR ) - { - keys.add( tabtr.get( "CODTAB" ) ); - descrs.add( tabtr.get( "S0" ) ); - } - else - { - yesnofatal_box( "Inserito un tipo di riga non valido (%s)", (const char *)tiporiga ); - } - } - listbox.replace_items( keys, descrs ); - sheet( ).set_getmask( ss_getmask ); - int numhandler = pro( ).get_int( "NHANDLER", "HANDLERS" ); - for( i = 1; i <= numhandler; i ++ ) - { - TString chiave; - chiave.format( "%d", i ); - TToken_string riga = pro( ).get( chiave, "HANDLERS" ); - user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) ); - }; -} - -TMask* TMotore_application::get_mask( int mode ) -{ - switch ( mode ) - { - case MODE_INS: - case MODE_MOD: - get_edit_mask( ); - edit_mask( ).enable( DLG_PRINT, ( mode == MODE_MOD ) ); - edit_mask( ).enable( 99, ( mode == MODE_MOD ) ); - return ( _msk1 ); - break; - default: - return _msk; - break; - }; -} - -void TMotore_application::set_descr(int i, const char * dfi) -{ - TToken_string& r = ss( ).row(i); - r.add(dfi, 0); -} - -void TMotore_application::carica_righe_libere(int from) -{ - if (from < 0) from = ss( ).items( ); - for (int i = from; i < 20; i++) - set_descr( i, "" ); - ss( ).force_update( ); -} - -const char* TMotore_application::get_next_key( ) -{ - TToken_string key; - TMask& m = curr_mask( ); - - TString value = m.get( F_CODNUM ); - if ( value.blank( ) ) - return NULL; - TTable tabnum( "NUM" ); - tabnum.zero( ); - tabnum.put( "CODTAB", value ); - if( tabnum.read( ) == NOERR ) - { - // Se per questa numerazione è abilitata le numerazione automatica - if( tabnum.get_bool ( "B1" ) ) - { - TLocalisamfile doc( LF_DOC ); - doc.zero( ); - doc.put( "CODNUM", value ); - doc.put( "ANNO", m.get( F_ANNO ) ); - doc.put( "NDOC", 9999999L ); - // Se per questa numerazione è abilitata le numerazione provvisoria - if( tabnum.get_bool ( "B0" ) ) - { - doc.put( "PROVV", "P" ); - } - else // Altrimenti ... - { - doc.put( "PROVV", "D" ); - }; - if( doc.read( _isgteq ) == NOERR ) - { - doc.prev( ); - } - long num = ( value == doc.get( "CODNUM" ) ) ? doc.get_long( "NDOC" ) : 0; - key.format( "%d|%d", F_NDOC, num + 1 ); - return key; - } - }; - return NULL; -} - -int TMotore_application::read(TMask& m) -{ - azzera_piedi( ); - int err = TRelation_application::read( m ); - if ( err == NOERR ) - { - TLocalisamfile& rdoc = rel( ).lfile(LF_RIGHEDOC); - TRectype r = rdoc.curr( ); - r.zero( ); - r.put( "CODNUM", m.get( F_CODNUM ) ); - r.put( "PROVV", m.get( F_PROVV ) ); - r.put( "ANNO", m.get( F_ANNO ) ); - r.put( "NDOC", m.get_long( F_NDOC ) ); - _righe_rec->read( r ); - - TSheet_field& f = (TSheet_field&) m.field( F_SHEET ); - f.destroy( ); - int last = _righe_rec->last_row( ); - for( int i = 1; i <= last; i ++ ) - { - TRectype &rec = _righe_rec->row( i, TRUE ); - load_riga( f, i - 1, rec ); - calcola_riga( rec ); - } - - TToken_string s( pro( ).get( "PROGPIEDE", "MAIN" ) ); - i = s.get_int( ); - int j = 0; - while( i != 0 ) - { - real strpiede( _piedi[ i ] ); - m.set( BASE_PIEDE + ( ++j ), strpiede.stringa( 15 ) ); - i = s.get_int( ); - } - } - return err; -} - -bool TMotore_application::check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 anno, TString16 ndoc ) -{ - return ( ( rdoc.get("CODNUM") == codnum ) && - ( rdoc.get("NDOC") == ndoc ) && - ( rdoc.get("ANNO" ) == anno ) && - ( rdoc.get_bool( "PROVV" ) == provv ) ); -} - -int TMotore_application::write(const TMask& m) -{ - int err; - if ( esegui_procedura( OP_NUOVO ) != NOERR ) - return FALSE; - err = NOERR; // avanza_numero( m.get_bool( F_PROVV ) ); - if ( err == NOERR ) - { - err = TRelation_application::write( m ); - if ( err == NOERR ) - { - TSheet_field& f = ss( ); - _righe_rec->destroy_rows( ); - if ( m.insert_mode( ) ) - _righe_rec->renum_key( "NRIGA", 1 ); - for ( int i = 0; i < f.items( ); i ++ ) - { - TToken_string& t = f.row( i ); - TRectype& rec = _righe_rec->row(i + 1, TRUE); - store_riga( f, i, rec ); - } - err = _righe_rec->write( ); - } - } - return err; -}; - -int TMotore_application::rewrite(const TMask& m) -{ - if ( ! valida_operazione( OP_MODIFICA ) ) - return FALSE; - int err = TRelation_application::rewrite( m ); - if ( err == NOERR ) - { - TSheet_field& f = ss( ); - _righe_rec->destroy_rows( ); - if ( m.insert_mode( ) ) - _righe_rec->renum_key( "NRIGA", 1 ); - for ( int i = 0; i < f.items( ); i ++ ) - { - TToken_string& t = f.row( i ); - TRectype& rec = _righe_rec->row(i + 1, TRUE); - store_riga( f, i, rec ); - } - err = _righe_rec->rewrite( ); - } - return err; -}; - - -// La funzione si trova in ve0100b - -long TMotore_application::prossimo_numero( bool provv ) -{ - long ret; - TTable tabnum( "NUM" ); - - tabnum.read( ); - if ( provv ) - ret = tabnum.get_long( "I0" ) + 1; - else - ret = tabnum.get_long( "I1" ) + 1; - return ( ret ); -}; - -int TMotore_application::avanza_numero( bool provv ) -{ - TTable tabnum( "NUM" ); - - int err = tabnum.read( ); - if ( err == NOERR ) - { - if ( provv ) - tabnum.put( "I0", tabnum.get_long( "I0" ) + 1 ); - else - tabnum.put( "I1", tabnum.get_long( "I1" ) + 1 ); - err = tabnum.rewrite( ); - } - return err; -}; - -bool TMotore_application::remove( void ) -{ - if ( ! valida_operazione( OP_CANCELLA ) ) - return FALSE; - return TRelation_application::remove && ( _righe_rec->remove( ) == NOERR ); -} - -void TMotore_application::load_riga( TSheet_field& f, int numrig, TRectype& r ) -{ - TToken_string& riga = f.row(numrig); - riga = r.get( "STATORIGA" ); - riga.add( r.get( "TIPORIGA" ) ); - riga.add( r.get( "PROFRIGA" ) ); - riga.add( r.get( "CODMAG" ) ); - riga.add( r.get( "CODART" ) ); - riga.add( r.get( "DESCR" ) ); - riga.add( r.get( "DESCLUNGA" ) ); - riga.add( r.get( "PREZZO" ) ); - riga.add( r.get( "UMQTA" ) ); - riga.add( r.get_real( "QTA" ).string(11) ); - riga.add( r.get( "QTAEVASA" ) ); - riga.add( r.get( "RIGAEVASA" ) ); - riga.add( r.get( "TARA" ) ); -} - -void TMotore_application::store_riga( TSheet_field& f, int numrig, TRectype& r ) -{ - TToken_string& riga = f.row(numrig); - - r.put( "CODNUM", edit_mask( ).get( F_CODNUM ) ); - r.put( "ANNO", edit_mask( ).get( F_ANNO ) ); - r.put( "PROVV", edit_mask( ).get( F_PROVV ) ); - r.put( "NDOC", edit_mask( ).get_long( F_NDOC ) ); - r.put( "STATORIGA", riga.get( 0 ) ); - r.put( "TIPORIGA", riga.get( 1 ) ); - r.put( "PROFRIGA", riga.get( 2 ) ); - r.put( "CODMAG", riga.get( 3 ) ); - r.put( "CODART", riga.get( 4 ) ); - r.put( "DESCR", riga.get( 5 ) ); - r.put( "DESCLUNGA", riga.get( 6 ) ); - r.put( "PREZZO", riga.get( 7 ) ); - r.put( "UMQTA", riga.get( 8 ) ); - r.put( "QTA", riga.get( 9 ) ); - r.put( "QTAEVASA", riga.get( 10 ) ); - r.put( "RIGAEVASA", riga.get( 11 ) ); - r.put( "TARA", riga.get( 12 ) ); -} - - -void TMotore_application::calcola_riga( TRectype& r ) -{ - TFilename proriganame( r.get("PROFRIGA") ); - proriganame.ext( "INI" ); - TConfig proriga( proriganame ); - TToken_string s(proriga.get("PROGPIEDE", "MAIN")); - int func = s.get_int( ); - while( func ) - { - _piedi[ s.get_int( ) ] += user_row_calculate( r, func ); - func = s.get_int( ); - } -} - - -bool TMotore_application::user_create( ) -{ - azzera_piedi( ); - _msk = new TMask("VE1000A"); - query_mask( ).set_handler( F_NDOC, ndoc_handler ); - query_mask( ).set_handler( F_CODNUM, num_handler ); - query_mask( ).set_handler( F_TIPODOC, tip_handler ); - // La maschera di inserimento/modifica per ora non la so! - // Viene letta dal profilo non appena trovato il record - _msk1 = NULL; - - // Metto in relazione testata e righe - _rel = new TRelation(LF_DOC); - rel( ).add( LF_RIGHEDOC,"CODNUM=CODNUM;ANNO=ANNO;PROVV=PROVV;NDOC=NDOC" ); - - // Inizializzo il Record_array - _righe_rec = new TRecord_array( LF_RIGHEDOC, "NRIGA", 1 ); - - // Inizializzo l'array con la posizione delle colonne - for( int i = 0; i <= MAX_COLUMNS; i ++ ) - _pos_cols[ i ] = -1; - return TRUE; -} - -bool TMotore_application::user_destroy( ) -{ - // Se è ancora allocata, distruggo la maschera di modifica - if ( _msk1 ) delete _msk1; - - // Distruggo la maschera di modifica - delete _msk; - - // Distruggo la relazione - delete _rel; - - // Distruggo il Record_array - delete _righe_rec; - - return TRUE; -} - -int TMotore_application::esegui_procedura( int operazione ) -{ - // Accesso unico alla chiamata di procedure tramite operazione - int index = ( int )pro( ).get_long( nome_sezione( operazione ), "MAIN" ); - if ( index ) - return ( user_function( index ) ); - return ( NOERR ); -} - - -bool TMotore_application::valida_operazione( int operazione ) -{ - if ( operazione != OP_NUOVO ) - { - if ( !stato_valido( stato_corrente( ), operazione ) ) - { - segnala_stato_non_valido( operazione ); - return FALSE; - } - }; - if ( esegui_procedura( operazione ) == NOERR ) - return FALSE; - return TRUE; -} - -const char * TMotore_application::nome_sezione( int op ) -{ - switch( op ) - { - case OP_NUOVO: - return "INSERIMENTO"; - break; - case OP_MODIFICA: - return "MODIFICA"; - break; - case OP_CANCELLA: - return "CANCELLAZIONE"; - break; - case OP_STAMPA: - return "STAMPA"; - break; - case OP_RAGGRUPPA: - return "RAGGRUPPA"; - break; - case OP_USER: - return "SPECIALE"; - break; - default: - CHECK( FALSE, "tentativo di ottenere il nome di una operazione inesistente!" ); - // Per evitare la warning - return ""; - break; - } -} - -int TMotore_application::stato_finale( int operazione ) -{ - TString s( pro( ).get( "STATOFINALE", nome_sezione( operazione ) ) ); - if( strcmp( s, "N" ) == 0 ) return NO_CHANGE_STATUS; - return ( atoi( s ) ); -}; - -bool TMotore_application::stato_valido( int stato, int operazione ) -{ -#ifdef _DEBUG - warning_box( "Controllo stati validi!\nStato corrente %d.\nStati validi %s.", stato_corrente( ), ( const char * )stati_validi( operazione ) ); -#endif - char p[2] = "0"; - TToken_string ret ( stati_validi( operazione ), ',' ); - p[0] += (char)stato; - return ( ret.get_pos( p ) != -1 ); -}; - -void TMotore_application::setta_stato_corrente( int nuovostato ) -{ - // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); - TString p; - p.format( "%d", nuovostato ); - - TLocalisamfile& doc = rel( ).lfile(LF_DOC); - - p[0] += (char)nuovostato; - doc.put("STATO", p); - doc.rewrite( ); - query_mask( ).set( F_STATO, p ); - // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); -} - -int TMotore_application::stato_corrente( ) -{ - int i = query_mask( ).get_int( F_STATO ); - return ( i == 0 ? NO_DOC_STATUS : i ); -}; - -void TMotore_application::segnala_stato_non_valido( int operazione ) -{ - TString messaggio; - switch( operazione ) - { - case OP_NUOVO: - // Sempre valido - break; - case OP_MODIFICA: - messaggio = "Il documento non si trova in uno stato valido per poter essere modificato!"; - break; - case OP_CANCELLA: - messaggio = "Il documento non si trova in uno stato valido per poter essere cancellato!"; - break; - case OP_STAMPA: - messaggio = "Il documento non si trova in uno stato valido per poter essere stampato!"; - break; - case OP_RAGGRUPPA: - messaggio = "Il documento non si trova in uno stato valido per poter essere raggruppato!"; - break; - case OP_USER: - messaggio = "Il documento non si trova in uno stato valido per effettuare la operazione richiesta!"; - break; - default: - CHECK( FALSE, "Tentativo di segnalare stato non valido di una operazione non esistente!" ); - break; - }; - messaggio << "\nStato corrente :%d.\nStati validi :%s."; - warning_box( messaggio, stato_corrente( ), ( const char * )stati_validi( operazione ) ); -}; - -int ve0100(int argc, char** argv) -{ - TMotore_application a; - - a.run(argc, argv, "Gestione documenti"); - return 0; -} +#include + +#ifndef __CHECKS_H +#include +#endif + +#ifndef __TABUTIL_H +#include +#endif + +#ifndef __BRWAPP_H +#include +#endif + +#ifndef __RELAPP_H +#include +#endif + +#ifndef __CONFIG_H +#include +#endif + +#ifndef __LFFILES_H +#include +#endif + +#ifndef __DEFMASK_H +#include "defmask.h" +#endif + +#ifndef __VEUML_H +#include "veuml.h" +#endif + +#ifndef __SHEET_H +#include +#endif + +#ifndef __REAL_H +#include +#endif + +#ifndef __MSKSHEET_H +#include +#endif + +#ifndef __VE0100_H +#include "ve0100.h" +#endif + +#ifndef __VE0100C_H +#include "ve0100C.h" +#endif + +#ifndef __VE0100D_H +#include "ve0100D.h" +#endif + +#ifndef __TCLIFOR_H +#include "tclifor.h" +#endif + +// Numero di colonne presenti sullo sheet totale +#define MAX_COLUMNS 22 + +#define F_LBTIPORIGA 175 + +// Definizione della classe dell'applicazione motore +class TMotore_application : public TRelation_application +{ + // Array di totalizzatori + real _piedi[79]; + + // Record array per la gestione delle righe + TRecord_array* _righe_rec; + + // Puntatore al profilo del documento caricato + TConfig* _pro; + + // Puntatore al nome, per evitare di ricrearlo se è uguale + TFilename* _proname; + + // Puntatore alla maschera di ricerca + TMask* _msk; + + // Puntatore alla maschera di modifica/inserimento ( dipende dal profilo ) + TMask* _msk1; + + // puntatore alla relazione + TRelation* _rel; + + // Puntatore allo sheet delle righe documento + TSheet_field* _sheet; + + // Ridefinizione dei metodi virtuali + virtual bool user_create( ); + virtual bool user_destroy( ); + virtual TMask* get_mask(int mode); + virtual bool changing_mask(int mode); + virtual TRelation* get_relation( ) const { return _rel;} + + virtual int read( TMask& m ); + virtual bool remove( void ); + virtual int write(const TMask& m); + virtual int rewrite(const TMask& m); + + // Punti di ingresso per le funzioni utente + + // Funzioni da associare ad ogni procedura + int user_function( int index ); + + // Funzioni per il calcolo delle righe + real user_row_calculate( TRectype& row, int index ); + + void user_set_handler( int fieldid, int index ); + + long prossimo_numero( bool provv ); + int avanza_numero( bool provv ); + void get_edit_mask( void ); + void azzera_piedi( ); + + // Esegue, se c'è, la procedura utente relativa ad una certa operazione + int esegui_procedura( int operazione ); + +protected: + + // Procedure e funzioni per la gestione della maschera e dei files + void read_rdoc(TMask& m); + + // formato dipendente dallo sheet (sono le varie colonne) + void load_riga( TSheet_field& f, int numrig, TRectype& r ); + void store_riga( TSheet_field& f, int numrig, TRectype& r ); + + void save(TRelation* r) const; + void set_descr (int numrig, const char* descr); + void carica_righe_libere(int from = -1); + bool check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 _anno, TString16 _ndoc ); + + // Procedure e funzioni per la gestione degli stati + void setta_stato_corrente( int nuovostato ); + const char* nome_sezione( int op ); + int stato_corrente( ); + int stato_finale( int operazione ); + bool stato_valido( int stato, int operazione ); + void segnala_stato_non_valido( int operazione ); + TString& stati_validi( int operazione ){ return ( pro( ).get( "STATIVALIDI", nome_sezione( operazione ) ) );}; + + void calcola_riga( TRectype& rdoc ); + + // Handle che ritorna la maschera per le righe + static TMask * ss_getmask( int numriga, TMask& fullmask, bool destroy ); + + // Handler che gestisce la richiesta del tipo riga in inserimento + static bool ss_handler( TSheet_field& ss, int r, KEY key ); + + // Handler per la maschera di ricerca + static bool ndoc_handler(TMask_field& f, KEY key); + static bool num_handler(TMask_field& f, KEY key); + static bool tip_handler(TMask_field& f, KEY key); + + // Configurazione dello sheet dato il profilo + void configura_sheet( TSheet_field& sheet, TConfig& config ); + +public: + + // Funzioni di accesso alle variabili privste + + TRecord_array& righe_rec( ) { CHECK( _righe_rec, "Record array delle righe nullo!" ); return * _righe_rec; }; + TConfig& pro( ) { CHECK( _pro, "Profilo del documento nullo!" ); return *_pro; }; + TFilename& proname( ) { CHECK( _proname, "Nome del profilo nullo!" ); return *_proname; }; + TMask& query_mask( ) { CHECK( _msk, "Maschera di ricerca nulla!" ); return *_msk; }; + TMask& edit_mask( ) { CHECK( _msk1, "Maschera di modifica nulla!" ); return *_msk1; }; + TRelation& rel( ) { CHECK( _rel, "Relazione nulla!" ); return *_rel; }; + TSheet_field& sheet( ) { CHECK( _sheet, "Sheet nullo!" ); return *_sheet; }; + + // Operazione + + bool valida_operazione( int operazione ); + + TSheet_field& ss( ) const { return *_sheet; } + TMotore_application( ) { _pro = NULL; } + virtual ~TMotore_application( ) { if ( _pro ) delete _pro; } + virtual const char* get_next_key( ); + +}; + +HIDDEN TMotore_application& app( ) { return (TMotore_application&) main_app( ); } + +int TMotore_application::user_function( int index ) +{ + switch( index ) + { + case 1: + break; + default: + yesnofatal_box( "Chiamata ad una procedura utente non definita: %d", index ); + return FALSE; + break; + }; + return NOERR; +}; + +// Funzione che dato il profilo di riga ottiene la maschera +// Serve per ottenere una maschera diversa per ogni riga +// Da migliorare, mettendo una cache + +TMask *TMotore_application::ss_getmask( int numriga, TMask& fullmask, bool destroy ) +{ + static TMask* m; + + if ( destroy ) + { + delete m; + return( NULL ); + } + else + { + TFilename nome_proriga( fullmask.get( 103 ) ); + nome_proriga.ext( "ini" ); + TConfig proriga( nome_proriga ); + m = new TMask( proriga.get( "MSK", "MAIN" ) ); + int numhandler = proriga.get_int( "NHANDLER", "HANDLERS" ); + for( int i = 1; i <= numhandler; i ++ ) + { + TString chiave; + chiave.format( "%d", i ); + TToken_string riga = proriga.get( chiave, "HANDLERS" ); + app().user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) ); + }; + return( m ); + } +} + +real TMotore_application::user_row_calculate( TRectype& r, int index ) +{ + switch( index ) + { + case 100 : + return ( f100( r ) ); + break; + default: + CHECK( FALSE, "Tentativo di chiamare una funzione di calcolo riga inesistente!" ); + return 0.0; + } +}; + +void TMotore_application::user_set_handler( int fieldid, int index ) +{ + switch( index ) + { + case 1: + edit_mask( ).set_handler( fieldid, ora_hndl ); + break; + case 2: + edit_mask( ).set_handler( fieldid, codcli_hndl ); + break; + case 3: + edit_mask( ).set_handler( fieldid, dummy_hndl ); + break; + default: + CHECK( FALSE, "Tentativo di installare un handler non definito" ); + break; + } + +}; + +bool TMotore_application::ss_handler( TSheet_field& ss, int r, KEY key ) +{ + if ( key == K_INS ) // Inserimento + { + TMask& m = *app( )._msk1; + TTable tabtr( "%TRI" ); + tabtr.zero( ); + tabtr.put( "CODTAB", m.get( F_LBTIPORIGA ) ); + tabtr.read( ); + TToken_string& riga = ss.row( r ); + riga.add( 1, 0 ); + riga.add( m.get( F_LBTIPORIGA ), 1 ); + riga.add( tabtr.get( "S4" ), 2 ); + return TRUE; + }; + if ( key == K_CTRL + K_INS ) // Dopo inserimento + { + TMask& m = *app( )._msk1; + TTable tabtr( "%TRI" ); + tabtr.zero( ); + tabtr.put( "CODTAB", m.get( F_LBTIPORIGA ) ); + tabtr.read( ); + TToken_string& riga = ss.row( r ); + TFilename nome_proriga( tabtr.get( "S4" ) ); + nome_proriga.ext( "ini" ); + TConfig pro( nome_proriga ); + int ncols = pro.get_int( "NCOLS", "COLUMNS" ); + // Disabilita tutte le colonne + for( int i = 1; i <= MAX_COLUMNS; i ++ ) + ss.disable_cell ( ss.items( ) - 1, i ); + // Abilita le colonne indicate nel profilo della riga + for( i = 1; i <= ncols; i ++ ) + { + TString16 chiave; + chiave.format( "%d", i ); + int coltoenable = pro.get_int( chiave, "COLUMNS" ); + ss.enable_cell ( ss.items( ) - 1, coltoenable - 1 ); + }; + ss.force_update( ); + app( ).curr_mask( ).send_key( K_ROWEDIT, F_SHEET ); + return TRUE; + }; + return TRUE; +}; + +bool TMotore_application::num_handler( TMask_field& f, KEY key ) +{ + // Ottengo la maschera + TMask& m = f.mask( ); + + if (key == K_TAB && m.is_running( ) ) + { + // Se la numerazione non è specificata, + const TString16 value( m.get( F_CODNUM ) ); + if ( value.blank( ) ) + { + // Pulisce la descrizione + m.set(F_DESNUM, "" ); + // Pulisce i tipi di documento consentiti + m.set(F_TIPIDOCS, "" ); + // Pulisce il tipo di documento + m.set(F_TIPODOC, "" ); + return TRUE; + } + // Apro la tabella numerazioni + TTable tabnum( "NUM" ); + tabnum.zero( ); + tabnum.put( "CODTAB", value ); + if( tabnum.read( ) == NOERR ) + { + // Copio la descriozione della numerazione + m.set(F_DESNUM, tabnum.get("S0") ); + // Copio i tipi di documento validi per la numerazione + const TString tipidocs( tabnum.get("S2") ); + m.set(F_TIPIDOCS, tipidocs ); + // Propone il primo tipo di documento come default + m.set(F_TIPODOC, tipidocs.left( 4 ) ); + + // Se per questa numerazione è abilitata le numerazione provvisoria + if ( tabnum.get_bool ( "B0" ) ) + { + // Setta di default la numerazione provvisoria + m.set( F_PROVV, "P" ); + // Abilita il campo per la selezione della numerazione + m.enable( F_PROVV ); + } + else // Altrimenti ... + { + // Setta la numerazione a definitiva + m.set( F_PROVV, "D" ); + // Disabilita il campo per la selezione della numerazione + m.disable( F_PROVV ); + }; + return TRUE; + } + message_box( "Numerazione non valida!" ); + return FALSE; + } + if (key == K_ENTER && m.is_running( ) ) + { // Se la numerazione non è specificata, + const TString16 value( m.get( F_CODNUM ) ); + if ( value.blank( ) ) + { + message_box( "Occorre una numerazione per inserire un documento!" ); + m.first_focus( F_NDOC ); + return FALSE; + } + } + return TRUE; +} + +bool TMotore_application::tip_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask( ); + if (key == K_TAB && m.is_running( ) ) + { + const TString16 value( m.get( F_TIPODOC ) ); + if ( value.blank( ) ) + { + // Pulisce il profilo + m.set(F_PROFILO, "" ); + return TRUE; + } + TString tipi_consentiti( m.get( F_TIPIDOCS ) ); + TString16 tipo( f.get( ) ); + tipo.trim( ); + bool tipo_valido = FALSE; + for ( int i = 0; i < 10; i ++ ) + { + TString16 curtipo( tipi_consentiti.mid( i * 4, 4 ) ); + curtipo.trim( ); + if( curtipo == tipo ) + { + tipo_valido = TRUE; + break; + } + } + if( ! tipo_valido ) + { + message_box( "Tipo non valido per la numerazione selezionata!" ); + f.set( "" ); + return FALSE; + } + TTable tabtip( "%TIP" ); + tabtip.read( ); + m.set(F_DESTIPODOC, tabtip.get("S0") ); + m.set(F_PROFILO, tabtip.get("S4") ); + } + if (key == K_ENTER && m.is_running( ) ) + { TString tipo( f.get( ) ); + if ( ! tipo.blank( ) ) + { TTable tabtip( "%TIP" ); + tabtip.read( ); + m.set(F_PROFILO, tabtip.get("S4") ); + } + else + { message_box( "Occorre un tipo documento per inserire un documento!" ); + m.first_focus( F_TIPODOC ); + return FALSE; + } + } + return TRUE; +} + +bool TMotore_application::ndoc_handler(TMask_field& f, KEY key) +{ + TMask& m = f.mask( ); + if (key == K_TAB && m.is_running( ) ) + { TLocalisamfile& doc = app( ).rel( ).lfile( ); + doc.zero( ); + doc.put("CODNUM", m.get( F_CODNUM ) ); + doc.put("PROVV", m.get( F_PROVV ) ); + doc.put("ANNO", m.get( F_ANNO ) ); + doc.put("NDOC", f.get( ) ); + if ( doc.read( ) == NOERR ) + { m.set(F_TIPODOC, doc.get( "TIPODOC" ) ); + TTable tabtip( "%TIP" ); + tabtip.put( "CODTAB", doc.get( "TIPODOC" ) ); + tabtip.read( ); + m.set(F_PROFILO, tabtip.get("S4") ); + m.stop_run( K_AUTO_ENTER ); + } + } + return TRUE; +} + + +void TMotore_application::azzera_piedi( ) +{ + for ( int i = 0; i < 40; i++ ) + _piedi[ i ] = 0.0; +} +bool TMotore_application::changing_mask(int mode) +{ + static int lastmode = NO_MODE; + + const bool change = ( mode != lastmode ); + lastmode = mode; + return change; + +} + +void TMotore_application::configura_sheet( TSheet_field& sheet, TConfig& config ) +{ + int ncols = config.get_int( "NCOLS", "SHEET" ); + for( int i = 1; i <= ncols; i ++ ) + { + TString col; + col.format( "%d", i ); + TToken_string sheet_col( config.get( col, "SHEET" ) ); + const TString descr( sheet_col.get( 1 ) ); + if ( ! descr.blank( ) ) + sheet.set_column_header( i, descr ); + TString size( sheet_col.get( 2 ) ); + if ( ! size.blank( ) ) + sheet.set_column_width( i, sheet_col.get_int( 2 ) ); + int coltomove = sheet_col.get_int( 0 ) - 1; + sheet.move_column( coltomove, i ); + }; + for ( int j = MAX_COLUMNS; j >= i - 1; j -- ) + sheet.delete_column( j ); +}; + +void TMotore_application::get_edit_mask( void ) +{ + TFilename fn; + + fn = query_mask( ).get( F_PROFILO ); + // query_mask( ).enable(DLG_NEWREC); + fn.ext( "ini" ); + fn.upper( ); + if ( _pro ) + { + if( (*_proname) == fn ) + return; + delete _pro; + }; + _pro = new TConfig( fn ); + _proname = new TFilename( fn ); + _proname->upper( ); + if ( _msk1 ) delete _msk1; + _msk1 = new TMask( pro( ).get( "MSKFILE", "MAIN" ) ); + // edit_mask( ).set( F_PROFILO, query_mask( ).get( F_PROFILO ) ); + edit_mask( ).set( F_DESNUM, query_mask( ).get( F_DESNUM ) ); + _sheet = &(TSheet_field &)edit_mask( ).field(F_SHEET); + sheet( ).set_notify( ss_handler ); + configura_sheet( *_sheet, *_pro ); + TList_field& listbox = ( TList_field& ) _msk1->field( F_LBTIPORIGA ); + const int numtr = app( ).pro( ).get_int( "NTIPIRIGA", "RIGHE" ); + TTable tabtr( "%TRI" ); + TToken_string keys( "" ), descrs( "" ); + for ( int i = 1; i <= numtr; i ++ ) + { + TString chiave; + TToken_string item; + chiave.format( "%d", i ); + tabtr.zero( ); + TString tiporiga( app( ).pro( ).get( chiave, "RIGHE" ) ); + tabtr.put( "CODTAB", tiporiga ); + if ( tabtr.read( ) == NOERR ) + { + keys.add( tabtr.get( "CODTAB" ) ); + descrs.add( tabtr.get( "S0" ) ); + } + else + { + yesnofatal_box( "Inserito un tipo di riga non valido (%s)", (const char *)tiporiga ); + } + } + listbox.replace_items( keys, descrs ); + sheet( ).set_getmask( ss_getmask ); + int numhandler = pro( ).get_int( "NHANDLER", "HANDLERS" ); + for( i = 1; i <= numhandler; i ++ ) + { + TString chiave; + chiave.format( "%d", i ); + TToken_string riga = pro( ).get( chiave, "HANDLERS" ); + user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) ); + }; +} + +TMask* TMotore_application::get_mask( int mode ) +{ + switch ( mode ) + { + case MODE_INS: + case MODE_MOD: + get_edit_mask( ); + edit_mask( ).enable( DLG_PRINT, ( mode == MODE_MOD ) ); + edit_mask( ).enable( 99, ( mode == MODE_MOD ) ); + return ( _msk1 ); + break; + default: + return _msk; + break; + }; +} + +void TMotore_application::set_descr(int i, const char * dfi) +{ + TToken_string& r = ss( ).row(i); + r.add(dfi, 0); +} + +void TMotore_application::carica_righe_libere(int from) +{ + if (from < 0) from = ss( ).items( ); + for (int i = from; i < 20; i++) + set_descr( i, "" ); + ss( ).force_update( ); +} + +const char* TMotore_application::get_next_key( ) +{ + TToken_string key; + TMask& m = curr_mask( ); + + TString value = m.get( F_CODNUM ); + if ( value.blank( ) ) + return NULL; + TTable tabnum( "NUM" ); + tabnum.zero( ); + tabnum.put( "CODTAB", value ); + if( tabnum.read( ) == NOERR ) + { + // Se per questa numerazione è abilitata le numerazione automatica + if( tabnum.get_bool ( "B1" ) ) + { + TLocalisamfile doc( LF_DOC ); + doc.zero( ); + doc.put( "CODNUM", value ); + doc.put( "ANNO", m.get( F_ANNO ) ); + doc.put( "NDOC", 9999999L ); + // Se per questa numerazione è abilitata le numerazione provvisoria + if( tabnum.get_bool ( "B0" ) ) + { + doc.put( "PROVV", "P" ); + } + else // Altrimenti ... + { + doc.put( "PROVV", "D" ); + }; + if( doc.read( _isgteq ) == NOERR ) + { + doc.prev( ); + } + long num = ( value == doc.get( "CODNUM" ) ) ? doc.get_long( "NDOC" ) : 0; + key.format( "%d|%d", F_NDOC, num + 1 ); + return key; + } + }; + return NULL; +} + +int TMotore_application::read(TMask& m) +{ + azzera_piedi( ); + int err = TRelation_application::read( m ); + if ( err == NOERR ) + { + TLocalisamfile& rdoc = rel( ).lfile(LF_RIGHEDOC); + TRectype r = rdoc.curr( ); + r.zero( ); + r.put( "CODNUM", m.get( F_CODNUM ) ); + r.put( "PROVV", m.get( F_PROVV ) ); + r.put( "ANNO", m.get( F_ANNO ) ); + r.put( "NDOC", m.get_long( F_NDOC ) ); + _righe_rec->read( r ); + + TSheet_field& f = (TSheet_field&) m.field( F_SHEET ); + f.destroy( ); + int last = _righe_rec->last_row( ); + for( int i = 1; i <= last; i ++ ) + { + TRectype &rec = _righe_rec->row( i, TRUE ); + load_riga( f, i - 1, rec ); + calcola_riga( rec ); + } + + TToken_string s( pro( ).get( "PROGPIEDE", "MAIN" ) ); + i = s.get_int( ); + int j = 0; + while( i != 0 ) + { + real strpiede( _piedi[ i ] ); + m.set( BASE_PIEDE + ( ++j ), strpiede.stringa( 15 ) ); + i = s.get_int( ); + } + } + return err; +} + +bool TMotore_application::check_key( TLocalisamfile& rdoc, TString16 codnum, bool provv, TString16 anno, TString16 ndoc ) +{ + return ( ( rdoc.get("CODNUM") == codnum ) && + ( rdoc.get("NDOC") == ndoc ) && + ( rdoc.get("ANNO" ) == anno ) && + ( rdoc.get_bool( "PROVV" ) == provv ) ); +} + +int TMotore_application::write(const TMask& m) +{ + int err; + if ( esegui_procedura( OP_NUOVO ) != NOERR ) + return FALSE; + err = NOERR; // avanza_numero( m.get_bool( F_PROVV ) ); + if ( err == NOERR ) + { + err = TRelation_application::write( m ); + if ( err == NOERR ) + { + TSheet_field& f = ss( ); + _righe_rec->destroy_rows( ); + if ( m.insert_mode( ) ) + _righe_rec->renum_key( "NRIGA", 1 ); + for ( int i = 0; i < f.items( ); i ++ ) + { + TToken_string& t = f.row( i ); + TRectype& rec = _righe_rec->row(i + 1, TRUE); + store_riga( f, i, rec ); + } + err = _righe_rec->write( ); + } + } + return err; +}; + +int TMotore_application::rewrite(const TMask& m) +{ + if ( ! valida_operazione( OP_MODIFICA ) ) + return FALSE; + int err = TRelation_application::rewrite( m ); + if ( err == NOERR ) + { + TSheet_field& f = ss( ); + _righe_rec->destroy_rows( ); + if ( m.insert_mode( ) ) + _righe_rec->renum_key( "NRIGA", 1 ); + for ( int i = 0; i < f.items( ); i ++ ) + { + TToken_string& t = f.row( i ); + TRectype& rec = _righe_rec->row(i + 1, TRUE); + store_riga( f, i, rec ); + } + err = _righe_rec->rewrite( ); + } + return err; +}; + + +// La funzione si trova in ve0100b + +long TMotore_application::prossimo_numero( bool provv ) +{ + long ret; + TTable tabnum( "NUM" ); + + tabnum.read( ); + if ( provv ) + ret = tabnum.get_long( "I0" ) + 1; + else + ret = tabnum.get_long( "I1" ) + 1; + return ( ret ); +}; + +int TMotore_application::avanza_numero( bool provv ) +{ + TTable tabnum( "NUM" ); + + int err = tabnum.read( ); + if ( err == NOERR ) + { + if ( provv ) + tabnum.put( "I0", tabnum.get_long( "I0" ) + 1 ); + else + tabnum.put( "I1", tabnum.get_long( "I1" ) + 1 ); + err = tabnum.rewrite( ); + } + return err; +}; + +bool TMotore_application::remove( void ) +{ + if ( ! valida_operazione( OP_CANCELLA ) ) + return FALSE; + return TRelation_application::remove && ( _righe_rec->remove( ) == NOERR ); +} + +void TMotore_application::load_riga( TSheet_field& f, int numrig, TRectype& r ) +{ + TToken_string& riga = f.row(numrig); + riga = r.get( "STATORIGA" ); + riga.add( r.get( "TIPORIGA" ) ); + riga.add( r.get( "PROFRIGA" ) ); + riga.add( r.get( "CODMAG" ) ); + riga.add( r.get( "CODART" ) ); + riga.add( r.get( "DESCR" ) ); + riga.add( r.get( "DESCLUNGA" ) ); + riga.add( r.get( "PREZZO" ) ); + riga.add( r.get( "UMQTA" ) ); + riga.add( r.get_real( "QTA" ).string(11) ); + riga.add( r.get( "QTAEVASA" ) ); + riga.add( r.get( "RIGAEVASA" ) ); + riga.add( r.get( "TARA" ) ); +} + +void TMotore_application::store_riga( TSheet_field& f, int numrig, TRectype& r ) +{ + TToken_string& riga = f.row(numrig); + + r.put( "CODNUM", edit_mask( ).get( F_CODNUM ) ); + r.put( "ANNO", edit_mask( ).get( F_ANNO ) ); + r.put( "PROVV", edit_mask( ).get( F_PROVV ) ); + r.put( "NDOC", edit_mask( ).get_long( F_NDOC ) ); + r.put( "STATORIGA", riga.get( 0 ) ); + r.put( "TIPORIGA", riga.get( 1 ) ); + r.put( "PROFRIGA", riga.get( 2 ) ); + r.put( "CODMAG", riga.get( 3 ) ); + r.put( "CODART", riga.get( 4 ) ); + r.put( "DESCR", riga.get( 5 ) ); + r.put( "DESCLUNGA", riga.get( 6 ) ); + r.put( "PREZZO", riga.get( 7 ) ); + r.put( "UMQTA", riga.get( 8 ) ); + r.put( "QTA", riga.get( 9 ) ); + r.put( "QTAEVASA", riga.get( 10 ) ); + r.put( "RIGAEVASA", riga.get( 11 ) ); + r.put( "TARA", riga.get( 12 ) ); +} + + +void TMotore_application::calcola_riga( TRectype& r ) +{ + TFilename proriganame( r.get("PROFRIGA") ); + proriganame.ext( "INI" ); + TConfig proriga( proriganame ); + TToken_string s(proriga.get("PROGPIEDE", "MAIN")); + int func = s.get_int( ); + while( func ) + { + _piedi[ s.get_int( ) ] += user_row_calculate( r, func ); + func = s.get_int( ); + } +} + + +bool TMotore_application::user_create( ) +{ + TCliFor C; + C.load( 'C', 1 ); + TString s; + TString s1( C.get( LF_CLIFO, "RAGSOC" ) ); + TString s2( C.get( LF_CFVEN, "CODINDDOC" ) ); + s.format( "%s:%d", ( const char * )s1, atoi( s2 ) ); + message_box( ( const char * ) s ); + + azzera_piedi( ); + _msk = new TMask("VE1000A"); + query_mask( ).set_handler( F_NDOC, ndoc_handler ); + query_mask( ).set_handler( F_CODNUM, num_handler ); + query_mask( ).set_handler( F_TIPODOC, tip_handler ); + // La maschera di inserimento/modifica per ora non la so! + // Viene letta dal profilo non appena trovato il record + _msk1 = NULL; + + // Metto in relazione testata e righe + _rel = new TRelation(LF_DOC); + rel( ).add( LF_RIGHEDOC,"CODNUM=CODNUM|ANNO=ANNO|PROVV=PROVV|NDOC=NDOC" ); + + // Inizializzo il Record_array + _righe_rec = new TRecord_array( LF_RIGHEDOC, "NRIGA", 1 ); + + return TRUE; +} + +bool TMotore_application::user_destroy( ) +{ + // Se è ancora allocata, distruggo la maschera di modifica + if ( _msk1 ) delete _msk1; + + // Distruggo la maschera di modifica + delete _msk; + + // Distruggo la relazione + delete _rel; + + // Distruggo il Record_array + delete _righe_rec; + + return TRUE; +} + +int TMotore_application::esegui_procedura( int operazione ) +{ + // Accesso unico alla chiamata di procedure tramite operazione + int index = ( int )pro( ).get_long( nome_sezione( operazione ), "MAIN" ); + if ( index ) + return ( user_function( index ) ); + return ( NOERR ); +} + + +bool TMotore_application::valida_operazione( int operazione ) +{ + if ( operazione != OP_NUOVO ) + { + if ( !stato_valido( stato_corrente( ), operazione ) ) + { + segnala_stato_non_valido( operazione ); + return FALSE; + } + }; + if ( esegui_procedura( operazione ) == NOERR ) + return FALSE; + return TRUE; +} + +const char * TMotore_application::nome_sezione( int op ) +{ + switch( op ) + { + case OP_NUOVO: + return "INSERIMENTO"; + break; + case OP_MODIFICA: + return "MODIFICA"; + break; + case OP_CANCELLA: + return "CANCELLAZIONE"; + break; + case OP_STAMPA: + return "STAMPA"; + break; + case OP_RAGGRUPPA: + return "RAGGRUPPA"; + break; + case OP_USER: + return "SPECIALE"; + break; + default: + CHECK( FALSE, "tentativo di ottenere il nome di una operazione inesistente!" ); + // Per evitare la warning + return ""; + break; + } +} + +int TMotore_application::stato_finale( int operazione ) +{ + TString s( pro( ).get( "STATOFINALE", nome_sezione( operazione ) ) ); + if( strcmp( s, "N" ) == 0 ) return NO_CHANGE_STATUS; + return ( atoi( s ) ); +}; + +bool TMotore_application::stato_valido( int stato, int operazione ) +{ +#ifdef _DEBUG + warning_box( "Controllo stati validi!\nStato corrente %d.\nStati validi %s.", stato_corrente( ), ( const char * )stati_validi( operazione ) ); +#endif + char p[2] = "0"; + TToken_string ret ( stati_validi( operazione ), ',' ); + p[0] += (char)stato; + return ( ret.get_pos( p ) != -1 ); +}; + +void TMotore_application::setta_stato_corrente( int nuovostato ) +{ + // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); + TString p; + p.format( "%d", nuovostato ); + + TLocalisamfile& doc = rel( ).lfile(LF_DOC); + + p[0] += (char)nuovostato; + doc.put("STATO", p); + doc.rewrite( ); + query_mask( ).set( F_STATO, p ); + // warning_box( "Settaggio stati validi!\nStato corrente %s.\nStati validi %s.\nStato finale %s.", stato_corrente( ), stati_validi( operazione ), stato_finale( operazione ) ); +} + +int TMotore_application::stato_corrente( ) +{ + int i = query_mask( ).get_int( F_STATO ); + return ( i == 0 ? NO_DOC_STATUS : i ); +}; + +void TMotore_application::segnala_stato_non_valido( int operazione ) +{ + TString messaggio; + switch( operazione ) + { + case OP_NUOVO: + // Sempre valido + break; + case OP_MODIFICA: + messaggio = "Il documento non si trova in uno stato valido per poter essere modificato!"; + break; + case OP_CANCELLA: + messaggio = "Il documento non si trova in uno stato valido per poter essere cancellato!"; + break; + case OP_STAMPA: + messaggio = "Il documento non si trova in uno stato valido per poter essere stampato!"; + break; + case OP_RAGGRUPPA: + messaggio = "Il documento non si trova in uno stato valido per poter essere raggruppato!"; + break; + case OP_USER: + messaggio = "Il documento non si trova in uno stato valido per effettuare la operazione richiesta!"; + break; + default: + CHECK( FALSE, "Tentativo di segnalare stato non valido di una operazione non esistente!" ); + break; + }; + messaggio << "\nStato corrente :%d.\nStati validi :%s."; + warning_box( messaggio, stato_corrente( ), ( const char * )stati_validi( operazione ) ); +}; + +int ve0100(int argc, char** argv) +{ + TMotore_application a; + + a.run(argc, argv, "Gestione documenti"); + return 0; +} diff --git a/ve/ve0300.cpp b/ve/ve0300.cpp index c20648162..6e40bcdb4 100755 --- a/ve/ve0300.cpp +++ b/ve/ve0300.cpp @@ -1,1138 +1,1170 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - - "Compilatore di profili" per la gestione vendite. - Considerando: - - Profilo documento - - Configurazione vendite per la ditta - - Condizioni atmosferiche - genera le maschere appropriate. - Accetta sulla riga di comando il nome del profilo documento per cui deve generare - la maschera. Il nome del file .MSK viene dedotto dal profilo documento stesso. - - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef __CHECKS_H -#include -#endif - -#ifndef __FSTREAM_H -#include -#endif - -#ifndef __SCANNER_H -#include -#endif - -#ifndef __CONFIG_H -#include -#endif - -#ifndef __APPLICATION_H -#include -#endif - -#ifndef __UTILITY_H -#include -#endif - -#ifndef __DEFMASK_H -#include -#endif - -#ifndef __VE0100_H -#include "ve0100.h" -#endif - -#ifndef __VEUML_H -#include "veuml.h" -#endif - -// Costanti simboliche per i tipi di campo - -#define T_DATE 1 -#define T_STRING 2 -#define T_NUMBER 3 -#define T_BOOLEAN 4 -#define T_LISTBOX 5 -#define T_MEMO 6 -#define T_GROUPBOX 7 - -// Costanti simboliche per flags del campo - -#define FS_HIDDEN 0 -#define FS_DISABLED 1 -#define FS_NORMAL 2 -#define FS_REQUIRED 3 - -// Significato delle colonne nella tabella _tab0300b -#define B_NOME 0 -#define B_MSKTYPE 1 -#define B_MSKSIZE 2 -#define B_DESCR 3 -#define B_WIDTH 4 - -// Significato dei campi nel profilo del documento -#define P_STATO 0 -#define P_PROMPT 1 -#define P_HELP 2 -#define P_WARNING 3 - - -// Numero massimo di linee per pagina - -#define MAX_LINES_PER_PAGE 17 -#define MASK_FIRST_LINE 6 - -class TMaschera : public TObject -{ - -private: - - // Linea corrente - int _curline; - - // Pagina corrente - int _curpage; - -public: - - void advance_line( ){ _curline ++; }; - - // Genera una serie di righe uguali per funzione ( DISPLAY, ecc. ) - void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); - - // Crea un controllo del tipo specificato - void control( const int type, const int id = DLG_NULL, const int size = -1 ); - - // CHECKTYPE - void check( const int i ); - - // PAGE - void pagina( const int i ){ _out << "PA \"Pagina " << i << "\" 11 60 14\n"; }; - - // PROMPT - void prompt( const int x, const int y, const TString& s = "" ){ _out << "PR " << x << " " << y << " \"" << s << "\"\n"; }; - - // BEGIN - void begin( void ) { outline ( "BE" ); }; - - // END - void end( void ) { outline ( "EN" ); }; - - // ENDMASK - void endmask( void ) { outline ( "ENDMASK" ); }; - - // FLAG - void flag( const TString& s ) { _out << "FLAG \"" << s << "\"\n"; }; - - // HELP - void help( const TString& s ) { _out << "HE \"" << s << "\"\n"; }; - - // WARNING - void warning( const TString& s ) { _out << "WA \"" << s << "\"\n"; }; - - // GROUP - void group( const int g ) { _out << "GR " << g << "\n"; }; - - // FIELD - void field( const TString& s ) { outline( s, "FI "); }; - - // ITEM - void item( const TString& s ); - - // MESSAGE - void message( const TString& s ) { outline( s, "ME "); }; - - // USE - void use( const TString& s ){ outline( s, "US " ); }; - - // DISPLAY - void display( const TString& s ){ outline( s, "DI " ); }; - - // INPUT - void input( const TString& s ){ outline( s, "IN " ); }; - - // OUTPUT - void output( const TString& s ){ outline( s, "OU " ); }; - - // Funzioni per la lettura/scrittura di CURPAGE - int page( ) { return _curpage; }; - void page( const int i ){ _curpage = i; }; - - // Funzioni per la lettura/scrittura di CURLINE - int line( ) { return _curline; }; - void line( const int i ){ _curline = i; }; - - // Costruttore, vuole il nome del file .INI - TMaschera( const TFilename outfile ); - - // Vero se la pagina è aperta - bool _pageopen; - - // File .MSK di output - ofstream _out; - - -}; - - -TMaschera::TMaschera( const TFilename outfile ) : _out( outfile ) -{ - _curline = 1; - _curpage = 1; - _pageopen = FALSE; - bool _groupopen = FALSE; -} - -void TMaschera::outline( const TString& s, const TString& prefix, const char sep ) -{ - if ( s.left( 1 ) == "@" ) - _out << "CO " << prefix << s.mid( 1 ) << "\n"; - else - { TToken_string u( s, sep ); - for ( int i = 0; i < u.items(); i ++ ) - _out << prefix << u.get( i ) << "\n"; - } -} - -void TMaschera::check( const int i ) -{ - switch( i ) - { - case FS_REQUIRED: - outline ( "CH REQUIRED" ); - break; - default: - outline ( "CH NORMAL" ); - break; - } -} - -void TMaschera::control( const int type, const int id, const int size ) -{ - switch ( type ) - { case T_DATE : _out << "DA"; break; - case T_STRING : _out << "ST"; break; - case T_BOOLEAN : _out << "BO"; break; - case T_NUMBER : _out << "NU"; break; - case T_LISTBOX : _out << "LI"; break; - case T_MEMO : _out << "ME"; break; - case T_GROUPBOX : _out << "GR"; break; - }; - _out << " " << id; - if ( size > 0 ) - { if ( size > 100 ) - _out << " " << ( int )( size / 100 ) << " " << ( size % 100 ); - else - _out << " " << size; - }; - _out << "\n"; -} - -void TMaschera::item( const TString& str ) -{ int i, j; - TToken_string u( str, '@' ); - TToken_string s; - - for( i = 0; i < u.items(); i ++ ) - { _out << "IT \"" << s[ 0 ] << "\"\n"; - for( j = 1; j < s.items(); j ++ ) - _out << "ME " << s[ j ] << "\n"; - } - } - -class TGruppo : public TObject -{ -protected: - - int _id; - int _height; - bool _present; - -public: - - void id( int id ){ _id = id; } - int id( ){ return _id; } - void height( int h ){ _height = h; } - int height( ){ return _height; } - void present( bool p ){ _present = p; } - bool present( ){ return _present; } - - TGruppo ( int i ); - TGruppo ( int i, TConfig& pro ); -}; - -TGruppo::TGruppo( int i ) -{ - TConfig pro( "ve0300c.ini" ); - _id = i; - _height = pro.get_int( "HEIGHT", format( "%d", i ) ); -}; - -TGruppo::TGruppo( int i, TConfig& pro ) -{ - _id = i; - _height = pro.get_int( "HEIGHT", format( "%d", i ) ); -}; - -class TField : public TObject -{ -protected: - - TString _nome; - int _gruppo; - int _id; - int _type; - int _size; - int _stato; - int _x, _y; - TString _prompt, _flag, _help, _warning, _fieldname; - TToken_string _use, _input, _display, _output, _special, _items, _configs; - -public: - - TField( TString& campo, TConfig& pro ); - TField( ); - - void genera( TMaschera& _m ); - void configura( TConfig& pro ); - - void x( int x ){ _x = x; } - void y( int y ){ _y = y; } - void gruppo( int gruppo ){ _gruppo = gruppo; } - void id( int id ){ _id = id; } - void type( int type ){ _type = type; } - void size( int size ){ _size = size; } - void stato( int stato ){ _stato = stato; } - int x( ){ return _x; } - int y( ){ return _y; } - int gruppo( ){ return _gruppo; } - int id( ){ return _id; } - int type( ){ return _type; } - int size( ){ return _size; } - int stato( ){ return _stato; } - - - void nome( TString& nome ){ _nome = nome; } - void prompt( TString& prompt ){ _prompt = prompt; } - void flag( TString& flag ){ _flag = flag; } - void help( TString& help ){ _help = help; } - void warning( TString& warning ){ _warning = warning; } - void fieldname( TString& fieldname ){ _fieldname = fieldname; } - TString& nome( ){ return _nome; } - TString& prompt( ){ return _prompt; } - TString& flag( ){ return _flag; } - TString& help( ){ return _help; } - TString& warning( ){ return _warning; } - TString& fieldname( ){ return _fieldname; } - - void use( TToken_string& use ){ _use = use; } - void input( TToken_string& input ){ _input = input; } - void display( TToken_string& display ){ _display = display; } - void output( TToken_string& output ){ _output = output; } - void special( TToken_string& special ){ _special = special; } - void items( TToken_string& items ){ _items = items; } - void configs( TToken_string& configs ){ _configs = configs; } - TToken_string& use( ){ return _use; } - TToken_string& input( ){ return _input; } - TToken_string& display( ){ return _display; } - TToken_string& output( ){ return _output; } - TToken_string& special( ){ return _special; } - TToken_string& items( ){ return _items; } - TToken_string& configs( ){ return _configs; } - - - friend int sort_by_group(const TObject** o1, const TObject** o2 ); - // friend int TMask_generator::group( const TField& f1 ); -}; - -int sort_by_group(const TObject** o1, const TObject** o2 ) -{ - int g1 = ((TField * )( *o1 ))->_gruppo; - int g2 = ((TField * )( *o2 ))->_gruppo; - return ( g1 < g2 ) ? -1 : ( ( g1 = g2 ) ? 0 : 1 ); -}; - -TField::TField( TString& campo, TConfig& pro ) : _nome( campo ) -{ - _nome.trim( ); - _fieldname = pro.get( "FIELDNAME", campo ); - _x = _gruppo = pro.get_int( "X", campo ); - _y = _gruppo = pro.get_int( "Y", campo ); - _gruppo = pro.get_int( "GROUP", campo ); - CHECK( _gruppo != 0, "Gruppo uguale a 0" ); - _id = pro.get_int( "MSKID", campo ); - _type = pro.get_int( "TYPE", campo ); - _size = pro.get_int( "SIZE", campo ); - _prompt = pro.get( "PROMPT", campo ); - if( _prompt[ 0 ] == '\"' ) - { - _prompt.ltrim( 1 ); - _prompt.rtrim( 1 ); - }; - _flag = pro.get( "FLAG", campo ); - _help = pro.get( "FLAG", campo ); - _warning = pro.get( "FLAG", campo ); - _use = pro.get( "USE", campo ); - _use.separator( '~' ); - _input = pro.get( "INPUT", campo ); - _input.separator( '~' ); - _display = pro.get( "DISPLAY", campo ); - _display.separator( '~' ); - _output = pro.get( "OUTPUT", campo ); - _output.separator( '~' ); - _special = pro.get( "SPECIAL", campo ); - _special.separator( '~' ); - _configs = pro.get( "CONFIGS", campo ); - _configs.separator( '~' ); - _items = ""; - int last = pro.get_int( "NITEMS", campo ); - for( int i = 1; i <= last; i ++ ) - _items.add( pro.get( "ITEM", campo, i ) ); -}; - -TField::TField( ) -{ - _nome = ""; - _fieldname = ""; - _x = 0; - _y = 0; - _gruppo = 0; - _id = 0; - _type = 0; - _size = 0; - _prompt = ""; - _flag = ""; - _help = ""; - _warning = ""; - _use = ""; - _use.separator( '~' ); - _input = ""; - _input.separator( '~' ); - _display = ""; - _display.separator( '~' ); - _output = ""; - _output.separator( '~' ); - _special = ""; - _special.separator( '~' ); - _configs = ""; - _configs.separator( '~' ); - _items = ""; - _items.separator( '@' ); -}; - -void TField::configura( TConfig& pro ) -{ - TToken_string riga_profilo( pro.get( _nome, "PROFILO" ) ); - TString newprompt( riga_profilo.get( P_PROMPT ) ) ; - TString newhelp( riga_profilo.get( P_HELP ) ) ; - TString newwarning( riga_profilo.get( P_WARNING ) ) ; - if ( ! newprompt.blank( ) ) - _prompt = newprompt; - if ( ! newhelp.blank( ) ) - _help = newhelp; - if ( ! newwarning.blank( ) ) - _warning = newwarning; -} - -void TField::genera( TMaschera& m ) -{ - TString s; - - if ( _size != 0 ) - m.control( _type, _id, _size ); - else - m.control( _type, _id ); - m.begin(); - switch( _stato ) - { case FS_HIDDEN: - m.prompt( 2, 2 ); - s = "H"; - s << _flag; - m.flag( s ) ; - break; - case FS_DISABLED : - m.prompt( _x, _y + m.line( ), _prompt ); - s = "D"; - s << _flag; - m.flag( s ) ; - // m.advance_line( ); - break; - case FS_NORMAL : - case FS_REQUIRED : - m.prompt( _x, _y + m.line( ), _prompt ); - m.flag( _flag ); - // m.advance_line( ); - break; - } - m.check( _stato ); - if ( !_fieldname.blank( ) ) m.field( _fieldname ); - if ( !_items.blank( ) ) m.item( _items ); - if ( !_use.blank( ) ) m.use( _use ); - if ( !_input.blank( ) ) m.input( _input ); - if ( !_display.blank( ) ) m.display( _display ); - if ( !_output.blank( ) ) m.output( _output ); - if ( !_help.blank( ) ) m.help( _help ); - if ( !_warning.blank( ) ) m.warning( _warning ); - if ( !_special.blank( ) ) m.outline( _special ); - m.end(); - if ( ( m.line() > MAX_LINES_PER_PAGE ) && ( m._pageopen == TRUE)) - { m.end(); - m._pageopen = FALSE; - m.line( MASK_FIRST_LINE ); - }; -} - - -class TMask_generator -{ - -private: - - // Identificatore corrente per lo sheet - int _curid; - - // vero se il gruppo è aperto - bool _groupopen; - - // nome del file di .INI di input - TFilename _proname; - - // File .INI di riferimento per i campi - TConfig _fieldsini; - - // File .INI di riferimento per i gruppi - TConfig _groupsini; - - // File .INI di input - TConfig* _pro; - - TConfig _ditta; - - // Tabelle per la generazione - - // Campi dei documenti - TString_array _fields; - - // Campi dello sheet - TString_array _tab0300b; - -protected: - - // Carica un file di tabella in un TString array - void carica_tabella( const TFilename& fn, TString_array& tabella ); - - // Scrive sul file di output una serie di righe uguali per funzione ( DISPLAY, ecc. ) - void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); - - - // Crea un controllo del tipo specificato - void control( const int type, const int id = DLG_NULL, const int size = -1 ); - - // Ritorna vero se una componente della maschera è presente - int present( const int i, TToken_string line ){ const TString s = line.get( i ); return !(s.blank( )); }; - - // Carica dati dei campi - void carica_dati_campi( const TFilename& fn, TArray& a ); - - // Funzioni di accesso alle variabili private - // ------------------------------------------ - - // Funzioni per la lettura/scrittura di ID. Si incrementa da solo. - int id ( ) { return( _curid++ ); }; - void id( const int i ){ _curid = i; }; - - - // Funzioni di generazione ad alto livello - // --------------------------------------- - - // Genera un campo a partire da una linea del file VE0300A.DAT - void genera_campo( TToken_string _line ); - - // Genera un campo dello sheet a partire da una linea del file VE0300B.DAT - void genera_campo_sheet( TToken_string _line ); - - - // Genera la colonna dello sheet a partire da una linea del file VE0300B.DAT - void genera_item_sheet( TToken_string _line ); - - // Genera l'intestazione di una pagina ( non la prima ) - void intestazione_pagina( ); - - // Ritorna lo stato che dovrà avere il campo sulla maschera da generare - int stato_del_campo( TString campo ); - -public: - - TMaschera * _m; - - // Costruttore, vuole il nome del file .INI - TMask_generator( const TString& profilo ); - - // Attiva la generazione della maschera - void genera( ); - - // Distruttore - virtual ~TMask_generator( ); - -}; - -// Definizione dei metodi di TMask_generator -// ----------------------------------------- - -TMask_generator::TMask_generator( const TString& profilo ) : _proname( profilo ), _fieldsini( "ve0300a.ini" ), _groupsini( "ve0300c.ini" ), _ditta( CONFIG_DITTA ) -{ - // All'inizio il gruppo è 'chiuso' - _groupopen = FALSE; - - // Forza l'estensione al profilo - _proname.ext( "ini" ); - - // Se il file di profilo non esiste, esci con un errore fatale - if ( !fexist( _proname ) ) - fatal_box( "Il file %s non esiste!", ( const char * )_proname ); - - CHECK( fexist( "ve0300a.ini" ), "Il file ve0300a.ini non esiste!" ); - _fieldsini.list_paragraphs( _fields ); - CHECK( fexist( "ve0300b.dat" ), "Il file ve0300b.dat non esiste!" ); - carica_tabella( "ve0300b.dat", _tab0300b ); - - _pro = new TConfig( _proname ); - - TFilename _mskname( _pro->get( "MSKFILE", "MAIN") ); - _mskname.ext( "msk" ); - - - _m = new TMaschera( _mskname ); - -}; - -TMask_generator::~TMask_generator( ) -{ - delete _m; - delete _pro; -}; - - -void TMask_generator::carica_dati_campi( const TFilename& fn, TArray& a ) -{ - TScanner infile( fn ); - TString line; - TField *campo = NULL; - - while ( infile.ok( ) ) - { line = infile.line( ); - while ( ( line.empty() || line[ 0 ] == '#' ) && infile.ok( ) ) - { line = infile.line( ); - line.trim(); } - if( infile.ok( ) ) - { if ( line[ 0 ] == '[' ) // Carica un un campo - { line.strip( "[]" ); - if ( campo ) - { a.add( campo ); - // delete campo; - }; - campo = new TField(); - campo->nome( line ); - } - else - { int pos; - if( ( pos = line.find( '=' ) ) == 0 ) - yesnofatal_box( "Linea errata nel file.INI: %s", (const char *) line ); - else - { - TString key = line.sub( 0, pos ); - key.trim(); - TString value = line.mid( pos + 1 ); - value.trim(); - if( key == "X" ) - { campo->x( atoi( value ) ); } - else if( key == "Y" ) - { campo->y( atoi( value ) ); } - else if( key == "GROUP" ) - { campo->gruppo( atoi( value ) ); } - else if( key == "FIELDNAME" ) - { campo->fieldname( value ); } - else if( key == "MSKID" ) - { campo->id( atoi( value ) ); } - else if( key == "TYPE" ) - { campo->type( atoi( value ) ); } - else if( key == "SIZE" ) - { campo->size( atoi( value ) ); } - else if( key == "PROMPT" ) - { if( value[ 0 ] == '"' ) - { value.rtrim( 1 ); - value.ltrim( 1 ); }; - campo->prompt( value ); } - else if( key == "FLAG" ) - { campo->flag( value ); } - else if( key == "USE" ) - { campo->use( (TToken_string & ) value ); } - else if( key == "INPUT" ) - { campo->input( (TToken_string & )value ); } - else if( key == "DISPLAY" ) - { campo->display( (TToken_string & )value ); } - else if( key == "OUTPUT" ) - { campo->output( (TToken_string & )value ); } - else if( key == "WARNING" ) - { campo->warning( value ); } - else if( key == "HELP" ) - { campo->help( value ); } - else if( key == "SPECIAL" ) - { campo->special( (TToken_string & )value ); } - else if( key == "ITEMS" ) - { campo->items( (TToken_string & )value ); } - else if( key == "CONFIGS" ) - { campo->configs( (TToken_string & )value ); } - else yesnofatal_box( "Chiave non trovata(%s)", (const char *) key ); - } - } - } - } - if ( campo ) - { a.add( campo ); - // delete campo; - }; -} - -void TMask_generator::carica_tabella( const TFilename& fn, TString_array& tabella ) -{ TScanner in( fn ); - TToken_string line = in.line(); - while( line.not_empty( ) ) - { // Attacca tutte le righe che finiscono con § - while ( line.right( 1 ) == "§" ) - { line.rtrim( 1 ); - line << in.line( ); - }; - tabella.add( line ); - line = in.line(); - } -}; - -int TMask_generator::stato_del_campo( TString campo ) -{ - // Strategia al 28/08/95 - // Se il campo, nel file .INI di definizione dei campi, è legato a qualche voce in - // configurazione, legge il suo stato, altrimenti assume il massimo. - // Va poi a verificare nel .INI da compilare, e verifica li' la impostazione. - // Controlla poi la impostazione per il gruppo, come impostato nel file .INI - // e nella sezione CONFIGS nel .INI di defiunizione dei gruppi. - // Utilizza poi la minore delle due. - TToken_string config( _fieldsini.get( "CONFIGS", campo ) ); - int items = config.items( ); - int stato = FS_REQUIRED; - for ( int i = 0; i < items; i += 3 ) - { TString chiave = config[ i ]; - TString valore = config[ i + 1 ]; - TString reale = _ditta.get( chiave, "VE" ); - if ( reale == valore ) - stato = atoi( ( char * ) config[ i + 2 ] ); - }; - TToken_string riga_profilo( _pro->get( campo, "PROFILO" ) ); - int stato_profilo = riga_profilo.get_int( P_STATO ); - stato = ( stato < stato_profilo )? stato : stato_profilo; - TString gruppo ( _fieldsini.get( "GROUP", campo ) ); - gruppo.trim( ); - config = ( _groupsini.get( "CONFIGS", gruppo ) ); - int stato_gruppo = FS_REQUIRED; - for ( i = 0; i < items; i += 3 ) - { TString chiave = config[ i ]; - TString valore = config[ i + 1 ]; - TString reale = _ditta.get( chiave, "VE" ); - if ( reale == valore ) - stato_gruppo = atoi( ( char * ) config[ i + 2 ] ); - }; - stato = ( stato < stato_gruppo )? stato : stato_gruppo; - int stato_gruppo_profilo = _pro->get_int( gruppo, "PROFILOGRUPPO" ); - stato = ( stato < stato_gruppo_profilo )? stato : stato_gruppo_profilo; - return stato; - -} - -void TMask_generator::genera_campo_sheet( TToken_string _line ) -{ - const int type( _line.get_int( B_MSKTYPE ) ); - _m->control( type, id( ), _line.get_int( B_MSKSIZE ) ); - _m->begin( ); - _m->prompt( 2, 2 ); - _m->end( ); -} - -void TMask_generator::genera_item_sheet( TToken_string _line ) -{ - _m->_out << "IT \"" << _line.get( B_DESCR ); - _m->_out << "@" << _line.get_int( B_WIDTH ) << "\"\n"; -} - -void TMask_generator::intestazione_pagina( ) -{ - _m->page( _m->page( ) + 1 ); - _m->pagina( _m->page( ) ); - - _m->control( T_GROUPBOX, DLG_NULL, 7806 ); - _m->begin( ); - _m->prompt( 1, 0, "" ); - _m->end( ); - - _m->control( T_STRING, DLG_NULL, 4 ); - _m->begin(); - _m->prompt( 2, 1, "Cod. num. " ); - _m->group( 2 ); - _m->flag( "DUZ" ); - _m->end(); - - _m->control( T_STRING, DLG_NULL, 50 ); - _m->begin(); - _m->prompt( 24, 1 ); - _m->flag( "DU" ); - _m->group( 3 ); - _m->end(); - - _m->control( T_STRING, DLG_NULL, 4 ); - _m->begin(); - _m->prompt( 2, 2, "Tipo doc. " ); - _m->flag( "DU" ); - _m->group( 4 ); - _m->end(); - - _m->control( T_STRING, DLG_NULL, 50 ); - _m->begin(); - _m->prompt( 24, 2 ); - _m->flag( "DU" ); - _m->group( 5 ); - _m->end(); - - _m->control( T_NUMBER, DLG_NULL, 6 ); - _m->begin(); - _m->prompt( 2, 3, "Doc.: nr. " ); - _m->group( 6 ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_DATE ); - _m->begin(); - _m->prompt( 24, 3, "Data " ); - _m->group( 7 ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_NUMBER, DLG_NULL, 1 ); - _m->begin(); - _m->prompt( 50, 3, "Stato " ); - _m->group( 8 ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_STRING, DLG_NULL, 4 ); - _m->begin(); - _m->prompt( 66, 3, "Es. " ); - _m->flag( "D" ); - _m->group( 9 ); - _m->end(); - - _m->control( T_STRING, DLG_NULL, 6 ); - _m->begin(); - if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) - _m->prompt( 2, 4, "Cliente " ); - else - _m->prompt( 2, 4, "Fornitore " ); - _m->flag( "D" ); - _m->group( 10 ); - _m->end(); - - _m->control( T_STRING, DLG_NULL, 50 ); - _m->begin(); - _m->prompt( 24, 4, "" ); - _m->flag( "D" ); - _m->group( 11 ); - _m->end(); - -} - -void TMask_generator::genera( ) -{ - int i; - - // Definizione della toolbar - - - _m->outline( "TOOLBAR \"\" 0 20 0 2" ); - _m->outline( "BU 18 8 2" ); - _m->begin(); - _m->prompt( -15, -1, "~Registra" ); - _m->message( "EXIT,20082" ); - _m->end(); - - _m->outline( "BU 17 8 2" ); - _m->begin(); - _m->prompt( -25, -1, "~Elimina" ); - _m->message( "EXIT,127" ); - _m->end(); - - _m->outline( "BU 99 8 2" ); - _m->begin(); - _m->prompt( -35, -1, "E~labora" ); - _m->message( "EXIT,345" ); - _m->end(); - - _m->outline( "BU 24 8 2" ); - _m->begin(); - _m->prompt( -45, -1 ); - _m->message( "EXIT,346" ); - _m->end(); - - _m->outline( "BU 2 8 2" ); - _m->begin(); - _m->prompt( -55, -1 ); - _m->message( "EXIT,27" ); - _m->end(); - - // End della toolbar - _m->end(); - - - // Header della prima pagina - - _m->outline( "PA \"Pagina \" 11 60 14" ); - - _m->control( T_GROUPBOX, DLG_NULL, 7806 ); - _m->begin( ); - _m->prompt( 1, 0, "" ); - _m->end( ); - - _m->control( T_STRING, F_CODNUM, 4 ); - _m->begin(); - _m->prompt( 2, 1, "Cod. num. " ); - _m->field( "CODNUM" ); - _m->flag( "GDUZ" ); - _m->message( "CO,2@" ); - _m->end(); - - _m->control( T_STRING, F_DESNUM, 50 ); - _m->begin(); - _m->prompt( 24, 1 ); - _m->flag( "GDU" ); - _m->message( "CO,3@" ); - _m->end(); - - _m->control( T_STRING, F_TIPODOC, 4 ); - _m->begin(); - _m->prompt( 2, 2, "Tipo doc. " ); - _m->flag( "GDU" ); - _m->message( "CO,4@" ); - _m->end(); - - _m->control( T_STRING, F_DESTIPODOC, 50 ); - _m->begin(); - _m->prompt( 24, 2 ); - _m->flag( "GDU" ); - _m->message( "CO,5@" ); - _m->end(); - - _m->control( T_NUMBER, F_NDOC, 6 ); - _m->begin(); - _m->prompt( 2, 3, "Doc.: nr. " ); - _m->message( "CO,6@" ); - _m->flag( "GDR" ); - _m->end(); - - _m->control( T_DATE, F_DATADOC ); - _m->begin(); - _m->prompt( 24, 3, "Data " ); - _m->message( "CO,7@" ); - _m->flag( "" ); - _m->end(); - - _m->control( T_NUMBER, F_STATO, 1 ); - _m->begin(); - _m->prompt( 50, 3, "Stato " ); - _m->message( "CO,8@" ); - _m->flag( "D" ); - _m->end(); - - _m->control( T_STRING, F_ANNO, 4 ); - _m->begin(); - _m->prompt( 66, 3, "Es. " ); - _m->flag( "GD" ); - _m->message( "CO,9@" ); - _m->end(); - - _m->control( T_STRING, F_CODCF, 6 ); - _m->begin(); - if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) - _m->prompt( 2, 4, "Cliente " ); - else - _m->prompt( 2, 4, "Fornitore " ); - _m->flag( "" ); - _m->message( "CO,10@" ); - _m->end(); - - _m->control( T_STRING, F_DESCF, 50 ); - _m->begin( ); - _m->prompt( 24, 4, "" ); - _m->flag( "" ); - _m->message( "CO,11@" ); - _m->end(); - - _m->line( MASK_FIRST_LINE ); - - // Generazione - - // Scorro l'array dei campi, per vedere gli stati ed i gruppi - - TArray campi; - TAssoc_array gruppi; - - carica_dati_campi( "ve0300a.ini", campi ); - int last = campi.items( ); - for( i = 0; i < last; i ++ ) - { - TString nome = (( TField & )campi[ i ]).nome( ); - int stato = stato_del_campo( nome ); - if( stato != FS_HIDDEN ) - { - const int addgruppo = (( TField & )campi[ i ]).gruppo( ); - TString16 chiave; - chiave.format( "%5d", addgruppo ); - if ( !gruppi.is_key( chiave ) ) - gruppi.add( chiave, new TGruppo( addgruppo, _groupsini ) ); - } - (( TField & )campi[ i ]).stato( stato ); - }; - campi.sort( sort_by_group ); - - // Generazione vera e propria - _m->_pageopen = TRUE; - last = campi.items( ); - int curgruppo = 0; - for( i = 0; i < last; i ++ ) - { - if ( _m->_pageopen == FALSE) - { - intestazione_pagina( ); - _m->_pageopen = TRUE; - } - TField& campo = ( TField& ) campi[ i ]; - if ( campo.gruppo( ) != curgruppo ) - { - TString16 chiave; - chiave.format( "%5d", campo.gruppo( ) ); - if ( gruppi.is_key( chiave ) ) - { - TGruppo& gruppo = ( TGruppo& ) gruppi[ chiave ]; - if ( _m->line( ) + gruppo.height( ) > MAX_LINES_PER_PAGE ) - { - _m->end( ); - intestazione_pagina( ); - _m->line( MASK_FIRST_LINE ); - } - else - { - TString16 vecchiachiave; - vecchiachiave.format( "%5d", curgruppo ); - if ( gruppi.is_key( vecchiachiave ) ) - { - _m->line( _m->line( ) + ( ( TGruppo& ) gruppi[ vecchiachiave ]).height( ) ); - } - } - }; - curgruppo = campo.gruppo( ); - }; - campo.configura( *_pro ); - campo.genera( *_m ); - } - if ( _m->_pageopen == TRUE ) _m->end( ); - intestazione_pagina( ); - - // Generazione del listbox per i tipi di riga da aggiungere nello sheet - _m->control ( T_LISTBOX, F_LBTIPORIGA, 30 ); - _m->begin(); - _m->prompt( 2, 7, "Tipo riga da aggiungere " ); - _m->end( ); - - // Generazione dello sheet : vedi il profilo - TScanner sheet_in( "ve0300b.dat" ); - _m->_out << "SPREADSHEET " << F_SHEET << "\n"; - _m->begin(); - _m->prompt( 2, 8 ); - for( i = 0; i < _tab0300b.items( ); i ++ ) - genera_item_sheet( _tab0300b.row( i ) ); - _m->end(); - _m->end(); - - // Generazione pagina dei piedi - TToken_string s(_pro->get( "PROGPIEDE", "MAIN" ) ); - if ( s.not_empty() ) - { - intestazione_pagina( ); - int cp = 1; - int piede = s.get_int();; - while ( piede != 0 ) - { - _m->control( T_NUMBER, BASE_PIEDE + cp, 1805 ); - _m->begin(); - TString header = _ditta.get( "PIEDE", "ve", piede ); - while( header.len() < 40 ) header << " "; - _m->prompt( 2, 7 + cp, header ); - _m->flag( "D" ); - _m->end(); - cp ++; - piede = s.get_int(); - } - _m->end(); - }; - _m->endmask( ); - - // Stategia al 30/06/95 - // Creo una maschera con tutte le colonne, poi, a RUNTIME, - // dal motore, nascondo e adatto le colonne. - - // Generazione maschera dello sheet - _m->_out << "PA \"Pagina 1\" 8 5 64 13\n"; - - id( 101 ); - for( i = 0; i < _tab0300b.items( ); i ++ ) - genera_campo_sheet( _tab0300b.row( i ) ); - _m->end(); - _m->end(); - _m->endmask( ); -} - - -// Applicazione guscio - -class TGenMask_application : public TApplication -{ - -protected: - - virtual bool create( ); - virtual bool menu( MENU_TAG _m ); - -}; - - -bool TGenMask_application::menu(MENU_TAG _m) -{ - TMask_generator a( argv( 2 ) ); - a.genera( ); - return( TRUE ); -}; - -bool TGenMask_application::create( ) -{ - TApplication::create(); - menu( 0 ); - return FALSE; -}; - -int ve0300( int argc, char** argv ) -{ - - if ( argc < 3 ) - fatal_box( "Sintassi: VE0 -3 " ); - - TGenMask_application a; - a.run ( argc, argv, "Generazione in corso ..." ); - return 0; -} +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + + "Compilatore di profili" per la gestione vendite. + Considerando: + - Profilo documento + - Configurazione vendite per la ditta + - Condizioni atmosferiche + genera le maschere appropriate. + Accetta sulla riga di comando il nome del profilo documento per cui deve generare + la maschera. Il nome del file .MSK viene dedotto dal profilo documento stesso. + + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#ifndef __CHECKS_H +#include +#endif + +#ifndef __FSTREAM_H +#include +#endif + +#ifndef __SCANNER_H +#include +#endif + +#ifndef __CONFIG_H +#include +#endif + +#ifndef __APPLICATION_H +#include +#endif + +#ifndef __UTILITY_H +#include +#endif + +#ifndef __DEFMASK_H +#include +#endif + +#ifndef __VE0100_H +#include "ve0100.h" +#endif + +#ifndef __VEUML_H +#include "veuml.h" +#endif + +// Costanti simboliche per i tipi di campo + +#define T_DATE 1 +#define T_STRING 2 +#define T_NUMBER 3 +#define T_BOOLEAN 4 +#define T_LISTBOX 5 +#define T_MEMO 6 +#define T_GROUPBOX 7 + +// Costanti simboliche per flags del campo + +#define FS_HIDDEN 0 +#define FS_DISABLED 1 +#define FS_NORMAL 2 +#define FS_REQUIRED 3 + +// Significato delle colonne nella tabella _tab0300b +#define B_NOME 0 +#define B_MSKTYPE 1 +#define B_MSKSIZE 2 +#define B_DESCR 3 +#define B_WIDTH 4 + +// Significato dei campi nel profilo del documento +#define P_STATO 0 +#define P_PROMPT 1 +#define P_HELP 2 +#define P_WARNING 3 + + +// Numero massimo di linee per pagina + +#define MAX_LINES_PER_PAGE 16 +#define MASK_FIRST_LINE 6 + +class TMaschera : public TObject +{ + +private: + + // Linea corrente + int _curline; + + // Pagina corrente + int _curpage; + +public: + + void advance_line( ){ _curline ++; }; + + // Genera una serie di righe uguali per funzione ( DISPLAY, ecc. ) + void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); + + // Crea un controllo del tipo specificato + void control( const int type, const int id = DLG_NULL, const int size = -1 ); + + // CHECKTYPE + void check( const int i ); + + // PAGE + void pagina( const int i ){ _out << "PA \"Pagina " << i << "\" 11 60 14\n"; }; + + // PROMPT + void prompt( const int x, const int y, const TString& s = "" ){ _out << "PR " << x << " " << y << " \"" << s << "\"\n"; }; + + // BEGIN + void begin( void ) { outline ( "BE" ); }; + + // END + void end( void ) { outline ( "EN" ); }; + + // ENDMASK + void endmask( void ) { outline ( "ENDMASK" ); }; + + // FLAG + void flag( const TString& s ) { _out << "FLAG \"" << s << "\"\n"; }; + + // HELP + void help( const TString& s ) { _out << "HE \"" << s << "\"\n"; }; + + // WARNING + void warning( const TString& s ) { _out << "WA \"" << s << "\"\n"; }; + + // GROUP + void group( const int g ) { _out << "GR " << g << "\n"; }; + + // FIELD + void field( const TString& s ) { outline( s, "FI "); }; + + // ITEM + void item( const TString& s ); + + // MESSAGE + void message( const TString& s ) { outline( s, "ME "); }; + + // USE + void use( const TString& s ){ outline( s, "US " ); }; + + // DISPLAY + void display( const TString& s ){ outline( s, "DI " ); }; + + // INPUT + void input( const TString& s ){ outline( s, "IN " ); }; + + // OUTPUT + void output( const TString& s ){ outline( s, "OU " ); }; + + // Funzioni per la lettura/scrittura di CURPAGE + int page( ) { return _curpage; }; + void page( const int i ){ _curpage = i; }; + + // Funzioni per la lettura/scrittura di CURLINE + int line( ) { return _curline; }; + void line( const int i ){ _curline = i; }; + + // Costruttore, vuole il nome del file .INI + TMaschera( const TFilename outfile ); + + // Vero se la pagina è aperta + bool _pageopen; + + // File .MSK di output + ofstream _out; + + +}; + + +TMaschera::TMaschera( const TFilename outfile ) : _out( outfile ) +{ + _curline = 1; + _curpage = 1; + _pageopen = FALSE; + bool _groupopen = FALSE; +} + +void TMaschera::outline( const TString& s, const TString& prefix, const char sep ) +{ + if ( s.left( 1 ) == "@" ) + _out << "CO " << prefix << s.mid( 1 ) << "\n"; + else + { TToken_string u( s, sep ); + for ( int i = 0; i < u.items(); i ++ ) + _out << prefix << u.get( i ) << "\n"; + } +} + +void TMaschera::check( const int i ) +{ + switch( i ) + { + case FS_REQUIRED: + outline ( "CH REQUIRED" ); + break; + default: + outline ( "CH NORMAL" ); + break; + } +} + +void TMaschera::control( const int type, const int id, const int size ) +{ + switch ( type ) + { + case T_DATE: + _out << "DA"; + break; + case T_STRING: + _out << "ST"; + break; + case T_BOOLEAN: + _out << "BO"; + break; + case T_NUMBER: + _out << "NU"; + break; + case T_LISTBOX: + _out << "LI"; + break; + case T_MEMO: + _out << "ME"; + break; + case T_GROUPBOX: + _out << "GR"; + break; + } + _out << " " << id; + if ( size > 0 ) + { + if ( size > 100 ) + _out << " " << ( int )( size / 100 ) << " " << ( size % 100 ); + else + _out << " " << size; + } + _out << "\n"; +} + +void TMaschera::item( const TString& str ) +{ + int i, j; + TToken_string u( str, '@' ); + TToken_string s; + + for( i = 0; i < u.items(); i ++ ) + { + _out << "IT \"" << s[ 0 ] << "\"\n"; + for( j = 1; j < s.items(); j ++ ) + _out << "ME " << s[ j ] << "\n"; + } +} + +class TGruppo : public TObject +{ +protected: + + int _id; + int _height; + bool _present; + +public: + + void id( int id ){ _id = id; } + int id( ){ return _id; } + void height( int h ){ _height = h; } + int height( ){ return _height; } + void present( bool p ){ _present = p; } + bool present( ){ return _present; } + + TGruppo ( int i ); + TGruppo ( int i, TConfig& pro ); +}; + +TGruppo::TGruppo( int i ) +{ + TConfig pro( "ve0300c.ini" ); + _id = i; + _height = pro.get_int( "HEIGHT", format( "%d", i ) ); +}; + +TGruppo::TGruppo( int i, TConfig& pro ) +{ + _id = i; + _height = pro.get_int( "HEIGHT", format( "%d", i ) ); +}; + +class TField : public TObject +{ +protected: + + TString _nome; + int _gruppo; + int _id; + int _type; + int _size; + int _stato; + int _x, _y; + TString _prompt, _flag, _help, _warning, _fieldname; + TToken_string _use, _input, _display, _output, _special, _items, _configs; + +public: + + TField( TString& campo, TConfig& pro ); + TField( ); + + void genera( TMaschera& _m ); + void configura( TConfig& pro ); + + void x( int x ){ _x = x; } + void y( int y ){ _y = y; } + void gruppo( int gruppo ){ _gruppo = gruppo; } + void id( int id ){ _id = id; } + void type( int type ){ _type = type; } + void size( int size ){ _size = size; } + void stato( int stato ){ _stato = stato; } + int x( ){ return _x; } + int y( ){ return _y; } + int gruppo( ){ return _gruppo; } + int id( ){ return _id; } + int type( ){ return _type; } + int size( ){ return _size; } + int stato( ){ return _stato; } + + + void nome( TString& nome ){ _nome = nome; } + void prompt( TString& prompt ){ _prompt = prompt; } + void flag( TString& flag ){ _flag = flag; } + void help( TString& help ){ _help = help; } + void warning( TString& warning ){ _warning = warning; } + void fieldname( TString& fieldname ){ _fieldname = fieldname; } + TString& nome( ){ return _nome; } + TString& prompt( ){ return _prompt; } + TString& flag( ){ return _flag; } + TString& help( ){ return _help; } + TString& warning( ){ return _warning; } + TString& fieldname( ){ return _fieldname; } + + void use( TToken_string& use ){ _use = use; } + void input( TToken_string& input ){ _input = input; } + void display( TToken_string& display ){ _display = display; } + void output( TToken_string& output ){ _output = output; } + void special( TToken_string& special ){ _special = special; } + void items( TToken_string& items ){ _items = items; } + void configs( TToken_string& configs ){ _configs = configs; } + TToken_string& use( ){ return _use; } + TToken_string& input( ){ return _input; } + TToken_string& display( ){ return _display; } + TToken_string& output( ){ return _output; } + TToken_string& special( ){ return _special; } + TToken_string& items( ){ return _items; } + TToken_string& configs( ){ return _configs; } + + + friend int sort_by_group(const TObject** o1, const TObject** o2 ); + // friend int TMask_generator::group( const TField& f1 ); +}; + +int sort_by_group(const TObject** o1, const TObject** o2 ) +{ + int g1 = ((TField * )( *o1 ))->_gruppo; + int g2 = ((TField * )( *o2 ))->_gruppo; + return ( g1 < g2 ) ? -1 : ( ( g1 = g2 ) ? 0 : 1 ); +}; + +TField::TField( TString& campo, TConfig& pro ) : _nome( campo ) +{ + _nome.trim( ); + _fieldname = pro.get( "FIELDNAME", campo ); + _x = _gruppo = pro.get_int( "X", campo ); + _y = _gruppo = pro.get_int( "Y", campo ); + _gruppo = pro.get_int( "GROUP", campo ); + CHECK( _gruppo != 0, "Gruppo uguale a 0" ); + _id = pro.get_int( "MSKID", campo ); + CHECK( _id != 0, "Campo con MSKID uguale a 0" ); + _type = pro.get_int( "TYPE", campo ); + _size = pro.get_int( "SIZE", campo ); + _prompt = pro.get( "PROMPT", campo ); + if( _prompt[ 0 ] == '\"' ) + { + _prompt.ltrim( 1 ); + _prompt.rtrim( 1 ); + }; + _flag = pro.get( "FLAG", campo ); + _help = pro.get( "FLAG", campo ); + _warning = pro.get( "FLAG", campo ); + _use = pro.get( "USE", campo ); + _use.separator( '~' ); + _input = pro.get( "INPUT", campo ); + _input.separator( '~' ); + _display = pro.get( "DISPLAY", campo ); + _display.separator( '~' ); + _output = pro.get( "OUTPUT", campo ); + _output.separator( '~' ); + _special = pro.get( "SPECIAL", campo ); + _special.separator( '~' ); + _configs = pro.get( "CONFIGS", campo ); + _configs.separator( '~' ); + _items = ""; + int last = pro.get_int( "NITEMS", campo ); + for( int i = 1; i <= last; i ++ ) + _items.add( pro.get( "ITEM", campo, i ) ); +}; + +TField::TField( ) +{ + _nome = ""; + _fieldname = ""; + _x = 0; + _y = 0; + _gruppo = 0; + _id = 0; + _type = 0; + _size = 0; + _prompt = ""; + _flag = ""; + _help = ""; + _warning = ""; + _use = ""; + _use.separator( '~' ); + _input = ""; + _input.separator( '~' ); + _display = ""; + _display.separator( '~' ); + _output = ""; + _output.separator( '~' ); + _special = ""; + _special.separator( '~' ); + _configs = ""; + _configs.separator( '~' ); + _items = ""; + _items.separator( '@' ); +} + +void TField::configura( TConfig& pro ) +{ + TToken_string riga_profilo( pro.get( _nome, "PROFILO" ) ); + TString newprompt( riga_profilo.get( P_PROMPT ) ) ; + TString newhelp( riga_profilo.get( P_HELP ) ) ; + TString newwarning( riga_profilo.get( P_WARNING ) ) ; + if ( ! newprompt.blank( ) ) + _prompt = newprompt; + if ( ! newhelp.blank( ) ) + _help = newhelp; + if ( ! newwarning.blank( ) ) + _warning = newwarning; +} + +void TField::genera( TMaschera& m ) +{ + TString s; + + if ( _size != 0 ) + m.control( _type, _id, _size ); + else + m.control( _type, _id ); + m.begin(); + switch( _stato ) + { + case FS_HIDDEN: + m.prompt( 2, 2 ); + s = "H"; + s << _flag; + m.flag( s ) ; + break; + case FS_DISABLED : + m.prompt( _x, _y + m.line( ), _prompt ); + s = "D"; + s << _flag; + m.flag( s ) ; + break; + case FS_NORMAL : + case FS_REQUIRED : + m.prompt( _x, _y + m.line( ), _prompt ); + m.flag( _flag ); + break; + } + m.check( _stato ); + if ( !_fieldname.blank( ) ) m.field( _fieldname ); + if ( !_items.blank( ) ) m.item( _items ); + if ( !_use.blank( ) ) m.use( _use ); + if ( !_input.blank( ) ) m.input( _input ); + if ( !_display.blank( ) ) m.display( _display ); + if ( !_output.blank( ) ) m.output( _output ); + if ( !_help.blank( ) ) m.help( _help ); + if ( !_warning.blank( ) ) m.warning( _warning ); + if ( !_special.blank( ) ) m.outline( _special ); + m.end(); + if ( ( m.line() > MAX_LINES_PER_PAGE ) && ( m._pageopen == TRUE)) + { + m.end(); + m._pageopen = FALSE; + m.line( MASK_FIRST_LINE ); + } +} + + +class TMask_generator +{ + +private: + + // Identificatore corrente per lo sheet + int _curid; + + // vero se il gruppo è aperto + bool _groupopen; + + // nome del file di .INI di input + TFilename _proname; + + // File .INI di riferimento per i campi + TConfig _fieldsini; + + // File .INI di riferimento per i gruppi + TConfig _groupsini; + + // File .INI di input + TConfig* _pro; + + TConfig _ditta; + + // Tabelle per la generazione + + // Campi dei documenti + TString_array _fields; + + // Campi dello sheet + TString_array _tab0300b; + +protected: + + // Carica un file di tabella in un TString array + void carica_tabella( const TFilename& fn, TString_array& tabella ); + + // Scrive sul file di output una serie di righe uguali per funzione ( DISPLAY, ecc. ) + void outline( const TString& s = "", const TString& prefix = "", const char sep = '~' ); + + + // Crea un controllo del tipo specificato + void control( const int type, const int id = DLG_NULL, const int size = -1 ); + + // Ritorna vero se una componente della maschera è presente + int present( const int i, TToken_string line ){ const TString s = line.get( i ); return !(s.blank( )); }; + + // Carica dati dei campi + void carica_dati_campi( const TFilename& fn, TArray& a ); + + // Funzioni di accesso alle variabili private + // ------------------------------------------ + + // Funzioni per la lettura/scrittura di ID. Si incrementa da solo. + int id ( ) { return( _curid++ ); }; + void id( const int i ){ _curid = i; }; + + + // Funzioni di generazione ad alto livello + // --------------------------------------- + + // Genera un campo a partire da una linea del file VE0300A.DAT + void genera_campo( TToken_string _line ); + + // Genera un campo dello sheet a partire da una linea del file VE0300B.DAT + void genera_campo_sheet( TToken_string _line ); + + + // Genera la colonna dello sheet a partire da una linea del file VE0300B.DAT + void genera_item_sheet( TToken_string _line ); + + // Genera l'intestazione di una pagina ( non la prima ) + void intestazione_pagina( ); + + // Ritorna lo stato che dovrà avere il campo sulla maschera da generare + int stato_del_campo( TString campo ); + +public: + + TMaschera * _m; + + // Costruttore, vuole il nome del file .INI + TMask_generator( const TString& profilo ); + + // Attiva la generazione della maschera + void genera( ); + + // Distruttore + virtual ~TMask_generator( ); + +}; + +// Definizione dei metodi di TMask_generator +// ----------------------------------------- + +TMask_generator::TMask_generator( const TString& profilo ) : _proname( profilo ), _fieldsini( "ve0300a.ini" ), _groupsini( "ve0300c.ini" ), _ditta( CONFIG_DITTA ) +{ + // All'inizio il gruppo è 'chiuso' + _groupopen = FALSE; + + // Forza l'estensione al profilo + _proname.ext( "ini" ); + + // Se il file di profilo non esiste, esci con un errore fatale + if ( !fexist( _proname ) ) + fatal_box( "Il file %s non esiste!", ( const char * )_proname ); + + CHECK( fexist( "ve0300a.ini" ), "Il file ve0300a.ini non esiste!" ); + _fieldsini.list_paragraphs( _fields ); + CHECK( fexist( "ve0300b.dat" ), "Il file ve0300b.dat non esiste!" ); + carica_tabella( "ve0300b.dat", _tab0300b ); + + _pro = new TConfig( _proname ); + + TFilename _mskname( _pro->get( "MSKFILE", "MAIN") ); + _mskname.ext( "msk" ); + + + _m = new TMaschera( _mskname ); + +}; + +TMask_generator::~TMask_generator( ) +{ + delete _m; + delete _pro; +}; + + +void TMask_generator::carica_dati_campi( const TFilename& fn, TArray& a ) +{ + TScanner infile( fn ); + TString line; + TField *campo = NULL; + + while ( infile.ok( ) ) + { + line = infile.line( ); + line.trim( ); + while ( ( line.empty() || line[ 0 ] == '#' || line.left( 2 ) == "//" ) && infile.ok( ) ) + { + line = infile.line( ); + line.trim(); + } + if( infile.ok( ) ) + { + if ( line[ 0 ] == '[' ) // Carica un un campo + { + line.strip( "[]" ); + if ( campo ) + a.add( campo ); + campo = new TField(); + campo->nome( line ); + } + else + { + int pos; + if( ( pos = line.find( '=' ) ) == 0 ) + yesnofatal_box( "Linea errata nel file.INI: %s", (const char *) line ); + else + { + TString key = line.sub( 0, pos ); + key.trim(); + TString value = line.mid( pos + 1 ); + value.trim(); + if( key == "X" ) + campo->x( atoi( value ) ); + else if( key == "Y" ) + campo->y( atoi( value ) ); + else if( key == "GROUP" ) + campo->gruppo( atoi( value ) ); + else if( key == "FIELDNAME" ) + campo->fieldname( value ); + else if( key == "MSKID" ) + campo->id( atoi( value ) ); + else if( key == "TYPE" ) + campo->type( atoi( value ) ); + else if( key == "SIZE" ) + campo->size( atoi( value ) ); + else if( key == "PROMPT" ) + { + if( value[ 0 ] == '"' ) + { + value.rtrim( 1 ); + value.ltrim( 1 ); + }; + campo->prompt( value ); + } + else if( key == "FLAG" ) + campo->flag( value ); + else if( key == "USE" ) + campo->use( (TToken_string & ) value ); + else if( key == "INPUT" ) + campo->input( (TToken_string & )value ); + else if( key == "DISPLAY" ) + campo->display( (TToken_string & )value ); + else if( key == "OUTPUT" ) + campo->output( (TToken_string & )value ); + else if( key == "WARNING" ) + campo->warning( value ); + else if( key == "HELP" ) + campo->help( value ); + else if( key == "SPECIAL" ) + campo->special( (TToken_string & )value ); + else if( key == "ITEMS" ) + campo->items( (TToken_string & )value ); + else if( key == "CONFIGS" ) + campo->configs( (TToken_string & )value ); + else yesnofatal_box( "Chiave non trovata(%s)", (const char *) key ); + } + } + } + } + if ( campo ) + a.add( campo ); +} + +void TMask_generator::carica_tabella( const TFilename& fn, TString_array& tabella ) +{ TScanner in( fn ); + TToken_string line = in.line(); + while( line.not_empty( ) ) + { // Attacca tutte le righe che finiscono con § + while ( line.right( 1 ) == "§" ) + { line.rtrim( 1 ); + line << in.line( ); + }; + tabella.add( line ); + line = in.line(); + } +}; + +int TMask_generator::stato_del_campo( TString campo ) +{ + // Strategia al 28/08/95 + // Se il campo, nel file .INI di definizione dei campi, è legato a qualche voce in + // configurazione, legge il suo stato, altrimenti assume il massimo. + // Va poi a verificare nel .INI da compilare, e verifica li' la impostazione. + // Controlla poi la impostazione per il gruppo, come impostato nel file .INI + // e nella sezione CONFIGS nel .INI di defiunizione dei gruppi. + // Utilizza poi la minore delle due. + TToken_string config( _fieldsini.get( "CONFIGS", campo ) ); + int items = config.items( ); + int stato = FS_REQUIRED; + for ( int i = 0; i < items; i += 3 ) + { TString chiave = config[ i ]; + TString valore = config[ i + 1 ]; + TString reale = _ditta.get( chiave, "VE" ); + if ( reale == valore ) + stato = atoi( ( char * ) config[ i + 2 ] ); + }; + TToken_string riga_profilo( _pro->get( campo, "PROFILO" ) ); + int stato_profilo = riga_profilo.get_int( P_STATO ); + stato = ( stato < stato_profilo )? stato : stato_profilo; + TString gruppo ( _fieldsini.get( "GROUP", campo ) ); + gruppo.trim( ); + config = ( _groupsini.get( "CONFIGS", gruppo ) ); + int stato_gruppo = FS_REQUIRED; + for ( i = 0; i < items; i += 3 ) + { TString chiave = config[ i ]; + TString valore = config[ i + 1 ]; + TString reale = _ditta.get( chiave, "VE" ); + if ( reale == valore ) + stato_gruppo = atoi( ( char * ) config[ i + 2 ] ); + }; + stato = ( stato < stato_gruppo )? stato : stato_gruppo; + int stato_gruppo_profilo = _pro->get_int( gruppo, "PROFILOGRUPPO" ); + stato = ( stato < stato_gruppo_profilo )? stato : stato_gruppo_profilo; + return stato; + +} + +void TMask_generator::genera_campo_sheet( TToken_string _line ) +{ + const int type( _line.get_int( B_MSKTYPE ) ); + _m->control( type, id( ), _line.get_int( B_MSKSIZE ) ); + _m->begin( ); + _m->prompt( 2, 2 ); + _m->end( ); +} + +void TMask_generator::genera_item_sheet( TToken_string _line ) +{ + _m->_out << "IT \"" << _line.get( B_DESCR ); + _m->_out << "@" << _line.get_int( B_WIDTH ) << "\"\n"; +} + +void TMask_generator::intestazione_pagina( ) +{ + _m->page( _m->page( ) + 1 ); + _m->pagina( _m->page( ) ); + + _m->control( T_GROUPBOX, DLG_NULL, 7806 ); + _m->begin( ); + _m->prompt( 1, 0, "" ); + _m->end( ); + + _m->control( T_STRING, DLG_NULL, 4 ); + _m->begin(); + _m->prompt( 2, 1, "Cod. num. " ); + _m->group( 2 ); + _m->flag( "DUZ" ); + _m->end(); + + _m->control( T_STRING, DLG_NULL, 50 ); + _m->begin(); + _m->prompt( 24, 1 ); + _m->flag( "DU" ); + _m->group( 3 ); + _m->end(); + + _m->control( T_STRING, DLG_NULL, 4 ); + _m->begin(); + _m->prompt( 2, 2, "Tipo doc. " ); + _m->flag( "DU" ); + _m->group( 4 ); + _m->end(); + + _m->control( T_STRING, DLG_NULL, 50 ); + _m->begin(); + _m->prompt( 24, 2 ); + _m->flag( "DU" ); + _m->group( 5 ); + _m->end(); + + _m->control( T_NUMBER, DLG_NULL, 6 ); + _m->begin(); + _m->prompt( 2, 3, "Doc.: nr. " ); + _m->group( 6 ); + _m->flag( "D" ); + _m->end(); + + _m->control( T_DATE ); + _m->begin(); + _m->prompt( 24, 3, "Data " ); + _m->group( 7 ); + _m->flag( "D" ); + _m->end(); + + _m->control( T_NUMBER, DLG_NULL, 1 ); + _m->begin(); + _m->prompt( 50, 3, "Stato " ); + _m->group( 8 ); + _m->flag( "D" ); + _m->end(); + + _m->control( T_STRING, DLG_NULL, 4 ); + _m->begin(); + _m->prompt( 66, 3, "Es. " ); + _m->flag( "D" ); + _m->group( 9 ); + _m->end(); + + _m->control( T_STRING, DLG_NULL, 6 ); + _m->begin(); + if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) + _m->prompt( 2, 4, "Cliente " ); + else + _m->prompt( 2, 4, "Fornitore " ); + _m->flag( "D" ); + _m->group( 10 ); + _m->end(); + + _m->control( T_STRING, DLG_NULL, 50 ); + _m->begin(); + _m->prompt( 24, 4, "" ); + _m->flag( "D" ); + _m->group( 11 ); + _m->end(); + +} + +void TMask_generator::genera( ) +{ + int i; + + // Definizione della toolbar + + + _m->outline( "TOOLBAR \"\" 0 20 0 2" ); + _m->outline( "BU 18 8 2" ); + _m->begin(); + _m->prompt( -15, -1, "~Registra" ); + _m->message( "EXIT,20082" ); + _m->end(); + + _m->outline( "BU 17 8 2" ); + _m->begin(); + _m->prompt( -25, -1, "~Elimina" ); + _m->message( "EXIT,127" ); + _m->end(); + + _m->outline( "BU 99 8 2" ); + _m->begin(); + _m->prompt( -35, -1, "E~labora" ); + _m->message( "EXIT,345" ); + _m->end(); + + _m->outline( "BU 24 8 2" ); + _m->begin(); + _m->prompt( -45, -1 ); + _m->message( "EXIT,346" ); + _m->end(); + + _m->outline( "BU 2 8 2" ); + _m->begin(); + _m->prompt( -55, -1 ); + _m->message( "EXIT,27" ); + _m->end(); + + // End della toolbar + _m->end(); + + + // Header della prima pagina + + _m->outline( "PA \"Pagina \" 11 60 14" ); + + _m->control( T_GROUPBOX, DLG_NULL, 7806 ); + _m->begin( ); + _m->prompt( 1, 0, "" ); + _m->end( ); + + _m->control( T_STRING, F_CODNUM, 4 ); + _m->begin(); + _m->prompt( 2, 1, "Cod. num. " ); + _m->field( "CODNUM" ); + _m->flag( "GDUZ" ); + _m->message( "CO,2@" ); + _m->end(); + + _m->control( T_STRING, F_DESNUM, 50 ); + _m->begin(); + _m->prompt( 24, 1 ); + _m->flag( "GDU" ); + _m->message( "CO,3@" ); + _m->end(); + + _m->control( T_STRING, F_TIPODOC, 4 ); + _m->begin(); + _m->prompt( 2, 2, "Tipo doc. " ); + _m->flag( "GDU" ); + _m->message( "CO,4@" ); + _m->end(); + + _m->control( T_STRING, F_TIPOCF, 1 ); + _m->begin(); + _m->prompt( 2, 2, "Tipo CF " ); + _m->flag( "H" ); + _m->end(); + + _m->control( T_STRING, F_DESTIPODOC, 50 ); + _m->begin(); + _m->prompt( 24, 2 ); + _m->flag( "GDU" ); + _m->message( "CO,5@" ); + _m->end(); + + _m->control( T_NUMBER, F_NDOC, 6 ); + _m->begin(); + _m->prompt( 2, 3, "Doc.: nr. " ); + _m->message( "CO,6@" ); + _m->flag( "GDR" ); + _m->end(); + + _m->control( T_DATE, F_DATADOC ); + _m->begin(); + _m->prompt( 24, 3, "Data " ); + _m->message( "CO,7@" ); + _m->flag( "" ); + _m->end(); + + _m->control( T_NUMBER, F_STATO, 1 ); + _m->begin(); + _m->prompt( 50, 3, "Stato " ); + _m->message( "CO,8@" ); + _m->flag( "D" ); + _m->end(); + + _m->control( T_STRING, F_ANNO, 4 ); + _m->begin(); + _m->prompt( 66, 3, "Es. " ); + _m->flag( "GD" ); + _m->message( "CO,9@" ); + _m->end(); + + _m->control( T_STRING, F_CODCF, 6 ); + _m->begin(); + if ( _pro->get( "TIPOCF", "MAIN" ) == "C" ) + _m->prompt( 2, 4, "Cliente " ); + else + _m->prompt( 2, 4, "Fornitore " ); + _m->flag( "" ); + _m->message( "CO,10@" ); + _m->end(); + + _m->control( T_STRING, F_DESCF, 50 ); + _m->begin( ); + _m->prompt( 24, 4, "" ); + _m->flag( "" ); + _m->message( "CO,11@" ); + _m->end(); + + _m->line( MASK_FIRST_LINE ); + + // Generazione + + // Scorro l'array dei campi, per vedere gli stati ed i gruppi + + TArray campi; + TAssoc_array gruppi; + + carica_dati_campi( "ve0300a.ini", campi ); + int last = campi.items( ); + for( i = 0; i < last; i ++ ) + { + TString nome = (( TField & )campi[ i ]).nome( ); + int stato = stato_del_campo( nome ); + if( stato != FS_HIDDEN ) + { + const int addgruppo = (( TField & )campi[ i ]).gruppo( ); + TString16 chiave; + chiave.format( "%5d", addgruppo ); + if ( !gruppi.is_key( chiave ) ) + gruppi.add( chiave, new TGruppo( addgruppo, _groupsini ) ); + } + (( TField & )campi[ i ]).stato( stato ); + }; + campi.sort( sort_by_group ); + + // Generazione vera e propria + _m->_pageopen = TRUE; + last = campi.items( ); + int curgruppo = 0; + for( i = 0; i < last; i ++ ) + { + if ( _m->_pageopen == FALSE) + { + intestazione_pagina( ); + _m->_pageopen = TRUE; + } + TField& campo = ( TField& ) campi[ i ]; + if ( campo.gruppo( ) != curgruppo ) + { + TString16 chiave; + chiave.format( "%5d", campo.gruppo( ) ); + if ( gruppi.is_key( chiave ) ) + { + TGruppo& gruppo = ( TGruppo& ) gruppi[ chiave ]; + if ( _m->line( ) + gruppo.height( ) > MAX_LINES_PER_PAGE ) + { + _m->end( ); + intestazione_pagina( ); + _m->line( MASK_FIRST_LINE ); + } + else + { + TString16 vecchiachiave; + vecchiachiave.format( "%5d", curgruppo ); + if ( gruppi.is_key( vecchiachiave ) ) + { + _m->line( _m->line( ) + ( ( TGruppo& ) gruppi[ vecchiachiave ]).height( ) ); + } + } + }; + curgruppo = campo.gruppo( ); + }; + campo.configura( *_pro ); + campo.genera( *_m ); + } + if ( _m->_pageopen == TRUE ) _m->end( ); + intestazione_pagina( ); + + // Generazione del listbox per i tipi di riga da aggiungere nello sheet + _m->control ( T_LISTBOX, F_LBTIPORIGA, 30 ); + _m->begin(); + _m->prompt( 2, 7, "Tipo riga da aggiungere " ); + _m->end( ); + + // Generazione dello sheet : vedi il profilo + TScanner sheet_in( "ve0300b.dat" ); + _m->_out << "SPREADSHEET " << F_SHEET << "\n"; + _m->begin(); + _m->prompt( 2, 8 ); + for( i = 0; i < _tab0300b.items( ); i ++ ) + genera_item_sheet( _tab0300b.row( i ) ); + _m->end(); + _m->end(); + + // Generazione pagina dei piedi + TToken_string s(_pro->get( "PROGPIEDE", "MAIN" ) ); + if ( s.not_empty() ) + { + intestazione_pagina( ); + int cp = 1; + int piede = s.get_int();; + while ( piede != 0 ) + { + _m->control( T_NUMBER, BASE_PIEDE + cp, 1805 ); + _m->begin(); + TString header = _ditta.get( "PIEDE", "ve", piede ); + while( header.len() < 40 ) header << " "; + _m->prompt( 2, 7 + cp, header ); + _m->flag( "D" ); + _m->end(); + cp ++; + piede = s.get_int(); + } + _m->end(); + }; + _m->endmask( ); + + // Stategia al 30/06/95 + // Creo una maschera con tutte le colonne, poi, a RUNTIME, + // dal motore, nascondo e adatto le colonne. + + // Generazione maschera dello sheet + _m->_out << "PA \"Pagina 1\" 8 5 64 13\n"; + + id( 101 ); + for( i = 0; i < _tab0300b.items( ); i ++ ) + genera_campo_sheet( _tab0300b.row( i ) ); + _m->end(); + _m->end(); + _m->endmask( ); +} + + +// Applicazione guscio + +class TGenMask_application : public TApplication +{ + +protected: + + virtual bool create( ); + virtual bool menu( MENU_TAG _m ); + +}; + + +bool TGenMask_application::menu(MENU_TAG _m) +{ + TMask_generator a( argv( 2 ) ); + a.genera( ); + return( TRUE ); +}; + +bool TGenMask_application::create( ) +{ + TApplication::create(); + menu( 0 ); + return FALSE; +}; + +int ve0300( int argc, char** argv ) +{ + + if ( argc < 3 ) + fatal_box( "Sintassi: VE0 -3 " ); + + TGenMask_application a; + a.run ( argc, argv, "Generazione in corso ..." ); + return 0; +}