2010-07-24 07:17:32 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <automask.h>
|
|
|
|
#include <defmask.h>
|
|
|
|
#include <recset.h>
|
|
|
|
#include <sheet.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#include <doc.h>
|
|
|
|
|
|
|
|
#include "ci2.h"
|
|
|
|
#include "cilib.h"
|
|
|
|
#include "ci2100a.h"
|
2010-07-31 11:31:19 +00:00
|
|
|
#include "rilore.h"
|
2010-08-01 05:54:40 +00:00
|
|
|
#include "../ca/calib01.h"
|
2010-07-24 07:17:32 +00:00
|
|
|
#include "../ve/velib.h"
|
|
|
|
|
|
|
|
////////////////////////////////////////////
|
|
|
|
//// CLASSE TRilevamento_prev_msk ////
|
|
|
|
////////////////////////////////////////////
|
|
|
|
|
|
|
|
//Classe TRilevamento_prev_msk
|
|
|
|
class TRilevamento_prev_msk : public TAutomask
|
|
|
|
{
|
|
|
|
int _qtaore;
|
2010-07-31 11:31:19 +00:00
|
|
|
short _cdc_sid, _cdc_lid;
|
|
|
|
short _cms_sid, _cms_lid;
|
|
|
|
short _fase_sid, _fase_lid;
|
|
|
|
short _scdc_sid, _scdc_lid;
|
|
|
|
short _scms_sid, _scms_lid;
|
|
|
|
short _sfase_sid, _sfase_lid;
|
|
|
|
|
2010-07-24 07:17:32 +00:00
|
|
|
protected:
|
|
|
|
const real proponi_costo(const TMask& msk);
|
|
|
|
const real proponi_costo(TToken_string& riga);
|
|
|
|
|
2010-07-31 11:31:19 +00:00
|
|
|
void get_anal_fields(TString & cdc, TString & cms, TString & fase);
|
|
|
|
void get_row_anal_fields(TToken_string & row, TString & cdc, TString & cms, TString & fase);
|
|
|
|
void put_row_anal_fields(TToken_string & row, const TString & cdc, const TString & cms, const TString & fase);
|
2010-07-24 07:17:32 +00:00
|
|
|
void carica_default();
|
|
|
|
void riempi_sheet();
|
|
|
|
void nuova_riga();
|
|
|
|
void azzera_riga(TSheet_field& sheet);
|
|
|
|
void azzera_tutto(TSheet_field& sheet);
|
|
|
|
void registra();
|
|
|
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void esegui() const;
|
|
|
|
TRilevamento_prev_msk();
|
|
|
|
};
|
|
|
|
|
|
|
|
const real TRilevamento_prev_msk::proponi_costo(const TMask& msk)
|
|
|
|
{
|
|
|
|
real costo = ZERO;
|
|
|
|
const char tipo = msk.get(S_RISOATT)[0];
|
|
|
|
TString80 codice;
|
|
|
|
switch(tipo)
|
|
|
|
{
|
|
|
|
case 'R': codice = msk.get(S_CODRIS); break;
|
|
|
|
case 'A': codice = msk.get(S_CODATT); break;
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
const int anno = msk.get_date(S_DADATA).year();
|
|
|
|
TString4 mese; mese.format("%02d", msk.get_date(S_DADATA).month());
|
|
|
|
const TString4 tpora = msk.get(S_TPORA);
|
|
|
|
|
|
|
|
const TRisoatt_key chiave(tipo, codice, anno, mese, tpora);
|
|
|
|
TModule_table roa("&ROA");
|
|
|
|
roa.put("CODTAB", chiave);
|
|
|
|
int err = roa.read();
|
|
|
|
|
|
|
|
if(err == NOERR)
|
|
|
|
costo = roa.get_real("R1");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TString8 tmp; tmp << anno << mese;
|
|
|
|
const long anme = atol(tmp);
|
|
|
|
TString query;
|
|
|
|
query << "USE &ROA\n"
|
|
|
|
<< "SELECT I0<" << anme << "\n"
|
|
|
|
<< "FROM CODTAB=" << tipo << codice.left_just(16) << "\n"
|
|
|
|
<< "TO CODTAB=" << tipo << codice.left_just(16) << "\n"
|
|
|
|
<< "BY I0\n";
|
|
|
|
TISAM_recordset rec(query);
|
|
|
|
|
|
|
|
if(rec.move_last())
|
|
|
|
costo = rec.cursor()->curr().get_real("R1");
|
|
|
|
}
|
|
|
|
return costo;
|
|
|
|
}
|
|
|
|
|
|
|
|
const real TRilevamento_prev_msk::proponi_costo(TToken_string& riga)
|
|
|
|
{
|
|
|
|
real costo = ZERO;
|
|
|
|
TSheet_field& sheet = sfield(F_SHEET);
|
|
|
|
const char tipo = riga.get_char(sheet.cid2index(S_RISOATT));
|
|
|
|
TString80 codice;
|
|
|
|
switch(tipo)
|
|
|
|
{
|
|
|
|
case 'R': codice = riga.get(sheet.cid2index(S_CODRIS)); break;
|
|
|
|
case 'A': codice = riga.get(sheet.cid2index(S_CODATT)); break;
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
|
|
|
|
TString cazzone = riga.get(sheet.cid2index(S_DADATA));
|
|
|
|
const TDate dadata(riga.get(sheet.cid2index(S_DADATA)));
|
|
|
|
const int anno = dadata.year();
|
|
|
|
TString4 mese; mese.format("%02d", dadata.month());
|
|
|
|
const TString4 tpora = riga.get(sheet.cid2index(S_TPORA));
|
|
|
|
|
|
|
|
const TRisoatt_key chiave(tipo, codice, anno, mese, tpora);
|
|
|
|
TModule_table roa("&ROA");
|
|
|
|
roa.put("CODTAB", chiave);
|
|
|
|
int err = roa.read();
|
|
|
|
|
|
|
|
if(err == NOERR)
|
|
|
|
costo = roa.get_real("R1");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TString8 tmp; tmp << anno << mese;
|
|
|
|
const long anme = atol(tmp);
|
|
|
|
TString query;
|
|
|
|
query << "USE &ROA\n"
|
|
|
|
<< "SELECT I0<" << anme << "\n"
|
|
|
|
<< "FROM CODTAB=" << tipo << codice.left_just(16) << "\n"
|
|
|
|
<< "TO CODTAB=" << tipo << codice.left_just(16) << "\n"
|
|
|
|
<< "BY I0\n";
|
|
|
|
TISAM_recordset rec(query);
|
|
|
|
|
|
|
|
if(rec.move_last())
|
|
|
|
costo = rec.cursor()->curr().get_real("R1");
|
|
|
|
}
|
|
|
|
return costo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-31 11:31:19 +00:00
|
|
|
void TRilevamento_prev_msk::get_anal_fields(TString & cdc, TString & cms, TString & fase)
|
|
|
|
{
|
|
|
|
TString val;
|
|
|
|
|
|
|
|
cdc.cut(0);
|
|
|
|
if (_cdc_sid >= 0)
|
|
|
|
for ( short id = _cdc_sid; id <= _cdc_lid; id++)
|
|
|
|
{
|
|
|
|
val = get(id);
|
|
|
|
val.rpad(field(id).size());
|
|
|
|
cdc << val;
|
|
|
|
}
|
|
|
|
cdc.trim();
|
|
|
|
cms.cut(0);
|
|
|
|
if (_cms_sid >= 0)
|
|
|
|
for ( short id = _cms_sid; id <= _cms_lid; id++)
|
|
|
|
{
|
|
|
|
val = get(id);
|
|
|
|
val.rpad(field(id).size());
|
|
|
|
cms << val;
|
|
|
|
}
|
|
|
|
cms.trim();
|
|
|
|
fase.cut(0);
|
|
|
|
if (_fase_sid >= 0)
|
|
|
|
for ( short id = _fase_sid; id <= _fase_lid; id++)
|
|
|
|
{
|
|
|
|
val = get(id);
|
|
|
|
val.rpad(field(id).size());
|
|
|
|
fase << val;
|
|
|
|
}
|
|
|
|
fase.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRilevamento_prev_msk::get_row_anal_fields(TToken_string & row, TString & cdc, TString & cms, TString & fase)
|
|
|
|
{
|
|
|
|
TMask & m = sfield(F_SHEET).sheet_mask();
|
|
|
|
TString val;
|
|
|
|
|
|
|
|
cdc.cut(0);
|
|
|
|
if (_scdc_sid >= 0)
|
|
|
|
for ( short id = _scdc_sid; id <= _scdc_lid; id++)
|
|
|
|
{
|
|
|
|
val = m.get(id);
|
|
|
|
val.rpad(m.field(id).size());
|
|
|
|
cdc << val;
|
|
|
|
}
|
|
|
|
cdc.trim();
|
|
|
|
cms.cut(0);
|
|
|
|
if (_scms_sid >= 0)
|
|
|
|
for ( short id = _scms_sid; id <= _scms_lid; id++)
|
|
|
|
{
|
|
|
|
val = m.get(id);
|
|
|
|
val.rpad(m.field(id).size());
|
|
|
|
cms << val;
|
|
|
|
}
|
|
|
|
cms.trim();
|
|
|
|
fase.cut(0);
|
|
|
|
if (_sfase_sid >= 0)
|
|
|
|
for ( short id = _sfase_sid; id <= _sfase_lid; id++)
|
|
|
|
{
|
|
|
|
val = m.get(id);
|
|
|
|
val.rpad(m.field(id).size());
|
|
|
|
fase << val;
|
|
|
|
}
|
|
|
|
fase.trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRilevamento_prev_msk::put_row_anal_fields(TToken_string & row, const TString & cdc, const TString & cms, const TString & fase)
|
|
|
|
{
|
|
|
|
TSheet_field & s = sfield(F_SHEET);
|
|
|
|
TMask & m = s.sheet_mask();
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
if (_scdc_sid >= 0)
|
|
|
|
for (short id = _scdc_sid; id <= _scdc_lid; id++)
|
|
|
|
{
|
|
|
|
const int len = m.field(id).size();
|
|
|
|
row.add(cdc.mid(pos, len), s.cid2index(id));
|
|
|
|
pos += len;
|
|
|
|
}
|
|
|
|
pos = 0;
|
|
|
|
if (_scms_sid >= 0)
|
|
|
|
for (short id = _scms_sid; id <= _scms_lid; id++)
|
|
|
|
{
|
|
|
|
const int len = m.field(id).size();
|
|
|
|
row.add(cms.mid(pos, len), s.cid2index(id));
|
|
|
|
pos += len;
|
|
|
|
}
|
|
|
|
pos = 0;
|
|
|
|
if (_sfase_sid >= 0)
|
|
|
|
for (short id = _sfase_sid; id <= _sfase_lid; id++)
|
|
|
|
{
|
|
|
|
const int len = m.field(id).size();
|
|
|
|
row.add(fase.mid(pos, len), s.cid2index(id));
|
|
|
|
pos += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-24 07:17:32 +00:00
|
|
|
void TRilevamento_prev_msk::carica_default()
|
|
|
|
{
|
|
|
|
//leggo dalla maschera i campi chiave di ricerca
|
2010-07-31 11:31:19 +00:00
|
|
|
const int anno = get_date(F_DADATA).year();
|
2010-07-24 07:17:32 +00:00
|
|
|
const TString4 risoatt = get(F_RISOATT) == "T" ? "" : get(F_RISOATT);
|
|
|
|
TString4 damese; damese.format("%02d", get_date(F_DADATA).month());
|
|
|
|
TString4 amese; amese.format("%02d", get_date(F_ADATA).month());
|
|
|
|
const TString4 tpora = get(F_TPORA);
|
2010-07-31 11:31:19 +00:00
|
|
|
TString80 codcosto;
|
|
|
|
TString80 codcms;
|
|
|
|
TString16 codfase;
|
2010-07-24 07:17:32 +00:00
|
|
|
TString16 codice;
|
2010-07-31 11:31:19 +00:00
|
|
|
|
|
|
|
switch(get(F_RISOATT)[0])
|
2010-07-24 07:17:32 +00:00
|
|
|
{
|
|
|
|
case 'T': codice = get(F_CODICE); break;
|
|
|
|
case 'R': codice = get(F_CODRIS); break;
|
|
|
|
case 'A': codice = get(F_CODATT); break;
|
|
|
|
default: break;
|
|
|
|
}
|
2010-07-31 11:31:19 +00:00
|
|
|
|
|
|
|
get_anal_fields(codcosto, codcms, codfase);
|
|
|
|
|
|
|
|
TString query;
|
|
|
|
query << "USE " << LF_RILORE << "\n";
|
|
|
|
if (risoatt.full())
|
|
|
|
query << "SELECT (BETWEEN(" << RILORE_TIPORA << ",\"" << risoatt << "\",\"" << risoatt << "\"))";
|
|
|
|
if (codice.full())
|
|
|
|
query << "&&(BETWEEN(" << RILORE_CODICE << ",\"" << codice << "\",\"" << codice << "\"))";
|
|
|
|
if (anno > 0)
|
|
|
|
query << "&&(BETWEEN(" << RILORE_ANNO << ",\"" << anno << "\",\"" << anno << "\"))";
|
|
|
|
query << "(BETWEEN(MESE,\"" << damese << "\",\"" << amese << "\"))&&";
|
|
|
|
if (tpora.full())
|
|
|
|
query << "&&(BETWEEN(" << RILORE_TPORA << ",\"" << tpora << "\",\"" << tpora << "\"))";
|
|
|
|
if (codcosto.full())
|
|
|
|
query << "&&(BETWEEN(" << RILORE_CODCOSTO << ",\"" << codcosto << "\",\"" << codcosto << "\"))";
|
|
|
|
if (codcms.full())
|
|
|
|
query << "&&(BETWEEN(" << RILORE_CODCMS << ",\"" << codcms << "\",\"" << codcms << "\"))";
|
|
|
|
if (codfase.full())
|
|
|
|
query << "&&(BETWEEN(" << RILORE_CODFASE << ",\"" << codfase << "\",\"" << codfase << "\"))";
|
|
|
|
query << "\n";
|
|
|
|
|
|
|
|
TString fromto = RILORE_TIPO "=\"D\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(risoatt != 'T')
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_TIPORA << "=\"" << risoatt << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(codice.full())
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_CODICE << "=\"" << codice << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(anno > 0)
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_ANNO << "=\"" << anno << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(damese.full())
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << RILORE_MESE << "=\"" << damese << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(tpora.full())
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_TPORA << "=\"" << tpora << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
query << "FROM " << fromto << "\n"
|
|
|
|
<< "TO " << fromto;
|
|
|
|
|
|
|
|
TISAM_recordset def(query);
|
|
|
|
|
|
|
|
TSheet_field& sheet = sfield(F_SHEET);
|
|
|
|
sheet.destroy();
|
|
|
|
|
|
|
|
const TDate da(1, get_date(F_DADATA).month(), get_date(F_DADATA).year());
|
2010-08-01 05:54:40 +00:00
|
|
|
TDate a = da; a.set_end_month();
|
2010-07-24 07:17:32 +00:00
|
|
|
|
|
|
|
//riempio lo sheet con i dati che soddisfano il filtro preparato prima
|
|
|
|
for(bool ok = def.move_first(); ok; ok = def.move_next())
|
|
|
|
{
|
|
|
|
TRilevamento_ore rilore(def.cursor()->curr());
|
|
|
|
TToken_string& riga = sheet.row(-1);
|
|
|
|
riga.add(rilore.tipora(), sheet.cid2index(S_RISOATT));
|
|
|
|
switch(rilore.tipora())
|
|
|
|
{
|
|
|
|
case 'R': riga.add(rilore.codice(), sheet.cid2index(S_CODRIS)); break;
|
|
|
|
case 'A': riga.add(rilore.codice(), sheet.cid2index(S_CODATT)); break;
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
riga.add(rilore.dadata(), sheet.cid2index(S_DADATA));
|
|
|
|
riga.add(rilore.adata(), sheet.cid2index(S_ADATA));
|
|
|
|
riga.add(rilore.tpora(), sheet.cid2index(S_TPORA));
|
2010-07-31 11:31:19 +00:00
|
|
|
riga.add(da.string(), sheet.cid2index(S_DADATA));
|
|
|
|
riga.add(a.string(), sheet.cid2index(S_ADATA));
|
|
|
|
put_row_anal_fields(riga, rilore.codcosto(), rilore.codcms(), rilore.codfase());
|
2010-07-24 07:17:32 +00:00
|
|
|
riga.add(rilore.qtaore(), sheet.cid2index(S_QTAORE));
|
|
|
|
riga.add(proponi_costo(riga).string(), sheet.cid2index(S_COSTO));
|
|
|
|
}
|
|
|
|
sheet.force_update();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//RIEMPI_SHEET: metodo che riempie lo sheet in base ai campi chiave
|
|
|
|
//compilati sulla maschera
|
|
|
|
void TRilevamento_prev_msk::riempi_sheet()
|
|
|
|
{
|
|
|
|
//leggo dalla maschera i campi chiave di ricerca
|
|
|
|
const int anno = get_date(F_DADATA).year();
|
|
|
|
const TString4 risoatt = get(F_RISOATT) == "T" ? "" : get(F_RISOATT);
|
2010-08-01 05:54:40 +00:00
|
|
|
TString4 damese; damese.format("%02d", get_date(F_DADATA).month()); if (damese == "00") damese = "01";
|
|
|
|
TString4 amese; amese.format("%02d", get_date(F_ADATA).month()); if (amese == "00") amese = "12";
|
2010-07-24 07:17:32 +00:00
|
|
|
const TString4 tpora = get(F_TPORA);
|
2010-07-31 11:31:19 +00:00
|
|
|
TString80 codcosto;
|
|
|
|
TString80 codcms;
|
|
|
|
TString16 codfase;
|
2010-07-24 07:17:32 +00:00
|
|
|
TString16 codice;
|
|
|
|
switch(get(F_RISOATT)[0])
|
|
|
|
{
|
|
|
|
case 'T': codice = get(F_CODICE); break;
|
|
|
|
case 'R': codice = get(F_CODRIS); break;
|
|
|
|
case 'A': codice = get(F_CODATT); break;
|
|
|
|
default: break;
|
|
|
|
}
|
2010-07-31 11:31:19 +00:00
|
|
|
|
|
|
|
get_anal_fields(codcosto, codcms, codfase);
|
|
|
|
|
|
|
|
TString query;
|
2010-08-01 05:54:40 +00:00
|
|
|
query << "USE " << LF_RILORE << "\n" ;
|
|
|
|
|
|
|
|
TString select;
|
2010-07-31 11:31:19 +00:00
|
|
|
if (risoatt.full())
|
2010-08-01 05:54:40 +00:00
|
|
|
select << "(BETWEEN(" << RILORE_TIPORA << ",\"" << risoatt << "\",\"" << risoatt << "\"))";
|
2010-07-31 11:31:19 +00:00
|
|
|
if (codice.full())
|
2010-08-01 05:54:40 +00:00
|
|
|
{
|
|
|
|
if (select.full()) select << "&&";
|
|
|
|
select << "(BETWEEN(" << RILORE_CODICE << ",\"" << codice << "\",\"" << codice << "\"))";
|
|
|
|
}
|
2010-07-31 11:31:19 +00:00
|
|
|
if (anno > 0)
|
2010-08-01 05:54:40 +00:00
|
|
|
{
|
|
|
|
if (select.full()) select << "&&";
|
|
|
|
select << "(BETWEEN(" << RILORE_ANNO << ",\"" << anno << "\",\"" << anno << "\"))";
|
|
|
|
}
|
|
|
|
if (select.full()) select << "&&";
|
|
|
|
select << "(BETWEEN(MESE,\"" << damese << "\",\"" << amese << "\"))";
|
2010-07-31 11:31:19 +00:00
|
|
|
if (tpora.full())
|
2010-08-01 05:54:40 +00:00
|
|
|
{
|
|
|
|
if (select.full()) select << "&&";
|
|
|
|
select << "(BETWEEN(" << RILORE_TPORA << ",\"" << tpora << "\",\"" << tpora << "\"))";
|
|
|
|
}
|
2010-07-31 11:31:19 +00:00
|
|
|
if (codcosto.full())
|
2010-08-01 05:54:40 +00:00
|
|
|
{
|
|
|
|
if (select.full()) select << "&&";
|
|
|
|
select << "(BETWEEN(" << RILORE_CODCOSTO << ",\"" << codcosto << "\",\"" << codcosto << "\"))";
|
|
|
|
}
|
2010-07-31 11:31:19 +00:00
|
|
|
if (codcms.full())
|
2010-08-01 05:54:40 +00:00
|
|
|
{
|
|
|
|
if (select.full()) select << "&&";
|
|
|
|
select << "(BETWEEN(" << RILORE_CODCMS << ",\"" << codcms << "\",\"" << codcms << "\"))";
|
|
|
|
}
|
2010-07-31 11:31:19 +00:00
|
|
|
if (codfase.full())
|
2010-08-01 05:54:40 +00:00
|
|
|
{
|
|
|
|
if (select.full()) select << "&&";
|
|
|
|
select << "(BETWEEN(" << RILORE_CODFASE << ",\"" << codfase << "\",\"" << codfase << "\"))";
|
|
|
|
}
|
|
|
|
if (select.full())
|
|
|
|
query << "SELECT " << select << "\n";
|
2010-07-31 11:31:19 +00:00
|
|
|
|
|
|
|
TString fromto = RILORE_TIPO "=\"P\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(risoatt != 'T')
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_TIPORA << "=\"" << risoatt << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(codice.full())
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_CODICE << "=\"" << codice << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(anno > 0)
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_ANNO << "=\"" << anno << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(damese.full())
|
|
|
|
{
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << RILORE_MESE << "=\"" << damese << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
if(tpora.full())
|
2010-07-31 11:31:19 +00:00
|
|
|
fromto << " " << RILORE_TPORA << "=\"" << tpora << "\" ";
|
2010-07-24 07:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
query << "FROM " << fromto << "\n"
|
|
|
|
<< "TO " << fromto;
|
|
|
|
|
|
|
|
TISAM_recordset def(query);
|
|
|
|
|
|
|
|
TSheet_field& sheet = sfield(F_SHEET);
|
|
|
|
sheet.destroy();
|
|
|
|
|
|
|
|
//riempio lo sheet con i dati che soddisfano il filtro preparato prima
|
|
|
|
for(bool ok = def.move_first(); ok; ok = def.move_next())
|
|
|
|
{
|
|
|
|
TRilevamento_ore rilore(def.cursor()->curr());
|
|
|
|
TToken_string& riga = sheet.row(-1);
|
|
|
|
riga.add(rilore.tipora(), sheet.cid2index(S_RISOATT));
|
|
|
|
switch(rilore.tipora())
|
|
|
|
{
|
|
|
|
case 'R': riga.add(rilore.codice(), sheet.cid2index(S_CODRIS)); break;
|
|
|
|
case 'A': riga.add(rilore.codice(), sheet.cid2index(S_CODATT)); break;
|
|
|
|
default : break;
|
|
|
|
}
|
|
|
|
riga.add(rilore.dadata(), sheet.cid2index(S_DADATA));
|
|
|
|
riga.add(rilore.adata(), sheet.cid2index(S_ADATA));
|
|
|
|
riga.add(rilore.tpora(), sheet.cid2index(S_TPORA));
|
2010-07-31 11:31:19 +00:00
|
|
|
put_row_anal_fields(riga, rilore.codcosto(), rilore.codcms(), rilore.codfase());
|
2010-07-24 07:17:32 +00:00
|
|
|
riga.add(rilore.dadata(), sheet.cid2index(S_DADATA));
|
|
|
|
riga.add(rilore.adata(), sheet.cid2index(S_ADATA));
|
|
|
|
riga.add(rilore.qtaore(), sheet.cid2index(S_QTAORE));
|
|
|
|
riga.add(rilore.costo().string(), sheet.cid2index(S_COSTO));
|
2010-07-31 11:31:19 +00:00
|
|
|
}
|
2010-08-01 05:54:40 +00:00
|
|
|
sheet.force_update();
|
2010-07-24 07:17:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//NUOVA_RIGA: metodo che aggiunge una riga allo sheet
|
|
|
|
//tenendo conto dei campi chiave compilati in testata
|
|
|
|
void TRilevamento_prev_msk::nuova_riga()
|
|
|
|
{
|
|
|
|
TSheet_field& sheet = sfield(F_SHEET);
|
2010-07-31 11:31:19 +00:00
|
|
|
TToken_string & riga = sheet.row(-1);
|
|
|
|
const int r = sheet.items() - 1;
|
|
|
|
sheet.select(r);
|
2010-07-24 07:17:32 +00:00
|
|
|
TMask& msk = sheet.sheet_mask();
|
|
|
|
|
|
|
|
//guardo il tipo risorsa / attrezzatura che sto ricercando
|
2010-07-31 11:31:19 +00:00
|
|
|
const bool tutti = get(F_RISOATT)[0] == 'T';
|
|
|
|
const TString4 tipo = tutti ? "R" : get(F_RISOATT);
|
|
|
|
TString codice;
|
|
|
|
TString16 dadata(get(F_DADATA));
|
|
|
|
TString16 adata(get(F_ADATA));
|
|
|
|
TString tpora = get(F_TPORA);
|
|
|
|
TString codcosto;
|
|
|
|
TString codcms;
|
|
|
|
TString codfase;
|
|
|
|
|
|
|
|
riga.add(tipo, sheet.cid2index(S_RISOATT));
|
|
|
|
if (!tutti)
|
|
|
|
{
|
|
|
|
if (tipo == "R")
|
|
|
|
riga.add(get(F_CODRIS), sheet.cid2index(S_CODRIS));
|
|
|
|
else
|
|
|
|
riga.add(get(F_CODATT), sheet.cid2index(S_CODATT));
|
|
|
|
}
|
|
|
|
riga.add(dadata, sheet.cid2index(S_DADATA));
|
|
|
|
riga.add(adata, sheet.cid2index(S_ADATA));
|
|
|
|
riga.add(tpora, sheet.cid2index(S_TPORA));
|
|
|
|
get_anal_fields(codcosto, codcms, codfase);
|
|
|
|
put_row_anal_fields(riga, codcosto, codcms, codfase);
|
|
|
|
|
|
|
|
riga.add(proponi_costo(msk).string(), sheet.cid2index(S_COSTO));
|
|
|
|
sheet.update_mask(r);
|
|
|
|
msk.enable(S_RISOATT, tutti);
|
|
|
|
if (tutti || tipo == "R")
|
|
|
|
msk.enable(S_CODRIS);
|
|
|
|
if (tutti || tipo == "A")
|
|
|
|
msk.enable(S_CODATT);
|
|
|
|
msk.enable(S_DADATA, dadata.empty());
|
|
|
|
msk.enable(S_ADATA, adata.empty());
|
|
|
|
msk.enable(S_TPORA, tpora.empty());
|
|
|
|
if (_scdc_sid >= 0)
|
|
|
|
for ( short id = _scdc_sid; id <= _scdc_lid; id++)
|
|
|
|
msk.enable(id, codcosto.blank());
|
|
|
|
if (_scms_sid >= 0)
|
|
|
|
for ( short id = _scms_sid; id <= _scms_lid; id++)
|
|
|
|
msk.enable(id, codcms.blank());
|
|
|
|
if (_sfase_sid >= 0)
|
|
|
|
for ( short id = _sfase_sid; id <= _sfase_lid; id++)
|
|
|
|
msk.enable(id, codfase.blank());
|
2010-07-24 07:17:32 +00:00
|
|
|
|
|
|
|
//lancio la maschera di riga da compilare
|
|
|
|
if(msk.run() == K_ENTER)
|
|
|
|
{
|
|
|
|
const int qtaore = msk.get_int(S_QTAORE);
|
|
|
|
const real prezzo = msk.get_real(S_COSTO);
|
|
|
|
|
|
|
|
if(qtaore > 0)
|
2010-07-31 11:31:19 +00:00
|
|
|
sheet.update_row(r);
|
2010-07-24 07:17:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sheet.destroy(sheet.items() - 1);
|
|
|
|
sheet.force_update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msk.enable_default();
|
|
|
|
|
|
|
|
sheet.check_row(sheet.items() - 1);
|
|
|
|
sheet.force_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//AZZERA_RIGA: metodo che azzera il valore unitario della riga selezionata
|
|
|
|
//(N.B.: le righe con valore unitario nullo verranno eliminate in fase di registrazione)
|
|
|
|
void TRilevamento_prev_msk::azzera_riga(TSheet_field& sheet)
|
|
|
|
{
|
|
|
|
const int nriga = sheet.selected();
|
|
|
|
TToken_string& row = sheet.row(nriga);
|
|
|
|
|
|
|
|
row.add(0, sheet.cid2index(S_QTAORE));
|
|
|
|
|
|
|
|
TMask& msk = sheet.sheet_mask();
|
|
|
|
_qtaore = msk.get_int(S_QTAORE);
|
|
|
|
msk.set(S_QTAORE, 0L);
|
|
|
|
}
|
|
|
|
|
|
|
|
//AZZERA_TUTTO: metodo che azzera il valore unitario di tutte le righe visualizzate sullo sheet
|
|
|
|
//(N.B.: le righe con valore unitario nullo verranno eliminate in fase di registrazione)
|
|
|
|
void TRilevamento_prev_msk::azzera_tutto(TSheet_field& sheet)
|
|
|
|
{
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row)
|
|
|
|
{
|
|
|
|
TToken_string& row = sheet.row(r);
|
|
|
|
row.add(0, sheet.cid2index(S_QTAORE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//REGISTRA: metodo che salva nella tabella di modulo le
|
|
|
|
//righe dello sheet che hanno valore > 0, ed elimina quelle che hanno
|
|
|
|
//vaoler pari a zero, e poi ricarica lo sheet
|
|
|
|
void TRilevamento_prev_msk::registra()
|
|
|
|
{
|
2010-07-29 22:50:40 +00:00
|
|
|
TLocalisamfile file(LF_RILORE);
|
2010-07-24 07:17:32 +00:00
|
|
|
TSheet_field& sheet = sfield(F_SHEET);
|
|
|
|
|
|
|
|
FOR_EACH_SHEET_ROW(sheet, r, row)
|
|
|
|
{
|
|
|
|
TToken_string& riga = *(TToken_string*)row;
|
|
|
|
const char tipora = riga.get_char(sheet.cid2index(S_RISOATT));
|
|
|
|
const TString16 codice = tipora == 'R' ? riga.get(sheet.cid2index(S_CODRIS)) : riga.get(sheet.cid2index(S_CODATT));
|
|
|
|
const TDate& dadata = riga.get(sheet.cid2index(S_DADATA));
|
|
|
|
const TDate& adata = riga.get(sheet.cid2index(S_ADATA));
|
|
|
|
const TString4 tpora = riga.get(sheet.cid2index(S_TPORA));
|
2010-07-31 11:31:19 +00:00
|
|
|
TString80 codcosto;
|
|
|
|
TString80 codcms;
|
|
|
|
TString80 codfase;
|
2010-07-24 07:17:32 +00:00
|
|
|
const int qtaore = riga.get_int(sheet.cid2index(S_QTAORE));
|
|
|
|
const TString& tmp = riga.get(sheet.cid2index(S_COSTO));
|
|
|
|
const real costo(tmp);
|
|
|
|
TString4 mese; mese.format("%02d", adata.month());
|
|
|
|
TRilevamento_ore rilroa('P', tipora, codice, adata.year(), mese, tpora);
|
2010-07-31 11:31:19 +00:00
|
|
|
|
|
|
|
get_row_anal_fields(riga, codcosto, codcms, codfase);
|
|
|
|
|
|
|
|
if(!rilroa.empty() && qtaore == 0)
|
2010-07-24 07:17:32 +00:00
|
|
|
rilroa.remove(file);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRilevamento_ore rilroa;
|
|
|
|
rilroa.set_tipo('P');
|
|
|
|
rilroa.set_tipora(tipora);
|
|
|
|
rilroa.set_codice(codice);
|
|
|
|
rilroa.set_anno(adata.year());
|
|
|
|
rilroa.set_mese(mese);
|
|
|
|
rilroa.set_tpora(tpora);
|
|
|
|
rilroa.set_codcosto(codcosto);
|
|
|
|
rilroa.set_codcms(codcms);
|
|
|
|
rilroa.set_codfase(codfase);
|
|
|
|
rilroa.set_dadata(dadata);
|
|
|
|
rilroa.set_adata(adata);
|
|
|
|
rilroa.set_qtaore(qtaore);
|
|
|
|
rilroa.set_costo(costo);
|
|
|
|
|
|
|
|
int err = rilroa.rewrite_write(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
riempi_sheet();
|
|
|
|
}
|
|
|
|
|
|
|
|
//ON_FIELD_EVENT: metodo che gestisce gli eventi sui vari campi della maschera
|
|
|
|
bool TRilevamento_prev_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
switch (f.dlg())
|
|
|
|
{
|
|
|
|
case DLG_DEFAULT:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
carica_default();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case DLG_CERCA:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
riempi_sheet();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case DLG_NEWREC:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
nuova_riga();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case DLG_SAVEREC:
|
|
|
|
if (e == fe_button)
|
|
|
|
{
|
|
|
|
registra();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DLG_RESET:
|
|
|
|
if(e == fe_button)
|
|
|
|
{
|
|
|
|
TSheet_field& sheet = sfield(F_SHEET);
|
|
|
|
switch(jolly)
|
|
|
|
{
|
|
|
|
case 0: azzera_tutto(sheet); break;
|
|
|
|
case 1: azzera_riga(sheet); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
sheet.force_update();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DLG_CANCEL:
|
|
|
|
if(e == fe_button && jolly == 1)
|
|
|
|
{
|
|
|
|
TSheet_field& sheet = sfield(F_SHEET);
|
|
|
|
TMask& msk = sheet.sheet_mask();
|
|
|
|
const int qtaore = msk.get_int(S_QTAORE);
|
|
|
|
|
|
|
|
if(sheet.selected() == sheet.items() - 1)
|
|
|
|
{
|
|
|
|
sheet.destroy(sheet.items() - 1);
|
|
|
|
sheet.force_update();
|
|
|
|
}
|
|
|
|
else if(_qtaore > 0)
|
|
|
|
{
|
|
|
|
TToken_string& row = sheet.row(sheet.selected());
|
|
|
|
row.add(_qtaore, sheet.cid2index(S_QTAORE));
|
|
|
|
_qtaore = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case F_SHEET:
|
|
|
|
if (e == se_query_add)
|
|
|
|
{
|
|
|
|
send_key(K_SPACE, DLG_NEWREC);
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-01 05:54:40 +00:00
|
|
|
case S_CODRIS:
|
|
|
|
case S_CODATT:
|
|
|
|
case S_DADATA:
|
|
|
|
case S_TPORA:
|
|
|
|
if (e == fe_modify)
|
|
|
|
f.mask().set(S_COSTO, proponi_costo(f.mask()).string());
|
2010-07-24 07:17:32 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRilevamento_prev_msk::esegui() const
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TRilevamento_prev_msk::TRilevamento_prev_msk()
|
|
|
|
: TAutomask("ci2100a")
|
|
|
|
{
|
2010-08-01 05:54:40 +00:00
|
|
|
const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
|
|
|
|
TConfig& ini = ca_config();
|
|
|
|
TSheet_field & s = sfield(F_SHEET);
|
|
|
|
TMask & sm = s.sheet_mask();
|
|
|
|
int y = 3;
|
|
|
|
int sy = 8;
|
|
|
|
short dlg = F_ANAL; // id del primo campo da generare
|
|
|
|
short sdlg = S_CDC1 + 100; // id del primo campo da generare
|
|
|
|
|
|
|
|
_cdc_sid = _cdc_lid = _cms_sid = _cms_lid = _fase_sid = _fase_lid = -1;
|
|
|
|
_scdc_sid = _scdc_lid = _scms_sid = _scms_lid = _sfase_sid = _sfase_lid = -1;
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
const TString& level = ini.get("Level", NULL, i+1); // Legge il livello 1 o 2
|
|
|
|
|
|
|
|
if (level == "CDC") // Crea centro di costo
|
|
|
|
{
|
|
|
|
if (fasinfo.parent() == LF_CDC)
|
|
|
|
{
|
|
|
|
int h = ca_multilevel_code_info(LF_CDC).levels();
|
|
|
|
const int h1 = ca_create_fields_compact(*this, 0, LF_FASI, 2, y, dlg, dlg + 100);
|
|
|
|
y += 2;
|
|
|
|
_cdc_sid = dlg;
|
|
|
|
_cdc_lid = dlg + h - 1;
|
|
|
|
_fase_sid = _cdc_lid + 1;
|
|
|
|
_fase_lid = dlg + h1 - 1;
|
|
|
|
dlg += h1;
|
|
|
|
const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy, sdlg, sdlg + 50);
|
|
|
|
sy += 2;
|
|
|
|
_scdc_sid = sdlg;
|
|
|
|
_scdc_lid = sdlg + h - 1;
|
|
|
|
_sfase_sid = _scdc_lid + 1;
|
|
|
|
_sfase_lid = sdlg + sh - 1;
|
|
|
|
sdlg += sh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int h = ca_create_fields_compact(*this, 0, LF_CDC, 2, y++, dlg, dlg + 100);
|
|
|
|
_cdc_sid = dlg;
|
|
|
|
_cdc_lid = dlg + h - 1;
|
|
|
|
dlg += h;
|
|
|
|
const int sh = ca_create_fields_compact(sm, 0, LF_CDC, 2, sy++, sdlg, sdlg + 50);
|
|
|
|
_scdc_sid = sdlg;
|
|
|
|
_scdc_lid = sdlg + sh - 1;
|
|
|
|
sdlg += h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (level == "CMS") // Crea commessa
|
|
|
|
{
|
|
|
|
if (fasinfo.parent() == LF_COMMESSE)
|
|
|
|
{
|
|
|
|
int h = ca_multilevel_code_info(LF_COMMESSE).levels();
|
|
|
|
const int h1 = ca_create_fields_compact(*this, 0, LF_FASI, 2, y, dlg, dlg + 100);
|
|
|
|
y += 2;
|
|
|
|
_cms_sid = dlg;
|
|
|
|
_cms_lid = dlg + h - 1;
|
|
|
|
_fase_sid = _cms_lid + 1;
|
|
|
|
_fase_lid = dlg + h1 - 1;
|
|
|
|
dlg += h1;
|
|
|
|
const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy, sdlg, sdlg + 50);
|
|
|
|
sy += 2;
|
|
|
|
_scms_sid = sdlg;
|
|
|
|
_scms_lid = sdlg + h - 1;
|
|
|
|
_sfase_sid = _scms_lid + 1;
|
|
|
|
_sfase_lid = sdlg + sh - 1;
|
|
|
|
sdlg += sh;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const int h = ca_create_fields_compact(*this, 0, LF_COMMESSE, 2, y++, dlg, dlg + 100);
|
|
|
|
_cms_sid = dlg;
|
|
|
|
_cms_lid = dlg + h - 1;
|
|
|
|
dlg += h;
|
|
|
|
const int sh = ca_create_fields_compact(sm, 0, LF_COMMESSE, 2, sy++, sdlg, sdlg + 50);
|
|
|
|
_scms_sid = sdlg;
|
|
|
|
_scms_lid = sdlg + sh - 1;
|
|
|
|
sdlg += sh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
|
|
|
|
{
|
|
|
|
const int h = ca_create_fields_compact(*this, 0, LF_FASI, 2, y++, dlg, dlg + 100);
|
|
|
|
_fase_sid = dlg;
|
|
|
|
_fase_lid = dlg + h - 1;
|
|
|
|
dlg += h;
|
|
|
|
const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy++, sdlg, sdlg + 50);
|
|
|
|
_sfase_sid = sdlg;
|
|
|
|
_sfase_lid = sdlg + sh - 1;
|
|
|
|
sdlg += h;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (short id = S_CDC12 + 100; id >= S_CDC1 + 100; id--)
|
|
|
|
{
|
|
|
|
const int pos = sm.id2pos(id);
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
TMask_field& f = sm.fld(pos);
|
|
|
|
const int size = f.size();
|
|
|
|
TString prompt = f.prompt();
|
|
|
|
|
|
|
|
if (prompt.blank())
|
|
|
|
prompt = ((TEditable_field &)f).get_warning();
|
|
|
|
s.set_column_header(id, prompt);
|
|
|
|
s.set_column_justify(id, f.is_kind_of(CLASS_REAL_FIELD));
|
|
|
|
s.set_column_width(id, (max(3+size, prompt.len()+1)) * CHARX);
|
|
|
|
s.enable_column(id);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
s.delete_column(id);
|
|
|
|
}
|
2010-07-24 07:17:32 +00:00
|
|
|
_qtaore = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////
|
|
|
|
//// CLASSE TRilevamento_prev_app ////
|
|
|
|
////////////////////////////////////////////
|
|
|
|
|
|
|
|
//classe TRilevamento_prev_app
|
|
|
|
class TRilevamento_prev_app : public TSkeleton_application
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void main_loop();
|
|
|
|
};
|
|
|
|
|
|
|
|
void TRilevamento_prev_app::main_loop()
|
|
|
|
{
|
|
|
|
TRilevamento_prev_msk msk;
|
|
|
|
while (msk.run() != K_QUIT)
|
|
|
|
msk.esegui();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ci2100(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
TRilevamento_prev_app a;
|
|
|
|
a.run (argc, argv, TR("Rilevamento Ore Preventivo"));
|
|
|
|
return TRUE;
|
|
|
|
}
|