2007-06-21 14:20:08 +00:00
|
|
|
#include "ve2400.h"
|
|
|
|
#include "ve2401.h"
|
2007-07-12 11:00:23 +00:00
|
|
|
#include "../db/dblib.h"
|
2007-06-21 14:20:08 +00:00
|
|
|
|
|
|
|
#include <automask.h>
|
|
|
|
#include <diction.h>
|
|
|
|
#include <recset.h>
|
2009-11-03 15:52:58 +00:00
|
|
|
#include <utility.h>
|
2007-06-21 14:20:08 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Utility per gestione struttura codice avanzato
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const TString& root_code()
|
|
|
|
{
|
2007-07-12 11:00:23 +00:00
|
|
|
static TString8 _root_code; // Solitamente lungo 3, ma stiamo larghi
|
2007-06-21 14:20:08 +00:00
|
|
|
if (_root_code.empty())
|
|
|
|
{
|
2007-06-26 09:56:34 +00:00
|
|
|
const TString query = "USE FSA SELECT B0=\"X\"";
|
2007-06-21 14:20:08 +00:00
|
|
|
TISAM_recordset set(query);
|
|
|
|
if (set.move_first())
|
|
|
|
_root_code = set.get("CODTAB").as_string();
|
|
|
|
else
|
|
|
|
_root_code = " "; // Evito riletture inutili
|
|
|
|
}
|
|
|
|
return _root_code;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TRectype& get_sublevel_info(const TString& code)
|
|
|
|
{
|
|
|
|
return cache().get("FSA", code.full() ? code : root_code());
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
2010-02-24 22:59:50 +00:00
|
|
|
// Maschera dinamica per inserimento codici
|
2007-06-21 14:20:08 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TCodart_mask : public TAutomask
|
|
|
|
{
|
2007-07-12 11:00:23 +00:00
|
|
|
static TCodice_articolo _restart;
|
2009-10-23 14:17:03 +00:00
|
|
|
TString80 _children;
|
2009-11-03 15:52:58 +00:00
|
|
|
TString80 _separators;
|
2010-02-24 22:59:50 +00:00
|
|
|
TString80 _prompts;
|
|
|
|
bool _add_descr;
|
2007-06-26 11:06:18 +00:00
|
|
|
|
2007-06-21 14:20:08 +00:00
|
|
|
protected:
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2007-07-12 11:00:23 +00:00
|
|
|
void start_run();
|
2007-06-21 14:20:08 +00:00
|
|
|
void create_level(int level, const TString& subcode);
|
2007-07-12 11:00:23 +00:00
|
|
|
bool build_children();
|
2007-06-21 14:20:08 +00:00
|
|
|
|
|
|
|
public:
|
2007-06-26 11:06:18 +00:00
|
|
|
bool restart() const { return _restart.full(); }
|
2008-01-17 11:12:05 +00:00
|
|
|
static void restart_with(const TString& cod) { _restart = cod; }
|
2009-10-23 14:17:03 +00:00
|
|
|
const TString & get_descr_separator(const int level);
|
2009-12-03 15:05:19 +00:00
|
|
|
int get_descr_order(const int level);
|
2010-02-24 22:59:50 +00:00
|
|
|
const bool add_descr() { return _add_descr; }
|
2007-06-26 11:06:18 +00:00
|
|
|
|
2007-06-21 14:20:08 +00:00
|
|
|
TCodart_mask();
|
|
|
|
};
|
|
|
|
|
2007-07-12 11:00:23 +00:00
|
|
|
TCodice_articolo TCodart_mask::_restart;
|
2007-06-26 11:06:18 +00:00
|
|
|
|
2007-06-21 14:20:08 +00:00
|
|
|
bool TCodart_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
switch (o.dlg())
|
|
|
|
{
|
|
|
|
case 101:
|
2007-07-12 11:00:23 +00:00
|
|
|
if (e == fe_modify && !o.empty()) // Se cambio il contenuto del primo livello ...
|
2007-06-26 11:06:18 +00:00
|
|
|
{
|
2007-07-12 11:00:23 +00:00
|
|
|
_restart = o.get();
|
|
|
|
stop_run(K_FORCE_CLOSE);
|
2007-06-26 11:06:18 +00:00
|
|
|
}
|
2007-06-21 14:20:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-07-12 11:00:23 +00:00
|
|
|
void TCodart_mask::start_run()
|
|
|
|
{
|
|
|
|
first_focus(101);
|
|
|
|
if (_restart.full())
|
|
|
|
{
|
|
|
|
const TString r(_restart);
|
|
|
|
bool spegni101 = false;
|
|
|
|
int from = 0;
|
|
|
|
for (short id = 101; id2pos(id) >= 0; id++)
|
|
|
|
{
|
|
|
|
const int len = efield(id).size();
|
|
|
|
const TString16 part = r.mid(from, len);
|
|
|
|
if (part.not_empty())
|
|
|
|
{
|
|
|
|
set(id, part);
|
|
|
|
from += len;
|
|
|
|
if (id == 101)
|
|
|
|
{
|
|
|
|
if (build_children())
|
|
|
|
first_focus(102);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
spegni101 = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
_restart.cut(0);
|
|
|
|
enable(101, !spegni101);
|
|
|
|
}
|
|
|
|
TAutomask::start_run();
|
|
|
|
}
|
|
|
|
|
2009-12-03 15:05:19 +00:00
|
|
|
int TCodart_mask::get_descr_order(const int level)
|
|
|
|
{
|
|
|
|
int order = 0;
|
|
|
|
const int pos = 48 + (level - 1);
|
|
|
|
|
|
|
|
if (level > 0 && _separators.len() >= pos)
|
|
|
|
{
|
|
|
|
char ord = _separators[pos];
|
|
|
|
|
|
|
|
if (ord > ' ')
|
|
|
|
order = ord - '0';
|
|
|
|
}
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
2009-10-23 14:17:03 +00:00
|
|
|
const TString & TCodart_mask::get_descr_separator(const int level)
|
|
|
|
{
|
|
|
|
TString & sep = get_tmp_string(8);
|
|
|
|
|
|
|
|
if (level > 0)
|
|
|
|
{
|
2009-11-03 15:52:58 +00:00
|
|
|
sep = _separators.mid((level - 1)*6, 6);
|
|
|
|
sep.trim();
|
|
|
|
sep = esc(sep);
|
2009-10-23 14:17:03 +00:00
|
|
|
}
|
|
|
|
return (const TString & )sep;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-21 14:20:08 +00:00
|
|
|
void TCodart_mask::create_level(int level, const TString& subcode)
|
|
|
|
{
|
|
|
|
const TRectype& fsa = get_sublevel_info(subcode);
|
|
|
|
if (!fsa.empty())
|
|
|
|
{
|
|
|
|
const TString4 code = fsa.get("CODTAB"); // Puo' essere diverso da subcode!
|
2010-02-24 22:59:50 +00:00
|
|
|
TString80 prompt = fsa.get("S0");
|
2010-02-28 23:31:58 +00:00
|
|
|
if (level > 1)
|
2010-02-24 22:59:50 +00:00
|
|
|
{
|
2010-02-28 23:31:58 +00:00
|
|
|
TString16 gprompt = _prompts.mid((level - 2) * 10, 10);
|
2010-02-28 22:00:38 +00:00
|
|
|
gprompt.trim();
|
|
|
|
if (gprompt.blank() || !prompt.starts_with(gprompt))
|
2010-02-24 22:59:50 +00:00
|
|
|
prompt = gprompt;
|
|
|
|
}
|
|
|
|
prompt.left_just(30);
|
2007-06-21 14:20:08 +00:00
|
|
|
const TString& picture = fsa.get("S1");
|
|
|
|
const int length = picture.len();
|
|
|
|
|
2007-07-12 11:00:23 +00:00
|
|
|
TEdit_field& kfld = add_string(100+level, 0, prompt, 1, level, length, "BU");
|
2007-06-21 14:20:08 +00:00
|
|
|
TEdit_field& dfld = add_string(200+level, 0, "", 40, level, 36, "D");
|
|
|
|
|
|
|
|
TFilename tmp; tmp.temp();
|
|
|
|
ofstream out(tmp);
|
|
|
|
|
|
|
|
out << "USE GSA" << endl; //usa la tabella dei sottolivelli articolo
|
|
|
|
|
|
|
|
out << "IN CODTAB[1,3] \"" << code << "\" SELECT" << endl;
|
|
|
|
out << "IN CODTAB[4,0] " << kfld.dlg() << endl;
|
|
|
|
out << "DI \"" << prompt;
|
|
|
|
if (length > prompt.len())
|
|
|
|
out << '@' << length;
|
|
|
|
out << "\" CODTAB[4,0]" << endl;
|
|
|
|
out << "DI \"" << HR("Descrizione") << "@50\" S0" << endl;
|
|
|
|
out << "OU " << kfld.dlg() << " CODTAB[4,0]" << endl;
|
|
|
|
out << "OU " << dfld.dlg() << " S0" << endl;
|
|
|
|
|
|
|
|
out << "CH RE" << endl;
|
|
|
|
out << "EN" << endl;
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
TScanner scan(tmp);
|
|
|
|
while (scan.pop() != "EN")
|
|
|
|
kfld.parse_item(scan);
|
|
|
|
|
2009-11-03 15:52:58 +00:00
|
|
|
xvt_fsys_remove_file(tmp);
|
2007-06-21 14:20:08 +00:00
|
|
|
set_handlers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-12 11:00:23 +00:00
|
|
|
bool TCodart_mask::build_children()
|
2007-06-21 14:20:08 +00:00
|
|
|
{
|
|
|
|
TString8 code = root_code();
|
|
|
|
code << get(101);
|
2007-07-09 08:01:05 +00:00
|
|
|
|
|
|
|
// Non usare qui un TString& children, altrimenti cambia sul piu' bello!
|
2009-10-23 14:17:03 +00:00
|
|
|
_children = cache().get("GSA", code, "S1");
|
2009-11-03 15:52:58 +00:00
|
|
|
_separators = cache().get("GSA", code, "S2");
|
2010-02-28 23:31:58 +00:00
|
|
|
_prompts = cache().get("GSA", code, "S4");
|
|
|
|
_prompts.left(10);
|
|
|
|
_prompts.rpad(10);
|
|
|
|
_prompts << cache().get("GSA", code, "S3");
|
2010-02-24 22:59:50 +00:00
|
|
|
_add_descr = cache().get("GSA", code, "B0").full();
|
2008-01-17 11:12:05 +00:00
|
|
|
|
|
|
|
// Affetto la stringona S1 in sottocodici da 3 caratteri l'uno
|
2007-07-09 08:01:05 +00:00
|
|
|
for (int i = 0; i < 9; i++)
|
2007-06-21 14:20:08 +00:00
|
|
|
{
|
2009-10-23 14:17:03 +00:00
|
|
|
const TString4 subcode = _children.mid(i*3, 3);
|
2007-06-21 14:20:08 +00:00
|
|
|
if (subcode.full())
|
|
|
|
create_level(i+2, subcode);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
force_update();
|
2007-07-12 11:00:23 +00:00
|
|
|
return id2pos(102) > 0;
|
2007-06-21 14:20:08 +00:00
|
|
|
}
|
|
|
|
|
2010-04-15 23:06:48 +00:00
|
|
|
TCodart_mask::TCodart_mask() : TAutomask(TR("Articolo guidato"), 1, 78, 21)
|
2007-06-21 14:20:08 +00:00
|
|
|
{
|
|
|
|
add_button(DLG_OK, 0, "", -12, -1, 10, 2);
|
|
|
|
add_button(DLG_CANCEL, 0, "", -22, -1, 10, 2);
|
|
|
|
create_level(1, EMPTY_STRING);
|
|
|
|
}
|
|
|
|
|
2007-07-09 10:28:38 +00:00
|
|
|
bool advanced_codart_ask(TString& code, TString& desc)
|
2007-06-21 14:20:08 +00:00
|
|
|
{
|
2007-06-26 11:06:18 +00:00
|
|
|
bool ok = false;
|
|
|
|
bool running = true;
|
2007-07-09 10:28:38 +00:00
|
|
|
|
|
|
|
if (code.full())
|
|
|
|
TCodart_mask::restart_with(code);
|
2007-07-12 11:00:23 +00:00
|
|
|
code.cut(0);
|
|
|
|
desc.cut(0);
|
2007-07-09 10:28:38 +00:00
|
|
|
|
2007-06-26 11:06:18 +00:00
|
|
|
while (running)
|
2007-06-21 14:20:08 +00:00
|
|
|
{
|
2007-06-26 11:06:18 +00:00
|
|
|
TCodart_mask m;
|
|
|
|
ok = m.run() == K_ENTER;
|
|
|
|
if (ok)
|
2009-12-03 15:05:19 +00:00
|
|
|
{
|
|
|
|
int order[20];
|
|
|
|
int elements = 0;
|
|
|
|
int id;
|
2010-04-18 22:55:27 +00:00
|
|
|
const bool add_des = m.add_descr();
|
|
|
|
const int start_id = add_des ? 101 : 102;
|
2009-12-03 15:05:19 +00:00
|
|
|
|
2010-04-18 22:55:27 +00:00
|
|
|
order[0] = 0;
|
|
|
|
for (id = start_id; m.id2pos(id) >= 0; id++, elements++)
|
2009-12-03 15:05:19 +00:00
|
|
|
{
|
|
|
|
const int el = id - 101;
|
|
|
|
order[el] = m.get_descr_order(el);
|
|
|
|
code << m.get(id);
|
|
|
|
}
|
2010-04-15 23:06:48 +00:00
|
|
|
|
2009-12-03 15:05:19 +00:00
|
|
|
while (elements-- > 0)
|
|
|
|
{
|
|
|
|
int ord = 1000;
|
|
|
|
int el = -1;
|
2010-02-24 22:59:50 +00:00
|
|
|
|
|
|
|
for (id = start_id; m.id2pos(id) >= 0; id++)
|
2009-12-03 15:05:19 +00:00
|
|
|
{
|
2010-04-18 22:55:27 +00:00
|
|
|
if (order[id - 101] < ord)
|
2009-12-03 15:05:19 +00:00
|
|
|
{
|
2010-04-18 22:55:27 +00:00
|
|
|
el = id - 101;
|
2009-12-03 15:05:19 +00:00
|
|
|
ord = order[el];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (el >= 0)
|
|
|
|
{
|
2010-04-14 13:52:02 +00:00
|
|
|
const int dlg = el + 101;
|
2009-12-03 15:05:19 +00:00
|
|
|
order[el] = 1001;
|
2010-04-15 23:06:48 +00:00
|
|
|
if (desc.full())
|
2009-12-03 15:05:19 +00:00
|
|
|
desc << m.get_descr_separator(el);
|
2010-04-18 22:55:27 +00:00
|
|
|
desc << esc(m.get(dlg + 100));
|
2009-12-03 15:05:19 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-26 11:06:18 +00:00
|
|
|
running = false;
|
2007-06-25 15:43:58 +00:00
|
|
|
}
|
2007-06-26 11:06:18 +00:00
|
|
|
else
|
|
|
|
running = m.restart();
|
2007-06-21 14:20:08 +00:00
|
|
|
}
|
2007-06-25 15:43:58 +00:00
|
|
|
return ok;
|
2007-06-21 14:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Essenzialissima interfaccia pubblica
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool advanced_codart_enabled()
|
|
|
|
{
|
|
|
|
return root_code().full();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool advanced_codart_handler(TMask_field& fld, KEY key)
|
|
|
|
{
|
|
|
|
if (key == K_SPACE)
|
|
|
|
{
|
2007-06-25 15:43:58 +00:00
|
|
|
TString code, desc;
|
2007-07-09 10:28:38 +00:00
|
|
|
if (advanced_codart_ask(code, desc))
|
2007-06-25 15:43:58 +00:00
|
|
|
{
|
|
|
|
TMask& msk = fld.mask();
|
2009-10-23 14:17:03 +00:00
|
|
|
TString desc1 = desc.mid(50);
|
|
|
|
|
|
|
|
desc = desc.left(50);
|
2007-06-25 15:43:58 +00:00
|
|
|
msk.set(F_DESCR, desc);
|
2009-10-23 14:17:03 +00:00
|
|
|
msk.set(F_DESCRAGG, desc1);
|
2007-06-25 15:43:58 +00:00
|
|
|
msk.set(F_CODART, code, true);
|
2007-06-26 11:06:18 +00:00
|
|
|
msk.field(F_CODART).set_focus();
|
2007-06-25 15:43:58 +00:00
|
|
|
}
|
2007-06-21 14:20:08 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|