177 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			177 lines
		
	
	
		
			4.7 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <mask.h>
 | 
						||
#include <printapp.h>
 | 
						||
#include <utility.h>
 | 
						||
#include <lffiles.h>
 | 
						||
 | 
						||
#include "at0.h"
 | 
						||
#include "at0500a.h"
 | 
						||
 | 
						||
// nomi dei campi
 | 
						||
#include "soggetti.h"
 | 
						||
#include "sezioni.h"
 | 
						||
#include "convoc.h"
 | 
						||
#include "rconvoc.h"
 | 
						||
 | 
						||
class TSpostamentoConv : public TPrintapp
 | 
						||
{
 | 
						||
  TRelation*				_rel;
 | 
						||
  TMask*      			_msk;
 | 
						||
  int								_cur;
 | 
						||
	TLocalisamfile* 	_rconvoc;
 | 
						||
	TLocalisamfile* 	_soggetti;
 | 
						||
  TDate							_dataini, _datafin, _spostadal, _spostaal;
 | 
						||
	TString16 				_punto,_tipo, _sezione, _sottog;
 | 
						||
	TString16					_codsez, _codsot;
 | 
						||
	int								_quanti; // numero di convocazioni per giorni
 | 
						||
	int 							_spostati; // contatore dei soggetti spostati
 | 
						||
	TDate							_data;		 // data a cui spostare
 | 
						||
  //static bool filter_func_stconvoc(const TRelation* rel);
 | 
						||
  
 | 
						||
protected:
 | 
						||
  virtual bool user_create();
 | 
						||
  virtual bool user_destroy();
 | 
						||
  virtual bool set_print(int m);
 | 
						||
  virtual void set_page(int file, int cnt);
 | 
						||
  virtual bool preprocess_page(int file, int counter);
 | 
						||
 | 
						||
public:
 | 
						||
  TMask& app_mask() { return *_msk; }
 | 
						||
  TSpostamentoConv() {}
 | 
						||
};
 | 
						||
 | 
						||
HIDDEN inline TSpostamentoConv& app() { return (TSpostamentoConv&) main_app(); }
 | 
						||
 | 
						||
void TSpostamentoConv::set_page(int file, int cnt)
 | 
						||
{
 | 
						||
 | 
						||
	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_RCONVOC,RCV_DATACONV));
 | 
						||
 | 
						||
	set_row(2,"@13g@S", FLD(LF_SOGGETTI,SOG_NOME));
 | 
						||
	set_row(2,"@50g@S", FLD(LF_RCONVOC,RCV_CHIAMATA));
 | 
						||
			
 | 
						||
	set_row(3, "");			
 | 
						||
}
 | 
						||
 | 
						||
