Migliorata gestione sheet ricerca

git-svn-id: svn://10.65.10.50/branches/R_10_00@23179 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2016-02-25 11:34:01 +00:00
parent c846ab1358
commit e9a34d143f
19 changed files with 131 additions and 67 deletions

View File

@ -64,7 +64,7 @@ TObject* TContainer::succ_that( )
TObject* TContainer::pred_that( ) TObject* TContainer::pred_that( )
{ {
if( _last_condition ) if( _last_condition )
{ {
TObject* curr = pred_item( ); TObject* curr = pred_item( );
while( curr && !_last_condition( *curr ) ) while( curr && !_last_condition( *curr ) )
@ -588,6 +588,15 @@ void TArray::sort(
qsort(_data, last()+1, sizeof(TObject*), compare_ex); qsort(_data, last()+1, sizeof(TObject*), compare_ex);
} }
bool TArray::is_kind_of(word id) const
{ return class_id() == CLASS_ARRAY || TContainer::is_kind_of(id); }
TArray& objptr2array(TObject* obj)
{
CHECK(obj && obj->is_kind_of(CLASS_ARRAY), "Invalid array pointer");
return static_cast<TArray&>(*obj);
}
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TString_array // TString_array

View File

@ -135,6 +135,8 @@ public:
virtual const char* class_name() const ; virtual const char* class_name() const ;
// @cmember Ritorna l'id della class // @cmember Ritorna l'id della class
virtual word class_id() const ; virtual word class_id() const ;
// @cmember Controlla se si tratta di un oggetto derivato da TArray
virtual bool is_kind_of(word cid) const;
// @cmember Stampa un array // @cmember Stampa un array
virtual void print_on(ostream& out) const ; virtual void print_on(ostream& out) const ;
// @cmember Controlla se si tratta di un oggetto valido // @cmember Controlla se si tratta di un oggetto valido
@ -220,6 +222,8 @@ inline TObject& TArray::operator[] (int index) const
(__obj = (__arr).objptr(__r)) != NULL; \ (__obj = (__arr).objptr(__r)) != NULL; \
__r = (__arr).pred(__r)) __r = (__arr).pred(__r))
TArray& objptr2array(TObject* obj);
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
// TString_array // TString_array
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////

View File

@ -1059,11 +1059,12 @@ TToken_string& TBrowse::create_siblings(TToken_string& siblings) const
KEY TBrowse::run() KEY TBrowse::run()
{ {
const TString& val = field().get(); TEdit_field& e = field();
const TString& val = e.get();
if (val.starts_with("*")) if (val.starts_with("*"))
{ {
TFuzzy_browse fb(&field(), cursor()->key()); TFuzzy_browse fb(&e, cursor()->key());
const KEY k = fb.run(); const KEY k = fb.run();
if (k == K_ENTER) if (k == K_ENTER)
{ {
@ -1112,8 +1113,8 @@ KEY TBrowse::run()
if (_insert[0] == 'M' || _insert[0] == 'R') if (_insert[0] == 'M' || _insert[0] == 'R')
{ {
const TString& maskname = field().mask().source_file(); const TString& maskname = e.mask().source_file();
if (maskname.mid(2,2).compare("tb", 2, true) == 0 && field().in_key(0)) if (maskname.mid(2,2).compare("tb", 2, true) == 0 && e.in_key(0))
{ {
const char* tabname = _cursor->file().name(); const char* tabname = _cursor->file().name();
if (maskname.mid(4, 3).compare(tabname, 3, true) == 0) if (maskname.mid(4, 3).compare(tabname, 3, true) == 0)
@ -1126,7 +1127,7 @@ KEY TBrowse::run()
{ {
if (*i != '\0' && *i != '"' && strchr(i, '@') == NULL) if (*i != '\0' && *i != '"' && strchr(i, '@') == NULL)
{ {
const short id = field().atodlg(i); const short id = e.atodlg(i);
const TEditable_field& f = field(id); const TEditable_field& f = field(id);
if (f.active() && f.is_editable()) if (f.active() && f.is_editable())
{ {
@ -1139,7 +1140,7 @@ KEY TBrowse::run()
xvt_scr_reset_busy_cursor(); xvt_scr_reset_busy_cursor();
TBrowse_sheet s(_cursor, _items, caption, _head, buttons, field(), siblings, _custom_filter_handler); TBrowse_sheet s(_cursor, _items, caption, _head, buttons, e, siblings, _custom_filter_handler);
k = s.run(); k = s.run();
selected = s.selected(); selected = s.selected();
@ -1704,6 +1705,27 @@ TRecnotype TFuzzy_browse::find_magic(const TString& magic_val, double& best)
} }
} }
} }
} else
if (testlen > 0)
{
for (c = 0L; c.ok(); ++c)
{
TString80 val = curr.get(_altfld);
clean_string(val);
const int i = val.find(magic_val);
if (i >= 0)
{
const double n = 1.0 - 0.01*i;
if (n > best)
{
best = n;
recno = c.pos();
if (n >= 1.0)
break;
}
}
}
} }
if (recno >= 0) if (recno >= 0)

View File

@ -4,7 +4,7 @@ np No Profit
fe Comunicazione Polivalente fe Comunicazione Polivalente
77 Percipienti 77 Percipienti
gd Gestione DNinst gd Gestione DNinst
se Contabilità Semplificata se SEPA
cg Contabilità Generale cg Contabilità Generale
ci Contabilità Industriale ci Contabilità Industriale
dc Dichiarazione CONAI dc Dichiarazione CONAI
@ -43,6 +43,6 @@ lv Lavanderie
?? Modulo vario ex-l1 Gestione Lavanderie Ext1 ?? Modulo vario ex-l1 Gestione Lavanderie Ext1
l2 Lavanderie 02 l2 Lavanderie 02
?? Modulo vario ex-l3 Gestione Lavanderie Ext3 ?? Modulo vario ex-l3 Gestione Lavanderie Ext3
?? Modulo vario ex-l4 Gestione Lavanderie Ext4 bs Bee Store
ha Hardy Caffè ha Hardy Caffè
ri Riclassificazioni ri Riclassificazioni

View File

@ -50,7 +50,7 @@ static bool is_prime(size_t n)
static size_t next_size(size_t p) static size_t next_size(size_t p)
{ {
for (p = p*2-1; !is_prime(p); p += 2); for (p = p*4-1; !is_prime(p); p += 2);
return p; return p;
} }
@ -60,6 +60,7 @@ static size_t next_size(size_t p)
struct THash_entry struct THash_entry
{ {
char buf[8];
char* key; char* key;
unsigned int hash; unsigned int hash;
TObject* value; TObject* value;
@ -95,7 +96,16 @@ bool THash_bucket::add(const char* key, unsigned int hash, TObject* value)
CHECK(_entries < nMaxEntries, "bucket full"); CHECK(_entries < nMaxEntries, "bucket full");
_bloom |= bloom(hash); _bloom |= bloom(hash);
THash_entry& e = _entry[_entries++]; THash_entry& e = _entry[_entries++];
if (strlen(key) < sizeof(e.buf))
{
strcpy_s(e.buf, sizeof(e.buf), key);
e.key = NULL;
}
else
{
*e.buf = '\0';
e.key = _strdup(key); e.key = _strdup(key);
}
e.hash = hash; e.hash = hash;
e.value = value; e.value = value;
return _entries > 3*nMaxEntries/4; // Danger! return _entries > 3*nMaxEntries/4; // Danger!
@ -116,7 +126,7 @@ THash_entry* THash_bucket::lookup(const char* key, unsigned int hash)
for (int p = _entries-1; p >= 0; p--) for (int p = _entries-1; p >= 0; p--)
{ {
THash_entry& e = _entry[p]; THash_entry& e = _entry[p];
if (e.hash == hash && strcmp(e.key, key) == 0) if (e.hash == hash && strcmp(e.key ? e.key : e.buf, key) == 0)
return &e; return &e;
} }
} }
@ -128,6 +138,7 @@ TObject* THash_bucket::remove(int p)
CHECKD(p >= 0 && p < _entries, "Invalid item index ", p); CHECKD(p >= 0 && p < _entries, "Invalid item index ", p);
THash_entry& e = _entry[p]; THash_entry& e = _entry[p];
TObject* obj = e.value; TObject* obj = e.value;
if (e.key)
free(e.key); free(e.key);
if (p < _entries-1) if (p < _entries-1)
memcpy(&_entry[p], &_entry[_entries-1], sizeof(THash_entry)); memcpy(&_entry[p], &_entry[_entries-1], sizeof(THash_entry));
@ -143,7 +154,6 @@ TObject* THash_bucket::remove(THash_entry* e)
return NULL; return NULL;
} }
THash_bucket::~THash_bucket() THash_bucket::~THash_bucket()
{ {
for (int p = _entries-1; p >= 0; p--) for (int p = _entries-1; p >= 0; p--)

View File

@ -683,7 +683,7 @@ TMask_field& TMask::field(short id) const
int TMask::field2pos(const char* fieldname) const int TMask::field2pos(const char* fieldname) const
{ {
if (real::is_natural(fieldname)) if (real::is_natural(fieldname) || *fieldname == '-')
{ {
const short id = atoi(fieldname); const short id = atoi(fieldname);
return id2pos(id); return id2pos(id);

View File

@ -660,33 +660,30 @@ const TString& TMask_field::evaluate_field(short id) const
if (id == 0) if (id == 0)
return get(); return get();
const TMask* m = &mask(); const TMask_field* fld = mask().find_by_id(id); // Handles negatives id too
if (fld)
if (id < 0) return fld->get();
{
TSheet_field* sh = m->get_sheet();
if (sh != NULL)
{
m = &sh->mask();
id = -id;
}
}
const int pos = m->id2pos(id);
if (pos >= 0)
return m->fld(pos).get();
return EMPTY_STRING; return EMPTY_STRING;
} }
const TString & TMask_field::evaluate_field(const char * s) const const TString & TMask_field::evaluate_field(const char* s) const
{ {
if (s && *s) if (s && *s)
{ {
if (s[0] == '#') if (s[0] == '#')
s++; s++;
if (isdigit(*s) || *s=='-')
{
const short id = atoi(s); const short id = atoi(s);
return evaluate_field(id); return evaluate_field(id);
} else
if (*s>='A' && *s<='Z')
{
const TMask_field* fld = mask().find_by_fieldname(s);
if (fld)
return fld->get();
}
} }
return EMPTY_STRING; return EMPTY_STRING;
} }

View File

@ -45,7 +45,7 @@
//#define L1AUT 42 //#define L1AUT 42
#define L2AUT 43 #define L2AUT 43
//#define L3AUT 44 //#define L3AUT 44
//#define L4AUT 45 #define BSAUT 45
#define HAAUT 46 #define HAAUT 46
#define RIAUT 47 #define RIAUT 47
#define ENDAUT 48 #define ENDAUT 48

View File

@ -1166,7 +1166,7 @@ bool TPrefix::set_studio(const char* study, long ditta)
const TString old_study(__ptprf); const TString old_study(__ptprf);
const TString old_firm(_prefix); const TString old_firm(_prefix);
strcpy(__ptprf, study); strcpy_s(__ptprf, sizeof(__ptprf), study);
const word len = strlen(__ptprf); const word len = strlen(__ptprf);
if (len > 0 && __ptprf[len-1] != '\\' && __ptprf[len-1] != '/') if (len > 0 && __ptprf[len-1] != '\\' && __ptprf[len-1] != '/')
{ {
@ -1179,7 +1179,7 @@ bool TPrefix::set_studio(const char* study, long ditta)
bool ok = set_codditta(ditta, TRUE); bool ok = set_codditta(ditta, TRUE);
if (!ok) if (!ok)
{ {
strcpy(__ptprf, old_study); strcpy_s(__ptprf, sizeof(__ptprf), old_study);
set(old_firm, true); set(old_firm, true);
} }
return ok; return ok;

View File

@ -973,6 +973,12 @@ const TRectype& TDB_cache::get_rec(int file, const char* key1, const char* key2,
return get(file, tok); return get(file, tok);
} }
const TRectype& TDB_cache::get_rec(int file, char c, long n)
{
char key[16]; sprintf_s(key, sizeof(key), "%c|%ld", c, n);
return get(file, key);
}
bool TDB_cache::discard(int file, const char* key) bool TDB_cache::discard(int file, const char* key)
{ {
return rec_cache(file).discard(key); return rec_cache(file).discard(key);

View File

@ -264,6 +264,9 @@ public:
// Smarter get: no token string key needed // Smarter get: no token string key needed
const TRectype& get_rec(int file, const char* key1, const char* key2=NULL, const char* key3=NULL, const char* key4=NULL); const TRectype& get_rec(int file, const char* key1, const char* key2=NULL, const char* key3=NULL, const char* key4=NULL);
// clifo&anagr get: no token string key needed
const TRectype& get_rec(int file, char c, long n);
const TString& get(int file, const char* key_tok, const char * campo); const TString& get(int file, const char* key_tok, const char * campo);
const TString& get(int file, long key, const char * campo); const TString& get(int file, long key, const char * campo);
const TString& get(const char* table, const char* key_tok, const char* campo); const TString& get(const char* table, const char* key_tok, const char* campo);

View File

@ -103,15 +103,16 @@ void TRelation_application::set_limits(
cur.setkey(); cur.setkey();
if (cur.items() > 0) if (cur.items() > 0)
{ {
TBaseisamfile& f = cur.file();
if (what & 0x1) if (what & 0x1)
{ {
cur = 0; cur = 0;
_first = cur.file().recno(); _first = f.recno();
} }
if (what & 0x2) if (what & 0x2)
{ {
cur = cur.items() - 1; cur = cur.items() - 1;
_last = cur.file().recno(); _last = f.recno();
} }
} }
else else
@ -120,17 +121,18 @@ void TRelation_application::set_limits(
else else
{ {
setkey(); setkey();
if (!file().empty()) TBaseisamfile& f = file();
if (!f.empty())
{ {
if (what & 0x1) if (what & 0x1)
{ {
if (file().first() == NOERR) if (f.first() == NOERR)
_first = file().recno(); _first = f.recno();
} }
if (what & 0x2) if (what & 0x2)
{ {
if (file().last() == NOERR) if (f.last() == NOERR)
_last = file().recno(); _last = f.recno();
} }
} }
else else

View File

@ -1551,7 +1551,7 @@ int TCursor::test(TIsamop op, TReclock lockop) const
{ {
if (ok()) if (ok())
{ {
trovato = TRUE; trovato = true;
break; break;
} }
else else
@ -1654,7 +1654,7 @@ TRecnotype TCursor::read(TIsamop op, TReclock lockop)
if (match <= *s) if (match <= *s)
{ {
const int pagecnt = read_page(p); const int pagecnt = read_page(p);
found = TRUE; found = true;
for (int i = 0; i < pagecnt && _pos < 0L; i++) for (int i = 0; i < pagecnt && _pos < 0L; i++)
if (_page[i] == curpos) if (_page[i] == curpos)
_pos = _pagefirstpos + i; _pos = _pagefirstpos + i;
@ -1683,7 +1683,6 @@ TRecnotype TCursor::read(TIsamop op, TReclock lockop)
return _pos; return _pos;
} }
TCursor::TCursor(TRelation* r, const char* fil, int nkey, TCursor::TCursor(TRelation* r, const char* fil, int nkey,
const TRectype *from, const TRectype* to, int tilde) const TRectype *from, const TRectype* to, int tilde)
: _if(r), _nkey(nkey), _fexpr(NULL), _frozen(false), _filter_update(false), : _if(r), _nkey(nkey), _fexpr(NULL), _frozen(false), _filter_update(false),
@ -2073,7 +2072,7 @@ const char* TSorted_cursor::fill_sort_key(TString& k)
} }
else else
{ {
if (is_up) // if (is_up) // Test inutile: tutte le chiavi sono maiuscole 08-02-2016
sf.upper(); sf.upper();
} }
switch (fld_type) switch (fld_type)
@ -2121,11 +2120,10 @@ TRecnotype TSorted_cursor::read(TIsamop op, TReclock lockop)
last = (i + 1) * pagesize() - 1; last = (i + 1) * pagesize() - 1;
else else
first = i * pagesize(); first = i * pagesize();
} }
const bool ghiacciato = !frozen(); const bool ghiacciato = !frozen();
if (ghiacciato) freeze(TRUE); if (ghiacciato) freeze(true);
TString256 testing; TString256 testing;
while (first <= last) while (first <= last)
@ -2176,7 +2174,8 @@ TRecnotype TSorted_cursor::read(TIsamop op, TReclock lockop)
file().setstatus(op == _isequal ? _iskeynotfound : _iseof); file().setstatus(op == _isequal ? _iskeynotfound : _iseof);
} }
if (ghiacciato) freeze(FALSE); if (ghiacciato)
freeze(false);
return found; return found;
} }
@ -2191,12 +2190,12 @@ void TSorted_cursor::change_order(const char* order_expr)
_order_expr.restart(); _order_expr.restart();
while ((s=_order_expr.get()).not_empty() && (_is_valid_expr=check_expr(s))) ; while ((s=_order_expr.get()).not_empty() && (_is_valid_expr=check_expr(s))) ;
if (_is_valid_expr) if (_is_valid_expr)
_is_changed_expr=TRUE; _is_changed_expr=true;
} }
} }
TSorted_cursor::TSorted_cursor(TRelation *f, const char * order_expr, const char * filter, int key, const TRectype* from, const TRectype* to) TSorted_cursor::TSorted_cursor(TRelation *f, const char * order_expr, const char * filter, int key, const TRectype* from, const TRectype* to)
: TCursor(f,filter,key,from,to) : TCursor(f,filter,key,from,to)
{ {
change_order(order_expr); change_order(order_expr);
} }

View File

@ -1588,6 +1588,7 @@ void TReport_field::print(TBook& book) const
switch (_type) switch (_type)
{ {
case 'B': case 'B':
/*
if (is_power_reseller()) if (is_power_reseller())
{ {
const TReport_rct& rctout = get_draw_rect(); const TReport_rct& rctout = get_draw_rect();
@ -1607,6 +1608,7 @@ void TReport_field::print(TBook& book) const
} }
} }
else else
*/
{ {
print_rect(book); print_rect(book);
const TString& str = formatted_text(); const TString& str = formatted_text();

View File

@ -1109,9 +1109,10 @@ void TFilename::ext(const char* e)
*this << e; *this << e;
} }
*/ */
char v[_MAX_DRIVE], d[_MAX_DIR], n[_MAX_FNAME]; char v[_MAX_DRIVE], d[_MAX_DIR], n[_MAX_FNAME], p[_MAX_PATH];
xvt_fsys_parse_pathname(_str, v, d, n, NULL, NULL); xvt_fsys_parse_pathname(_str, v, d, n, NULL, NULL);
xvt_fsys_build_pathname(_str, v, d, n, e, NULL); xvt_fsys_build_pathname(p, v, d, n, e, NULL);
set(p);
} }
// Certified 95% // Certified 95%

View File

@ -483,17 +483,17 @@ public:
// @class TFilename | Classe per la gestione dei nome dei file // @class TFilename | Classe per la gestione dei nome dei file
// //
// @base public | TString // @base public | TString
class TFilename : public TString256 class TFilename : public TString
// @author:(INTERNAL) Guido // @author:(INTERNAL) Guido
{ {
// @access Public Member // @access Public Member
public: public:
// @cmember Costruttore // @cmember Costruttore
TFilename(const char* n = "") : TString256(n) { } TFilename(const char* n = "") : TString(260) { set(n); }
// @cmember Costruttore // @cmember Costruttore
TFilename(const TString& n) : TString256(n) { } TFilename(const TString& n) : TString(260) { set(n); }
// @cmember Costruttore // @cmember Costruttore
TFilename(const TFilename& n) : TString256(n) { } TFilename(const TFilename& n) : TString(260) { set(n); }
// @cmember Assegnazione tra TFilename e stringa // @cmember Assegnazione tra TFilename e stringa
const TString& operator =(const char* s) { return set(s); } const TString& operator =(const char* s) { return set(s); }
@ -520,7 +520,7 @@ public:
// @cmember Trasforma un path da relativo ad assoluto // @cmember Trasforma un path da relativo ad assoluto
TFilename& make_absolute_path(); TFilename& make_absolute_path();
// @cmember aggiunge uno slash finale // @cmember aggiunge uno slash finale
TFilename& TFilename::slash_terminate(); TFilename& slash_terminate();
// @cmember Testa se il file esiste // @cmember Testa se il file esiste
bool exist() const; bool exist() const;
// @cmember Cancella il file // @cmember Cancella il file

View File

@ -102,13 +102,13 @@ bool fcopy(
if (xvt_str_same(orig, dest)) if (xvt_str_same(orig, dest))
return true; // Or FALSE? return true; // Or FALSE?
FILE* i = fopen(orig, rflag); FILE* i = NULL; fopen_s(&i, orig, rflag);
if (i == NULL) if (i == NULL)
return error_box(FR("Impossibile leggere il file %s\nda copiare in %s"), orig, dest); return error_box(FR("Impossibile leggere il file '%s'\nda copiare in '%s'\nErrore %d"), orig, dest, errno);
if (!append) if (!append)
xvt_fsys_remove_file(dest); xvt_fsys_remove_file(dest);
FILE* o = fopen(dest, wflag); FILE* o = NULL; fopen_s(&o, dest, wflag);
if (o == NULL) if (o == NULL)
{ {
fclose(i); fclose(i);

View File

@ -294,6 +294,12 @@ HIDDEN bool _cf_val(TMask_field& f, KEY key)
const TString& stato = get_fld_val_param(f, 0); const TString& stato = get_fld_val_param(f, 0);
if (stato.full() && stato != "IT") if (stato.full() && stato != "IT")
return true; return true;
if (cf[0]>='8' && cf.len() == 11) // codice fiscale ONLUS
{
for (const char* c = cf; *c && ok; c++)
ok = (*c>='0') && (*c<='9');
}
else
ok = pi_check(stato, cf); ok = pi_check(stato, cf);
} }
else else
@ -602,8 +608,8 @@ HIDDEN bool _numcalc_val(TMask_field& f, KEY k)
} }
e.setvar(i, f.evaluate_field(s)); e.setvar(i, f.evaluate_field(s));
} }
const TString& s = e.as_string(); const real n = e.as_real();
f.set(s); f.set(n.string());
return true; return true;
} }

View File

@ -145,6 +145,9 @@ bool TVariant::as_bool() const
case _alfafld: case _alfafld:
{ {
const TString& str = as_string(); const TString& str = as_string();
if (str.len() > 1) // May be " 1"
ok = atoi(str) != 0;
else
ok = str.full() && strchr("1TVXY", str[0]) != NULL; ok = str.full() && strchr("1TVXY", str[0]) != NULL;
} }
break; break;