242 lines
		
	
	
		
			6.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			242 lines
		
	
	
		
			6.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <mask.h>
 | 
						||
#include <printapp.h>
 | 
						||
#include <tabutil.h>
 | 
						||
#include <utility.h>
 | 
						||
 | 
						||
#include <lffiles.h>
 | 
						||
#include "lf.h"
 | 
						||
#include "soggetti.h"
 | 
						||
#include "benem.h"
 | 
						||
 | 
						||
#include "at2.h"
 | 
						||
#include "at2400a.h"
 | 
						||
                   
 | 
						||
class TBenem_application : public TPrintapp
 | 
						||
{
 | 
						||
  static bool filter_func_benem(const TRelation *);
 | 
						||
 | 
						||
  TRelation*        _rel;
 | 
						||
  TMask*            _msk;
 | 
						||
  TLocalisamfile*		_benem;
 | 
						||
  TRecord_array*		_sbenemerenze;
 | 
						||
  
 | 
						||
  int 							_cur1, _cur2, _cur3, _cur4;
 | 
						||
  TDate 						_data_stampa;
 | 
						||
  TString						_codsez, _codsot;
 | 
						||
  
 | 
						||
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:
 | 
						||
  void crea_intestazione();
 | 
						||
  void filtra_sezioni();
 | 
						||
  
 | 
						||
  TMask& app_mask() { return *_msk; }
 | 
						||
  TBenem_application() : _data_stampa(TODAY) {}
 | 
						||
};
 | 
						||
 | 
						||
HIDDEN inline TBenem_application& app() { return (TBenem_application&) main_app(); }
 | 
						||
 | 
						||
void TBenem_application::filtra_sezioni()
 | 
						||
{
 | 
						||
 	TString sezini = _msk->get(F_SEZINI);
 | 
						||
 	TString sotini = _msk->get(F_SOTINI);
 | 
						||
 	TString sezfin = _msk->get(F_SEZFIN);
 | 
						||
 	TString sotfin = _msk->get(F_SOTFIN);
 | 
						||
  select_cursor(_cur4); 
 | 
						||
  TLocalisamfile& fl = current_cursor()->file(LF_SOGGETTI);
 | 
						||
  TRectype da(fl.curr());
 | 
						||
  TRectype a(fl.curr());   
 | 
						||
  da.zero();
 | 
						||
  a.zero();
 | 
						||
  if ((sezini.not_empty()) && (sezini.ok()))
 | 
						||
		da.put(SOG_CODSEZ, sezini);
 | 
						||
  if ((sotini.not_empty()) && (sotini.ok()))    	
 | 
						||
		da.put(SOG_CODSOT, sotini);
 | 
						||
  if ((sezfin.not_empty()) && (sezfin.ok()))
 | 
						||
		a.put(SOG_CODSEZ, sezfin);
 | 
						||
  if ((sotfin.not_empty()) && (sotfin.ok()))    	
 | 
						||
		a.put(SOG_CODSOT, sotfin);
 | 
						||
	current_cursor()->setregion(da, a);
 | 
						||
}	
 | 
						||
 | 
						||
void TBenem_application::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@S", FLD(LF_SOGGETTI,SOG_TOTDON));
 | 
						||
	
 | 
						||
	set_row(2,"@13g@S", FLD(LF_SOGGETTI,SOG_NOME));
 | 
						||
	set_row(2,"@50g@ld", FLD(LF_SOGGETTI,SOG_DATAULTDON));
 | 
						||
}
 | 
						||
 | 
						||
bool TBenem_application::filter_func_benem(const TRelation* rel)
 | 
						||
{   
 | 
						||
	bool filtrato = TRUE;
 | 
						||
	
 | 
						||
	TLocalisamfile*      sog = &(rel->lfile(LF_SOGGETTI)); 
 | 
						||
  
 | 
						||
	//filtro per categorie
 | 
						||
	
 | 
						||
	TMask& msk = app().app_mask();
 | 
						||
  TString catpri = msk.get(F_CAT1);
 | 
						||
  TString catsec = msk.get(F_CAT2);
 | 
						||
  TString catter = msk.get(F_CAT3);
 | 
						||
  TString catqua = msk.get(F_CAT4);
 | 
						||
  TString catqui = msk.get(F_CAT5);
 | 
						||
  TString catses = msk.get(F_CAT6);
 | 
						||
  
 | 
						||
  TAssoc_array categorie;
 | 
						||
  if (catpri.not_empty() && catpri.ok())
 | 
						||
  	categorie.add((const char*) catpri);
 | 
						||
  if (catsec.not_empty() && catsec.ok())
 | 
						||
  	categorie.add((const char*) catsec);
 | 
						||
  if (catter.not_empty() && catter.ok())
 | 
						||
  	categorie.add((const char*) catter);
 | 
						||
  if (catqua.not_empty() && catqua.ok())
 | 
						||
  	categorie.add((const char*) catqua);
 | 
						||
  if (catqui.not_empty() && catqui.ok())
 | 
						||
  	categorie.add((const char*) catqui);
 | 
						||
  if (catses.not_empty() && catses.ok())
 | 
						||
  	categorie.add((const char*) catses);
 | 
						||
	
 | 
						||
	if (categorie.items() != 0)
 | 
						||
	{
 | 
						||
		TString cat = sog->curr().get(SOG_CATDON);
 | 
						||
		if (categorie.is_key((const char*) cat))
 | 
						||
			filtrato = TRUE;
 | 
						||
		else
 | 
						||
			filtrato = FALSE;	
 | 
						||
	}	
 | 
						||
  return filtrato;
 | 
						||
}
 | 
						||
 | 
						||
