235 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			235 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <form.h>
 | 
						|
#include <mask.h>
 | 
						|
#include <printapp.h>
 | 
						|
 | 
						|
#include <lffiles.h>
 | 
						|
#include "lf.h"
 | 
						|
#include "sezioni.h"
 | 
						|
#include <comuni.h>
 | 
						|
 | 
						|
#include "at6.h"
 | 
						|
#include "at6200a.h"
 | 
						|
enum ts { undefined = 0, elenco = 1, etichette = 2 };
 | 
						|
 | 
						|
// definizione form per etichette
 | 
						|
class TSez_form : public TForm
 | 
						|
{
 | 
						|
public:
 | 
						|
	
 | 
						|
	virtual TCursor* cursor() const;
 | 
						|
	virtual TRelation* relation() const;
 | 
						|
	TPrint_section& get_body() { return section('B'); } ;
 | 
						|
  TSez_form(): TForm() {};
 | 
						|
  TSez_form(const char* form, const char * code = "", int editlevel = 0, const char* desc = "")
 | 
						|
    						: TForm(form,code,editlevel,desc) {};
 | 
						|
  virtual ~TSez_form() {};
 | 
						|
};
 | 
						|
 | 
						|
class TSezprint_application : public TPrintapp
 | 
						|
{
 | 
						|
  TRelation*        _rel;
 | 
						|
  TMask*            _msk;
 | 
						|
  TSez_form*				_form_eti;
 | 
						|
  
 | 
						|
  int 							_cur1, _cur2;
 | 
						|
  TParagraph_string _dencom, _indirizzo;
 | 
						|
  TDate 						_data_stampa;
 | 
						|
  ts								_tipo_stampa;
 | 
						|
  
 | 
						|
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();
 | 
						|
  
 | 
						|
  TSezprint_application() : _data_stampa(TODAY), _indirizzo("", 22), _dencom("", 25) {}
 | 
						|
};
 | 
						|
 | 
						|
HIDDEN inline TSezprint_application& app() { return (TSezprint_application&) main_app(); }
 | 
						|
 | 
						|
TCursor* TSez_form::cursor() const { return app().current_cursor(); }
 | 
						|
 | 
						|
TRelation* TSez_form::relation() const { return cursor()->relation(); }
 | 
						|
 | 
						|
void TSezprint_application::set_page(int file, int cnt)
 | 
						|
{
 | 
						|
	switch (_tipo_stampa)
 | 
						|
	{
 | 
						|
		case etichette:
 | 
						|
		{
 | 
						|
			TPrint_section& corpo = _form_eti->get_body();
 | 
						|
			corpo.reset();
 | 
						|
			corpo.update();
 | 
						|
  		for (int i = 0; i < corpo.height(); i++)
 | 
						|
  		{
 | 
						|
  			TPrintrow& riga = corpo.row(i);
 | 
						|
  			set_row(i+1,riga);
 | 
						|
			}
 | 
						|
			force_setpage(TRUE);
 | 
						|
		}
 | 
						|
		break;
 | 
						|
		case elenco:
 | 
						|
		{
 | 
						|
			set_row(1,"@0g@S", FLD(LF_SEZIONI,SEZ_CODSEZ));
 | 
						|
			set_row(1,"@2g@S", FLD(LF_SEZIONI,SEZ_CODSOT));
 | 
						|
			set_row(1,"@5g@S", FLD(LF_SEZIONI,SEZ_DENSEZ));
 | 
						|
			set_row(1,"@31g@S", FLD(LF_SEZIONI,SEZ_DENSOT));	
 | 
						|
			set_row(1,"@57g#a",&_indirizzo);
 | 
						|
			set_row(1,"@80g#a",&_dencom);
 | 
						|
			set_row(1,"@101g@S",FLD(LF_SEZIONI,SEZ_TELEFONO));
 | 
						|
			set_row(1,"@117g@S",FLD(LF_SEZIONI,SEZ_FAX));
 | 
						|
		}
 | 
						|
		break;
 | 
						|
	}					
 | 
						|
}
 | 
						|
 | 
						|
