diff --git a/cg/cg0100.cpp b/cg/cg0100.cpp index dfe452cd8..d1496d2a5 100755 --- a/cg/cg0100.cpp +++ b/cg/cg0100.cpp @@ -33,6 +33,7 @@ public: virtual TRelation* get_relation() const {return _rel;} CG0100_application() {} }; +HIDDEN inline CG0100_application & app() { return (CG0100_application &) main_app();} int CG0100_application::read(TMask& m) @@ -124,6 +125,7 @@ bool CG0100_application::protected_record(TRectype &rec) conto ==_saldi->get_int(PCN_CONTO) && sottoc ==_saldi->get_long(PCN_SOTTOCONTO); } + get_relation()->save_status(); pconti.zero() ; pconti.put(PCN_GRUPPO, gruppo); // Se e' un conto controllo se ha dei sottoconti @@ -134,8 +136,9 @@ bool CG0100_application::protected_record(TRectype &rec) pconti.setkey(1) ; pconti.read(); pconti.next(); - - return pconti.good() && (pconti.curr() == rec1); + const bool prot = (pconti.good() && (pconti.curr() == rec1)); + get_relation()->restore_status(); + return prot; } void CG0100_application::init_query_mode(TMask& m) @@ -250,38 +253,43 @@ HIDDEN bool gruppo_handler(TMask_field& f, KEY key) const TMask& m = f.mask(); const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); const int conto = atoi(m.get(FLD_CM1_CONTO)); - const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); - if (gruppo == 0 && conto == 0 && sottoc == 0) - return TRUE; - - CG0100_application & app = (CG0100_application &) main_app(); - TLocalisamfile& pconti = app.get_relation()->lfile(); - - if ((gruppo == 0) && (conto != 0 || sottoc != 0)) - return f.warning_box("Codice conto impossibile!"); - if (conto > 0 && sottoc == 0) // conto => ricerca gruppo + TLocalisamfile& pconti = app().get_relation()->lfile(); + if (gruppo != 0 && conto != 0) { pconti.zero() ; pconti.put(PCN_GRUPPO, gruppo) ; pconti.setkey(1) ; - pconti.read(_isequal, _nolock ); + pconti.read(); if (pconti.bad()) - return f.warning_box ("Non esiste il gruppo relativo a questo conto"); + return f.warning_box ("Il gruppo non esiste"); } - if (sottoc > 0) // sottoconto => ricerca conto + } + return TRUE; +} + +HIDDEN bool conto_handler(TMask_field& f, KEY key) +{ + if (key == K_ENTER) + { + const TMask& m = f.mask(); + const int gruppo = atoi(m.get(FLD_CM1_GRUPPO)); + const int conto = atoi(m.get(FLD_CM1_CONTO)); + const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO)); + TLocalisamfile& pconti = app().get_relation()->lfile(); + + if (gruppo != 0 && conto != 0 && sottoc != 0) { pconti.zero() ; pconti.put(PCN_GRUPPO, gruppo) ; pconti.put(PCN_CONTO, conto) ; pconti.setkey(1) ; - pconti.read(_isequal, _nolock ); + pconti.read(); if (pconti.bad()) - return f.warning_box ("Non esiste il conto relativo a questo sottoconto"); + return m.field(FLD_CM1_CONTO).warning_box ("Il conto non esiste"); else { - TString tmcf = pconti.get(PCN_TMCF); - if (tmcf.not_empty()) - return f.warning_box ("Non puoi inserire un sottoconto di un conto relativo ad un cliente/fornitore"); + if (pconti.get(PCN_TMCF).not_empty()) + return m.field(FLD_CM1_SOTTOCONTO).warning_box ("Non e' possibile inserire un sottoconto di un conto relativo ad un cliente/fornitore"); } } } @@ -292,12 +300,13 @@ HIDDEN bool sottoc_handler(TMask_field& f, KEY key) { if (key == K_TAB) { - int gruppo = f.mask().get_int(FLD_CM1_GRUPPO); + const int gruppo = f.mask().get_int(FLD_CM1_GRUPPO); if (gruppo == 0) return TRUE; - int conto = f.mask().get_int(FLD_CM1_CONTO); - long sottoconto = f.mask().get_long(FLD_CM1_SOTTOCONTO); - if (sottoconto != 0 && conto == 0) return f.error_box("Manca il CONTO"); - f.mask().stop_run(K_AUTO_ENTER); + const int conto = f.mask().get_int(FLD_CM1_CONTO); + const long sottoconto = f.mask().get_long(FLD_CM1_SOTTOCONTO); + if (sottoconto != 0 && conto == 0) + return f.mask().field(FLD_CM1_CONTO).error_box("Manca il conto"); + return f.mask().stop_run(K_AUTO_ENTER); } return TRUE; } @@ -306,8 +315,8 @@ bool CG0100_application::user_create() { _msk = new TMask("cg0100a") ; _msk->set_handler(FLD_CM1_GRUPPO, gruppo_handler); + _msk->set_handler(FLD_CM1_CONTO, conto_handler); _msk->set_handler(FLD_CM1_SOTTOCONTO, sottoc_handler); - /* _msk->set_handler(FLD_CM1_INDBIL, indbil_handler); */ _msk->set_handler(FLD_CM1_TMCF, tmcf_handler); _rel = new TRelation(LF_PCON);