diff --git a/src/ba/ba1.cpp b/src/ba/ba1.cpp index e654bfd91..51ad73fae 100755 --- a/src/ba/ba1.cpp +++ b/src/ba/ba1.cpp @@ -16,7 +16,7 @@ int main(int argc,char** argv) case 4: ba1500(argc,argv); break; // Attivazione moduli case 5: ba1600(argc,argv); break; // Creazione dischi e fascicolatore case 6: ba1700(argc,argv); break; // Installazione moduli - case 7: ba1800(argc,argv); break; // Utility(?) + case 7: ba1800(argc,argv); break; // importazione file case 8: ba1900(argc,argv); break; // Dizionario default: ba1100(argc,argv); break; // Manutenzione } diff --git a/src/ba/ba1800.cpp b/src/ba/ba1800.cpp index 5efdc1445..5492f27a6 100755 --- a/src/ba/ba1800.cpp +++ b/src/ba/ba1800.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -25,9 +26,11 @@ HIDDEN int get_isamfiles() HIDDEN int str2isamfile(const TString& str) { int logic_num = 0; + if (!str.blank()) { const int logic = atoi(str); + if (logic > 0) { if (logic > LF_DIR && logic < LF_EXTERNAL) @@ -35,7 +38,8 @@ HIDDEN int str2isamfile(const TString& str) if (logic < get_isamfiles()) { TBaseisamfile file(logic); - if (file.is_valid(FALSE) == NOERR) + + if (file.is_valid(false) == NOERR) logic_num = logic; } } @@ -43,9 +47,11 @@ HIDDEN int str2isamfile(const TString& str) else { const int len = str.len(); + if (len == 3 || (str[0] == '%' && len == 4)) { const int first = len == 3 ? 0 : 1; + if (isalpha(str[first]) && isalnum(str[first+1]) && isalnum(str[first+2])) logic_num = str[0] == '%' ? LF_TABCOM : LF_TAB; } @@ -58,15 +64,16 @@ HIDDEN int choose_isamfile(int selected) { TArray_sheet sht(-1,-1,-4,-4,TR("Selezione archivio"), HR("Codice|Descrizione archivio@70")); TToken_string tt(80); - long sel = 0; - const int nfiles = get_isamfiles(); + for (int logic = LF_TABCOM; logic < nfiles; logic++) { if (logic == selected) sel = sht.items(); + const TFixed_string desc = prefix().description(logic); + if (desc.full() && desc.compare("File non presente", -1, true) != 0) { tt.format("%d", logic); @@ -111,7 +118,7 @@ public: void recalc_layout(int dx, int dy); bool clickable() const { return _clickable; } - void set_clickable(bool on = TRUE) { _clickable = on; } + void set_clickable(bool on = true) { _clickable = on; } void destroy_rows() { _rows.destroy(); } void add_row(const char* row) { _rows.add(row); } @@ -150,14 +157,17 @@ public: int TColumnizer_win::on_column(long col) { - int index = -1; + int index = -1; + if (col > 0) { int action = 1; // 1 = Add, 2 = Remove int i; + for (i = _column.items()-1; i >= 0; i--) { const long cur_col = _column.get_long(i); + if (cur_col == col) { action = 2; @@ -171,13 +181,14 @@ int TColumnizer_win::on_column(long col) } TSheet_field& sf = owner().mask().sfield(F_FIELDS); + switch(action) { case 1: index = _column.insert_long(col, i+1); break; case 2: - _column.destroy(i, TRUE); + _column.destroy(i, true); index = i; break; default: @@ -197,21 +208,21 @@ void TColumnizer_win::update() TString80 str; TField_window::update(); - set_color(NORMAL_COLOR, NORMAL_BACK_COLOR); for (i = y; i < maxy-RULER_HEIGHT; i++) { TToken_string* row = (TToken_string*)_rows.objptr(i); + if (row) stringat(NUM_WIDTH, i+RULER_HEIGHT, _rows.row(i)); else break; } - set_brush(DISABLED_BACK_COLOR); - bar(x, y, maxx, y+RULER_HEIGHT); + TString points(maxx); + points.fill('.'); for (int n = x+1; n < maxx; n++) { @@ -227,7 +238,6 @@ void TColumnizer_win::update() } } stringat(NUM_WIDTH, y, points); - bar(x, y, x+NUM_WIDTH, maxy); for (i = y; i < maxy; i++) { @@ -238,19 +248,24 @@ void TColumnizer_win::update() set_pen(COLOR_BLACK); int last_column = 0; + for (i = 0; i < _column.items(); i++) { const int j = (int)_column.get_long(i); + if (j > x) { - _pixmap = TRUE; + _pixmap = true; line((j+NUM_WIDTH)*CHARX, (y+1)*CHARY, (j+NUM_WIDTH)*CHARX, maxy*CHARY); - _pixmap = FALSE; + _pixmap = false; } const int available = j-last_column; + str.format("%d(%d)", i+1, available); + int len = str.len(); + if (len > available) { len = str.find('('); @@ -266,11 +281,11 @@ void TColumnizer_win::update() last_column = j; } - _pixmap = TRUE; + _pixmap = true; line((x+NUM_WIDTH)*CHARX, (y+1)*CHARY, maxx*CHARX, (y+1)*CHARY); line(x*CHARX, (y+RULER_HEIGHT)*CHARY, maxx*CHARX, (y+RULER_HEIGHT)*CHARY); line((x+NUM_WIDTH)*CHARX, y*CHARY, (x+NUM_WIDTH)*CHARX, maxy*CHARY); - _pixmap = FALSE; + _pixmap = false; } long TColumnizer_win::handler(WINDOW win, EVENT* ep) @@ -281,6 +296,7 @@ long TColumnizer_win::handler(WINDOW win, EVENT* ep) if (_clickable) { long column = (ep->v.mouse.where.h + CHARX/2) / CHARX; + column += origin().x - NUM_WIDTH; if (on_column(column) >= 0) force_update(); @@ -296,6 +312,7 @@ void TColumnizer_win::recalc_layout(int dx, int dy) { long maxy = _rows.items() - rows()/2 + 1; long maxx = dx; + if (maxx <= 0) maxx = _column.get_long(_column.items()-1) + 384; maxx -= columns()/2 + NUM_WIDTH; @@ -330,6 +347,7 @@ protected: // TMask protected: // TAutomask virtual bool on_field_event(TOperable_field& f, TField_event e, long jolly); + void check_import(); protected: // Internal use only bool file_open(TFilename& name) const; @@ -338,14 +356,10 @@ protected: // Internal use only bool load_aga(const TFilename& name); void file_preview() const; bool is_aga_file(const TFilename& name) const; - bool import_file(); + bool import_file(); + bool update_file(); TRelation_description* rel_desc(int logicnum); - - // First non-static handlers in history! - bool file_handler(TOperable_field& f, TField_event e); - bool ini_handler(TOperable_field& f, TField_event e); - bool isamfile_handler(TOperable_field& f, TField_event e); public: TRelation_description* rel_desc(); @@ -374,7 +388,7 @@ public: bool TFields_mask::on_field_event(TOperable_field& of, TField_event fe, long jolly) { - bool ok = TRUE; + bool ok = true; switch(of.dlg()) { case F_FIELD: @@ -391,16 +405,18 @@ TRelation_description* TFields_mask::rel_desc() const TSheet_field* sf = get_sheet(); TWizard_mask& wm = (TWizard_mask&)sf->mask(); TRelation_description* rd = wm.rel_desc(); + return rd; } bool TFields_mask::field_handler(TOperable_field& of, TField_event fe) { - bool ok = TRUE; + bool ok = true; if (fe == fe_button) { TRelation_description* rd = rel_desc(); + if (rd) { if (rd->choose_field(of.get())) @@ -416,12 +432,14 @@ bool TFields_mask::field_handler(TOperable_field& of, TField_event fe) if (fe == fe_modify || fe_close) { const TString& n = of.get(); + if (n.not_empty()) { TRelation_description* rd = rel_desc(); if (rd) { const char* d = rd->get_field_description(n); + if (d && *d) set(F_DESCR, d); else @@ -480,9 +498,11 @@ void TFields_sheet::create(WINDOW win) void TFields_sheet::describe_fields() { TRelation_description* rd = _sheet_mask->rel_desc(); + if (rd) { TString str; + for (int r = items()-1; r >= 0; r--) { TToken_string& riga = row(r); @@ -496,7 +516,7 @@ void TFields_sheet::describe_fields() } TFields_sheet::TFields_sheet(TAutomask* m) - : TSheet_field(m), _sheet_mask(NULL) + : TSheet_field(m), _sheet_mask(nullptr) { } @@ -509,51 +529,62 @@ TFields_sheet::~TFields_sheet() bool TWizard_mask::file_open(TFilename& fname) const { DIRECTORY dir; + xvt_fsys_get_dir(&dir); // Save dir FILE_SPEC fs; + xvt_fsys_convert_str_to_fspec(fname, &fs); const bool good = xvt_dm_post_file_open(&fs, TR("Selezionare il file ...")) == FL_OK; - xvt_fsys_set_dir(&dir); // Restore dir - - if (good) - fname = fs.name; + xvt_fsys_set_dir(&dir); // Restore dir + + if (good) + { + char buffer[_MAX_PATH]; + + xvt_fsys_convert_fspec_to_str(&fs, buffer, _MAX_PATH); + fname = buffer; + } return good; } void TWizard_mask::load_ini(const TString& ininame) { TWait_cursor hourglass; + if (!_frozen) { - _frozen = TRUE; + _frozen = true; TConfig ini(ininame, "MAIN"); + const int recsize = ini.get_int("RECORDSIZE"); if (recsize > 0) { - set(F_FIXEDLEN, "X", TRUE); - set(F_RECLEN, recsize, TRUE); + set(F_FIXEDLEN, "X", true); + set(F_RECLEN, recsize, true); } else - set(F_RECSEP, ini.get("RECORDSEP").left(4), TRUE); + set(F_RECSEP, ini.get("RECORDSEP").sleft(4), true); set(F_SKIPLINES, ini.get_int("SKIPLINES")); - const TString16 fldsep = ini.get("FIELDSEP").left(1); - set(F_FIELDSEP, fldsep, TRUE); + const TString16 fldsep = ini.get("FIELDSEP").sleft(1); + set(F_FIELDSEP, fldsep, true); ini.set_paragraph("RECORD"); if (fldsep.empty()) { TColumnizer_field& cf = (TColumnizer_field&)field(F_COLUMNIZER); + for (int i = 0; ; i++) { if (i > 0) { - const long position = ini.get_long("POSITION", NULL, i); + const long position = ini.get_long("POSITION", nullptr, i); + if (position > 0) cf.add_column(position); else @@ -565,23 +596,25 @@ void TWizard_mask::load_ini(const TString& ininame) } TString use = ini.get("USE"); + if (use.not_empty()) set(F_ISAM, use); TRelation_description* rd = rel_desc(); - TFields_sheet& fs = (TFields_sheet&)sfield(F_FIELDS); TFieldref fr; + for (int i = 0; ini.exist("NAME", i) || ini.exist("POSITION", i); i++) { - const TString& campo = ini.get("FIELD", NULL, i); + const TString& campo = ini.get("FIELD", nullptr, i); TToken_string& row = fs.row(i); + if (campo.not_empty()) { fr = campo; row = fr.name(); - if (rd == NULL) + if (rd == nullptr) { int isam = fr.file(); if (isam) @@ -590,13 +623,12 @@ void TWizard_mask::load_ini(const TString& ininame) rd = rel_desc(); } } - if (rd) row.add(rd->get_field_description(fr.name())); } } fs.force_update(); - _frozen = FALSE; + _frozen = false; } } @@ -608,6 +640,7 @@ void TWizard_mask::save_ini(const TFilename& ininame) const yesno_box(FR("Si desidera sovrascrivere il file %s"), (const char*)ininame)) { TConfig ini(ininame, "MAIN"); + ini.remove_all(); ini.set("RECORDSEP", get(F_RECSEP)); ini.set("RECORDSIZE", get(F_RECLEN)); @@ -624,27 +657,33 @@ void TWizard_mask::save_ini(const TFilename& ininame) const { const TColumnizer_field& cf = (const TColumnizer_field&)field(F_COLUMNIZER); long last_column = 0; + for (int i = 0; ; i++) { const long column = cf.get_column(i); + if (column <= 0) break; + const long len = column - last_column; - ini.set("POSITION", last_column, NULL, TRUE, i); - ini.set("LENGTH", len, NULL, TRUE, i); + + ini.set("POSITION", last_column, nullptr, true, i); + ini.set("LENGTH", len, nullptr, true, i); last_column = column; } } TSheet_field& sf = sfield(F_FIELDS); + FOR_EACH_SHEET_ROW(sf, r, row) { - ini.set("FIELD", row->get(0), NULL, TRUE, r); + ini.set("FIELD", row->get(0), nullptr, true, r); const char* name = row->get(1); - if (name == NULL || *name <= ' ') + + if (name == nullptr || *name <= ' ') name = row->get(0); - ini.set("NAME", name, NULL, TRUE, r); + ini.set("NAME", name, nullptr, true, r); } } } @@ -653,9 +692,11 @@ void TWizard_mask::save_ini(const TFilename& ininame) const bool TWizard_mask::is_aga_file(const TFilename& name) const { bool yes = xvt_str_compare_ignoring_case(name.ext(), "txt") == 0; + if (yes) { TScanner aga(name); + yes = aga.paragraph("Data"); // Esiste il paragrafo dati? } return yes; @@ -664,37 +705,39 @@ bool TWizard_mask::is_aga_file(const TFilename& name) const bool TWizard_mask::load_aga(const TFilename& name) { TWait_cursor hourglass; + if (!_frozen) { - _frozen = TRUE; + _frozen = true; + TSheet_field& sf = sfield(F_FIELDS); TScanner aga(name); TToken_string riga(1024); TToken_string campo(15, ','); TString isam; - bool inside_header = FALSE; + bool inside_header = false; while (aga.line().not_empty()) { riga = aga.token(); - if (riga.compare("[Data]", -1, TRUE) == 0) + if (riga.compare("[Data]", -1, true) == 0) { - set(F_FIXEDLEN, "", TRUE); - set(F_RECLEN, "", TRUE); - set(F_RECSEP, "", TRUE); - set(F_FIELDSEP, "|", TRUE); - set(F_SKIPLINES, aga.linenum(), TRUE); + set(F_FIXEDLEN, "", true); + set(F_RECLEN, "", true); + set(F_RECSEP, "", true); + set(F_FIELDSEP, "|", true); + set(F_SKIPLINES, aga.linenum(), true); if (isam.not_empty()) - set(F_ISAM, isam, TRUE); + set(F_ISAM, isam, true); break; } - if (inside_header) { - if (riga.compare("Fields", 6, TRUE) == 0) + if (riga.compare("Fields", 6, true) == 0) { const int uguale = riga.find('='); + if (uguale >= 0) { riga.ltrim(uguale+1); @@ -704,36 +747,38 @@ bool TWizard_mask::load_aga(const TFilename& name) sf.check_row(sf.items()-1); } } - } else - if (riga.compare("File", 4, TRUE) == 0) - { - const int uguale = riga.find('='); - if (uguale >= 0) - { - isam = riga.mid(uguale+1); - isam.trim(); - } - } - else - inside_header = riga[0] != '['; + } + else + if (riga.compare("File", 4, true) == 0) + { + const int uguale = riga.find('='); + if (uguale >= 0) + { + isam = riga.smid(uguale+1); + isam.trim(); + } + } + else + inside_header = riga[0] != '['; } else { - if (riga.compare("[Header]", -1, TRUE) == 0) + if (riga.compare("[Header]", -1, true) == 0) { sf.destroy(); - inside_header = TRUE; + inside_header = true; } } } - _frozen = FALSE; + _frozen = false; } - return TRUE; + return true; } void TWizard_mask::file_preview() const { TWait_cursor hourglass; + if (_frozen) return; @@ -743,9 +788,9 @@ void TWizard_mask::file_preview() const const long skiplines = get_long(F_SKIPLINES); const TString& recsep = get(F_RECSEP); const TString& fieldsep = get(F_FIELDSEP); - const TString& fname = get(F_FILE); int flags = ios::in; + if (fixedlen) flags |= ios::binary; ifstream f(fname, flags); @@ -767,17 +812,19 @@ void TWizard_mask::file_preview() const } TColumnizer_field& cf = (TColumnizer_field&)field(F_COLUMNIZER); - int displines = get_int(F_DISPLINES); + if (displines <= 0) displines = cf.visible_rows(); TString_array righe; int l; + for (l = 0; l < displines; l++) { righe.add(new TToken_string(MAXLINE), l); - TToken_string& riga = righe.row(l); + + TToken_string& riga = righe.row(l); char* buff = riga.get_buffer(); if (fixedlen) @@ -800,22 +847,25 @@ void TWizard_mask::file_preview() const } if (fieldsep.blank()) - { cf.enable(); - } else { TPointer_array maxlen; + int maxcol = 0; int l; for (l = righe.items()-1; l >= 0; l--) { TToken_string& riga = righe.row(l); + riga.separator(fieldsep[0]); + int col = 0; + FOR_EACH_TOKEN(riga, tok) { const long len = *tok ? strlen(tok) : 1; + if (len > maxlen.get_long(col)) maxlen.add_long(len, col); col++; @@ -825,40 +875,47 @@ void TWizard_mask::file_preview() const } cf.disable(); cf.destroy_columns(); + long last_column = 0; + for (l = 0; l < maxcol; l++) { const long len = maxlen.get_long(l); + last_column += len; cf.add_column(last_column); } TToken_string oldrow; TString str; + for (l = righe.items()-1; l >= 0; l--) { TToken_string& riga = righe.row(l); + oldrow = riga; riga.cut(0); + int col = 0; + FOR_EACH_TOKEN(oldrow, tok) { const int len = (int)maxlen.get_long(col); + str = tok; - if (str[0] =='#' || real::is_real(str)) - str.right_just(len); - else - str.left_just(len); + str.left_just(len); + while (str.len() < len) + str << ' '; riga << str; col++; } } } - cf.destroy_rows(); for (int m = 0; m < righe.items(); m++) { TToken_string& riga = righe.row(m); + cf.add_row(riga); } cf.recalc_layout(reclen, righe.items()); @@ -868,231 +925,262 @@ TRelation_description* TWizard_mask::rel_desc(int logicnum) { if (_rel && _rel->lfile().num() != logicnum) { - delete _rel; - _rel = NULL; - delete _reldesc; - _reldesc = NULL; + safe_delete(_rel); + safe_delete(_reldesc); } - if (_rel == NULL && logicnum > 0) + if (_rel == nullptr && logicnum > 0) { _rel = new TRelation(logicnum); _reldesc = new TRelation_description(*_rel); } - return _reldesc; } TRelation_description* TWizard_mask::rel_desc() { - TRelation_description* rd = NULL; + TRelation_description* rd = nullptr; const TString& isam = get(F_ISAM); const int logicnum = str2isamfile(isam); + if (logicnum > 0) rd = rel_desc(logicnum); return rd; } -bool TWizard_mask::file_handler(TOperable_field& f, TField_event e) -{ - bool ok = TRUE; - - if (e == fe_button) - { - TFilename n("*.txt"); - if (file_open(n)) - { - f.set(n); - e = fe_modify; - } - } - - if (e == fe_modify) - { - TFilename n = f.get(); - if (n.exist()) - { - if (is_aga_file(n)) - { - load_aga(n); - } - else - { - const char* ext[] = { "imp", "ini", NULL }; - for (int e = 0; ext[e]; e++) - { - n.ext(ext[e]); - if (n.exist()) - { - set(F_INI, n, TRUE); - return TRUE; - } - } - } - - n = n.name(); - n.ext(""); - if ((n[0] == 'f' || n[0] == 'F') && atoi(n.mid(1,-1))) - n.ltrim(1); - if (str2isamfile(n)) - set(F_ISAM, n, TRUE); - - file_preview(); - } - else - ok = error_box(TR("Il file non esiste")); - } - return ok; -} - -bool TWizard_mask::ini_handler(TOperable_field& f, TField_event e) -{ - bool ok = TRUE; - switch (e) - { - case fe_button: - { - TFilename n("*.imp"); - if (file_open(n)) - f.set(n); - else - break; - } - case fe_init: - case fe_modify: - { - const TFilename n = f.get(); - const bool pieno = !n.blank(); - enable(F_SAVE, pieno); - if (pieno) - { - if (n.exist()) - { - load_ini(n); - file_preview(); - } - } - } - break; - default: - break; - } - return ok; -} - -bool TWizard_mask::isamfile_handler(TOperable_field& f, TField_event e) -{ - bool ok = TRUE; - switch (e) - { - case fe_init: - disable(F_IMPORT); - break; - case fe_button: - { - int logicnum = str2isamfile(f.get()); - logicnum = choose_isamfile(logicnum); - if (logicnum > 0) - f.set(logicnum); - else - break; - } - case fe_modify: - { - bool can_import = str2isamfile(f.get()) > 0; - if (can_import) - { - TFields_sheet& fs = (TFields_sheet&)sfield(F_FIELDS); - fs.describe_fields(); - } - else - ok = error_box(TR("File dati non valido")); - can_import &= fexist(get(F_FILE)); - enable(F_IMPORT, can_import); - reset(F_ZAP); - } - break; - } - return ok; -} - bool TWizard_mask::import_file() { - bool ok = FALSE; - const TFilename filename = get(F_FILE); + const int logicnum = str2isamfile(get(F_ISAM)); + if (!filename.exist()) return error_box(FR("Il file %s non esiste"), (const char*)filename); - - const int logicnum = str2isamfile(get(F_ISAM)); - if (logicnum <= 0) +if (logicnum <= 0) return error_box(TR("E' necessario specificare un file di destinazione valido")); - rel_desc(0); // Chiude il file isam correntemente in uso, altrimenti niente _excllock - TSystemisamfile sif(logicnum); + + TSystemisamfile sif(logicnum); + int err = sif.open_ex(_excllock); - if (err != NOERR) + + if (err != NOERR) return error_box(FR("Impossibile aprire il file %d: errore %d"), logicnum, err); - const bool empty = sif.items() == 0L; - sif.close(); - + + const bool empty = sif.items() == 0L; + + sif.close(); if (get_bool(F_ZAP)) { if (!empty && yesno_box(FR("Procedere con l'azzeramento del file %d?"), logicnum)) - sif.packfile(FALSE, TRUE); + sif.packfile(false, true); } const TFilename ininame = get(F_INI); + if (ininame.exist()) { TFile_text txt(filename, ininame); + err = txt.open('r'); if (err == NOERR) { TRecord_text rec; + for (long numrec = 1; txt.read(rec) == NOERR; numrec++) { err = txt.autosave(rec); if (err != NOERR) - { - ok = error_box(FR("Errore %d durante la scrittura del record %ld:"), + return error_box(FR("Errore %d durante la scrittura del record %ld:"), err, numrec); - break; - } } } else - ok = error_box(FR("Impossibile leggere il file %s"), (const char*)filename); + return error_box(FR("Impossibile leggere il file %s"), (const char*)filename); } else { if (is_aga_file(filename)) { err = sif.open_ex(_excllock); - if (err == NOERR) - ok = sif.load(filename) == NOERR; + if (err == NOERR) + { + int err = sif.load(filename); + + if (err != NOERR) + return error_box(FR("Impossibile caricare il file %s errore %d"), + (const char*)filename, err); + } else - ok = error_box(FR("Impossibile aprire il file %d: errore %d"), logicnum, err); + return error_box(FR("Impossibile aprire il file %d: errore %d"), logicnum, err); sif.close(); } else - ok = error_box(FR("Il file %s non esiste"), (const char*)ininame); + return error_box(FR("Il file %s non esiste"), (const char*)ininame); } - return ok; + return true; +} + +bool TWizard_mask::update_file() +{ + const TFilename filename = get(F_FILE); + const int logicnum = str2isamfile(get(F_ISAM)); + + if (!filename.exist()) + return error_box(FR("Il file %s non esiste"), (const char*)filename); + if (logicnum <= 0) + return error_box(TR("E' necessario specificare un file di destinazione valido")); + + rel_desc(0); // Chiude il file isam correntemente in uso, altrimenti niente _excllock + + TSystemisamfile sif(logicnum); + int err = sif.open_ex(_excllock); + + if (err != NOERR) + return error_box(FR("Impossibile aprire il file %d: errore %d"), logicnum, err); + const bool empty = sif.items() == 0L; + const TFilename ininame = get(F_INI); + + if (ininame.exist()) + { + TTrec recdes(logicnum); + TDir d(logicnum); + TFile_text txt(filename, ininame); + TTracciato_record * trc = txt.t_rec(logicnum); + CHECK(trc != nullptr, "Bad record description"); + int nflds = trc->nfields(); + + err = txt.open('r'); + if (err == NOERR) + { + TRecord_text rec; + TString msg = "Aggiornamento "; + + msg << d.name(); + + TProgress_monitor p(fsize(filename), msg); + + for (long numrec = 1; p.setstatus(txt.read_file()->tellg()) && txt.read(rec) == NOERR; numrec++) + { + TRectype outrec(logicnum); + + // find record + for (int i = 0; i < nflds; i++) + { + TTracciato_campo & des = trc->get(i); + const TString name = des.field().name(); + + outrec.put(name, rec.get(i)); + } + int err = outrec.read(sif, _isequal); + + if (err == NOERR) + { + // update record + for (int i = 0; i < nflds; i++) + { + TTracciato_campo & des = trc->get(i); + const TString name = des.field().name(); + + outrec.put(name, rec.get(i)); + } + err = outrec.rewrite(sif); + if (err != NOERR) + return error_box(FR("Errore %d durante la scrittura del record %ld:"), + err, numrec); + } + } + sif.close(); + } + else + return error_box(FR("Impossibile leggere il file %s"), (const char*)filename); + } + else + return error_box(FR("Il file %s non esiste"), (const char*)ininame); + return true; +} + +void TWizard_mask::check_import() +{ + bool can_import = str2isamfile(get(F_ISAM)) > 0; + + if (can_import) + { + TFields_sheet& fs = (TFields_sheet&)sfield(F_FIELDS); + + fs.describe_fields(); + } + can_import &= fexist(get(F_FILE)); + enable(F_IMPORT, can_import); + enable(F_UPDATE, can_import); } bool TWizard_mask::on_field_event(TOperable_field& f, TField_event e, long jolly) { - bool ok = TRUE; - if (jolly == 0) { switch(f.dlg()) { case F_FILE: - ok = file_handler(f, e); + if (e == fe_modify) + { + TFilename n = f.get(); + + if (n.exist()) + { + if (is_aga_file(n)) + load_aga(n); + else + { + const char* ext[] = { "imp", "ini", nullptr }; + + for (int e = 0; ext[e]; e++) + { + n.ext(ext[e]); + if (n.exist()) + { + set(F_INI, n, true); + return true; + } + } + } + n = n.name(); + n.ext(""); + if ((n[0] == 'f' || n[0] == 'F') && atoi(n.smid(1, -1))) + n.ltrim(1); + if (str2isamfile(n)) + set(F_ISAM, n, true); + file_preview(); + check_import(); + } + else + return error_box(TR("Il file non esiste")); + } break; case F_INI: - ok = ini_handler(f, e); + if (e == fe_button) + { + TFilename n("*.imp"); + + if (file_open(n)) + f.set(n); + check_import(); + } + else + if (e == fe_init || e == fe_modify) + { + const TFilename n = f.get(); + const bool pieno = n.full(); + + enable(F_SAVE, pieno); + if (pieno) + { + if (n.exist()) + { + load_ini(n); + file_preview(); + } + } + check_import(); + } break; case F_RECLEN: case F_RECSEP: @@ -1104,16 +1192,41 @@ bool TWizard_mask::on_field_event(TOperable_field& f, TField_event e, long jolly file_preview(); break; case F_ISAM: - ok = isamfile_handler(f, e); + if (e == fe_init) + { + disable(F_IMPORT); + disable(F_UPDATE); + } + else + if (e == fe_button) + { + int logicnum = str2isamfile(f.get()); + + logicnum = choose_isamfile(logicnum); + if (logicnum > 0) + f.set(logicnum); + else + error_box(TR("File dati non valido")); + } + else + if (e == fe_modify) + { + check_import(); + reset(F_ZAP); + } break; case F_SAVE: if (e == fe_button) save_ini(get(F_INI)); break; - case F_IMPORT: + case F_IMPORT: if (e == fe_button) import_file(); - break; + break; + case F_UPDATE: + if (e == fe_button) + update_file(); + break; case F_COLUMNIZER: if (e == fe_init) file_preview(); // Indispensabile! @@ -1126,14 +1239,15 @@ bool TWizard_mask::on_field_event(TOperable_field& f, TField_event e, long jolly { TFields_sheet& fs = (TFields_sheet&)sfield(F_FIELDS); - ok = ((TFields_mask&)fs.sheet_mask()).on_field_event(f, e, 0); + return ((TFields_mask&)fs.sheet_mask()).on_field_event(f, e, 0); } - return ok; + return true; } TMask_field* TWizard_mask::parse_field(TScanner& scanner) { const TString& key = scanner.key(); + if (key == "BR") return new TColumnizer_field(this); if (key == "SP") @@ -1142,7 +1256,7 @@ TMask_field* TWizard_mask::parse_field(TScanner& scanner) } TWizard_mask::TWizard_mask() - : _frozen(FALSE), _reldesc(NULL), _rel(NULL) + : _frozen(false), _reldesc(nullptr), _rel(nullptr) { read_mask("ba1800a", 0, 1); set_handlers(); @@ -1150,10 +1264,8 @@ TWizard_mask::TWizard_mask() TWizard_mask::~TWizard_mask() { - if (_reldesc) - delete _reldesc; - if (_rel) - delete _rel; + safe_delete(_reldesc); + safe_delete(_rel); } /////////////////////////////////////////////////////////// @@ -1172,12 +1284,15 @@ public: void TImport_wizard::import() { const int nLogicNum = atoi(argv(2)); + if (nLogicNum >= LF_USER) { const TFilename strName = argv(3); + if (strName.exist()) { TSystemisamfile file(nLogicNum); + file.load(strName); } else @@ -1192,7 +1307,8 @@ void TImport_wizard::main_loop() if (argc() < 3) { TWizard_mask m; - m.run(); + + while (m.run() == K_ENTER); } else import(); @@ -1201,6 +1317,7 @@ void TImport_wizard::main_loop() int ba1800(int argc, char* argv[]) { TImport_wizard of_oz; + of_oz.run(argc, argv, TR("Import Wizard")); return 0; } diff --git a/src/ba/ba1800.h b/src/ba/ba1800.h index 430c654a0..4caa18f72 100755 --- a/src/ba/ba1800.h +++ b/src/ba/ba1800.h @@ -13,5 +13,6 @@ #define F_ZAP 210 #define F_SAVE 250 #define F_IMPORT 251 +#define F_UPDATE 252 #define F_COLUMNIZER 300 #define F_FIELDS 301 diff --git a/src/ba/ba1800a.uml b/src/ba/ba1800a.uml index 7794eff51..bb2da6423 100755 --- a/src/ba/ba1800a.uml +++ b/src/ba/ba1800a.uml @@ -1,21 +1,28 @@ #include "ba1800.h" -TOOLBAR "" 0 20 0 3 +TOOLBAR "" 0 0 0 2 BUTTON F_SAVE 10 2 BEGIN - PROMPT -13 -11 "~Registra" + PROMPT -14 -11 "~Registra" PICTURE TOOL_SAVEREC END BUTTON F_IMPORT 10 2 BEGIN - PROMPT -23 -11 "~Importa" + PROMPT -24 -11 "~Importa" + PICTURE TOOL_IMPORT +END + +BUTTON F_UPDATE 10 2 +BEGIN + PROMPT -34 -11 "~Aggiorna" + PICTURE BMP_LINK END BUTTON DLG_QUIT 10 2 BEGIN - PROMPT -33 -11 "" + PROMPT -44 -11 "" END ENDPAGE @@ -25,7 +32,7 @@ PAGE "Importazione" -1 -1 78 23 STRING F_FILE 50 BEGIN PROMPT 1 1 "File da importare " - FLAGS "B" + FSELECT "*.*" END STRING F_INI 50 diff --git a/src/ba/bamenu.men b/src/ba/bamenu.men index b55f209cf..9f9f9e51f 100755 --- a/src/ba/bamenu.men +++ b/src/ba/bamenu.men @@ -123,7 +123,8 @@ Item_09 = "Gestione dizionario", "ba2 -6", "" Item_10 = "Query e Report", [MENU_014], "", 10217 Item_11 = "Firma digitale", "ba8 -6", "" Item_12 = "Trasferimenti", "ba7 -0 -f", "" -Item_13 = "Teleassistenza", "setup/teamviewerqs.exe", "F", 10236 +Item_13 = "Importazione file di testo", "ba1 -7", "" +Item_14 = "Teleassistenza", "setup/teamviewerqs.exe", "F", 10236 [MENU_016] Caption = "Procedure speciali"