459 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			459 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <mask.h>
 | 
						|
#include <msksheet.h>
 | 
						|
#include <form.h>
 | 
						|
#include <printapp.h>
 | 
						|
 | 
						|
#include "lf.h"
 | 
						|
#include "soggetti.h"
 | 
						|
#include "sezioni.h"
 | 
						|
 | 
						|
#include "at3.h"
 | 
						|
#include "at3100a.h"
 | 
						|
 | 
						|
 | 
						|
#define	ALIAS_TABCTD	100			// alias tabella categorie donatori
 | 
						|
#define ALIAS_TABTCS	200			// alias tabella tipi/esiti controlli sanitari
 | 
						|
#define ALIAS_TABLCP	300			// alias tabella località postali
 | 
						|
 | 
						|
 | 
						|
#define STATO_IDONEO  'I'			// IDONEITA'
 | 
						|
#define STATO_FINESO	'F'			// FINE SOSPENSIONE
 | 
						|
 | 
						|
enum ts { undefined = 0, elenco = 1, etichette = 2, cartoline = 3 };
 | 
						|
 | 
						|
// definizione form per etichette e cartoline
 | 
						|
class TConv_form : public TForm
 | 
						|
{
 | 
						|
public:
 | 
						|
	
 | 
						|
	virtual TCursor* cursor() const;
 | 
						|
	virtual TRelation* relation() const;
 | 
						|
	TPrint_section& get_body() { return section('B'); } ;
 | 
						|
  TConv_form(): TForm() {};
 | 
						|
  TConv_form(const char* form, const char * code = "", int editlevel = 0, const char* desc = "")
 | 
						|
    						: TForm(form,code,editlevel,desc) {};
 | 
						|
  virtual ~TConv_form() {};
 | 
						|
};
 | 
						|
 | 
						|
class TConv_application : public TPrintapp
 | 
						|
{
 | 
						|
  static bool filter_func_conv(const TRelation *);
 | 
						|
 | 
						|
  TRelation*        _rel;
 | 
						|
  TMask*            _msk;
 | 
						|
  TConv_form*				_form_eti;	// per etichette
 | 
						|
  TConv_form*				_form_car;	// per cartoline
 | 
						|
  
 | 
						|
	TAssoc_array*			_asezioni;	// array per controllare che non venga convocata
 | 
						|
																// 2 volte la stessa sezione/sottogruppo
 | 
						|
  
 | 
						|
  int 							_cur1, _cur2, _cur3, _cur4;
 | 
						|
  TDate 						_data_stampa;      
 | 
						|
  
 | 
						|
  int								_sez_corrente;
 | 
						|
  ts								_tipo_stampa;
 | 
						|
  bool							_intesta;
 | 
						|
  
 | 
						|
  // completare con tutti i dati selezionabili
 | 
						|
  TString						_codsez, _codsot;
 | 
						|
  TDate							_dataconv;
 | 
						|
  long 							_intmin, _intmax;
 | 
						|
	
 | 
						|
  
 | 
						|
protected:
 | 
						|
  virtual bool user_create();
 | 
						|
  virtual bool user_destroy();
 | 
						|
  virtual bool set_print(int m);
 | 
						|
  virtual void set_page(int file, int cnt);
 | 
						|
  virtual void print();
 | 
						|
  virtual bool preprocess_page (int file, int counter);
 | 
						|
 | 
						|
	virtual TAssoc_array& get_array_sez() { return *_asezioni; }
 | 
						|
	static bool check_sez_sheet(const char* codice);	
 | 
						|
	static bool convocazioni_notify(TSheet_field& s, int r, KEY k);
 | 
						|
	static void add_rows_convocazioni(TSheet_field& s, int count = 10, int start = 1);
 | 
						|
 | 
						|
public:
 | 
						|
  void crea_intestazione();
 | 
						|
  void filtra_sezione();
 | 
						|
  void header_sezione();
 | 
						|
  
 | 
						|
  TConv_application() : _data_stampa(TODAY) {}
 | 
						|
};
 | 
						|
 | 
						|