bool TSpostamentoConv::preprocess_page(int file, int counter)
 | 
						||
{
 | 
						||
	TDate& data = app()._data;
 | 
						||
	app()._spostati++;
 | 
						||
	if (app()._spostati > app()._quanti)
 | 
						||
	{
 | 
						||
		++data;
 | 
						||
		if (data > app()._spostaal)
 | 
						||
			data = app()._spostaal;
 | 
						||
		app()._spostati = 1;
 | 
						||
	}	
 | 
						||
	current_cursor()->curr().put(RCV_DATACONV,data);
 | 
						||
	current_cursor()->file().setkey(1);
 | 
						||
	const int err = current_cursor()->file().rewrite();
 | 
						||
	current_cursor()->file().setkey(2);
 | 
						||
	current_cursor()->curr(LF_SOGGETTI).put(SOG_DATACONV,data);
 | 
						||
	current_cursor()->file(LF_SOGGETTI).rewrite();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TSpostamentoConv::set_print(int m)
 | 
						||
{ 
 | 
						||
  KEY tasto;
 | 
						||
  tasto = _msk->run();
 | 
						||
	if (tasto == K_ENTER)
 | 
						||
  {
 | 
						||
    _dataini 		= _msk->get(F_DATAINI);
 | 
						||
    _datafin 		= _msk->get(F_DATAFIN);
 | 
						||
    _punto      = _msk->get(F_PUNTO);
 | 
						||
    _tipo				= _msk->get(F_TIPO);
 | 
						||
    _codsez     = _msk->get(F_CODSEZ);
 | 
						||
    _codsot			= _msk->get(F_CODSOT);
 | 
						||
    _spostadal  = _msk->get(F_SPOSTADAL);
 | 
						||
    _spostaal  = _msk->get(F_SPOSTAAL);
 | 
						||
		TString80 filtro = "";			
 | 
						||
  	// filtro per punto di prelievo
 | 
						||
  	if (_punto.not_empty())
 | 
						||
  	{
 | 
						||
  		if (filtro.not_empty())
 | 
						||
				filtro << " && ";
 | 
						||
			filtro << format("(115->PUNTO == \"%s\")",(const char*)_punto);
 | 
						||
		}	
 | 
						||
		// filtro per tipo
 | 
						||
		if (_tipo.not_empty())
 | 
						||
		{
 | 
						||
  		if (filtro.not_empty())
 | 
						||
				filtro << " && ";
 | 
						||
			filtro << format("(115->TIPO == \"%s\")",(const char*)_tipo);
 | 
						||
		}			
 | 
						||
		// filtro per sezione/sottogruppo
 | 
						||
		if (_sezione.not_empty())
 | 
						||
		{
 | 
						||
  		if (filtro.not_empty())
 | 
						||
				filtro << " && ";
 | 
						||
 			filtro << format("(90->CODSEZ == \"%s\")",(const char*)_sezione);
 | 
						||
			if (_sottog.not_empty())
 | 
						||
			{
 | 
						||
	  		if (filtro.not_empty())
 | 
						||
					filtro  << " && ";
 | 
						||
				filtro << format("(90->CODSOT == \"%s\")",(const char*)_sottog);
 | 
						||
			}
 | 
						||
		}
 | 
						||
		// filtro per data
 | 
						||
	  TRectype da(LF_RCONVOC);
 | 
						||
  	TRectype a (LF_RCONVOC);
 | 
						||
  	if (_dataini.ok())
 | 
						||
			da.put(RCV_DATACONV, _dataini);
 | 
						||
  	if (_datafin.ok())
 | 
						||
			a.put(RCV_DATACONV, _datafin);
 | 
						||
	  _cur = add_cursor(new TCursor(_rel,"", 2, &da, &a));
 | 
						||
	  // non posso metterlo nel costruttore del tcursor perch<63>
 | 
						||
	  // non c'<27> la possibilit<69> di specificare il parametro TRUE che c'<27>
 | 
						||
	  // nella setfilter
 | 
						||
		current_cursor()->setfilter((const char*) filtro, TRUE);
 | 
						||
		current_cursor()->freeze();
 | 
						||
   	const int giorni = (int)(_spostaal-_spostadal)+1;	// giorni su cui suddividere la chiamata
 | 
						||
 		_quanti = ((int)(current_cursor()->items())/giorni); // quanti donatori per giorno
 | 
						||
 		if (_quanti < 1)
 | 
						||
 			_quanti = 1;
 | 
						||
		_spostati = 0;
 | 
						||
		_data = _spostadal;		
 | 
						||
    reset_files(); 
 | 
						||
    add_file(LF_RCONVOC);
 | 
						||
		reset_print();
 | 
						||
    return TRUE;
 | 
						||
  }
 | 
						||
  else
 | 
						||
    return FALSE;
 | 
						||
}
 | 
						||
 | 
						||
bool TSpostamentoConv::user_create()
 | 
						||
{
 | 
						||
  _rel = new TRelation(LF_RCONVOC);
 | 
						||
  _rel->add(LF_SOGGETTI, "CODICE==CODICE");
 | 
						||
  _rel->add(LF_CONVOC, "NUMERO==NUMERO");
 | 
						||
/*  
 | 
						||
  _rel->add("LCP", "CODTAB==DOM_CODLOC",1,LF_SOGGETTI,ALIAS_LCP);
 | 
						||
  _rel->add(LF_COMUNI, "COM==DOM_CODCOM",1,LF_SOGGETTI);
 | 
						||
  // per stampare la denominazione della sezione nell'intestazione
 | 
						||
  _rel->add(LF_SEZIONI, "CODSEZ==CODSEZ|CODSOT==CODSOT",1,LF_SOGGETTI);
 | 
						||
*/  
 | 
						||
  _msk = new TMask("at0500a");
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TSpostamentoConv::user_destroy()
 | 
						||
{
 | 
						||
  delete _msk;
 | 
						||
  delete _rel;
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
int at0500(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TSpostamentoConv a;
 | 
						||
  a.run(argc, argv, "Spostamento convocazioni");
 | 
						||
  return 0;
 | 
						||
}
 |