b1210fb257
git-svn-id: svn://10.65.10.50/trunk@1705 c028cbd2-c16b-5b4b-a496-9718f37d4682
902 lines
25 KiB
C++
Executable File
902 lines
25 KiB
C++
Executable File
#include <xvt_defs.h>
|
|
|
|
#ifndef __CHECKS_H
|
|
#include <checks.h>
|
|
#endif
|
|
|
|
#ifndef __TABUTIL_H
|
|
#include <tabutil.h>
|
|
#endif
|
|
|
|
#ifndef __BRWAPP_H
|
|
#include <brwapp.h>
|
|
#endif
|
|
|
|
#ifndef __RELAPP_H
|
|
#include <relapp.h>
|
|
#endif
|
|
|
|
#ifndef __CONFIG_H
|
|
#include <config.h>
|
|
#endif
|
|
|
|
#ifndef __LFFILES_H
|
|
#include <lffiles.h>
|
|
#endif
|
|
|
|
#ifndef __DEFMASK_H
|
|
#include "defmask.h"
|
|
#endif
|
|
|
|
#ifndef __VEUML_H
|
|
#include "f:\u\alex\p.due\ve\VEUML.H"
|
|
#endif
|
|
|
|
#ifndef __SHEET_H
|
|
#include <sheet.h>
|
|
#endif
|
|
|
|
#ifndef __REAL_H
|
|
#include <real.h>
|
|
#endif
|
|
|
|
#ifndef __MSKSHEET_H
|
|
#include <msksheet.h>
|
|
#endif
|
|
|
|
#ifndef __VE0100_H
|
|
#include "VE0100.H"
|
|
#endif
|
|
|
|
#ifndef __VE0100C_H
|
|
#include "VE0100C.H"
|
|
#endif
|
|
|
|
#ifndef __VE0100D_H
|
|
#include "VE0100D.H"
|
|
#endif
|
|
|
|
// Handlers per i campi delle bolle
|
|
|
|
extern bool ora_hndl(TMask_field& field, KEY key);
|
|
extern bool codcli_hndl(TMask_field& field, KEY key);
|
|
extern bool dummy_hndl(TMask_field& field, KEY key);
|
|
|
|
// Numero di colonne presenti sullo sheet totale
|
|
#define MAX_COLUMNS 22
|
|
|
|
#define F_LBTIPORIGA 175
|
|
#define F_TIPIDOCS 172
|
|
|
|
// 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);
|
|
virtual void init_query_mode(TMask&);
|
|
|
|
// 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( 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" ) );
|
|
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( int r, KEY key )
|
|
{
|
|
if ( key == K_INS )
|
|
{
|
|
TMask m( "ve1000b" );
|
|
TList_field& listbox = ( TList_field& ) m.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( );
|
|
tabtr.put( "CODTAB", app( ).pro( ).get( chiave, "RIGHE" ) );
|
|
tabtr.read( );
|
|
keys.add( tabtr.get( "CODTAB" ) );
|
|
descrs.add( tabtr.get( "S0" ) );
|
|
}
|
|
listbox.replace_items( keys, descrs );
|
|
if( m.run( ) == K_ESC ) return FALSE;
|
|
tabtr.put( "CODTAB", m.get( F_LBTIPORIGA ) );
|
|
tabtr.read( );
|
|
TToken_string& riga = app( ).sheet( ).row( r );
|
|
riga.add( 1, 0 );
|
|
riga.add( m.get( F_LBTIPORIGA ), 1 );
|
|
riga.add( tabtr.get( "S4" ), 2 );
|
|
app( ).sheet( ).force_update( );
|
|
return TRUE;
|
|
}
|
|
return TRUE;
|
|
};
|
|
|
|
bool TMotore_application::num_handler( TMask_field& f, KEY key )
|
|
{
|
|
TMask& m = f.mask( );
|
|
if (key == K_TAB && m.is_running( ) )
|
|
{
|
|
TTable tabnum( "NUM" );
|
|
|
|
tabnum.read( );
|
|
m.set(F_DESNUM, tabnum.get("S0") );
|
|
m.set(F_TIPIDOCS, tabnum.get("S2") );
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMotore_application::tip_handler(TMask_field& f, KEY key)
|
|
{
|
|
TMask& m = f.mask( );
|
|
if (key == K_TAB && m.is_running( ) )
|
|
{
|
|
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_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 );
|
|
}
|
|
}
|
|
/* m.set( F_TIPODOC, doc.get( "TIPODOC" );
|
|
TTable tabtip( "TIP" );
|
|
tabtip.read( );
|
|
m.set(F_PROFILO, tabtip.get("S4") );
|
|
}
|
|
else
|
|
{ TString tipodoc = m.get( F_TIPODOC );
|
|
if ( ! f.blank( ) )
|
|
{ message_box( "Per inserire un nuovo documento occorre\nspecificare il tipo documento!" );
|
|
m.first_focus( F_TIPODOC );
|
|
return FALSE;
|
|
}
|
|
}
|
|
} */
|
|
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 i;
|
|
const int ncols = config.get_int( "NCOLS", "SHEET" );
|
|
for( i = 1; i <= ncols; i ++ )
|
|
{ TString col;
|
|
col.format( "%d", i );
|
|
TToken_string sheet_col( config.get( col, "SHEET" ) );
|
|
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 ) );
|
|
sheet.move_column( sheet_col.get_int( 0 ) - 1, 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 );
|
|
sheet( ).set_getmask( ss_getmask );
|
|
int numhandler = pro( ).get_int( "NHANDLER", "HANDLERS" );
|
|
for( int 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( );
|
|
}
|
|
|
|
void TMotore_application::init_query_mode(TMask& _mask)
|
|
{
|
|
_mask.disable( DLG_NEWREC );
|
|
}
|
|
|
|
const char* TMotore_application::get_next_key( )
|
|
{
|
|
TToken_string _t;
|
|
|
|
_t.add( F_CODNUM );
|
|
_t.add( query_mask( ).get( F_CODNUM ) );
|
|
_t.add( F_ANNO );
|
|
_t.add( query_mask( ).get( F_ANNO ) );
|
|
_t.add( F_PROVV );
|
|
_t.add( query_mask( ).get( F_PROVV ) );
|
|
_t.add( F_NDOC );
|
|
_t.add( prossimo_numero( query_mask( ).get( F_PROVV ) == "P" ) );
|
|
return( _t );
|
|
}
|
|
|
|
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 ) );
|
|
}
|
|
|
|
/*
|
|
void TMotore_application::read_rdoc(TMask& m)
|
|
{
|
|
|
|
TLocalisamfile& rdoc = rel( ).lfile(LF_RIGHEDOC);
|
|
|
|
TString16 _cod_num = rel( ).lfile( ).get( "CODNUM" );
|
|
bool _provv(query_mask( ).get_bool(F_PROVV));
|
|
TString16 _anno(query_mask( ).get(F_ANNO));
|
|
TString16 _ndoc(query_mask( ).get(F_NDOC));
|
|
rdoc.zero( );
|
|
rdoc.put("CODNUM", _cod_num);
|
|
rdoc.put("PROVV", _provv);
|
|
rdoc.put("ANNO", _anno);
|
|
rdoc.put("NDOC", _ndoc);
|
|
// loop per il caricamento delle righe
|
|
for ( int err = rdoc.read(_isgteq); err == NOERR && check_key(rdoc,_cod_num,_provv, _anno, _ndoc ); err = rdoc.next( ) )
|
|
{ const numrig = rdoc.get_int( "NRIGA" );
|
|
CHECK(numrig > 0, "Documento con numero di riga nullo!!");
|
|
const int TipoRiga = rdoc.get_int( "TIPORIGA" );
|
|
const TString16 Codart = rdoc.get( "CODART" );
|
|
const TString Descr = rdoc.get( "DESCR" );
|
|
const TString16 UmQta = rdoc.get( "UMQTA" );
|
|
const real Qta = rdoc.get_real( "QTA" );
|
|
// add_riga(numrig-1, TipoRiga, (TString &)Codart, (TString &)Descr, (TString &)UmQta, Qta);
|
|
// calcola_riga( rdoc );
|
|
}
|
|
}
|
|
*/
|
|
|
|
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;
|
|
};
|
|
|
|
// int TMotore_application::nuovo_documento( )
|
|
// {
|
|
//
|
|
// };
|
|
|
|
/*int TMotore_application::modifica_documento( )
|
|
{
|
|
KEY k;
|
|
|
|
edit_mask( ).autoload( _rel );
|
|
k = edit_mask( ).run( );
|
|
if ( k == K_SAVE )
|
|
{
|
|
if ( esegui_procedura( pro( ).indice_procedura( OP_MODIFICA ) ) != NOERR )
|
|
return FALSE;
|
|
edit_mask( ).autosave( _rel );
|
|
rel( ).rewrite( );
|
|
};
|
|
modify_mode( );
|
|
return NOERR;
|
|
};*/
|
|
|
|
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= "";
|
|
// riga.add( r.get( "NRIGA" ) );
|
|
riga = r.get( "STATORIGA" );
|
|
riga.add( r.get( "TIPORIGA" ) );
|
|
|
|
/*
|
|
switch(r.get_int( "TIPORIGA" ) )
|
|
{ case 1: riga.add("Merce"); break;
|
|
case 2: riga.add("Articolo Merce"); break;
|
|
case 3: riga.add("Spese"); break;
|
|
case 4: riga.add("Commento"); break;
|
|
case 5: riga.add("Omaggio"); break;
|
|
default: riga.add("Tipo Errato"); break;
|
|
}*/
|
|
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( "NRIGA", riga.get( 0 ) );
|
|
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( );
|
|
// Carico la maschera di ricerca dei documenti
|
|
_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;
|
|
}
|