#include #include #include "batbreg.h" #define REG_JOURNAL 5 class TGeneric_table_app : public Tab_application { long _oldditta; int _oldanno; bool _exist_journal; protected: virtual bool user_create() ; public: virtual void init_insert_mode(TMask& m) ; virtual bool protected_record(TRectype& rec) ; bool exist_journal() {return _exist_journal;} TGeneric_table_app() {} virtual ~TGeneric_table_app() {} }; HIDDEN inline TGeneric_table_app& app() { return (TGeneric_table_app&) main_app();} void TGeneric_table_app::init_insert_mode(TMask& m) { if (get_tabname() != "REG") return; long ditta = get_firm(); int anno = atoi(m.get(F_ANNO)); if (ditta != _oldditta || anno != _oldanno) { _oldditta = ditta; _oldanno = anno; TTable reg(get_tabname()); reg.zero(); reg.put("CODTAB", m.get(F_ANNO)); TRectype to(reg.curr()); _exist_journal = FALSE; for (reg.read(_isgteq); !_exist_journal && reg.good() && reg.curr() <= to; reg.next()) _exist_journal = (reg.get_long("I0") == REG_JOURNAL); } } bool TGeneric_table_app::protected_record(TRectype& rec) { bool prot = rec.get_bool(FPC); if (!prot) { if (get_tabname() == "%IVD") // Impedisce la cancellazione di una classe se ha sottoclassi { TLocalisamfile& f = get_relation()->lfile(); const TRecnotype pos = f.recno(); const TString16 cod(rec.get("CODTAB")); const int err = f.next(); if (err == NOERR) { TString16 next(f.get("CODTAB")); next.cut(cod.len()); prot = cod == next; } f.readat(pos); } } return prot; } HIDDEN bool tiporeg_handler(TMask_field& f, KEY k) { if ((k == K_TAB || k == K_ENTER) && app().exist_journal() && (atoi(f.get()) == REG_JOURNAL) ) return error_box("Non e' possibile avere due registri giornale nello stesso anno"); return TRUE; } bool TGeneric_table_app::user_create() { Tab_application::user_create(); if (get_tabname() == "REG") get_mask()->set_handler(F_TIPO, tiporeg_handler); return TRUE; } int ba3100(int argc, char* argv[]) { TGeneric_table_app a ; a.run(argc, argv, "Tabella"); return 0; }