Files correlati : at7.exe Ricompilazione Demo : [ ] Commento : sistemato stampa etichette/cartoline/tessere su A4 git-svn-id: svn://10.65.10.50/trunk@11646 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			405 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			405 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <form.h>
 | |
| #include <mask.h>
 | |
| #include <printapp.h>
 | |
| #include <recarray.h>
 | |
| #include <utility.h>
 | |
| 
 | |
| #include "soggetti.h" 
 | |
| #include "donaz.h"
 | |
| #include "benem.h"
 | |
| #include "sezioni.h"
 | |
| #include <comuni.h>
 | |
| 
 | |
| #include "at7.h"    
 | |
| #include "at4100b.h"
 | |
| #include "at4100c.h"
 | |
| #include "at7400a.h"
 | |
| #include "atlib.h"
 | |
| 
 | |
| #define ALIAS_CTD			700		// categoria donatori
 | |
| #define ALIAS_CTN1		701		// categoria non donatori 1
 | |
| #define ALIAS_CTN2		702		// categoria non donatori 2
 | |
| 
 | |
| #define ALIAS_TCS 		200		// tipi/esiti controlli sanitari
 | |
| #define ALIAS_LDN 		400		// punti di prelievo
 | |
| #define ALIAS_LDNDON	401		// punti di prelievo
 | |
| 
 | |
| #define ALIAS_LCPDOM	100		// localita' postale di domicilio
 | |
| #define ALIAS_COMDOM 	501		// comune di domicilio
 | |
| #define ALIAS_COMNAS 	500		// comune di nascita
 | |
| 
 | |
| #define ALIAS_BNZ			600		// benemerenze
 | |
| 
 | |
| enum ts { undefined=0, schede=1, etichette=2, cartoline=3, donazioni=4 };
 | |
|  
 | |
| // definizione form per tessere associative
 | |
| class TPerCodice_form : public TForm
 | |
| {
 | |
| public:
 | |
| 	
 | |
| 	virtual TCursor* cursor() const;
 | |
| 	virtual TRelation* relation() const;
 | |
| 	TPrint_section& get_body() { return section('B'); } ;
 | |
|   TPerCodice_form(): TForm() {};
 | |
|   TPerCodice_form(const char* form, const char * code = "", int editlevel = 0, const char* desc = "")
 | |
|     						: TForm(form,code,editlevel,desc) {};
 | |
|   virtual ~TPerCodice_form() {};
 | |
| };
 | |
| 
 | |
| class TStampePerCodice : public TPrintapp
 | |
| {
 | |
|   TRelation*			_rel;
 | |
| 	TLocalisamfile* _donaz;
 | |
| 	TLocalisamfile* _benem;
 | |
| 	TRecord_array*	_sdonazioni;
 | |
| 	TRecord_array*  _sbenemerenze;
 | |
|   TMask*      		_msk;
 | |
|   TPerCodice_form*	_form_sch;
 | |
|   TPerCodice_form*	_form_car;
 | |
|   TPerCodice_form*	_form_eti;
 | |
|   TPerCodice_form*	_form_don;
 | |
|   ts							_tipostampa;
 | |
|   int 						_cur;
 | |
|   TDate 					_data_stampa;
 | |
| 	TString16				_codsez, _codsot, _orario, _datacart;
 | |
| 	TString80				_invitoper, _data, _presso1, _presso2, _presso3, _presso4;
 | |
| 	TString80				_note, _intest1, _intest2, _intest3, _intest4;
 | |
| 	bool						_usomodo, _usasez;
 | |
|   int							_etlarghezza, _etcolonne, _etrighe, _etbordoini, _etbordofin, _netichette; 
 | |
|   int							_contaschede, _schxpag, _lenpage;
 | |
|   int 						_caxpag, _cabordoini, _cabordofin, _ncartoline;
 | |
| 
 | |
| 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);
 | |
|   virtual print_action postprocess_print(int file, int counter);
 | |
|   ts dati_cartolina();
 | |
| 	
 | |
| public:
 | |
|   void dati_sezione(const TString16 codsez, const TString16 codsot);
 | |
| 	
 | |
|   TMask& app_mask() { return *_msk; }
 | |