HIDDEN inline TConv_application& app() { return (TConv_application&) main_app(); }
 | 
						|
 | 
						|
TCursor* TConv_form::cursor() const { return app().current_cursor(); }
 | 
						|
 | 
						|
TRelation* TConv_form::relation() const { return cursor()->relation(); }
 | 
						|
 | 
						|
void TConv_application::add_rows_convocazioni(TSheet_field& s, int count, int start)
 | 
						|
{
 | 
						|
	if (start == 1)
 | 
						|
		s.destroy();
 | 
						|
	for (int r=start; r<start+count; r++)
 | 
						|
		TToken_string& row = s.row(r-1);
 | 
						|
}
 | 
						|
 | 
						|
void TConv_application::set_page(int file, int cnt)
 | 
						|
{
 | 
						|
	switch (_tipo_stampa)
 | 
						|
	{
 | 
						|
		case elenco:
 | 
						|
		{
 | 
						|
			set_row(1,"@0g@pn", FLD(LF_SOGGETTI,SOG_CODICE,"#########"));
 | 
						|
			set_row(1,"@10g@S", FLD(LF_SOGGETTI,SOG_CATDON));
 | 
						|
			set_row(1,"@13g@S", FLD(LF_SOGGETTI,SOG_COGNOME));
 | 
						|
			set_row(1,"@39g@ld", FLD(LF_SOGGETTI,SOG_DATANASC));
 | 
						|
			set_row(1,"@50g@ld", FLD(LF_SOGGETTI,SOG_DATAPROSSI));
 | 
						|
			set_row(1,"@61g@ld", FLD(LF_SOGGETTI,SOG_DATAPROSAF));
 | 
						|
			set_row(1,"@72g@ld", FLD(LF_SOGGETTI,SOG_DATAULTDON));
 | 
						|
			set_row(1,"@83g@ld", FLD(LF_SOGGETTI,SOG_DATAULTID));
 | 
						|
			set_row(1,"@94g@S", FLD(LF_SOGGETTI,SOG_IDON1));
 | 
						|
			set_row(1,"@97g@S", FLD(LF_SOGGETTI,SOG_IDON2));
 | 
						|
			
 | 
						|
			set_row(2,"@13g@S", FLD(LF_SOGGETTI,SOG_NOME));
 | 
						|
			set_row(2,"@53g@pn", FLD(LF_SOGGETTI,SOG_INTSI,"###"));
 | 
						|
			set_row(2,"@64g@pn", FLD(LF_SOGGETTI,SOG_INTAF,"###"));
 | 
						|
			set_row(2,"@76g@S", FLD(LF_SOGGETTI,SOG_TIPOULTDON));
 | 
						|
			set_row(2,"@87g@S", FLD(LF_SOGGETTI,SOG_TIPOULTID));
 | 
						|
			set_row(2,"@94g@S", FLD(LF_SOGGETTI,SOG_IDON3));
 | 
						|
			set_row(2,"@97g@S", FLD(LF_SOGGETTI,SOG_IDON4));
 | 
						|
		}
 | 
						|
		break;
 | 
						|
		case etichette:
 | 
						|
		{
 | 
						|
			TPrint_section& corpo = _form_eti->get_body();
 | 
						|
			corpo.reset();
 | 
						|
			corpo.update();
 | 
						|
  		for (int i = 0; i < corpo.items(); i++)
 | 
						|
  		{
 | 
						|
  			TPrintrow& riga = corpo.row(i);
 | 
						|
  			set_row(i+1,"%s",riga.row());
 | 
						|
			}  			
 | 
						|
			force_setpage(TRUE);	// serve perchè alla prossima etichetta rifaccia la setpage
 | 
						|
														// altrimenti stampa sempre la stessa etichetta
 | 
						|
		}
 | 
						|
		break;
 | 
						|
		case cartoline:
 | 
						|
		{
 | 
						|
			TPrint_section& corpo = _form_car->get_body();
 | 
						|
			corpo.reset();
 | 
						|
			corpo.update();
 | 
						|
  		for (int i = 0; i < corpo.items(); i++)
 | 
						|
  		{
 | 
						|
  			TPrintrow& riga = corpo.row(i);
 | 
						|
  			set_row(i+1,"%s",riga.row());
 | 
						|
			}  			
 | 
						|
			force_setpage(TRUE);	// serve perchè alla prossima etichetta rifaccia la setpage
 | 
						|
														// altrimenti stampa sempre la stessa etichetta
 | 
						|
		}
 | 
						|
		break;
 | 
						|
	}					
 | 
						|
}
 | 
						|
 | 
						|
