e1594fd672
git-svn-id: svn://10.65.10.50/trunk@4223 c028cbd2-c16b-5b4b-a496-9718f37d4682
347 lines
9.9 KiB
C++
Executable File
347 lines
9.9 KiB
C++
Executable File
//#include <form.h>
|
||
#include <mask.h>
|
||
#include <msksheet.h>
|
||
#include <printapp.h>
|
||
#include <utility.h>
|
||
|
||
#include "lf.h"
|
||
#include "soggetti.h"
|
||
#include "sezioni.h"
|
||
#include <comuni.h>
|
||
|
||
#include "at1.h"
|
||
#include "at1400a.h"
|
||
|
||
#define ALIAS_COMRES 300
|
||
#define ALIAS_COMNAS 400
|
||
//#define ALIAS_CTN1 500
|
||
//#define ALIAS_CTN2 600
|
||
#define ALIAS_LCP 700
|
||
#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 TTessere_application : public TPrintapp
|
||
{
|
||
TRelation* _rel;
|
||
TMask* _msk;
|
||
TAssoc_array _categorie;
|
||
//TTessere_form* _form_pag;
|
||
TAssoc_array _asoggetti;
|
||
|
||
int _numdon;
|
||
bool _aggiorna;
|
||
|
||
int _cur1, _cur2, _cur3, _cur4;
|
||
TDate _data_stampa;
|
||
TString _riepilogodon;
|
||
|
||
static bool filter_func_auto(const TRelation* rel);
|
||
static bool filter_func_manuale(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);
|
||
virtual print_action postprocess_page(int file, int counter);
|
||
|
||
static void add_rows_soggetti(TSheet_field& s, int count = 10, int start = 1);
|
||
|
||
public:
|
||
void filtra_sezioni();
|
||
void filtra_codici();
|
||
TMask& app_mask() { return *_msk; }
|
||
TTessere_application() : _data_stampa(TODAY), _riepilogodon(50) {}
|
||
};
|
||
|
||
HIDDEN inline TTessere_application& app() { return (TTessere_application&) 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 TTessere_application::add_rows_soggetti(TSheet_field& s, int count, int start)
|
||
{
|
||
if (start == 1)
|
||
s.destroy();
|
||
for (int r=start; r<start+count; r++)
|
||
TToken_string& row = s.row(r-1);
|
||
}
|
||
|
||
void TTessere_application::filtra_codici()
|
||
{
|
||
select_cursor(_cur4);
|
||
TRectype da(LF_SOGGETTI);
|
||
TRectype a (LF_SOGGETTI);
|
||
TSheet_field& s = (TSheet_field&)_msk->field(F_SOGGETTI);
|
||
long maxcod = 0;
|
||
long mincod = 99999;
|
||
for (int r=0; r < s.items(); r++)
|
||
{
|
||
TToken_string& row = s.row(r);
|
||
const long codice = row.get_long(0);
|
||
if (codice != 0)
|
||
{
|
||
if (codice > maxcod)
|
||
maxcod = codice;
|
||
if (codice < mincod)
|
||
mincod = codice;
|
||
}
|
||
}
|
||
if (mincod != 0)
|
||
da.put(SOG_CODICE, mincod);
|
||
if (maxcod != 0)
|
||
a.put(SOG_CODICE, maxcod);
|
||
current_cursor()->setregion(da, a);
|
||
}
|
||
|
||
void TTessere_application::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);
|
||
select_cursor(_cur4);
|
||
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 TTessere_application::set_page(int file, int cnt)
|
||
{
|
||
TString16 data_stampa = _data_stampa.string();
|
||
set_row(3, "@30g@S", FLD(LF_SEZIONI,SEZ_DENSEZ));
|
||
set_row(4, "@30g@S", FLD(LF_SEZIONI,SEZ_DENSOT));
|
||
set_row(9,"@33g%s@1j@pn", "Cod. prov.",FLD(LF_SOGGETTI,SOG_CODICE,"#########"));
|
||
set_row(12,"@37g@10ls", FLD(LF_SOGGETTI,SOG_TESSAVIS));
|
||
set_row(14,"@45g%10s", (const char*) data_stampa);
|
||
set_row(16,"@8g@ls@1j@ls", FLD(LF_SOGGETTI,SOG_COGNOME), FLD(LF_SOGGETTI,SOG_NOME));
|
||
set_row(18,"@8g@ls@1j@2s", FLD(-ALIAS_COMNAS,COM_DENCOM),FLD(-ALIAS_COMNAS,COM_PROVCOM));
|
||
set_row(18,"@45g@ld", FLD(LF_SOGGETTI,SOG_DATANASC));
|
||
set_row(20,"@10g@ls@1j@2s",FLD(-ALIAS_COMRES,COM_DENCOM),FLD(-ALIAS_COMRES,COM_PROVCOM));
|
||
set_row(20,"@45g@15ls", FLD(LF_SOGGETTI,SOG_TELABI));
|
||
set_row(22,"@2g@50ls", FLD(LF_SOGGETTI,SOG_DOM_INDIR));
|
||
set_row(24,"@10g@16ls", FLD(LF_SOGGETTI,SOG_CF));
|
||
set_row(28,"@4g@4ls", FLD(LF_SOGGETTI,SOG_GRUPPOAB0));
|
||
set_row(28,"@17g@3ls", FLD(LF_SOGGETTI,SOG_RHANTID));
|
||
set_row(28,"@30g@6ls", FLD(LF_SOGGETTI,SOG_FENOTIPORH));
|
||
set_row(28,"@48g@3ls", FLD(LF_SOGGETTI,SOG_KELL));
|
||
set_row(28,"@58g@3ls", FLD(LF_SOGGETTI,SOG_DU));
|
||
set_row(32,"@4g@20ls", FLD(LF_SOGGETTI,SOG_DOCID));
|
||
set_row(41,"@4g#t", &_riepilogodon);
|
||
set_row(72,"");
|
||
}
|
||
|
||
bool TTessere_application::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 TTessere_application::filter_func_manuale(const TRelation* rel)
|
||
{
|
||
TLocalisamfile& sog = rel->lfile();
|
||
TAssoc_array& array_sogg = app()._asoggetti;
|
||
const char* codice = sog.get(SOG_CODICE);
|
||
return (array_sogg.is_key(codice));
|
||
}
|
||
|
||
print_action TTessere_application::postprocess_page(int file, int counter)
|
||
{
|
||
printer().formfeed();
|
||
return NEXT_PAGE;
|
||
}
|
||
|
||
bool TTessere_application::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 effettuate fino al ";
|
||
_riepilogodon << dataultima.string();
|
||
_riepilogodon << " n.ro ";
|
||
_riepilogodon << totdon;
|
||
}
|
||
if (_aggiorna)
|
||
{
|
||
sogg.put(SOG_T_STAMPATA,TRUE);
|
||
sogg.rewrite();
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
bool TTessere_application::set_print(int m)
|
||
{
|
||
TSheet_field& s = (TSheet_field&)_msk->field(F_SOGGETTI);
|
||
s.destroy();
|
||
s.force_update();
|
||
if (s.items()==0)
|
||
add_rows_soggetti(s,8);
|
||
KEY tasto;
|
||
tasto = _msk->run();
|
||
if (tasto == K_ENTER)
|
||
{
|
||
reset_files();
|
||
add_file(LF_SOGGETTI);
|
||
_asoggetti.destroy();
|
||
for (int r=0; r < s.items(); r++)
|
||
{
|
||
TToken_string& row = s.row(r);
|
||
const long codice = row.get_long(0);
|
||
const char* scodice = row.get(0);
|
||
if (codice != 0)
|
||
_asoggetti.add(scodice);
|
||
}
|
||
if (_asoggetti.items() != 0)
|
||
{
|
||
_aggiorna = _msk->get_bool(F_AGGIORNA2);
|
||
filtra_codici();
|
||
current_cursor()->setfilter("");
|
||
current_cursor()->set_filterfunction (filter_func_manuale, TRUE);
|
||
}
|
||
else
|
||
{
|
||
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);
|
||
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 TTessere_application::user_create()
|
||
{
|
||
_rel = new TRelation(LF_SOGGETTI);
|
||
_rel->add(LF_COMUNI, "COM==COMNASC",1,0,ALIAS_COMNAS);
|
||
_rel->add(LF_COMUNI, "COM==DOM_CODCOM",1,0,ALIAS_COMRES);
|
||
_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);
|
||
|
||
_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("at1400a");
|
||
_msk->set_handler(F_PRINTER, printer_handler);
|
||
|
||
//_form_pag = new TTessere_form("AT_PAGIN"); // dovr<76> esserci PAGINE
|
||
|
||
TString16 config;
|
||
config << "TESSERE";
|
||
printer().read_configuration(config);
|
||
return TRUE;
|
||
}
|
||
|
||
bool TTessere_application::user_destroy()
|
||
{
|
||
delete _msk;
|
||
delete _rel;
|
||
//delete _form_pag;
|
||
|
||
printer().read_configuration();
|
||
return TRUE;
|
||
}
|
||
|
||
int at1400(int argc, char* argv[])
|
||
{
|
||
|
||
TTessere_application a;
|
||
|
||
a.run(argc, argv, "Stampa tessere associative");
|
||
|
||
return 0;
|
||
}
|