245 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			245 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <form.h>
 | 
						||
#include <mask.h>
 | 
						||
#include <msksheet.h>
 | 
						||
#include <printapp.h>
 | 
						||
#include <utility.h>
 | 
						||
 | 
						||
#include "soggetti.h"
 | 
						||
#include "sezioni.h"
 | 
						||
#include <comuni.h>
 | 
						||
 | 
						||
#include "at4.h"
 | 
						||
#include "at4500a.h"
 | 
						||
 | 
						||
#include "at4500.h"
 | 
						||
//#define ALIAS_COMRES 300
 | 
						||
//#define ALIAS_COMNAS 400 
 | 
						||
//#define ALIAS_CTN1   500
 | 
						||
//#define ALIAS_CTN2   600
 | 
						||
#define ALIAS_LCP    100
 | 
						||
//#define ALIAS_CTD    800
 | 
						||
 
 | 
						||
// definizione form per tessere associative
 | 
						||
class TTessere_form : public TForm
 | 
						||
{
 | 
						||
public:
 | 
						||
	
 | 
						||
	virtual TCursor* cursor() const;
 | 
						||
	virtual TRelation* relation() const;
 | 
						||
	TPrint_section& get_body() { return section('B'); } ;
 | 
						||
  TTessere_form(): TForm() {};
 | 
						||
  TTessere_form(const char* form, const char * code = "", int editlevel = 0, const char* desc = "")
 | 
						||
    						: TForm(form,code,editlevel,desc) {};
 | 
						||
  virtual ~TTessere_form() {};
 | 
						||
};
 | 
						||
 | 
						||