bool TConv_application::filter_func_conv (const TRelation * rel)
 | 
						|
{
 | 
						|
  TLocalisamfile&  sog = rel->lfile(LF_SOGGETTI);
 | 
						|
  TDate	dataprossi = sog.curr().get_date(SOG_DATAPROSSI);
 | 
						|
  
 | 
						|
	const char stato = rel->curr(-ALIAS_TABTCS).get_char("S6");
 | 
						|
	const bool dimesso = rel->curr(-ALIAS_TABCTD).get_char("B0");
 | 
						|
 | 
						|
 | 
						|
  //TDate dataultconv = sog.curr().get_date(SOG_DATAULTCONV);
 | 
						|
  if (dataprossi.ok())
 | 
						|
	{                                              
 | 
						|
		// intervallo tra data convocazione e data calcolata per pross. si
 | 
						|
  	long intconvsi = app()._dataconv - dataprossi;  
 | 
						|
  	// intervallo tra data convocazione e data ultima convocazione 
 | 
						|
  	//long intultconvsi = app()._data - dataultconv;
 | 
						|
  	
 | 
						|
  	if ((intconvsi >= 0) && (intconvsi < app()._intmax) && ((stato == STATO_IDONEO) || (stato == STATO_FINESO)) && (dimesso != 'X')) 
 | 
						|
  		return TRUE;
 | 
						|
  	else          
 | 
						|
  		return FALSE;
 | 
						|
	} 	
 | 
						|
  else
 | 
						|
  	// non ha la data di prossima donazione SI
 | 
						|
  	return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
bool TConv_application::preprocess_page(int file, int counter)
 | 
						|
{
 | 
						|
	if ((_tipo_stampa == elenco) && (!_intesta)) 
 | 
						|
	{
 | 
						|
		_intesta = TRUE;
 | 
						|
		header_sezione();
 | 
						|
	}
 | 
						|
	// contatore soggetti stampati
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TConv_application::print()
 | 
						|
{
 | 
						|
	_intesta = FALSE;
 | 
						|
	filtra_sezione();
 | 
						|
	TPrint_application::print();
 | 
						|
	TSheet_field& s = (TSheet_field&)_msk->field(F_CONVOCAZIONI);
 | 
						|
	_sez_corrente++;                
 | 
						|
	if (_sez_corrente <= s.items())
 | 
						|
		repeat_print();
 | 
						|
	return;		
 | 
						|
}
 | 
						|
 | 
						|
void TConv_application::filtra_sezione()
 | 
						|
{
 | 
						|
	TSheet_field& s = (TSheet_field&)_msk->field(F_CONVOCAZIONI);
 | 
						|
	TToken_string& row = s.row(_sez_corrente-1);
 | 
						|
	_codsez = row.get(0);
 | 
						|
	_codsot = row.get();
 | 
						|
	_dataconv = row.get();
 | 
						|
	// deve diventare un membro
 | 
						|
	TString _giorno = row.get();
 | 
						|
	_intmin = row.get_int();
 | 
						|
	_intmax = row.get_int();
 | 
						|
	// deve diventare un membro
 | 
						|
	TString _tipoconv = row.get();
 | 
						|
                         
 | 
						|
  select_cursor(_cur4);
 | 
						|
  TLocalisamfile& fl = current_cursor()->file(LF_SOGGETTI);
 | 
						|
  TRectype da(fl.curr());
 | 
						|
  TRectype a(fl.curr());   
 | 
						|
  da.zero();
 | 
						|
  a.zero('Z');
 | 
						|
  if ((_codsez.not_empty()) && (_codsez.ok()))
 | 
						|
  {
 | 
						|
		da.put(SOG_CODSEZ, _codsez);
 | 
						|
		a.put(SOG_CODSEZ, _codsez);
 | 
						|
	}	
 | 
						|
  if ((_codsot.not_empty()) && (_codsot.ok()))    	
 | 
						|
  {
 | 
						|
		da.put(SOG_CODSOT, _codsot);
 | 
						|
		a.put(SOG_CODSOT, _codsot);
 | 
						|
	}
 | 
						|
	current_cursor()->freeze(FALSE);
 | 
						|
	current_cursor()->setregion(da, a);
 | 
						|
}    
 | 
						|
 | 
						|
bool TConv_application::set_print(int)
 | 
						|
{           
 | 
						|
  TSheet_field& s = (TSheet_field&)_msk->field(F_CONVOCAZIONI);
 | 
						|
  if (s.items()==0)
 | 
						|
  	add_rows_convocazioni(s,8);
 | 
						|
  _asezioni->destroy();
 | 
						|
 	for (int r=0; r < s.items(); r++)
 | 
						|
 	{
 | 
						|
 		TToken_string& row = s.row(r);
 | 
						|
 		TString codice = row.get(0);
 | 
						|
 		TString codsot = row.get();
 | 
						|
 		codice << codsot;
 | 
						|
 		if (codice.not_empty())
 | 
						|
 			_asezioni->add(codice);
 | 
						|
 	}
 | 
						|
	_tipo_stampa = undefined;
 | 
						|
  KEY tasto;
 | 
						|
  tasto = _msk->run();
 | 
						|
	switch (tasto)               
 | 
						|
	{
 | 
						|
		case F_ELENCO:
 | 
						|
			_tipo_stampa = elenco;
 | 
						|
			break;		
 | 
						|
		case F_ETICHETTE:
 | 
						|
			_tipo_stampa = etichette;
 | 
						|
			break;
 | 
						|
		case F_CARTOLINE:
 | 
						|
			_tipo_stampa = cartoline;
 | 
						|
			break;			
 | 
						|
		case K_ESC:			
 | 
						|
			_msk->reset();
 | 
						|
	}
 | 
						|
  if (_tipo_stampa != undefined)
 | 
						|
  {
 | 
						|
    reset_files(); 
 | 
						|
    add_file(LF_SOGGETTI);
 | 
						|
    
 | 
						|
    select_cursor(_cur4);
 | 
						|
		TSheet_field& s = (TSheet_field&)_msk->field(F_CONVOCAZIONI);
 | 
						|
   	for (int r=s.items()-1; r>=s.first_empty(); r--)
 | 
						|
   	{
 | 
						|
			TToken_string& row = s.row(r);
 | 
						|
			_codsez = row.get(0);
 | 
						|
			_codsot = row.get();
 | 
						|
			if (_codsez.empty() || (!_codsez.ok()))
 | 
						|
				s.destroy(r);
 | 
						|
		}						
 | 
						|
		// filtro su non esclusi, idonei e categorie non dimessi
 | 
						|
		// questo filtro non funziona perchè non funziona il riconoscimento dell'alias 
 | 
						|
		// nelle espressioni; sarebbe molto bello averlo a disposizione!
 | 
						|
		//current_cursor()->setfilter("((ESCLUSO == \"\") && (-100->B0!=\"X\") && ((-200->S6 == \"I\") || (-200->S6 == \"F\")))", TRUE);
 | 
						|
		// filtro su non esclusi
 | 
						|
		current_cursor()->setfilter("(ESCLUSO == \"\")", TRUE);
 | 
						|
   	// filtro su data e altri filtri che non posso mettere nella setfilter
 | 
						|
    current_cursor()->set_filterfunction (filter_func_conv, TRUE);
 | 
						|
    reset_print();
 | 
						|
    _sez_corrente = 1;
 | 
						|
    crea_intestazione();
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
  else
 | 
						|
    return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
void TConv_application::crea_intestazione()
 | 
						|
{
 | 
						|
 | 
						|
  reset_header();
 | 
						|
  
 | 
						|
  if (_tipo_stampa == elenco)
 | 
						|
  {
 | 
						|
  	TString sep(132);
 | 
						|
  	sep = "";
 | 
						|
  	sep.fill('-');
 | 
						|
  	set_header(3, (const char *) sep);
 | 
						|
  
 | 
						|
	  set_header(5,"@0gCod.@10gC.@13gCognome@39gNato il@50gData pr.SI@61gData pr.AF@72gData/Tipo@83gData/Tipo@94gIdon.");
 | 
						|
	  set_header(6,"@13gNome@50gInterv. SI@61gInterv. AF@72gult. don.@83gult. idon.@94gper");  
 | 
						|
	  set_header(7,"@0g---------@10g--@13g-------------------------@39g----------@50g----------@61g----------@72g----------@83g----------@94g-----");
 | 
						|
	}	  
 | 
						|
}
 | 
						|
 | 
						|
void TConv_application::header_sezione()
 | 
						|
{
 | 
						|
	TString densez = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSEZ);
 | 
						|
	TString densot = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSOT);
 | 
						|
	TString intestazione(132);
 | 
						|
	intestazione = "Sezione: ";
 | 
						|
	intestazione << _codsez;
 | 
						|
	intestazione << "/";
 | 
						|
	intestazione << _codsot;
 | 
						|
	intestazione << " ";
 | 
						|
	intestazione << densez;
 | 
						|
	if ((densot.ok())&& (densot.not_empty()))
 | 
						|
	{
 | 
						|
		intestazione << "/";
 | 
						|
		intestazione << densot;
 | 
						|
	}		
 | 
						|
	intestazione.center_just();
 | 
						|
	set_header(1,"@0g%s", (const char*) intestazione);
 | 
						|
	
 | 
						|
	intestazione = "ELENCO CONVOCATI PER IL ";
 | 
						|
	intestazione << _dataconv.string();	
 | 
						|
	intestazione.center_just();
 | 
						|
	set_header(2, "@0g%s", (const char*) intestazione);
 | 
						|
	TString data_stampa = _data_stampa.string();
 | 
						|
	set_header(2,"@0g%10s", (const char*) data_stampa);
 | 
						|
	intestazione = "";
 | 
						|
	intestazione << "Pag. @#";
 | 
						|
	set_header(2, "@120g%s", (const char*) intestazione);  
 | 
						|
	
 | 
						|
	return;
 | 
						|
}
 | 
						|
 | 
						|
bool TConv_application::user_create()
 | 
						|
{
 | 
						|
  _rel = new TRelation(LF_SOGGETTI);
 | 
						|
  _rel->add("TCS", "CODTAB==STATO",    1, 0, ALIAS_TABTCS);	// per verificare che sia IDONEO
 | 
						|
  _rel->add("CTD", "CODTAB==CATDON",   1, 0, ALIAS_TABCTD);		// per verificare che sia DONATORE NON DIMESSO
 | 
						|
  _rel->add("LCP", "CODTAB==LOCALITA", 1, 0, ALIAS_TABLCP);		// per verificare che sia DONATORE NON DIMESSO
 | 
						|
  _rel->add(LF_COMUNI, "COM==COM");
 | 
						|
  _rel->add(LF_SEZIONI, "CODSEZ==CODSEZ|CODSOT==CODSOT");
 | 
						|
 | 
						|
  _cur1 = add_cursor(new TCursor(_rel, "", 1));	//cursore ordinamento per codice
 | 
						|
  _cur2 = add_cursor(new TCursor(_rel, "", 2));	//cursore ordinamento per cognome e nome
 | 
						|
  _cur3 = add_cursor(new TCursor(_rel, "", 3));	//cursore ordinamento per sezione+sottogruppo+codice
 | 
						|
  _cur4 = add_cursor(new TCursor(_rel, "", 4));	//cursore ordinamento per sezione+sottogruppo+cognome e nome
 | 
						|
 | 
						|
  _msk = new TMask("at3100a");
 | 
						|
	TSheet_field& sc = (TSheet_field&)_msk->field(F_CONVOCAZIONI);
 | 
						|
	sc.set_notify(convocazioni_notify);
 | 
						|
  _form_eti = new TConv_form("AT_ETSOG");	
 | 
						|
  _form_car = new TConv_form("AT_CARTO");	
 | 
						|
  
 | 
						|
	_asezioni = new TAssoc_array();
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TConv_application::user_destroy()
 | 
						|
{
 | 
						|
  delete _msk;
 | 
						|
  delete _rel;
 | 
						|
  delete _form_eti;
 | 
						|
  delete _form_car;
 | 
						|
  delete _asezioni;
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TConv_application::check_sez_sheet(const char* codice)
 | 
						|
{ 
 | 
						|
	TAssoc_array& array_sez = app().get_array_sez();
 | 
						|
	if (array_sez.is_key(codice))
 | 
						|
		return FALSE;
 | 
						|
	else
 | 
						|
	{
 | 
						|
		array_sez.add(codice);	
 | 
						|
		return TRUE;
 | 
						|
	}
 | 
						|
}		
 | 
						|
 | 
						|
 | 
						|
bool TConv_application::convocazioni_notify(TSheet_field& s, int r, KEY k)
 | 
						|
{              
 | 
						|
	bool ok = TRUE;
 | 
						|
	switch (k)
 | 
						|
	{
 | 
						|
		case K_TAB:
 | 
						|
		// entrata riga
 | 
						|
		{
 | 
						|
			TToken_string& row = s.row(r);
 | 
						|
	 		TString codice = row.get(0);
 | 
						|
 			TString codsot = row.get();
 | 
						|
 			codice << codsot;
 | 
						|
			if (codice.not_empty())
 | 
						|
			{
 | 
						|
				TAssoc_array& array_sez = app().get_array_sez();
 | 
						|
				if (array_sez.is_key(codice))
 | 
						|
					array_sez.remove(codice);
 | 
						|
			}					
 | 
						|
			if ((r == s.items()-1) && (r == s.first_empty()))
 | 
						|
			{
 | 
						|
				add_rows_convocazioni(s,8,r+1);
 | 
						|
				s.select(r);
 | 
						|
			}
 | 
						|
		}
 | 
						|
	  break;
 | 
						|
		case K_CTRL+K_TAB:
 | 
						|
		// uscita riga
 | 
						|
		{
 | 
						|
			TToken_string& row = s.row(r);
 | 
						|
 			TString codice = row.get(0);
 | 
						|
 			TString codsot = row.get();
 | 
						|
 			codice << codsot;
 | 
						|
			if (codice.not_empty())
 | 
						|
			{
 | 
						|
				ok = check_sez_sheet(codice);
 | 
						|
				if (!ok)
 | 
						|
					return s.error_box("Sezione già convocata");
 | 
						|
			}
 | 
						|
			if ((r == s.items()-1) && (r == s.first_empty()))
 | 
						|
			{
 | 
						|
				add_rows_convocazioni(s,8,r+1);
 | 
						|
				s.select(r);
 | 
						|
			}
 | 
						|
		}
 | 
						|
	  break;  	
 | 
						|
	}  
 | 
						|
  return ok;  
 | 
						|
}
 | 
						|
 | 
						|
int at3100(int argc, char* argv[])
 | 
						|
{
 | 
						|
 | 
						|
  TConv_application a;
 | 
						|
 | 
						|
  a.run(argc, argv, "Convocazioni");
 | 
						|
 | 
						|
  return 0;
 | 
						|
}
 |