From f25b2776e7e55d9f7fa46ae9135df22a24e95d97 Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 7 Oct 2008 09:09:01 +0000 Subject: [PATCH] Patch level : 10.0 Files correlati : cg0 Ricompilazione Demo : [ ] Commento : Migliorato controllo di protezione dalla cancellazione dei sottoconti git-svn-id: svn://10.65.10.50/trunk@17360 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg0100.cpp | 152 ++++++++++++++++---------------------------------- 1 file changed, 48 insertions(+), 104 deletions(-) diff --git a/cg/cg0100.cpp b/cg/cg0100.cpp index cef26025b..8b7e6e48d 100755 --- a/cg/cg0100.cpp +++ b/cg/cg0100.cpp @@ -1,6 +1,5 @@ #include #include -#include #include "cg0.h" #include "cg0100.h" @@ -8,17 +7,12 @@ #include #include -#define ATTIVITA 1 -#define PASSIVITA 2 -#define COSTI 3 -#define RICAVI 4 -#define ORDINE 5 +enum TIndicatore_bilancio { ATTIVITA=1, PASSIVITA, COSTI, RICAVI, ORDINE }; class TPianoconti_app : public TRelation_application { TMask* _msk; TRelation *_rel; - bool _pcon_com; bool user_create(); bool user_destroy(); @@ -31,22 +25,18 @@ class TPianoconti_app : public TRelation_application virtual int write(const TMask& m); virtual int rewrite(const TMask & m); virtual int read(TMask& m); - virtual void on_firm_change(); public: // @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata - virtual bool check_autorization() const - {return FALSE;} + virtual bool check_autorization() const { return false; } virtual TRelation* get_relation() const {return _rel;} - TPianoconti_app() : _pcon_com(FALSE) {} }; -HIDDEN inline TPianoconti_app & app() { return (TPianoconti_app &) main_app();} +HIDDEN inline TPianoconti_app& app() { return (TPianoconti_app&) main_app();} int TPianoconti_app::read(TMask& m) - { - const TRelation *r = get_relation(); + const TRelation* r = get_relation(); m.autoload(*r); if (m.get(FLD_CM1_LETTIVD).empty()) { @@ -115,60 +105,39 @@ int TPianoconti_app::write(const TMask& m) return r->write(); } -// Controlla se puo' essere effettuata la cancellazione di un conto -void TPianoconti_app::on_firm_change() -{ - TDir d; - d.get(LF_PCON, _nolock, _nordir, _sysdirop); - _pcon_com = d.is_com(); -} - bool TPianoconti_app::protected_record(TRectype &rec) { - if (!_pcon_com ) + bool prot = false; + + const int gruppo = rec.get_int(PCN_GRUPPO); + const int conto = rec.get_int(PCN_CONTO); + const long sottoc = rec.get_long(PCN_SOTTOCONTO); + + // Se e' un sottoconto posso cancellarlo se non esistono saldi + if (sottoc != 0) { - TMask* m = get_mask(MODE_MOD); - const int gruppo = m->get_int(FLD_CM1_GRUPPO); - const int conto = m->get_int(FLD_CM1_CONTO); - const long sottoc = m->get_long(FLD_CM1_SOTTOCONTO); - - // Se e' un sottoconto posso cancellarlo se non esistono saldi - if ((gruppo != 0) && (conto != 0) && (sottoc != 0)) - { - TLocalisamfile saldi(LF_SALDI); - - saldi.setkey(2); - saldi.put(PCN_GRUPPO, gruppo); - saldi.put(PCN_CONTO, conto); - saldi.put(PCN_SOTTOCONTO, sottoc); - saldi.read(_isgteq); - return saldi.good() && - gruppo == saldi.get_int(PCN_GRUPPO) && conto == saldi.get_int(PCN_CONTO) && sottoc == saldi.get_long(PCN_SOTTOCONTO) && - (saldi.get_real(SLD_SALDO) != ZERO || saldi.get_real(SLD_PDARE) != ZERO || - saldi.get_real(SLD_PAVERE) != ZERO || saldi.get_real(SLD_SALDOFIN) != ZERO || - saldi.get_real(SLD_PDAREPRO) != ZERO || saldi.get_real(SLD_PAVEREPRO) != ZERO); - } - else - { - TLocalisamfile& pconti = _rel->lfile(); - - get_relation()->save_status(); - pconti.zero() ; - pconti.put(PCN_GRUPPO, gruppo); - // Se e' un conto controllo se ha dei sottoconti - if (conto != 0) - pconti.put(PCN_CONTO, conto); - TRectype rec1(pconti.curr()); - - pconti.setkey(1) ; - pconti.read(); - pconti.next(); - bool prot = (pconti.good() && (pconti.curr() == rec1)); - get_relation()->restore_status(); - return prot; - } + TLocalisamfile saldi(LF_SALDI); + saldi.setkey(2); + saldi.put(PCN_GRUPPO, gruppo); + saldi.put(PCN_CONTO, conto); + saldi.put(PCN_SOTTOCONTO, sottoc); + prot = saldi.read(_isgteq) == NOERR && + gruppo == saldi.get_int(PCN_GRUPPO) && conto == saldi.get_int(PCN_CONTO) && sottoc == saldi.get_long(PCN_SOTTOCONTO) && + (saldi.get_real(SLD_SALDO) != ZERO || saldi.get_real(SLD_PDARE) != ZERO || + saldi.get_real(SLD_PAVERE) != ZERO || saldi.get_real(SLD_SALDOFIN) != ZERO || + saldi.get_real(SLD_PDAREPRO) != ZERO || saldi.get_real(SLD_PAVEREPRO) != ZERO); } - return FALSE; + else + { + TLocalisamfile pconti(LF_PCON); + pconti.put(PCN_GRUPPO, gruppo); + // Se e' un conto controllo se ha dei sottoconti + if (conto != 0) + pconti.put(PCN_CONTO, conto); + const TRectype rec1(pconti.curr()); + prot = pconti.read(_isgreat) == NOERR && pconti.curr().same_key(rec1, 1, 1); + } + return prot; } void TPianoconti_app::init_query_mode(TMask& m) @@ -289,71 +258,47 @@ void TPianoconti_app::init_insert_mode(TMask& m) HIDDEN bool gruppo_handler(TMask_field& f, KEY key) { - TMask& m = f.mask(); - const int gruppo = m.get_int(FLD_CM1_GRUPPO); - const int conto = m.get_int(FLD_CM1_CONTO); -// const long sottoc = m.get_long(FLD_CM1_SOTTOCONTO); - if (key == K_ENTER) { - TLocalisamfile& pconti = app().get_relation()->lfile(); + TMask& m = f.mask(); + const int gruppo = m.get_int(FLD_CM1_GRUPPO); + const int conto = m.get_int(FLD_CM1_CONTO); if (gruppo != 0 && conto != 0) { - pconti.zero() ; + TLocalisamfile pconti(LF_PCON); pconti.put(PCN_GRUPPO, gruppo) ; - pconti.setkey(1) ; - pconti.read(); - if (pconti.bad()) - return f.warning_box (TR("Il gruppo non esiste")); + if (pconti.read() != NOERR) + return f.error_box (TR("Il gruppo non esiste")); } } - - return TRUE; + return true; } HIDDEN bool conto_handler(TMask_field& f, KEY key) { - TMask& m = f.mask(); - const int gruppo = m.get_int(FLD_CM1_GRUPPO); - const int conto = m.get_int(FLD_CM1_CONTO); - const long sottoc = m.get_long(FLD_CM1_SOTTOCONTO); - if (key == K_ENTER) { - TLocalisamfile& pconti = app().get_relation()->lfile(); - + TMask& m = f.mask(); + const int gruppo = m.get_int(FLD_CM1_GRUPPO); + const int conto = m.get_int(FLD_CM1_CONTO); + const long sottoc = m.get_long(FLD_CM1_SOTTOCONTO); if (gruppo != 0 && conto != 0 && sottoc != 0) { - pconti.zero() ; + TLocalisamfile pconti(LF_PCON); pconti.put(PCN_GRUPPO, gruppo) ; pconti.put(PCN_CONTO, conto) ; - pconti.setkey(1) ; - pconti.read(); - if (pconti.bad()) - return m.field(FLD_CM1_CONTO).warning_box (TR("Il conto non esiste")); + if (pconti.read() != NOERR) + return m.field(FLD_CM1_CONTO).error_box (TR("Il conto non esiste")); else { if (pconti.get(PCN_TMCF).not_empty()) - return m.field(FLD_CM1_SOTTOCONTO).warning_box (TR("Non e' possibile inserire un sottoconto di un conto relativo ad un cliente/fornitore")); + return m.field(FLD_CM1_SOTTOCONTO).error_box (TR("Non e' possibile inserire un sottoconto di un conto relativo ad un cliente/fornitore")); } } } return TRUE; } -HIDDEN bool sottoc_handler(TMask_field& f, KEY key) -{ - TMask& m = f.mask(); - if (m.query_mode() && key == K_TAB) - { - const int gruppo = m.get_int(FLD_CM1_GRUPPO); -// const int conto = m.get_int(FLD_CM1_CONTO); -// const long sottoc = m.get_long(FLD_CM1_SOTTOCONTO); - if (gruppo == 0) return TRUE; - } - return TRUE; -} - bool TPianoconti_app::user_create() { open_files(LF_PCON, LF_SALDI, LF_TABCOM, LF_ABPCON, 0); @@ -361,7 +306,6 @@ bool TPianoconti_app::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_TMCF, tmcf_handler); _rel = new TRelation(LF_PCON); // set_search_field(FH_SOTTOCONTO); // Ottima trovata, ma non funziona