Files correlati : db0.exe db0500a.msk db0500b.msk db1.exe db1100a.msk Attivata la descrizione della distinta in immissione Copiato l’articolo nel codice distinta in ricerca Impostata l’unità di misura nella pagina disponibilità dell’esplosione Stampate la descrizione di distinta a e di riga nell’ esplosione git-svn-id: svn://10.65.10.50/branches/R_10_00@24001 c028cbd2-c16b-5b4b-a496-9718f37d4682
1984 lines
53 KiB
C++
Executable File
1984 lines
53 KiB
C++
Executable File
#include "dblib.h"
|
||
|
||
#include <automask.h>
|
||
#include <defmask.h>
|
||
#include <execp.h>
|
||
#include <modaut.h>
|
||
#include <progind.h>
|
||
#include <relapp.h>
|
||
#include <sheet.h>
|
||
#include <treectrl.h>
|
||
#include <toolfld.h>
|
||
#include <utility.h>
|
||
#include <urldefid.h>
|
||
|
||
#include "db0.h"
|
||
#include "../mg/mglib.h"
|
||
#include "../mg/anamag.h"
|
||
|
||
#include "db0500a.h"
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TMov_mask
|
||
///////////////////////////////////////////////////////////
|
||
class TMov_mask : public TAutomask
|
||
{
|
||
TArticolo _art;
|
||
TSheet_field * _sh;
|
||
TAssoc_array _costs;
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
public:
|
||
TAssoc_array & costs() { return _costs;}
|
||
TMov_mask(const char * codice, TSheet_field * s) : TAutomask("db0500d"), _art(codice), _sh(s) {}
|
||
virtual ~TMov_mask() { }
|
||
};
|
||
|
||
bool TMov_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_TIPOVAL:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
TDistinta_tree d;
|
||
|
||
const int tipo = o.mask().get_int(F_TIPOVAL);
|
||
real val;
|
||
real cos;
|
||
real lav;
|
||
|
||
_costs.destroy();
|
||
d.set_root(_sh->mask().get(F_CODICE));
|
||
|
||
switch (tipo)
|
||
{
|
||
case 1 : // Costo
|
||
case 2 : // Complessivo
|
||
{
|
||
const int rows = _sh->items();
|
||
|
||
for (int i = 0; i < rows; i++)
|
||
{
|
||
TToken_string row = _sh->row(i);
|
||
const TString4 tipo = row.get(_sh->cid2index(F_TIPOCOMP));
|
||
if (tipo == "A")
|
||
{
|
||
TArticolo comp(row.get(_sh->cid2index(F_CODART)));
|
||
real qta(row.get(_sh->cid2index(F_EXPR)));
|
||
real calo = comp.get_real(ANAMAG_USER1);
|
||
|
||
if (calo == ZERO) calo = UNO;
|
||
|
||
TString80 strprezzo("#"); strprezzo << comp.codice();
|
||
real prezzo;
|
||
|
||
if (d.exist(strprezzo))
|
||
{
|
||
prezzo = d.get_real(strprezzo);
|
||
_costs.add(comp.codice(), prezzo);
|
||
}
|
||
else
|
||
prezzo = comp.get_real(ANAMAG_ULTCOS1);
|
||
cos += (prezzo * calo) * qta;
|
||
}
|
||
else
|
||
if (tipo == "L")
|
||
{
|
||
TLavorazione lab(row.get(_sh->cid2index(F_CODLAV)));
|
||
real qta(row.get(_sh->cid2index(F_EXPR)));
|
||
|
||
lav += (lab.prezzo() * qta);
|
||
}
|
||
}
|
||
|
||
lav *= (CENTO - o.mask().get_real(F_SCONTO))/CENTO;
|
||
cos += lav;
|
||
val = cos;
|
||
|
||
if (tipo == 2)
|
||
val *= (UNO + _art.get_real(ANAMAG_PERCRIC)/CENTO);
|
||
}
|
||
break;
|
||
case 3 : // Peso + Mandopera a peso
|
||
{
|
||
real peso;
|
||
real val_mat;
|
||
real val_lav;
|
||
const int rows = _sh->items();
|
||
|
||
for (int i = 0; i < rows; i++)
|
||
{
|
||
TToken_string row = _sh->row(i);
|
||
const TString4 tipo = row.get(_sh->cid2index(F_TIPOCOMP));
|
||
if (tipo == "A")
|
||
{
|
||
TArticolo comp(row.get(_sh->cid2index(F_CODART)));
|
||
const TString8 um(row.get(_sh->cid2index(F_UMEXPR)));
|
||
real qta(row.get(_sh->cid2index(F_EXPR)));
|
||
real calo = comp.get_real(ANAMAG_USER1);
|
||
|
||
if (calo == ZERO) calo = UNO;
|
||
|
||
TString80 strprezzo("#"); strprezzo << comp.codice();
|
||
real prezzo;
|
||
|
||
if (d.exist(strprezzo))
|
||
{
|
||
prezzo = d.get_real(strprezzo);
|
||
_costs.add(comp.codice(), prezzo);
|
||
}
|
||
else
|
||
prezzo = comp.get_real(ANAMAG_ULTCOS1);
|
||
val_mat += (prezzo * calo) * qta;
|
||
if (um.starts_with("GR"))
|
||
peso += qta;
|
||
}
|
||
else
|
||
if (tipo == "L")
|
||
{
|
||
TLavorazione lav(row.get(_sh->cid2index(F_CODLAV)));
|
||
|
||
val_lav += lav.prezzo();
|
||
}
|
||
}
|
||
val = val_mat + val_lav * peso * (CENTO - o.mask().get_real(F_SCONTO))/CENTO;
|
||
cos = val ;
|
||
val = cos * (CENTO + _art.get_real(ANAMAG_PERCRIC))/CENTO;
|
||
}
|
||
break;
|
||
case 4 : // Peso + Mandopera a prezzo
|
||
{
|
||
real val_mat;
|
||
real val_lav;
|
||
const int rows = _sh->items();
|
||
|
||
for (int i = 0; i < rows; i++)
|
||
{
|
||
TToken_string row = _sh->row(i);
|
||
const TString4 tipo = row.get(_sh->cid2index(F_TIPOCOMP));
|
||
if (tipo == "A")
|
||
{
|
||
TArticolo comp(row.get(_sh->cid2index(F_CODART)));
|
||
real qta(row.get(_sh->cid2index(F_EXPR)));
|
||
|
||
real calo = comp.get_real(ANAMAG_USER1);
|
||
|
||
if (calo == ZERO) calo = UNO;
|
||
|
||
TString80 strprezzo("#"); strprezzo << comp.codice();
|
||
real prezzo;
|
||
|
||
if (d.exist(strprezzo))
|
||
{
|
||
prezzo = d.get_real(strprezzo);
|
||
_costs.add(comp.codice(), prezzo);
|
||
}
|
||
else
|
||
prezzo = comp.get_real(ANAMAG_ULTCOS1);
|
||
val_mat += (prezzo * calo) * qta;
|
||
}
|
||
else
|
||
if (tipo == "L")
|
||
{
|
||
TLavorazione lav(row.get(_sh->cid2index(F_CODLAV)));
|
||
real qta(row.get(_sh->cid2index(F_EXPR)));
|
||
|
||
val_lav += lav.prezzo() * qta;
|
||
}
|
||
}
|
||
val = val_mat + val_lav * (CENTO - o.mask().get_real(F_SCONTO))/CENTO;
|
||
cos = val ;
|
||
val = cos * (CENTO + _art.get_real(ANAMAG_PERCRIC))/CENTO;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
o.mask().set(F_PREZZOM, cos.string());
|
||
o.mask().set(F_PREZZOV, val.string());
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDistinta_app
|
||
///////////////////////////////////////////////////////////
|
||
class TQuery_mask;
|
||
class TDistinta_mask;
|
||
|
||
class TDistinta_app : public TRelation_application
|
||
{
|
||
TDistinta_tree* _tree;
|
||
TRelation* _therel;
|
||
TQuery_mask* _querymask;
|
||
TDistinta_mask* _themask;
|
||
int _mode;
|
||
|
||
bool parms2rel(const TMask& m);
|
||
|
||
protected:
|
||
virtual void init_insert_mode(TMask &);
|
||
virtual bool user_create();
|
||
virtual bool user_destroy();
|
||
virtual TRelation* get_relation() const { return _therel; }
|
||
virtual bool changing_mask(int mode);
|
||
virtual TMask* get_mask(int mode);
|
||
virtual void init_query_mode(TMask& m);
|
||
virtual int read(TMask& m);
|
||
virtual int write(const TMask& m);
|
||
virtual int rewrite(const TMask& m);
|
||
virtual bool remove();
|
||
virtual void ini2sheet(TConfig& ini, TSheet_field &sheet);
|
||
virtual void sheet2ini(TSheet_field &sheet,TConfig& ini);
|
||
|
||
void load_memo(TMask& m, TToken_string& memo);
|
||
|
||
void remove_desc(TMask& m);
|
||
|
||
public:
|
||
TRelation& relation() { return *_therel; }
|
||
};
|
||
|
||
TDistinta_app& app()
|
||
{ return (TDistinta_app&)main_app();}
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDistinta_sheet
|
||
///////////////////////////////////////////////////////////
|
||
|
||
|
||
class TDistinta_sheet : public TSheet
|
||
{
|
||
TCodgiac_livelli _livgiac;
|
||
TArray _data;
|
||
|
||
protected:
|
||
virtual void get_row(long n, TToken_string& row);
|
||
virtual long get_items() const { return _data.items(); }
|
||
|
||
public:
|
||
TArray& rows_array() { return _data; }
|
||
TDistinta_sheet(int numlev);
|
||
virtual ~TDistinta_sheet() { }
|
||
};
|
||
|
||
void TDistinta_sheet::get_row(long n, TToken_string& row)
|
||
{
|
||
const TRiga_esplosione& re = (const TRiga_esplosione&)_data[int(n)];
|
||
row.cut(0);
|
||
row.add(re.tipo());
|
||
row.add(re.articolo());
|
||
if (_livgiac.enabled(1))
|
||
row.add(_livgiac.unpack_grpcode(re.giacenza(),1));
|
||
if (_livgiac.enabled(2))
|
||
row.add(_livgiac.unpack_grpcode(re.giacenza(),2));
|
||
if (_livgiac.enabled(3))
|
||
row.add(_livgiac.unpack_grpcode(re.giacenza(),3));
|
||
if (_livgiac.enabled(4))
|
||
row.add(_livgiac.unpack_grpcode(re.giacenza(),4));
|
||
row.add(re.um());
|
||
row.add(re.val().string(0, 5));
|
||
row.add(re.livello());
|
||
row.add(re.ordinamento());
|
||
}
|
||
|
||
TDistinta_sheet::TDistinta_sheet(int numlev)
|
||
: TSheet(-1, -1, 76, 20, TR("Esplosione"),
|
||
numlev == 4 ? HR("Tipo|Codice@20|Liv.1@10|Liv.2@6|Liv.3@6|Liv.4@6|UM|Quantita'@18R|Liv.@R|Sort@8R") :
|
||
numlev == 3 ? HR("Tipo|Codice@20|Liv.1@10|Liv.2@6|Liv.3@6|UM|Quantita'@18R|Liv.@R|Sort@8R") :
|
||
numlev == 2 ? HR("Tipo|Codice@20|Liv.1@10|Liv.2@6|UM|Quantita'@18R|Liv.@R|Sort@8R") :
|
||
numlev == 1 ? HR("Tipo|Codice@20|Liv.1@10|UM|Quantita'@18R|Liv.@R|Sort@8R") :
|
||
HR("Tipo|Codice@20|UM|Quantita'@18R|Liv.@R|Sort@8R") )
|
||
{
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TQuery_mask
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TQuery_mask : public TAutomask
|
||
{
|
||
TDistinta_tree& _tree;
|
||
TToken_string _curr;
|
||
|
||
TCodart_livelli _livart;
|
||
TCodgiac_livelli _livgiac;
|
||
|
||
bool redraw_tree(TField_event e);
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
void create_browse1(TEdit_field& kfld, int level, short key_id) const;
|
||
void create_browse2(TEdit_field& kfld, int level, short key_id, short des_id) const ;
|
||
bool ask_new_code(const TCodice_articolo& oldcode, TCodice_articolo& newcode) const;
|
||
|
||
bool are_similar(const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const;
|
||
bool generate_subcode(const TCodice_articolo& oldcode, const TCodice_articolo& newcode,
|
||
const TCodice_articolo& oldsub, TCodice_articolo& newsub) const;
|
||
bool copy_article_rows(const int lfile, const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const;
|
||
bool copy_article(const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const;
|
||
bool copy_distinct(const TCodice_articolo& oldcode, const TCodice_articolo& newcode, bool recursive);
|
||
|
||
public:
|
||
const TToken_string& curr() const { return _curr; }
|
||
bool restart_tree();
|
||
|
||
TQuery_mask(TDistinta_tree& tree);
|
||
virtual ~TQuery_mask() { }
|
||
};
|
||
|
||
void TQuery_mask::create_browse1(TEdit_field& kfld, int level, short key_id) const
|
||
{
|
||
TFilename tmp; tmp.temp();
|
||
ofstream out(tmp);
|
||
|
||
out << "USE GCA" << endl; //usa la tabella dei livelli articolo
|
||
|
||
const short id = key_id + level - 1;
|
||
const TString& prompt = _livart.name(level);
|
||
const TString& picture = _livart.picture(level);
|
||
out << "IN CODTAB[1,1] \"" << level << "\"" << endl;
|
||
out << "IN CODTAB[2,0] " << id << endl;
|
||
out << "DI \"" << prompt;
|
||
const int length = _livart.code_length(level);
|
||
if (length > prompt.len())
|
||
out << '@' << length;
|
||
out << "\" CODTAB[2,0]" << endl;
|
||
out << "DI \"" << TR("Descrizione") << "@50\" S0" << endl;
|
||
out << "OU " << id << " CODTAB[2,0]" << endl;
|
||
out << "OU " << 300 + level << " S0" << endl;
|
||
if (level == 1)
|
||
out << "CH RE" << endl;
|
||
else
|
||
out << "CH NO" << endl;
|
||
out << "EN" << endl;
|
||
out.close();
|
||
|
||
TScanner scan(tmp);
|
||
while (scan.pop() != "EN")
|
||
kfld.parse_item(scan);
|
||
|
||
tmp.fremove();
|
||
}
|
||
|
||
void TQuery_mask::create_browse2(TEdit_field& kfld, int level, short key_id, short des_id) const
|
||
{
|
||
TFilename tmp; tmp.temp();
|
||
ofstream out(tmp);
|
||
|
||
out << "USE GCA KE 2 SELECT CODTAB[1,1]=='" << level << "'" << endl; //cerca per descrizione
|
||
|
||
const short id = des_id + level - 1;
|
||
out << "IN S0 " << id << endl;
|
||
out << "DI \"" << TR("Descrizione") << "@50\" S0" << endl;
|
||
|
||
const TString& prompt = _livart.name(level);
|
||
out << "DI \"" << prompt;
|
||
const int length = _livart.code_length(level);
|
||
if (length > prompt.len())
|
||
out << '@' << length;
|
||
out << "\" CODTAB[2,0]" << endl;
|
||
|
||
out << "CO OU " << (key_id + level -1) << endl;
|
||
if (level == 1)
|
||
out << "CH RE" << endl;
|
||
else
|
||
out << "CH NO" << endl;
|
||
out << "EN" << endl;
|
||
out.close();
|
||
|
||
TScanner scan(tmp);
|
||
while (scan.pop() != "EN")
|
||
kfld.parse_item(scan);
|
||
|
||
tmp.fremove();
|
||
}
|
||
|
||
bool TQuery_mask::ask_new_code(const TCodice_articolo& oldcode, TCodice_articolo& newcode) const
|
||
{
|
||
if (newcode.blank())
|
||
newcode = oldcode;
|
||
|
||
const int last_level = _livart.last_level();
|
||
const int width = last_level > 0 ? _livart.packed_length(last_level)+last_level*3+16 : 38;
|
||
TMask m(TR("Copia articolo/distinta"), 1, width, 5);
|
||
m.add_button_tool(DLG_OK, "", TOOL_OK);
|
||
m.add_button_tool(DLG_CANCEL, "", TOOL_CANCEL);
|
||
m.add_static(DLG_NULL, 0, PR("Vecchio codice "), 1, 1);
|
||
m.add_static(DLG_NULL, 0, PR("Nuovo codice "), 1, 2);
|
||
int tab0 = 16;
|
||
|
||
if (last_level > 0)
|
||
{
|
||
int i = 0;
|
||
for (i = 1; i <= last_level; i++) //cicla su tutti i livelli del codart abilitati
|
||
{
|
||
const TString& picture = _livart.picture(i);
|
||
for (int y = 0; y < 2; y++)
|
||
{
|
||
if (y == 1)
|
||
{
|
||
TString4 flags = "BU";
|
||
if (picture[0] == '0')
|
||
flags << 'Z';
|
||
TEdit_field& kfld = m.add_string(200+i, 0, "", tab0, y+1, picture.len(), flags);
|
||
create_browse1(kfld, i, 201);
|
||
}
|
||
else
|
||
m.add_string(100+i, 0, "", tab0, y+1, picture.len(), "D");
|
||
}
|
||
m.set(100+i, _livart.unpack_grpcode(oldcode, i));
|
||
m.set(200+i, _livart.unpack_grpcode(newcode, i));
|
||
|
||
tab0 += picture.len()+3;
|
||
}
|
||
for (i = 1; i <= last_level; i++)
|
||
{
|
||
TEdit_field& dfld = m.add_string(300 + i, 0, "", 200, 2, 50, "", 50);
|
||
|
||
create_browse2(dfld, i, 201, 301);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m.add_string(101, 0, "", tab0, 1, 20, "D");
|
||
m.add_string(201, 0, "", tab0, 2, 20, "U");
|
||
m.set(101, oldcode);
|
||
m.set(201, newcode);
|
||
}
|
||
|
||
if (m.run() == K_ENTER)
|
||
{
|
||
if (last_level > 0)
|
||
_livart.pack_maskgrpcodes(newcode, m, 201, last_level);
|
||
else
|
||
newcode = m.get(201);
|
||
}
|
||
|
||
return newcode.full() && newcode != oldcode;
|
||
}
|
||
|
||
bool TQuery_mask::copy_article_rows(const int lfile, const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const
|
||
{
|
||
bool ok = true;
|
||
|
||
// NRIGA vale per tutte le righe dei file connessi ad ANAMAG: CODCORR, DESLIN e UMART
|
||
TRecord_array um(lfile, "NRIGA");
|
||
um.renum_key(ANAMAG_CODART, oldcode);
|
||
um.read(um.key());
|
||
if (um.rows() > 0)
|
||
{
|
||
um.renum_key(ANAMAG_CODART, newcode);
|
||
ok = um.write() == NOERR;
|
||
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
bool TQuery_mask::copy_article(const TCodice_articolo& oldcode, const TCodice_articolo& newcode) const
|
||
{
|
||
TLocalisamfile anamag(LF_ANAMAG);
|
||
anamag.put(ANAMAG_CODART, newcode);
|
||
bool ok = anamag.read() != NOERR;
|
||
if (ok)
|
||
{
|
||
anamag.put(ANAMAG_CODART, oldcode);
|
||
ok = anamag.read() == NOERR;
|
||
if (ok)
|
||
{
|
||
anamag.put(ANAMAG_CODART, newcode);
|
||
ok = anamag.write() == NOERR;
|
||
if (ok)
|
||
{
|
||
copy_article_rows(LF_CODCORR, oldcode, newcode);
|
||
copy_article_rows(LF_DESLIN, oldcode, newcode);
|
||
copy_article_rows(LF_UMART, oldcode, newcode);
|
||
}
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
// Confornta due codici articolo diversi e dice che sono simili
|
||
// solo se hanno una parte dei sottocodici uguali
|
||
bool TQuery_mask::are_similar(const TCodice_articolo& oldcode,
|
||
const TCodice_articolo& newcode) const
|
||
{
|
||
const int last = _livart.last_level();
|
||
if (last <= 1)
|
||
return false;
|
||
|
||
int uguali = 0, diversi = 0;
|
||
for (int l = 1; l <= last; l++)
|
||
{
|
||
const TString oldstr = _livart.unpack_grpcode(oldcode, l);
|
||
if (oldstr.empty()) // Ultimo pezzo facoltativo?
|
||
break;
|
||
const TString newstr = _livart.unpack_grpcode(newcode, l);
|
||
if (oldstr == newstr)
|
||
uguali++;
|
||
else
|
||
diversi++;
|
||
}
|
||
return (diversi > 0) && (uguali > 0); // (uguali*diversi)!=0
|
||
}
|
||
|
||
bool TQuery_mask::generate_subcode(const TCodice_articolo& oldcode,
|
||
const TCodice_articolo& newcode,
|
||
const TCodice_articolo& oldsub,
|
||
TCodice_articolo& newsub) const
|
||
{
|
||
newsub = oldsub;
|
||
const int last = _livart.last_level();
|
||
for (int l = 1; l <= last; l++)
|
||
{
|
||
const TString oldstr = _livart.unpack_grpcode(oldcode, l);
|
||
if (oldstr.empty()) // Ultimo pezzo facoltativo?
|
||
break;
|
||
const TString newstr = _livart.unpack_grpcode(newcode, l);
|
||
const TString substr = _livart.unpack_grpcode(oldsub, l);
|
||
if (oldstr != newstr && oldstr == substr)
|
||
newsub.overwrite(newstr, _livart.code_start(l)-1);
|
||
}
|
||
return newsub != oldsub;
|
||
}
|
||
|
||
bool TQuery_mask::copy_distinct(const TCodice_articolo& oldcode,
|
||
const TCodice_articolo& newcode, bool recursive)
|
||
{
|
||
bool ok = oldcode.full() && newcode.full() && oldcode != newcode;
|
||
if (ok)
|
||
{
|
||
TLocalisamfile dist(LF_DIST);
|
||
dist.put("CODDIST", oldcode);
|
||
ok = dist.read() == NOERR;
|
||
if (ok)
|
||
{
|
||
// Se la vecchia distinta corrisponde ad un articolo di magazzino
|
||
// anche la nuova avra' il suo nuovo articolo corrispondente
|
||
const TRectype& oldartrec = cache().get(LF_ANAMAG, oldcode);
|
||
TRectype newartrec = cache().get(LF_ANAMAG, newcode);
|
||
if (!oldartrec.empty() && newartrec.empty())
|
||
{
|
||
copy_article(oldcode, newcode);
|
||
cache().discard(LF_ANAMAG, newcode); // Annulla record vuoto in cache
|
||
newartrec = cache().get(LF_ANAMAG, newcode);
|
||
}
|
||
|
||
dist.put("CODDIST", newcode);
|
||
if (!newartrec.empty())
|
||
{
|
||
// Copio la descrizione dall'articolo collegato
|
||
dist.put("DESCR", newartrec.get("DESCR"));
|
||
// Determino l'unita' di misura predefinita
|
||
TToken_string umkey;
|
||
umkey << newcode << "|1";
|
||
const TString& um = cache().get(LF_UMART, umkey, "UM");
|
||
dist.put("UM", um);
|
||
}
|
||
else
|
||
{
|
||
dist.put("ARTPROD", " ");
|
||
const TRectype& lavrec = cache().get("LAV",newcode);
|
||
if (!lavrec.empty())
|
||
dist.put("DESCR",lavrec.get("S0"));
|
||
}
|
||
|
||
const int err = dist.write();
|
||
if (err != NOERR)
|
||
{
|
||
if (err == _isreinsert)
|
||
ok = error_box(FR("La distinta '%s' e' gia' presente"), (const char*)newcode);
|
||
else
|
||
ok = error_box(FR("Errore %d durante la registrazione della distinta '%s'"), err, (const char*)newcode);
|
||
}
|
||
}
|
||
else
|
||
ok = error_box(FR("Il codice '%s' non corrisponde ad una distinta valida"), (const char*)oldcode);
|
||
}
|
||
|
||
if (ok)
|
||
{
|
||
// copia le righe di distinta
|
||
TRecord_array rdist(LF_RDIST, "NRIG");
|
||
rdist.renum_key("CODDIST", oldcode);
|
||
if (rdist.read(rdist.key()) == NOERR)
|
||
{
|
||
rdist.renum_key("CODDIST", newcode);
|
||
if (recursive)
|
||
{
|
||
for (int r = rdist.last_row(); r > 0; r = rdist.pred_row(r))
|
||
{
|
||
TRectype& row = rdist.row(r, false); // Rewriteable row
|
||
char row_type = row.get_char("TIPO");
|
||
// Tento rigenerazione del codice solo su articoli e distinte
|
||
if (row_type == 'A' || row_type == 'D')
|
||
{
|
||
const TCodice_articolo oldsub = row.get("CODCOMP");
|
||
TCodice_articolo newsub;
|
||
if (generate_subcode(oldcode, newcode, oldsub, newsub))
|
||
{
|
||
row.put("CODCOMP", newsub);
|
||
// Controllo se la riga e' in realta' una distinta
|
||
if (row_type == 'A' && !cache().get(LF_DIST, oldsub).empty())
|
||
row_type = 'D';
|
||
if (row_type == 'D')
|
||
copy_distinct(oldsub, newsub, recursive);
|
||
else
|
||
copy_article(oldsub, newsub);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
rdist.write();
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
|
||
bool TQuery_mask::restart_tree()
|
||
{
|
||
TString id;
|
||
if (_tree.has_root())
|
||
_tree.curr_id(id);
|
||
if (!_tree.restart())
|
||
return false;
|
||
int d =get_int(F_MIN_DEPTH);
|
||
int dir=1; // direzione di scorrimento albero
|
||
do
|
||
{
|
||
while (dir == 1 && !_tree.is_leaf())
|
||
{
|
||
if (_tree.is_cyclic())
|
||
break;
|
||
_tree.expand();
|
||
_tree.goto_firstson();
|
||
if ((_tree.has_rbrother() || d != 0) && _tree.curr_depth() >= d)
|
||
{
|
||
_tree.goto_father();
|
||
dir = -1;
|
||
break;
|
||
}
|
||
}
|
||
if (_tree.has_rbrother())
|
||
{
|
||
_tree.goto_rbrother();
|
||
dir = 1;
|
||
}
|
||
else
|
||
{
|
||
_tree.goto_father();
|
||
dir = -1;
|
||
}
|
||
} while (_tree.curr_depth() > 0);
|
||
|
||
if (id.full())
|
||
_tree.goto_node(id);
|
||
|
||
TTree_field& tf = tfield(F_TREE);
|
||
tf.win().update_thumb(0, 0);
|
||
tf.win().force_update();
|
||
return true;
|
||
}
|
||
|
||
bool TQuery_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case F_VAR_LIV1:
|
||
case F_VAR_LIV2:
|
||
case F_VAR_LIV3:
|
||
case F_VAR_LIV4:
|
||
case F_CODICE:
|
||
if (e == fe_modify)
|
||
{
|
||
TString strliv,oldstrliv;
|
||
for (int l=0; l < 4 ; l++)
|
||
_livgiac.pack_grpcode(strliv,get(F_VAR_LIV1+l), l+1);
|
||
|
||
TTree_field& tf = tfield(F_TREE);
|
||
const TCodice_articolo val = get(F_CODICE);
|
||
if (val.not_empty() && _tree.has_root())
|
||
{
|
||
long pos = _tree.find_node(val);
|
||
_tree.curr_giaclev(oldstrliv);
|
||
if (pos <= 0 || pos == 1 && strliv != oldstrliv)
|
||
{
|
||
if (_tree.set_root(val,"",1.0,strliv))
|
||
redraw_tree(e);
|
||
}
|
||
else
|
||
{
|
||
tf.select_current();
|
||
do { _tree.expand(); } while (_tree.goto_father());
|
||
pos = _tree.find_node(val, SCAN_PRE_ORDER | SCAN_IGNORING_UNEXPANDED);
|
||
|
||
TField_window& win = tf.win();
|
||
const TPoint& range = win.range();
|
||
if (pos > range.y)
|
||
win.set_scroll_max(win.columns(), pos+win.rows());
|
||
|
||
win.update_thumb(-1, pos-1);
|
||
win.force_update();
|
||
tf.set_focus();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (val.empty() || _tree.set_root(val,"",1.0,strliv))
|
||
redraw_tree(e);
|
||
}
|
||
}
|
||
break;
|
||
case F_SORT:
|
||
if (e == fe_init || e == fe_modify)
|
||
{
|
||
int sk = atoi(o.get());
|
||
if (sk >= 0 && sk <= 5)
|
||
{
|
||
_tree.set_sort_key(sk);
|
||
redraw_tree(e);
|
||
}
|
||
else
|
||
error_box(FR("Chiave di ordinamento errata: %d"), sk);
|
||
}
|
||
break;
|
||
case F_TREE:
|
||
if (e == fe_modify)
|
||
{
|
||
_tree.curr_id(_curr);
|
||
TCodice_articolo code; _tree.curr_code(code);
|
||
set(F_CODICE, code, 0x2);
|
||
}
|
||
break;
|
||
case DLG_SELECT:
|
||
if (e == fe_button)
|
||
{
|
||
const TString& str = get(F_CODICE);
|
||
if (str.full())
|
||
set(F_CODICEQ, str);
|
||
else
|
||
return false;
|
||
}
|
||
break;
|
||
case F_COPY:
|
||
if (e == fe_button)
|
||
{
|
||
const TCodice_articolo oldcode = get(F_CODICE);
|
||
if (oldcode.blank())
|
||
error_box(TR("Selezionare un codice"));
|
||
else
|
||
{
|
||
TCodice_articolo newcode;
|
||
if (ask_new_code(oldcode, newcode))
|
||
{
|
||
bool recursive = are_similar(oldcode, newcode);
|
||
if (recursive)
|
||
recursive = yesno_box(TR("Si desidera riportare le modifiche al codice anche sui componenti?"));
|
||
if (copy_distinct(oldcode, newcode, recursive))
|
||
{
|
||
set(F_CODICEQ, newcode); // Passa in modifica della nuova disitinta
|
||
stop_run(K_ENTER);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case F_EXPLODE:
|
||
if (e == fe_button)
|
||
{
|
||
TCodice_articolo art = get(F_CODICE);
|
||
if (art.not_empty())
|
||
{
|
||
TString strliv;
|
||
_tree.curr_giaclev(strliv);
|
||
_tree.set_root(art,"",1.0,strliv);
|
||
restart_tree();
|
||
}
|
||
if (_tree.goto_root())
|
||
{
|
||
_tree.curr_code(art);
|
||
TString80 caption;
|
||
caption << TR("Esplosione ") << art;
|
||
|
||
TMask m("db0500c");
|
||
m.set_caption(caption);
|
||
m.set(F_SORT, get(F_SORT));
|
||
m.set(F_ARTICOLI, "X");
|
||
m.set(F_LAVORAZIONI, "X");
|
||
m.set(F_VIRTUALI, "X");
|
||
if (m.run() == K_ENTER)
|
||
{
|
||
TDistinta_sheet a(_livgiac.last_level());
|
||
a.set_caption(caption);
|
||
int sk = m.get_int(F_SORT);
|
||
int md = m.get_int(F_MAXDEPTH);
|
||
TExplosion_grouping gr = TExplosion_grouping(m.get_int(F_GROUPMODE));
|
||
bool mb = m.get_bool(F_MATBASE);
|
||
bool sp = m.get_bool(F_STOPPROD);
|
||
|
||
TString16 fi;
|
||
if (m.get_bool(F_ARTICOLI)) fi << 'A';
|
||
if (m.get_bool(F_LAVORAZIONI)) fi << 'L';
|
||
if (m.get_bool(F_VIRTUALI)) fi << 'V';
|
||
if (m.get_bool(F_GHOST)) fi << 'G';
|
||
|
||
if (_tree.goto_root())
|
||
{
|
||
TIndwin iw(0, caption, false, false);
|
||
_tree.explode(a.rows_array(), mb, gr, md, fi, sk, sp);
|
||
}
|
||
a.run();
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case F_VAR_CODMAG:
|
||
case F_VAR_CODDEP:
|
||
case F_VAR_IMPIANTO:
|
||
case F_VAR_LINEA:
|
||
if (e == fe_modify || e == fe_init)
|
||
{
|
||
switch (o.dlg()) {
|
||
case F_VAR_IMPIANTO:
|
||
_tree.set_global("_IMPIANTO",o.get()); break;
|
||
case F_VAR_LINEA:
|
||
_tree.set_global("_LINEA",o.get()); break;
|
||
case F_VAR_CODMAG:
|
||
case F_VAR_CODDEP:
|
||
{
|
||
TString8 codmagdep;
|
||
add_magcode(codmagdep, get(F_VAR_CODMAG));
|
||
add_depcode(codmagdep, get(F_VAR_CODDEP));
|
||
_tree.set_global("_MAGDEP",codmagdep);
|
||
}
|
||
break;
|
||
}
|
||
redraw_tree(e);
|
||
}
|
||
break;
|
||
case F_MIN_DEPTH:
|
||
case F_HIDE_GHOST:
|
||
if (e == fe_modify || e == fe_init)
|
||
{
|
||
const char ig=*get(F_HIDE_GHOST);
|
||
_tree.set_ignore_ghost(ig > ' ');
|
||
redraw_tree(e);
|
||
}
|
||
break;
|
||
case F_SHOW_QTA:
|
||
if (e == fe_modify || e == fe_init)
|
||
{
|
||
const char v=*o.get();
|
||
_tree.set_qta_on_descr(v > ' ');
|
||
redraw_tree(e);
|
||
}
|
||
break;
|
||
case F_DESCR_SEP:
|
||
if (e == fe_modify || e == fe_init)
|
||
{
|
||
const char v=*o.get();
|
||
_tree.set_descr_separator(v);
|
||
redraw_tree(e);
|
||
}
|
||
break;
|
||
case F_SHOW_LIV1:
|
||
case F_SHOW_LIV2:
|
||
case F_SHOW_LIV3:
|
||
case F_SHOW_LIV4:
|
||
if (e == fe_modify || e == fe_init)
|
||
{
|
||
const char v=*o.get();
|
||
_tree.set_livgiac_on_descr(o.dlg() - F_SHOW_LIV1 +1, v > ' ');
|
||
redraw_tree(e);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TQuery_mask::redraw_tree(TField_event e)
|
||
{
|
||
if (e == fe_modify && _tree.goto_root())
|
||
{
|
||
if (get(F_CODICE).blank())
|
||
{
|
||
TCodice_articolo c; _tree.curr_code(c);
|
||
set(F_CODICE, c);
|
||
return on_field_event((TOperable_field &)field(F_CODICE), fe_modify, 0l);
|
||
}
|
||
restart_tree();
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
|
||
TQuery_mask::TQuery_mask(TDistinta_tree& dt)
|
||
: TAutomask("db0500a"), _tree(dt)
|
||
{
|
||
if (!app().has_module(MRAUT))
|
||
{
|
||
hide(F_VAR_IMPIANTO);
|
||
hide(F_VAR_LINEA);
|
||
}
|
||
for (int l=0; l<4; l++)
|
||
{
|
||
show(F_VAR_LIV1+l, _livgiac.enabled(l+1));
|
||
show(F_SHOW_LIV1+l, _livgiac.enabled(l+1));
|
||
if (_livgiac.enabled(l+1))
|
||
{
|
||
field(F_VAR_LIV1+l).set_prompt(_livgiac.name(l+1));
|
||
field(F_SHOW_LIV1+l).set_prompt(format(FR("Mostra %s"),(const char *)_livgiac.name(l+1)));
|
||
}
|
||
}
|
||
|
||
TTree_field& tree = tfield(F_TREE);
|
||
tree.set_tree(&_tree);
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDistinta_mask
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TDistinta_mask : public TAutomask
|
||
{
|
||
TDistinta_tree& _tree;
|
||
TCodgiac_livelli *_livelli_giac;
|
||
TString _numdoc;
|
||
TDate _datadoc;
|
||
TString4 _tipocf;
|
||
TString8 _codcf;
|
||
|
||
private:
|
||
void set_um_rif(int row);
|
||
|
||
bool on_distsheet_event(TOperable_field& o, TField_event e, long jolly);
|
||
bool on_unitsheet_event(TOperable_field& o, TField_event e, long jolly);
|
||
bool on_parmsheet_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
bool test_row(const TToken_string& row);
|
||
void load_um();
|
||
|
||
static void sheetrighe_get(TSheet_field &fld_righe, int item);
|
||
static void sheetrighe_put(TSheet_field &fld_righe, int item);
|
||
|
||
public:
|
||
TDistinta_mask(TDistinta_tree& dt);
|
||
virtual ~TDistinta_mask() { }
|
||
};
|
||
|
||
void TDistinta_mask::sheetrighe_get(TSheet_field &fld_righe, int item)
|
||
{
|
||
TDistinta_mask &m=(TDistinta_mask &)fld_righe.mask();
|
||
// prende il record della riga corrente dal record array
|
||
TRectype &rec= fld_righe.record()->row(item, true);
|
||
TToken_string &row= fld_righe.row(item-1);
|
||
// codici di livello
|
||
row.add(m._livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,1),fld_righe.cid2index(F_LIV1) );
|
||
row.add(m._livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,2),fld_righe.cid2index(F_LIV2) );
|
||
row.add(m._livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,3),fld_righe.cid2index(F_LIV3) );
|
||
row.add(m._livelli_giac->unpack_grpcode(rec.get("LIVELLO") ,4),fld_righe.cid2index(F_LIV4) );
|
||
}
|
||
void TDistinta_mask::sheetrighe_put(TSheet_field &fld_righe, int item)
|
||
{
|
||
TDistinta_mask &m=(TDistinta_mask &)fld_righe.mask();
|
||
TToken_string &row= fld_righe.row(item-1);
|
||
|
||
TRectype &recrighe= fld_righe.record()->row(item, true);
|
||
// codici livello
|
||
if (m._livelli_giac->enabled())
|
||
{
|
||
TString16 packedcode;
|
||
m._livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV1)),1);
|
||
m._livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV2)),2);
|
||
m._livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV3)),3);
|
||
m._livelli_giac->pack_grpcode(packedcode,row.get(fld_righe.cid2index(F_LIV4)),4);
|
||
recrighe.put("LIVELLO", packedcode);
|
||
}
|
||
}
|
||
|
||
void TDistinta_mask::load_um()
|
||
{
|
||
// *****************************
|
||
// LETTURA SHEET UNITA' DI MISURA
|
||
TSheet_field& units= (TSheet_field &)field(F_UNITA); // prende lo sheet delle unit<69> di misura
|
||
const char tree_type=_tree.get_type(get(F_CODICE));
|
||
|
||
if (!app().is_transaction())
|
||
{
|
||
if (tree_type=='L')
|
||
{
|
||
units.destroy();
|
||
}
|
||
else
|
||
{
|
||
app().relation().lfile().put("CODDIST",get(F_CODICE));
|
||
units.record()->read(*units.putkey(app().relation()));
|
||
units.autoload(app().relation());
|
||
}
|
||
}
|
||
units.disable_cell(0, units.cid2index(FU_FC));
|
||
const bool virtuale=tree_type!='A' && tree_type !='L';
|
||
units.enable_column(units.cid2index(FU_UM),virtuale);
|
||
units.enable_column(units.cid2index(FU_DESC),virtuale);
|
||
units.enable_column(units.cid2index(FU_FC),virtuale);
|
||
units.enable_column(units.cid2index(FU_PREZZO),virtuale);
|
||
|
||
const TString& main_um = get(F_UM);
|
||
if (main_um.full())
|
||
{
|
||
if (units.empty())
|
||
units.row(0) << main_um << "|1"; // aggiunge una riga allo sheet
|
||
|
||
const int idx_um = units.cid2index(FU_UM);
|
||
TString4 um;
|
||
FOR_EACH_SHEET_ROW_BACK(units, u, urow)
|
||
{
|
||
urow->get(idx_um, um);
|
||
if (um.full() && um == main_um)
|
||
{
|
||
set_um_rif(u);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!units.empty())
|
||
{
|
||
const TString4 um = units.cell(0,units.cid2index(FU_UM));
|
||
set(F_UM, um);
|
||
set(F_UMART1ST, um);
|
||
set_um_rif(0);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
bool TDistinta_mask::test_row(const TToken_string& row)
|
||
{
|
||
const TCodice_articolo father = get(F_CODICE);
|
||
|
||
TCodice_articolo code; row.get(1, code);
|
||
bool ok = code != father;
|
||
if (ok && _tree.find_node(father) > 0)
|
||
{
|
||
TToken_string path; _tree.curr_id(path);
|
||
path.add(code);
|
||
ok = !_tree.is_cyclic(path);
|
||
}
|
||
if (!ok)
|
||
error_box(FR("Il codice '%s' non puo' essere utilizzato\n"
|
||
"in quanto la distinta risulterebbe ciclica."), (const char*)code);
|
||
|
||
// Se e' una lavorazione
|
||
if (get(F_TIPO)[0] == 'L')
|
||
{
|
||
ok = row[0] == 'L' && _tree.is_lav(code);
|
||
if (!ok)
|
||
error_box(FR("Il codice '%s' non e' una lavorazione"), (const char*)code);
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
// Forza la riga row ad essere quella dell'unita' di distinta
|
||
void TDistinta_mask::set_um_rif(int row)
|
||
{
|
||
TSheet_field& sht = sfield(F_UNITA);
|
||
const int chk = sht.cid2index(FU_RIF);
|
||
const int fc = sht.cid2index(FU_FC);
|
||
const int cod = sht.cid2index(FU_UM);
|
||
|
||
FOR_EACH_SHEET_ROW(sht, r, priga)
|
||
{
|
||
if (r == row)
|
||
{
|
||
priga->add("X", chk);
|
||
set(F_UM, priga->get(cod), true);
|
||
set(F_FCUMART, priga->get(fc), true);
|
||
}
|
||
else
|
||
priga->add("", chk);
|
||
}
|
||
sht.force_update();
|
||
}
|
||
|
||
bool TDistinta_mask::on_unitsheet_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
TSheet_field& sht = sfield(F_UNITA);
|
||
switch(e)
|
||
{
|
||
case se_query_modify:
|
||
sht.sheet_mask().enable(DLG_DELREC, get_bool(F_VIRTUALE) && sht.items()>1);
|
||
break;
|
||
case se_query_del:
|
||
return get_bool(F_VIRTUALE) && sht.items()>1; // Impedisce di cancellare l'unita' di misura base
|
||
case se_notify_modify:
|
||
if (jolly == 0)
|
||
set(F_UMART1ST,sht.cell(0,sht.cid2index(FU_UM)));
|
||
break;
|
||
case se_query_add:
|
||
if (!get_bool(F_VIRTUALE))
|
||
return false;
|
||
break;
|
||
case se_notify_add:
|
||
if (jolly == 0L)
|
||
{
|
||
const int fc = sht.cid2index(FU_FC);
|
||
sht.disable_cell(0, fc);
|
||
sht.row(0).add("1", fc);
|
||
}
|
||
break;
|
||
case fe_close:
|
||
if (sht.empty() || *sht.cell(0,0) <= ' ')
|
||
return sht.error_box(TR("E' necessario specificare l'unita' di misura principale"));
|
||
else
|
||
{
|
||
const int fc = sht.cid2index(FU_RIF);
|
||
int r;
|
||
for (r = sht.items()-1; r > 0; r--)
|
||
if (*sht.cell(r, fc) > ' ')
|
||
break;
|
||
set_um_rif(r);
|
||
}
|
||
break;
|
||
case fe_modify:
|
||
if (o.dlg() == FU_RIF && o.get().full())
|
||
set_um_rif(sht.selected());
|
||
break;
|
||
default: break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TDistinta_mask::on_distsheet_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
const short id = o.dlg();
|
||
switch (id)
|
||
{
|
||
case F_SHEET:
|
||
if (e == se_notify_add || e == se_notify_modify || e == fe_close)
|
||
{
|
||
TSheet_field& sheet = (TSheet_field&)o;
|
||
const int nrig = int(jolly);
|
||
TToken_string& row = sheet.row(nrig);
|
||
switch(e)
|
||
{
|
||
case se_notify_add:
|
||
row.add("A", F_TIPOCOMP-FIRST_FIELD); // Forza il listbox ad articolo
|
||
row.add("", F_EXPR-FIRST_FIELD); // Forza la quantita' ad 1
|
||
row.add(nrig+1, F_SORT0-FIRST_FIELD); // Inizializza numero riga
|
||
sheet.select(nrig);
|
||
break;
|
||
case se_notify_modify:
|
||
return test_row(row);
|
||
case fe_close:
|
||
{
|
||
TString80 code;
|
||
TString80 code1;
|
||
for (int n = sheet.items()-1; n >= 0; n--)
|
||
{
|
||
const TToken_string& row = sheet.row(n);
|
||
row.get(F_CODART-FIRST_FIELD, code);
|
||
if (!code.blank())
|
||
{
|
||
if (!test_row(row))
|
||
return false;
|
||
for (int m = n - 1; m >= 0; m--)
|
||
{
|
||
const TToken_string& row = sheet.row(m);
|
||
row.get(F_CODART-FIRST_FIELD, code1);
|
||
if (code == code1)
|
||
{
|
||
int k = noyesall_box("Il codice %s e' ripetuto alla riga %d,\ncontinuare ugualmente ?", (const char *) code, n + 1);
|
||
if (k == K_NO)
|
||
return false;
|
||
else
|
||
if (k == K_SPACE)
|
||
return true;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
sheet.destroy(n);
|
||
}
|
||
}
|
||
if (sheet.items() == 0)
|
||
message_box(TR("E' necessario inserire almeno una riga nella distinta"));
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
case F_TIPOCOMP:
|
||
if (e == fe_init && o.focusdirty() &&
|
||
( *o.get()=='D' || *o.get()=='V'))
|
||
{
|
||
// introduzione di una distinta virtuale: il default <20> l'ereditariet<65> dei livelli di giac
|
||
TMask & m = sfield(F_SHEET).sheet_mask();
|
||
for (int l=0; l < 4; l++)
|
||
{
|
||
if (m.get(F_LIV1+l).blank())
|
||
m.set(F_TIPOLIV1+l,"E");
|
||
}
|
||
}
|
||
break;
|
||
|
||
case F_CODART:
|
||
case F_CODLAV:
|
||
case F_CODDIS:
|
||
case F_CODVAR:
|
||
if (e == fe_modify || e == fe_init)
|
||
{
|
||
TMask& m = o.mask();
|
||
const TEdit_field& ef = (const TEdit_field&)o;
|
||
const TRectype& rec = ef.browse()->cursor()->curr();
|
||
switch(rec.num())
|
||
{
|
||
case LF_ANAMAG:
|
||
if (m.get(F_UMEXPR).empty())
|
||
{
|
||
const TCodice_articolo art = o.get();
|
||
if (art.not_empty() && _tree.is_mag(art))
|
||
{
|
||
TCodice_um um = "$$"; // Unita' distinta
|
||
TQuantita qta(art, um, ZERO);
|
||
m.set(F_UMEXPR, qta.um());
|
||
}
|
||
}
|
||
if (e == fe_modify && rec.get_bool("SOSPESO"))
|
||
warning_box(FR("Attenzione l'articolo %s e' sospeso."), (const char *) rec.get(ANAMAG_CODART));
|
||
break;
|
||
case LF_DIST :
|
||
break;
|
||
default :
|
||
m.set(F_UMEXPR, rec.get("S6"));
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
case F_EXPR:
|
||
if (e == fe_modify)
|
||
{
|
||
TAutomask& m = (TAutomask&)o.mask();
|
||
TString str = o.get(); str.replace(',', '.');
|
||
if (str.not_empty())
|
||
{
|
||
TDistinta_expr expr;
|
||
if (expr.set(str))
|
||
{
|
||
if (expr.numvar() > 0)
|
||
{
|
||
for (int v = expr.numvar()-1; v >= 0; v--)
|
||
{
|
||
const char* name = expr.varname(v);
|
||
if (!_tree.is_global(name))
|
||
{
|
||
const TRectype& var = cache().get("VAR", name);
|
||
if (var.empty())
|
||
return m.error_box(FR("La variabile %s non e' definita in tabella"), name);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
str = expr.as_string(); str.replace('.', ',');
|
||
o.set(expr.as_string());
|
||
}
|
||
}
|
||
else
|
||
return m.error_box(FR("Errore di sintassi: %s"), expr.last_token());
|
||
}
|
||
else
|
||
return m.error_box(TR("L'espressione deve essere specificata"));
|
||
}
|
||
break;
|
||
case F_SORT1:
|
||
case F_SORT2:
|
||
case F_SORT3:
|
||
case F_SORT4:
|
||
case F_SORT5:
|
||
if ((fe_modify || fe_close) && o.empty())
|
||
{
|
||
TString16 key; key << (o.dlg() - F_SORT1 + 1);
|
||
bool completo = cache().get("ORD", key).get_bool("B0");
|
||
if (completo)
|
||
{
|
||
TAutomask& m = (TAutomask&)o.mask();
|
||
TSheet_field& s = *m.get_sheet();
|
||
return m.error_box(FR("Specificare l'ordinamento %s alla riga %d"),
|
||
(const char*)key, s.selected()+1);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool TDistinta_mask::on_parmsheet_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
TSheet_field &sf = sfield(F_PARAMS);
|
||
const short id = o.dlg();
|
||
switch (id)
|
||
{
|
||
case FV_PARAM:
|
||
if (sf.row(sf.selected())[0] == 'G' && (e == fe_modify || e == fe_close))
|
||
{
|
||
const TString& var = o.get();
|
||
if (!_tree.is_global(var))
|
||
return error_box(FR("La variabile %s non e' una delle variabili globali. Consultare la documentazione del modulo Distinta Base"),(const char *)var);
|
||
}
|
||
break;
|
||
case FV_VALUE:
|
||
if (e == fe_modify || e == fe_close)
|
||
{
|
||
TString var;
|
||
sf.row(sf.selected()).get(1,var);
|
||
TString expr = o.get(); expr.replace(',', '.');
|
||
TDistinta_expr e;
|
||
const TTypeexp exprtype = _tree.get_var_type(var);
|
||
if (!e.set(expr, exprtype))
|
||
return false;
|
||
|
||
for (int v = e.numvar()-1; v >= 0; v--)
|
||
{
|
||
const char* name = e.varname(v);
|
||
if (!_tree.is_global(name))
|
||
{
|
||
const TRectype& var = cache().get("VAR", name);
|
||
if (var.empty())
|
||
return error_box(FR("La variabile %s non e' definita in tabella"), name);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
static int _sort_key = 0;
|
||
|
||
static int compare_sheet_rows(const TObject** o1, const TObject** o2)
|
||
{
|
||
TToken_string* s1 = (TToken_string*)*o1;
|
||
TToken_string* s2 = (TToken_string*)*o2;
|
||
|
||
const int key_pos = (_sort_key ? (F_SORT1+_sort_key-1) : F_SORT0) - FIRST_FIELD;
|
||
long k1 = s1->get_long(key_pos);
|
||
long k2 = s2->get_long(key_pos);
|
||
|
||
if (k1 == 0) k1 = 100000000L;
|
||
if (k2 == 0) k2 = 100000000L;
|
||
|
||
return k1 == k2 ? 0 : (k1 > k2 ? +1 : -1);
|
||
}
|
||
|
||
bool TDistinta_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
const short id = o.dlg();
|
||
switch (id)
|
||
{
|
||
case F_CODICE:
|
||
if (e == fe_init)
|
||
{
|
||
const TString& code = o.get();
|
||
if (code.not_empty())
|
||
{
|
||
const char type = _tree.get_type(code);
|
||
|
||
switch(type)
|
||
{
|
||
case 'A':
|
||
{
|
||
set(F_TIPO, "A", true);
|
||
|
||
const TArticolo mag(code);
|
||
|
||
if (get(F_DESCR).blank())
|
||
set(F_DESCR, mag.get(ANAMAG_DESCR));
|
||
set(F_PREZZO, mag.get(ANAMAG_COSTSTD));
|
||
set(F_PESO, mag.get(ANAMAG_PESO));
|
||
set(F_UMP, mag.get(ANAMAG_UMP));
|
||
}
|
||
break;
|
||
case 'L':
|
||
{
|
||
set(F_TIPO, "L", true);
|
||
|
||
const TLavorazione lav(code);
|
||
|
||
if (get(F_DESCR).blank())
|
||
set(F_DESCR, lav.descr());
|
||
set(F_UM, lav.um());
|
||
set(F_PREZZO, lav.prezzo());
|
||
}
|
||
break;
|
||
default:
|
||
set(F_TIPO, "V", true);
|
||
// le distinte virtuali non possono essere master
|
||
break;
|
||
}
|
||
load_um();
|
||
}
|
||
}
|
||
else
|
||
break;
|
||
case F_SORT:
|
||
if (e == fe_modify || e == fe_close)
|
||
{
|
||
TSheet_field& sf = sfield(F_SHEET);
|
||
_sort_key = atoi(o.get());
|
||
if (e == fe_close)
|
||
{
|
||
if (_sort_key > 0)
|
||
{
|
||
if (yesno_box(FR("Attenzione, l'ordine di immissione verra' modificato:\n"
|
||
"Si desidera registrare secondo l'ordinamento %d?"), _sort_key))
|
||
_sort_key = -1;
|
||
else
|
||
_sort_key = 0;
|
||
o.reset();
|
||
}
|
||
else
|
||
_sort_key = -1;
|
||
}
|
||
if (_sort_key >= 0)
|
||
{
|
||
TString_array& a = sf.rows_array();
|
||
a.TArray::sort(compare_sheet_rows);
|
||
sf.force_update();
|
||
}
|
||
}
|
||
break;
|
||
case F_SORTA:
|
||
if (e == fe_button)
|
||
{
|
||
TSheet_field& sheet = o.mask().sfield(F_SHEET);
|
||
sheet.sort();
|
||
sheet.force_update();
|
||
}
|
||
break;
|
||
case DLG_AGGPRZ:
|
||
case DLG_MOV:
|
||
if (e == fe_button)
|
||
{
|
||
const bool do_mov = (id == DLG_MOV);
|
||
|
||
if (app().has_module(MGAUT))
|
||
{
|
||
cache().destroy(LF_DIST);
|
||
cache().destroy(LF_RDIST);
|
||
TSheet_field& sf = sfield(F_SHEET);
|
||
TMov_mask mov(get(F_CODICE), &sf);
|
||
TMagazzini m;
|
||
|
||
if (!do_mov)
|
||
{
|
||
mov.hide(F_DATAREG);
|
||
mov.hide(F_CODCAUS);
|
||
mov.hide(F_DESCAU);
|
||
mov.hide(F_CODMAG);
|
||
mov.hide(F_DESMAG);
|
||
mov.hide(F_CODDEP);
|
||
mov.hide(F_DESDEP);
|
||
mov.hide(F_QUANT);
|
||
mov.hide(F_SCONTO);
|
||
mov.hide(F_NUMDOC);
|
||
mov.hide(F_DATADOC);
|
||
}
|
||
else
|
||
{
|
||
if (!m.gestmultimag())
|
||
{
|
||
mov.disable(F_CODMAG);
|
||
mov.disable(F_DESMAG);
|
||
mov.disable(F_CODDEP);
|
||
mov.disable(F_DESDEP);
|
||
}
|
||
else
|
||
if (!m.gestdep())
|
||
{
|
||
mov.disable(F_CODDEP);
|
||
mov.disable(F_DESDEP);
|
||
}
|
||
mov.set(F_CODMAG, m.standardmag());
|
||
mov.set(F_CODDEP, m.standarddep());
|
||
mov.set(F_NUMDOC, _numdoc);
|
||
mov.set(F_DATADOC, _datadoc);
|
||
}
|
||
mov.set(F_TIPOCF, _tipocf);
|
||
mov.set(F_CODCF, _codcf, 0x3);
|
||
mov.set(F_PREZZOM, get(F_PREZZO));
|
||
if (mov.run() == K_ENTER)
|
||
{
|
||
TFilename name;
|
||
|
||
_tipocf = mov.get(F_TIPOCF);
|
||
_codcf = mov.get(F_CODCF);
|
||
if (do_mov)
|
||
{
|
||
TAssoc_array & arts = mov.costs();
|
||
|
||
name.temp("", "ini");
|
||
|
||
_numdoc = mov.get(F_NUMDOC);
|
||
_datadoc = mov.get_date(F_DATADOC);
|
||
FOR_EACH_ASSOC_OBJECT(arts, obj, key, item)
|
||
{
|
||
TArticolo & articolo = (TArticolo &) cached_article(key);
|
||
const real costo = * (real *)item;
|
||
|
||
if (articolo.lock_and_prompt())
|
||
{
|
||
articolo.put(ANAMAG_ULTCOS1, costo);
|
||
articolo.rewrite();
|
||
}
|
||
}
|
||
|
||
{
|
||
TConfig c(name);
|
||
c.set_paragraph("Transaction");
|
||
c.set("Action", "Insert");
|
||
c.set("Mode", "");
|
||
c.set_paragraph(format("%d", LF_MOVMAG));
|
||
c.set(MOVMAG_DATAREG, mov.get(F_DATAREG));
|
||
c.set(MOVMAG_CODCAUS, mov.get(F_CODCAUS));
|
||
c.set(MOVMAG_NUMDOC, _numdoc);
|
||
c.set(MOVMAG_EXNUMDOC, _numdoc);
|
||
c.set(MOVMAG_EXDATADOC, _datadoc.string());
|
||
c.set(MOVMAG_TIPOCF, mov.get(F_TIPOCF));
|
||
c.set(MOVMAG_CODCF, mov.get(F_CODCF));
|
||
c.set_paragraph(format("%d,1", LF_RMOVMAG));
|
||
TString8 codmag(mov.get(F_CODMAG));
|
||
|
||
codmag.rpad(3);
|
||
codmag << mov.get(F_CODDEP);
|
||
c.set(RMOVMAG_CODMAG, codmag);
|
||
c.set(RMOVMAG_CODART, get(F_CODICE));
|
||
c.set(RMOVMAG_UM, get(F_UM));
|
||
c.set(RMOVMAG_QUANT, mov.get(F_QUANT));
|
||
c.set(RMOVMAG_PREZZO, mov.get(F_PREZZOM));
|
||
}
|
||
|
||
TExternal_app app(format("mg1 -0 -i%s", (const char *)name));
|
||
|
||
app.run();
|
||
}
|
||
TLocalisamfile art(LF_ANAMAG);
|
||
art.put(ANAMAG_CODART, get(F_CODICE));
|
||
if (art.read(_isequal, _testandlock) == NOERR)
|
||
{
|
||
const real costo(mov.get(F_PREZZOM)); // Aggiorna ultimo costo in anagrafica
|
||
if (!do_mov)
|
||
art.put(ANAMAG_ULTCOS1, costo);
|
||
if (mov.get(F_TIPOCF) == "F")
|
||
art.put(ANAMAG_CODFORN, mov.get(F_CODCF));
|
||
art.rewrite();
|
||
}
|
||
const real prezzo(mov.get(F_PREZZOV));
|
||
TLocalisamfile umart(LF_UMART);
|
||
umart.put(UMART_CODART, get(F_CODICE));
|
||
umart.put(UMART_NRIGA, 1);
|
||
if (umart.read(_isequal, _testandlock) == NOERR)
|
||
{
|
||
umart.put(UMART_PREZZO, prezzo); // Aggiorna prezzo di vendita
|
||
umart.rewrite();
|
||
}
|
||
set(F_CODICE, get(F_CODICE), 0x3);
|
||
|
||
if (do_mov)
|
||
{
|
||
TConfig c(name);
|
||
|
||
c.set_paragraph(format("%d", LF_MOVMAG));
|
||
|
||
const long movmag = c.get_long(MOVMAG_NUMREG);
|
||
|
||
if (movmag > 0L && yesno_box("Vuoi stampare le etichette"))
|
||
{
|
||
const TString8 codcaus(mov.get(F_CODCAUS));
|
||
const TString codart(get(F_CODICE));
|
||
TExternal_app etich_app(format("mg3 -5 101=%s,103=%s,106=M,109=%s,110=%ld,111=%ld",
|
||
(const char *) codart, (const char *) codart, (const char *) codcaus, movmag, movmag));
|
||
|
||
etich_app.run();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
if (yesno_box("Si desidera stampare le etichette"))
|
||
{
|
||
const long annoes = TDate(TODAY).year();
|
||
const TString codart(get(F_CODICE));
|
||
TExternal_app etich_app(format("mg3 -5 101=%s,103=%s,106=G,116=%ld",
|
||
(const char *) codart, (const char *) codart, annoes));
|
||
|
||
etich_app.run();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case F_UNITA:
|
||
return on_unitsheet_event(o, e, jolly);
|
||
case F_SHEET:
|
||
return on_distsheet_event(o, e, jolly);
|
||
default:
|
||
if (id >= 101 && id < 500) // E' in uno sheet?
|
||
{
|
||
switch (jolly)
|
||
{
|
||
case 1 : return on_distsheet_event(o, e, jolly);
|
||
case 2 : return on_unitsheet_event(o, e, jolly);
|
||
case 3 : return on_parmsheet_event(o, e, jolly);
|
||
default: break;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
TDistinta_mask::TDistinta_mask(TDistinta_tree& dt)
|
||
: TAutomask("db0500b"), _tree(dt)
|
||
{
|
||
TSheet_field& sf = sfield(F_SHEET);
|
||
sf.set_append(false);
|
||
TMask& sm = sf.sheet_mask();
|
||
TString16 key;
|
||
int i;
|
||
for (i = 4; i >= 0; i--)
|
||
{
|
||
key.format("%d", i+1);
|
||
const bool kill = cache().get("ORD",key).empty();
|
||
if (kill)
|
||
{
|
||
const short id = F_SORT1+i;
|
||
sm.hide(id);
|
||
sf.delete_column(id);
|
||
}
|
||
}
|
||
|
||
_livelli_giac = new TCodgiac_livelli();
|
||
for (i = 3; i >= 0; i--)
|
||
{
|
||
const short id = F_LIV1+i*2;
|
||
_livelli_giac->set_sheetcolumn(sf,id,i+1);
|
||
if (!_livelli_giac->enabled(i+1))
|
||
{
|
||
sf.delete_column(id+1);
|
||
sf.sheet_mask().hide(id+1);
|
||
}
|
||
}
|
||
TSheet_field& su = sfield(F_UNITA);
|
||
su.set_lines_record(*(new TRecord_array(LF_UMART, "NRIGA")));
|
||
|
||
sf.set_userget(sheetrighe_get);
|
||
sf.set_userput(sheetrighe_put);
|
||
cache().test_file_changes(LF_TAB);
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDistinta_app
|
||
///////////////////////////////////////////////////////////
|
||
|
||
bool TDistinta_app::user_create()
|
||
{
|
||
_therel = new TRelation(LF_DIST);
|
||
_tree = new TDistinta_tree;
|
||
_querymask = new TQuery_mask(*_tree);
|
||
_themask = new TDistinta_mask(*_tree);
|
||
|
||
return true;
|
||
}
|
||
|
||
bool TDistinta_app::user_destroy()
|
||
{
|
||
delete _themask;
|
||
delete _querymask;
|
||
delete _therel;
|
||
delete _tree;
|
||
return true;
|
||
}
|
||
|
||
void TDistinta_app::init_insert_mode(TMask &m)
|
||
{
|
||
TSheet_field& f = m.sfield(F_UNITA);
|
||
if (f.empty())
|
||
f.row(0) = " |1"; // aggiunge una riga allo sheet
|
||
m.set(F_MASTER,"X");
|
||
}
|
||
|
||
bool TDistinta_app::changing_mask(int mode)
|
||
{
|
||
const bool was_query = _mode == MODE_QUERY || _mode == MODE_QUERYINS;
|
||
const bool is_query = mode == MODE_QUERY || mode == MODE_QUERYINS;
|
||
return was_query != is_query;
|
||
}
|
||
|
||
TMask* TDistinta_app::get_mask(int mode)
|
||
{
|
||
const bool is_query = mode == MODE_QUERY || mode == MODE_QUERYINS;
|
||
_mode = mode;
|
||
return is_query ? (TMask*)_querymask : (TMask*)_themask;
|
||
}
|
||
|
||
void TDistinta_app::init_query_mode(TMask& m)
|
||
{
|
||
((TQuery_mask&)m).restart_tree();
|
||
set_search_field(F_CODICE);
|
||
m.enable_page(1);
|
||
}
|
||
|
||
void TDistinta_app::load_memo(TMask& m, TToken_string& memo)
|
||
{
|
||
TSheet_field& params = m.sfield(F_PARAMS);
|
||
params.destroy();
|
||
const int righe = memo.items();
|
||
for (int i = 0; i < righe; i++)
|
||
{
|
||
TToken_string& row = params.row(i);
|
||
memo.get(i, row);
|
||
int equal = row.find('=');
|
||
if (equal > 0)
|
||
row[equal] = SAFE_PIPE_CHR;
|
||
row.insert(format(" %c",SAFE_PIPE_CHR),0);
|
||
row.replace('.', ',');
|
||
if (_tree->is_global(row.get(1)))
|
||
row[0]='G';
|
||
}
|
||
}
|
||
|
||
int TDistinta_app::read(TMask& m)
|
||
{
|
||
const int err = TRelation_application::read(m);
|
||
|
||
if (err == NOERR)
|
||
{
|
||
TSheet_field& sheet = m.sfield(F_SHEET);
|
||
FOR_EACH_SHEET_ROW(sheet, nrig, row)
|
||
{
|
||
TString s = row->get(sheet.cid2index(F_EXPR));
|
||
s.replace('.' , ',');
|
||
row->add(s, sheet.cid2index(F_EXPR));
|
||
sheet.check_row(nrig);
|
||
row->add(nrig+1, sheet.cid2index(F_SORT0));
|
||
if (*row->get(sheet.cid2index(F_DESCOMP)) == '\0')
|
||
{
|
||
const char type = row->get(sheet.cid2index(F_TIPOCOMP))[0];
|
||
const TString cod = row->get(sheet.cid2index(F_CODART));
|
||
|
||
switch (type)
|
||
{
|
||
case 'A':
|
||
row->add(cache().get(LF_ANAMAG, cod, ANAMAG_DESCR), sheet.cid2index(F_DESCOMP));
|
||
break;
|
||
case 'L':
|
||
row->add(cache().get("LAV", cod, "S0"), sheet.cid2index(F_DESCOMP));
|
||
break;
|
||
case 'D':
|
||
row->add(cache().get(LF_DIST, cod, "DESCR"), sheet.cid2index(F_DESCOMP));
|
||
break;
|
||
case 'V':
|
||
row->add(cache().get("VAR", cod, "S0"), sheet.cid2index(F_DESCOMP));
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
TToken_string memo(1024, '\n');
|
||
memo = _therel->curr().get("PARAMETRI");
|
||
load_memo(m, memo);
|
||
}
|
||
|
||
return err;
|
||
}
|
||
|
||
void TDistinta_app::ini2sheet(TConfig& ini, TSheet_field& s)
|
||
{
|
||
if (s.dlg() == F_PARAMS)
|
||
{
|
||
const TFixed_string fname("PARAMETRI");
|
||
TFieldref memof(fname, 0);
|
||
TToken_string memo(1024, '\n');
|
||
memo = memof.read(ini, "112");
|
||
memo.replace(SAFE_PIPE_CHR, '\n');
|
||
load_memo(s.mask(), memo);
|
||
}
|
||
else
|
||
{
|
||
TRelation_application::ini2sheet(ini, s);
|
||
}
|
||
}
|
||
|
||
bool TDistinta_app::parms2rel(const TMask& m)
|
||
{
|
||
TToken_string memo(1024, '\n');
|
||
TSheet_field& parms = m.sfield(F_PARAMS);
|
||
TString var,expr;
|
||
FOR_EACH_SHEET_ROW(parms, r, row)
|
||
{
|
||
var = row->get(0);
|
||
const char typ = var[0];
|
||
var = row->get();
|
||
if (!var.blank())
|
||
{
|
||
expr = row->get(); expr.replace(',', '.');
|
||
if (typ == 'G' && !_tree->is_global(var))
|
||
error_box(FR("La variabile %s non e' una delle variabili globali. Consultare la documentazione del modulo Distinta Base"),(const char *)var);
|
||
memo.add(var);
|
||
memo << '=';
|
||
memo << expr;
|
||
}
|
||
}
|
||
_therel->curr().put("PARAMETRI", memo);
|
||
|
||
// Azzera albero per rispecchiare eventuali modifiche
|
||
_querymask->restart_tree();
|
||
return true;
|
||
}
|
||
|
||
void TDistinta_app::remove_desc(TMask& m)
|
||
{
|
||
TSheet_field& sf = m.sfield(F_SHEET);
|
||
TString descr = cache().get(LF_ANAMAG, m.get(F_CODICE), ANAMAG_DESCR);
|
||
TString distdescr = m.get(F_DESCR);
|
||
|
||
if (descr == distdescr)
|
||
m.reset(F_DESCR);
|
||
|
||
FOR_EACH_SHEET_ROW(sf, r, row)
|
||
{
|
||
TString s = row->get(sf.cid2index(F_EXPR));
|
||
s.replace(',' , '.');
|
||
row->add(s, sf.cid2index(F_EXPR));
|
||
const char type = row->get(sf.cid2index(F_TIPOCOMP))[0];
|
||
const TString cod = row->get(sf.cid2index(F_CODART));
|
||
|
||
switch (type)
|
||
{
|
||
case 'A':
|
||
descr = cache().get(LF_ANAMAG, cod, ANAMAG_DESCR);
|
||
break;
|
||
case 'L':
|
||
descr = cache().get("LAV", cod, "S0");
|
||
break;
|
||
case 'D':
|
||
descr = cache().get(LF_DIST, cod, "DESCR");
|
||
break;
|
||
case 'V':
|
||
descr = cache().get("VAR", cod, "S0");
|
||
default:
|
||
break;
|
||
}
|
||
if (descr == row->get(sf.cid2index(F_DESCOMP)))
|
||
row->add("",sf.cid2index(F_DESCOMP));
|
||
}
|
||
|
||
}
|
||
|
||
int TDistinta_app::write(const TMask& m)
|
||
{
|
||
parms2rel(m);
|
||
remove_desc((TMask&)m);
|
||
int err = TRelation_application::write(m);
|
||
if (err == NOERR && get_relation()->lfile().get_bool("VIRTUALE"))
|
||
{
|
||
TSheet_field& f = m.sfield(F_UNITA); // prende lo sheet delle unit<69> di misura
|
||
f.record()->renum_key(UMART_CODART, m.get(F_CODICE));
|
||
err = f.record()->write(false);
|
||
}
|
||
return err;
|
||
}
|
||
|
||
int TDistinta_app::rewrite(const TMask& m)
|
||
{
|
||
parms2rel(m);
|
||
remove_desc((TMask&)m);
|
||
int err = TRelation_application::rewrite(m);
|
||
if (err == NOERR && get_relation()->lfile().get_bool("VIRTUALE"))
|
||
{
|
||
TSheet_field& f= m.sfield(F_UNITA); // prende lo sheet delle unit<69> di misura
|
||
f.record()->renum_key(UMART_CODART, m.get(F_CODICE));
|
||
err = f.record()->write(true);
|
||
}
|
||
return err;
|
||
}
|
||
|
||
void TDistinta_app::sheet2ini(TSheet_field& s, TConfig& ini)
|
||
{
|
||
if (s.dlg() == F_PARAMS)
|
||
{
|
||
parms2rel(s.mask());
|
||
const TFixed_string fname("PARAMETRI");
|
||
TFieldref memof(fname, LF_DIST);
|
||
TString memo = memof.read(_therel->curr());
|
||
memo.replace('\n', SAFE_PIPE_CHR);
|
||
memof.write(ini, "112", memo);
|
||
}
|
||
else
|
||
{
|
||
TRelation_application::sheet2ini(s, ini);
|
||
}
|
||
}
|
||
|
||
bool TDistinta_app::remove()
|
||
{
|
||
bool ok = TRelation_application::remove();
|
||
if (ok)
|
||
{
|
||
TMask &m=curr_mask();
|
||
TSheet_field &f= (TSheet_field &)m.field(F_UNITA); // prende lo sheet delle unit<69> di misura
|
||
TLocalisamfile anamag(LF_ANAMAG);
|
||
anamag.put("CODART",m.get(F_CODICE));
|
||
int err=anamag.read();// esiste l'articolo
|
||
switch(err)
|
||
{
|
||
case _iskeynotfound :
|
||
case _isemptyfile :
|
||
case _iseof:
|
||
ok = f.record()->remove()==NOERR;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// db0500 gestione distinte
|
||
///////////////////////////////////////////////////////////
|
||
|
||
int db0500(int argc, char* argv[])
|
||
{
|
||
TDistinta_app a;
|
||
a.run(argc, argv, TR("Distinta base"));
|
||
return 0;
|
||
}
|