f99184fbe6
Files correlati : Ricompilazione Demo : [ ] Commento :un sacco di modifiche su ribaltamenti, tabelle ripartizioni, conversione ecc. git-svn-id: svn://10.65.10.50/trunk@12733 c028cbd2-c16b-5b4b-a496-9718f37d4682
301 lines
7.1 KiB
C++
Executable File
301 lines
7.1 KiB
C++
Executable File
#include <automask.h>
|
|
#include <recarray.h>
|
|
#include <relapp.h>
|
|
|
|
#include "ca0800a.h"
|
|
#include "calib01.h"
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TRiparti_msk
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TRiparti_msk : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
void create_sheet();
|
|
|
|
public:
|
|
TRiparti_msk();
|
|
};
|
|
|
|
bool TRiparti_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_TIPORIP:
|
|
if (e == fe_init || e == fe_modify)
|
|
{
|
|
TSheet_field& sf = sfield(F_SHEET);
|
|
TMask& sm = sf.sheet_mask();
|
|
const int t = atoi(o.get());
|
|
sm.show(101, t < 2); // Percentuale
|
|
sm.show(201, t == 2); // Parti
|
|
sm.enable(101, t != 1);
|
|
sf.enable_column(0, t != 1);
|
|
sf.force_update();
|
|
}
|
|
if (e == fe_close && atoi(o.get()) == 0)
|
|
{
|
|
TSheet_field& sf = sfield(F_SHEET);
|
|
real tot;
|
|
FOR_EACH_SHEET_ROW(sf, i, row)
|
|
tot += real(row->get(0));
|
|
tot.round(2);
|
|
if (tot != CENTO)
|
|
return error_box(TR("Il totale delle percentuali di riparto deve essere 100"));
|
|
}
|
|
break;
|
|
case F_SHEET:
|
|
if (e == fe_init)
|
|
{
|
|
TSheet_field& sf = sfield(F_SHEET);
|
|
TMask& sm = sf.sheet_mask();
|
|
const bool on = get(F_TIPO)[0] != 'C';
|
|
for (short id = 202; id < 214; id++)
|
|
{
|
|
if (sm.id2pos(id) > 0)
|
|
{
|
|
sf.enable_column(id, on);
|
|
sm.enable(id, on);
|
|
}
|
|
if (sm.id2pos(id+50) > 0)
|
|
sm.enable(id+50, on);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
if (e == fe_modify || e == fe_close)
|
|
{
|
|
const short id = o.dlg();
|
|
int level = -1;
|
|
if (id >= 202 && id <= 217)
|
|
{
|
|
level = (o.dlg()-202) % 4;
|
|
} else
|
|
if (id >= F_CODCDC_1 && id <= F_CODCDC_4)
|
|
{
|
|
level = id-F_CODCDC_1;
|
|
} else
|
|
if (id >= F_CODCMS_1 && id <= F_CODCMS_4)
|
|
{
|
|
level = id-F_CODCMS_1;
|
|
}
|
|
if (level >= 0)
|
|
{
|
|
TEdit_field& fld = (TEdit_field&)o;
|
|
return ca_test_multilevel_field(fld, level);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TRiparti_msk::create_sheet()
|
|
{
|
|
TSheet_field& sf = sfield(F_SHEET);
|
|
TMask& sm = sf.sheet_mask();
|
|
|
|
sm.hide(-1);
|
|
|
|
TConfig ini(CONFIG_DITTA, "ca");
|
|
const bool use_pdc = ini.get_bool("UsePdcc");
|
|
|
|
ca_create_fields(sm, LF_CDC, 1, 1, 202, 252);
|
|
ca_create_fields(sm, LF_COMMESSE, 1, 5, 206, 256);
|
|
ca_create_fields(sm, LF_FASI, 1, 9, 210, 260);
|
|
ca_create_fields(sm, use_pdc ? LF_PCON : LF_PCONANA, 1, 13, 214, 264);
|
|
|
|
for (short id = 217; id >= 202; id--)
|
|
{
|
|
const int pos = sm.id2pos(id);
|
|
if (pos >= 0)
|
|
{
|
|
TMask_field& f = sm.fld(pos);
|
|
const int size = f.size();
|
|
const TString& prompt = f.prompt();
|
|
sf.set_column_header(id, prompt);
|
|
sf.set_column_justify(id, f.is_kind_of(CLASS_REAL_FIELD));
|
|
sf.set_column_width(id, (max(3+size, prompt.len()+1)) * CHARX);
|
|
}
|
|
else
|
|
{
|
|
sf.delete_column(id);
|
|
}
|
|
}
|
|
}
|
|
|
|
TRiparti_msk::TRiparti_msk() : TAutomask("ca0800a")
|
|
{
|
|
ca_create_fields(*this, LF_CDC, 2, 5, F_CODCDC_1, F_DESCDC_1);
|
|
ca_create_fields(*this, LF_COMMESSE, 2, 11, F_CODCMS_1, F_DESCMS_1);
|
|
create_sheet();
|
|
}
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TRiparti_app
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TRiparti_app : public TRelation_application
|
|
{
|
|
TRelation* _rel;
|
|
TRiparti_msk* _msk;
|
|
|
|
const TString& somma_campi(TToken_string& row, int first, bool pdc = false) const;
|
|
void write_rows();
|
|
|
|
void spezza_campo(const TString& str, TToken_string& row, int first) const;
|
|
void read_rows();
|
|
|
|
protected:
|
|
virtual bool user_create();
|
|
virtual bool user_destroy();
|
|
virtual int write(const TMask& m);
|
|
virtual int rewrite(const TMask& m);
|
|
virtual int read(TMask& m);
|
|
|
|
virtual TRelation* get_relation() const { return _rel; }
|
|
virtual TMask* get_mask(int) { return _msk; }
|
|
};
|
|
|
|
const TString& TRiparti_app::somma_campi(TToken_string& row, int first, bool pdc) const
|
|
{
|
|
TSheet_field& sheet = _msk->sfield(F_SHEET);
|
|
TMask& m = sheet.sheet_mask();
|
|
|
|
const short id = 201 + first;
|
|
|
|
TString& str = get_tmp_string(20);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
TString80 token = row.get(first+i);
|
|
if (m.id2pos(id+i) < 0)
|
|
break;
|
|
const TEdit_field& fld = m.efield(id+i);
|
|
if (pdc)
|
|
token.right_just(fld.size(), '0');
|
|
else
|
|
token.left_just(fld.size());
|
|
str << token;
|
|
}
|
|
return str;
|
|
}
|
|
|
|
void TRiparti_app::spezza_campo(const TString& str, TToken_string& row, int first) const
|
|
{
|
|
TSheet_field& sheet = _msk->sfield(F_SHEET);
|
|
TMask& m = sheet.sheet_mask();
|
|
TString80 token;
|
|
|
|
const short id = 201 + first;
|
|
int start = 0;
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
if (m.id2pos(id+i) < 0)
|
|
break;
|
|
const TEdit_field& fld = m.efield(id+i);
|
|
const int len = fld.size();
|
|
token = str.mid(start, len); token.trim();
|
|
row.add(token, first+i);
|
|
start += len;
|
|
}
|
|
}
|
|
|
|
|
|
void TRiparti_app::write_rows()
|
|
{
|
|
TRectype* key = new TRectype(LF_RRIP);
|
|
const char tipo = _msk->get(F_TIPO)[0];
|
|
key->put("TIPO", tipo);
|
|
key->put("CODICE", _msk->get(tipo == 'B' ? F_CODICE_B : F_CODICE_I));
|
|
|
|
TRecord_array a(LF_RRIP, "NRIGA");
|
|
a.set_key(key);
|
|
|
|
TConfig ini(CONFIG_DITTA, "ca");
|
|
const bool use_pdc = ini.get_bool("UsePdcc");
|
|
|
|
TSheet_field& sheet = _msk->sfield(F_SHEET);
|
|
FOR_EACH_SHEET_ROW(sheet, i, row)
|
|
{
|
|
TRectype& rec = a.row(i+1, true); // Crea una riga nuova
|
|
rec.put("RIPARTO", row->get(0));
|
|
rec.put("CODCOSTO", somma_campi(*row, 1));
|
|
rec.put("CODCMS", somma_campi(*row, 5));
|
|
rec.put("CODFASE", somma_campi(*row, 9));
|
|
rec.put("CODCONTO", somma_campi(*row,13,use_pdc));
|
|
}
|
|
a.rewrite();
|
|
}
|
|
|
|
void TRiparti_app::read_rows()
|
|
{
|
|
TRectype key (LF_RRIP);
|
|
const char tipo = _msk->get(F_TIPO)[0];
|
|
key.put("TIPO", tipo);
|
|
key.put("CODICE", _msk->get(tipo == 'B' ? F_CODICE_B : F_CODICE_I));
|
|
TRecord_array a(key, "NRIGA");
|
|
|
|
TSheet_field& sheet = _msk->sfield(F_SHEET);
|
|
sheet.destroy();
|
|
for (int i = 1; i <= a.rows(); i++)
|
|
{
|
|
const TRectype& rec = a.row(i);
|
|
TToken_string& row = sheet.row(i-1);
|
|
row = rec.get("RIPARTO");
|
|
spezza_campo(rec.get("CODCOSTO"), row, 1);
|
|
spezza_campo(rec.get("CODCMS"), row, 5);
|
|
spezza_campo(rec.get("CODFASE"), row, 9);
|
|
spezza_campo(rec.get("CODCONTO"), row,13);
|
|
}
|
|
}
|
|
|
|
|
|
int TRiparti_app::write(const TMask& m)
|
|
{
|
|
const int err = TRelation_application::write(m);
|
|
if (err == NOERR)
|
|
write_rows();
|
|
return err;
|
|
}
|
|
|
|
int TRiparti_app::rewrite(const TMask& m)
|
|
{
|
|
const int err = TRelation_application::rewrite(m);
|
|
if (err == NOERR)
|
|
write_rows();
|
|
return err;
|
|
}
|
|
|
|
int TRiparti_app::read(TMask& m)
|
|
{
|
|
const int err = TRelation_application::read(m);
|
|
if (err == NOERR)
|
|
read_rows();
|
|
return err;
|
|
}
|
|
|
|
bool TRiparti_app::user_create()
|
|
{
|
|
_rel = new TRelation(LF_RIP);
|
|
_msk = new TRiparti_msk;
|
|
return true;
|
|
}
|
|
|
|
bool TRiparti_app::user_destroy()
|
|
{
|
|
delete _rel;
|
|
delete _msk;
|
|
return true;
|
|
}
|
|
|
|
int ca0800(int argc, char* argv[])
|
|
{
|
|
TRiparti_app a;
|
|
a.run(argc, argv, TR("Tabella di ripartizione"));
|
|
return 0;
|
|
}
|
|
|