From 885a21a2d1de3d565eb4b9919a1d695c3584b50a Mon Sep 17 00:00:00 2001 From: guy Date: Fri, 30 Nov 2012 14:40:18 +0000 Subject: [PATCH] Supporto per TRecord_array con chiave su CODTAB[a,b] git-svn-id: svn://10.65.10.50/branches/R_10_00@22761 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/controls.cpp | 7 +++-- include/currency.cpp | 62 +++++++++++++++++++++++--------------------- include/doc.h | 1 + include/isam.cpp | 11 +++++++- include/msksheet.cpp | 55 +++++++++++++++++++++++++-------------- include/recarray.cpp | 51 +++++++++++++++++++++++++++++------- include/recset.cpp | 2 +- include/strings.cpp | 15 +++-------- 8 files changed, 131 insertions(+), 73 deletions(-) diff --git a/include/controls.cpp b/include/controls.cpp index bc7e117a7..0ff04152c 100755 --- a/include/controls.cpp +++ b/include/controls.cpp @@ -876,8 +876,10 @@ XI_OBJ* TControl::find_operable(XI_OBJ* container, bool forward, bool normal) co XI_OBJ* obj = child[c]; switch (obj->type) { - case XIT_LIST: case XIT_BTN: + if (obj->v.btn->type == XIBT_BUTTON_CHECKBOX) + break; + case XIT_LIST: case XIT_FIELD: if (normal && obj->cid > 0) found = obj; @@ -1655,7 +1657,8 @@ void TButton_control::create(WINDOW win, short cid, xi_dequeue(); xi_tree_free(def); - update_tab_cid(); + if (wc != WC_CHECKBUTTON) // Annullo fastidiosa gestione tab per i checkbutton + update_tab_cid(); } int TButton_control::button_type() const diff --git a/include/currency.cpp b/include/currency.cpp index 11c035528..867e60880 100755 --- a/include/currency.cpp +++ b/include/currency.cpp @@ -108,36 +108,39 @@ void TDowJones::flush() } void TDowJones::test_cache() -{ - // Controllo se e' cambiata la ditta - const long newfirm = prefix().get_codditta(); - if (newfirm != _codditta) +{ + if (prefix_valid()) { - _codditta = newfirm; - _firm_val = prefix().firm().codice_valuta(); - } - - if (_euro_val.empty()) - { - fill(); - FOR_EACH_ASSOC_OBJECT(_cache, hash, key, obj) if (*key) + // Controllo se e' cambiata la ditta + const long newfirm = prefix().get_codditta(); + if (newfirm != _codditta) { - const TExchangeData& data = *(const TExchangeData*)obj; - if (data._is_euro && _euro_val.empty()) - _euro_val = key; + _codditta = newfirm; + _firm_val = prefix().firm().codice_valuta(); + } + if (_euro_val.empty()) + { + fill(); + FOR_EACH_ASSOC_OBJECT(_cache, hash, key, obj) if (*key) + { + const TExchangeData& data = *(const TExchangeData*)obj; + if (data._is_euro && _euro_val.empty()) + _euro_val = key; + } + _firm_val = prefix().firm().codice_valuta(); } - - if (_euro_val.empty()) // Si son dimenticati dell'EURO? - { - TExchangeData* euro = new TExchangeData; - euro->_chg = UNO; euro->_dec = euro->_dec_prices = 2; - euro->_is_euro = true; - _euro_val = "EUR"; - _cache.add(_euro_val, euro); - } - - _firm_val = prefix().firm().codice_valuta(); } + + if (_euro_val.empty()) // Si son dimenticati dell'EURO? + { + TExchangeData* euro = new TExchangeData; + euro->_chg = UNO; euro->_dec = euro->_dec_prices = 2; + euro->_is_euro = true; + _euro_val = "EUR"; + _cache.add(_euro_val, euro); + } + if (_firm_val.empty()) + _firm_val = _euro_val; } const char* TDowJones::expand_value(const char* val) @@ -165,7 +168,9 @@ const char* TDowJones::expand_value(const char* val) const TDowJones::TExchangeData& TDowJones::get(const char* val) { test_cache(); - return (const TExchangeData&)query(expand_value(val)); + if (prefix_valid()) + return (const TExchangeData&)query(expand_value(val)); + return *(const TExchangeData*)_cache.first_item(); } const TString& TDowJones::get_firm_val() @@ -205,7 +210,7 @@ real TDowJones::exchange(const real& num, // Importo da convertire real to = tochg; if (to <= ZERO) to = datato._chg; - n = n * to / fr; // Nuovo modo + n = n * to / fr; // Nuovo modo if (price == 0 || price == 1) // Arrotonda solo in caso normale n.round(price ? datato._dec_prices : datato._dec); } @@ -337,7 +342,6 @@ int TCurrency::get_euro_dec(bool price) return DowJones.get_dec(get_euro_val(), price); } - void TCurrency::force_firm_val(const char* val) { DowJones.force_firm_val(val); diff --git a/include/doc.h b/include/doc.h index 33f6ecfa9..13c3cddd9 100755 --- a/include/doc.h +++ b/include/doc.h @@ -84,6 +84,7 @@ #define DOC_TIPOCFFATT "TIPOCFFATT" #define DOC_CODCFFATT "CODCFFATT" #define DOC_LIQDIFF "LIQDIFF" +#define DOC_IVAXCASSA "IVAXCASSA" #define DOC_DATACOMP "DATACOMP" #define DOC_DATAFCOMP "DATAFCOMP" #define DOC_CUP "CUP" diff --git a/include/isam.cpp b/include/isam.cpp index 065155da2..967799e7b 100755 --- a/include/isam.cpp +++ b/include/isam.cpp @@ -3874,7 +3874,16 @@ int TRectype::remove(TBaseisamfile& f) const void TRectype::renum_key(const char* field, const char* val) { - put(field, val); + if (strchr(field, '[') != NULL) // Accept CODTAB[6,10] + { + const TFieldref fref(field, 0); + TString80 str = val; + if (real::is_natural(val)) + str.right_just(fref.len(*this), '0'); + fref.write(str, *this); + } + else + put(field, val); } // Certified 99% diff --git a/include/msksheet.cpp b/include/msksheet.cpp index b0f240be3..9082315be 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -2790,7 +2790,6 @@ bool TSheet_field::parse_item(TScanner& scanner) void TSheet_field::parse_input(TScanner& scanner) { - const char* s = scanner.pop(); _file_k_names.add(s); @@ -2800,7 +2799,6 @@ void TSheet_field::parse_input(TScanner& scanner) scanner.push(); TString& str = scanner.line(); _file_k_ids.add(str); - } else // Field on the mask { @@ -2810,9 +2808,7 @@ void TSheet_field::parse_input(TScanner& scanner) else scanner.push(); } } - - - + // Certified 100% void TSheet_field::create(WINDOW parent) { @@ -3486,13 +3482,22 @@ TRectype* TSheet_field::putkey(const TRelation& r) _sheetfile->zero(); _file_k_ids.restart(); for (TString16 dbfieldname = _file_k_names.get(0); - dbfieldname.not_empty(); + dbfieldname.full(); dbfieldname = _file_k_names.get()) { - TMask_field& f= mask().field(_file_k_ids.get_int()); - if (mask().edit_mode()) - ((TLoadable_field&)f).autoload(r); // Molto probabilmente inutile! - _sheetfile->put(dbfieldname, f.get()); + TString80 id = _file_k_ids.get(); + if (id[0] == '"') + { + id.strip("\""); + _sheetfile->curr().renum_key(dbfieldname, id); + } + else + { + TMask_field& f = mask().field(atoi(id)); + if (mask().edit_mode()) + ((TLoadable_field&)f).autoload(r); // Molto probabilmente inutile! + _sheetfile->curr().renum_key(dbfieldname, f.get()); + } } return &_sheetfile->curr(); } @@ -3581,22 +3586,34 @@ bool TSheet_field::autosave(TRelation& rel) if (mask().insert_mode()) { // rinumera la chiave - TString dbfieldname; - TMask_field * f; - restart_key(); - while ((f = get_key(dbfieldname))) - _linee_rec->renum_key(dbfieldname, f->get()); + _file_k_ids.restart(); + for (TString16 dbfieldname = _file_k_names.get(0); + dbfieldname.full(); + dbfieldname = _file_k_names.get()) + { + TString80 id = _file_k_ids.get(); + if (id[0] == '"') + { + id.strip("\""); + _linee_rec->renum_key(dbfieldname, id); + } + else + { + const TMask_field& f = mask().field(atoi(id)); + _linee_rec->renum_key(dbfieldname, f.get()); + } + } } } // ******* // trasferisce le linee dallo sheet al record array (ignorando righe vuote alla fine) - int i= items(); - while (i >= 1 && row(i-1).empty_items()) + int i = items(); + while (i > 0 && row(i-1).empty_items()) i--; - for (; i >= 1; i--) + for (; i > 0; i--) { TRectype &rec = _linee_rec->row(i, true); - autosave_line(i,rec); + autosave_line(i,rec); // autosave_line parte da 1 :-( } } return _enable_autoload; diff --git a/include/recarray.cpp b/include/recarray.cpp index 2e5cf9b3f..ef3a16014 100755 --- a/include/recarray.cpp +++ b/include/recarray.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -47,7 +48,7 @@ TRecord_array::TRecord_array(const TRecord_array& a) } // Questo si che e' il costruttore dei miei sogni -// Senza cavolate come numfield o necessita' di interi record come chiave! +// Senza cavolate come numfield o necessità di interi record come chiave! TRecord_array::TRecord_array(const char* keytok, int logicnum, int first) : _file(logicnum), _offset(first - 1) { @@ -100,6 +101,14 @@ void TRecord_array::set_key(TRectype* r) renum_key(rf.Name, val); CHECKS(i > 0 || val.full(), "First key field can't be empty: ", rf.Name); } + + if (_num.find('[') > 0) + { + const TFieldref field(_num, 0); + val = r->get(field.name()); + val.cut(field.from()); + renum_key(field.name(), val); + } } } @@ -196,7 +205,15 @@ void TRecord_array::sort(COMPARE_FUNCTION sort_func) int TRecord_array::rec2row(const TRectype& r) const { CHECK(r.num() == _file, "Incompatible record"); - const int n = r.get_int(_num) - _offset; // Non e' detto che sia un int! + int n = 0; + if (_num.find('[') > 0) + { + const TFieldref fref(_num, 0); + n = atoi(fref.read(r)); + } + else + n = r.get_int(_num); // Non e' detto che sia un int! + n -= _offset; CHECKD(n >= 0 && n < 30000, "Bad line number in record ", n + _offset); return n; } @@ -302,7 +319,13 @@ void TRecord_array::destroy_rows() bool TRecord_array::good( const TRectype& rec) const // @parm Record di cui confrontare i campi { - const bool yes = key().same_key(rec, 1, 1); + bool yes = key().same_key(rec, 1, 1); + if (yes && _num.find('[') > 0) + { + const TFieldref fref(_num, 0); + const char* codtab = fref.name(); + yes = rec.get(codtab).starts_with(key().get(codtab)); + } return yes; } @@ -310,7 +333,11 @@ int TRecord_array::read(TRectype* filter) { CHECK(filter != NULL, "You can't specify NULL as filter "); CHECKD(filter->num() == _file, "Bad key record ", filter->num()); - CHECKS(filter->get(_num).empty(), "You can't specify in the filter the field ", (const char*)_num); + +#ifndef NDEBUG + const TFieldref fref(_num, 0); + CHECKS(*fref.read(*filter) < ' ', "You can't specify in the filter the field ", (const char*)_num); +#endif _data.destroy(); set_key(filter); @@ -360,10 +387,14 @@ int TRecord_array::remove_from(TIsamfile& f, int pos) const TRectype* rec = (TRectype*)key().dup(); CHECK(!rec->empty(), "Can't use empty key"); - rec->put(_num, pos); + TString16 n; n << pos; + rec->renum_key(_num, n); + + const TFieldref fref(_num, 0); + for (int e = rec->read(f, _isgteq); e == NOERR && good(*rec); e = rec->next(f)) - { - const int found = rec->get_int(_num); + { + const int found = atoi(fref.read(*rec)); if (found >= pos) { err = rec->remove(f); @@ -434,11 +465,13 @@ int TRecord_array::write(bool re) const { TRectype* rec = (TRectype*)key().dup(); CHECK(!rec->empty(), "TRecord_array has an empty key"); - rec->put(_num, pos); + TString16 n; n << pos; + rec->renum_key(_num, n); err = rec->read(f, _isgteq); if (err == NOERR && good(*rec)) // Cerca una riga >= pos sul file { - last_on_file = rec->get_int(_num); + const TFieldref fref(_num, 0); + last_on_file = atoi(fref.read(*rec)); if (last_on_file == pos) // La riga c'era ma ora non piu' { err = (rec->remove(f)); // Cancello il record indesiderato diff --git a/include/recset.cpp b/include/recset.cpp index fea5cfb37..c89e2c62d 100755 --- a/include/recset.cpp +++ b/include/recset.cpp @@ -85,7 +85,7 @@ const TToken_string& TRecordset::sheet_head() const case _intfld: case _longfld: head << 'R'; break; case _datefld: head << 'D'; break; - case _realfld: head << 'V'; break; + case _realfld: head << (ci._width > 7 ? 'V' : 'R'); break; default: break; } } diff --git a/include/strings.cpp b/include/strings.cpp index 1fd76e363..1a05c8a1c 100755 --- a/include/strings.cpp +++ b/include/strings.cpp @@ -134,18 +134,9 @@ TString::~TString() char TString::shift(int n) { - CHECK(n>0,"Scorrimento a destra delle stringhe non ancora supportato"); - CHECK(n<_size,"Errore di scorrimento"); - char r=*(_str+n-1); - if (n) - { - char *c=_str; - while (*c) - { - *(c)=*(c+n); - c++; - } - } + CHECK(n>0 && n<=len(),"Errore di scorrimento"); + const char r=*(_str+n-1); + strcpy(_str, _str+n); return r; }