From 9ec0e386886b8cd973e0a795bf5d5c7df9c5948b Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 2 Feb 1999 08:43:43 +0000 Subject: [PATCH] Patch level : Files correlati : Ricompilazione Demo : [ ] Commento : Who cares? git-svn-id: svn://10.65.10.50/trunk@7728 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/array.cpp | 2 + include/csort.c | 12 +-- include/currency.cpp | 3 +- include/date.cpp | 2 +- include/default.url | 1 - include/form.cpp | 4 +- include/isam.h | 4 +- include/mask.cpp | 26 ++++++ include/mask.h | 2 + include/maskfld.cpp | 80 ++++++++-------- include/maskfld.h | 3 + include/multirec.cpp | 7 +- include/printer.h | 2 +- include/recarray.cpp | 41 +++++++++ include/recarray.h | 22 +++++ include/relapp.cpp | 8 +- include/relation.cpp | 39 ++++++-- include/relation.h | 2 +- include/stdtypes.h | 6 +- include/strings.cpp | 2 + include/tabapp.cpp | 31 ++++--- include/tabapp.h | 8 +- include/tabutil.cpp | 53 +++++------ include/validate.cpp | 215 ++++++++++++++++++++++++------------------- 24 files changed, 354 insertions(+), 221 deletions(-) diff --git a/include/array.cpp b/include/array.cpp index 8c1e35de1..d94909438 100755 --- a/include/array.cpp +++ b/include/array.cpp @@ -611,6 +611,8 @@ void TPointer_array::copy(const TArray& a) // for (int i = a.size()-1; i >= 0; i--) // add(a.objptr(i), i); memcpy(data(), a.data(), a.size() * sizeof(TObject*)); + _items = a._items; + _next = a._next; } int TPointer_array::add(TObject* object, int index) diff --git a/include/csort.c b/include/csort.c index fcfe15a49..fe77f7c72 100755 --- a/include/csort.c +++ b/include/csort.c @@ -366,27 +366,17 @@ static void dumpbuff() @(FSV) */ -/* @(!) 2.3.00.112 */ -static FILE *wopen(name) - char *name; /* nome del file temporaneo */ - /* @(:) 2.3.00.112 */ +static FILE *wopen(char* name) /* nome del file temporaneo */ { FILE *fp; char s[42]; - /* @(!) 2.3.00.112 */ static int n = 0; - /* @(:) 2.3.00.112 */ - - /* @(!) 2.3.00.316 */ sprintf(s, "srt%02d", ++n); - /* @(:) 2.3.00.316 */ TMPFNAME(name,s); fp = fopen(name, "wb+"); if (fp == NULL) - { fatal_box("Can't open SORT file"); - } return fp; } diff --git a/include/currency.cpp b/include/currency.cpp index f66d80bee..1484b4d5f 100755 --- a/include/currency.cpp +++ b/include/currency.cpp @@ -13,6 +13,7 @@ class TDowJones : public TFile_cache real _chg; // Cambio int _dec; // Decimali per gli importi normali int _dec_prices; // Decimali per i prezzi unitari + int _dec_change; // Decimali per i cambi bool _is_euro; // E' l'EURO in persona bool _contro_euro; // Il cambio e' espresso contro EURO @@ -76,6 +77,7 @@ TObject* TDowJones::rec2obj(const TRectype& rec) const data->_dec_prices = rec.get_int("I1"); if (data->_dec_prices < data->_dec) data->_dec_prices = data->_dec; + data->_dec_change = rec.get_int("I2"); data->_is_euro = rec.get_bool("B0"); data->_contro_euro = rec.get_bool("B1"); } @@ -371,7 +373,6 @@ bool TCurrency::same_value_as(const TCurrency& cur) const return FALSE; } - TCurrency::TCurrency(const real& num, const char* val, const real& exchg, bool price) : _num(num), _price(price) { diff --git a/include/date.cpp b/include/date.cpp index a1733bfe2..6ae981070 100755 --- a/include/date.cpp +++ b/include/date.cpp @@ -454,7 +454,7 @@ bool TDate::isdate(const char* s) y < 0) return FALSE; - return d <= _days_in_month[m - 1] || (m == 2 && (y % 4 == 0) && d == 29); + return d <= last_day(m,y); } diff --git a/include/default.url b/include/default.url index 195884815..ba9d784b1 100755 --- a/include/default.url +++ b/include/default.url @@ -118,7 +118,6 @@ image BMP_CANCEL QRESDIR"cancel.bmp" image BMP_QUIT QRESDIR"quit.bmp" image BMP_QUITDN QRESDIR"quitdn.bmp" image BMP_SELECT QRESDIR"select.bmp" -image BMP_STOP QRESDIR"stop.bmp" //image BMP_FIRSTREC QRESDIR"firstrec.bmp" //image BMP_PREVREC QRESDIR"prevrec.bmp" //image BMP_NEXTREC QRESDIR"nextrec.bmp" diff --git a/include/form.cpp b/include/form.cpp index 2019851ba..4e5fd208c 100755 --- a/include/form.cpp +++ b/include/form.cpp @@ -2504,12 +2504,12 @@ word TPrint_section::height() const { h = subsection_above()->effective_height(); } - if (int(h) < 0) // Can't write h < 0! + if (short(h) < 0) // Can't write h < 0! { if (section_type() == 'F') { h += printer().formlen(); - if (int(h) < 0) // Still < 0 ?? get out... + if (short(h) < 0) // Still < 0 ?? get out... h = 0; } else diff --git a/include/isam.h b/include/isam.h index 0219383a4..5dc774924 100755 --- a/include/isam.h +++ b/include/isam.h @@ -70,8 +70,6 @@ protected: protected: // @cmember Segnalazione di un campo inesistente virtual void unknown_field(const char* name) const; - // @cmember Compara due tipo di record del file (vedi ) - virtual int compare(const TSortable& s) const; // @cmember Ritorna il nome dell'ultimo campo chiave identificato da

