Files correlati : Ricompilazione Demo : [ ] Commento : Programma di aggiornamento dati AT da CT Bologna git-svn-id: svn://10.65.10.50/trunk@9245 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			239 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			239 lines
		
	
	
		
			5.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <filetext.h>
 | 
						|
#include <form.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <printer.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "at8.h"
 | 
						|
#include "at8800a.h"
 | 
						|
#include "soggetti.h"
 | 
						|
#include "donaz.h"
 | 
						|
 | 
						|
#define ATFILENAME "ctbo2at.dat"
 | 
						|
 | 
						|
class TCtbo2at_file;
 | 
						|
 | 
						|
class TCtbo2at: public TSkeleton_application
 | 
						|
{
 | 
						|
  TMask* 				  _msk;
 | 
						|
  TRelation* 		  _rel;
 | 
						|
  TCursor* 			  _cur;
 | 
						|
  TCtbo2at_file*  _trasfile;
 | 
						|
  TRecord_array*  _donazioni;
 | 
						|
	TLocalisamfile* _donaz;
 | 
						|
	TDate						_data;
 | 
						|
  
 | 
						|
protected:
 | 
						|
  virtual bool create(void);
 | 
						|
  virtual void main_loop();
 | 
						|
  virtual bool destroy(void) ;
 | 
						|
  void transfer(void);
 | 
						|
  void inizializza_cur(void);
 | 
						|
  void inizializza_file(void);
 | 
						|
  void record(THash_object& lavoro);
 | 
						|
  static bool annulla_handler(TMask_field& f, KEY k);
 | 
						|
public:
 | 
						|
  
 | 
						|
  const TMask& msk() const { return *_msk; }
 | 
						|
  const TRecord_array& donazioni() { return *_donazioni;}
 | 
						|
  const TDate data() { return _data;}
 | 
						|
  
 | 
						|
  TCtbo2at() {}
 | 
						|
  virtual ~TCtbo2at() {}
 | 
						|
};
 | 
						|
 | 
						|
// restituisce un riferimento all' applicazione
 | 
						|
inline TCtbo2at& app() { return (TCtbo2at&) main_app();}
 | 
						|
 | 
						|
/////////////////////////////////////////////////////
 | 
						|
// Classe TCtbo2at_file customizzata dalla TFile_text //
 | 
						|
/////////////////////////////////////////////////////
 | 
						|
class TCtbo2at_file: public TFile_text
 | 
						|
{ 
 | 
						|
protected:
 | 
						|
  virtual void validate(TCursor& cur,TRecord_text &rec, TToken_string &val, TString& str);
 | 
						|
 | 
						|
public:
 | 
						|
  TCtbo2at_file(const TString& file_name, const TString& config_name);
 | 
						|
  virtual ~TCtbo2at_file() { }
 | 
						|
};
 | 
						|
 | 
						|
TCtbo2at_file::TCtbo2at_file(const TString& file_name, const TString& config_name)
 | 
						|
          : TFile_text(file_name, config_name)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
// creazione dell'applicazione
 | 
						|
