Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@18941 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			250 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			250 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "at9.h"
 | 
						|
#include "at9600a.h"
 | 
						|
 | 
						|
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <recarray.h>
 | 
						|
#include <relation.h>
 | 
						|
#include <textset.h>
 | 
						|
 | 
						|
#include "soggetti.h"
 | 
						|
#include "sezioni.h"
 | 
						|
#include <comuni.h>
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TEsporta_ON: osservatorio nazionale
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TEsporta_ON_mask : public TAutomask
 | 
						|
{
 | 
						|
 | 
						|
public:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
  TEsporta_ON_mask();
 | 
						|
	~TEsporta_ON_mask();
 | 
						|
};
 | 
						|
 | 
						|
bool TEsporta_ON_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
TEsporta_ON_mask::TEsporta_ON_mask() : TAutomask("at9600a") 
 | 
						|
{
 | 
						|
	//carica i parametri del file di configurazione
 | 
						|
	TConfig configfile("at96conf.ini", "MAIN");
 | 
						|
  for (int i = 0; i < fields() ; i++)
 | 
						|
	{
 | 
						|
		TMask_field& f = fld(i);
 | 
						|
		const TFieldref* fr = f.field();
 | 
						|
		if (fr != NULL)
 | 
						|
			f.set(configfile.get(fr->name()));
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
TEsporta_ON_mask::~TEsporta_ON_mask()
 | 
						|
{
 | 
						|
	//carica i parametri del file di configurazione
 | 
						|
	TConfig configfile("at96conf.ini", "MAIN");
 | 
						|
  for (int i = 0; i < fields() ; i++)
 | 
						|
	{
 | 
						|
		TMask_field& f = fld(i);
 | 
						|
		const TFieldref* fr = f.field();
 | 
						|
		if (fr != NULL)
 | 
						|
			configfile.set(fr->name(), f.get());
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
//	Record set soggetti
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TEsporta_ON_recordset : public TCSV_recordset
 | 
						|
{
 | 
						|
public:
 | 
						|
  virtual bool set(unsigned int fld, const TVariant& var);
 | 
						|
	TEsporta_ON_recordset();
 | 
						|
};
 | 
						|
 | 
						|
bool TEsporta_ON_recordset::set(unsigned int column, const TVariant& var)
 | 
						|
{
 | 
						|
	TString str;
 | 
						|
	if (var.is_date())
 | 
						|
	{
 | 
						|
		if (!var.is_empty())
 | 
						|
		{
 | 
						|
			const TDate data = var.as_date();
 | 
						|
			str.format("%04d-%02d-%02d", data.year(), data.month(), data.day());
 | 
						|
		}
 | 
						|
	}
 | 
						|
	else
 | 
						|
		str << var;
 | 
						|
	str.insert("\""); str << '"';
 | 
						|
  str.replace('|', '/');
 | 
						|
	return TCSV_recordset::set(column, TVariant(str));
 | 
						|
}
 | 
						|
 | 
						|
TEsporta_ON_recordset::TEsporta_ON_recordset() 
 | 
						|
: TCSV_recordset("CSV(\"|\")")
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TEsporta_ON applicazione
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TEsporta_ON_app : public TSkeleton_application
 | 
						|
{
 | 
						|
 | 
						|
protected:
 | 
						|
	virtual bool check_autorization() const {return false;}
 | 
						|
  virtual const char * extra_modules() const {return "at";}
 | 
						|
	virtual void main_loop();
 | 
						|
 | 
						|
	const TString& find_comune(const TRecordset& soggetti) const;
 | 
						|
	const TString& find_dencom_nasc(const TString& codcom) const;
 | 
						|
	void crea_prima_riga(TEsporta_ON_recordset& csv, const TString& sezini, const TString& sezfin) const;
 | 
						|
 | 
						|
public:
 | 
						|
	void esporta_soggetti(const TMask& msk) const;
 | 
						|
  
 | 
						|
};
 | 
						|
 | 
						|
void TEsporta_ON_app::crea_prima_riga(TEsporta_ON_recordset& csv, const TString& sezini, const TString& sezfin) const
 | 
						|
{
 | 
						|
	// query su sezioni per stabilire cosa scrivere nel primo record
 | 
						|
	// elenco delle sezioni trasferite separate da ','
 | 
						|
	TString querysez;
 | 
						|
	querysez << "USE SEZIONI\nSELECT CODSOT=''";
 | 
						|
	if (sezini.not_empty())
 | 
						|
		querysez << "\nFROM CODSEZ=\"" << sezini << "\"";
 | 
						|
	if (sezini.not_empty())
 | 
						|
		querysez << "\nTO CODSEZ=\"" << sezfin << "\"";
 | 
						|
	TISAM_recordset sezioni(querysez);
 | 
						|
	
 | 
						|
	// crea testata
 | 
						|
	TToken_string ts("", ',');
 | 
						|
	for (bool oks = sezioni.move_first(); oks; oks = sezioni.move_next())
 | 
						|
		ts.add(sezioni.get(SEZ_CODSEZ).as_string());
 | 
						|
	csv.new_rec(ts);
 | 
						|
}
 | 
						|
 | 
						|
void TEsporta_ON_app::esporta_soggetti(const TMask& m) const
 | 
						|
{
 | 
						|
	TConfig config("at9600a.ini");
 | 
						|
	
 | 
						|
	//query su sezioni
 | 
						|
  const TString4 sezini = m.get(F_SEZINI);
 | 
						|
	const TString4 sotini = m.get(F_SOTINI);
 | 
						|
	const TString4 sezfin = m.get(F_SEZFIN);
 | 
						|
	const TString4 sotfin = m.get(F_SOTFIN);
 | 
						|
	TEsporta_ON_recordset csv;
 | 
						|
	//crea la prima stupida riga
 | 
						|
	crea_prima_riga(csv, sezini, sezfin);
 | 
						|
	
 | 
						|
  
 | 
						|
	// query su soggetti
 | 
						|
	TString query;
 | 
						|
  query << "USE SOGGETTI KEY 3";
 | 
						|
 | 
						|
	const TDate data = m.get_date(F_DATA);
 | 
						|
	if (sezini.not_empty())
 | 
						|
		query << "\nFROM CODSEZ=\"" << sezini << "\"";
 | 
						|
	if (sezini.not_empty())
 | 
						|
		query << "\nTO CODSEZ=\"" << sezfin << "\"";
 | 
						|
 | 
						|
	TISAM_recordset soggetti(query);
 | 
						|
 | 
						|
	const int items = soggetti.items();
 | 
						|
	TProgind pi(items, "Estrazione soggetti...", true, true);
 | 
						|
	TString ws;
 | 
						|
	for (bool ok = soggetti.move_first(); ok; ok = soggetti.move_next())
 | 
						|
	{
 | 
						|
    if (!pi.addstatus(1))
 | 
						|
      break;
 | 
						|
		const TString4& catdon = soggetti.get(SOG_CATDON).as_string();
 | 
						|
		const TDate dataisc = soggetti.get(SOG_DATAISC).as_date();
 | 
						|
		const bool passa = config.get_bool(catdon, "CATEGORIE");
 | 
						|
 | 
						|
		const TString4& codsez = soggetti.get(SOG_CODSEZ).as_string();
 | 
						|
		TString16 sez_on = config.get(codsez, "SEZIONI");
 | 
						|
		if (sez_on.empty())
 | 
						|
			sez_on = codsez;
 | 
						|
 | 
						|
		//if ((catdon == "01" || catdon == "04") && (dataisc.empty() || dataisc <= data))
 | 
						|
		if (passa && (dataisc.empty() || dataisc <= data))
 | 
						|
		{
 | 
						|
			//creazione di un nuovo record di tipo soggetti
 | 
						|
			csv.new_rec("");
 | 
						|
			//..e successivo riempimento
 | 
						|
			csv.set(0, (TVariant) sez_on);
 | 
						|
			csv.set(1, soggetti.get(SOG_TESSAVIS));
 | 
						|
			csv.set(2, soggetti.get(SOG_CF));
 | 
						|
			csv.set(3, soggetti.get(SOG_COGNOME));
 | 
						|
			csv.set(4, soggetti.get(SOG_NOME));
 | 
						|
			csv.set(5, soggetti.get(SOG_SESSO));
 | 
						|
			csv.set(6, soggetti.get(SOG_DATANASC));
 | 
						|
			csv.set(7, NULL_VARIANT);
 | 
						|
			csv.set(8, NULL_VARIANT); //nazionalita
 | 
						|
			csv.set(9, soggetti.get(SOG_DOM_INDIR));
 | 
						|
			csv.set(10, soggetti.get(SOG_DOM_CAP));
 | 
						|
			csv.set(11, TVariant(find_comune(soggetti)));
 | 
						|
			csv.set(12, soggetti.get(SOG_TITSTUD));
 | 
						|
			csv.set(13, NULL_VARIANT); // professione
 | 
						|
			csv.set(14, soggetti.get(SOG_TELABI));
 | 
						|
			csv.set(15, soggetti.get(SOG_TELALT));
 | 
						|
			csv.set(16, TVariant(config.get(catdon, "CATDON"))); // categoria
 | 
						|
			csv.set(17, soggetti.get(SOG_EMAIL));
 | 
						|
			TString8 gruppoab0 = soggetti.get(SOG_GRUPPOAB0).as_string();
 | 
						|
			csv.set(18, TVariant(config.get(gruppoab0, "GRUPPOAB0"))); // gruppo ab0
 | 
						|
			TString8 kell = soggetti.get(SOG_KELL).as_string();		
 | 
						|
			csv.set(19, TVariant(config.get(kell, "KELL"))); // kell
 | 
						|
			csv.set(20, ""); // fattore rh
 | 
						|
			csv.set(21, soggetti.get(SOG_DATAISC));
 | 
						|
			csv.set(22, soggetti.get(SOG_DATADIM));
 | 
						|
			csv.set(23, NULL_VARIANT); // condizione non professionale
 | 
						|
		}
 | 
						|
	}	//for(move_first()..
 | 
						|
 	
 | 
						|
	TString80 path = config.get("NOMEFILE", "GENERALE");
 | 
						|
	if (path.empty())
 | 
						|
		path = "file_on.txt";
 | 
						|
	csv.save_as(path, fmt_text);
 | 
						|
#ifdef DBG
 | 
						|
	xvt_sys_goto_url(path, "open");
 | 
						|
#endif
 | 
						|
}
 | 
						|
 | 
						|
const TString& TEsporta_ON_app::find_comune(const TRecordset& soggetti) const
 | 
						|
{
 | 
						|
	TToken_string ws;
 | 
						|
	ws = "";
 | 
						|
	ws.add(soggetti.get(SOG_DOM_CODCOM).as_string() ,1);
 | 
						|
	return cache().get(LF_COMUNI, ws, COM_DENCOM);
 | 
						|
}
 | 
						|
 | 
						|
const TString& TEsporta_ON_app::find_dencom_nasc(const TString& codcom) const
 | 
						|
{
 | 
						|
	TToken_string key;
 | 
						|
	key.add(" ");
 | 
						|
	key.add(codcom);
 | 
						|
	return cache().get(LF_COMUNI, key, COM_DENCOM);
 | 
						|
}
 | 
						|
 | 
						|
void TEsporta_ON_app::main_loop()
 | 
						|
{
 | 
						|
	open_files(LF_SOGGETTI, LF_COMUNI, 0);
 | 
						|
  TEsporta_ON_mask m;
 | 
						|
  while (m.run() == K_ENTER)
 | 
						|
		esporta_soggetti(m);
 | 
						|
}
 | 
						|
 | 
						|
int at9600(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TEsporta_ON_app app;
 | 
						|
  app.run(argc, argv, TR("Estrazione dati per Osservatorio Nazionale"));
 | 
						|
  return 0;
 | 
						|
}
 |