Files correlati :ca3.exe ca3600.msk Ricompilazione Demo : [ ] Commento :modificato filtro sulle cms/cdc/fsc che vengono prese dagli sheet; tiene conto di una commessa (e cdc e fsc) di tipo multilivello git-svn-id: svn://10.65.10.50/trunk@13565 c028cbd2-c16b-5b4b-a496-9718f37d4682
344 lines
8.2 KiB
C++
Executable File
344 lines
8.2 KiB
C++
Executable File
#include <applicat.h>
|
||
#include <execp.h>
|
||
#include <reprint.h>
|
||
|
||
#include "movana.h"
|
||
#include "rmovana.h"
|
||
|
||
#include "ca3.h"
|
||
#include "ca3100.h"
|
||
#include "calib01.h"
|
||
#include "calib02.h"
|
||
#include "camask.h"
|
||
|
||
////////////////////////////////////////////////////////
|
||
// MASCHERA
|
||
////////////////////////////////////////////////////////
|
||
class TPrint_movimenti_ca_mask : public TAnal_report_mask
|
||
{
|
||
protected:
|
||
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
const TString& get_report_class() const;
|
||
bool test_compatible_report();
|
||
void create_page2();
|
||
int create_page2_sheet(int lf, int& y, short& dlg, bool required);
|
||
public:
|
||
TPrint_movimenti_ca_mask();
|
||
virtual ~TPrint_movimenti_ca_mask() {}
|
||
};
|
||
|
||
const TString& TPrint_movimenti_ca_mask::get_report_class() const
|
||
{
|
||
TString& classe = get_tmp_string();
|
||
classe = "ca3100";
|
||
const int stp = get_int(F_TIPOSTAMPA);
|
||
classe << (stp == 1 ? 'a' : 'b'); // tipo di report da usare
|
||
return classe;
|
||
}
|
||
|
||
bool TPrint_movimenti_ca_mask::test_compatible_report()
|
||
{
|
||
TFilename lib = get_report_class();
|
||
const TString& name = get(F_REPORT);
|
||
bool ok = name.not_empty();
|
||
if (ok)
|
||
{
|
||
TReport rep;
|
||
ok = rep.load(name);
|
||
if (ok)
|
||
{
|
||
const TString& classe = rep.get_class();
|
||
ok = classe == lib;
|
||
}
|
||
}
|
||
if (!ok)
|
||
{
|
||
set(F_REPORT, lib);
|
||
lib.ext("rep");
|
||
ok = lib.custom_path();
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TPrint_movimenti_ca_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_TIPOSTAMPA:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
test_compatible_report(); //in base al tipo stampa setta i report compatibili
|
||
}
|
||
break;
|
||
case F_REPORT:
|
||
if (e == fe_button)
|
||
{
|
||
const TString8 lib = get_report_class();
|
||
TFilename path = o.get();
|
||
if (select_custom_file(path, "rep", lib))
|
||
{
|
||
path = path.name();
|
||
path.ext("");
|
||
o.set(path);
|
||
}
|
||
} else
|
||
if (e == fe_close)
|
||
{
|
||
if (!test_compatible_report())
|
||
return error_box(TR("Impossibile trovare un report compatibile"));
|
||
}
|
||
break;
|
||
case F_DATAINI:
|
||
case F_DATAFIN:
|
||
if (e == fe_close)
|
||
{
|
||
const TString& anno = get(F_ANNO);
|
||
if (anno.not_empty()) //se l'anno esercizio esiste...
|
||
{
|
||
const TRectype& esc = cache().get("ESC", anno);
|
||
const TDate datainiesc = esc.get("D0");
|
||
const TDate datafinesc = esc.get("D1");
|
||
if (o.empty())
|
||
{
|
||
const TDate dataesc = o.dlg() == F_DATAINI ? datainiesc : datafinesc;
|
||
o.set(dataesc.string());
|
||
}
|
||
else
|
||
{
|
||
const TDate d = o.get();
|
||
if (d < datainiesc || d > datafinesc)
|
||
return error_box(TR("La data deve essere compresa nell'esercizio selezionato"));
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
|
||
default: break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
TPrint_movimenti_ca_mask::TPrint_movimenti_ca_mask()
|
||
:TAnal_report_mask("ca3100")
|
||
{
|
||
TConfig& cfg = ca_config();
|
||
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
||
|
||
const int logicnum = use_pdcc ? LF_PCON : LF_PCONANA;
|
||
|
||
// creazione dei campi della seconda pagina della maschera
|
||
create_sheet(F_RIGHE);
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// RECORDSET
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TPrint_movimenti_ca_recordset : public TISAM_recordset
|
||
{
|
||
int _anno;
|
||
TDate _dadata, _adata;
|
||
char _tipomov;
|
||
long _danumreg, _anumreg;
|
||
TString4 _dacaus, _acaus;
|
||
TString _codcosto, _codcms, _codfas;
|
||
|
||
protected:
|
||
static bool mov_filter(const TRelation* rel);
|
||
bool valid_record(const TRelation& rel) const;
|
||
|
||
virtual void set_custom_filter(TCursor& cur) const;
|
||
|
||
public:
|
||
void set_filter(const TPrint_movimenti_ca_mask& msk, int cms_row);
|
||
TPrint_movimenti_ca_recordset(const TString& sql) : TISAM_recordset(sql) { }
|
||
};
|
||
|
||
static const TPrint_movimenti_ca_recordset* myself = NULL;
|
||
|
||
//metodo per riconoscere se il record corrente soddisfa i filtri della maschera...strafighissimo!
|
||
bool TPrint_movimenti_ca_recordset::valid_record(const TRelation& rel) const
|
||
{
|
||
//prima controlla la testata...
|
||
const TRectype& mov = rel.curr(LF_MOVANA);
|
||
|
||
const char* datefld = _anno > 0 ? MOVANA_DATACOMP : MOVANA_DATAREG;
|
||
const TDate data = mov.get(datefld);
|
||
if (data < _dadata || (_adata.ok() && data > _adata))
|
||
return false;
|
||
|
||
const TString& codcaus = mov.get(MOVANA_CODCAUS);
|
||
if (codcaus < _dacaus || (_acaus.not_empty() && codcaus > _acaus))
|
||
return false;
|
||
|
||
if (_tipomov > ' ')
|
||
{
|
||
const char tipomov = mov.get_char(MOVANA_TIPOMOV);
|
||
if (tipomov != _tipomov)
|
||
return false;
|
||
}
|
||
|
||
//..poi le righe (devono comparire solo le righe con cdc/cms/fsc che appaiono nello sheet)
|
||
const TRectype& rmov = rel.curr(LF_RMOVANA);
|
||
|
||
if (_codcosto.not_empty())
|
||
{
|
||
const TString& cos = rmov.get(RMOVANA_CODCCOSTO);
|
||
if (!cos.starts_with(_codcosto))
|
||
return false;
|
||
}
|
||
if (_codcms.not_empty())
|
||
{
|
||
const TString& cms = rmov.get(RMOVANA_CODCMS);
|
||
if (!cms.starts_with(_codcms))
|
||
return false;
|
||
}
|
||
if (_codfas.not_empty())
|
||
{
|
||
const TString& fas = rmov.get(RMOVANA_CODFASE);
|
||
if (!fas.starts_with(_codfas))
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
bool TPrint_movimenti_ca_recordset::mov_filter(const TRelation* rel)
|
||
{
|
||
return myself->valid_record(*rel);
|
||
}
|
||
|
||
void TPrint_movimenti_ca_recordset::set_custom_filter(TCursor& cur) const
|
||
{
|
||
myself = this;
|
||
cur.set_filterfunction(mov_filter, true);
|
||
}
|
||
|
||
//metodo per caricare i valori nel recordset dalla maschera...fighissimo!!
|
||
void TPrint_movimenti_ca_recordset::set_filter(const TPrint_movimenti_ca_mask& msk, int cms_row)
|
||
{
|
||
_codcosto = _codcms = _codfas = "";
|
||
if (cms_row >= 0)
|
||
{
|
||
TSheet_field& sf = msk.sfield(F_RIGHE);
|
||
TMask& sm = sf.sheet_mask();
|
||
sf.update_mask(cms_row);
|
||
TRelation rel(LF_RMOVANA);
|
||
sm.autosave(rel);
|
||
_codcosto = rel.curr().get(RMOVANA_CODCCOSTO);
|
||
_codcms = rel.curr().get(RMOVANA_CODCMS);
|
||
_codfas = rel.curr().get(RMOVANA_CODFASE);
|
||
}
|
||
|
||
_dadata = msk.get_date(F_DATAINI);
|
||
_adata = msk.get_date(F_DATAFIN);
|
||
|
||
_dacaus = msk.get(F_CAUSALEINI);
|
||
_acaus = msk.get(F_CAUSALEFIN);
|
||
|
||
_tipomov = msk.get(F_TIPOMOV)[0];
|
||
}
|
||
|
||
|
||
|
||
////////////////////////////////////////////////////////
|
||
// REPORT
|
||
////////////////////////////////////////////////////////
|
||
class TPrint_movimenti_ca_rep : public TAnal_report
|
||
{
|
||
int _anno;
|
||
|
||
protected:
|
||
virtual bool set_recordset(const TString& sql);
|
||
virtual bool get_usr_val(const TString& name, TVariant& var) const;
|
||
|
||
public:
|
||
void set_filter(const TPrint_movimenti_ca_mask& msk, int cms_row);
|
||
};
|
||
|
||
bool TPrint_movimenti_ca_rep::get_usr_val(const TString& name, TVariant& var) const
|
||
{
|
||
if (name == "#ESERCIZIO")
|
||
{
|
||
var.set(_anno);
|
||
return true;
|
||
}
|
||
return TAnal_report::get_usr_val(name, var);
|
||
}
|
||
|
||
bool TPrint_movimenti_ca_rep::set_recordset(const TString& sql)
|
||
{
|
||
TPrint_movimenti_ca_recordset* rs = new TPrint_movimenti_ca_recordset(sql);
|
||
return TReport::set_recordset(rs);
|
||
}
|
||
|
||
void TPrint_movimenti_ca_rep::set_filter(const TPrint_movimenti_ca_mask& msk, int cms_row)
|
||
{
|
||
_anno = msk.get_int(F_ANNO);
|
||
TPrint_movimenti_ca_recordset* rs = (TPrint_movimenti_ca_recordset*)recordset();
|
||
rs->set_filter(msk, cms_row);
|
||
}
|
||
|
||
|
||
////////////////////////////////////////////////////////
|
||
// APPLICAZIONE
|
||
////////////////////////////////////////////////////////
|
||
class TPrint_movimenti_ca : public TSkeleton_application
|
||
{
|
||
TPrint_movimenti_ca_mask * _mask;
|
||
|
||
protected:
|
||
bool create();
|
||
bool destroy();
|
||
|
||
public:
|
||
virtual void main_loop();
|
||
};
|
||
|
||
bool TPrint_movimenti_ca::create()
|
||
{
|
||
_mask = new TPrint_movimenti_ca_mask;
|
||
return TSkeleton_application::create();
|
||
}
|
||
|
||
bool TPrint_movimenti_ca::destroy()
|
||
{
|
||
delete _mask;
|
||
return TSkeleton_application::destroy();
|
||
}
|
||
|
||
void TPrint_movimenti_ca::main_loop()
|
||
{
|
||
while (_mask->run() == K_ENTER)
|
||
{
|
||
//costruzione della query x il report in base ai parametri della maschera
|
||
TSheet_field& sheet = _mask->sfield(F_RIGHE);
|
||
const int n_righe_sheet = sheet.items();
|
||
//se lo sheet <20> vuoto aggiunge una riga vuota
|
||
if (n_righe_sheet == 0)
|
||
sheet.insert();
|
||
|
||
//report e book
|
||
TReport_book book; //book dei report
|
||
|
||
TPrint_movimenti_ca_rep rep;
|
||
rep.load(_mask->get(F_REPORT));
|
||
|
||
FOR_EACH_SHEET_ROW(sheet, r, row)
|
||
{
|
||
rep.set_filter(*_mask, r);
|
||
book.add(rep);
|
||
}
|
||
|
||
book.print_or_preview(); //stampa il book dei report
|
||
}
|
||
}
|
||
|
||
int ca3100(int argc, char* argv[])
|
||
{
|
||
TPrint_movimenti_ca a;
|
||
a.run(argc, argv, TR("Stampa movimenti"));
|
||
return 0;
|
||
} |