const char* last_key_field(int key) const; // @cmember Ritorna il contenuto del campo

-esimo @@ -89,6 +87,8 @@ protected: public: // @cmember Duplica il tipo di record virtual TObject* dup() const; + // @cmember Compara due tipo di record del file (vedi ) + virtual int compare(const TSortable& s) const; // @cmember Legge il file

con il tipo di record virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock); diff --git a/include/mask.cpp b/include/mask.cpp index 9916b884a..ad42df151 100755 --- a/include/mask.cpp +++ b/include/mask.cpp @@ -1632,6 +1632,32 @@ TReal_field& TMask::add_number ( // @doc EXTERNAL +// @mfunc Aggiunge runtime un campo importo alla maschera +// +// @rdesc Ritorna l'handle del campo creato +TCurrency_field& TMask::add_currency ( + short id, // @parm Numero identificatore del campo da aggiungere + int page, // @parm Pagina nel quale aggiungere il campo + const char* prompt, // @parm Prompt del campo + int x, // @parm Coordinata x (in caratteri) + int y, // @parm Coordinata y (in caratteri) + int dim, // @parm Lunghezza del campo sulla maschera + const char* flags, // @parm Flag di controllo del campo (default "") + short driver) // @parm Numero di decimali (default 0) + + // @xref + // +{ + TCurrency_field* f = new TCurrency_field(this); + f->construct(id, prompt, x, y, dim, _pagewin[page], flags, 0); + if (driver != 0) + f->add_driver(driver); + add_field(f); + return *f; +} + +// @doc EXTERNAL + // @mfunc Aggiunge runtime un campo data alla maschera // // @rdesc Ritorna l'handle del campo creato diff --git a/include/mask.h b/include/mask.h index 74a6b2295..87ee3ff2c 100755 --- a/include/mask.h +++ b/include/mask.h @@ -189,6 +189,8 @@ public: // @cmember Aggiunge runtime un campo numerico alla maschera TReal_field& add_number (short id, int page, const char* prompt, int x, int y, int dim, const char* flags = "", int ndec = 0); + // @cmember Aggiunge runtime un campo importo alla maschera + TCurrency_field& add_currency (short id, int page, const char* prompt, int x, int y, int dim, const char* flags = "", short driver = 0); // @cmember Aggiunge runtime un campo data alla maschera TDate_field& add_date (short id, int page, const char* prompt, int x, int y, const char* flags = ""); // @cmember Aggiunge runtime un campo bottone alla maschera diff --git a/include/maskfld.cpp b/include/maskfld.cpp index 2cf8dd60a..d46ac2725 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -1145,6 +1145,43 @@ const char* TEditable_field::prompt() const } +TOperable_field* TEditable_field::add_driver(short id) +{ + TOperable_field* driver = NULL; + if (id < 0) + { + TSheet_field* sheet = mask().get_sheet(); + if (sheet) + { + const int pos = sheet->mask().id2pos(-id); + if (pos >= 0) + driver = &(TOperable_field&)sheet->mask().fld(pos); + } + } + else + { + TOperable_field* driver = NULL; + const int pos = mask().id2pos(id); + if (pos >= 0) + { + driver = &(TOperable_field&)mask().fld(pos); + TString16 msg; + msg.format("CHECK,%d", dlg()); + driver->message(0, TRUE)->add(msg); + } + } + if (driver != NULL) + { + CHECKD(driver->is_kind_of(CLASS_OPERABLE_FIELD), "Field not operable ", id); + if (_drivers == NULL) + _drivers = new TPointer_array; + _drivers->add(driver); + } + else + NFCHECK("Non esiste ancora il campo driver %d", id); + return driver; +} + // Ritorna il messaggio d'errore associato al campo const char* TEditable_field::get_warning() const { return _warning ? (const char*)*_warning : ""; } @@ -1170,45 +1207,11 @@ bool TEditable_field::parse_item(TScanner& scanner) if (k == "DR") // DRIVENBY { - if (_drivers == NULL) - _drivers = new TPointer_array; TToken_string lista(scanner.line(), ' '); FOR_EACH_TOKEN(lista, tok) { - const int id = atoi(tok); - if (id > 0) - { - const int pos = mask().id2pos(id); - if (pos >= 0) - { - TOperable_field& driver = (TOperable_field&)mask().fld(pos); - CHECKD(driver.is_kind_of(CLASS_OPERABLE_FIELD), "Field not operable ", id); - _drivers->add(&driver); - TString16 msg; - msg.format("CHECK,%d", dlg()); - driver.message(0, TRUE)->add(msg); - } - else - NFCHECK("Non esiste ancora il campo driver %d", id); - } - else - { - TSheet_field* sheet = mask().get_sheet(); - if (sheet) - { - const int pos = sheet->mask().id2pos(-id); - if (pos >= 0) - { - TMask_field& driver = sheet->mask().fld(pos); - CHECKD(driver.is_kind_of(CLASS_OPERABLE_FIELD), "Field not operable ", -id); - _drivers->add(&driver); - } - else - NFCHECK("Non esiste il campo driver %d nella maschera principale", id); - } - else - NFCHECK("Non esiste il campo driver %d", id); - } + const short id = atoi(tok); + add_driver(id); } return TRUE; } @@ -3817,7 +3820,10 @@ const char* TCurrency_field::win2raw(const char* data) const else num = real(str); - str = num.string(); + if (num.is_zero()) + str.cut(0); + else + str = num.string(); return str; } diff --git a/include/maskfld.h b/include/maskfld.h index b9416f456..168a53b4a 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -651,6 +651,9 @@ public: // @cmember Ritorna TRUE se il campo e' di tipo editable virtual bool is_editable() const { return TRUE; } + // @cmember Aggiunge un campo driver + TOperable_field* add_driver(short id); + // @cmember Ritorna un eventuale campo driver TOperable_field* driver(int n) const { return _drivers ? (TOperable_field*)_drivers->objptr(n) : NULL; } diff --git a/include/multirec.cpp b/include/multirec.cpp index 35507ea8b..4c64055d3 100755 --- a/include/multirec.cpp +++ b/include/multirec.cpp @@ -264,7 +264,7 @@ TMultiple_rectype & TMultiple_rectype::copy(const TMultiple_rectype& r) int TMultiple_rectype::loaded_rows(int logicnum) const { const int index = log2ind(logicnum); - TRecord_array * r = (TRecord_array *) ((TMultiple_rectype *) this)->_files.objptr(index); + TRecord_array* r = (TRecord_array*) ((TMultiple_rectype *) this)->_files.objptr(index); if (_changed[index] || r == NULL) return 0; @@ -276,6 +276,7 @@ int TMultiple_rectype::compare(const TSortable& s) const { int res = TRectype::compare(s); TMultiple_rectype & m = (TMultiple_rectype &) s; + for (int i = 0 ; res == 0 && i < _logicnums.items(); i++) { const int logicnum = lognum(i); @@ -286,9 +287,9 @@ int TMultiple_rectype::compare(const TSortable& s) const { for (int j = r.last_row(), k = r1.last_row(); res == 0 && j > 0 && k > 0; j = r.pred_row(j), k = r1.pred_row(k)) { - res = j - k; + res = j - k; // Controlla che non ci siano salti if (res == 0) - res = r[j] != r1[j]; + res = r[j].compare(r1[j]); } } } diff --git a/include/printer.h b/include/printer.h index 9c4f3ce38..9c3647632 100755 --- a/include/printer.h +++ b/include/printer.h @@ -448,7 +448,7 @@ public: { return (_formlen=fl); } // @cmember Setta la dimensione del footer int footerlen (int fl) - { return (_footersize=fl); } + { CHECKD(fl >= 0 && fl < 1024, "Bad footerlen ", fl); return _footersize = fl; } // @cmember Setta la dimensione dell'header int headerlen (int hl) { return (_headersize=hl); } diff --git a/include/recarray.cpp b/include/recarray.cpp index 05b21f9a1..eb1d66b96 100755 --- a/include/recarray.cpp +++ b/include/recarray.cpp @@ -683,3 +683,44 @@ const TString& TRecord_cache::get(const char* key, const char* field) return get(key).get(field); } +/////////////////////////////////////////////////////////// +// TDB_cache +/////////////////////////////////////////////////////////// + +TRecord_cache& TDB_cache::cache(int file) +{ + CHECKD(file >= LF_USER && file < LF_EXTERNAL, "Invalid file ", file); + TRecord_cache* rc = (TRecord_cache*)objptr(file); + if (rc == NULL) + { + rc = new TRecord_cache(file); + rc->set_items_limit(file==LF_TAB || file==LF_TABCOM ? 1024 : 256); + rc->test_file_changes(); + add(rc, file); + } + return *rc; +} + +const TRectype& TDB_cache::get(const char* table, const char* key) +{ + CHECK(table && *table, "Invalid Table code"); + + int file = LF_TAB; + if (*table == '%') + { + file = LF_TABCOM; + table++; + } + TString80 tabkey; + tabkey << table << '|' << key; + return get(file, key); +} + +TDB_cache& cache() +{ + static TDB_cache* _frate_cercone = NULL; + if (_frate_cercone == NULL) + _frate_cercone = new TDB_cache; + return *_frate_cercone; +} + diff --git a/include/recarray.h b/include/recarray.h index 2bdf2f09b..1c6597e4a 100755 --- a/include/recarray.h +++ b/include/recarray.h @@ -217,11 +217,33 @@ public: // @cmember ritorna il record con una determinata chiave virtual const TRectype& get(const char* chiave); + // @cmember ritorna il record con una determinata chiave numerica + const TRectype& get(long chiave) + { char str[24]; sprintf(str, "%ld", chiave); return get(str); } + TRecord_cache(int num, int key = 1); TRecord_cache(TLocalisamfile *f, int key = 1); TRecord_cache(const char* table, int key = 1); virtual ~TRecord_cache() { } }; + +class TDB_cache : public TArray +{ +protected: + TRecord_cache& cache(int file); + +public: + const TRectype& get(int file, const char* key) + { return cache(file).get(key); } + + const TRectype& get(int file, long key) + { return cache(file).get(key); } + + const TRectype& get(const char* table, const char* key); +}; + +TDB_cache& cache(); + #endif diff --git a/include/relapp.cpp b/include/relapp.cpp index 1f120dd25..e50c2616c 100755 --- a/include/relapp.cpp +++ b/include/relapp.cpp @@ -657,13 +657,17 @@ int TRelation_application::delete_mode() bool can_delete = FALSE; if (find(1)) { + TRelation& r = *get_relation(); _autodelete = 0x3; - if (!protected_record(get_relation()->curr())) + if (!protected_record(r.curr())) { if (modify_mode()) + { + r.restore_status(); can_delete = remove(); + } + query_mode(); } - query_mode(); _autodelete = FALSE; } if (!can_delete) diff --git a/include/relation.cpp b/include/relation.cpp index 2a0c53f6b..c66e3b289 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -1049,14 +1049,23 @@ TRecnotype TCursor::buildcursor(TRecnotype rp) int TCursor::filtercursor(int pagecnt, TRecnotype* page) { - int np=0; /*, handle = file().handle(); */ - TRectype& rec=file().curr(); - for (int i=0; i< pagecnt; i++) + TLocalisamfile& fil = file(); + TRectype& rec = fil.curr(); + int np = 0; + + for (int i = 0; i < pagecnt; i++) { - file().readat(rec,page[i]); - if (update_relation()) _if->update(); - if ((_filterfunction ? _filterfunction(_if) : TRUE ) && - (_fexpr ? __evalcondition(*_if, _fexpr, _frefs) : TRUE)) + rec.readat(fil,page[i]); + if (update_relation()) + _if->update(); + + bool ok = TRUE; + if (_filterfunction) + ok = _filterfunction(_if); + if (ok && _fexpr) + ok = __evalcondition(*_if, _fexpr, _frefs); + + if (ok) { if (np < i) page[np] = page[i]; np++; @@ -1232,16 +1241,17 @@ void TCursor::setkey(int nkey) int TCursor::test(TIsamop op, TReclock lockop) const { TLocalisamfile& curfile = file(); + const TRectype& currec = curfile.curr(); curfile.setkey(_nkey); int err = NOERR; if (op == _isequal) { - const TString match(curfile.curr().key(_nkey)); + const TString match(currec.key(_nkey)); bool trovato = FALSE; for (err = curfile.read(op, lockop); - err == NOERR && match == curfile.curr().key(_nkey); + err == NOERR && match == currec.key(_nkey); err = curfile.next(lockop)) { if (ok()) @@ -1273,6 +1283,17 @@ int TCursor::test(TIsamop op, TReclock lockop) const { if (lockop != _nolock) curfile.reread(_unlock); + + const TString& kto = to(); + if (kto.not_empty()) + { + const TFixed_string curkey(currec.key(_nkey)); + if (kto.compare(curkey, kto.len()) < 0) + { + err = _iseof; + break; + } + } } } } diff --git a/include/relation.h b/include/relation.h index 8ee13cebb..6b6678bfb 100755 --- a/include/relation.h +++ b/include/relation.h @@ -15,7 +15,7 @@ class TSort; // // @base public | TObject class TRelation : public TObject -// @author:(INTERNAL) Sandro +// @author:(INTERNAL) Alex { // @cfriend TRelationdef friend class TRelationdef; diff --git a/include/stdtypes.h b/include/stdtypes.h index 54724c1fe..32d60a480 100755 --- a/include/stdtypes.h +++ b/include/stdtypes.h @@ -31,7 +31,7 @@ typedef unsigned short UINT16; // @doc EXTERNAL // @type UINT32 | Altro nome di assegnazione per gli unsigned long -#ifdef WIN32 +#if XVT_OS==XVT_OS_WIN32 typedef unsigned int UINT32; #else typedef unsigned long UINT32; @@ -46,7 +46,7 @@ typedef short INT16; // @doc EXTERNAL // @type INT32 | Altro nome di assegnazione per i long -#ifdef WIN32 +#if XVT_OS==XVT_OS_WIN32 typedef int INT32; #else typedef long INT32; @@ -56,7 +56,7 @@ typedef long INT32; // @type bool | Tipo booleano che puo' assumere i valori TRUE (definito come 1) // e FALSE (definito come 0). -#ifdef WIN32 +#if XVT_OS==XVT_OS_WIN32 #ifndef __cplusplus typedef unsigned short bool; diff --git a/include/strings.cpp b/include/strings.cpp index dd0ce27a7..cbb0eb46e 100755 --- a/include/strings.cpp +++ b/include/strings.cpp @@ -1514,6 +1514,8 @@ bool TToken_string::get( *p = _separator; } } + else + tok.cut(0); return found; } diff --git a/include/tabapp.cpp b/include/tabapp.cpp index acf584338..633534703 100755 --- a/include/tabapp.cpp +++ b/include/tabapp.cpp @@ -3,34 +3,34 @@ #include // @cmember Costruttore -Tab_application::Tab_application() +TTable_application::TTable_application() : _msk(NULL), _rel(NULL) { } // @cmember Distruttore -Tab_application::~Tab_application() +TTable_application::~TTable_application() { } -// @cmember Indica se la futura ritornera' una maschera diversa +// @cmember Indica se la futura ritornera' una maschera diversa // dalla corrente. -bool Tab_application::changing_mask(int mode) +bool TTable_application::changing_mask(int mode) { return FALSE; } // @cmember Richiede la maschera da usare -TMask* Tab_application::get_mask(int mode) +TMask* TTable_application::get_mask(int mode) { CHECK(_msk, "Null mask"); return _msk; } // @cmember Ritorna la relazione da modificare -TRelation* Tab_application::get_relation() const +TRelation* TTable_application::get_relation() const { CHECK(_rel, "Null relation"); return _rel; } -void Tab_application::print() +void TTable_application::print() { TString16 cmd; cmd << "ba3 -1 " << get_tabname(); @@ -38,28 +38,28 @@ void Tab_application::print() stampa.run(); } -void Tab_application::init_query_mode(TMask& m) +void TTable_application::init_query_mode(TMask& m) { m.enable(-GR_MODIFY_PROTECTED); m.enable(-GR_RECORD_PROTECTED); } -void Tab_application::init_modify_mode(TMask& m) +void TTable_application::init_modify_mode(TMask& m) { m.disable(-GR_MODIFY_PROTECTED); const bool enable = !(_rel->curr().get_bool(FPC)); m.enable(-GR_RECORD_PROTECTED,enable); } -bool Tab_application::protected_record(TRectype& rec) +bool TTable_application::protected_record(TRectype& rec) { return rec.get_bool(FPC); } -TString& Tab_application::get_mask_name(TString& t) const +TString& TTable_application::get_mask_name(TString& t) const { CHECK(_rel,"Can't use a NULL relation to retrieve table module"); - TTable& tab = (TTable&) _rel->lfile(_tabname); + TTable& tab = (TTable&) _rel->lfile(); TString16 m = _tabname; if (m[0] == '%') m.ltrim(1); @@ -67,10 +67,11 @@ TString& Tab_application::get_mask_name(TString& t) const t = tab.module(); t << "tb" << m; t.upper(); + return t; } -TMask* Tab_application::set_mask(TMask* m) +TMask* TTable_application::set_mask(TMask* m) { if (_msk != NULL) delete _msk; @@ -90,7 +91,7 @@ TMask* Tab_application::set_mask(TMask* m) return _msk; } -bool Tab_application::user_create() +bool TTable_application::user_create() { if (argc() < 3) return FALSE; @@ -124,7 +125,7 @@ bool Tab_application::user_create() return TRUE; } -bool Tab_application::user_destroy() +bool TTable_application::user_destroy() { if (_msk) delete _msk; if (_rel) delete _rel; diff --git a/include/tabapp.h b/include/tabapp.h index 343c8c463..55b74c847 100755 --- a/include/tabapp.h +++ b/include/tabapp.h @@ -11,14 +11,12 @@ #define FPC "FPC" -#define TTable_application Tab_application - // @doc EXTERNAL // @class Tab_application | Classe per la definizione della per le tabelle // // @base public | TRelation_application -class Tab_application : public TRelation_application +class TTable_application : public TRelation_application // @author:(INTERNAL) Nicola // @access:(INTERNAL) Private Member @@ -65,9 +63,9 @@ public: { return _tabname; } // @cmember Costruttore - Tab_application(); + TTable_application(); // @cmember Distruttore - virtual ~Tab_application(); + virtual ~TTable_application(); }; #endif diff --git a/include/tabutil.cpp b/include/tabutil.cpp index 83d607adf..df02a4c2e 100755 --- a/include/tabutil.cpp +++ b/include/tabutil.cpp @@ -145,8 +145,8 @@ void TTable::load_module_description() n.lower(); if (fexist(n)) { - TConfig des(n); - _module = des.get("Module","TabDescr"); + TConfig des(n, "TabDescr"); + _module = des.get("Module"); } n = "??tb"; n << _tabname; @@ -157,35 +157,28 @@ void TTable::load_module_description() if (list_files(n, f) == 1) { n = f.row(0); - if (!n.exist()) - n.overwrite("ba",0); - if (n.exist()) + if (_module.empty()) { - if (_module.empty()) - { - _module = n.left(2); - _module.lower(); - } - TScanner m(n); - bool ok = TRUE; - while (ok) - { - const TString& l2 = m.line().left(2); - if (l2.empty()) - ok = FALSE; - else - if (l2 == "PA") - break; - } - if (ok) - { - const int apicia = m.token().find('"')+1; - const int apicic = m.token().find('"', apicia); - _description = m.token().sub(apicia, apicic); - } - } - else - _module = "ba"; + _module = n.left(2); + _module.lower(); + } + TScanner m(n); + bool ok = TRUE; + while (ok) + { + const TString& l2 = m.line().left(2); + if (l2.empty()) + ok = FALSE; + else + if (l2 == "PA") + break; + } + if (ok) + { + const int apicia = m.token().find('"')+1; + const int apicic = m.token().find('"', apicia); + _description = m.token().sub(apicia, apicic); + } } else _module = "ba"; diff --git a/include/validate.cpp b/include/validate.cpp index e4b026e83..4b0df40ca 100755 --- a/include/validate.cpp +++ b/include/validate.cpp @@ -1,9 +1,9 @@ +#include #include -#include #include #include +#include #include -#include #include @@ -72,53 +72,71 @@ bool pi_check( const char* st, // @parm Stato di assegnazione della Partita IVA const char* paiva) // @parm Codice della Partita IVA da controllare { - int tot = 0, y; - TString16 stato (st); - TString16 pi (paiva); + const TFixed_string stato(st); + const TFixed_string pi(paiva); + + if (pi.empty()) + return TRUE; - if ((stato.not_empty()) && (stato != "IT")) return TRUE; - if (pi.empty()) return TRUE; - if (pi.len() != 11) - return FALSE; - - for (int i = 0; i <= 9; i++) + bool ok = TRUE; // Assumiamo ottimisticamente che tutto va be' + + if (stato.blank() || stato == "IT") { - if ((i + 1) & 0x0001) tot += (pi[i] - '0'); - else + // Testa partita iva italiana + ok = pi.len() == 11; + if (ok) { - y = (pi[i] - '0') * 2; - if (y >= 10) - { - tot += (y / 10); - y = y % 10; + int tot = 0, y; + for (int i = 0; i <= 9; i++) + { + if ((i + 1) & 0x0001) + tot += (pi[i] - '0'); + else + { + y = (pi[i] - '0') * 2; + if (y >= 10) + { + tot += (y / 10); + y = y % 10; + } + tot += y; + } } - tot += y; - } - } - y = 10 - (tot % 10); - if (y == 10) y = 0; - bool ok = (pi[10] == (y + '0')); - + y = 10 - (tot % 10); + if (y == 10) y = 0; + ok = (pi[10] == (y + '0')); + } + } + else + { + const char* stpi[] = { "BE09", "DE09", "DK08", "EL08", "ES09", + "FR11", "GB09", "GB12", "IE08", "IT11", + "LU08", "NL12", "PT09", NULL }; + TString16 test; + test.format("%s%02d", (const char*)stato, pi.len()); + + ok = FALSE; + for (int g = 0; stpi[g]; g++) + { + ok = (test == stpi[g]); + if (ok) + break; + } + } + return ok; } - -// Controlla la partita iva se e' non vuota ed italiana +// Controlla la partita iva se e' non vuota HIDDEN bool _pi_val(TMask_field& f, KEY) { - if (f.mask().query_mode()) return TRUE; + TMask& m = f.mask(); + if (m.query_mode()) + return TRUE; - TString16 stato(f.mask().get(atoi(get_val_param(0)))), pi(f.get()); - - if (stato.not_empty() && stato != "IT") return TRUE; - if (pi.empty()) return TRUE; - if (pi.len() != 11) - { - f.error_box("Lunghezza partita IVA diversa da 11"); - return FALSE; - } - - bool ok = pi_check (stato, pi); + const TString& stato = m.get(atoi(get_val_param(0))); + const TString& pi = f.get(); + bool ok = pi_check(stato, pi); if (!ok) { if(f.dirty()) @@ -126,7 +144,8 @@ HIDDEN bool _pi_val(TMask_field& f, KEY) ok = f.yesno_box("Partita IVA errata, la accetto ugualmente?"); if (ok) f.set_dirty(FALSE); } - else ok = TRUE; // Era gia' errata e la ho accettata + else + ok = TRUE; // Era gia' errata e la ho accettata } return ok; } @@ -241,35 +260,32 @@ HIDDEN bool _cf_val(TMask_field& f, KEY key) } -HIDDEN bool _xt_pi_val(TMask_field& f, KEY key) - +HIDDEN bool _xt_pi_val(TMask_field& f, KEY key) { TMask& m = f.mask(); - if (m.query_mode()) return TRUE; + if (m.query_mode()) + return TRUE; - TString16 value(f.get()); - if (value.empty()) return f.error_box("Partita IVA obbligatoria"); - - const TString16 stato(m.get(atoi(get_val_param(0)))); - if (stato.not_empty() && stato != "IT") return TRUE; + TString16 value = f.get(); + if (value.empty()) + return f.error_box("Partita IVA obbligatoria"); - if (!_pi_val(f, key)) return FALSE; + if (!_pi_val(f, key)) + return FALSE; - TLocalisamfile c(LF_COMUNI); - - const int pi = atoi(value.mid(7,3)); - - for (int i = 1 ; i < 3; i++) + const TString& stato = m.get(atoi(get_val_param(0))); +// if (stato.not_empty() && stato != "IT") return TRUE; + if (stato.empty() || stato == "IT") { - const int comune = atoi(get_val_param(i)); - if (comune) + const int pi = atoi(value.mid(7,3)); + for (int i = 1 ; i < 3; i++) { - const TString16 com(m.get(comune)); // Comune residenza fiscale e residenza - if (com.not_empty()) + const short id_comune = short(atoi(get_val_param(i))); + if (id_comune > 0 && !m.field(id_comune).empty()) { - c.zero(); - c.put("COM", com); - if (c.read() == NOERR) + TString16 codcom; codcom << " |" << m.get(id_comune); + const TRectype& c = cache().get(LF_COMUNI, codcom); + if (!c.empty()) { const int s1 = c.get_int("UFFIVA1"); const int s2 = c.get_int("UFFIVA2"); @@ -292,12 +308,10 @@ HIDDEN bool _xt_pi_val(TMask_field& f, KEY key) return TRUE; } - HIDDEN bool _xtz_pi_val(TMask_field& f, KEY key) { - if (f.mask().query_mode()) return TRUE; - TString16 pi(f.get()); - if (pi.empty()) return TRUE; + if (f.empty() || f.mask().query_mode()) + return TRUE; return _xt_pi_val(f, key); } @@ -306,7 +320,7 @@ HIDDEN bool _xt_cf_val(TMask_field& f, KEY key) { if (f.mask().query_mode()) return TRUE; - TString16 cf(f.get()); + TString16 cf = f.get(); if (cf.empty()) return f.error_box("Codice fiscale obbligatorio"); if (!_cf_val(f, key)) return FALSE; @@ -402,27 +416,26 @@ HIDDEN bool _xt_cf_val(TMask_field& f, KEY key) } -HIDDEN bool _xtz_cf_val(TMask_field& f, KEY key) - +HIDDEN bool _xtz_cf_val(TMask_field& f, KEY key) { - if (f.mask().query_mode()) return TRUE; - const char* cf = f.get(); - return (*cf == '\0') ? TRUE : _xt_cf_val(f, key); + if (f.empty() || f.mask().query_mode()) + return TRUE; + return _xt_cf_val(f, key); } HIDDEN bool _notempty_val(TMask_field& f, KEY) { - return f.mask().query_mode() || f.get().not_empty(); + return f.mask().query_mode() || !f.empty(); } HIDDEN bool _date_cmp(TMask_field& f, KEY) { - TFixed_string s(f.get()); - if (s.empty()) return TRUE; + if (f.empty()) + return TRUE; - TDate d0(s), d1(f.mask().get(atoi(get_val_param(1)))); + TDate d0(f.get()), d1(f.mask().get(atoi(get_val_param(1)))); TFixed_string op(get_val_param(0)); if (op == "==") return d0 == d1; @@ -440,15 +453,16 @@ HIDDEN bool _date_cmp(TMask_field& f, KEY) } -HIDDEN bool _fixlen_val(TMask_field& f, KEY) +HIDDEN bool _fixlen_val(TMask_field& f, KEY) { - const TFixed_string s(f.get()); - - if (s.empty()) return TRUE; + if (f.empty()) + return TRUE; + const TString& s = f.get(); const int length = atoi(get_val_param(0)); const bool ok = s.len() == length; - if (!ok) f.error_box("Lunghezza errata: deve essere %d", length); + if (!ok) + f.error_box("Lunghezza errata: deve essere %d", length); return ok; } @@ -456,28 +470,36 @@ HIDDEN bool _fixlen_val(TMask_field& f, KEY) HIDDEN bool _mtcheck_val(TMask_field& f, KEY) { const int month = atoi(f.get()); - if (month < 1 || month > 13) return FALSE; - + if (month < 1 || month > 13) + return FALSE; +/* TLocalisamfile d(LF_NDITTE); d.zero(); d.put(NDT_CODDITTA, prefix().get_codditta()); d.read(); - if (d.bad()) return TRUE; - if (d.get_char(NDT_FREQVIVA) == 'M') return TRUE; + if (d.bad()) + return TRUE; + if (d.get_char(NDT_FREQVIVA) == 'M') + return TRUE; return month == 13 || (month % 3) == 0; +*/ + const TRectype& d = cache().get(LF_NDITTE, prefix().get_codditta()); + if (d.get_char(NDT_FREQVIVA) == 'T') + return month == 13 || (month % 3) == 0; + return TRUE; } HIDDEN bool _reqif_val(TMask_field& f, KEY k) { - if (k == K_ENTER) + if (k == K_ENTER && f.empty()) { - if (f.get().not_empty()) return TRUE; + const TMask& m = f.mask(); const int nparms = get_val_param_num(); - for (int i = 0 ; i < nparms; i++) + for (int i = 0; i < nparms; i++) { - const short id = atoi(get_val_param(i)); - if (id > 0 && f.mask().get(id).not_empty()) + const short id = f.atodlg(get_val_param(i)); + if (id > 0 && !m.field(id).empty()) return FALSE; } } @@ -487,9 +509,8 @@ HIDDEN bool _reqif_val(TMask_field& f, KEY k) HIDDEN bool _autoexit_val(TMask_field& f, KEY key) { - TMask& m = f.mask(); - - if (!m.query_mode() || key == K_ENTER) + const TMask& m = f.mask(); + if (key == K_ENTER || !m.query_mode() ) return TRUE; /* @@ -545,7 +566,7 @@ HIDDEN bool _numcalc_val(TMask_field& f, KEY k) const int fldid = atoi(s); e.setvar(i, fldid == 0 ? f.get() : f.mask().get(fldid)); } - const TFixed_string s(e.as_string()); + const TString& s = e.as_string(); f.set(s); return TRUE; } @@ -568,7 +589,7 @@ HIDDEN bool _strcalc_val(TMask_field& f, KEY k) const int fldid = atoi(s); e.setvar(i, fldid == 0 ? f.get() : f.mask().get(fldid)); } - TFixed_string s( e.as_string()); + const TString& s = e.as_string(); f.set(s); return TRUE; } @@ -576,11 +597,11 @@ HIDDEN bool _strcalc_val(TMask_field& f, KEY k) HIDDEN bool _onereq_val(TMask_field& f, KEY k) { - if (k != K_ENTER) return TRUE; const TMask& m = f.mask(); - if (m.mode() == MODE_QUERY) return TRUE; - const int nparms = get_val_param_num(); + if (k != K_ENTER || m.query_mode()) + return TRUE; + const int nparms = get_val_param_num(); for (int i = 0; i < nparms ; i++) { const char* s = m.get(atoi(get_val_param(i)));