1996-08-21 15:30:23 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <expr.h>
|
|
|
|
#include <msksheet.h>
|
1996-08-23 13:01:51 +00:00
|
|
|
#include <progind.h>
|
1996-08-21 15:30:23 +00:00
|
|
|
#include <relation.h>
|
1996-08-23 13:01:51 +00:00
|
|
|
#include <stack.h>
|
|
|
|
#include <tabutil.h>
|
1996-08-21 15:30:23 +00:00
|
|
|
#include <urldefid.h>
|
|
|
|
#include <viswin.h>
|
|
|
|
|
|
|
|
#include "ve4.h"
|
|
|
|
#include "ve4100.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
1996-08-23 13:01:51 +00:00
|
|
|
// TTable_expression
|
1996-08-21 15:30:23 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
1996-08-23 13:01:51 +00:00
|
|
|
class TTable_expression : public TExpression
|
|
|
|
{
|
|
|
|
static TAssoc_array _expr;
|
1996-08-23 15:56:24 +00:00
|
|
|
static const TRelation* _rel;
|
1996-08-23 13:01:51 +00:00
|
|
|
|
|
|
|
protected:
|
1996-08-23 15:56:24 +00:00
|
|
|
virtual void evaluate_user_func(const char* name, int nparms,
|
|
|
|
TStack& stack, TTypeexp curtype) const;
|
|
|
|
|
|
|
|
int str2file(const TString& s) const;
|
|
|
|
void load_expr();
|
|
|
|
const TRelation& get_relation() const { CHECK(_rel, "NULL relation"); return *_rel; }
|
|
|
|
const char* get_var(const char* v) const;
|
|
|
|
|
1996-08-23 13:01:51 +00:00
|
|
|
public:
|
1996-08-23 15:56:24 +00:00
|
|
|
void set_relation(const TRelation& rel) { _rel = &rel; }
|
|
|
|
|
1996-08-23 13:01:51 +00:00
|
|
|
TTable_expression(TTypeexp t) : TExpression(t) { }
|
|
|
|
TTable_expression(const char* expr, TTypeexp t) : TExpression(expr, t) { }
|
|
|
|
virtual ~TTable_expression() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
TAssoc_array TTable_expression::_expr;
|
1996-08-23 15:56:24 +00:00
|
|
|
const TRelation* TTable_expression::_rel = NULL;
|
1996-08-23 13:01:51 +00:00
|
|
|
|
|
|
|
void TTable_expression::load_expr()
|
|
|
|
{
|
|
|
|
if (_expr.items() == 0)
|
|
|
|
{
|
|
|
|
TString n(15), e(127);
|
|
|
|
TTable expr("%FRM");
|
|
|
|
for (expr.first(); !expr.eof(); expr.next())
|
|
|
|
{
|
|
|
|
n = expr.get("CODTAB");
|
|
|
|
e = expr.get("S1");
|
|
|
|
e << expr.get("S2");
|
|
|
|
const TTypeexp t = expr.get_bool("B0") ? _numexpr : _strexpr;
|
|
|
|
_expr.add(n, new TTable_expression(e, t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1996-08-21 15:30:23 +00:00
|
|
|
|
1996-08-23 15:56:24 +00:00
|
|
|
int TTable_expression::str2file(const TString& str) const
|
|
|
|
{
|
|
|
|
HIDDEN const char* const s = "AUDCR";
|
|
|
|
HIDDEN const int logicnum[] = { LF_ANAMAG, LF_UMART, LF_DESLIN, LF_CONDV, LF_RCONDV };
|
|
|
|
const char* p = strchr(s, str[0]);
|
|
|
|
CHECKS(p, "Identificatore di file errato: ", (const char*)str);
|
|
|
|
const int ln = logicnum[p-s];
|
|
|
|
return ln;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* TTable_expression::get_var(const char* v) const
|
|
|
|
{
|
|
|
|
TString var(v);
|
|
|
|
int logicnum = 0;
|
|
|
|
const int arrow = var.find("->");
|
|
|
|
if (arrow > 0)
|
|
|
|
{
|
|
|
|
logicnum = str2file(var);
|
|
|
|
var = var.mid(arrow+2);
|
|
|
|
}
|
|
|
|
const char* val = "";
|
|
|
|
if (get_relation().exist(logicnum))
|
|
|
|
{
|
|
|
|
const TFieldref fr(var, logicnum);
|
|
|
|
val = fr.read(get_relation());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NFCHECK("Il campo %s non appartiene alla relazione.", v);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TTable_expression::evaluate_user_func(const char* name, int nparms,
|
|
|
|
TStack& stack, TTypeexp curtype) const
|
1996-08-21 15:30:23 +00:00
|
|
|
{
|
1996-08-23 13:01:51 +00:00
|
|
|
TTable_expression* expr = (TTable_expression*)_expr.objptr(name);
|
|
|
|
if (expr == NULL)
|
|
|
|
{
|
1996-08-23 15:56:24 +00:00
|
|
|
TExpression::evaluate_user_func(name, nparms, stack, curtype);
|
1996-08-23 13:01:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1996-08-23 15:56:24 +00:00
|
|
|
// Assegna i valori a tutte le variabili dell'espressione
|
1996-08-23 13:01:51 +00:00
|
|
|
TString var;
|
|
|
|
for (int v = expr->numvar()-1; v >= 0; v--)
|
1996-08-21 15:30:23 +00:00
|
|
|
{
|
1996-08-23 13:01:51 +00:00
|
|
|
var = expr->varname(v); var.upper();
|
|
|
|
if (var[0] == '_') // Parametro della funzione
|
|
|
|
{
|
|
|
|
const int n = atoi(var.mid(2,0));
|
1996-08-23 15:56:24 +00:00
|
|
|
CHECKS(n > 0 && n <= nparms, "Parametro errato ", (const char*)var);
|
|
|
|
if (curtype == _numexpr)
|
|
|
|
expr->setvar(var, (real&)stack.peek(nparms-n));
|
|
|
|
else
|
|
|
|
expr->setvar(var, (TString&)stack.peek(nparms-n));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char* val = get_var(var);
|
|
|
|
if (curtype == _numexpr)
|
|
|
|
expr->setvar(var, real(val));
|
|
|
|
else
|
|
|
|
expr->setvar(var, TString(val));
|
1996-08-23 13:01:51 +00:00
|
|
|
}
|
1996-08-21 15:30:23 +00:00
|
|
|
}
|
1996-08-23 13:01:51 +00:00
|
|
|
|
1996-08-23 15:56:24 +00:00
|
|
|
// Toglie i parametri dallo stack
|
|
|
|
for (int p = nparms; p > 0; p--)
|
1996-08-23 13:01:51 +00:00
|
|
|
stack.pop();
|
1996-08-23 15:56:24 +00:00
|
|
|
|
|
|
|
// Mette il risultato sullo stack
|
|
|
|
if (curtype == _numexpr)
|
|
|
|
stack.push((const real&)expr);
|
|
|
|
else
|
|
|
|
stack.push((const TString&)expr);
|
1996-08-23 13:01:51 +00:00
|
|
|
}
|
1996-08-21 15:30:23 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Maschera ricalcolo di magazzino
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TRicalcolo_mask : public TMask
|
|
|
|
{
|
|
|
|
TArray _rel, _des;
|
|
|
|
int _cur_file;
|
|
|
|
TToken_string _key_expr;
|
|
|
|
|
1996-08-23 13:01:51 +00:00
|
|
|
TRelation* _relation;
|
|
|
|
TCursor* _cursor;
|
|
|
|
|
1996-08-21 15:30:23 +00:00
|
|
|
protected:
|
|
|
|
static bool file_handler (TMask_field& f, KEY k);
|
|
|
|
static bool key_handler (TMask_field& f, KEY k);
|
|
|
|
static bool filter_handler(TMask_field& f, KEY k);
|
|
|
|
static bool field_handler (TMask_field& f, KEY k);
|
|
|
|
static bool fromto_handler(TMask_field& f, KEY k);
|
1996-08-23 13:01:51 +00:00
|
|
|
|
|
|
|
bool gestione_um(char tipo) const;
|
1996-08-21 15:30:23 +00:00
|
|
|
TRelation& get_rel() const;
|
|
|
|
const TRectype& get_rec() const;
|
|
|
|
const RecDes* get_rec_des() const;
|
1996-08-23 13:01:51 +00:00
|
|
|
TToken_string& get_key_expr(int k);
|
|
|
|
|
|
|
|
TRelation& create_relation();
|
|
|
|
TCursor& create_cursor();
|
1996-08-21 15:30:23 +00:00
|
|
|
|
1996-08-23 13:01:51 +00:00
|
|
|
public:
|
|
|
|
bool elabora();
|
|
|
|
|
1996-08-21 15:30:23 +00:00
|
|
|
TRicalcolo_mask();
|
|
|
|
virtual ~TRicalcolo_mask() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
TRicalcolo_mask::TRicalcolo_mask()
|
1996-08-23 13:01:51 +00:00
|
|
|
: TMask("ve4100"), _cur_file(0), _relation(NULL), _cursor(NULL)
|
1996-08-21 15:30:23 +00:00
|
|
|
{
|
1996-08-23 13:01:51 +00:00
|
|
|
const int lf[] = { LF_ANAMAG, LF_UMART, LF_DESLIN, LF_CONDV, LF_RCONDV, 0 };
|
1996-08-21 15:30:23 +00:00
|
|
|
for (int i = 0; lf[i]; i++)
|
|
|
|
{
|
|
|
|
TRelation* rel = new TRelation(lf[i]);
|
|
|
|
_rel.add(rel);
|
|
|
|
_des.add(new TRelation_description(*rel));
|
|
|
|
}
|
|
|
|
|
|
|
|
set_handler(F_FILE, file_handler);
|
|
|
|
set_handler(F_KEY, key_handler);
|
|
|
|
set_handler(F_FILTER, filter_handler);
|
|
|
|
|
|
|
|
TSheet_field& fields = (TSheet_field&)field(F_FIELDS);
|
|
|
|
TMask& fsm = fields.sheet_mask();
|
|
|
|
fsm.set_handler(F_FIELD, field_handler);
|
|
|
|
fsm.set_handler(F_FROM, fromto_handler);
|
|
|
|
fsm.set_handler(F_TO, fromto_handler);
|
|
|
|
|
|
|
|
TSheet_field& outputs = (TSheet_field&)field(F_OUTPUTS);
|
|
|
|
TMask& osm = outputs.sheet_mask();
|
|
|
|
osm.set_handler(F_FIELD, field_handler);
|
|
|
|
outputs.row(-1); // Aggiunge comunque una riga vuota;
|
|
|
|
osm.force_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
TRelation& TRicalcolo_mask::get_rel() const
|
|
|
|
{
|
|
|
|
return (TRelation&)_rel[_cur_file];
|
|
|
|
}
|
|
|
|
|
|
|
|
const TRectype& TRicalcolo_mask::get_rec() const
|
|
|
|
{
|
|
|
|
return get_rel().lfile().curr();
|
|
|
|
}
|
|
|
|
|
|
|
|
const RecDes* TRicalcolo_mask::get_rec_des() const
|
|
|
|
{
|
|
|
|
return get_rec().rec_des();
|
|
|
|
}
|
|
|
|
|
|
|
|
TToken_string& TRicalcolo_mask::get_key_expr(int key)
|
|
|
|
{
|
|
|
|
_key_expr.cut(0);
|
|
|
|
if (key > 0)
|
|
|
|
{
|
|
|
|
const RecDes* rd = get_rec_des();
|
|
|
|
const KeyDes& kd = rd->Ky[key-1];
|
|
|
|
for (int i = 0; i < kd.NkFields; i++)
|
|
|
|
{
|
|
|
|
const int nf = kd.FieldSeq[i] % MaxFields;
|
|
|
|
const RecFieldDes& rf = rd->Fd[nf];
|
|
|
|
_key_expr.add(rf.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _key_expr;
|
|
|
|
}
|
|
|
|
|
1996-08-23 13:01:51 +00:00
|
|
|
bool TRicalcolo_mask::gestione_um(char tipo) const
|
|
|
|
{
|
|
|
|
const char* const lco = "LCO";
|
|
|
|
for (int i = 0; i < 3 && toupper(tipo) != lco[i]; i++);
|
|
|
|
TConfig ve(CONFIG_DITTA, "ve");
|
|
|
|
return ve.get_bool("GESUM", NULL, i+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRelation& TRicalcolo_mask::create_relation()
|
|
|
|
{
|
|
|
|
const int logicnum = get_rec().num(); // Numero logico del file principale
|
|
|
|
|
|
|
|
if (_relation)
|
|
|
|
delete _relation;
|
|
|
|
_relation = new TRelation(logicnum);
|
|
|
|
|
|
|
|
const TString& unita_misura = get(F_UNITA_MISURA);
|
|
|
|
const TString& lingua = get(F_LINGUA);
|
|
|
|
|
|
|
|
const TString& tipo_lco = get(F_TIPO_LCO); // Listini, contratti, offerte
|
|
|
|
const TString& cat_ven = get(F_CAT_VEN);
|
|
|
|
const TString& tipo_cf = get(F_TIPO_CF);
|
|
|
|
const TString& codice_cf = get(F_CODICE_CF);
|
|
|
|
const TString& codice_lco = get(F_CODICE_LCO);
|
|
|
|
|
|
|
|
TString condv_expr;
|
|
|
|
if (cat_ven.not_empty() && codice_cf.not_empty() && codice_lco.not_empty())
|
|
|
|
{
|
|
|
|
condv_expr << "TIPO=\"" << tipo_lco << '"';
|
|
|
|
condv_expr << "|CATVEN=\"" << cat_ven << '"';
|
|
|
|
condv_expr << "|TIPOCF=\"" << tipo_cf << '"';
|
|
|
|
condv_expr << "|CODCF=\"" << codice_cf << '"';
|
|
|
|
condv_expr << "|COD=\"" << codice_lco << '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
TString expr(48);
|
|
|
|
|
|
|
|
switch (logicnum)
|
|
|
|
{
|
|
|
|
case LF_ANAMAG:
|
|
|
|
{
|
|
|
|
expr = "CODART=CODART";
|
|
|
|
if (unita_misura.not_empty())
|
|
|
|
{
|
|
|
|
expr << "|UM=\"" << unita_misura << '"';
|
|
|
|
_relation->add(LF_UMART, expr, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_relation->add(LF_UMART, expr, 1);
|
|
|
|
|
|
|
|
if (lingua.not_empty())
|
|
|
|
{
|
|
|
|
expr = "CODART=CODART";
|
|
|
|
expr << "|CODLIN=\"" << lingua << '"';
|
|
|
|
_relation->add(LF_DESLIN, expr, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (condv_expr.not_empty())
|
|
|
|
{
|
|
|
|
_relation->add(LF_CONDV, condv_expr, 1);
|
|
|
|
|
|
|
|
if (unita_misura.not_empty())
|
|
|
|
{
|
|
|
|
expr = condv_expr;
|
|
|
|
expr << "|TIPORIGA=\"A\"";
|
|
|
|
expr << "|CODRIGA=CODART";
|
|
|
|
expr << "|UM=\"" << unita_misura << '"';
|
|
|
|
_relation->add(LF_RCONDV, expr, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LF_UMART:
|
|
|
|
{
|
|
|
|
_relation->add(LF_ANAMAG, "CODART=CODART", 1);
|
|
|
|
|
|
|
|
if (lingua.not_empty())
|
|
|
|
{
|
|
|
|
expr = "CODART=CODART";
|
|
|
|
expr << "|CODLIN=\"" << lingua << '"';
|
|
|
|
_relation->add(LF_DESLIN, expr, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (condv_expr.not_empty())
|
|
|
|
{
|
|
|
|
_relation->add(LF_CONDV, condv_expr, 1);
|
|
|
|
expr = condv_expr;
|
|
|
|
expr << "|TIPORIGA=\"A\"";
|
|
|
|
expr << "|CODRIGA=CODART";
|
|
|
|
expr << "|UM=UM";
|
|
|
|
_relation->add(LF_RCONDV, expr, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LF_DESLIN:
|
|
|
|
{
|
|
|
|
_relation->add(LF_ANAMAG, "CODART=CODART", 1);
|
|
|
|
|
|
|
|
expr = "CODART=CODART";
|
|
|
|
if (unita_misura.not_empty())
|
|
|
|
{
|
|
|
|
expr << "|UM=\"" << unita_misura << '"';
|
|
|
|
_relation->add(LF_UMART, expr, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_relation->add(LF_UMART, expr, 1);
|
|
|
|
|
|
|
|
if (condv_expr.not_empty())
|
|
|
|
{
|
|
|
|
_relation->add(LF_CONDV, condv_expr, 1);
|
|
|
|
|
|
|
|
if (unita_misura.not_empty())
|
|
|
|
{
|
|
|
|
expr = condv_expr;
|
|
|
|
expr << "|TIPORIGA=\"A\"";
|
|
|
|
expr << "|CODRIGA=CODART";
|
|
|
|
expr << "|UM=\"" << unita_misura << '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LF_RCONDV:
|
|
|
|
{
|
|
|
|
_relation->add(LF_ANAMAG, "CODRIGA=CODART", 1);
|
|
|
|
|
|
|
|
if (gestione_um(tipo_lco[0]))
|
|
|
|
_relation->add(LF_UMART, "CODRIGA=CODART|UM=UM", 2);
|
|
|
|
|
|
|
|
if (lingua.not_empty())
|
|
|
|
{
|
|
|
|
expr = "CODRIGA=CODART";
|
|
|
|
expr << "|CODLIN=\"" << lingua << '"';
|
|
|
|
_relation->add(LF_DESLIN, expr, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
_relation->add(LF_RCONDV, "TIPO=TIPO|CATVEN=CATVEN|TIPOCF=TIPOCF|CODCF=CODCF|COD=COD", 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return *_relation;
|
|
|
|
}
|
|
|
|
|
|
|
|
TCursor& TRicalcolo_mask::create_cursor()
|
|
|
|
{
|
|
|
|
TString filter = get(F_FILTER); filter.strip("\n");
|
|
|
|
|
|
|
|
int key = get_int(F_KEY);
|
|
|
|
|
|
|
|
TRectype start(get_rec()), stop(get_rec());
|
|
|
|
start.zero(); stop.zero();
|
|
|
|
|
|
|
|
TToken_string& key_des = get_key_expr(key);
|
|
|
|
|
|
|
|
TSheet_field& fs = (TSheet_field&)field(F_FIELDS);
|
|
|
|
TString field, val;
|
|
|
|
bool key_seq = key > 0; // I primi campi corrispondono alla chiave selezionata?
|
|
|
|
|
|
|
|
for (int r = 0; r < fs.items(); r++)
|
|
|
|
{
|
|
|
|
TToken_string& row = fs.row(r);
|
|
|
|
field = row.get(0);
|
|
|
|
if (field.not_empty())
|
|
|
|
{
|
|
|
|
if (key_seq && key_des.get_pos(field) == r)
|
|
|
|
{
|
|
|
|
val = row.get();
|
|
|
|
if (val.not_empty()) start.put(field, val);
|
|
|
|
val = row.get();
|
|
|
|
if (val.not_empty()) stop.put(field, val);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
key_seq = FALSE;
|
|
|
|
val = row.get();
|
|
|
|
if (val.not_empty())
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << field << ">=" << val << ')';
|
|
|
|
}
|
|
|
|
val = row.get();
|
|
|
|
if (val.not_empty())
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << field << "<=" << val << ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key <= 0)
|
|
|
|
key = 1;
|
|
|
|
|
|
|
|
if (_cursor)
|
|
|
|
delete _cursor;
|
|
|
|
_cursor = new TCursor(&create_relation(), filter, key, &start, &stop);
|
|
|
|
return *_cursor;
|
|
|
|
}
|
|
|
|
|
1996-08-21 15:30:23 +00:00
|
|
|
bool TRicalcolo_mask::file_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
TRicalcolo_mask& m = (TRicalcolo_mask&)f.mask();
|
|
|
|
if (k == K_SPACE)
|
|
|
|
{
|
|
|
|
const int n = atoi(f.get());
|
|
|
|
if (n != m._cur_file || !m.is_running())
|
|
|
|
{
|
|
|
|
m._cur_file = n;
|
|
|
|
const RecDes* rd = m.get_rec_des();
|
|
|
|
const int keys = rd->NKeys;
|
|
|
|
|
|
|
|
TToken_string codes(16);
|
|
|
|
TToken_string values(80);
|
|
|
|
TString16 tmp;
|
|
|
|
codes.add(0);
|
|
|
|
values.add("Nessuna");
|
|
|
|
for (int k = 1; k <= keys; k++)
|
|
|
|
{
|
|
|
|
codes.add(k);
|
|
|
|
tmp.format("Chiave %d", k);
|
|
|
|
values.add(tmp);
|
|
|
|
}
|
|
|
|
TList_field& lk = (TList_field&)m.field(F_KEY);
|
|
|
|
lk.replace_items(codes, values);
|
|
|
|
if (atoi(lk.get()) != 0)
|
|
|
|
lk.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRicalcolo_mask::key_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
if (k == K_SPACE)
|
|
|
|
{
|
|
|
|
TRicalcolo_mask& m = (TRicalcolo_mask&)f.mask();
|
|
|
|
const int cur_key = atoi(f.get());
|
|
|
|
TToken_string& key_expr = m.get_key_expr(cur_key);
|
|
|
|
const bool empty = key_expr.empty_items();
|
1996-08-23 15:56:24 +00:00
|
|
|
int first_enabled = 0;
|
1996-08-21 15:30:23 +00:00
|
|
|
|
|
|
|
TSheet_field& sheet = (TSheet_field&)m.field(F_FIELDS);
|
|
|
|
TString_array& sa = sheet.rows_array();
|
|
|
|
sa.destroy();
|
|
|
|
if (empty)
|
|
|
|
{
|
|
|
|
for (int i = 4; i >= 0; i--)
|
|
|
|
sa.add("");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRelation_description& des = (TRelation_description&)m._des[m._cur_file];
|
|
|
|
for (TString field = key_expr.get(0); field.not_empty(); field = key_expr.get())
|
|
|
|
{
|
|
|
|
const int r = sa.add(field);
|
|
|
|
sa.row(r).add(des.get_field_description(field), F_DESCR-F_FIELD);
|
|
|
|
}
|
1996-08-23 13:01:51 +00:00
|
|
|
if (des.file_num() == LF_CONDV || des.file_num() == LF_RCONDV)
|
1996-08-23 15:56:24 +00:00
|
|
|
first_enabled = 4;
|
1996-08-23 13:01:51 +00:00
|
|
|
}
|
1996-08-23 15:56:24 +00:00
|
|
|
|
|
|
|
for (int r = sa.items()-1; r >= 0; r--)
|
|
|
|
sheet.enable_cell(0, -1, r >= first_enabled);
|
|
|
|
|
1996-08-21 15:30:23 +00:00
|
|
|
sheet.force_update();
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRicalcolo_mask::filter_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
if (f.to_check(k))
|
|
|
|
{
|
|
|
|
TString filter(f.get()); filter.strip("\n");
|
|
|
|
TExpression expr(_strexpr);
|
|
|
|
ok = expr.set(filter, _strexpr);
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
TRicalcolo_mask& m = (TRicalcolo_mask&)f.mask();
|
|
|
|
const TRectype& rec = m.get_rec();
|
|
|
|
TString var;
|
|
|
|
for (int v = expr.numvar()-1; v >= 0; v--)
|
|
|
|
{
|
|
|
|
var = expr.varname(v); var.upper();
|
|
|
|
ok = rec.exist(var);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
f.error_box("Il campo '%s' non esiste!", (const char*)var);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
f.error_box("Simbolo non riconosciuto: '%s'", expr.last_compiled_token());
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRicalcolo_mask::field_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
switch (k)
|
|
|
|
{
|
|
|
|
case K_TAB:
|
|
|
|
case K_ENTER:
|
|
|
|
if (!f.empty() && f.to_check(k))
|
|
|
|
{
|
|
|
|
TRicalcolo_mask& m = (TRicalcolo_mask&)f.mask().get_sheet()->mask();
|
|
|
|
const TRectype& rec = m.get_rec();
|
|
|
|
const char* field = f.get();
|
|
|
|
if (!rec.exist(field))
|
|
|
|
ok = f.error_box("Il campo %s non esiste!", field);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case K_F9:
|
|
|
|
{
|
|
|
|
TMask& m = f.mask();
|
|
|
|
TRicalcolo_mask& rm = (TRicalcolo_mask&)m.get_sheet()->mask();
|
|
|
|
TRelation_description& rd = (TRelation_description&)rm._des[rm._cur_file];
|
|
|
|
if (rd.choose_field(f.get()))
|
|
|
|
{
|
|
|
|
f.set(rd.field_name());
|
|
|
|
m.set(F_DESCR, rd.field_desc());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRicalcolo_mask::fromto_handler(TMask_field& f, KEY k)
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
if (f.to_check(k))
|
|
|
|
{
|
|
|
|
const TMask& m = f.mask();
|
|
|
|
const TString& field = m.get(F_FIELD);
|
|
|
|
if (field.not_empty())
|
|
|
|
{
|
|
|
|
TRicalcolo_mask& rm = (TRicalcolo_mask&)m.get_sheet()->mask();
|
|
|
|
const TRectype& rec = rm.get_rec();
|
|
|
|
const int max = rec.length(field);
|
|
|
|
if (f.get().len() > max)
|
|
|
|
{
|
1996-08-23 13:01:51 +00:00
|
|
|
TString msg(32); msg = "Inserire ";
|
1996-08-21 15:30:23 +00:00
|
|
|
if (max > 1) msg << max; else msg << "un";
|
1996-08-23 13:01:51 +00:00
|
|
|
msg << " caratter" << (max > 1 ? 'i' : 'e') << " al massimo.";
|
1996-08-21 15:30:23 +00:00
|
|
|
ok = f.error_box(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1996-08-23 13:01:51 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Ciclo principale di elaborazione
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool TRicalcolo_mask::elabora()
|
|
|
|
{
|
|
|
|
TIndwin iw(48, "Inizializzazione ...", TRUE, FALSE, 48);
|
|
|
|
begin_wait();
|
|
|
|
|
|
|
|
TCursor& cur = create_cursor();
|
|
|
|
|
|
|
|
TViswin vw("ve4100.txt", "Ricalcolo valori",
|
|
|
|
FALSE, TRUE, FALSE, 3, 3, -3, -3, FALSE);
|
|
|
|
|
|
|
|
for (cur = 0; cur.ok(); ++cur)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
end_wait();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-08-21 15:30:23 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Ricalcolo di magazzino
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TRicalcola_application : public TApplication
|
1996-08-23 13:01:51 +00:00
|
|
|
{
|
|
|
|
protected:
|
1996-08-21 15:30:23 +00:00
|
|
|
virtual bool menu(MENU_TAG);
|
|
|
|
virtual bool create();
|
|
|
|
|
|
|
|
public:
|
|
|
|
TRicalcola_application() { }
|
|
|
|
virtual ~TRicalcola_application() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TRicalcola_application::create()
|
|
|
|
{
|
|
|
|
dispatch_e_menu(MENU_ITEM(1));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRicalcola_application::menu(MENU_TAG)
|
|
|
|
{
|
|
|
|
TRicalcolo_mask m;
|
|
|
|
while (m.run() == K_ENTER)
|
1996-08-23 13:01:51 +00:00
|
|
|
m.elabora();
|
|
|
|
|
1996-08-21 15:30:23 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ve4100(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TRicalcola_application r;
|
|
|
|
r.run(argc, argv, "Ricalcolo valori");
|
|
|
|
return 0;
|
|
|
|
}
|