Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 873 git-svn-id: svn://10.65.10.50/trunk@15151 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			692 lines
		
	
	
		
			17 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			692 lines
		
	
	
		
			17 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <mask.h>
 | 
						||
#include <printer.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <recarray.h>
 | 
						||
#include <relation.h>
 | 
						||
#include <urldefid.h>
 | 
						||
#include <utility.h>
 | 
						||
 | 
						||
#include "at3.h"
 | 
						||
 | 
						||
// nomi campi maschera
 | 
						||
#include "at3700a.h"
 | 
						||
          
 | 
						||
// nomi dei campi
 | 
						||
#include "soggetti.h"
 | 
						||
#include "atstats.h"
 | 
						||
#include "sezioni.h"
 | 
						||
 | 
						||
// classe per la definizione di una riga di statistica
 | 
						||
class TRigaSGruppo : public TObject
 | 
						||
{                             
 | 
						||
	TString16			_gruppo, _rh;
 | 
						||
	TArray				_valori;
 | 
						||
 | 
						||
protected:
 | 
						||
	const TRigaSGruppo& copy(const TRigaSGruppo& riga);
 | 
						||
public:
 | 
						||
	const TString16 gruppo() const { return _gruppo; }
 | 
						||
	const TString16 rh() const { return _rh; } 
 | 
						||
	TObject* dup() const { return new TRigaSGruppo(*this); }
 | 
						||
	const TRigaSGruppo& operator = (const TRigaSGruppo& riga);
 | 
						||
	const real& operator [] (int colonna) const;
 | 
						||
	void aggiorna_valore(int colonna, const real& numero) ;
 | 
						||
	void azzera_valori();
 | 
						||
	// costruttore
 | 
						||
	TRigaSGruppo(TString16 gruppo, TString16 rh) {_gruppo = gruppo; _rh = rh;}
 | 
						||
	// costruttore di copia
 | 
						||
	TRigaSGruppo(const TRigaSGruppo& riga)  { copy(riga); }
 | 
						||
	virtual ~TRigaSGruppo() {};
 | 
						||
};
 | 
						||
 | 
						||
const TRigaSGruppo& TRigaSGruppo::copy(const TRigaSGruppo& riga)
 | 
						||
{
 | 
						||
	_gruppo = riga._gruppo;
 | 
						||
	_rh = riga._rh;
 | 
						||
	_valori = riga._valori;
 | 
						||
	return (*this);
 | 
						||
}
 | 
						||
 | 
						||
const TRigaSGruppo& TRigaSGruppo::operator = (const TRigaSGruppo& riga)
 | 
						||
{
 | 
						||
	copy(riga);
 | 
						||
	return (*this);
 | 
						||
}
 | 
						||
 | 
						||
const real& TRigaSGruppo::operator [] (int colonna) const
 | 
						||
{
 | 
						||
	real* valore = (real*)_valori.objptr(colonna);
 | 
						||
	if (valore == NULL)
 | 
						||
		return ZERO;
 | 
						||
	else
 | 
						||
		return *valore;		
 | 
						||
}
 | 
						||
 | 
						||
void TRigaSGruppo::aggiorna_valore(int colonna, const real& numero)
 | 
						||
{
 | 
						||
	real* valore = (real*)_valori.objptr(colonna);
 | 
						||
	if (valore == NULL)
 | 
						||
		_valori.add(new real(numero), colonna);
 | 
						||
	else
 | 
						||
		*valore += numero;
 | 
						||
}
 | 
						||
  
 | 
						||
void TRigaSGruppo::azzera_valori()
 | 
						||
{
 | 
						||
	_valori.destroy();
 | 
						||
}
 | 
						||
                   
 | 
						||
