/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * "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 XVT_INCL_DEFS #include #endif #include "\prassi\veuml.h" #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 // 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 // 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 _tab0300a #define A_NOME 0 #define A_FILEFLD 1 #define A_MSKFLD 2 #define A_MSKTYPE 3 #define A_DESCR 4 #define A_MSKSIZE 5 #define A_FLAG 6 #define A_USE 7 #define A_INPUT 8 #define A_DISPLAY 9 #define A_OUTPUT 10 #define A_SPECIAL 11 #define A_ITEMS 12 // 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 // Numero massimo di linee per pagina #define MAX_LINES_PER_PAGE 14 class TMask_generator { private: // Identificatore corrente per lo sheet int _curid; // Linea corrente int _curline; // Pagina corrente int _curpage; // Vero se la pagina è aperta bool _pageopen; // nome del file di .INI di input TFilename _proname; // File .INI di input TConfig* _pro; // File .MSK di output ofstream* _out; // Ultima linea letta TToken_string _line; // Tabelle per la generazione // Campi dei documenti TString_array _tab0300a; // 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( )); }; // Funzioni per generare la maschera // --------------------------------- // 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"; }; // 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 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 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; }; // 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( ); public: // 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 ) { // All'inizio la pagina è 'chiusa' _pageopen = FALSE; // La pagina iniziale è la 1 _curpage = 1; // La linea iniziale è la 8 _curline = 8; // 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!", _proname ); CHECK( fexist( "ve0300a.dat" ), "Il file ve0300a.dat non esiste!" ); carica_tabella( "ve0300a.dat", _tab0300a ); CHECK( fexist( "ve0300b.dat" ), "Il file ve0300b.dat non esiste!" ); carica_tabella( "ve0300b.dat", _tab0300b ); }; TMask_generator::~TMask_generator( ) { delete _out; }; 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(); } }; void TMask_generator::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 TMask_generator::check( const int i ) { switch( i ) { case FS_REQUIRED: outline ( "CH REQUIRED" ); break; default: outline ( "CH NORMAL" ); break; } }; void TMask_generator::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; }; (*_out) << " " << id; if ( size > 0 ) if ( size > 100 ) (*_out) << " " << ( int )( size / 100 ) << " " << ( size % 100 ); else (*_out) << " " << size; (*_out) << "\n"; }; void TMask_generator::item( const TString& str ) { int i, j; TToken_string u( str, '~' ); TString s, mess; for( i = 0; i < u.items(); i ++ ) { s = u.get( i ); if ( ( j = s.find( "£" ) ) != -1 ) { mess = s.mid( j + 1 ); s = s.left( j ); }; if ( ( j = s.find ( "§" ) ) != -1 ) s[ j ] = '|'; (*_out) << "IT \"" << s << "\"\n"; if ( mess.not_empty( ) ) (*_out) << "ME " << mess << "\n"; } } void TMask_generator::genera_campo_sheet( TToken_string _line ) { const int type( _line.get_int( B_MSKTYPE ) ); control( type, id( ), _line.get_int( B_MSKSIZE ) ); begin( ); prompt( 2, 2 ); end( ); } void TMask_generator::genera_item_sheet( TToken_string _line ) { (*_out) << "IT \"" << _line.get( B_DESCR ); (*_out) << "@" << _line.get_int( B_WIDTH ) << "\"\n"; } void TMask_generator::genera_campo( TToken_string _line ) { TString s; const int type( _line.get_int( A_MSKTYPE ) ); const int size( _line.get_int( A_MSKSIZE ) ); if ( present( A_MSKSIZE, _line ) ) control( type, _line.get_int( A_MSKFLD ), size ); else control( type, _line.get_int( A_MSKFLD ) ); begin(); TString name( _line.get( A_NOME ) ); name.trim(); int value = _pro->get_int( name, "PROFILO" ); switch( value ) { case FS_HIDDEN: prompt( 2, 2 ); s = "H"; s << _line.get( A_FLAG ); flag( s ) ; break; case FS_DISABLED : prompt( 2, line( ), _line.get( A_DESCR ) ); s = "D"; s << _line.get( A_FLAG ); flag( s ) ; line( line( ) + 1 ); break; case FS_NORMAL : case FS_REQUIRED : prompt( 2, line( ), _line.get( A_DESCR ) ); flag( _line.get( A_FLAG ) ); line( line( ) + 1 ); break; } const TString chiave( _line.get( A_NOME ) ); check( _pro->get_int( chiave, "PROFILO" ) ); if ( present( A_FILEFLD, _line ) ) field( _line.get( A_FILEFLD ) ); if ( present( A_ITEMS, _line ) ) item( _line.get( A_ITEMS ) ); if ( present( A_USE, _line ) ) use( _line.get( A_USE ) ); if ( present( A_INPUT, _line ) ) input( _line.get( A_INPUT ) ); if ( present( A_DISPLAY, _line ) ) display( _line.get( A_DISPLAY ) ); if ( present( A_OUTPUT, _line ) ) output( _line.get( A_OUTPUT ) ); if ( present( A_SPECIAL, _line ) ) outline( _line.get( A_SPECIAL ) ); end(); if ( ( line() > MAX_LINES_PER_PAGE ) && ( _pageopen == TRUE)) { end(); _pageopen = FALSE; line( 8 ); }; } void TMask_generator::intestazione_pagina( ) { page( page( ) + 1 ); pagina( page( ) ); (*_out) << "GR " << DLG_NULL << " 77 4\n"; begin(); prompt( 1, 1 ); end(); control( T_STRING, DLG_NULL, 4 ); begin(); prompt( 2, 2, "Codice numerazione " ); group( 2 ); flag( "DUZ" ); end(); control( T_STRING, DLG_NULL, 40 ); begin(); prompt( 32, 2 ); flag( "DU" ); group( 3 ); end(); control( T_STRING, DLG_NULL, 12 ); begin(); prompt( 32, 3, "Profilo :" ); flag( "DU" ); group( 4 ); end(); control( T_STRING, DLG_NULL, 4 ); begin(); prompt( 2, 3, "Esercizio " ); flag( "D" ); group( 5 ); end(); control( T_LISTBOX, DLG_NULL, 14 ); begin(); prompt( 32, 5, "Numerazione " ); item( "P§Provvisoria" ); item( "D§Definitiva " ); flag( "D" ); group( 6 ); end(); control( T_NUMBER, DLG_NULL, 7 ); begin(); prompt( 2, 5, "Numero documento " ); group( 7 ); flag( "DZ" ); end(); control( T_NUMBER, DLG_NULL, 1 ); begin(); prompt( 2, 6, "Stato corrente " ); group( 8 ); flag( "D" ); end(); control( T_DATE ); begin(); prompt( 51, 6, "Data documento " ); group( 9 ); flag( "D" ); end(); } void TMask_generator::genera( ) { int i; _pro = new TConfig( _proname ); TFilename _mskname( _pro->get( "MSKFILE", "MAIN") ); _mskname.ext( "msk" ); _out = new ofstream( _mskname ); // Definizione della toolbar outline( "TOOLBAR \"\" 0 20 0 2" ); outline( "BU 18 8 2" ); begin(); prompt( -15, -1, "~Registra" ); message( "EXIT,20082" ); end(); outline( "BU 17 8 2" ); begin(); prompt( -25, -1, "~Elimina" ); message( "EXIT,127" ); end(); outline( "BU 99 8 2" ); begin(); prompt( -35, -1, "E~labora" ); message( "EXIT,345" ); end(); outline( "BU 24 8 2" ); begin(); prompt( -45, -1 ); message( "EXIT,346" ); end(); outline( "BU 2 8 2" ); begin(); prompt( -55, -1 ); message( "EXIT,27" ); end(); // End della toolbar end(); // Header della prima pagina outline( "PA \"Pagina \" 11 60 14" ); (*_out) << "GR " << DLG_NULL << " 77 4\n"; begin(); prompt( 1, 1 ); end(); control( T_STRING, F_CODNUM, 4 ); begin(); prompt( 2, 2, "Codice numerazione " ); field( "CODNUM" ); flag( "GDUZ" ); message( "CO,2@" ); end(); control( T_STRING, F_DESNUM, 40 ); begin(); prompt( 32, 2 ); flag( "GDU" ); message( "CO,3@" ); end(); control( T_STRING, F_PROFILO, 12 ); begin(); prompt( 32, 3, "Profilo :" ); flag( "GDU" ); message( "CO,4@" ); end(); control( T_STRING, F_ANNO, 4 ); begin(); prompt( 2, 3, "Esercizio " ); field( "ANNO" ); flag( "GD" ); message( "CO,5@" ); end(); control( T_LISTBOX, F_PROVV, 14 ); begin(); prompt( 32, 5, "Numerazione " ); field( "PROVV" ); item( "P§Provvisoria£CO,6@" ); item( "D§Definitiva £CO,6@" ); end(); control( T_NUMBER, F_NDOC, 7 ); begin(); prompt( 2, 5, "Numero documento " ); field( "NDOC" ); message( "CO, 7@" ); flag( "Z" ); end(); control( T_NUMBER, F_STATO, 1 ); begin(); prompt( 2, 6, "Stato corrente " ); field( "STATO" ); message( "CO,8@" ); flag( "GD" ); end(); control( T_DATE, F_DATADOC ); begin(); prompt( 51, 6, "Data documento " ); message( "CO,9@" ); field( "DATADOC" ); end(); // Generazione _pageopen = TRUE; for( i = 0; i < _tab0300a.items( ); i ++ ) { if (_pageopen == FALSE) { intestazione_pagina( ); _pageopen = TRUE; } genera_campo( _tab0300a.row( i ) ); } if ( _pageopen == TRUE ) end( ); intestazione_pagina( ); // Generazione dello sheet : vedi il profilo TScanner sheet_in( "ve0300b.dat" ); (*_out) << "SPREADSHEET " << F_SHEET << "\n"; begin(); prompt( 2, 7 ); for( i = 0; i < _tab0300b.items( ); i ++ ) genera_item_sheet( _tab0300b.row( i ) ); end(); end(); // Generazione pagina dei piedi TToken_string s(_pro->get( "PROGPIEDE", "MAIN" ) ); if ( s.not_empty() ) { intestazione_pagina( ); TConfig ditta(CONFIG_DITTA); int cp = 1; int piede = s.get_int();; while ( piede != 0 ) { control( T_NUMBER, BASE_PIEDE + cp, 1805 ); begin(); TString header = ditta.get( "PIEDE", "ve", piede ); while( header.len() < 40 ) header << " "; prompt( 2, 7 + cp, header ); flag( "D" ); end(); cp ++; piede = s.get_int(); } end(); }; 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 (*_out) << "PA \"Pagina 1\" 8 5 64 13\n"; id( 101 ); for( i = 0; i < _tab0300b.items( ); i ++ ) genera_campo_sheet( _tab0300b.row( i ) ); end(); end(); endmask( ); delete _pro; delete _out; } // 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; }