From f2c81b4290f69752174d404fde574a084727792a Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 29 Aug 1997 16:37:26 +0000 Subject: [PATCH] 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 --- include/form.cpp | 225 +++++++++++++++++++++++++---------------------- include/form.h | 8 +- 2 files changed, 125 insertions(+), 108 deletions(-) diff --git a/include/form.cpp b/include/form.cpp index 05e45c2bc..4d5568473 100755 --- a/include/form.cpp +++ b/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,,[!!...],{|[!!...]} // dove: è 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; iput(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; iget(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,, - // dove: nome tabella da leggere - // costante stringa o riferimento a campo della form (preceduto da '#') da usare come chiave di ricerca - // identificativo del campo da leggere dalla tabella + } + + if (code== "_TABLEREAD") + { + // lettura generica di un campo di una tabella + // sintassi: _TABLEREAD,,, + // dove: nome tabella da leggere + // costante stringa o riferimento a campo della form (preceduto da '#') da usare come chiave di ricerca + // 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,[,][,...] // dove: è 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|} // dove: è 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 diff --git a/include/form.h b/include/form.h index 5c9baec2f..7babdc24e 100755 --- a/include/form.h +++ b/include/form.h @@ -778,10 +778,12 @@ public: // @cmember Ritorna l'altezza effettiva del campo virtual int effective_height() const { return _effective_height; } + // @cmember Formatta la stringa

. 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

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);