diff --git a/ve/velib03.cpp b/ve/velib03.cpp index 911e42128..3aa79c954 100755 --- a/ve/velib03.cpp +++ b/ve/velib03.cpp @@ -949,11 +949,74 @@ void TDocumento::dirty_fields() } } +static TToken_string * __key; + +HIDDEN int sort_doc_rows(const TObject** r0, const TObject** r1) +{ + TRiga_documento * row0 = (TRiga_documento *) *r0; + TRiga_documento * row1 = (TRiga_documento *) *r1; + int res = 0; + TToken_string & key = * __key; + TString val0, val1; + + FOR_EACH_TOKEN(key, fldname) + { + const int reverse = *fldname == '-' ? -1 : 1; + + if (reverse < 0) + fldname++; + + const TFieldref fld(fldname, 0); + val0 = fld.read(*row0); + val1 = fld.read(*row1); + + switch (row0->type(fld.name())) + { + case _intfld : + case _longfld : + case _realfld : + case _wordfld : + { + const real r0 = val0; + const real r1 = val1; + + if (r0 != r1) + res = (r0 < r1 ? -1 : 1) * reverse; + } + break; + case _datefld : + { + const TDate d0 = val0; + const TDate d1 = val1; + + if (d0 != d1) + res = (d0 < d1 ? -1 : 1) * reverse; + } + break; + default: + if (val0 != val1) + res = xvt_str_compare_ignoring_case(val0, val1) * reverse; + break; + } + if (res != 0) + break; + } + return res; +} + +void TDocumento::sort_rows(const char * key) +{ + __key = new TToken_string(key); + body().sort(sort_doc_rows); + delete __key; + __key = NULL; +} + int TDocumento::write_rewrite(TBaseisamfile & f, bool re) const -{ +{ TDocumento& myself = *((TDocumento *)this); const bool new_doc = nuovo() || numero() <= 0; // E' nuovo di zecca! - + if (new_doc) { char stato_finale = tipo().stato_finale_inserimento();