247 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			247 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// 771233.cpp - distinta quadro G
 | 
						|
#include <relapp.h>
 | 
						|
#include "77lib.h"
 | 
						|
#include "774200.h"
 | 
						|
#include "771232.h"    
 | 
						|
#include "quadrogd.h"
 | 
						|
#include "77qgd.h"
 | 
						|
 | 
						|
#define LF_QUAGD  101   // lffiles.h
 | 
						|
 | 
						|
class TDistintaQuadroG : public TRelation_application
 | 
						|
{
 | 
						|
    TRelation*       _rel;
 | 
						|
    TMask*           _msk;
 | 
						|
    int              _anno_dic;  // anno dichiarazione
 | 
						|
    TString80        _title;
 | 
						|
    TRiporti         _rip;
 | 
						|
    bool             _registra;
 | 
						|
    int              _file;           
 | 
						|
    TString16        _quadro;
 | 
						|
    
 | 
						|
  private:               
 | 
						|
    static bool nprog_handler   (TMask_field& f, KEY key);
 | 
						|
    static bool codanagr_handler(TMask_field& f, KEY key);
 | 
						|
    static bool codditta_hnd    (TMask_field& f, KEY key);    
 | 
						|
    static bool setta_nprog     (TMask_field& f);
 | 
						|
  
 | 
						|
  protected:
 | 
						|
    virtual bool user_create();
 | 
						|
    virtual bool user_destroy(); 
 | 
						|
    virtual int  rewrite(const TMask& m);
 | 
						|
    virtual int  write  (const TMask& m);  
 | 
						|
    virtual bool remove();
 | 
						|
    virtual TRelation* get_relation() const { return _rel; }
 | 
						|
    virtual TMask* get_mask(int mode)       { return _msk; }
 | 
						|
    virtual bool changing_mask(int mode)    { return FALSE; }
 | 
						|
    virtual void init_query_mode (TMask&);
 | 
						|
    virtual void init_query_insert_mode (TMask&);    
 | 
						|
    virtual void on_config_change();    
 | 
						|
    bool    scrivi_dati_per(TRectype& rec);
 | 
						|
    
 | 
						|
  public:                    
 | 
						|
    const char*   taitol() { return (const char*)_title; }  
 | 
						|
  public:
 | 
						|
    TDistintaQuadroG();
 | 
						|
    virtual ~TDistintaQuadroG() {};
 | 
						|
};                    
 | 
						|
 | 
						|
inline TDistintaQuadroG& app() { return (TDistintaQuadroG&) main_app(); }
 | 
						|
 | 
						|
TDistintaQuadroG::TDistintaQuadroG(): _rel(NULL)
 | 
						|
{
 | 
						|
  _title = "Distinta quadro G";
 | 
						|
  _quadro = "GD";
 | 
						|
  _file = LF_QUAGD;
 | 
						|
}
 | 
						|
 | 
						|
// Ricerca e output dell'ultimo nprog del percipiente scelto
 | 
						|