|   TStampePerCodice() : _data_stampa(TODAY) {}
 | |
| };
 | |
| 
 | |
| HIDDEN inline TStampePerCodice& app() { return (TStampePerCodice&) main_app(); }
 | |
| 
 | |
| TCursor* TPerCodice_form::cursor() const { return app().current_cursor(); }
 | |
| 
 | |
| TRelation* TPerCodice_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 << "CARTOLINE";
 | |
|   
 | |
|       TPrinter& p = printer();
 | |
|       p.set_printtype(winprinter);           // Force configuration update
 | |
|       p.read_configuration(config);
 | |
|       if (p.set())
 | |
|       	f.message_box("Stampante configurata per stampa cartoline");
 | |
|     }    
 | |
|   }
 | |
|   return TRUE;  
 | |
| }
 | |
| 
 | |
| void TStampePerCodice::dati_sezione(const TString16 codsez, const TString16 codsot)
 | |
| {
 | |
| 	_intest1 = current_cursor()->curr(LF_SEZIONI).get(SEZ_INTESTAZ1);
 | |
| 	_intest2 = current_cursor()->curr(LF_SEZIONI).get(SEZ_INTESTAZ2);
 | |
| 	_intest3 = current_cursor()->curr(LF_SEZIONI).get(SEZ_INTESTAZ3);
 | |
| 	_intest4 = current_cursor()->curr(LF_SEZIONI).get(SEZ_INTESTAZ4);
 | |
| 	if (_usasez)
 | |
| 	{
 | |
| 		if (_presso1.blank())
 | |
| 		{
 | |
| 			_presso1 = current_cursor()->curr(LF_SEZIONI).get(SEZ_CONVSEDE1);
 | |
| 			_presso2 = current_cursor()->curr(LF_SEZIONI).get(SEZ_CONVSEDE2);
 | |
| 			_presso3 = current_cursor()->curr(LF_SEZIONI).get(SEZ_CONVSEDE3);
 | |
| 			_presso4 = current_cursor()->curr(LF_SEZIONI).get(SEZ_CONVSEDE4);
 | |
| 		}			
 | |
| 		if (_orario.blank())
 | |
| 			_orario = current_cursor()->curr(LF_SEZIONI).get(SEZ_CONVORA);
 | |
| 		if (_note.blank())
 | |
| 			_note = current_cursor()->curr(LF_SEZIONI).get(SEZ_CONVNOTE);
 | |
| 	}
 | |
| 	return;
 | |
| }
 | |
| 
 | |
| 
 | |
| ts TStampePerCodice::dati_cartolina()
 | |
| {
 | |
| 	TMask msk("at4100b");
 | |
|  	if (msk.run() == K_ENTER) 
 | |
|  	{ 
 | |
|  		_invitoper = msk.get(F_INVITOPER);
 | |
|  		_data			 = msk.get(F_DATA);
 | |
|  		_presso1   = msk.get(F_PRESSO1);
 | |
|  		_presso2   = msk.get(F_PRESSO2);
 | |
|  		_presso3   = msk.get(F_PRESSO3);
 | |
|  		_presso4   = msk.get(F_PRESSO4);
 | |
|  		_datacart  = msk.get(F_DATACART);
 | |
|  		_orario  	 = msk.get(F_ORARIO);
 | |
|  		_note   	 = msk.get(F_NOTE);
 | |
|  		_usasez		 = msk.get_bool(F_USASEZ);
 | |
|  		return cartoline;
 | |
|  	}
 | |
|  	else
 | |
|  		return undefined;
 | |
| }
 | |
| 
 | |
| void TStampePerCodice::set_page(int file, int cnt)
 | |