bool TCtbo2at::create()
 | 
						|
{
 | 
						|
  _msk = new TMask("at8800a");
 | 
						|
  _rel = new TRelation(LF_SOGGETTI);
 | 
						|
  _cur = NULL;
 | 
						|
  _msk->set(F_FILENAME,ATFILENAME);
 | 
						|
	_donaz = new TLocalisamfile(LF_DONAZ);
 | 
						|
 	_donazioni = new TRecord_array(LF_DONAZ,DON_PROGDON);
 | 
						|
 | 
						|
  //_msk->set_handler(DLG_CANCEL, annulla_handler);
 | 
						|
  _trasfile = NULL;
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
// distruzione dell'applicazione
 | 
						|
bool TCtbo2at::destroy()
 | 
						|
{
 | 
						|
  delete _donazioni;
 | 
						|
  delete _donaz;
 | 
						|
  delete _cur;
 | 
						|
  delete _rel;
 | 
						|
  delete _msk;
 | 
						|
 | 
						|
  if (_trasfile)
 | 
						|
    delete _trasfile;
 | 
						|
  return TSkeleton_application::destroy();
 | 
						|
}
 | 
						|
 | 
						|
// carica la maschera 
 | 
						|
void TCtbo2at::main_loop()
 | 
						|
{ 
 | 
						|
  // Preimposta gli eventuali valori specificati sulla riga di comando            
 | 
						|
  KEY key = K_ENTER;
 | 
						|
  while (key != K_QUIT)
 | 
						|
  {
 | 
						|
    key = _msk->run();
 | 
						|
    if (key == K_ENTER)
 | 
						|
      transfer();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
// trasferimento dati da file CT su programma avis
 | 
						|
void TCtbo2at::transfer()
 | 
						|
{
 | 
						|
  inizializza_cur();
 | 
						|
   
 | 
						|
  TFilename ctboini = "ctbo2at.ini";
 | 
						|
  
 | 
						|
  _trasfile = new TCtbo2at_file(_msk->get(F_FILENAME), ctboini);
 | 
						|
  inizializza_file();
 | 
						|
  
 | 
						|
  long n_sog = _cur->items();
 | 
						|
  if (n_sog > 0)
 | 
						|
  {
 | 
						|
   TProgind pi(n_sog,"Lettura dati da archivio CT...",FALSE,TRUE);
 | 
						|
             
 | 
						|
   TAssoc_array& tracciati = _trasfile->tracciati();
 | 
						|
   //scandisco tutti i soggetti
 | 
						|
   for (*_cur = 0; _cur->pos() < n_sog; ++(*_cur))
 | 
						|
   {
 | 
						|
      pi.addstatus(1L);
 | 
						|
      
 | 
						|
			TRectype* key = new TRectype(LF_DONAZ);
 | 
						|
			key->put(DON_CODICE,_cur->file().get(SOG_CODICE));
 | 
						|
			_donazioni->read(key);
 | 
						|
      
 | 
						|
      THash_object* lavoro =  tracciati.get_hashobj();
 | 
						|
      //scandisco tutti i record  di un effetto
 | 
						|
      for (int i = 0; lavoro != NULL; i++)
 | 
						|
      {
 | 
						|
        record(*lavoro);//emetto il record
 | 
						|
        lavoro =  tracciati.get_hashobj();
 | 
						|
      }
 | 
						|
   }
 | 
						|
  }
 | 
						|
  _trasfile->close();
 | 
						|
  delete _trasfile;
 | 
						|
  _trasfile = NULL;
 | 
						|
	message_box("Operazione terminata");
 | 
						|
}
 | 
						|
 | 
						|
//inizializza il cursore
 | 
						|
void TCtbo2at::inizializza_cur()
 | 
						|
{            
 | 
						|
  TProgind prg (1,"Preparazione archivio soggetti da trasferire\nPrego attendere...",FALSE, FALSE);
 | 
						|
  _cur = new TCursor(_rel);
 | 
						|
  _cur->freeze();
 | 
						|
}
 | 
						|
 | 
						|
//inizializza il file di testo su cui emettere i dati
 | 
						|
void TCtbo2at::inizializza_file()
 | 
						|
{
 | 
						|
	TFilename filect = _msk->get(F_FILENAME);
 | 
						|
  _trasfile->open(filect,'r');
 | 
						|
	//_trasfile->force_record_separator(TRUE);
 | 
						|
      
 | 
						|
}
 | 
						|
 | 
						|
//emetto un record 
 | 
						|
void TCtbo2at::record(THash_object& lavoro)
 | 
						|
{
 | 
						|
  TTracciato_record&  oggetto = (TTracciato_record&)lavoro.obj();
 | 
						|
  const TString& tipo = oggetto.type();
 | 
						|
  TRecord_text rec(tipo);
 | 
						|
  //carico il record da emettere
 | 
						|
  _trasfile->autoload(rec, *_cur, &tipo);
 | 
						|
  _trasfile->write(rec);//emetto i dati su file
 | 
						|
}
 | 
						|
 | 
						|
// handler per gestire la conferma dell'annullamento dei dati inseriti
 | 
						|
// nella maschera
 | 
						|
bool TCtbo2at::annulla_handler(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
  TMask &m = f.mask();
 | 
						|
  if (k == K_SPACE)
 | 
						|
  {
 | 
						|
    if (yesno_box("Vuoi veramente annullare i dati inseriti"))
 | 
						|
       m.reset();
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
// gestione dei messaggi estesi nei campi
 | 
						|
void TCtbo2at_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
 | 
						|
{
 | 
						|
  const TString code(s.get(0));
 | 
						|
  TString valore;
 | 
						|
  if (code == "_TOTALE")
 | 
						|
  {
 | 
						|
  	int totale = 0;
 | 
						|
    TString16 tipodon(s.get());
 | 
						|
    CHECK(tipodon[0]=='!',"Macro _TOTALE senza carattere '!'");
 | 
						|
    tipodon.ltrim(1);
 | 
						|
		for (int r=1; r<=app().donazioni().rows(); r++)
 | 
						|
		{
 | 
						|
			const TRectype& riga = app().donazioni().row(r);                
 | 
						|
			const TDate datadon = riga.get(DON_DATADON);
 | 
						|
			if ((riga.get(DON_TIPODON)==tipodon) && (app().data().year() == datadon.year()))
 | 
						|
				totale++;
 | 
						|
    }
 | 
						|
    valore.cut(0);
 | 
						|
    valore << totale;
 | 
						|
  }
 | 
						|
  else if (code == "_ULTIMA")
 | 
						|
  {
 | 
						|
    valore.cut(0);
 | 
						|
  	TString16 tipodon(s.get());
 | 
						|
    CHECK(tipodon[0]=='!',"Macro _ULTIMA senza carattere '!'");
 | 
						|
    tipodon.ltrim(1);
 | 
						|
		for (int r=1; r<=app().donazioni().rows(); r++)
 | 
						|
		{
 | 
						|
			const TRectype& riga = app().donazioni().row(r);
 | 
						|
			const TDate datadon = riga.get(DON_DATADON);
 | 
						|
			if ((riga.get(DON_TIPODON)==tipodon) && (app().data().year() == datadon.year()))
 | 
						|
				valore = riga.get(DON_DATADON);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  else NFCHECK("Macro non definita: %s", (const char *)code);
 | 
						|
  str = valore;
 | 
						|
}
 | 
						|
 | 
						|
int at8800(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TCtbo2at a ;
 | 
						|
  a.run(argc, argv, "Acquisizione dati da CT Bologna");
 | 
						|
  return 0;
 | 
						|
}
 |