909 lines
		
	
	
		
			25 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			909 lines
		
	
	
		
			25 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#ifndef __VE0100_H
 | 
						|
#include "ve0100.h"
 | 
						|
#endif                    
 | 
						|
 | 
						|
#ifndef __VE0100O_H
 | 
						|
#include "ve0100o.h"                                                      
 | 
						|
#endif                    
 | 
						|
 | 
						|
#ifndef __VEINI_H
 | 
						|
#include "veini.h"
 | 
						|
#endif                    
 | 
						|
 | 
						|
#ifndef __MGLIB_H
 | 
						|
#include "..\mg\mglib.h"
 | 
						|
#endif                    
 | 
						|
 | 
						|
#ifndef __UTILITY_H
 | 
						|
#include "utility.h"
 | 
						|
#endif                    
 | 
						|
 | 
						|
void TMotore_application::init_query_mode( TMask& m )
 | 
						|
{
 | 
						|
     _msk->set( F_CODNUM, _codnum); 
 | 
						|
     _msk->field(F_CODNUM).set_focusdirty(TRUE);
 | 
						|
     _msk->field(F_CODNUM).on_key(K_TAB);
 | 
						|
     _msk->field(F_CODNUM).set_dirty(FALSE);
 | 
						|
     
 | 
						|
     _msk->set( F_TIPODOC, _tipodoc, TRUE); 
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::init_insert_mode( TMask& m )
 | 
						|
{
 | 
						|
  TString tipocf( "A" );
 | 
						|
  tipocf[ 0 ] = app().tipocf();  
 | 
						|
 | 
						|
  const TString16 codnum(m.get(F_CODNUM));
 | 
						|
  const int anno = m.get_int(F_ANNO);
 | 
						|
  const char provv = m.get(F_PROVV)[0];
 | 
						|
  const long numdoc = m.get_long(F_NDOC);
 | 
						|
  
 | 
						|
  _doc->read(provv, anno, codnum, numdoc);
 | 
						|
  _doc->set_tipo(m.get(F_TIPODOC));
 | 
						|
  
 | 
						|
  _codnum = codnum;
 | 
						|
  _tipodoc = m.get(F_TIPODOC);
 | 
						|
  
 | 
						|
 | 
						|
  m.field(F_CODNUM).set_focusdirty(TRUE);
 | 
						|
  m.field(F_CODNUM).on_key(K_TAB);
 | 
						|
  m.field(F_TIPODOC).set_focusdirty(TRUE);
 | 
						|
  m.field(F_TIPODOC).on_key(K_TAB);
 | 
						|
  m.set(F_STATO, _doc->head().get("STATO"));
 | 
						|
  const TString16 data_doc(m.get( F_DATADOC));
 | 
						|
    
 | 
						|
  const int pos = m.id2pos( F_DATACAMBIO1);
 | 
						|
  
 | 
						|
  if (pos >= 0 && m.fld(pos).active())
 | 
						|
    m.fld(pos).set(data_doc);    
 | 
						|
  m.disable(DLG_PRINT);
 | 
						|
  _occas_mask->reset( );
 | 
						|
  const int ndefaults = pro( ).get_int( "NDEFAULTS", "DEFAULT" );          // prof
 | 
						|
  
 | 
						|
  for( int i = 1; i <= ndefaults; i++ )
 | 
						|
  {
 | 
						|
     TString16 chiave;
 | 
						|
     chiave.format( "%d", i );
 | 
						|
     TToken_string valore( pro( ).get( chiave, "DEFAULT" ) );
 | 
						|
     int campo( valore.get_int( 0 ) );
 | 
						|
     TString default_val( valore.get( 1 ) );
 | 
						|
     m.set( campo, default_val, TRUE );
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::init_modify_mode( TMask& m )
 | 
						|
{
 | 
						|
  m.enable(DLG_PRINT);
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::update_profile()
 | 
						|
{
 | 
						|
  TFilename fn(_doc->tipo().profile_name());
 | 
						|
  
 | 
						|
  fn.ext("ini");
 | 
						|
  if (_pro && _pro->name() != fn) 
 | 
						|
  {
 | 
						|
    delete _pro;    
 | 
						|
    _pro = NULL;
 | 
						|
  }
 | 
						|
  if (_pro == NULL) 
 | 
						|
    _pro =  new TConfig( fn );
 | 
						|
}
 | 
						|
 | 
						|
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 NOERR;
 | 
						|
      break;
 | 
						|
  }
 | 
						|
  return NOERR;      
 | 
						|
}
 | 
						|
 | 
						|
// Funzione che dato il profilo di riga ottiene la maschera
 | 
						|
// Serve per ottenere una maschera diversa per ogni riga
 | 
						|
TMask * TMotore_application::ss_getmask( int numriga, TMask& fullmask)
 | 
						|
{     
 | 
						|
  const int n = numriga + 1;
 | 
						|
  if (n <= app()._doc->physical_rows())
 | 
						|
  {
 | 
						|
    TRiga_documento & riga = (*(app()._doc))[numriga + 1];
 | 
						|
      
 | 
						|
    return ((TTipo_riga_documento &)riga.tipo()).mask(); 
 | 
						|
  }
 | 
						|
  else
 | 
						|
    return & fullmask;
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::user_set_handler( int fieldid, int index, TMask* m )
 | 
						|
{
 | 
						|
  if ( !m )
 | 
						|
    m = &edit_mask( );
 | 
						|
  switch( index )
 | 
						|
  { 
 | 
						|
  case 1:
 | 
						|
    m->set_handler( fieldid, ora_hndl );
 | 
						|
    break;
 | 
						|
  case 3:
 | 
						|
    m->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_ENTER ) // modifica
 | 
						|
  {
 | 
						|
    TRiga_documento & riga = (*(app()._doc))[r + 1];
 | 
						|
    
 | 
						|
    riga.autosave(ss);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    if ( key == K_DEL ) // Cancellazione 
 | 
						|
    {
 | 
						|
      app()._doc->destroy_row(r + 1, TRUE);
 | 
						|
      if (r < app()._doc->rows())
 | 
						|
      {
 | 
						|
        TRiga_documento & riga = (*(app()._doc))[r + 1];
 | 
						|
        if (riga.tipo().tipo() == RIGA_OMAGGI && riga.generata())
 | 
						|
        {
 | 
						|
          ss.destroy(r + 1);
 | 
						|
          app()._doc->destroy_row(r + 1, TRUE);
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
    else
 | 
						|
      if (key == K_INS) // Inserimento              
 | 
						|
      {
 | 
						|
        if (r < app()._doc->rows())
 | 
						|
        {
 | 
						|
          TRiga_documento & riga = (*(app()._doc))[r + 1];
 | 
						|
          if (riga.tipo().tipo() == RIGA_OMAGGI && riga.generata())
 | 
						|
            return FALSE;
 | 
						|
        }
 | 
						|
        TMask & emask = app().edit_mask();             
 | 
						|
        app()._doc->insert_row(r + 1, emask.get( F_LBTIPORIGA ));
 | 
						|
      }
 | 
						|
      else     
 | 
						|
        if (key == K_CTRL + K_INS)
 | 
						|
        {
 | 
						|
          TRiga_documento & riga = (*(app()._doc))[r + 1];
 | 
						|
          TRectype & ven_rec = app().doc().clifor().vendite();
 | 
						|
          TString16 s(ven_rec.get(CFV_CODMAG));
 | 
						|
          
 | 
						|
          s << ven_rec.get(CFV_CODDEP);
 | 
						|
          riga.put("CODMAG", s);
 | 
						|
          riga.autoload(ss);     
 | 
						|
          ss.check_row(r);
 | 
						|
          ss.select(r);
 | 
						|
        }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::num_handler( TMask_field& f, KEY key )
 | 
						|
{                       
 | 
						|
  // Ottengo la maschera             
 | 
						|
  TMask& m = f.mask( ); 
 | 
						|
  
 | 
						|
  if (key == K_TAB && f.focusdirty())
 | 
						|
  {                          
 | 
						|
    TTable & tabnum  = ((TTable &) ((TEdit_field &)f).browse()->cursor()->file());
 | 
						|
    if ( tabnum.good()) 
 | 
						|
    {
 | 
						|
      // Copio la descrizione 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 );
 | 
						|
      TString16 curtipo( m.get( F_TIPODOC ) );
 | 
						|
          
 | 
						|
        // Propone il primo tipo di documento come default
 | 
						|
      m.set( F_TIPODOC, tipidocs.left( 4 ) );
 | 
						|
      m.send_key( K_TAB, F_TIPODOC );
 | 
						|
      // Se per questa numerazione h 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 );
 | 
						|
      }             
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {                 
 | 
						|
      m.set( F_DESNUM, "" );
 | 
						|
      m.set( F_TIPIDOCS, "" );
 | 
						|
      m.set( F_TIPODOC, "" );
 | 
						|
    }
 | 
						|
  } 
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::elabora_handler( TMask_field& f, KEY key )
 | 
						|
{          
 | 
						|
  if (key == K_SPACE)
 | 
						|
  {     
 | 
						|
    return message_box("Funzione in fase di implementazione");
 | 
						|
    TString_array elabs;   
 | 
						|
    TMask & m = f.mask();
 | 
						|
    const TString16 tipo(m.get(F_TIPODOC));
 | 
						|
    const TString16 stato(m.get(F_STATO));
 | 
						|
    TLista_elaborazioni & elab = app().elab();
 | 
						|
    
 | 
						|
    elab.select(elabs, TRUE, m.insert_mode(), NULL, NULL, tipo, stato);
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::print_handler( TMask_field& f, KEY key )
 | 
						|
 | 
						|
{
 | 
						|
  if (key == K_SPACE)                       
 | 
						|
  {
 | 
						|
    TMask& m = f.mask();
 | 
						|
    
 | 
						|
    if (app().save(TRUE))   // Registra il record corrente
 | 
						|
    {
 | 
						|
      TString commandline("ve1 -0 ");
 | 
						|
      
 | 
						|
      commandline << m.get( F_CODNUM ) << " " << m.get( F_ANNO ) << " ";
 | 
						|
      commandline << m.get( F_PROVV )<< " " << m.get( F_NDOC );
 | 
						|
      
 | 
						|
      TExternal_app interattivo( commandline );
 | 
						|
      
 | 
						|
      interattivo.run( );
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::occas_code_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if (key == K_TAB && f.focusdirty())
 | 
						|
  {
 | 
						|
    const char* code = f.get();
 | 
						|
    if (*code)
 | 
						|
    {
 | 
						|
      TRelation occas(LF_OCCAS);
 | 
						|
      occas.lfile().put("CFPI", code);
 | 
						|
      if (occas.read(_isequal) == NOERR)
 | 
						|
      {
 | 
						|
        f.mask().autoload(occas);
 | 
						|
        f.mask().send_key(K_TAB, O_COMUNE);         // Forza decodifica comuni
 | 
						|
        f.mask().send_key(K_TAB, O_COMUNENAS);
 | 
						|
      }  
 | 
						|
    }
 | 
						|
  } 
 | 
						|
  return TRUE;
 | 
						|
}  
 | 
						|
 | 
						|
bool TMotore_application::occas_handler( TMask_field& f, KEY key )
 | 
						|
{
 | 
						|
  TDocumento_mask & m = (TDocumento_mask &)f.mask();
 | 
						|
  if ( key == K_SPACE && m.is_running( ) )
 | 
						|
  {   
 | 
						|
    TDocumento & doc = app().doc(); 
 | 
						|
    TMask * occ_m = app()._occas_mask;
 | 
						|
    TOccasionale & occ = doc.occas();  
 | 
						|
    TCli_for & cli_for = doc.clifor();
 | 
						|
    for (int i = occ_m->fields() - 1; i >= 0; i--)
 | 
						|
    {
 | 
						|
      TMask_field & f = occ_m->fld(i);
 | 
						|
      const TFieldref * c = f.field();
 | 
						|
      if (c)
 | 
						|
        f.set(c->read(occ));
 | 
						|
    } 
 | 
						|
    if (occ_m->run() != K_ESC)         
 | 
						|
    {
 | 
						|
      doc.put("OCFPI", occ_m->get(O_CODICE));
 | 
						|
      for (int i = occ_m->fields() - 1; i >= 0; i--)
 | 
						|
      {
 | 
						|
        TMask_field & f = occ_m->fld(i);
 | 
						|
        TFieldref * c = (TFieldref *) f.field();
 | 
						|
        if (c)
 | 
						|
          c->write(f.get(), occ);
 | 
						|
      } 
 | 
						|
      m.occ2mask(occ);
 | 
						|
    }
 | 
						|
    f.set_focus( );
 | 
						|
  }  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TMotore_application::tip_handler( TMask_field& f, KEY key )
 | 
						|
{                       
 | 
						|
  TMask& m = f.mask( );
 | 
						|
  if ( key == K_TAB && m.is_running( ) && m.get(F_TIPODOC).not_empty())
 | 
						|
  {                          
 | 
						|
    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;
 | 
						|
    }   
 | 
						|
  }
 | 
						|
  if ( key == K_ENTER && m.is_running( ) )
 | 
						|
  { TString tipo( f.get( ) );
 | 
						|
    if ( tipo.blank( ) )
 | 
						|
    { 
 | 
						|
      message_box( "Occorre un tipo documento per inserire un documento!" );
 | 
						|
      m.first_focus( F_TIPODOC );
 | 
						|
      return FALSE;
 | 
						|
    }
 | 
						|
  }             
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TMotore_application::clifo_handler( TMask_field& f, KEY key )
 | 
						|
{                
 | 
						|
  if (key != K_ENTER && f.to_check(key, TRUE))        
 | 
						|
  { 
 | 
						|
    TDocumento & d = app().doc();
 | 
						|
    TDocumento_mask & m = (TDocumento_mask &) f.mask();
 | 
						|
    const TString & val = f.get();
 | 
						|
  
 | 
						|
    d.put("TIPOCF", app().tipocf());
 | 
						|
    d.put("CODCF", atol(val));
 | 
						|
                                               
 | 
						|
    app().doc().clifor().put(CLI_CODCF, ""); // force reload
 | 
						|
    TCli_for & cli_for = app().doc().clifor(); 
 | 
						|
    TOccasionale & occas = app().doc().occas();
 | 
						|
      
 | 
						|
    if ( cli_for.get_bool("SOSPESO") )
 | 
						|
      return f.error_box( "Il codice '%ld' e' sospeso e non puo' essere utilizzato", atol(val) );  
 | 
						|
    m.cli2mask(cli_for, occas, *(app()._config_ditta));
 | 
						|
    if (cli_for.occasionale())
 | 
						|
    {
 | 
						|
      if(m.id2pos(F_OCCASEDIT) > 0 && f.to_check(key) && *(occas.codice()) == '\0')
 | 
						|
        m.send_key( K_SPACE, F_OCCASEDIT );   // Lancia maschera occasionali        
 | 
						|
    }
 | 
						|
    else      
 | 
						|
      app().doc().zero("OCFPI");
 | 
						|
  }  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
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 )
 | 
						|
{                    
 | 
						|
  TBit_array to_delete(MAX_COLUMNS);
 | 
						|
  to_delete.set();
 | 
						|
  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 int field_id = sheet_col.get_int(0);
 | 
						|
    const int coltomove = sheet.cid2index(field_id);
 | 
						|
    to_delete.reset(coltomove);
 | 
						|
 | 
						|
    const TString descr(sheet_col.get( 1 ));
 | 
						|
    
 | 
						|
    if (descr.not_empty() )
 | 
						|
      sheet.set_column_header( field_id, descr);
 | 
						|
 | 
						|
    const int size( sheet_col.get_int(2));
 | 
						|
 | 
						|
    if (size != 0)
 | 
						|
      sheet.set_column_width( field_id, size);
 | 
						|
  } 
 | 
						|
  to_delete.reset(0);
 | 
						|
  to_delete.reset(1);
 | 
						|
                
 | 
						|
  const int sconto_col = sheet.cid2index(FR_SCONTO);
 | 
						|
  if (to_delete[sconto_col] == FALSE)
 | 
						|
  {
 | 
						|
    const bool del = (_config_ditta->get("GESSCORIGA") == "N");
 | 
						|
  
 | 
						|
    to_delete.set(sconto_col, del);
 | 
						|
  }
 | 
						|
  
 | 
						|
  for ( i = MAX_COLUMNS - 1; i >= 0; i-- )
 | 
						|
     if( to_delete[i] )
 | 
						|
     {
 | 
						|
       sheet.enable_column( i + FIRST_FIELD, FALSE);
 | 
						|
       sheet.delete_column( i + FIRST_FIELD);
 | 
						|
     }
 | 
						|
}
 | 
						|
 | 
						|
TMask* TMotore_application::get_mask( int mode )
 | 
						|
{     
 | 
						|
  switch ( mode )
 | 
						|
  {
 | 
						|
    case MODE_INS: 
 | 
						|
    case MODE_MOD: 
 | 
						|
      {                
 | 
						|
        const TString16 tipodoc(_msk->get(F_TIPODOC)); 
 | 
						|
        
 | 
						|
        TDocumento_mask * msk1 = (TDocumento_mask *) _doc_masks.objptr(tipodoc);
 | 
						|
        
 | 
						|
        _doc->set_tipo(tipodoc);
 | 
						|
        update_profile();
 | 
						|
        
 | 
						|
        TString tipocf( app( ).pro( ).get( "TIPOCF", "MAIN" ) );     //prof
 | 
						|
        app( ).tipocf( tipocf[ 0 ] );
 | 
						|
        if (msk1 == NULL)
 | 
						|
        {
 | 
						|
          msk1 = new TDocumento_mask(_doc->tipo().mask_name(), _doc); // prof
 | 
						|
          _doc_masks.add(tipodoc, msk1);
 | 
						|
          _sheet = &( TSheet_field& )msk1->field( F_SHEET );
 | 
						|
           sheet( ).set_notify( ss_handler );
 | 
						|
           sheet().set_append(FALSE);
 | 
						|
          TList_field& listbox = ( TList_field& ) msk1->field( F_LBTIPORIGA );
 | 
						|
          const int numtr = app( ).pro( ).get_int( "NTIPIRIGA", "RIGHE" ); //prof
 | 
						|
          TToken_string keys, descrs; 
 | 
						|
          TRiga_documento r(_doc);
 | 
						|
          
 | 
						|
          for ( int i = 1; i <= numtr; i ++ )
 | 
						|
          {                                  
 | 
						|
            TString16 var;      
 | 
						|
            
 | 
						|
            var.format("%d", i);
 | 
						|
            TString tiporiga(app().pro().get(var, "RIGHE"));  // pro
 | 
						|
            r.set_tipo(tiporiga);
 | 
						|
            keys.add(r.tipo().codice());
 | 
						|
            descrs.add(r.tipo().descrizione());
 | 
						|
          }
 | 
						|
          listbox.replace_items( keys, descrs );    
 | 
						|
          configura_sheet( *_sheet, *_pro );
 | 
						|
          ((TVariable_sheet_field&)sheet()).set_getmask( ss_getmask );
 | 
						|
          if (msk1->id2pos( F_OCCASEDIT ) > 0 ) 
 | 
						|
            msk1->set_handler( F_OCCASEDIT, occas_handler );
 | 
						|
          msk1->set_handler( F_CODCF, clifo_handler );
 | 
						|
          msk1->set_handler( F_CODPAG, condpag_hndl );
 | 
						|
          msk1->set_handler( F_DATAINSC, condpag_hndl );
 | 
						|
          msk1->set_handler( F_CODNOTE, note_hndl );
 | 
						|
          msk1->set_handler( F_DATADOC, data_hndl );
 | 
						|
          msk1->set_handler( 99, elabora_handler );        // cazzo !!!!!!
 | 
						|
          msk1->set_handler( DLG_PRINT, print_handler );
 | 
						|
          int numhandler = pro( ).get_int( "NHANDLER", "HANDLERS" ); // prof
 | 
						|
          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 ) );
 | 
						|
          }           
 | 
						|
          
 | 
						|
          TMag_livelli l("FCG");
 | 
						|
          
 | 
						|
          for ( i = MAX_GIAC_LEVEL; i > 0; i--)
 | 
						|
          {
 | 
						|
            const short pos = _sheet->cid2index(FR_LIV1 + i -1);
 | 
						|
            if (l.enabled(i))
 | 
						|
            { 
 | 
						|
              const TString & header = l.name(i);
 | 
						|
              const int len = header.len() + 1;      
 | 
						|
              const int f_len = l.code_lenght(i);
 | 
						|
              _doc->set_liv_giac_len(i, f_len);
 | 
						|
 | 
						|
              _sheet->set_column_header(pos, l.name(i));
 | 
						|
              _sheet->set_column_width(pos, (len > f_len ? len : f_len) * 8);
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
              _sheet->delete_column(pos);
 | 
						|
              _doc->set_liv_giac_len(i, 0);
 | 
						|
            }
 | 
						|
          }
 | 
						|
                                                 
 | 
						|
// configurazione campi
 | 
						|
 | 
						|
          const bool gesval   = _config_ditta->get_bool("GESVAL");          
 | 
						|
          const bool gescambi = _config_ditta->get_bool("GESVALAC");   
 | 
						|
             
 | 
						|
          if (gesval)
 | 
						|
          {
 | 
						|
            msk1->show(F_CODVAL, !gescambi);
 | 
						|
            msk1->show(F_DATACAMBIO, !gescambi);
 | 
						|
            msk1->show(F_NOMEVAL, !gescambi); 
 | 
						|
            msk1->show(F_CODVAL1, gescambi);
 | 
						|
            msk1->show(F_DATACAMBIO1, gescambi);
 | 
						|
            msk1->show(F_NOMEVAL1, gescambi); 
 | 
						|
            msk1->show(F_CAMBIO);
 | 
						|
          }
 | 
						|
          else
 | 
						|
          {
 | 
						|
            msk1->disable(F_CODVAL);
 | 
						|
            msk1->disable(F_DATACAMBIO);
 | 
						|
            msk1->disable(F_NOMEVAL); 
 | 
						|
            msk1->hide(F_CODVAL1);
 | 
						|
            msk1->hide(F_DATACAMBIO1);
 | 
						|
            msk1->hide(F_NOMEVAL1); 
 | 
						|
            msk1->disable(F_CAMBIO);
 | 
						|
          }
 | 
						|
 | 
						|
          const bool geslin   =  _config_ditta->get_bool("GESLIN");          
 | 
						|
 | 
						|
          msk1->enable(F_CODLIN, geslin); 
 | 
						|
          msk1->enable(F_DESLIN, geslin); 
 | 
						|
 | 
						|
          const bool geslis         =  _config_ditta->get_bool("GES", "ve", 1);          
 | 
						|
          const bool gesliscatven   =  _config_ditta->get_bool("GESLISCV");          
 | 
						|
         
 | 
						|
          if (geslis)             
 | 
						|
          {
 | 
						|
            msk1->show(F_CODLIST, !gesliscatven);
 | 
						|
            msk1->show(F_CODLIST1, gesliscatven);
 | 
						|
          }
 | 
						|
          else
 | 
						|
          {
 | 
						|
            msk1->disable(F_CODLIST);
 | 
						|
            msk1->hide(F_CODLIST1);
 | 
						|
          }
 | 
						|
 | 
						|
          const bool gescontr       =  _config_ditta->get_bool("GES", "ve", 2);          
 | 
						|
          const bool gescontrcli    =  _config_ditta->get_bool("GESCONCC");          
 | 
						|
 | 
						|
          if (gescontr)
 | 
						|
          {                          
 | 
						|
           
 | 
						|
            msk1->show(F_CODCONT1, gescontrcli);    
 | 
						|
            msk1->show(F_CODCONT, !gescontrcli);
 | 
						|
          }
 | 
						|
          else        
 | 
						|
          {
 | 
						|
            msk1->disable(F_CODCONT);
 | 
						|
            msk1->hide(F_CODCONT1);
 | 
						|
          }
 | 
						|
 | 
						|
          const bool gesoff        =  _config_ditta->get_bool("GES", "ve", 3);          
 | 
						|
 | 
						|
          msk1->enable(F_CODCAMP, gesoff);
 | 
						|
 | 
						|
          const bool gessco        =  _config_ditta->get_char("GESSCO") != 'N';          
 | 
						|
 | 
						|
          msk1->enable(F_SCONTOPERC, gessco);
 | 
						|
 | 
						|
          const bool gesage        =  _config_ditta->get_bool("GESAGE");          
 | 
						|
 | 
						|
          msk1->enable(F_CODAG, gesage);
 | 
						|
          msk1->enable(F_DESAG, gesage);
 | 
						|
          msk1->enable(F_CODAGVIS, gesage);
 | 
						|
          msk1->enable(F_DESAGVIS, gesage);
 | 
						|
        }                           
 | 
						|
        else
 | 
						|
          _sheet = &( TSheet_field& )edit_mask( ).field( F_SHEET );
 | 
						|
        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 );
 | 
						|
}
 | 
						|
 | 
						|
const char* TMotore_application::get_next_key( )
 | 
						|
{ 
 | 
						|
  TToken_string key;
 | 
						|
  TMask& m = curr_mask( );
 | 
						|
  const TString value = m.get( F_CODNUM );
 | 
						|
 | 
						|
  if (value.not_empty())
 | 
						|
  {
 | 
						|
    TTable tabnum( "%NUM" );
 | 
						|
    tabnum.zero( );
 | 
						|
    tabnum.put( "CODTAB", value );    
 | 
						|
    if ( tabnum.read( ) == NOERR && tabnum.get_bool ( "B1" ))
 | 
						|
      // Se per questa numerazione h abilitata le numerazione automatica
 | 
						|
    {
 | 
						|
      TLocalisamfile doc(LF_DOC);
 | 
						|
      doc.zero();
 | 
						|
      doc.put("CODNUM", value);
 | 
						|
      doc.put("ANNO", m.get(F_ANNO));
 | 
						|
      doc.put("PROVV", m.get(F_PROVV));
 | 
						|
      
 | 
						|
      TRectype cmp_rec(doc.curr());   // record campione
 | 
						|
  
 | 
						|
      doc.put( "NDOC", 9999999L );
 | 
						|
      if (doc.read(_isgreat) == NOERR) 
 | 
						|
        doc.prev();                                                          
 | 
						|
  
 | 
						|
      const long num = ((doc.curr() == cmp_rec) ? doc.get_long( "NDOC" ) : 0) + 1;
 | 
						|
      
 | 
						|
      key.format( "%d|%d", F_NDOC, num);          
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return key;
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::read( TMask& m )
 | 
						|
{  
 | 
						|
//  const int err = _doc->read(_doc->head());
 | 
						|
  
 | 
						|
//  if ( err == NOERR )
 | 
						|
//  {                        
 | 
						|
    m.autoload(*_rel);
 | 
						|
    _codnum = m.get(F_CODNUM);
 | 
						|
    _tipodoc = m.get(F_TIPODOC);
 | 
						|
    ((TDocumento_mask &)m).cli2mask(app().doc().clifor(), app().doc().occas(), *(app()._config_ditta));
 | 
						|
 | 
						|
    TSheet_field& f = ( TSheet_field& ) m.field( F_SHEET );
 | 
						|
 | 
						|
    f.destroy( ); 
 | 
						|
    const int rows = _doc->physical_rows();
 | 
						|
    for (int i = 1; i <= rows; i++)
 | 
						|
    { 
 | 
						|
      f.insert(-1, FALSE);                                   
 | 
						|
      TToken_string & r = f.row(i -1);
 | 
						|
      TRiga_documento & rec = (*_doc)[i];
 | 
						|
      
 | 
						|
      rec.autoload(f);   
 | 
						|
      f.check_row(i - 1);
 | 
						|
    } 
 | 
						|
//  }
 | 
						|
//  return err;
 | 
						|
   return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::write( const TMask& m )  // C 90
 | 
						|
{ 
 | 
						|
  int err = esegui_procedura(OP_NUOVO);
 | 
						|
  
 | 
						|
  if (err == NOERR)
 | 
						|
  {
 | 
						|
    m.field(F_STATO).set( _pro->get( "STATOFINALE", "INSERIMENTO" ) );
 | 
						|
    m.autosave(*_rel);   
 | 
						|
    err = _doc->write( );      
 | 
						|
    if (err == NOERR)
 | 
						|
      _rel->read();                  // per posizionare correttamente la relazione
 | 
						|
  }
 | 
						|
  
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::rewrite( const TMask& m ) // C 90
 | 
						|
{
 | 
						|
  if (!valida_operazione(OP_MODIFICA))
 | 
						|
    return NOERR;  // Errore gia' segnalato 
 | 
						|
  int err = esegui_procedura(OP_MODIFICA);
 | 
						|
 | 
						|
  if (err == NOERR)
 | 
						|
  {
 | 
						|
    m.autosave(*_rel);   
 | 
						|
    err = _doc->rewrite( );      
 | 
						|
  }
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TMotore_application::remove( void )  // C 80
 | 
						|
{                                           
 | 
						|
  if ( ! valida_operazione( OP_CANCELLA ) )
 | 
						|
    return TRUE; 
 | 
						|
  int err = esegui_procedura(OP_CANCELLA);
 | 
						|
  return _doc->remove() == NOERR;
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::open_files(int logicnum, ...)  
 | 
						|
{  
 | 
						|
  va_list marker;
 | 
						|
  va_start(marker, logicnum);
 | 
						|
  while (logicnum > 0)
 | 
						|
  {
 | 
						|
    CHECKD(_file.objptr(logicnum) == NULL, "File gia' aperto: ", logicnum);
 | 
						|
    _file.add(new TLocalisamfile(logicnum), logicnum);
 | 
						|
    logicnum = va_arg(marker, int);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::on_firm_change()
 | 
						|
{       
 | 
						|
  if (_config_ditta != NULL)
 | 
						|
    delete _config_ditta;
 | 
						|
  _config_ditta = new TConfig(CONFIG_DITTA);
 | 
						|
  condv().set_config(_config_ditta);
 | 
						|
  _doc_masks.destroy();
 | 
						|
  TApplication::on_firm_change();
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::user_create( )
 | 
						|
{  
 | 
						|
  _config_ditta = new TConfig(CONFIG_DITTA);
 | 
						|
 | 
						|
  // Metto in relazione testata e righe
 | 
						|
  _rel = new TRelation( LF_DOC );
 | 
						|
  open_files(LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG, LF_SCONTI, LF_UMART, LF_TAB, LF_TABCOM, LF_CLIFO,
 | 
						|
             LF_CFVEN, LF_INDSP, LF_OCCAS, 0);
 | 
						|
  _doc = new TDocumento;
 | 
						|
  _rel->lfile().set_curr(_doc);
 | 
						|
  _doc->set_relation(_rel);
 | 
						|
  
 | 
						|
  _condv = new TCond_vendita(&doc().clifor(), _config_ditta);
 | 
						|
  _doc->set_condv(_condv);
 | 
						|
                                  
 | 
						|
  _msk = new TMask("ve0100a"); 
 | 
						|
  query_mask( ).set_handler( F_CODNUM, num_handler );
 | 
						|
  _occas_mask = new TMask("ve0100o"); 
 | 
						|
  _occas_mask->set_handler( O_CODICE, occas_code_handler );
 | 
						|
  TConfig utente( CONFIG_USER );
 | 
						|
 | 
						|
  _codnum = utente.get("CODNUM");
 | 
						|
  _tipodoc = utente.get("TIPODOC");
 | 
						|
  
 | 
						|
  // La maschera di inserimento/modifica per ora non la so!
 | 
						|
  // Viene letta dal profilo non appena trovato il record
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::user_destroy( )
 | 
						|
{              
 | 
						|
  // Registro l'ultimo tipo documento e l'ultima numerazione
 | 
						|
  TConfig utente( CONFIG_USER );
 | 
						|
  utente.set( "CODNUM", _codnum, "ve" );
 | 
						|
  utente.set( "TIPODOC", _tipodoc, "ve" );
 | 
						|
 | 
						|
  if (_config_ditta != NULL)
 | 
						|
    delete _config_ditta;
 | 
						|
  // Distruggo la maschera di modifica
 | 
						|
  if ( _msk != NULL )
 | 
						|
    delete _msk;
 | 
						|
  
 | 
						|
  // Distruggo la relazione
 | 
						|
  delete _rel;
 | 
						|
  delete _condv;
 | 
						|
 | 
						|
  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 )  // C 90
 | 
						|
{
 | 
						|
  if (operazione != OP_NUOVO && !stato_valido( stato_corrente( ), operazione))
 | 
						|
  {  
 | 
						|
    segnala_stato_non_valido( operazione );
 | 
						|
    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          
 | 
						|
  if (stato == 0)
 | 
						|
    return TRUE;
 | 
						|
  char p[2] = "0";   
 | 
						|
  TToken_string ret ( stati_validi( operazione ), ',' );
 | 
						|
  p[0] += ( char )stato;
 | 
						|
  return ( ret.get_pos( p ) != -1 );
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::stato_corrente( )
 | 
						|
{                                   
 | 
						|
  return edit_mask().get_int(F_STATO);
 | 
						|
}
 | 
						|
 | 
						|
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;
 | 
						|
}
 |