class TStatisticaSog : public TApplication
 | 
						||
{
 | 
						||
	TMask*					_msk;
 | 
						||
	TRelation*   		_rel;
 | 
						||
	TCursor*				_cur;
 | 
						||
	TLocalisamfile* _sezioni;
 | 
						||
	TLocalisamfile* _soggetti;
 | 
						||
	TLocalisamfile* _atstats;
 | 
						||
	TAssoc_array*		_colonne;
 | 
						||
	TArray					_righe;
 | 
						||
	TString16				_sezini, _sotini, _sezfin, _sotfin, _gruppoazie;
 | 
						||
	TString16				_catdon;
 | 
						||
	TDate						_data;
 | 
						||
	bool 						_solotot, _pergruppo;
 | 
						||
	int							_sezionistampate;
 | 
						||
 | 
						||
protected:
 | 
						||
	virtual bool create();
 | 
						||
	virtual bool destroy();
 | 
						||
  virtual bool menu(MENU_TAG m);
 | 
						||
	virtual TMask& get_mask() { return *_msk; }
 | 
						||
	virtual TRelation* get_relation() const { return _rel; }
 | 
						||
	int data2row(const TString16 gruppo, const TString16 rh);
 | 
						||
	bool riepilogo();
 | 
						||
	bool stampa();
 | 
						||
	bool crea_colonne();
 | 
						||
	bool crea_righe();
 | 
						||
	void azzera_righe();
 | 
						||
	void stampa_sezione(TString16 codsez, TString16 codsot);
 | 
						||
	void crea_intestazione();
 | 
						||
public:
 | 
						||
	TStatisticaSog() {}
 | 
						||
	
 | 
						||
};
 | 
						||
 | 
						||
HIDDEN inline TStatisticaSog& app() { return (TStatisticaSog&) main_app(); }
 | 
						||
 | 
						||
int TStatisticaSog::data2row(const TString16 gruppo, const TString16 rh)
 | 
						||
{              
 | 
						||
	int igruppo = 0;
 | 
						||
	int irh = 0;
 | 
						||
	if (gruppo == "0")
 | 
						||
		igruppo = 1;
 | 
						||
	if (gruppo == "A")
 | 
						||
		igruppo = 2;
 | 
						||
	if (gruppo == "A1")
 | 
						||
		igruppo = 3;
 | 
						||
	if (gruppo == "A2")
 | 
						||
		igruppo = 4;
 | 
						||
	if (gruppo == "A1B")
 | 
						||
		igruppo = 5;
 | 
						||
	if (gruppo == "A2B")
 | 
						||
		igruppo = 6;
 | 
						||
	if (gruppo == "AB")
 | 
						||
		igruppo = 7;
 | 
						||
	if (gruppo == "B")
 | 
						||
		igruppo = 8;
 | 
						||
	if (rh == "POS")
 | 
						||
		irh = 1;
 | 
						||
	if (rh == "NEG")
 | 
						||
		irh = 2;
 | 
						||
	return igruppo*10 + irh;
 | 
						||
}
 | 
						||
 | 
						||