| {                                                
 | |
| 	switch (_tipostampa)
 | |
| 	{
 | |
| 		case etichette:
 | |
| 		{ 
 | |
| 			TPrint_section& corpo = _form_eti->get_body();
 | |
| 			for (int r=1;r<=_etcolonne;r++)
 | |
| 			{                     
 | |
| 				if (current_cursor()->pos()<current_cursor()->items())
 | |
| 				{ 
 | |
| 					_netichette++;   
 | |
| 					force_setpage(TRUE);
 | |
| 					corpo.update();
 | |
| 					int nriga = 1;                     
 | |
| 					if (_etrighe > 0)
 | |
| 					{
 | |
| 						int resto = _netichette % (_etrighe*_etcolonne);
 | |
| 						if (resto > 0 && resto <= _etcolonne)
 | |
| 							nriga =	nriga+_etbordoini;
 | |
| 					}		
 | |
|   				for (word i = 0; i < corpo.height(); i++)
 | |
|   				{
 | |
|   					TPrintrow& riga = corpo.row(i);
 | |
|   					TString256 riga1 = riga.row();
 | |
| 						riga1.cut(_etlarghezza);
 | |
|   					int colonna = ((r-1)*_etlarghezza);
 | |
|   					TString16 formato;
 | |
|   					formato << '@' << colonna << "g";
 | |
|   					riga1.insert(formato,0);
 | |
|   					set_row(nriga++,riga1);
 | |
| 					}
 | |
| 					if (r < _etcolonne)  			
 | |
| 						++(*current_cursor());
 | |
| 				}					
 | |
| 			}				
 | |
| 		}
 | |
| 		break;
 | |
| 		case schede:
 | |
| 		{
 | |
| 			TPrint_section& corpo = _form_sch->get_body();
 | |
| 			corpo.update_and_print(printmode_normal, TRUE);
 | |
| 			force_setpage(TRUE);
 | |
| 		}
 | |
| 		break;
 | |
| 		case donazioni:
 | |
| 		{
 | |
| 			TPrint_section& corpo = _form_don->get_body();
 | |
| 			corpo.update_and_print(printmode_normal,TRUE);
 | |
| 			force_setpage(TRUE);
 | |
| 		}
 | |
| 		break;
 | |
| 		case cartoline:
 | |
| 		{		
 | |
| 			TPrint_section& corpo = _form_car->get_body();
 | |
| 			const TString16 codsez = current_cursor()->curr().get(SOG_CODSEZ);		
 | |
| 			const TString16 codsot = current_cursor()->curr().get(SOG_CODSOT);		
 | |
| 			if ((_codsez!=codsez)||(_codsot!=codsot))
 | |
| 			{
 | |
| 				_codsez = codsez;
 | |
| 				_codsot = codsot;
 | |
| 				dati_sezione(codsez, codsot);
 | |
| 				corpo.reset();
 | |
| 			  TForm_item& intest1 = corpo.find_field(CAR_INTEST1);
 | |
| 			  intest1.set(_intest1);
 | |
| 			  TForm_item& intest2 = corpo.find_field(CAR_INTEST2);
 | |
| 			  intest2.set(_intest2);
 | |
| 			  TForm_item& intest3 = corpo.find_field(CAR_INTEST3);
 | |
| 			  intest3.set(_intest3);
 | |
| 			  TForm_item& intest4 = corpo.find_field(CAR_INTEST4);
 | |
| 			  intest4.set(_intest4);
 | |
| 			  TForm_item& invito = corpo.find_field(CAR_INVITOPER);
 | |
| 	  		invito.set(_invitoper);
 | |
| 			  TForm_item& data = corpo.find_field(CAR_DATA);
 | |
| 	  		data.set(_data);
 | |
| 			  TForm_item& presso1 = corpo.find_field(CAR_PRESSO1);
 | |
| 	  		presso1.set(_presso1);
 | |
| 			  TForm_item& presso2 = corpo.find_field(CAR_PRESSO2);
 | |
| 	  		presso2.set(_presso2);
 | |
| 			  TForm_item& presso3 = corpo.find_field(CAR_PRESSO3);
 | |
| 	  		presso3.set(_presso3);
 | |
| 			  TForm_item& presso4 = corpo.find_field(CAR_PRESSO4);
 | |
| 	  		presso4.set(_presso4);
 | |
| 			  TForm_item& orario = corpo.find_field(CAR_ORARIO);
 | |
| 	  		orario.set(_orario);
 | |
| 			  TForm_item& datacart = corpo.find_field(CAR_DATACART);
 | |
| 	  		datacart.set(_datacart);
 | |
| 			  TForm_item& note = corpo.find_field(CAR_NOTE);
 | |
| 	  		note.set(_note);
 | |
| 			}	  		
 | |
| 			corpo.update();
 | |
| 			word primariga = 0;
 | |
| 			word ultimariga = corpo.height(); 	
 | |
| 			if (_caxpag > 0)
 | |
| 			{
 | |
| 				if (_ncartoline % _caxpag == 0) // numero cartoline per pagina
 | |
| 					primariga = _cabordoini;						// bordo iniziale
 | |
| 				if (_ncartoline % _caxpag == _caxpag-1) // numero cartoline per pagina - 1
 | |
| 					ultimariga -= _cabordofin;						// bordo finale
 | |
| 			}		
 | |
| 			int nriga = 1;
 | |
| 			for (word i = primariga; i < ultimariga; i++)
 | |
| 			{
 | |
| 				TPrintrow& riga = corpo.row(i);
 | |
| 				set_row(nriga++,riga);
 | |
| 			}  			
 | |
| 			force_setpage(TRUE);
 | |
| 			_ncartoline++;
 | |
| 		}
 | |
| 		break;
 | |
| 	}							
 | |
| }
 | |
