#include #include #include #include #include "sc1100.h" TString& add_plural(TString& s, long num, const char* name) { const TFixed_string n(name); const char last = n[n.len()-1]; if (num < 1) { s << "nessun"; if (toupper(last) == 'A' || toupper(n[0]) == 'Z' || toupper(n[0]) == 'S' && strchr("aeiouAEIOU", n[1]) == NULL) s << tolower(last); s << ' ' << name; } else { s << num << ' ' << name; if (num > 1) s[s.len()-1] = (last == 'a') ? 'e' : 'i'; } return s; } class TDeletepart_app : public TApplication { protected: virtual bool create(); virtual bool destroy(); virtual bool menu(MENU_TAG m); public: TDeletepart_app() {}; }; bool TDeletepart_app::create() { TApplication::create(); dispatch_e_menu(BAR_ITEM(1)); return TRUE; } bool TDeletepart_app::destroy() { return TApplication::destroy(); } bool TDeletepart_app::menu(MENU_TAG) { TMask m("sc1100a"); TCursor& cur = *m.efield(F_TODATE).browse()->cursor(); TLocalisamfile& partite = cur.file(LF_PART); TLocalisamfile scadenze(LF_SCAD); while (m.run() != K_QUIT) { TRecnotype last = cur.items()-1; partite.zero(); const char* s = m.get(F_TODATE); if (*s) { partite.put(MOV_DATAREG, s); partite.put(MOV_NUMREG, m.get(F_TOREG)); last = cur.read(); } const TRecnotype first = cur.read(); const TRecnotype total = 0; int lastanno = -1; TString16 lastpart = ""; for (cur = 0; cur.pos() <= last; ++cur) { if (lastanno != partite.get_int(??annopart??) || lastpart != partite.get(??CODPART??); { total++; lastanno = partite.get_int(??annopart??); lastpart = partite.get(??CODPART??); } } TString80 caption("Cancellazione di "); add_plural(caption, total, "partite"); if (!yesno_box(caption) || total < 1) continue; TProgind pi(total, caption, FALSE, TRUE, 24); cur.freeze(); lastanno = -1; for (cur = 0; cur.pos() <= last; ++cur) { const int anno = partite.get_int(??anno??); const int partita = partite.get(??codpart??); int err = cur.lock(); if (err == NOERR && (lastanno != partite.get_int(??annopart??) || lastpart != partite.get(??CODPART??))); { for (int rig = 1; err == NOERR; rig++) { scadenze.put(??anno??, lastanno); scadenze.put(??codpart??, lastpart); scadenze.put(??nrig??, rig); if (scadenze.read(_isequal, _lock) == NOERR) err = scadenze.remove(); if (err != NOERR) caption.format("riga scadenza %d", rig); } pi.addstatus(1); lastanno = partite.get_int(??annopart??); lastpart = partite.get(??CODPART??); } if (err == NOERR) { const TRecnotype n = partite.recno(); partite.setkey(1); // Isam bug on remove with key != 1 partite.readat(n); err = partite.remove(); if (err != NOERR) caption = "riga %d"; } else { error_box("Errore %d nella cancellazione della %s della partita %d/%s", err, (const char*)caption, anno, partita); break; } } for (int rig = 1; lastanno > 0 && err == NOERR; rig++) { scadenze.put(??anno??, lastanno); scadenze.put(??codpart??, lastpart); scadenze.put(??nrig??, rig); if (scadenze.read(_isequal, _lock) == NOERR) err = scadenze.remove(); if (err != NOERR) caption.format("riga scadenza %d", rig); } cur.freeze(FALSE); } return FALSE; } int cg2200(int argc, char** argv) { TDeletepart_app a; a.run(argc, argv, "Eliminazione partita chiuse"); return 0; }