Corretta put_paragraph (da controllare) apply_format e vari validate
git-svn-id: svn://10.65.10.50/trunk@5139 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
8af278924f
commit
f2c81b4290
225
include/form.cpp
225
include/form.cpp
@ -1461,7 +1461,8 @@ bool TForm_string::read()
|
||||
|
||||
void TForm_string::put_paragraph(const char* s)
|
||||
{
|
||||
if (hidden()) return;
|
||||
if (hidden()) return;
|
||||
|
||||
const int h = height();
|
||||
|
||||
if (h > 1)
|
||||
@ -1489,25 +1490,30 @@ void TForm_string::put_paragraph(const char* s)
|
||||
}
|
||||
_effective_height = i;
|
||||
}
|
||||
else
|
||||
string_at(-1, _y, s);
|
||||
else
|
||||
{
|
||||
if (_prompt.empty())
|
||||
string_at(x(), _y, s);
|
||||
else
|
||||
string_at(-1 , _y, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TForm_string::apply_format(TString& s, const TString& p) const
|
||||
void TForm_string::apply_format(TString& s) const
|
||||
{
|
||||
TString tmp(s);
|
||||
if (!p.blank())
|
||||
if (!picture().blank())
|
||||
{
|
||||
TToken_string delim(4, ','); // Stringa con i due delimitatori
|
||||
const char* pic = p; // Picture senza delimitatori
|
||||
const char * pic = picture(); // Picture senza delimitatori
|
||||
|
||||
if (pic[0] == '(') // Se ci sono i delimitatori ...
|
||||
{
|
||||
const int bra = p.find(')');
|
||||
const int bra = picture().find(')');
|
||||
if (bra > 0) // ... cerca la parentesi chiusa
|
||||
{
|
||||
delim = p.sub(1, bra); // memorizza delimitatori
|
||||
delim = picture().sub(1, bra); // memorizza delimitatori
|
||||
pic += bra+1; // toglili dalla picture
|
||||
}
|
||||
}
|
||||
@ -1553,7 +1559,7 @@ bool TForm_string::update()
|
||||
do_message(n);
|
||||
// prende il campo e lo stampa
|
||||
s = get();
|
||||
apply_format(s, picture());
|
||||
apply_format(s);
|
||||
put_paragraph(s);
|
||||
}
|
||||
return TRUE;
|
||||
@ -1562,7 +1568,7 @@ bool TForm_string::update()
|
||||
const char* TForm_string::example() const
|
||||
{
|
||||
TString prova("XXXXXXXXXXXXXXXXXXXXXXXXXX");
|
||||
apply_format(prova, picture());
|
||||
apply_format(prova);
|
||||
const int w = width();
|
||||
if (prova.size() > w && w > 0) prova.cut(w);
|
||||
return strcpy(__tmp_string, prova);
|
||||
@ -1576,7 +1582,6 @@ const char* TForm_string::example() const
|
||||
|
||||
class TForm_number : public TForm_string
|
||||
{
|
||||
void apply_format(real& r, TString& s) const;
|
||||
|
||||
protected: // TForm_string
|
||||
virtual const char* class_name() const { return "NUMERO"; }
|
||||
@ -1593,6 +1598,7 @@ public:
|
||||
void set_decimals(int d) { _height = d; }
|
||||
virtual const char* example() const;
|
||||
virtual void set_picture(const char* p);
|
||||
virtual void apply_format(TString& s) const;
|
||||
virtual void put_paragraph(const char * s);
|
||||
|
||||
TForm_number(TPrint_section* section) : TForm_string(section) {}
|
||||
@ -1640,26 +1646,20 @@ bool TForm_number::update()
|
||||
|
||||
if (!n.is_zero())
|
||||
{
|
||||
TString s;
|
||||
real n(get());
|
||||
apply_format(n,s);
|
||||
TString s(get());
|
||||
apply_format(s);
|
||||
put_paragraph(s);
|
||||
// do_message();
|
||||
}
|
||||
else
|
||||
{
|
||||
// const int nm = (_message.objptr(1) != NULL ? 1 : 0);
|
||||
// do_message(nm);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void TForm_number::apply_format(real& n , TString& s) const
|
||||
void TForm_number::apply_format(TString& s) const
|
||||
{
|
||||
if (!picture().blank())
|
||||
{
|
||||
{
|
||||
real n(s);
|
||||
TToken_string delim(4, ','); // Stringa con i due delimitatori
|
||||
TString pic(picture()); // Picture senza delimitatori
|
||||
int maxlen = -1;
|
||||
@ -1711,7 +1711,7 @@ void TForm_number::apply_format(real& n , TString& s) const
|
||||
s << d; // ... aggiungilo alla fine
|
||||
}
|
||||
}
|
||||
else s = n.string();
|
||||
// else s = n.string();
|
||||
}
|
||||
|
||||
void TForm_number::set_picture(const char *p)
|
||||
@ -1723,9 +1723,8 @@ void TForm_number::set_picture(const char *p)
|
||||
|
||||
const char* TForm_number::example() const
|
||||
{
|
||||
real n("123456789120.00"); n.round(2);
|
||||
TString s;
|
||||
apply_format(n,s);
|
||||
TString s("123456789120.00");
|
||||
apply_format(s);
|
||||
return strcpy(__tmp_string, s);
|
||||
}
|
||||
|
||||
@ -4633,7 +4632,8 @@ bool TForm::validate(TForm_item &cf, TToken_string &s)
|
||||
const TString code(s.get(0)); // prende il primo parametro, il codice del messaggio
|
||||
TString valore;
|
||||
|
||||
if (code=="_ISAMREAD") {
|
||||
if (code=="_ISAMREAD")
|
||||
{
|
||||
// lettura generica di un file del database
|
||||
// sintassi: _ISAMREAD,<file>,<espressione input>[!<espressione input>!...],{<campo file>|<espressione output>[!<espressione output>!...]}
|
||||
// dove: <file> è il numero logico del file o il nome della tabella
|
||||
@ -4649,17 +4649,22 @@ bool TForm::validate(TForm_item &cf, TToken_string &s)
|
||||
else file= new TTable(f_code); // altrimenti è una tabella
|
||||
file->zero(); // vuota il record corrente del file
|
||||
TToken_string in(s.get(), '!');
|
||||
for (i=0; i<in.items(); i++) { // scansione sugli elementi dell'input
|
||||
for (i=0; i<in.items(); i++)
|
||||
{ // scansione sugli elementi dell'input
|
||||
TString curr(in.get(i));
|
||||
poseq= curr.find("=="); // divide la stringa corrente in lvalue e rvalue
|
||||
if (poseq== -1) {
|
||||
if (poseq== -1)
|
||||
{
|
||||
poseq= curr.find('=');
|
||||
if (poseq != -1) posrv= poseq+1;
|
||||
} else posrv= poseq+2;
|
||||
}
|
||||
else
|
||||
posrv= poseq+2;
|
||||
TString fld(curr.left(poseq)); // preleva il nome del campo del file alla sinistra dell'uguale
|
||||
TString expr(curr.mid(posrv)); // preleva l'espressione di assegnamento alla destra dell'uguale
|
||||
TExpression rval(expr, _strexpr);
|
||||
for (j=0; j<rval.numvar(); j++) { // scansione delle variabili dell'espressione di rvalue
|
||||
for (j=0; j<rval.numvar(); j++)
|
||||
{ // scansione delle variabili dell'espressione di rvalue
|
||||
TString var= rval.varname(j);
|
||||
if (var[0]=='#') var.ltrim(1); // rimuove dalla stringa il primo carattere
|
||||
TForm_item &fi= cf.find_field(var);
|
||||
@ -4667,71 +4672,92 @@ bool TForm::validate(TForm_item &cf, TToken_string &s)
|
||||
}
|
||||
file->put(fld, (const char *)rval); // scrive il risultato dell'espressione nel campo del file
|
||||
}
|
||||
if (file->read()== NOERR) { // tenta una lettura del file
|
||||
if (file->read()== NOERR)
|
||||
{ // tenta una lettura del file
|
||||
TToken_string out(s.get(), '!');
|
||||
for (i=0; i<out.items(); i++) { // scansione sugli elementi dell'output
|
||||
for (i=0; i<out.items(); i++)
|
||||
{ // scansione sugli elementi dell'output
|
||||
TString curr(out.get(i));
|
||||
poseq= curr.find("=="); // divide la stringa corrente in lvalue e rvalue
|
||||
if (poseq== -1) {
|
||||
if (poseq== -1)
|
||||
{
|
||||
poseq= curr.find('=');
|
||||
if (poseq != -1) posrv= poseq+1;
|
||||
} else posrv= poseq+2;
|
||||
if (poseq== -1) {
|
||||
}
|
||||
else
|
||||
posrv= poseq+2;
|
||||
if (poseq== -1)
|
||||
{
|
||||
const TString &dat= file->get(curr); // preleva il nome del campo del file e lo legge dal record
|
||||
cf.put_paragraph(dat);
|
||||
} else {
|
||||
cf.set(dat);
|
||||
}
|
||||
else
|
||||
{
|
||||
TString fld(curr.left(poseq)); // preleva il nome del campo del form alla sinistra dell'uguale
|
||||
const TString &dat= file->get(curr.mid(posrv)); // preleva il nome del campo del file alla destra dell'uguale e lo legge dal record
|
||||
if (fld[0]=='#') fld.ltrim(1);
|
||||
if (fld.right(1)== "@") { // se c'è la a-commerciale è un gruppo
|
||||
if (fld.find("->") != -1) { // se nel gruppo c'è la freccia si riferisce ad un'altra sezione
|
||||
if (fld.right(1)== "@")
|
||||
{ // se c'è la a-commerciale è un gruppo
|
||||
if (fld.find("->") != -1)
|
||||
{ // se nel gruppo c'è la freccia si riferisce ad un'altra sezione
|
||||
sec= fld[0];
|
||||
if (fld[1] != '-') pt= char2page(fld[1]);
|
||||
else pt= even_page;
|
||||
itms= section(sec, pt).fields();
|
||||
} else { // altrimenti si riferisce alla sezione corrente
|
||||
}
|
||||
else
|
||||
{ // altrimenti si riferisce alla sezione corrente
|
||||
sec= cf.section().section_type();
|
||||
pt= cf.section().page_type();
|
||||
itms= cf.section().fields();
|
||||
}
|
||||
for (j=0; j<itms; j++) { // per ogni campo della sezione specificata (o sottointesa)...
|
||||
for (j=0; j<itms; j++)
|
||||
{ // per ogni campo della sezione specificata (o sottointesa)...
|
||||
TForm_item &fi= section(sec, pt).field(j);
|
||||
fi.put_paragraph(dat);
|
||||
fi.set(dat);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
TForm_item &fi= cf.find_field(fld);
|
||||
fi.put_paragraph(dat);
|
||||
fi.set(dat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete file;
|
||||
return (TRUE);
|
||||
return TRUE;
|
||||
// fine _ISAMREAD
|
||||
} else if (code== "_TABLEREAD") {
|
||||
// lettura generica di un campo di una tabella
|
||||
// sintassi: _TABLEREAD,<tabella>,<chiave>,<campo file>
|
||||
// dove: <tabella> nome tabella da leggere
|
||||
// <chiave> costante stringa o riferimento a campo della form (preceduto da '#') da usare come chiave di ricerca
|
||||
// <campo file> identificativo del campo da leggere dalla tabella
|
||||
}
|
||||
|
||||
if (code== "_TABLEREAD")
|
||||
{
|
||||
// lettura generica di un campo di una tabella
|
||||
// sintassi: _TABLEREAD,<tabella>,<chiave>,<campo file>
|
||||
// dove: <tabella> nome tabella da leggere
|
||||
// <chiave> costante stringa o riferimento a campo della form (preceduto da '#') da usare come chiave di ricerca
|
||||
// <campo file> identificativo del campo da leggere dalla tabella
|
||||
TTable tab(s.get()); // prende il nome della tabella
|
||||
tab.zero(); // vuota il record corrente della tabella
|
||||
TString in(s.get()); // prende il valore o il campo da usare come codice di ricerca
|
||||
if (in[0]== '#') {
|
||||
in.ltrim(1);
|
||||
TForm_item &fi= cf.find_field(in);
|
||||
in= fi.get();
|
||||
if (in[0]== '#')
|
||||
{
|
||||
in.ltrim(1);
|
||||
TForm_item &fi= cf.find_field(in);
|
||||
in= fi.get();
|
||||
}
|
||||
tab.put("CODTAB", in); // setta la chiave nella tabella
|
||||
if (tab.read()== NOERR) {
|
||||
if (tab.read()== NOERR)
|
||||
{
|
||||
const TString &fld= s.get(); // prende il nome del campo da leggere...
|
||||
valore = tab.get(fld);
|
||||
cf.set(valore);
|
||||
cf.put_paragraph(valore);
|
||||
}
|
||||
return (TRUE);
|
||||
return TRUE;
|
||||
} // fine _TABLEREAD
|
||||
else if (code== "_ALIGN") {
|
||||
|
||||
if (code== "_ALIGN")
|
||||
{
|
||||
// allineamento della posizione di un campo rispetto ad un altro
|
||||
// sintassi: _ALIGN,<campo form>[,<allineamento>][,<allineamento>...]
|
||||
// dove: <campo form> è il campo della form (preceduto da '#') da cui prendere l'allineamento
|
||||
@ -4744,68 +4770,55 @@ bool TForm::validate(TForm_item &cf, TToken_string &s)
|
||||
TString in(s.get());
|
||||
if (in[0]== '#') in.ltrim(1);
|
||||
TForm_item &fi= cf.find_field(in);
|
||||
const int width = cf.width();
|
||||
valore = cf.get();
|
||||
TString clear(width);
|
||||
TString picture(cf.picture());
|
||||
clear.spaces();
|
||||
|
||||
int i= 2;
|
||||
short save_x = cf.x();
|
||||
short save_y = cf.y();
|
||||
short save_height = cf.height();
|
||||
cf.height() = 2; // Solo temporaneamente per far si' che stampi alla giusta posizione
|
||||
cf.set(clear);
|
||||
cf.put_paragraph(clear);
|
||||
while (i<s.items()) { // Calcola la nuova posizione
|
||||
TString align(s.get());
|
||||
if (align[0]=='!') align.ltrim(1);
|
||||
for (const char * cmd = s.get(); cmd != NULL; cmd = s.get())
|
||||
{ // Calcola la nuova posizione
|
||||
TString align(cmd);
|
||||
if (align[0]=='!')
|
||||
align.ltrim(1);
|
||||
|
||||
if (align== "TOP") cf.y()= fi.y();
|
||||
if (align== "MIDDLE") cf.y()= fi.y()+ fi.effective_height()/2;
|
||||
if (align== "BOTTOM") cf.y()= fi.y()+ fi.effective_height()-1;
|
||||
if (align== "LEFT") cf.set_x(fi.x());
|
||||
if (align== "RIGHT") cf.set_x(fi.x()+ fi.width());
|
||||
i++;
|
||||
}
|
||||
real x(valore);
|
||||
if (x.is_real(valore)) // se e' un numero controlla che non sia uguale 0
|
||||
{
|
||||
if (x != 0.0)
|
||||
valore = x.string(picture);
|
||||
else
|
||||
valore = "";
|
||||
else
|
||||
if (align== "MIDDLE") cf.y()= fi.y()+ fi.effective_height()/2;
|
||||
else
|
||||
if (align== "BOTTOM") cf.y()= fi.y()+ fi.effective_height()-1;
|
||||
else
|
||||
if (align== "LEFT") cf.set_x(fi.x());
|
||||
else
|
||||
if (align== "RIGHT") cf.set_x(fi.x()+ fi.width());
|
||||
}
|
||||
// altrimenti stampa la stringa cosi' com'e'
|
||||
cf.set(valore);
|
||||
cf.put_paragraph(valore);
|
||||
cf.y() = save_y;
|
||||
cf.set_x(save_x);
|
||||
cf.height() = save_height;
|
||||
return (TRUE);
|
||||
return TRUE;
|
||||
} // fine _ALIGN
|
||||
else if (code== "_PAGENO") // Messaggio per stampare il numero di pagina corrente
|
||||
|
||||
if (code== "_PAGENO") // Messaggio per stampare il numero di pagina corrente
|
||||
{
|
||||
TString16 pg; pg << int(printer().getcurrentpage() );
|
||||
//cf.put_paragraph(pg);
|
||||
cf.set(pg);
|
||||
return (TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
else if (code== "_TODAY")// Messaggio per stampare la data di oggi
|
||||
|
||||
if (code== "_TODAY")// Messaggio per stampare la data di oggi
|
||||
{
|
||||
TString16 dt(TDate(TODAY).string());
|
||||
cf.set(dt);
|
||||
//cf.put_paragraph(pg);
|
||||
return (TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
else if (code== "_NUMEXPR" || code== "_STREXPR") {
|
||||
// Messaggio per la valutazione di espressioni numeriche e stringhe
|
||||
|
||||
if (code== "_NUMEXPR" || code== "_STREXPR")
|
||||
{
|
||||
// Messaggio per la valutazione di espressioni numeriche e stringhe
|
||||
TExpression rval(s.get(),code[1]=='N' ? _numexpr:_strexpr,TRUE);
|
||||
cf.section().eval_expr(rval);
|
||||
const char *res=(const char *)rval;
|
||||
const char *res = (const char *)rval;
|
||||
if (!rval.error())
|
||||
cf.set(res);
|
||||
return (TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
else if (code== "_DITTA") {
|
||||
|
||||
if (code== "_DITTA")
|
||||
{
|
||||
// lettura dei dati della ditta
|
||||
// sintassi: _DITTA,{<campo relazione>|<macro>}
|
||||
// dove: <campo relazione> è un riferimento alla relazione di gestione dei dati della ditta (es. 113@->DENCOM è la denominazione del comune di residenza della ditta)
|
||||
@ -4896,8 +4909,10 @@ bool TForm::validate(TForm_item &cf, TToken_string &s)
|
||||
valore = fref.read(anag.curr());
|
||||
}
|
||||
cf.set(valore);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void TForm::print_on(ostream& out) const
|
||||
|
@ -778,10 +778,12 @@ public:
|
||||
// @cmember Ritorna l'altezza effettiva del campo
|
||||
virtual int effective_height() const
|
||||
{ return _effective_height; }
|
||||
// @cmember Formatta la stringa <p s>. Funzione che per default non fa nulla.
|
||||
// Ridefinita solo per TForm_number e TForm_string.
|
||||
virtual void apply_format(TString & s) const {}
|
||||
// @cmember Scrive la stringa <p s> alla posizione del TForm_item. Funzione che
|
||||
// per default non fa nulla. Ridefinita solo per TForm_number e TForm_string.
|
||||
virtual void put_paragraph(const char* s)
|
||||
{};
|
||||
virtual void put_paragraph(const char* s) {}
|
||||
|
||||
// @cmember Ritorna se si tratta di una campo temporaneo (reference)
|
||||
virtual bool& temp()
|
||||
@ -1041,7 +1043,6 @@ protected:
|
||||
virtual bool read();
|
||||
virtual bool update();
|
||||
virtual const char* example() const;
|
||||
virtual void apply_format(TString & s, const TString & p) const;
|
||||
|
||||
virtual TToken_string& memo_info() { return _memo; }
|
||||
|
||||
@ -1055,6 +1056,7 @@ public:
|
||||
virtual const int fields() { return _field.items();}
|
||||
virtual const TString& picture() const { return _picture; }
|
||||
virtual void set_picture(const char* p) { _picture = p; }
|
||||
virtual void apply_format(TString & s) const;
|
||||
virtual void put_paragraph(const char* s);
|
||||
|
||||
virtual bool edit(TMask& m);
|
||||
|
Loading…
x
Reference in New Issue
Block a user