| 
 | |
| print_action TStampePerCodice::postprocess_print(int file, int counter)
 | |
| { 
 | |
| 	if ((_tipostampa == schede) && (_schxpag > 1))
 | |
| 		printer().formlen(_lenpage);
 | |
| 	return NEXT_PAGE;
 | |
| }
 | |
| 
 | |
| bool TStampePerCodice::preprocess_page(int file, int counter)
 | |
| {                              
 | |
| 	if (_tipostampa==etichette && _etrighe == 0)
 | |
| 		if (printer().rows_left() < _form_eti->get_body().height())
 | |
| 			printer().formfeed();
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TStampePerCodice::set_print(int m)
 | |
| { 
 | |
|   TPrinter& p = printer();
 | |
| 	p.read_configuration();
 | |
| 	_tipostampa = undefined;
 | |
|   KEY tasto;
 | |
|   tasto = _msk->run();
 | |
|   switch (tasto)
 | |
|   {                  
 | |
| 	  case F_CARTOLINE:
 | |
|   		_tipostampa = (configura_stampante(p, "AT_CARTOLINE", "cartoline")) ? cartoline : undefined;
 | |
| 	 	break;
 | |
| 	  case F_SCHEDE:
 | |
| 	  	_tipostampa=schede;
 | |
| 	  	if (_schxpag > 1)
 | |
| 	  		printer().formlen(_lenpage/_schxpag);
 | |
| 	 	break;
 | |
| 	  case F_ETICHETTE:
 | |
|   		_tipostampa = (configura_stampante(p, "AT_ETICHETTE", "etichette")) ? etichette : undefined;
 | |
| 		break;  	
 | |
| 	  case F_DONAZIONI:
 | |
| 	  	_tipostampa=donazioni;	
 | |
| 	  break;
 | |
|   }	
 | |
| 	if (_tipostampa != undefined)
 | |
|   {                                        
 | |
|   	if (_tipostampa == cartoline)
 | |
|   		dati_cartolina();
 | |
| 		_contaschede = 0;
 | |
| 		_ncartoline  = 0;
 | |
| 		_netichette = 0;
 | |
| 	 	const long codini = _msk->get_long(F_CODINI);
 | |
| 	 	const long codfin = _msk->get_long(F_CODFIN);
 | |
| 	  TRectype da(LF_SOGGETTI);
 | |
| 	  TRectype a(LF_SOGGETTI);   
 | |
| 	  if (codini!=0)
 | |
| 			da.put(SOG_CODICE, codini);
 | |
| 		if (codfin!=0)		
 | |
| 			a.put(SOG_CODICE, codfin);
 | |
| 		current_cursor()->setregion(da, a);
 | |
|     reset_files(); 
 | |
|     add_file(LF_SOGGETTI);
 | |
| 		reset_print();
 | |
|     return TRUE;
 | |
|   }
 | |
|   else
 | |
|    	return FALSE;
 | |
| }
 | |
| 
 | |
| bool TStampePerCodice::user_create()
 | |
| {
 | |
|   _rel = new TRelation(LF_SOGGETTI);
 | |
|   _rel->add(LF_DONAZ, "CODICE==CODICE", 1);
 | |
|   _rel->add("LDN", "CODTAB==LUOGODON",1,LF_DONAZ, ALIAS_LDNDON);
 | |
|   _rel->add(LF_BENEM, "CODICE==CODICE", 1);
 | |
|   _rel->add("BNZ", "CODTAB==TIPOBEN", 1, LF_BENEM, ALIAS_BNZ);
 | |
|   _rel->add("CTD", "CODTAB==CATDON",1,0,ALIAS_CTD);
 | |
|   _rel->add("CTN", "CODTAB==CATNOND1",1,0,ALIAS_CTN1);
 | |
|   _rel->add("CTN", "CODTAB==CATNOND2",1,0,ALIAS_CTN2);
 | |
|   _rel->add("TCS", "CODTAB==STATO",1,0,ALIAS_TCS);
 | |
|   _rel->add("LDN", "CODTAB==PUNTORACC",1,0,ALIAS_LDN);
 | |
|   _rel->add("LCP", "CODTAB==DOM_CODLOC",1,0,ALIAS_LCPDOM);
 | |
|   _rel->add(LF_COMUNI, "COM==DOM_CODCOM",1,0,ALIAS_COMDOM);
 | |
|   _rel->add(LF_COMUNI, "COM==COMNASC",1,0,ALIAS_COMNAS);
 | |
|   _rel->add(LF_SEZIONI, "CODSEZ==CODSEZ|CODSOT==CODSOT");
 | |
|   _rel->add(LF_MEDICI, "CODMED==CODMED");
 | |
| 	_donaz 		= new TLocalisamfile(LF_DONAZ);
 | |
| 	_benem 		=	new TLocalisamfile(LF_BENEM);
 | |
| 	_sdonazioni 	= new TRecord_array(LF_DONAZ,DON_PROGDON);
 | |
| 	_sbenemerenze = new TRecord_array(LF_BENEM,BEN_PROGBEN);	
 | |
| 
 | |
|   _cur = add_cursor(new TCursor(_rel, "", 1));
 | |
|   _msk = new TMask("at7400a");   
 | |
|   //Modificato il form per le cartoline in ATCARTO2 da ATCARTO1 da Marco il 14/09/99
 | |
|   TConfig config(CONFIG_STUDIO);
 | |
| 
 | |
|   TString16 etformato = config.get("EtFormato");
 | |
|   _etlarghezza = config.get_int("EtLarghezza");
 | |
|   _etcolonne = config.get_int("EtColonne");
 | |
|   _etrighe = config.get_int("EtRighe");
 | |
|   _etbordoini = config.get_int("EtBordoIni"); 
 | |
|   _etbordofin = config.get_int("EtBordoFin"); 
 | |
| 	_form_eti = new TPerCodice_form(etformato);
 | |
| 
 | |
|   TString16 schformato = config.get("SchFormato");
 | |
|   _schxpag = config.get_int("SchXPag");
 | |
|   _form_sch = new TPerCodice_form(schformato);
 | |
|   _lenpage = printer().formlen();
 | |
|   TString16 caformato = config.get("CaFormato");
 | |
|   _form_car = new TPerCodice_form(caformato);
 | |
|   _caxpag = config.get_int("CaPerPag");
 | |
|   _cabordoini = config.get_int("CaBordoIni"); 
 | |
|   _cabordofin = config.get_int("CaBordoFin"); 
 | |
|   _form_don = new TPerCodice_form("ATDDONAZ");
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TStampePerCodice::user_destroy()
 | |
| {
 | |
|   delete _form_don;
 | |
|   delete _form_car;
 | |
|   delete _form_sch;
 | |
|   delete _form_eti;
 | |
|   delete _msk;
 | |
|   delete _sbenemerenze;  
 | |
|   delete _sdonazioni;
 | |
|   delete _benem;
 | |
|   delete _donaz;
 | |
|   delete _rel;
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| int at7400(int argc, char* argv[])
 | |
| {
 | |
|   TStampePerCodice a;
 | |
|   a.run(argc, argv, "Stampe per codice");
 | |
|   return 0;
 | |
| }
 |