bool TSezprint_application::preprocess_page(int file, int counter)
 | 
						|
{
 | 
						|
	if (_tipo_stampa == elenco)
 | 
						|
	{
 | 
						|
		TString256 localita = "";
 | 
						|
		localita << current_cursor()->curr("LCP").get("S0");
 | 
						|
		if (localita.not_empty() && localita.ok())
 | 
						|
			localita << " - ";		
 | 
						|
		localita << current_cursor()->curr(LF_COMUNI).get(COM_DENCOM);
 | 
						|
		_dencom = localita;
 | 
						|
		_indirizzo = current_cursor()->curr(LF_SEZIONI).get(SEZ_INDIRIZZO);
 | 
						|
	}		
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TSezprint_application::set_print(int)
 | 
						|
{
 | 
						|
	_tipo_stampa = undefined;
 | 
						|
  KEY tasto;
 | 
						|
  tasto = _msk->run();
 | 
						|
               
 | 
						|
	switch (tasto)               
 | 
						|
	{
 | 
						|
		case F_ELENCO:
 | 
						|
			_tipo_stampa = elenco;
 | 
						|
		break;
 | 
						|
		case F_ETICHETTE:
 | 
						|
			_tipo_stampa = etichette;
 | 
						|
		break;			
 | 
						|
	}			
 | 
						|
  if (_tipo_stampa != undefined)
 | 
						|
  {  
 | 
						|
  	TString16 codfr, codto;
 | 
						|
  	TString80 denfr, dento;
 | 
						|
    const int sort = _msk->get_int(F_SORT);
 | 
						|
    
 | 
						|
    reset_files(); 
 | 
						|
    add_file(LF_SEZIONI);
 | 
						|
    if (sort == 1)
 | 
						|
    {
 | 
						|
      codfr = _msk->get(F_CODFR);
 | 
						|
      codto = _msk->get(F_CODTO);
 | 
						|
 | 
						|
      select_cursor(_cur1); 
 | 
						|
      TLocalisamfile& fl = current_cursor()->file(LF_SEZIONI);
 | 
						|
      TRectype da(fl.curr());
 | 
						|
      TRectype a(fl.curr());   
 | 
						|
 | 
						|
      da.zero();
 | 
						|
      a.zero();
 | 
						|
      
 | 
						|
      da.put(SEZ_CODSEZ, codfr);
 | 
						|
      a.put(SEZ_CODSEZ, codto);
 | 
						|
 | 
						|
      current_cursor()->setregion(da, a);
 | 
						|
    }
 | 
						|
    else
 | 
						|
      if (sort == 2)
 | 
						|
      {
 | 
						|
        denfr = _msk->get(F_DENFR);
 | 
						|
        dento = _msk->get(F_DENTO);
 | 
						|
        
 | 
						|
        select_cursor(_cur2);
 | 
						|
 | 
						|
        TLocalisamfile& fl = current_cursor()->file(LF_SEZIONI);
 | 
						|
        TRectype da(fl.curr());
 | 
						|
        TRectype a(fl.curr());   
 | 
						|
        
 | 
						|
        da.zero();
 | 
						|
        a.zero();
 | 
						|
        
 | 
						|
        da.put(SEZ_DENSEZ, denfr);
 | 
						|
        a.put (SEZ_DENSEZ, dento);
 | 
						|
        
 | 
						|
        current_cursor()->setregion(da, a);
 | 
						|
      }
 | 
						|
		reset_print();      
 | 
						|
    crea_intestazione();
 | 
						|
    return TRUE;
 | 
						|
  }
 | 
						|
  else
 | 
						|
    return FALSE;
 | 
						|
}
 | 
						|
 | 
						|
void TSezprint_application::crea_intestazione()
 | 
						|
{
 | 
						|
  reset_header();
 | 
						|
  
 | 
						|
  if (_tipo_stampa == elenco)
 | 
						|
	{  
 | 
						|
  	TString sep(132);
 | 
						|
  	TString16 data_stampa;
 | 
						|
  	sep.fill('-');
 | 
						|
  	set_header(1, (const char *) sep);
 | 
						|
  	sep = "";
 | 
						|
  	sep << "Pag. @#";
 | 
						|
  	sep.right_just(132); 
 | 
						|
  	set_header(2,(const char*) sep);  
 | 
						|
  
 | 
						|
  	set_header(2,"@0gTABELLA SEZIONI/SOTTOGRUPPI@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.@5gDenominazione sezione@31gDenominazione sottogruppo@57gIndirizzo@80gComune@101gTelefono@117gFax");
 | 
						|
  	set_header(6,"@0g----@5g-------------------------@31g-------------------------");
 | 
						|
  	set_header(6,"@57g-----------------------@80g--------------------@101g---------------@117g---------------");
 | 
						|
	}  	
 | 
						|
}
 | 
						|
 | 
						|
bool TSezprint_application::user_create()
 | 
						|
{
 | 
						|
  _rel = new TRelation(LF_SEZIONI);
 | 
						|
  _rel->add(LF_COMUNI, "COM==COM");
 | 
						|
  _rel->add("LCP", "CODTAB==LOCALITA");
 | 
						|
 | 
						|
  _cur1 = add_cursor(new TCursor(_rel, "", 1));	//cursore ordinamento per codice
 | 
						|
  _cur2 = add_cursor(new TCursor(_rel, "", 2));	//cursore ordinamento per denominazione
 | 
						|
 | 
						|
  _msk = new TMask("at6200a");
 | 
						|
  
 | 
						|
  _form_eti = new TSez_form("AT_ETSEZ");
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TSezprint_application::user_destroy()
 | 
						|
{
 | 
						|
  delete _msk;
 | 
						|
  delete _rel;
 | 
						|
  delete _form_eti;
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
int at6200(int argc, char* argv[])
 | 
						|
{
 | 
						|
 | 
						|
  TSezprint_application a;
 | 
						|
 | 
						|
  a.run(argc, argv, "Stampa Sezioni");
 | 
						|
 | 
						|
  return 0;
 | 
						|
}
 |