Files correlati : ca0.exe Ricompilazione Demo : [ ] Commento : Terminata prima versione inserimento tabelle di riclassificazione git-svn-id: svn://10.65.10.50/trunk@12599 c028cbd2-c16b-5b4b-a496-9718f37d4682
460 lines
12 KiB
C++
Executable File
460 lines
12 KiB
C++
Executable File
#include <automask.h>
|
|
#include <recarray.h>
|
|
#include <relapp.h>
|
|
|
|
#include "ca0800a.h"
|
|
#include "calib01.h"
|
|
|
|
void append_select_clause(ostream& out, int level, int logic)
|
|
{
|
|
TString str;
|
|
if (logic == LF_PCON)
|
|
{
|
|
switch (level)
|
|
{
|
|
case 0: str = "CONTO==\"\""; break;
|
|
case 1: str = "SOTTOCONTO==\"\""; break;
|
|
default: break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const TMultilevel_code_info& mci = multilevel_code_info(logic);
|
|
const TFieldref& key = mci.fieldref(level);
|
|
|
|
str << "STR(";
|
|
if (level > 1)
|
|
str << "(NUM(LEN(" << key.name() << "))>" << key.from() << ')'; // SE LEN(CODCONTO)>=4
|
|
if (level < mci.levels())
|
|
{
|
|
if (level > 1) str << "&&";
|
|
str << "(NUM(LEN(" << key.name() << "))<=" << key.to() << ')'; // SE LEN(CODCONTO)<=7
|
|
}
|
|
str << ')';
|
|
}
|
|
if (str.not_empty())
|
|
out << " SE " << str << endl;
|
|
}
|
|
|
|
void append_run_clause(ostream& out, int logicnum)
|
|
{
|
|
const TRectype r(logicnum);
|
|
TString app; r.get_relapp(app);
|
|
if (app.not_empty())
|
|
out << "AD RU " << app << endl;
|
|
}
|
|
|
|
void create_browse1(TEdit_field& kfld, int level, int logic, short key_id, short des_id)
|
|
{
|
|
const TMultilevel_code_info& mci = multilevel_code_info(logic);
|
|
|
|
TFilename tmp; tmp.temp();
|
|
ofstream out(tmp);
|
|
|
|
out << "US " << logic << endl;
|
|
append_select_clause(out, level, logic);
|
|
append_run_clause(out, logic);
|
|
|
|
for (int i = 0; i <= level; i++)
|
|
{
|
|
const TString& picture = mci.picture(i);
|
|
const TString& prompt = mci.prompt(i);
|
|
const TFieldref& field = mci.fieldref(i);
|
|
const int length = field.to() - field.from();
|
|
out << "IN " << field << ' ' << (key_id+i) << endl;
|
|
out << "DI \"" << prompt;
|
|
if (length > prompt.len())
|
|
out << '@' << length;
|
|
out << "\" " << field << endl;
|
|
out << "OU " << (key_id+i) << ' ' << field << endl;
|
|
}
|
|
const TFieldref& field = mci.fieldref(0, 2);
|
|
out << "DI \"" << TR("Descrizione") << "@50\" " << field << endl;
|
|
out << "OU " << (des_id+level) << ' ' << field << endl;
|
|
out << "CH RE" << endl;
|
|
//out << "FI " << mci.fieldref(level) << endl;
|
|
out << "EN" << endl;
|
|
out.close();
|
|
|
|
TScanner scan(tmp);
|
|
while (scan.pop() != "EN")
|
|
kfld.parse_item(scan);
|
|
|
|
xvt_fsys_removefile(tmp);
|
|
}
|
|
|
|
void create_browse2(TEdit_field& kfld, int level, int logic, short key_id, short des_id)
|
|
{
|
|
const TMultilevel_code_info& mci = multilevel_code_info(logic);
|
|
|
|
const TFieldref& field = mci.fieldref(0, 2);
|
|
TString str2; str2 << field;
|
|
|
|
TFilename tmp; tmp.temp();
|
|
ofstream out(tmp);
|
|
out << "US " << logic << " KE 2" << endl;
|
|
append_select_clause(out, level, logic);
|
|
append_run_clause(out, logic);
|
|
|
|
out << "IN " << str2 << ' ' << kfld.dlg() << endl;
|
|
out << "DI \"" << TR("Descrizione") << "@50\" " << str2 << endl;
|
|
out << "OU " << kfld.dlg() << ' ' << str2 << endl;
|
|
|
|
for (int i = 0; i <= level; i++)
|
|
{
|
|
const TString& picture = mci.picture(i);
|
|
const TString& prompt = mci.prompt(i);
|
|
const TFieldref& field = mci.fieldref(i);
|
|
const int length = field.to() - field.from();
|
|
out << "DI \"" << prompt;
|
|
if (length > prompt.len())
|
|
out << '@' << length;
|
|
out << "\" " << field << endl;
|
|
out << "OU " << (key_id+i) << ' ' << field << endl;
|
|
}
|
|
out << "CH NO" << endl;
|
|
out << "EN" << endl;
|
|
out.close();
|
|
|
|
TScanner scan(tmp);
|
|
while (scan.pop() != "EN")
|
|
kfld.parse_item(scan);
|
|
|
|
xvt_fsys_removefile(tmp);
|
|
}
|
|
|
|
|
|
int create_fields(TMask& msk, int logicnum, int x, int y,
|
|
short key_id, short des_id)
|
|
{
|
|
const TMultilevel_code_info& mci = multilevel_code_info(logicnum);
|
|
|
|
int maxkeylen = 0, maxdeslen = 0;
|
|
for (int level = 0; level < mci.levels(); level++)
|
|
{
|
|
const TString& prompt = mci.prompt(level);
|
|
const TString& picture = mci.picture(level);
|
|
const int keylen = picture.len();
|
|
const int deslen = prompt.len();
|
|
if (keylen > maxkeylen) maxkeylen = keylen;
|
|
if (deslen > maxdeslen) maxdeslen = deslen;
|
|
}
|
|
|
|
maxdeslen++;
|
|
const int tab0 = x;
|
|
const int tab1 = tab0 + maxdeslen + maxkeylen + 4;
|
|
|
|
for (int i = 0; i < mci.levels(); i++)
|
|
{
|
|
const short kid = key_id+i;
|
|
|
|
const TString& picture = mci.picture(i);
|
|
TString80 prompt = mci.prompt(i);
|
|
prompt.left_just(maxdeslen);
|
|
|
|
const char* flags = picture[0] == '0' ? "BUZ" : "BU";
|
|
TEdit_field* kfld = NULL;
|
|
if (picture.find('A') < 0) // Numeric
|
|
kfld = &msk.add_number(kid, 0, prompt, tab0, y+i, picture.len(), flags);
|
|
else
|
|
kfld = &msk.add_string(kid, 0, prompt, tab0, y+i, picture.len(), flags);
|
|
create_browse1(*kfld, i, logicnum, key_id, des_id);
|
|
kfld->set_group(2);
|
|
|
|
const short did = des_id+i;
|
|
TEdit_field& dfld = msk.add_string(did, 0, "", tab1, y+i, 50, "B", 72+tab0-tab1);
|
|
create_browse2(dfld, i, logicnum, key_id, des_id);
|
|
dfld.set_group(2);
|
|
}
|
|
|
|
return mci.levels();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// 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 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");
|
|
|
|
create_fields(sm, LF_CDC, 1, 1, 202, 252);
|
|
create_fields(sm, LF_COMMESSE, 1, 5, 206, 256);
|
|
create_fields(sm, LF_FASI, 1, 9, 210, 260);
|
|
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")
|
|
{
|
|
create_fields(*this, LF_CDC, 2, 5, F_CODCDC_1, F_DESCDC_1);
|
|
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) 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) 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);
|
|
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);
|
|
|
|
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));
|
|
}
|
|
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;
|
|
}
|
|
|