class TStampaTessere : public TPrintapp
 | 
						||
{
 | 
						||
  TRelation*			_rel;
 | 
						||
  TMask*      		_msk;
 | 
						||
  TAssoc_array		_categorie;
 | 
						||
  TTessere_form*	_form_pag;
 | 
						||
  int							_numdon;
 | 
						||
  bool						_aggiorna;
 | 
						||
  int 						_cur;
 | 
						||
  TDate 					_data_stampa;
 | 
						||
	TString					_riepilogodon;
 | 
						||
 | 
						||
  static bool filter_func_auto(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:
 | 
						||
  void filtra_sezioni();
 | 
						||
  TMask& app_mask() { return *_msk; }
 | 
						||
  TStampaTessere() : _data_stampa(TODAY), _riepilogodon(35) {}
 | 
						||
};
 | 
						||
 | 
						||
HIDDEN inline TStampaTessere& app() { return (TStampaTessere&) main_app(); }
 | 
						||
 | 
						||
TCursor* TTessere_form::cursor() const { return app().current_cursor(); }
 | 
						||
 | 
						||
TRelation* TTessere_form::relation() const { return cursor()->relation(); }
 | 
						||
 | 
						||
HIDDEN bool printer_handler(TMask_field& f, KEY k)
 | 
						||
{        
 | 
						||
  if (k == K_SPACE)
 | 
						||
  {                  
 | 
						||
    TMask& m = f.mask();
 | 
						||
    if (!m.query_mode())
 | 
						||
    {
 | 
						||
      TString16 config;
 | 
						||
      config << "TESSERE";
 | 
						||
  
 | 
						||
      TPrinter& p = printer();
 | 
						||
      p.set_printtype(normprinter);           // Force configuration update
 | 
						||
      p.read_configuration(config);
 | 
						||
      if (p.set())
 | 
						||
      	f.message_box("Stampante configurata per stampa tessere");
 | 
						||
    }    
 | 
						||
  }
 | 
						||
  return TRUE;  
 | 
						||
}
 | 
						||
 | 
						||
void TStampaTessere::filtra_sezioni()
 | 
						||
{
 | 
						||
 	const TString16 sezini = _msk->get(F_SEZINI);
 | 
						||
 	const TString16 sotini = _msk->get(F_SOTINI);
 | 
						||
 	const TString16 sezfin = _msk->get(F_SEZFIN);
 | 
						||
 	const TString16 sotfin = _msk->get(F_SOTFIN);
 | 
						||
  TRectype da(LF_SOGGETTI);
 | 
						||
  TRectype a(LF_SOGGETTI);   
 | 
						||
	if (sezini.not_empty())  
 | 
						||
		da.put(SOG_CODSEZ, sezini);
 | 
						||
  if (sotini.not_empty())
 | 
						||
		da.put(SOG_CODSOT, sotini);
 | 
						||
  if (sezfin.not_empty())
 | 
						||
		a.put(SOG_CODSEZ, sezfin);
 | 
						||
  if (sotfin.not_empty())
 | 
						||
		a.put(SOG_CODSOT, sotfin);
 | 
						||
	current_cursor()->setregion(da, a);
 | 
						||
}	
 | 
						||
 | 
						||
void TStampaTessere::set_page(int file, int cnt)
 | 
						||
{
 | 
						||
	TPrint_section& corpo = _form_pag->get_body();
 | 
						||
	corpo.reset();
 | 
						||
  TForm_item& rigadon = corpo.find_field(TES_RIGADON1);
 | 
						||
	rigadon.set(_riepilogodon);
 | 
						||
	corpo.update();
 | 
						||
	for (word i = 0; i < corpo.height(); i++)
 | 
						||
	{
 | 
						||
		TPrintrow& riga = corpo.row(i);
 | 
						||
		set_row(i+1,riga);
 | 
						||
	}  			
 | 
						||
	force_setpage(TRUE);	// serve perch<63> alla prossima etichetta rifaccia la setpage
 | 
						||
												// altrimenti stampa sempre la stessa etichetta
 | 
						||
}
 | 
						||
 | 
						||
bool TStampaTessere::filter_func_auto(const TRelation* rel)
 | 
						||
{   
 | 
						||
	bool filtrato = TRUE;
 | 
						||
	TLocalisamfile& sog = rel->lfile(); 
 | 
						||
	filtrato = !(sog.get_bool(SOG_T_STAMPATA));
 | 
						||
	if (filtrato)
 | 
						||
		filtrato = (sog.get_int(SOG_TOTDON) >= app()._numdon);
 | 
						||
	if (filtrato)		
 | 
						||
	{ 
 | 
						||
		// filtro per categorie
 | 
						||
		TAssoc_array& categorie = app()._categorie;
 | 
						||
		if (categorie.items() != 0)
 | 
						||
		{
 | 
						||
			const TString16 cat = sog.get(SOG_CATDON);
 | 
						||
			filtrato = categorie.is_key((const char*) cat);
 | 
						||
		}	
 | 
						||
	}		
 | 
						||
  return filtrato;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampaTessere::preprocess_page(int file, int counter)
 | 
						||
{                              
 | 
						||
	TLocalisamfile& sogg = current_cursor()->file(LF_SOGGETTI);
 | 
						||
	
 | 
						||
	const int totdon = sogg.get_int(SOG_TOTDON);
 | 
						||
	const TDate dataultima = sogg.get(SOG_DATAULTDON);
 | 
						||
	_riepilogodon = "";
 | 
						||
	if (totdon != 0)	
 | 
						||
	{	
 | 
						||
		_riepilogodon = "Donazioni fino al ";
 | 
						||
		_riepilogodon << dataultima.string();
 | 
						||
		_riepilogodon << " n.";
 | 
						||
		_riepilogodon << totdon;
 | 
						||
	}	
 | 
						||
	if (_aggiorna)
 | 
						||
	{
 | 
						||
		sogg.put(SOG_T_STAMPATA,TRUE);
 | 
						||
		sogg.rewrite();
 | 
						||
	}		
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampaTessere::set_print(int m)
 | 
						||
{ 
 | 
						||
  KEY tasto;
 | 
						||
  tasto = _msk->run();
 | 
						||
  if (tasto == K_ENTER)
 | 
						||
  {
 | 
						||
    reset_files(); 
 | 
						||
    add_file(LF_SOGGETTI);
 | 
						||
    filtra_sezioni();
 | 
						||
    _numdon = _msk->get_int(F_NUMDON);
 | 
						||
    _aggiorna = _msk->get_bool(F_AGGIORNA);
 | 
						||
    //const char* filtro = format("(NUM(TOTDON>=%i)) && (T_STAMPATA!=\"X\")",_numdon);
 | 
						||
    //const char* filtro = format("T_STAMPATA!=\"X\"");
 | 
						||
    //const char* filtro = format("TOTDON>=%i",_numdon);
 | 
						||
   	//current_cursor()->setfilter(filtro);
 | 
						||
    _categorie.destroy();   	
 | 
						||
  	const TString16 catpri = _msk->get(F_CAT1);
 | 
						||
  	const TString16 catsec = _msk->get(F_CAT2);
 | 
						||
  	const TString16 catter = _msk->get(F_CAT3);
 | 
						||
  	const TString16 catqua = _msk->get(F_CAT4);
 | 
						||
  	const TString16 catqui = _msk->get(F_CAT5);
 | 
						||
  	const TString16 catses = _msk->get(F_CAT6);
 | 
						||
  	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);
 | 
						||
 		current_cursor()->set_filterfunction (filter_func_auto, TRUE);
 | 
						||
		reset_print();
 | 
						||
    return TRUE;
 | 
						||
  }
 | 
						||
  else
 | 
						||
    return FALSE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampaTessere::user_create()
 | 
						||
{
 | 
						||
  _rel = new TRelation(LF_SOGGETTI);
 | 
						||
  //_rel->add(LF_COMUNI, "COM==COMNASC",1,0,ALIAS_COMNAS);
 | 
						||
  _rel->add(LF_COMUNI, "COM==DOM_CODCOM");
 | 
						||
  _rel->add("LCP", "CODTAB==DOM_CODLOC",1,0,ALIAS_LCP);
 | 
						||
  _rel->add(LF_SEZIONI, "CODSEZ==CODSEZ|CODSOT==CODSOT");
 | 
						||
  _rel->add(LF_SEZIONI, "CODSEZ==CODSEZ|CODSOT==CODSOT");
 | 
						||
  //_rel->add("CTN", "CODTAB==CATNOND1",1,0,ALIAS_CTN1);
 | 
						||
  //_rel->add("CTN", "CODTAB==CATNOND2",1,0,ALIAS_CTN2);
 | 
						||
  //_rel->add("CTD", "CODTAB==CATDON",1,0,ALIAS_CTD);
 | 
						||
	//cursore ordinamento per sezione+sottogruppo+cognome+nome  
 | 
						||
  _cur = add_cursor(new TCursor(_rel, "", 3));
 | 
						||
  _msk = new TMask("at4500a");
 | 
						||
  _msk->set_handler(F_PRINTER, printer_handler);
 | 
						||
  _form_pag = new TTessere_form("ATTESSER");
 | 
						||
	TString16   config;
 | 
						||
	config << "TESSERE";
 | 
						||
  printer().read_configuration(config);
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampaTessere::user_destroy()
 | 
						||
{
 | 
						||
  delete _msk;
 | 
						||
  delete _rel;
 | 
						||
  delete _form_pag;
 | 
						||
  printer().read_configuration();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
int at4500(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TStampaTessere a;
 | 
						||
  a.run(argc, argv, "Stampa tessere associative");
 | 
						||
  return 0;
 | 
						||
}
 |