campo-sirio/at/at1200.cpp
cris 07036fc2b0 sviluppo nuove richieste e correzione errori
git-svn-id: svn://10.65.10.50/trunk@5021 c028cbd2-c16b-5b4b-a496-9718f37d4682
1997-08-01 14:49:53 +00:00

235 lines
6.3 KiB
C++
Executable File
Raw Blame History

#include <form.h>
#include <mask.h>
#include <printapp.h>
#include <recarray.h>
#include <tabutil.h>
#include <utility.h>
#include "at1.h"
#include "lf.h"
// nomi campi maschera
#include "at1200a.h"
// nomi dei campi
#include "soggetti.h"
#include "donaz.h"
#include "benem.h"
#include "sezioni.h"
class TAttribuzioneBenemerenze : public TPrintapp
{
TMask* _msk;
TRelation* _rel;
TLocalisamfile* _donaz;
TLocalisamfile* _benem;
TRecord_array* _sdonazioni;
TRecord_array* _sbenemerenze;
int _cur;
TDate _data_attribuzione; // data attribuzione benemerenza
TDate _data_stampa;
TString16 _tipoben; // tipo benemerenza da assegnare
int _numdon; // numero donazioni necessarie
TString16 _codsez, _codsot;
TParagraph_string _cognome_nome;
static bool filter_func_attriben(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();
void crea_intestazione();
void header_sezione(const TString16 codsez, const TString16 codsot);
TAttribuzioneBenemerenze() : _data_attribuzione(TODAY), _data_stampa(TODAY), _tipoben(""), _cognome_nome("",25) {}
};
HIDDEN inline TAttribuzioneBenemerenze& app() { return (TAttribuzioneBenemerenze&) main_app(); }
void TAttribuzioneBenemerenze::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);
}
bool TAttribuzioneBenemerenze::preprocess_page(int file, int counter)
{
TRectype& recsez = current_cursor()->curr(LF_SEZIONI);
TRectype& recsog = current_cursor()->curr();
TLocalisamfile& filesog = current_cursor()->file();
TString80 nome = recsog.get(SOG_COGNOME);
nome << " ";
nome << recsog.get(SOG_NOME);
_cognome_nome = nome;
const int totdon = recsog.get_int(SOG_TOTDON);
// salto pagina se cambio sezione
const TString16 codsez = recsog.get(SOG_CODSEZ);
const TString16 codsot = recsog.get(SOG_CODSOT);
if ((_codsez!=codsez)||(_codsot!=codsot))
{
if (_codsez != "**")
printer().formfeed();
_codsez = codsez;
_codsot = codsot;
header_sezione(codsez, codsot);
}
return TRUE;
}
void TAttribuzioneBenemerenze::set_page(int file, int cnt)
{
set_row(1,"@0g@pn", FLD(LF_SOGGETTI,SOG_CODICE,"########"));
set_row(1,"@9g@S", FLD(LF_SOGGETTI,SOG_CATDON));
set_row(1,"@12g#a", &_cognome_nome);
set_row(1,"@38g@ld", FLD(LF_SOGGETTI,SOG_DATANASC));
set_row(1,"@49g@pn", FLD(LF_SOGGETTI,SOG_TOTDON,"###"));
}
bool TAttribuzioneBenemerenze::filter_func_attriben(const TRelation* rel)
{
bool filtrato;
// filtro chi non ha gi<67> ricevuto la benemerenza richiesta
TLocalisamfile ben(LF_BENEM);
ben.setkey(3);
TRectype& recben = ben.curr();
recben.zero();
recben.put(BEN_CODICE, rel->lfile().curr().get_long(SOG_CODICE));
recben.put(BEN_TIPOBEN, app()._tipoben);
filtrato = (ben.read() != NOERR); // se ha gia' la ben. non va filtrato
// filtro chi ha il numero donazioni giuste
if (filtrato)
filtrato = rel->lfile().curr().get_int(SOG_TOTDON) >= app()._numdon;
return filtrato;
}
void TAttribuzioneBenemerenze::header_sezione(const TString16 codsez, const TString16 codsot)
{
const TString80 densez = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSEZ);
const TString80 densot = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSOT);
TString intestazione(132);
intestazione = "Sezione: ";
intestazione << codsez;
intestazione << "/";
intestazione << codsot;
intestazione << " ";
intestazione << densez;
if ((densot.ok())&& (densot.not_empty()))
{
intestazione << "/";
intestazione << densot;
}
intestazione.center_just();
set_header(1,"@0g%s", (const char*) intestazione);
return;
}
bool TAttribuzioneBenemerenze::set_print(int)
{
KEY tasto;
tasto = _msk->run();
if (tasto == K_ENTER)
{
_codsez = "**";
_codsot = "**";
_data_attribuzione = _msk->get(F_DATA);
_tipoben = _msk->get(F_TIPOBEN);
TTable bnz("BNZ");
bnz.put("CODTAB",(const char*) _tipoben);
if (bnz.read() == NOERR)
_numdon = bnz.get_int("I0");
else
return FALSE;
reset_files();
add_file(LF_SOGGETTI);
filtra_sezioni();
current_cursor()->setfilter("TOTDON!=0");
current_cursor()->set_filterfunction(filter_func_attriben,TRUE);
reset_print();
crea_intestazione();
return TRUE;
}
else
return FALSE;
}
void TAttribuzioneBenemerenze::crea_intestazione()
{
reset_header();
TString sep(132);
sep = "ATTRIBUZIONE BENEMERENZA ";
sep << _tipoben;
const TString80 descr = _msk->get(F_D_TIPOBEN);
sep << " ";
sep << descr;
sep << " ALLA DATA ";
TString16 data_stampa = _data_attribuzione.string();
sep << data_stampa;
sep.center_just();
set_header(2, "@0g%s", (const char*) sep);
data_stampa = _data_stampa.string();
set_header(2,"@0g%10s", (const char*) data_stampa);
sep = "";
sep << "Pag. @#";
set_header(2, "@120g%s", (const char*) sep);
sep = "";
sep.fill('-');
set_header(3, (const char *) sep);
set_header(4,"@0gCod.@7gC.@10gCognome e nome@36gNato il@47Num.don.");
set_header(5,"@0g------@9g--@12g-------------------------@38g----------@49g--------");
}
bool TAttribuzioneBenemerenze::user_create()
{
_msk = new TMask("at1200a");
_rel = new TRelation(LF_SOGGETTI);
_rel->add(LF_SEZIONI,"CODSEZ==CODSEZ|CODSOT==CODSOT");
//cursore ordinamento per sezione+sottogruppo+cognome+nome
_cur = add_cursor(new TCursor(_rel, "", 3));
_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);
return TRUE;
}
bool TAttribuzioneBenemerenze::user_destroy()
{
delete _rel;
delete _msk;
delete _donaz;
delete _benem;
delete _sdonazioni;
delete _sbenemerenze;
return TRUE;
}
int at1200(int argc, char* argv[])
{
TAttribuzioneBenemerenze a;
a.run(argc, argv, "Attribuzione benemerenze");
return 0;
}