bool TStatisticaSog::crea_colonne()
 | 
						||
{                   
 | 
						||
	_colonne->destroy();
 | 
						||
	real contatore(ZERO);
 | 
						||
	real* oggetto = new real(contatore);                                
 | 
						||
	const char* indice = "0";
 | 
						||
	_colonne->add(indice,(TObject*)oggetto);
 | 
						||
	indice = "1"; // maschi
 | 
						||
	contatore = contatore+1;
 | 
						||
	real* oggetto2 = new real(contatore);                                	
 | 
						||
	_colonne->add(indice,(TObject*)oggetto2);
 | 
						||
	indice = "2"; // femmine
 | 
						||
	contatore = contatore+1;
 | 
						||
	real* oggetto3 = new real(contatore);                                	
 | 
						||
	_colonne->add(indice,(TObject*)oggetto3);
 | 
						||
	indice = "9"; // non spec.
 | 
						||
	contatore = contatore+1;
 | 
						||
	real* oggetto4 = new real(contatore);                                	
 | 
						||
	_colonne->add(indice,(TObject*)oggetto4);
 | 
						||
	return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStatisticaSog::crea_righe()
 | 
						||
{                     
 | 
						||
	TString16 gruppo, rh;
 | 
						||
	for (int igruppo=0;igruppo<=8;igruppo++)
 | 
						||
	{		
 | 
						||
		switch (igruppo)
 | 
						||
		{  
 | 
						||
			case 0 : gruppo = "";   break;
 | 
						||
			case 1 : gruppo = "0";   break;
 | 
						||
			case 2 : gruppo = "A";   break;
 | 
						||
			case 3 : gruppo = "A1";  break;		
 | 
						||
			case 4 : gruppo = "A2"; break;
 | 
						||
			case 5 : gruppo = "A1B";  break;
 | 
						||
			case 6 : gruppo = "A2B"; break;						
 | 
						||
			case 7 : gruppo = "AB";  break;		
 | 
						||
			case 8 : gruppo = "B";   break;		
 | 
						||
		}            
 | 
						||
		for (int irh=0;irh <=2;irh++)
 | 
						||
		{
 | 
						||
			switch (irh)
 | 
						||
			{  
 | 
						||
				case 1  : rh = "POS"; break;
 | 
						||
				case 2  : rh = "NEG"; break;
 | 
						||
				default : rh = "   "; break;		
 | 
						||
			}            
 | 
						||
			_righe.add(new TRigaSGruppo(gruppo, rh), data2row(gruppo, rh));
 | 
						||
		}
 | 
						||
	}		
 | 
						||
	return _righe.items()>0;	
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
 | 
						||
bool TStatisticaSog::create()
 | 
						||
{
 | 
						||
	TApplication::create();
 | 
						||
	_msk = new TMask("at3700a");
 | 
						||
	_rel = new TRelation(LF_SOGGETTI);
 | 
						||
  _soggetti = new TLocalisamfile(LF_SOGGETTI);
 | 
						||
	_atstats = new TLocalisamfile(LF_ATSTATS);
 | 
						||
	_sezioni = new TLocalisamfile(LF_SEZIONI);
 | 
						||
	_colonne = new TAssoc_array();
 | 
						||
  dispatch_e_menu(BAR_ITEM(1));
 | 
						||
	return TRUE;
 | 
						||
}	
 | 
						||
 | 
						||
bool TStatisticaSog::destroy()	
 | 
						||
{
 | 
						||
	delete _colonne;
 | 
						||
	delete _sezioni;
 | 
						||
	delete _atstats;
 | 
						||
	delete _soggetti;
 | 
						||
	delete _rel;
 | 
						||
	delete _msk;
 | 
						||
	return TApplication::destroy();
 | 
						||
}
 | 
						||
 | 
						||
bool TStatisticaSog::menu(MENU_TAG m)
 | 
						||
{ 
 | 
						||
	TMask& msk = get_mask();
 | 
						||
	KEY tasto;
 | 
						||
 	tasto = msk.run();
 | 
						||
 	if (tasto == K_ENTER)
 | 
						||
 	{
 | 
						||
 		_sezini = _msk->get(F_SEZINI);
 | 
						||
 		_sotini = _msk->get(F_SOTINI);
 | 
						||
 		_sezfin = _msk->get(F_SEZFIN);
 | 
						||
 		_sotfin = _msk->get(F_SOTFIN);
 | 
						||
 		_catdon = _msk->get(F_CATDON);
 | 
						||
 		_data   = _msk->get_date(F_DATA);
 | 
						||
  	_pergruppo = _msk->get_bool(F_PERGRUPPO);
 | 
						||
  	_gruppoazie = _msk->get(F_GRUPPOAZIE);
 | 
						||
		_solotot = msk.get_bool(F_SOLOTOT);
 | 
						||
		if (riepilogo())
 | 
						||
			stampa();
 | 
						||
 	}
 | 
						||
 	return FALSE;
 | 
						||
}  
 | 
						||
 | 
						||
void TStatisticaSog::crea_intestazione()
 | 
						||
{ 
 | 
						||
	TPrintrow row;
 | 
						||
	TString256 sep;
 | 
						||
	sep = "STATISTICA SOGGETTI PER SESSO, GRUPPO E RH al ";
 | 
						||
	sep << _data.string();
 | 
						||
	sep.center_just(80);
 | 
						||
	row.put(sep);
 | 
						||
  row.put("@>", 1);
 | 
						||
  row.put("Pag. @#", 70);
 | 
						||
  printer().setheaderline(2, row);
 | 
						||
  sep = "";
 | 
						||
  if (_catdon.not_empty()) 
 | 
						||
  {
 | 
						||
  	sep << "Categoria " << _catdon << ' ';
 | 
						||
		sep << cache().get("CTD", _catdon).get("S0");
 | 
						||
	}		
 | 
						||
	else		
 | 
						||
		sep << "Tutte le categorie non dimessi";
 | 
						||
  sep.center_just(80);
 | 
						||
  row.reset();
 | 
						||
  row.put(sep);
 | 
						||
  printer().setheaderline(3, row);	  
 | 
						||
  sep = "";
 | 
						||
  sep << "Gruppo/Rh             Sconosciuto Maschi    Femmine   Non spec.  Totale";
 | 
						||
  row.reset();
 | 
						||
  row.put(sep);
 | 
						||
	printer().setheaderline(5, row);  
 | 
						||
	sep = "";
 | 
						||
	sep.fill('-',80);
 | 
						||
	row.reset();
 | 
						||
	row.put(sep);
 | 
						||
	printer().setheaderline(6, row);
 | 
						||
}
 | 
						||
 | 
						||
bool TStatisticaSog::stampa()
 | 
						||
{ 
 | 
						||
	if (printer().open())
 | 
						||
	{
 | 
						||
		_sezionistampate = 0;
 | 
						||
		crea_intestazione();
 | 
						||
		TRelation* relstat = new TRelation(LF_ATSTATS);
 | 
						||
		TCursor* curstat = new TCursor(relstat, "", 1);
 | 
						||
		TString16 oldsez = "**";
 | 
						||
		TString16 oldsot = "**";
 | 
						||
		double numero;
 | 
						||
		TString16 actsez, actsot;
 | 
						||
		TString16 gruppo, rh, sesso;
 | 
						||
		long last = curstat->items();
 | 
						||
	  for ( *curstat=0; curstat->pos() < last; ++(*curstat) )
 | 
						||
	  {
 | 
						||
			actsez = curstat->curr().get(ATSS_CODSEZ);																						  	
 | 
						||
			actsot = curstat->curr().get(ATSS_CODSOT);		
 | 
						||
			gruppo = curstat->curr().get(ATSS_GRUPPO);		
 | 
						||
			rh 		 = curstat->curr().get(ATSS_RH);		
 | 
						||
			sesso  = curstat->curr().get(ATSS_SESSO);		
 | 
						||
			if (sesso.empty())
 | 
						||
				sesso = "9";
 | 
						||
			numero = (double)curstat->curr().get_int(ATSS_NUMERO);		
 | 
						||
			if (actsez != oldsez || actsot != oldsot)
 | 
						||
			{                 
 | 
						||
				if (oldsez != "**" && oldsot != "**")
 | 
						||
				{
 | 
						||
					stampa_sezione(oldsez,oldsot);
 | 
						||
					azzera_righe();
 | 
						||
				}
 | 
						||
				oldsez = actsez;
 | 
						||
				oldsot = actsot;
 | 
						||
			}				
 | 
						||
			TRigaSGruppo& riga = (TRigaSGruppo&)_righe[data2row(gruppo,rh)];
 | 
						||
			real& colonna = (real&)_colonne->find((const char*)sesso);
 | 
						||
			real n = numero;
 | 
						||
			riga.aggiorna_valore((int) colonna.integer(),n);
 | 
						||
		}                             
 | 
						||
		if (oldsez != "**" && oldsot != "**")
 | 
						||
			stampa_sezione(oldsez,oldsot);
 | 
						||
		delete curstat;
 | 
						||
		delete relstat;
 | 
						||
		printer().close();
 | 
						||
		return TRUE;
 | 
						||
	}
 | 
						||
	else
 | 
						||
		return FALSE;		
 | 
						||
}
 | 
						||
 | 
						||
void TStatisticaSog::azzera_righe()
 | 
						||
{
 | 
						||
	TString16 gruppo, rh;
 | 
						||
	for (int igruppo=0;igruppo<=8;igruppo++)
 | 
						||
	{		
 | 
						||
		switch (igruppo)
 | 
						||
		{  
 | 
						||
			case 0 : gruppo = "";   break;
 | 
						||
			case 1 : gruppo = "0";   break;
 | 
						||
			case 2 : gruppo = "A";   break;
 | 
						||
			case 3 : gruppo = "A1";  break;		
 | 
						||
			case 4 : gruppo = "A2"; break;
 | 
						||
			case 5 : gruppo = "A1B";  break;
 | 
						||
			case 6 : gruppo = "A2B"; break;						
 | 
						||
			case 7 : gruppo = "AB";  break;		
 | 
						||
			case 8 : gruppo = "B";   break;		
 | 
						||
		}            
 | 
						||
		for (int irh=0;irh <=2;irh++)
 | 
						||
		{
 | 
						||
			switch (irh)
 | 
						||
			{  
 | 
						||
				case 1  : rh = "POS"; break;
 | 
						||
				case 2  : rh = "NEG"; break;
 | 
						||
				default : rh = "   "; break;		
 | 
						||
			}            
 | 
						||
			TRigaSGruppo& riga = (TRigaSGruppo&)_righe[data2row(gruppo,rh)];
 | 
						||
			riga.azzera_valori();
 | 
						||
		}
 | 
						||
	}		
 | 
						||
}
 | 
						||
 | 
						||
void TStatisticaSog::stampa_sezione(TString16 codsez, TString16 codsot)
 | 
						||
{ 
 | 
						||
	TPrintrow row;
 | 
						||
	TString256 rigastampa;
 | 
						||
	if (codsez == "ZZ" && codsot == "ZZ")
 | 
						||
	{
 | 
						||
		if (_sezionistampate != 1)
 | 
						||
		{
 | 
						||
			rigastampa = "";
 | 
						||
			rigastampa << "RIEPILOGO TOTALE SEZIONI DA " << _sezini << '/' << _sotini << " A " << _sezfin << '/' << _sotfin;
 | 
						||
			if (_pergruppo)
 | 
						||
				rigastampa << " - SOLO GRUPPI AZIENDALI";
 | 
						||
		}	
 | 
						||
	}	
 | 
						||
	else
 | 
						||
	{
 | 
						||
		_sezionistampate++;
 | 
						||
		if (_pergruppo)
 | 
						||
		{
 | 
						||
			rigastampa = "Gruppo aziendale ";
 | 
						||
			rigastampa << codsez;
 | 
						||
			rigastampa << codsot;
 | 
						||
		}
 | 
						||
		else
 | 
						||
		{		
 | 
						||
			rigastampa = "Sezione: ";
 | 
						||
			rigastampa << codsez;
 | 
						||
			if (codsot.not_empty())
 | 
						||
			{
 | 
						||
				rigastampa << "/";
 | 
						||
				rigastampa << codsot;
 | 
						||
			}		
 | 
						||
			rigastampa << " ";
 | 
						||
			TLocalisamfile sezioni(LF_SEZIONI);
 | 
						||
			sezioni.setkey(1);
 | 
						||
			sezioni.zero();
 | 
						||
			sezioni.put(SEZ_CODSEZ,codsez);
 | 
						||
			sezioni.put(SEZ_CODSOT,codsot);	
 | 
						||
			if (sezioni.read() == NOERR)
 | 
						||
			{
 | 
						||
				TString80 den = sezioni.get(SEZ_DENSEZ);
 | 
						||
				rigastampa << den;
 | 
						||
				den = sezioni.get(SEZ_DENSOT);
 | 
						||
				if (den.not_empty())
 | 
						||
				{
 | 
						||
					rigastampa << "/";
 | 
						||
					rigastampa << den;
 | 
						||
				}
 | 
						||
			}
 | 
						||
		}	
 | 
						||
	}	
 | 
						||
	if ((codsez == "ZZ" && codsot == "ZZ" && _sezionistampate != 1) || (codsez != "ZZ"))
 | 
						||
	{
 | 
						||
		rigastampa.center_just(80);
 | 
						||
		row.put(rigastampa);
 | 
						||
	  printer().setheaderline(1, row);
 | 
						||
	  
 | 
						||
	  TRigaSGruppo rigatotali("   ","   ");
 | 
						||
		TString16 valore;
 | 
						||
		TString16 gruppo, rh;
 | 
						||
		real totalegruppo = ZERO;
 | 
						||
		for (int igruppo=0;igruppo<=8;igruppo++)
 | 
						||
		{		
 | 
						||
			switch (igruppo)
 | 
						||
			{  
 | 
						||
				case 0 : gruppo = "";   break;
 | 
						||
				case 1 : gruppo = "0";   break;
 | 
						||
				case 2 : gruppo = "A";   break;
 | 
						||
				case 3 : gruppo = "A1";  break;		
 | 
						||
				case 4 : gruppo = "A2"; break;
 | 
						||
				case 5 : gruppo = "A1B";  break;
 | 
						||
				case 6 : gruppo = "A2B"; break;						
 | 
						||
				case 7 : gruppo = "AB";  break;		
 | 
						||
				case 8 : gruppo = "B";   break;		
 | 
						||
			}            
 | 
						||
			for (int irh=0;irh <=2;irh++)
 | 
						||
			{
 | 
						||
				switch (irh)
 | 
						||
				{  
 | 
						||
					case 1  : rh = "POS"; break;
 | 
						||
					case 2  : rh = "NEG"; break;
 | 
						||
					default : rh = "   "; break;		
 | 
						||
				}            
 | 
						||
				TRigaSGruppo& riga = (TRigaSGruppo&)_righe[data2row(gruppo,rh)];
 | 
						||
				row.reset();
 | 
						||
				rigastampa = "";
 | 
						||
				rigastampa << gruppo;
 | 
						||
				rigastampa << " ";
 | 
						||
				rigastampa << rh;
 | 
						||
				totalegruppo = ZERO;
 | 
						||
				int pos = 21;
 | 
						||
				for (int i=0;i<_colonne->items();i++)
 | 
						||
				{                      
 | 
						||
					rigatotali.aggiorna_valore(i,riga[i]);
 | 
						||
					totalegruppo+=riga[i];
 | 
						||
					valore = "";
 | 
						||
					valore.format("%8s",riga[i].string(8,0));
 | 
						||
					rigastampa.overwrite((const char*)valore, pos);
 | 
						||
					pos = pos+10;
 | 
						||
				}           
 | 
						||
				if (totalegruppo != 0)
 | 
						||
				{
 | 
						||
					valore = "";
 | 
						||
					valore.format("%8s",totalegruppo.string(8,0));
 | 
						||
					rigastampa.overwrite((const char*)valore, pos+4);
 | 
						||
					row.put((const char*) rigastampa);
 | 
						||
					printer().print(row);			
 | 
						||
				}				
 | 
						||
			}			
 | 
						||
		}	
 | 
						||
		// stampa totali per sezione
 | 
						||
		rigastampa = "";
 | 
						||
		rigastampa.fill('-',80);
 | 
						||
		row.reset();
 | 
						||
		row.put(rigastampa);
 | 
						||
		printer().print(row);
 | 
						||
		row.reset();
 | 
						||
		rigastampa = "";
 | 
						||
		rigastampa = "Totale";
 | 
						||
		real totale;
 | 
						||
		totale = ZERO;
 | 
						||
		int pos = 21;
 | 
						||
		for (int i=0;i<_colonne->items();i++)
 | 
						||
		{                      
 | 
						||
			totale+=rigatotali[i];
 | 
						||
			valore = "";
 | 
						||
			valore.format("%8s",rigatotali[i].string(8,0));
 | 
						||
			rigastampa.overwrite((const char*)valore, pos);
 | 
						||
			pos = pos+10;
 | 
						||
		}         
 | 
						||
		valore = "";
 | 
						||
		valore.format("%8s",totale.string(8,0));
 | 
						||
		rigastampa.overwrite((const char*)valore, pos+4);
 | 
						||
		row.put((const char*) rigastampa);
 | 
						||
		printer().print(row);
 | 
						||
		printer().formfeed();
 | 
						||
	}		
 | 
						||
}
 | 
						||
 | 
						||
bool TStatisticaSog::riepilogo()
 | 
						||
{            
 | 
						||
	if (crea_colonne() && crea_righe())
 | 
						||
	{   
 | 
						||
		// cancello i risultati della elaborazione precedente
 | 
						||
		TLocalisamfile stat(LF_ATSTATS);
 | 
						||
		for (stat.first(); !stat.eof(); stat.next())
 | 
						||
			stat.remove();
 | 
						||
		stat.setkey(1);			
 | 
						||
		_cur = new TCursor(_rel, "", 1);  
 | 
						||
		TString256 filtro = "";
 | 
						||
		// filtro per sezione/sottogruppo
 | 
						||
	 	if (_sezini.not_empty())
 | 
						||
	 	{
 | 
						||
	 		if (_sotini.not_empty())
 | 
						||
	 		{                    
 | 
						||
	 			filtro << "(";
 | 
						||
	 			filtro << format("(90->CODSEZ > \"%s\")",(const char*)_sezini);
 | 
						||
	 			filtro << " || ";
 | 
						||
	 			filtro << "(" << format("(90->CODSEZ == \"%s\")",(const char*)_sezini);
 | 
						||
	 			filtro << " && ";
 | 
						||
	 			filtro << format("(90->CODSOT >= \"%s\")",(const char*)_sotini);
 | 
						||
	 			filtro << ")";
 | 
						||
	 			filtro << ")";
 | 
						||
	 		}
 | 
						||
	 		else
 | 
						||
		 			filtro << format("(90->CODSEZ >= \"%s\")",(const char*)_sezini);
 | 
						||
	 	}
 | 
						||
	 	if (_sezfin.not_empty())
 | 
						||
	 	{
 | 
						||
 			if (filtro.not_empty())
 | 
						||
 				filtro << " && "; 
 | 
						||
	 	
 | 
						||
	 		if (_sotfin.not_empty())
 | 
						||
	 		{          
 | 
						||
	 			filtro << "(";
 | 
						||
	 			filtro << format("(90->CODSEZ < \"%s\")",(const char*)_sezfin);
 | 
						||
	 			filtro << " || ";
 | 
						||
	 			filtro << "(" << format("(90->CODSEZ == \"%s\")",(const char*)_sezfin);
 | 
						||
	 			filtro << " && ";
 | 
						||
	 			filtro << format("(90->CODSOT <= \"%s\")",(const char*)_sotfin);
 | 
						||
	 			filtro << ")";
 | 
						||
	 			filtro << ")";
 | 
						||
	 		}
 | 
						||
	 		else
 | 
						||
	 			filtro << format("(90->CODSEZ <= \"%s\")",(const char*)_sezfin);
 | 
						||
		}
 | 
						||
  	if (_pergruppo)
 | 
						||
  	{ 	                          
 | 
						||
 			if (filtro.not_empty())
 | 
						||
 				filtro << " && "; 
 | 
						||
  		if (_gruppoazie.not_empty())
 | 
						||
	  		filtro << format("(90->GRUPPOAZIE == \"%s\")",(const char*)_gruppoazie);
 | 
						||
			else	  		
 | 
						||
	  		filtro << format("(90->GRUPPOAZIE != \"\")");
 | 
						||
		}	  		
 | 
						||
		_cur->setfilter((const char*) filtro, TRUE);
 | 
						||
		TString16 codsez, codsot, catdon, catcoll, gruppoazie;
 | 
						||
		long numero;  
 | 
						||
		TString16 gruppo, rh, sesso;
 | 
						||
		TDate dataisc, datadim;
 | 
						||
		bool catdim, ok;
 | 
						||
		catdim =  cache().get("CTD", _catdon).get_bool("B0");
 | 
						||
		TRectype& recsog = _cur->curr();
 | 
						||
  	long last = _cur->items();   
 | 
						||
  	TProgind prg (last, "Elaborazione in corso... Prego attendere", FALSE, TRUE, 30);
 | 
						||
  	for ( *_cur=0; _cur->pos() < last; ++(*_cur) )
 | 
						||
  	{
 | 
						||
    	prg.addstatus(1);
 | 
						||
			catdon = recsog.get(SOG_CATDON);
 | 
						||
			catcoll = "";
 | 
						||
			dataisc = NULLDATE;
 | 
						||
			datadim = NULLDATE;
 | 
						||
			ok = FALSE;
 | 
						||
			if (catdon.not_empty())
 | 
						||
			{       
 | 
						||
				if (_catdon.not_empty())
 | 
						||
				{
 | 
						||
					if (catdim)
 | 
						||
					{	                       
 | 
						||
						datadim = recsog.get_date(SOG_DATADIM);
 | 
						||
				  	ok = ((catdon == _catdon) && (datadim <= _data));
 | 
						||
					}
 | 
						||
					else
 | 
						||
					{        
 | 
						||
						dataisc = recsog.get_date(SOG_DATAISC);
 | 
						||
						ok = ((catdon == _catdon) && (dataisc <= _data));			
 | 
						||
						if (!ok)
 | 
						||
						{
 | 
						||
								catcoll = cache().get("CTD", catdon).get("S6");
 | 
						||
								datadim = recsog.get_date(SOG_DATADIM);
 | 
						||
								ok = ((catcoll == _catdon) && (dataisc <= _data) && (datadim > _data));
 | 
						||
							// se la categoria collegata <20> vuota occorre esaminare lo storico
 | 
						||
						}						
 | 
						||
					}	
 | 
						||
				}
 | 
						||
				else
 | 
						||
				{
 | 
						||
					dataisc = recsog.get_date(SOG_DATAISC);
 | 
						||
					datadim = recsog.get_date(SOG_DATADIM);
 | 
						||
					if (cache().get("CTD", catdon).get_bool("B0"))
 | 
						||
				  	ok = ((dataisc <= _data) && (datadim > _data));
 | 
						||
					else
 | 
						||
						ok = (dataisc <= _data);			
 | 
						||
				}	
 | 
						||
			}									
 | 
						||
			if (ok)
 | 
						||
			{
 | 
						||
				if (_pergruppo)
 | 
						||
				{
 | 
						||
					gruppoazie = recsog.get(SOG_GRUPPOAZIE);
 | 
						||
					codsez = gruppoazie.sub(0,2);
 | 
						||
					codsot = gruppoazie.sub(2,4);
 | 
						||
				}	
 | 
						||
				else                                      
 | 
						||
				{
 | 
						||
					codsez = recsog.get(SOG_CODSEZ);
 | 
						||
					codsot = recsog.get(SOG_CODSOT);
 | 
						||
				}	
 | 
						||
				gruppo = recsog.get(SOG_GRUPPOAB0);
 | 
						||
				rh 		 = recsog.get(SOG_RHANTID);
 | 
						||
				sesso  = recsog.get(SOG_SESSO);
 | 
						||
				if (sesso.empty())
 | 
						||
					sesso = "9";
 | 
						||
				if (gruppo == "A1" || gruppo == "A2")
 | 
						||
					gruppo = "A";
 | 
						||
				if (gruppo == "A1B" || gruppo == "A2B")
 | 
						||
					gruppo = "AB";
 | 
						||
				if (!_solotot)
 | 
						||
				{
 | 
						||
					stat.zero();
 | 
						||
					stat.put(ATSS_CODSEZ, codsez);  	 
 | 
						||
					stat.put(ATSS_CODSOT, codsot);  	 
 | 
						||
					stat.put(ATSS_SESSO, 	sesso);  	 
 | 
						||
					stat.put(ATSS_GRUPPO, gruppo);  	 
 | 
						||
					stat.put(ATSS_RH, rh);  	 
 | 
						||
					if (stat.read() == NOERR)
 | 
						||
					{
 | 
						||
						numero = stat.get_long(ATSS_NUMERO);
 | 
						||
						numero++;
 | 
						||
						stat.put(ATSS_NUMERO, numero);
 | 
						||
						stat.rewrite();			
 | 
						||
					}			
 | 
						||
					else
 | 
						||
					{
 | 
						||
						stat.put(ATSS_CODSEZ, codsez);  	 
 | 
						||
						stat.put(ATSS_CODSOT, codsot);  	 
 | 
						||
						stat.put(ATSS_SESSO, sesso);  	 
 | 
						||
						stat.put(ATSS_GRUPPO, gruppo);  	 
 | 
						||
						stat.put(ATSS_RH, rh);  	 
 | 
						||
						numero = 1;
 | 
						||
						stat.put(ATSS_NUMERO, numero);
 | 
						||
						stat.write();
 | 
						||
					}
 | 
						||
				}	
 | 
						||
				stat.zero();
 | 
						||
				stat.put(ATSS_CODSEZ, "ZZ");  	 
 | 
						||
				stat.put(ATSS_CODSOT, "ZZ");  	 
 | 
						||
				stat.put(ATSS_SESSO, 	sesso);  	 
 | 
						||
				stat.put(ATSS_GRUPPO, gruppo);  	 
 | 
						||
				stat.put(ATSS_RH, rh);  	 
 | 
						||
				if (stat.read() == NOERR)
 | 
						||
				{
 | 
						||
					numero = stat.get_long(ATSS_NUMERO);
 | 
						||
					numero++;
 | 
						||
					stat.put(ATSS_NUMERO, numero);
 | 
						||
					stat.rewrite();			
 | 
						||
				}			
 | 
						||
				else
 | 
						||
				{
 | 
						||
					stat.put(ATSS_CODSEZ, "ZZ");  	 
 | 
						||
					stat.put(ATSS_CODSOT, "ZZ");  	 
 | 
						||
					stat.put(ATSS_SESSO, sesso);  	 
 | 
						||
					stat.put(ATSS_GRUPPO, gruppo);  	 
 | 
						||
					stat.put(ATSS_RH, rh);  	 
 | 
						||
					numero = 1;
 | 
						||
					stat.put(ATSS_NUMERO, numero);
 | 
						||
					stat.write();
 | 
						||
				}
 | 
						||
			}				
 | 
						||
		}	
 | 
						||
		return (stat.eod() > 0);
 | 
						||
	}		
 | 
						||
	else
 | 
						||
		return FALSE;	
 | 
						||
}         
 | 
						||
 | 
						||
int at3700(int argc, char* argv[])
 | 
						||
{
 | 
						||
	TStatisticaSog a;
 | 
						||
	a.run(argc, argv, "Statistica soggetti per sesso, gruppo e rh");
 | 
						||
	return 0;
 | 
						||
} |