From 849c764d190e62d41cff4036e63885eeff0b38a0 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 9 Aug 1995 09:54:36 +0000 Subject: [PATCH] Modificata gestione dei record array Corretta conversione in lettere dei numeri Aggiunti metodi select e swap_columns agli sheet git-svn-id: svn://10.65.10.50/trunk@1697 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/date.cpp | 106 ++++++++++++++++---------- include/isam.cpp | 114 +++++++++++++--------------- include/isam.h | 36 +++++---- include/maskfld.cpp | 6 +- include/maskfld.h | 6 ++ include/msksheet.cpp | 68 +++++++++++++++-- include/msksheet.h | 11 ++- include/real.cpp | 2 +- include/relapp.cpp | 4 +- include/relation.cpp | 172 ++++++++++++++++++++++++------------------- include/relation.h | 23 +++--- include/scadenze.h | 59 +++++++-------- 12 files changed, 361 insertions(+), 246 deletions(-) diff --git a/include/date.cpp b/include/date.cpp index 59090aca9..9bad86c3a 100755 --- a/include/date.cpp +++ b/include/date.cpp @@ -94,36 +94,45 @@ TDate::TDate(long l) : _val(l) TDate::TDate(const char* s) { _val = NULLDATE; - if (!isdate(s)) + + const int len = strlen(s); + if (len != 8 && len != 10) return; - int day, month, year; - - /* - if (strchr(s, '-') == NULL) - { - strcpy(__date_tmp_string, s); - - day = atoi(__date_tmp_string + 6); __date_tmp_string[6] = '\0'; - month = atoi(__date_tmp_string + 4); __date_tmp_string[4] = '\0'; - year = atoi(__date_tmp_string); - } - else - */ - CHECKS(strlen(s) == 10, "Non e' una data lunga 10 caratteri: ", s); -{ - day = atoi(s); - month = atoi(&s[3]); - year = atoi(&s[6]); - if (strlen(s) < 10) - year += 1900; -} -_val = makedata(day, month, year); + int d = 0, m = 0, y = 0; + if (len == 8) + { + for (int i = 0; i < 8; i++) + if (!isdigit(s[i])) break; + if (i == 8) + { + TString16 str(s); + d = atoi(str+6); str.cut(6); + m = atoi(str+4); str.cut(4); + y = atoi(str+0); + } + } + else + if (len == 10) + { + if (s[2] == s[5] && !isdigit(s[2])) + { + d = atoi(s); + m = atoi(&s[3]); + y = atoi(&s[6]); + } + } + +#ifdef DBG + if (d < 1 || d > 31 || m < 1 || m > 12 && y < 0) + yesnofatal_box("Lamentati con Guy se la data %s non viene accettata!", s); +#endif + _val = makedata(d, m, y); } TDate::TDate(int day, int month, int year) { - if (day && month && year) + if (day >= 1 && day <= 31 && month >= 1 && month <= 12 && year > 0) _val = makedata(day, month, year); else _val = NULLDATE; @@ -208,12 +217,8 @@ void TDate::read_from(istream& in) { char s[256]; in >> s; - if (isdate(s)) - { - TDate d(s); - _val = d._val; - } - else _val = NULLDATE; + TDate d(s); + _val = d._val; } // @mfunc Ritorna la data in formato di stringa (anche in formato ANSI) @@ -399,20 +404,41 @@ void TDate::addyear(int nyear) bool TDate::isdate(const char* s) -{ - // if (!*s) return FALSE; - if (strlen(s) < 8 || s[2] != s[5]) +{ + const int len = strlen(s); + if (len != 8 && len != 10) return FALSE; - const int day = atoi(s); - const int month = atoi(&s[3]); - const int year = atoi(&s[6]); - if (day < 1 || day > 31 || - month < 1 || month > 12 || - year < 0) + int d = 0, m = 0, y = 0; + if (len == 8) + { + for (int i = 0; i < 8; i++) + if (!isdigit(s[i])) break; + if (i == 8) + { + TString16 str(s); + d = atoi(str+6); str.cut(6); + m = atoi(str+4); str.cut(4); + y = atoi(str+0); + } + } + else + if (len == 10) + { + if (s[2] == s[5] && !isdigit(s[2])) + { + d = atoi(s); + m = atoi(&s[3]); + y = atoi(&s[6]); + } + } + + if (d < 1 || d > 31 || + m < 1 || m > 12 || + y < 0) return FALSE; - return day <= _days_in_month[month - 1] || (month == 2 && (year % 4 == 0) && day == 29); + return d <= _days_in_month[m - 1] || (m == 2 && (y % 4 == 0) && d == 29); } diff --git a/include/isam.cpp b/include/isam.cpp index 54e742028..efa0f47db 100755 --- a/include/isam.cpp +++ b/include/isam.cpp @@ -29,7 +29,6 @@ #endif -#define NOT_LINKED(i,f) CHECKS(i != NULL, "Record senza tracciato: impossibile eseguire ", f) #define NOT_OPEN() CHECKS(_isamfile != NULL, "File chiuso: ", (const char*)name()) //#define INTTLOCK 0x600 @@ -2012,7 +2011,6 @@ TRectype::TRectype(int logicnum) : _cod(NULL) { _logicnum = logicnum; - // _i = openf[_logicnum - 1]; if (openf[_logicnum - 1] != NULL) _length = DB_reclen(openf[logicnum - 1]->fhnd); else @@ -2047,7 +2045,6 @@ TRectype::TRectype(const TBaseisamfile* i): _cod(NULL) } *_tab = '\0'; _rec = new char [ _length ]; - // _i = i->filehnd(); if (_length) zero(); else @@ -2064,7 +2061,6 @@ TRectype::TRectype(const TRectype& r) _rec = new char [ _length ]; _rec[0] = r._rec[0]; memcpy(_rec + 1, r._rec + 1, _length - 1); - // _i = r._i; strcpy(_tab, r._tab); if (r._cod != NULL) _cod = new TRecfield(*this, "COD"); @@ -2075,11 +2071,10 @@ TRectype::~TRectype() { if (_cod != NULL) delete _cod; - delete _rec; + if (_rec != NULL) delete _rec; } void TRectype::settab(const char *tab) - { if (_cod != NULL) { @@ -2093,16 +2088,13 @@ void TRectype::settab(const char *tab) } TObject* TRectype::dup() const - { TRectype* o = new TRectype(*this); - return o; } HIDDEN bool fld_empty(const char* s, int len, bool number) - { /*if (number) { @@ -2140,9 +2132,9 @@ HIDDEN int fld_cmp(const char* a, const char* b, int len, bool number) RecDes* TRectype::rec_des() const { const isdef* i = openf[_logicnum-1]; - NOT_LINKED(i, "Record description"); + CHECKD(i, "Can't use a record of closed file ", _logicnum); RecDes* r = i->r; - CHECK(r, "Missing record description"); + CHECKD(r, "Missing record description of file", _logicnum); return r; } @@ -2167,15 +2159,14 @@ int TRectype::compare(const TSortable& s) const int res = 0; if (br.empty()) return UNDEFINED; + + const RecDes& rd = *rec_des(); for (int i = 0; i < items() ; i++) { const char* b = br.start(i); const char* a = start(i); - const byte typ = rec_des()->Fd[i].TypeF; - /* if (typ == _boolfld) res = *a - *b; - else - { */ - const int sz = rec_des()->Fd[i].Len; + const byte typ = rd.Fd[i].TypeF; + const int sz = rd.Fd[i].Len; const bool number = (typ == _intfld) || (typ == _realfld) || (typ == _longfld) || (typ == _wordfld) || (typ == _intzerofld) || (typ == _longzerofld) @@ -2184,7 +2175,6 @@ int TRectype::compare(const TSortable& s) const if (fld_empty(b, sz, number)) continue; res = ::fld_cmp(a, b, sz, number); - /* } */ if (res) return res; } return 0; @@ -2193,7 +2183,6 @@ int TRectype::compare(const TSortable& s) const TFieldtypes TRectype::type(const char* fieldname) const { - // NOT_LINKED(_i, "type"); return (TFieldtypes) CFieldType((char*) fieldname, rec_des()); } @@ -2201,7 +2190,6 @@ TFieldtypes TRectype::type(const char* fieldname) const int TRectype::length(const char* fieldname) const { - // NOT_LINKED(_i, "length"); return CFieldSize((char*) fieldname, rec_des()); } @@ -2209,21 +2197,18 @@ int TRectype::length(const char* fieldname) const int TRectype::ndec(const char* fieldname) const { - // NOT_LINKED(_i, "dec"); return CFieldDec((char*) fieldname, rec_des()); } bool TRectype::exist(const char* fieldname) const { - // NOT_LINKED(_i, "exist"); return findfld(rec_des(), (char*)fieldname) != -1; } const char* TRectype::fieldname(int i) const { - // NOT_LINKED(_i, "fieldname"); RecDes* rd = rec_des(); return i >= 0 && i < rd->NFields ? rd->Fd[i].Name : NULL; } @@ -2264,7 +2249,6 @@ const TString& TRectype::get(const char* fieldname) const int TRectype::get_int(const char* fieldname) const { - // NOT_LINKED(_i, "get_int"); if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1) UNKNOWN_FIELD(num(), fieldname); return atoi(_isam_string); @@ -2273,7 +2257,6 @@ int TRectype::get_int(const char* fieldname) const long TRectype::get_long(const char* fieldname) const { - // NOT_LINKED(_i, "get_long"); if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1) UNKNOWN_FIELD(num(), fieldname); return atol(_isam_string); @@ -2283,7 +2266,6 @@ long TRectype::get_long(const char* fieldname) const word TRectype::get_word(const char* fieldname) const { - // NOT_LINKED(_i, "get_word"); if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1) UNKNOWN_FIELD(num(), fieldname); return (word)atoi(_isam_string); @@ -2292,7 +2274,6 @@ word TRectype::get_word(const char* fieldname) const real TRectype::get_real(const char* fieldname) const { - // NOT_LINKED(_i, "get_real"); if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1) UNKNOWN_FIELD(num(), fieldname); real r(_isam_string); @@ -2303,8 +2284,6 @@ real TRectype::get_real(const char* fieldname) const char TRectype::get_char(const char* fieldname) const { - // NOT_LINKED(_i, "get_char"); - if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1) UNKNOWN_FIELD(num(), fieldname); return *_isam_string; @@ -2314,7 +2293,6 @@ char TRectype::get_char(const char* fieldname) const bool TRectype::get_bool(const char* fieldname) const { - // NOT_LINKED(_i, "get_bool"); if (CGetFieldBuff((char*) fieldname, rec_des(), _rec, _isam_string) == -1) UNKNOWN_FIELD(num(), fieldname); if (toupper(*_isam_string) == 'T' || toupper(*_isam_string) == 'Y' @@ -2345,8 +2323,6 @@ bool TRectype::get_memo(const char* fieldname, TTextfile& txt) const TDate TRectype::get_date(const char* fieldname) const { - // NOT_LINKED(_i, "get_date"); - const TRecfield f((TRectype&)*this, fieldname); return (TDate) f; } @@ -2356,7 +2332,6 @@ TDate TRectype::get_date(const char* fieldname) const void TRectype::put(const char* fieldname, int val) { - // NOT_LINKED(_i, "put"); if (CPutField((char*) fieldname, rec_des(), &val, _rec) == -1) UNKNOWN_FIELD(num(), fieldname); setempty(FALSE); @@ -2366,7 +2341,6 @@ void TRectype::put(const char* fieldname, int val) void TRectype::put(const char* fieldname, long val) { - // NOT_LINKED(_i, "put"); if (CPutField((char*) fieldname, rec_des(), &val, _rec) == -1) UNKNOWN_FIELD(num(), fieldname); setempty(FALSE); @@ -2393,7 +2367,6 @@ void TRectype::put(const char* fieldname, TTextfile& txt) void TRectype::put(const char* fieldname, word val) { - // NOT_LINKED(_i, "put"); if (CPutField((char*) fieldname, rec_des(), &val, _rec) == -1) UNKNOWN_FIELD(num(), fieldname); setempty(FALSE); @@ -2402,7 +2375,6 @@ void TRectype::put(const char* fieldname, word val) void TRectype::put(const char* fieldname, const real& val) { - // NOT_LINKED(_i, "put"); if (CPutField((char*) fieldname, rec_des(), val.ptr(), _rec) == -1) UNKNOWN_FIELD(num(), fieldname); setempty(FALSE); @@ -2411,7 +2383,6 @@ void TRectype::put(const char* fieldname, const real& val) void TRectype::put(const char* fieldname, const TDate& val) { - // NOT_LINKED(_i, "put"); TRecfield f(*this, fieldname); f = val.string(full); setempty(FALSE); @@ -2420,7 +2391,6 @@ void TRectype::put(const char* fieldname, const TDate& val) void TRectype::put(const char* fieldname, char val) { - // NOT_LINKED(_i, "put"); char w[2] = {val, '\0'}; if (CPutFieldBuff((char*) fieldname, rec_des(), w, _rec) == -1) @@ -2432,7 +2402,6 @@ void TRectype::put(const char* fieldname, char val) void TRectype::put(const char* fieldname, bool val) { - // NOT_LINKED(_i, "put"); char* s = val ? "T" : "F"; if (CPutFieldBuff((char*) fieldname, rec_des(), s, _rec) == -1) UNKNOWN_FIELD(num(), fieldname); @@ -2445,8 +2414,6 @@ void TRectype::put(const char* fieldname, bool val) void TRectype::put(const char* fieldname, const char* val) { - // NOT_LINKED(_i, "put"); - if (val == NULL || *val == '\0') // Da provare { TRecfield f(*this, fieldname); @@ -2481,7 +2448,6 @@ void TRectype::put(const char* fieldname, const char* val) void TRectype::zero(const char* fieldname) { - // NOT_LINKED(_i, "zero"); if (_cod != NULL && strcmp(fieldname , "COD") == 0) *_cod = _tab; else @@ -2508,7 +2474,6 @@ void TRectype::zero() void TRectype::zero(char c) { - // NOT_LINKED(_i, "zero"); recall(); memset(_rec + 1, c, len() - 1); @@ -2525,7 +2490,6 @@ TRectype& TRectype::operator =(const TRectype& rec) { CHECK(num() == rec.num(), "Can't assign records of different file"); - // _i = rec._i; // Copy filehndl memcpy(_rec, rec._rec, _length); // Copy contents setempty(rec.empty()); // Copy emptiness status return *this; @@ -2538,6 +2502,33 @@ TRectype& TRectype::operator =(const TBaseisamfile& f) return *this = f.curr(); } +// Certified 100% +int TRectype::read(TBaseisamfile& f, word op) +{ return f.read(*this, op); } + +// Certified 100% +int TRectype::next(TBaseisamfile& f) +{ + const int err = f.next(); + *this = f.curr(); + return err; +} + +// Certified 100% +int TRectype::write(TBaseisamfile& f) const +{ return f.write(*this); } + +// Certified 100% +int TRectype::rewrite(TBaseisamfile& f) const +{ + return f.rewrite(*this); +} + +// Certified 100% +int TRectype::remove(TBaseisamfile& f) const +{ + return f.remove(*this); +} // Certified 99% TRectype& TRectype::operator =(const char* rec) @@ -2550,7 +2541,6 @@ TRectype& TRectype::operator =(const char* rec) const char* TRectype::key(int numkey) const { - // NOT_LINKED(_i, "key"); CBuildKey(rec_des(), numkey, _rec, _isam_string,FALSE); return _isam_string; } @@ -2581,8 +2571,7 @@ void TRecfield::set(int from, int to) _type = rd->Fd[nf].TypeF; if (to >= 0) { - CHECK(from <= to && to <= rd->Fd[nf].Len, - "Invalid Range"); + CHECK(from <= to && to <= rd->Fd[nf].Len, "Invalid Range"); _len = to - from + 1; } else _len = rd->Fd[nf].Len - from; @@ -2592,7 +2581,6 @@ void TRecfield::set(int from, int to) TRecfield::TRecfield(TRectype& rec, const char* name, int from, int to) { - // NOT_LINKED(rec.filehnd(), "TRecfield"); strcpy(_name, name); _rec = &rec; set(from, to); @@ -2664,9 +2652,8 @@ HIDDEN void __getfieldbuff(byte l, byte t, const char* recin, char *s) HIDDEN void __putfieldbuff(byte l, byte d, byte t, const char* s, char* recout) - { - int len, i; + int len, i; if (recout == NULL) return; @@ -2841,7 +2828,6 @@ TRecfield::operator TDate() const TRecfield::operator const char*() const - { __getfieldbuff( _len, _type, _p, _isam_string); return _isam_string; @@ -2849,8 +2835,6 @@ TRecfield::operator const char*() const TRecnotype TRecfield::ptr() const - - { if (_p == NULL) return(-1L); unsigned char* wp = (unsigned char*) _p + 3; @@ -2862,15 +2846,23 @@ TRecnotype TRecfield::ptr() const return n ? -r : r; } - -void TTransaction::begin() -{ -} +/* + + /////////////////////////////////////////////////////////// + // Never implemented story + /////////////////////////////////////////////////////////// -void TTransaction::end(bool success) + void TTransaction::begin() + { + } -{ - if (success) ; - else ; -} + + void TTransaction::end(bool success) + + { + if (success) ; + else ; + } + + */ diff --git a/include/isam.h b/include/isam.h index 56abf4737..a04b046a3 100755 --- a/include/isam.h +++ b/include/isam.h @@ -58,14 +58,12 @@ class TRectype : public TSortable char* _rec; // Puntatore a inizio record int _logicnum; // Numero logico int _length; // Lunghezza - // isdef* _i; // Puntatore al file isam bool _isempty; // Se il record e' vuoto char _tab[5]; // identificatore della tabella TRecfield * _cod; // campo "COD" della tabella // @END protected: // TObject - virtual TObject* dup() const; // Duplica record virtual int compare(const TSortable& s) const; protected: @@ -73,6 +71,15 @@ protected: void setempty(bool val) { _isempty = val;} // Rende vero is_empty virtual RecDes* rec_des() const; +public: // TObject + virtual TObject* dup() const; // Duplica record + + virtual int read(TBaseisamfile& f, word op = _isequal); + virtual int next(TBaseisamfile& f); + virtual int write(TBaseisamfile& f) const; + virtual int rewrite(TBaseisamfile& f) const; + virtual int remove(TBaseisamfile& f) const; + public: // FPUB int items() const; @@ -116,7 +123,6 @@ public: void put(const char* fieldname, bool val); void put(const char* fieldname, const real& val); void put(const char* fieldname, TTextfile& txt); -#else #endif // @DES Put NON tipizzata @@ -475,26 +481,24 @@ public: TRecfield(TRectype& rec, const char* name, int from = 0, int to = -1); }; -// @C -// Classe TTransaction -// -// @END +/* -class TTransaction -{ -public: - // @FPUB - void begin(); - void end(bool success = TRUE); - void abort() { end(FALSE);} -}; + class TTransaction + { + public: + // @FPUB + void begin(); + void end(bool success = TRUE); + void abort() { end(FALSE);} + }; + + */ #ifdef __ISAM_CPP #define extern #endif // @DPUB -extern TTransaction transaction; extern TRectype** openrec; extern void get_idx_names(int logicnum, TToken_string& i_names); // @END diff --git a/include/maskfld.cpp b/include/maskfld.cpp index 9c3f47df9..da4d29111 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -2720,10 +2720,10 @@ const char * TDate_field::get_window_data() const void TDate_field::set_window_data(const char * data) { - if (roman()) - { + if (roman() && strlen(data) == 8) + { const TDate d(data); - data = d.string(); + data = d.string(ANSI); } TEdit_field::set_window_data(data); } diff --git a/include/maskfld.h b/include/maskfld.h index 2734c88c6..ef4e21023 100755 --- a/include/maskfld.h +++ b/include/maskfld.h @@ -183,9 +183,15 @@ public: { _flags.focusdirty = d; } // @cmember Setta lo stato di dirty del campo void set_dirty(bool d = TRUE); + // @cmember Setta la giustificazione a destra del campo void set_justify(bool r) { _flags.rightjust = r; } + + // @cmember Verifica la giustificazione a destra del campo + bool right_justified() const + { return _flags.rightjust; } + // @cmember Ritorna il nome della classe virtual const char* class_name() const; diff --git a/include/msksheet.cpp b/include/msksheet.cpp index 2aea195aa..e27e7431d 100755 --- a/include/msksheet.cpp +++ b/include/msksheet.cpp @@ -78,7 +78,8 @@ public: void move_column( const int fromindex, const int toindex ) const; void set_column_width( const int col, const int width ) const; void set_column_header( const int col, const TString& header ) const; - + + void swap_columns(const int fromid, const int toid) const; void enable_cell(int row, int column, bool on = TRUE); bool cell_disabled(int row, int column) const; @@ -92,8 +93,9 @@ public: int items() const { return _str.items(); } int selected() const { return _cur_rec; } + void select(int r); int columns() const { return _columns; } - + bool dirty() const { return _owner->dirty(); } void set_dirty(bool spork = TRUE) { _owner->set_dirty(spork); } @@ -261,10 +263,16 @@ TSpreadsheet::TSpreadsheet(short x, short y, short dx, short dy, long flags = XI_ATR_EDITMENU | XI_ATR_AUTOSCROLL; switch (acqua) { + case CLASS_EDIT_FIELD: + if (f->right_justified()) + flags |= XI_ATR_RJUST; + break; case CLASS_REAL_FIELD: - flags |= XI_ATR_RJUST; break; + flags |= XI_ATR_RJUST; + break; case CLASS_BUTTON_FIELD: - flags |= XI_ATR_SELECTABLE; break; + flags |= XI_ATR_SELECTABLE; + break; default: break; } @@ -888,6 +896,12 @@ void TSpreadsheet::activate(bool on) } } +void TSpreadsheet::select(int r) +{ + xi_scroll_rec(_list, r, NORMAL_COLOR, XI_ATR_ENABLED | XI_ATR_AUTOSELECT, 0); + set_focus_cell(0, 1); +} + #else #include @@ -1165,6 +1179,39 @@ void TSpreadsheet::move_column( const int fromindex, const int toindex) const #endif } +void TSpreadsheet::swap_columns(const int fromid, const int toid) const +{ +#if XVT_OS == XVT_OS_WIN + int num; + XI_OBJ** columns = xi_get_member_list(_list, &num); + + XI_OBJ* from_column = XI_NULL_OBJ; + XI_OBJ* to_column = XI_NULL_OBJ; + int from_pos = 0; + int to_pos = 0; + + for (int c = 1; c < num; c++) + { + XI_OBJ* column = columns[c]; + if (column->cid == fromid) + { + from_column = column; + from_pos = c; + } + if (column->cid == toid) + { + to_column = column; + to_pos = c; + }; + } + + xi_move_column(from_column, to_pos); + if (to_pos < from_pos) from_pos++; + xi_move_column(to_column, from_pos); +#endif +} + + void TSpreadsheet::set_column_width(const int col, const int width) const { #if XVT_OS == XVT_OS_WIN @@ -1261,7 +1308,7 @@ void TSpreadsheet::str2mask(int riga) // Certified 100% bool TSpreadsheet::notify(int rec, KEY k) { - const bool ok = _notify ? _notify(rec, k) : TRUE; + const bool ok = _notify ? _notify(*_owner, rec, k) : TRUE; if (k == K_ENTER) set_dirty(ok ? TRUE : 3); return ok; @@ -1504,6 +1551,11 @@ void TSheet_field::delete_column( const int col ) const _sheet->delete_column( col ); } +void TSheet_field::swap_columns(const int fromid, const int toid) const +{ + _sheet->swap_columns(fromid, toid); +} + void TSheet_field::move_column( const int fromindex, const int toindex ) const { _sheet->move_column(fromindex, toindex ); @@ -1535,6 +1587,12 @@ bool TSheet_field::on_hit() return TRUE; } +void TSheet_field::select(int r) +{ + _sheet->select(r); +} + + bool TSheet_field::test_focus_change() { return _sheet->test_focus_change(); diff --git a/include/msksheet.h b/include/msksheet.h index 82e6943fb..9686f60d7 100755 --- a/include/msksheet.h +++ b/include/msksheet.h @@ -5,10 +5,10 @@ #include #endif - +class TSheet_field; class TSpreadsheet; -typedef bool (*SPREADSHEET_NOTIFY)(int r, KEY k); -// Matteo + +typedef bool (*SPREADSHEET_NOTIFY)(TSheet_field& s, int r, KEY k); typedef TMask* (*SPREADSHEET_GETMASK)( int numriga, TMask& fullmask, bool destroy ); @@ -34,9 +34,12 @@ protected: public: TToken_string& row(int n); // Get/Create a new row TString_array& rows_array() const; // Get all rows + const char* cell(int r, int c) { return row(r).get(c); } // Get item c of row r + int first_empty() const; // First empty row int items() const; // Number of rows int selected() const; // Number of current row + void select(int r); // Select row r as current virtual void reset(); virtual void enable(bool on); @@ -58,6 +61,8 @@ public: void delete_column( const int col ) const; void move_column( const int fromindex, const int toindex ) const; + void swap_columns(const int fromid, const int toid) const; + void set_column_width( const int col, const int width ) const; void set_column_header( const int col, const TString& header ) const; void set_append(bool on = TRUE) { _append = on;} diff --git a/include/real.cpp b/include/real.cpp index 48cc17d69..4f69d6d3e 100755 --- a/include/real.cpp +++ b/include/real.cpp @@ -1072,7 +1072,7 @@ int TImporto::compare(const TSortable& s) const const TImporto& i = (const TImporto&)s; const real d = valore() - i.valore(); int res = d.sign(); - if (res == 0) + if (res == 0 && !is_zero()) res = sezione() != i.sezione(); return res; } diff --git a/include/relapp.cpp b/include/relapp.cpp index 0b23631a5..a14d3bed4 100755 --- a/include/relapp.cpp +++ b/include/relapp.cpp @@ -1,4 +1,4 @@ -// $Id: relapp.cpp,v 1.63 1995-07-19 09:57:17 guy Exp $ +// $Id: relapp.cpp,v 1.64 1995-08-09 09:54:27 guy Exp $ #include #include #include @@ -601,7 +601,7 @@ bool TRelation_application::save(bool check_dirty) get_relation()->lfile().reread(_unlock); // Unlock main file } was_dirty = FALSE; - return k == K_ESC; + return k == K_NO; } if (annulla) diff --git a/include/relation.cpp b/include/relation.cpp index b200474bd..8223e3a75 100755 --- a/include/relation.cpp +++ b/include/relation.cpp @@ -1,4 +1,4 @@ -// $Id: relation.cpp,v 1.55 1995-08-03 14:55:26 angelo Exp $ +// $Id: relation.cpp,v 1.56 1995-08-09 09:54:30 guy Exp $ // relation.cpp // fv 12/8/93 // relation class for isam files @@ -1539,12 +1539,7 @@ const char* TFieldref::read(const TRectype& rec) const if (_from > 0 || _to > 0) { const int l = buffer.len(); - // const int from = (_from > l) ? l : _from; - // const int to = (_to > l || _to < 1) ? l : _to; - // if (to < l) buffer.cut(to); if (_to < l && _to > 0) buffer.cut(_to); - - // if (from > 0) buffer.ltrim(from); if (_from > 0) buffer.ltrim(_from); } } @@ -1554,36 +1549,15 @@ const char* TFieldref::read(const TRectype& rec) const const char* TFieldref::read(const TRelation* c) const { CHECK(c != NULL, "Can't read field from NULL relation"); - const char * s; - /* - if (c == NULL) - { - TLocalisamfile f(_fileid, TRUE); - s = read(f.curr()); - } - else - */ - s = read(c->lfile(_id).curr()); - + const char * s = read(c->lfile(_id).curr()); return s; } void TFieldref::write(const char* val, TRelation* c) const { CHECK(c != NULL, "Can't write field on NULL relation"); - - /* - if (c == NULL) - { - TLocalisamfile f(_fileid, TRUE); - write(val, f.curr()); - } - else - */ -{ TRectype &curr = c->lfile(_id).curr(); write(val, curr); -} } @@ -1624,15 +1598,28 @@ TRecord_array::TRecord_array(const TRectype& r, const char* numfield, int first) TRecord_array::TRecord_array(int logicnum, const char* numfield, int first) : _file(logicnum), _num(numfield), _offset(first - 1) -{} +{ + add(new TRectype(logicnum)); +} + +TRecord_array::TRecord_array(const TRecord_array& a) +: TArray(a), _file(a._file), _offset(a._offset), _num(a._num) +{} const TRectype& TRecord_array::key() const { TRectype* r = (TRectype*)objptr(0); - CHECK(r, "A TRecord_array lost its key"); + CHECK(r, "TRecord_array lost its key"); return *r; } +bool TRecord_array::exist(int n) const +{ + const int i = n > 0 ? n - _offset : -1; + TRectype* r = (TRectype*)objptr(i); + return r != NULL; +} + TRectype& TRecord_array::row(int n, bool create) { @@ -1640,10 +1627,10 @@ TRectype& TRecord_array::row(int n, bool create) TRectype* r = (TRectype*)objptr(i); if (r == NULL && create) { - r = new TRectype(key()); + r = (TRectype*)key().dup(); // Crea nuovo record copiando la chiave n = add(r, i) + _offset; // Riassegna n se era negativo! r->put(_num, n); // Aggiorna campo numero riga - } + } CHECKD(r && n > 0, "Bad record number ", n); return *r; } @@ -1651,15 +1638,6 @@ TRectype& TRecord_array::row(int n, bool create) bool TRecord_array::renum_key(const char* field, const TString& num) { CHECKS(!num.blank(), "Blank key value for field: ", field); - - TRectype* r = (TRectype*)objptr(0); - if (r == NULL) - { - r = new TRectype(_file); - r->zero(); - add(r, 0); - } - const TString& curr = key().get(field); if (curr == num) @@ -1667,8 +1645,8 @@ bool TRecord_array::renum_key(const char* field, const TString& num) for (int i = last(); i >= 0; i--) { - r = (TRectype*)objptr(i); - if (r) r->put(field, num); + TRectype* r = (TRectype*)objptr(i); + if (r != NULL) r->put(field, num); } return TRUE; @@ -1686,16 +1664,23 @@ int TRecord_array::rec2row(const TRectype& r) const { CHECK(r == key(), "Incompatible record"); const int n = atoi(r.get(_num)) - _offset; // Non e' detto che sia un int! - CHECKD(n > 0 && n < 32000, "Bad line number in record ", n + _offset); + CHECKD(n >= 0 && n < 30000, "Bad line number in record ", n + _offset); return n; } -int TRecord_array::add_row(const TRectype& r) +int TRecord_array::add_row(TRectype* r) { - const int nr = rec2row(r); - TRectype* o = (TRectype*)objptr(nr); - if (o) *o = r; - else add(r, nr); + const int nr = rec2row(*r); + add(r, nr); + if (nr == 0 && rows() > 0) // Se ho cambiato il record campione + { // e ci sono altre righe ... + for (int f = r->items()-1; f >= 0; f--) + { + const char* fn = r->fieldname(f); + const TString& v = r->get(fn); + if (v.not_empty()) renum_key(fn, v); // ... aggiorna tutte le righe in base + } // ai campi non vuoti del campione + } return nr; } @@ -1719,29 +1704,44 @@ void TRecord_array::destroy_rows() destroy(i); } -int TRecord_array::read(const TRectype& filter) +int TRecord_array::read(TRectype* 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); + 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); destroy(); add(filter, 0); // Store filter record for later use - - TLocalisamfile f(_file); - f.curr() = key(); - int err = f.read(_isgteq); - for (int e = err; e == NOERR && f.curr() == key(); e = f.next()) - add_row(f.curr()); + int err = NOERR; + if (!filter->empty()) + { + TLocalisamfile f(_file); + TRectype* rec = (TRectype*)filter->dup(); + err = rec->read(f, _isgteq); + for (int e = err; e == NOERR && *rec == key(); e = rec->next(f)) + add_row(*rec); + delete rec; + } return err; } -int TRecord_array::write(bool re) + +int TRecord_array::read(const TRectype& filter) +{ + TRectype* f = (TRectype*)filter.dup(); + return read(f); +} + + + +int TRecord_array::write(bool re) const { int err = NOERR; TLocalisamfile f(_file); - + + int last_on_file = 0; + const int u = last(); for (int i = 1; i <= u; i++) { @@ -1751,44 +1751,62 @@ int TRecord_array::write(bool re) { if (re) { - err = f.rewrite(*r); + err = r->rewrite(f); if (err == _iskeynotfound || err == _iseof || err == _isemptyfile) - err = f.write(*r); + err = r->write(f); if (err != NOERR) break; } else { - err = f.write(*r); + err = r->write(f); if (err == _isreinsert) - err = f.rewrite(*r); + err = r->rewrite(f); if (err != NOERR) break; } } else - { - f.curr() = key(); f.put(_num, i + _offset); - err = f.read(); - if (err == NOERR) // La riga c'era ma ora non piu' + { + const int pos = i+_offset; + if (pos > last_on_file) { - err = f.remove(); - if (err != NOERR) - break; - } + TRectype* rec = (TRectype*)key().dup(); + rec->put(_num, pos); + err = rec->read(f, _isgteq); + if (err == NOERR) // La riga c'era ma ora non piu' + { + last_on_file = atoi(rec->get(_num)); + if (last_on_file == pos) + { + err = (rec->remove(f)); + if (err != NOERR) + { + delete rec; + break; + } + } + } + else + last_on_file = 30000; + delete rec; + } } } - if (re && err == NOERR) + if (re && err == NOERR && last_on_file != 30000) { + const int pos = i+_offset; + TRectype* rec = (TRectype*)key().dup(); // Cancella eventuali residui successivi - f.curr() = key(); f.put(_num, i + _offset); - for (int e = f.read(_isgteq); e == NOERR && f.curr() == key(); e = f.next()) + rec->put(_num, pos); + for (int e = rec->read(f, _isgteq); e == NOERR && *rec == key(); e = rec->next(f)) { - err = f.remove(); + err = rec->remove(f); if (err != NOERR) break; - } + } + delete rec; } return err; diff --git a/include/relation.h b/include/relation.h index 181a048dd..dc9d64740 100755 --- a/include/relation.h +++ b/include/relation.h @@ -1,4 +1,4 @@ -/* $Id: relation.h,v 1.23 1995-08-03 14:55:31 angelo Exp $ */ +/* $Id: relation.h,v 1.24 1995-08-09 09:54:34 guy Exp $ */ // join.h // fv 12/8/93 // join class for isam files @@ -135,21 +135,24 @@ class TRecord_array : private TArray int _offset; // Offset iniziale del record array TString16 _num; // Nome del campo col numero di riga -private: +protected: int rec2row(const TRectype& r) const; // Estrae il numero riga di un record - const TRectype& key() const; + const TString& num_field() const { return _num; } public: + const TRectype& key() const; int rows() const { return items()-1; } // Numero di righe presenti int last_row() const { return last() + _offset; } // Ultima riga - int first_row() const { return 1 + _offset ; } + int first_row() const { return 1 + _offset ; } // Prima riga - const TRectype& row(int r) const // Ennesima riga costante + const TRectype& row(int r) const // Riga r costante { CHECKD(r > _offset, "Bad record number ", r); return (const TRectype&)operator[](r - _offset); } - TRectype& row(int r, bool create); // Ennesima riga + bool exist(int r) const; // Controlla se esiste la riga r + TRectype& row(int r, bool create); // Riga r con possibilita' di crearla - virtual int add_row(const TRectype& r); // Aggiungi/cambia una riga + virtual int add_row(TRectype* r); // Aggiungi/cambia una riga + int add_row(const TRectype& r) { return add_row((TRectype*)r.dup()); } virtual bool destroy_row(int n, bool pack = FALSE); // Cancella una riga virtual bool destroy_row(const TRectype& r, bool pack = FALSE) { return destroy_row(rec2row(r), pack); } void destroy_rows(); // Cancella tutte le righe @@ -158,12 +161,14 @@ public: bool renum_key(const char* field, long num); // Rinumera campo chiave in seguito a reinsert virtual int read(const TRectype& r); // Leggi tutto l'array da file - virtual int write(bool re = FALSE); // Aggiorna il file - virtual int rewrite() { return write(TRUE); } + virtual int read(TRectype* r); // Leggi tutto l'array da file + virtual int write(bool re = FALSE) const; // Aggiorna il file + virtual int rewrite() const { return write(TRUE); } virtual int remove(); // Cancella tutti i record dal file TRecord_array(const TRectype& r, const char* numfield, int first = 1); TRecord_array(int logicnum, const char* numfield, int first = 1); + TRecord_array(const TRecord_array& a); }; diff --git a/include/scadenze.h b/include/scadenze.h index 9a48c11f6..e28da0b41 100755 --- a/include/scadenze.h +++ b/include/scadenze.h @@ -1,29 +1,30 @@ -#ifndef __SCADENZE_H -#define __SCADENZE_H - -#define SCAD_ANNO "ANNO" -#define SCAD_NUMPART "NUMPART" -#define SCAD_NRATA "NRATA" -#define SCAD_CODPAG "CODPAG" -#define SCAD_TIPOPAG "TIPOPAG" -#define SCAD_ULTCLASS "ULTCLASS" -#define SCAD_IMPORTO "IMPORTO" -#define SCAD_CODVAL "CODVAL" -#define SCAD_CAMBIO "CAMBIO" -#define SCAD_IMPORTOVAL "IMPORTOVAL" -#define SCAD_DATACAMBIO "DATACAM" -#define SCAD_DATASCAD "DATASCAD" -#define SCAD_TIPOCF "TIPOC" -#define SCAD_GRUPPO "GRUPPO" -#define SCAD_CONTO "CONTO" -#define SCAD_SOTTOCONTO "SOTTOCONTO" -#define SCAD_NSOLL "NSOLL" -#define SCAD_DATASOLL "DATASOLL" -#define SCAD_GGRIT "GGRIT" -#define SCAD_PAGATA "PAGATA" -#define SCAD_IMPORTOPAG "IMPORTOPAG" -#define SCAD_CODABIPR "CODABIPR" -#define SCAD_CODCABPR "CODCABPR" - -#endif - +#ifndef __SCADENZE_H +#define __SCADENZE_H + +#define SCAD_TIPOCF "TIPOC" +#define SCAD_GRUPPO "GRUPPO" +#define SCAD_CONTO "CONTO" +#define SCAD_SOTTOCONTO "SOTTOCONTO" +#define SCAD_ANNO "ANNO" +#define SCAD_NUMPART "NUMPART" +#define SCAD_NRIGA "NRIGA" +#define SCAD_NRATA "NRATA" +#define SCAD_CODPAG "CODPAG" +#define SCAD_TIPOPAG "TIPOPAG" +#define SCAD_ULTCLASS "ULTCLASS" +#define SCAD_IMPORTO "IMPORTO" +#define SCAD_CODVAL "CODVAL" +#define SCAD_CAMBIO "CAMBIO" +#define SCAD_IMPORTOVAL "IMPORTOVAL" +#define SCAD_DATACAMBIO "DATACAM" +#define SCAD_DATASCAD "DATASCAD" +#define SCAD_NSOLL "NSOLL" +#define SCAD_DATASOLL "DATASOLL" +#define SCAD_GGRIT "GGRIT" +#define SCAD_PAGATA "PAGATA" +#define SCAD_IMPORTOPAG "IMPORTOPAG" +#define SCAD_CODABIPR "CODABIPR" +#define SCAD_CODCABPR "CODCABPR" + +#endif +