Patch level : 12.0 no-patch
Files correlati : fp Commento : Aggiunto parser che legge una sintassi molto semplice per riempire le personalizzazioni di Campo, attualmente sono funzioni statiche, non ho ancora deciso se tenerle così
This commit is contained in:
parent
68b7da3923
commit
2cc174f686
@ -269,6 +269,8 @@ protected:
|
|||||||
bool export_paf0100f();
|
bool export_paf0100f();
|
||||||
bool export_paf3200f();
|
bool export_paf3200f();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Record clifo
|
// Record clifo
|
||||||
//void set_rec_clifo(char tipocf, long codcf);
|
//void set_rec_clifo(char tipocf, long codcf);
|
||||||
|
|
||||||
@ -284,7 +286,14 @@ public:
|
|||||||
int commit();
|
int commit();
|
||||||
int force_commit();
|
int force_commit();
|
||||||
void set_cache_insert(const bool v) { _cache_insert = v; }
|
void set_cache_insert(const bool v) { _cache_insert = v; }
|
||||||
|
|
||||||
|
// Test
|
||||||
|
static const TString& parse_expression(const TString& expr, TRiga_documento& rdoc);
|
||||||
|
static TString& parse_read(const TString& str, TRiga_documento& rdoc);
|
||||||
|
static TString& do_read(const TString& tabella, const TString& campo, TRiga_documento& rdoc);
|
||||||
|
static TString& parse_search(const TString& str, TRiga_documento& rdoc);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TDoc_fp();
|
TDoc_fp();
|
||||||
~TDoc_fp();
|
~TDoc_fp();
|
||||||
|
@ -1408,6 +1408,163 @@ bool TDoc_fp::export_paf3200f()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sintassi:
|
||||||
|
* READ(TABELLA, CAMPO) -> legge dalle tabelle predefinite
|
||||||
|
* SEARCH(TABELLA, CAMPO, RICERCA) -> legge da una tabella qualsiasi
|
||||||
|
* SEARCH e READ sono diverse sotto richiesta di Ilaria per avere una sintassi più chiara
|
||||||
|
* resto: TExpr_documento()
|
||||||
|
*/
|
||||||
|
const TString& TDoc_fp::parse_expression(const TString& expr, TRiga_documento& rdoc)
|
||||||
|
{
|
||||||
|
const TToken_string exprs(expr, '+');
|
||||||
|
TString& result = get_tmp_string().cut(0);
|
||||||
|
TExpr_documento expr_documento(_mixexpr, &rdoc.doc(), &rdoc);
|
||||||
|
|
||||||
|
FOR_EACH_STR_TOKEN(exprs, str)
|
||||||
|
{
|
||||||
|
// Come prima cosa trimmo la vita
|
||||||
|
str.trim();
|
||||||
|
if(str.starts_with("READ(", true))
|
||||||
|
{
|
||||||
|
result << parse_read(str, rdoc);
|
||||||
|
} else if(str.starts_with("SEARCH(", true))
|
||||||
|
{
|
||||||
|
result << parse_search(str, rdoc);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
// Controllo non sia una ricerca a DB con il punto
|
||||||
|
if(expr.contains("->"))
|
||||||
|
{
|
||||||
|
// Se contiene una freccia non posso fare un TToken_string easy
|
||||||
|
// Non esistono campi con -> vero?
|
||||||
|
str.replace("->", ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Questo diventa true se sono passato sopra o effettivamente ha un punto dall'inizio
|
||||||
|
if(expr.contains('.'))
|
||||||
|
{
|
||||||
|
TToken_string simple_field(expr, '.');
|
||||||
|
result << do_read(simple_field.get(0), simple_field.get(), rdoc);
|
||||||
|
}
|
||||||
|
// Se inizia come una stringa o non contiene parentesi -> no expr
|
||||||
|
else if (str.starts_with("\"") || !(str.contains("(") && str.contains(")")))
|
||||||
|
{
|
||||||
|
str.replace("\"", "");
|
||||||
|
result << str;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
expr_documento.set(str, _mixexpr);
|
||||||
|
result << expr_documento.as_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void extract_info(const TString& expr, TString& tabella, TString& campo, TToken_string* search)
|
||||||
|
{
|
||||||
|
// Prendo la stringa pulita della parte sinistra
|
||||||
|
TString clean_expr = expr.mid(expr.find('(') + 1);
|
||||||
|
// Tolgo eventuali spazi ai lati
|
||||||
|
clean_expr.trim();
|
||||||
|
// Tolgo la virgola finale
|
||||||
|
clean_expr.rtrim(1);
|
||||||
|
TToken_string info(clean_expr, ',');
|
||||||
|
|
||||||
|
// Trimmare sempre come se non sapessi fare altro nella vita
|
||||||
|
tabella.cut(0) << info.remove(0); tabella.trim();
|
||||||
|
campo.cut(0) << info.remove(0); campo.trim();
|
||||||
|
if(search != nullptr)
|
||||||
|
{
|
||||||
|
// Prendo il resto
|
||||||
|
search->cut(0) << info;
|
||||||
|
search->trim();
|
||||||
|
search->restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool calc_table(const TString& tabella, int& file)
|
||||||
|
{
|
||||||
|
file = atoi(tabella);
|
||||||
|
if (file == 0)
|
||||||
|
file = table2logic(tabella);
|
||||||
|
return is_multi_table(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
TString& TDoc_fp::parse_read(const TString& str, TRiga_documento& rdoc)
|
||||||
|
{
|
||||||
|
TString tabella, campo;
|
||||||
|
|
||||||
|
extract_info(str, tabella, campo, nullptr);
|
||||||
|
|
||||||
|
return do_read(tabella, campo, rdoc);
|
||||||
|
}
|
||||||
|
|
||||||
|
TString& TDoc_fp::do_read(const TString& tabella, const TString& campo, TRiga_documento& rdoc)
|
||||||
|
{
|
||||||
|
TString& result = get_tmp_string().cut(0);
|
||||||
|
int file;
|
||||||
|
|
||||||
|
bool multi_table = calc_table(tabella, file);
|
||||||
|
|
||||||
|
switch (file)
|
||||||
|
{
|
||||||
|
case LF_DOC:
|
||||||
|
result = rdoc.doc().get(campo);
|
||||||
|
break;
|
||||||
|
case LF_RIGHEDOC:
|
||||||
|
result = rdoc.get(campo);
|
||||||
|
break;
|
||||||
|
case LF_CLIFO:
|
||||||
|
result = rdoc.doc().clifor().get(campo);
|
||||||
|
break;
|
||||||
|
case LF_CFVEN:
|
||||||
|
result = rdoc.doc().clifor().vendite().get(campo);
|
||||||
|
break;
|
||||||
|
case LF_LETINT:
|
||||||
|
result = rdoc.doc().clifor().lettera().get(campo);
|
||||||
|
break;
|
||||||
|
case LF_ANAMAG:
|
||||||
|
result = rdoc.articolo().get(campo);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Skip
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
TString& TDoc_fp::parse_search(const TString& str, TRiga_documento& rdoc)
|
||||||
|
{
|
||||||
|
TString& result = get_tmp_string();
|
||||||
|
|
||||||
|
TString tabella, campo;
|
||||||
|
TToken_string input_search, search;
|
||||||
|
int file;
|
||||||
|
|
||||||
|
extract_info(str, tabella, campo, &input_search);
|
||||||
|
const bool multi_table = calc_table(tabella, file);
|
||||||
|
|
||||||
|
// Parso ogni singolo token della ricerca
|
||||||
|
FOR_EACH_TOKEN(input_search, tok)
|
||||||
|
{
|
||||||
|
search.add(parse_expression(tok, rdoc));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(multi_table)
|
||||||
|
{
|
||||||
|
result.cut(0) << cache().get(tabella, search, campo);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
result.cut(0) << cache().get(file, search, campo);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TDoc_fp::doc_to_paf(TDocumentoEsteso& doc)
|
bool TDoc_fp::doc_to_paf(TDocumentoEsteso& doc)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user