bool TBenem_application::preprocess_page(int file, int counter)
 | 
						||
{
 | 
						||
	// contatore soggetti stampati
 | 
						||
	// per ora non c'<27>
 | 
						||
	// salto pagina se cambio sezione
 | 
						||
	TString codsez = current_cursor()->curr().get(SOG_CODSEZ);		
 | 
						||
	TString codsot = current_cursor()->curr().get(SOG_CODSOT);		
 | 
						||
	if ((_codsez!=codsez)||(_codsot!=codsot))
 | 
						||
	{
 | 
						||
		//if (!_codsez.blank())
 | 
						||
		if (_codsez != "**")
 | 
						||
			printer().formfeed();
 | 
						||
			_codsez = codsez;
 | 
						||
			_codsot = codsot;
 | 
						||
	}
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
  
 | 
						||
int get_donbene(TString tipo)
 | 
						||
{
 | 
						||
	int donbene = 0;
 | 
						||
	TTable bnz("BNZ");
 | 
						||
	bnz.put("CODTAB",tipo);
 | 
						||
	if (bnz.read() == NOERR)
 | 
						||
		donbene = bnz.get_int("I0");
 | 
						||
	return donbene;		
 | 
						||
	
 | 
						||
}
 | 
						||
bool TBenem_application::set_print(int)
 | 
						||
{
 | 
						||
  KEY tasto;
 | 
						||
  tasto = _msk->run();
 | 
						||
  if (tasto == F_ELENCO)
 | 
						||
  {
 | 
						||
  	//_codsez.spaces(2);
 | 
						||
  	//_codsot.spaces(2);
 | 
						||
  	_codsez = "**";
 | 
						||
  	_codsot = "**";
 | 
						||
    reset_files(); 
 | 
						||
    add_file(LF_SOGGETTI);
 | 
						||
 | 
						||
    TString tipoben = _msk->get(F_TIPOBEN);
 | 
						||
                         
 | 
						||
		filtra_sezioni();
 | 
						||
		
 | 
						||
		int donbene = get_donbene(tipoben);
 | 
						||
		    
 | 
						||
    if (tipoben.not_empty() && tipoben.ok())
 | 
						||
    	current_cursor()->setfilter(format("TOTDON >= \"%i\"",donbene));
 | 
						||
 		else      
 | 
						||
    	current_cursor()->setfilter(format("TOTDON >= \"%i\"",donbene));
 | 
						||
    //  current_cursor()->setfilter("ESCLUSO != \"\"");
 | 
						||
		current_cursor()->set_filterfunction(filter_func_benem);
 | 
						||
    crea_intestazione();
 | 
						||
    return TRUE;
 | 
						||
  }
 | 
						||
  else
 | 
						||
    return FALSE;
 | 
						||
}
 | 
						||
 | 
						||
void TBenem_application::crea_intestazione()
 | 
						||
{
 | 
						||
  TString sep(132);
 | 
						||
  TString data_stampa;
 | 
						||
  
 | 
						||
  reset_header();
 | 
						||
  
 | 
						||
  sep.fill('-');
 | 
						||
  set_header(1, (const char *) sep);
 | 
						||
  sep = "";
 | 
						||
  sep << "Pag. @#";
 | 
						||
  sep.right_just(132); 
 | 
						||
  set_header(2,(const char*) sep);  
 | 
						||
  
 | 
						||
  set_header(2,"@0gELENCO SOGGETTI CHE DEVONO RICEVERE LA BENEMERENZA xx@104gDATA");
 | 
						||
  data_stampa = _data_stampa.string();
 | 
						||
  set_header(2,"@109g%10s", (const char*) data_stampa);
 | 
						||
  
 | 
						||
  sep = "";
 | 
						||
  sep.fill('-');
 | 
						||
  set_header(3, (const char *) sep);
 | 
						||
  
 | 
						||
  set_header(5,"@0gCod.@10gC.@13gCognome@39gNato il@50gData esc.");
 | 
						||
  set_header(6,"@13gNome@50gTipo esc.");  
 | 
						||
  set_header(7,"@0g---------@10g--@13g-------------------------@39g----------@50g--------");
 | 
						||
}
 | 
						||
 | 
						||
bool TBenem_application::user_create()
 | 
						||
{
 | 
						||
  _rel = new TRelation(LF_SOGGETTI);
 | 
						||
 	//_rel->add(LF_BENEM, "CODICE==CODICE");  
 | 
						||
	_benem = new TLocalisamfile(LF_BENEM);
 | 
						||
	_sbenemerenze = new TRecord_array(LF_BENEM,BEN_PROGBEN);	
 | 
						||
 | 
						||
 | 
						||
  _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("at2400a");
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TBenem_application::user_destroy()
 | 
						||
{
 | 
						||
  delete _msk;
 | 
						||
  delete _rel;
 | 
						||
  delete _benem;
 | 
						||
  delete _sbenemerenze;
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
int at2400(int argc, char* argv[])
 | 
						||
{
 | 
						||
 | 
						||
  TBenem_application a;
 | 
						||
 | 
						||
  a.run(argc, argv, "Elenco premiati");
 | 
						||
 | 
						||
  return 0;
 | 
						||
}
 |