bool TDistintaQuadroG::setta_nprog(TMask_field& f)
 | 
						|
{
 | 
						|
  long  nprog = 0L;
 | 
						|
  const char tipoa    = f.mask().get(F_TIPOA)[0];
 | 
						|
  const long codanagr = atol(f.get());
 | 
						|
  const long codditta = get_firm_770();
 | 
						|
  
 | 
						|
  TLocalisamfile quagd(app()._file);
 | 
						|
    
 | 
						|
  quagd.zero();
 | 
						|
  quagd.put(QGD_CODDITTA, codditta);
 | 
						|
  quagd.put(QGD_TIPOA,    tipoa);
 | 
						|
  quagd.put(QGD_CODANAGR, codanagr);
 | 
						|
    
 | 
						|
  TRectype rec(quagd.curr());
 | 
						|
    
 | 
						|
  quagd.read();
 | 
						|
    
 | 
						|
  if (quagd.curr() > rec) 
 | 
						|
  {
 | 
						|
    f.mask().set(F_NPROG, nprog+1);
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
      
 | 
						|
  for ( ; !quagd.eof(); quagd.next())   
 | 
						|
  {
 | 
						|
    if (quagd.curr() > rec) break;
 | 
						|
    nprog = quagd.get_long("NPROG");
 | 
						|
  }
 | 
						|
 | 
						|
  f.mask().set(F_NPROG, nprog+1);
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TDistintaQuadroG::codditta_hnd(TMask_field& f, KEY k)
 | 
						|
{         
 | 
						|
  if (k == K_TAB && !f.mask().is_running())
 | 
						|
  {
 | 
						|
    TString16 codditta; codditta << get_firm_770();
 | 
						|
    if (codditta != "0")        
 | 
						|
    {
 | 
						|
      f.set(codditta);
 | 
						|
      f.check();
 | 
						|
    }
 | 
						|
  }   
 | 
						|
  return TRUE;                                           
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TDistintaQuadroG::codanagr_handler(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
  if (k == K_TAB && f.focusdirty())
 | 
						|
  {
 | 
						|
    TString16 dummy(f.get());
 | 
						|
    if (dummy.not_empty())   
 | 
						|
      setta_nprog(f);
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
// Passa al modo inserimento/modifica.
 | 
						|
bool TDistintaQuadroG::nprog_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if (!f.mask().is_running()) return TRUE;
 | 
						|
 | 
						|
  if (key == K_CTRL+K_TAB)
 | 
						|
  {
 | 
						|
    f.set_dirty();
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
  
 | 
						|
  if (key == K_TAB)   
 | 
						|
  {
 | 
						|
    const int nprog = atoi(f.get());
 | 
						|
    if (nprog==0) return TRUE;
 | 
						|
// entra in modo modifica (se il record che ha chiave specificata esiste gia') oppure
 | 
						|
// inserimento (se trova che non esiste)
 | 
						|
//    f.mask().stop_run(K_AUTO_ENTER); 
 | 
						|
  }                                   
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TDistintaQuadroG::scrivi_dati_per(TRectype& rec)
 | 
						|
{
 | 
						|
  TLocalisamfile dati_per(LF_PERC);
 | 
						|
  const long codditta = rec.get_long("CODDITTA");
 | 
						|
  char       tipoa    = rec.get_char("TIPOA");
 | 
						|
  const long codanagr = rec.get_long("CODANAGR");
 | 
						|
  
 | 
						|
  dati_per.zero();
 | 
						|
  dati_per.put("CODDITTA", codditta);    
 | 
						|
  dati_per.put("TIPOA",    tipoa);    
 | 
						|
  dati_per.put("CODANAGR", codanagr);   
 | 
						|
  
 | 
						|
  const bool preesistente = (dati_per.read() == NOERR);
 | 
						|
  
 | 
						|
  if (!preesistente)
 | 
						|
  {
 | 
						|
    dati_per.zero();
 | 
						|
    dati_per.put("CODDITTA", codditta);    
 | 
						|
    dati_per.put("TIPOA", tipoa);    
 | 
						|
    dati_per.put("CODANAGR", codanagr);   
 | 
						|
    dati_per.write();   
 | 
						|
  }
 | 
						|
  return preesistente;
 | 
						|
}
 | 
						|
 | 
						|
int TDistintaQuadroG::rewrite(const TMask& m)
 | 
						|
{
 | 
						|
  m.autosave(*_rel);
 | 
						|
  const int err = _rel->rewrite();
 | 
						|
  scrivi_dati_per(_rel->curr());         
 | 
						|
  _registra = TRUE;
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
int TDistintaQuadroG::write(const TMask& m)
 | 
						|
{
 | 
						|
  m.autosave(*_rel);
 | 
						|
  const int err = _rel->write();
 | 
						|
  scrivi_dati_per(_rel->curr());         
 | 
						|
  _registra = TRUE;
 | 
						|
  return err;
 | 
						|
}
 | 
						|
 | 
						|
bool TDistintaQuadroG::remove()
 | 
						|
{
 | 
						|
  _registra = TRUE;
 | 
						|
  return TRelation_application::remove();
 | 
						|
}
 | 
						|
 | 
						|
bool TDistintaQuadroG::user_create()
 | 
						|
{                      
 | 
						|
  _msk = new TMask("77qgda");
 | 
						|
  _msk->set_handler(F_CODDITTA, codditta_hnd);
 | 
						|
  _msk->set_handler(F_NPROG, nprog_handler);
 | 
						|
  _msk->set_handler(F_CODANAGRCOM, codanagr_handler);
 | 
						|
  _msk->set_handler(F_CODANAGRPERC, codanagr_handler);
 | 
						|
 | 
						|
  _rel      = new TRelation(LF_QUAGD);
 | 
						|
 | 
						|
  set_search_field(F_CODANAGRPERC);
 | 
						|
  _registra = FALSE;
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TDistintaQuadroG::user_destroy()
 | 
						|
{ 
 | 
						|
  delete _msk;
 | 
						|
  delete _rel; 
 | 
						|
  
 | 
						|
  if (_registra)
 | 
						|
    _rip.set(_quadro);
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TDistintaQuadroG::on_config_change()
 | 
						|
{                                
 | 
						|
  TConfig conf(CONFIG_STUDIO);
 | 
						|
  _anno_dic = (int)conf.get_long(ANNO_SEL, NULL); 
 | 
						|
}
 | 
						|
 | 
						|
void TDistintaQuadroG::init_query_mode(TMask& m)
 | 
						|
{ 
 | 
						|
  m.set(F_ANNODIC, _anno_dic);
 | 
						|
// forza il ricalcolo dell'ultimo numero disponibile
 | 
						|
  TString16 dummy(m.get(F_NPROG));
 | 
						|
  if (dummy.not_empty())
 | 
						|
    setta_nprog(m.field(F_NPROG));
 | 
						|
 | 
						|
  m.hide(-1);  // nasconde (hide) group 1 - Scelta ANAGR
 | 
						|
  m.show(-2);  // abilita (show) group 2 - Ricerca su DATI PERC
 | 
						|
}
 | 
						|
 | 
						|
void TDistintaQuadroG::init_query_insert_mode(TMask& m)
 | 
						|
{ 
 | 
						|
  m.set(F_ANNODIC, _anno_dic);
 | 
						|
  m.hide(-2);  // group 2 Nasconde ricerca su PERC
 | 
						|
  m.show(-1);  // group 1 Ricerca su ANAGR
 | 
						|
}
 | 
						|
 | 
						|
bool distinta_quadro_g(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TDistintaQuadroG a;
 | 
						|
  a.run(argc,argv,a.taitol());
 | 
						|
  return TRUE;
 | 
						|
} |