campo-sirio/db/db1300.cpp
alex 16258dc547 Patch level : xx.502
Files correlati     :
Ricompilazione Demo : [ ]
Commento            : Riportata la versione 10.05 patch 502


git-svn-id: svn://10.65.10.50/trunk@8388 c028cbd2-c16b-5b4b-a496-9718f37d4682
1999-07-16 14:59:11 +00:00

459 lines
11 KiB
C++
Executable File

#include <applicat.h>
#include <automask.h>
#include <progind.h>
#include <relation.h>
#include <sheet.h>
#include "dblib.h"
#include "db1300a.h"
#include "db0500a.h"
///////////////////////////////////////////////////////////
// TXmas_tree
///////////////////////////////////////////////////////////
class TXmas_tree : public TDistinta_tree
{
TIsamtempfile _dist, _rdist;
// TAssoc_array _ass_dist, _ass_rdist;
protected:
virtual const TRectype& find_head(const TCodice_articolo& art) const;
virtual const TRectype* find_child(const TCodice_articolo& art, int child) const;
public:
void add_branch(TDistinta_tree& dt);
TXmas_tree();
virtual ~TXmas_tree() { }
};
const TRectype& TXmas_tree::find_head(const TCodice_articolo& art) const
{
TRectype& rec = _dist.curr();
rec.put("CODDIST", art);
const int err = ((TXmas_tree*)this)->_dist.read();
if (err != NOERR)
rec.zero();
return rec;
}
const TRectype* TXmas_tree::find_child(const TCodice_articolo& art, int child) const
{
/*
TString80 key; key << art << '|' << child;
TRectype* rec = (TRectype*)_ass_rdist.objptr(key);
if (rec == NULL)
{
TLocalisamfile& righe = (TLocalisamfile&)_rdist;
righe.put("CODDIST", art);
righe.put("NRIG", child);
const int err = righe.read();
if (err == NOERR)
{
rec = new TRectype(righe.curr());
((TXmas_tree*)this)->_ass_rdist.add(key, rec);
}
}
return rec;
*/
TLocalisamfile& righe = (TLocalisamfile&)_rdist;
righe.put("CODDIST", art);
righe.put("NRIG", child);
const int err = righe.read();
return err == NOERR ? &righe.curr() : NULL;
}
void TXmas_tree::add_branch(TDistinta_tree& dt)
{
TString old_node; dt.curr_id(old_node); // Memorizza posizione
while (dt.has_father())
{
const real qta = dt.last_qta();
if (qta.is_zero())
break; // Inutile proseguire
TCodice_um um; dt.curr_um(um);
TCodice_articolo art; dt.curr_code(art);
if (find_head(art).empty())
{
TRectype& rec = _dist.curr();
rec = cache().get(LF_DIST, art);
if (rec.empty())
{
rec.put("CODDIST", art);
}
rec.write(_dist);
}
dt.goto_father();
TCodice_articolo father; dt.curr_code(father);
TString80 level; dt.curr_giaclev(level);
const TRectype* child = NULL;
for (int c = 1; ; c++)
{
child = find_child(art, c);
if (child == NULL)
break;
if (child->get("CODCOMP") != father)
continue;
if (!level.blank() && child->get("LIVELLO") != level)
continue;
if (child->get_real("EXPR") == qta)
break;
}
if (child == NULL)
{
TRectype& curr = _rdist.curr();
curr.put("CODDIST", art);
curr.put("NRIG", c);
curr.put("TIPO", "A");
curr.put("CODCOMP", father);
curr.put("LIVELLO", level);
curr.put("UM", um);
curr.put("EXPR", qta);
curr.write(_rdist);
}
}
dt.goto_node(old_node); // Ripristina posizione
}
TXmas_tree::TXmas_tree()
: _dist(LF_DIST, NULL, TRUE, TRUE), _rdist(LF_RDIST, NULL, TRUE, TRUE)
{
}
///////////////////////////////////////////////////////////
// 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, "Implosione",
numlev == 4 ? "Tipo|Codice@20|Liv.1@10|Liv.2@6|Liv.3@6|Liv.4@6|UM|Quantita'@18R|Liv.@R|Sort@8R" :
numlev == 3 ? "Tipo|Codice@20|Liv.1@10|Liv.2@6|Liv.3@6|UM|Quantita'@18R|Liv.@R|Sort@8R" :
numlev == 2 ? "Tipo|Codice@20|Liv.1@10|Liv.2@6|UM|Quantita'@18R|Liv.@R|Sort@8R" :
numlev == 1 ? "Tipo|Codice@20|Liv.1@10|UM|Quantita'@18R|Liv.@R|Sort@8R" :
"Tipo|Codice@20|UM|Quantita'@18R|Liv.@R|Sort@8R")
{
}
///////////////////////////////////////////////////////////
// Display_mask
///////////////////////////////////////////////////////////
class TDisplay_mask : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TDisplay_mask() : TAutomask("db1300b") { }
virtual ~TDisplay_mask() { }
};
bool TDisplay_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_EXPLODE:
if (e == fe_button)
{
TXmas_tree& tree = (TXmas_tree&)*tfield(F_TREE).tree();
if (tree.goto_root())
{
TCodice_articolo art; tree.curr_code(art);
TString80 caption; caption << "Lista d'implosione " << art;
TMask m("db0500c");
m.set_caption(caption);
m.set(F_ARTICOLI, "X");
m.set(F_LAVORAZIONI, "X");
m.set(F_VIRTUALI, "X");
if (m.run() == K_ENTER)
{
TCodgiac_livelli livgiac;
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);
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, "Elaborazione in corso...", FALSE, FALSE);
tree.explode(a.rows_array(), mb, gr, md, fi, sk);
}
a.run();
}
}
}
break;
default:
break;
}
return TRUE;
}
///////////////////////////////////////////////////////////
// Implosion_mask
///////////////////////////////////////////////////////////
class TImplosion_mask : public TAutomask
{
TXmas_tree* _xmas;
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
void implode();
void display();
TImplosion_mask();
virtual ~TImplosion_mask();
};
bool TImplosion_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_RESETVARS:
if (e == fe_button)
{
TSheet_field& vars = sfield(F_VARS);
if (vars.items() > 0)
{
vars.destroy();
delete _xmas;
_xmas = new TXmas_tree;
}
}
break;
default:
break;
}
return TRUE;
}
struct TImplosion_parameters
{
TCodice_articolo _art;
TString80 _liv;
TXmas_tree* _xmas;
};
HIDDEN bool implode_callback(TTree& tree, void* jolly, word flags)
{
if (flags == SCAN_PRE_ORDER)
{
TImplosion_parameters* ip = (TImplosion_parameters*)jolly;
TDistinta_tree& dt = (TDistinta_tree&)tree;
TCodice_articolo code; dt.curr_code(code);
if (code == ip->_art)
{
if (ip->_liv.blank())
ip->_xmas->add_branch(dt);
else
{
TString80 curliv; dt.curr_giaclev(curliv);
if (ip->_liv == curliv)
ip->_xmas->add_branch(dt);
}
}
}
return FALSE;
}
void TImplosion_mask::implode()
{
TRelation rel(LF_DIST);
TRectype dist_f(LF_DIST), dist_t(LF_DIST);
dist_f.put("CODDIST", get(F_DA_ARTICOLO));
dist_t.put("CODDIST", get(F_AD_ARTICOLO));
TCursor cur(&rel, "", 1, &dist_f, &dist_t);
long items = 0;
if (get_bool(F_USECATMER))
{
rel.add(LF_ANAMAG, "CODART==CODDIST");
const TString& cm = get(F_CATMER);
const int cmlen = cm.len();
TString filter;
filter << LF_ANAMAG << "->GRMERC";
if (cmlen > 0 && cmlen < 5)
filter << "[1," << cmlen << ']';
filter << "=\"" << cm << '"';
cur.setfilter(filter, TRUE);
TIndwin iw(0, "Creazione lista articoli da esplodere...", FALSE, FALSE);
items = cur.items();
}
else
{
TWait_cursor hourglass;
items = cur.items();
}
cur.freeze();
TString caption;
caption << "Esplosione di " << items << " articoli in corso...";
TProgind pi(items, caption, TRUE, TRUE);
TSheet_field& vars = sfield(F_VARS);
const TRectype& curr = cur.curr();
TString livello;
TCodgiac_livelli livgiac;
TDistinta_tree dt;
TImplosion_parameters ip;
ip._art = get(F_ARTICOLO);
ip._xmas = _xmas;
for (cur = 0L; cur.pos() < items; ++cur)
{
pi.addstatus(1);
if (pi.iscancelled()) break;
if (vars.items() == 0) vars.row(-1); // Crea almeno una riga vuota
// Scansione di tutte le righe abilitate
FOR_EACH_SHEET_ROW(vars, r, row) if (vars.cell_enabled(r, 0))
{
dt.clear_globals();
dt.set_global("_IMPIANTO", row->get(0));
dt.set_global("_LINEA", row->get(1));
dt.set_global("_MAGAZZINO", row->get(2));
dt.set_global("_DEPOSITO", row->get(3));
vars.check_row(r);
livgiac.pack_maskgrpcodes(livello, vars.sheet_mask(), 105, 4);
dt.set_root(curr.get("CODDIST"), "", 1.0, livello);
dt.scan_depth_first(implode_callback, &ip);
}
}
FOR_EACH_SHEET_ROW(vars, r, row)
vars.disable_cell(r, -1);
vars.force_update();
pi.set_text("Espansione dell'albero di implosione...");
do_events();
livgiac.pack_maskgrpcodes(livello, *this, F_LEV1, 4);
_xmas->set_root(ip._art, "", 1.0, livello);
_xmas->expand_all();
}
void TImplosion_mask::display()
{
TDisplay_mask* m = new TDisplay_mask;
TTree_field& tf = m->tfield(F_TREE);
tf.set_tree(_xmas);
m->run();
delete m;
}
TImplosion_mask::TImplosion_mask() : TAutomask("db1300a")
{
_xmas = new TXmas_tree;
TCodgiac_livelli liv;
liv.set_sheet_columns(sfield(F_VARS), 105);
}
TImplosion_mask::~TImplosion_mask()
{ delete _xmas; }
///////////////////////////////////////////////////////////
// Implosion Application
///////////////////////////////////////////////////////////
class TImplosion : public TSkeleton_application
{
TImplosion_mask* _impl;
public:
virtual bool create();
virtual void on_firm_change();
virtual void main_loop();
virtual bool destroy();
void reset_tree();
};
bool TImplosion::create()
{
open_files(LF_TAB, LF_TABCOM, LF_DIST, LF_RDIST, LF_ANAMAG, LF_UMART, NULL);
_impl = new TImplosion_mask;
return TSkeleton_application::create();
}
void TImplosion::on_firm_change()
{
TCodgiac_livelli livgiac;
for (int i = 1; i <= 4; i++)
_impl->enable(F_LEV1+i-1, livgiac.enabled(i));
}
void TImplosion::main_loop()
{
while (_impl->run() != K_QUIT)
{
_impl->implode();
_impl->display();
}
}
bool TImplosion::destroy()
{
delete _impl;
return TSkeleton_application::destroy();
}
int db1300(int argc, char* argv[])
{
TImplosion bum;
bum.run(argc, argv, "Implosione");
return 0;
}