// -------------------------------------------------------------- // fv: cg0 -5 : gestione maschere contabilita' // -------------------------------------------------------------- #include #include #include #include "cgtbbnp.h" #include "cgtbesc.h" #include "cgtbnot.h" #include "cglib01.h" #define TAB_NOTECLI "%NOT" class CGTTable_application : public TTable_application { // ------------- specifiche tabella esercizi ---- static bool dataini_handler(TMask_field& f, KEY k); static bool checkbut_handler(TMask_field& f, KEY k); void check_sheet(); bool check_esercizio(TString& cod, TDate s1, TDate f1); static bool desnot_handler(TMask_field& f, KEY k); void fragment_string(); void glue_string(); // -------------------------------------------- protected: virtual void init_query_insert_mode(TMask& m) ; virtual void init_insert_mode(TMask& m) ; virtual void init_modify_mode(TMask& m) ; virtual void init_query_mode (TMask&); virtual bool protected_record(TRectype & rec); virtual bool user_create(); virtual bool user_destroy(); virtual int read(TMask& m); virtual int write(const TMask& m); virtual int rewrite(const TMask& m); public: // @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata virtual bool check_autorization() const {return false;} static CGTTable_application& app() { return (CGTTable_application&)main_app(); } CGTTable_application() : TTable_application() {} virtual ~CGTTable_application() {} }; bool CGTTable_application::protected_record(TRectype &rec) { if (get_tabname() == "ESC") { // cerca saldo con questo esercizio const TString16 cod(rec.get("CODTAB")); TLocalisamfile saldi(LF_SALDI); saldi.put(SLD_ANNOES, cod); // se ce n'e' uno non si puo' cancellare if (saldi.read(_isgteq) == NOERR && cod == rec.get("CODTAB")) return TRUE; } return TTable_application::protected_record(rec); } void CGTTable_application::init_query_insert_mode(TMask& m) { if (get_tabname() == "BNP") { m.show(F_CODICEABI); m.show(F_CODICECAB); m.field(F_CODICEABI).check_type(CHECK_REQUIRED); m.field(F_CODICECAB).check_type(CHECK_REQUIRED); m.hide(F_ABI); m.hide(F_CAB); m.field(F_ABI).check_type(CHECK_NONE); m.field(F_CAB).check_type(CHECK_NONE); } } void CGTTable_application::init_insert_mode(TMask& m) { if (get_tabname() == "BNP") { m.show(F_CODICEABI); m.show(F_CODICECAB); m.field(F_CODICEABI).check_type(CHECK_REQUIRED); m.field(F_CODICECAB).check_type(CHECK_REQUIRED); m.hide(F_ABI); m.hide(F_CAB); m.field(F_ABI).check_type(CHECK_NONE); m.field(F_CAB).check_type(CHECK_NONE); } } void CGTTable_application::init_modify_mode(TMask& m) { if (get_tabname() == "BNP") { m.efield(F_IBAN_STATO).validate(K_TAB); } } void CGTTable_application::init_query_mode(TMask& m) { TTable_application::init_query_mode(m); if (get_tabname() == "BNP") { m.show(F_ABI); m.show(F_CAB); m.field(F_ABI).check_type(CHECK_REQUIRED); m.field(F_CAB).check_type(CHECK_REQUIRED); m.hide(F_CODICEABI); m.hide(F_CODICECAB); m.field(F_CODICECAB).check_type(CHECK_NONE); } } bool CGTTable_application::user_create() { bool ok = TTable_application::user_create(); if (ok) { if (get_tabname() == "ESC") { get_mask()->set_handler(F_DATAINI, dataini_handler); get_mask()->set_handler(BUT_CHECK, checkbut_handler); } if (get_tabname() == TAB_NOTECLI) get_mask()->set_handler(F_NOT_DESC, desnot_handler); } return ok; } bool CGTTable_application::user_destroy() { return TTable_application::user_destroy(); } int CGTTable_application::read(TMask& m) { int err = Tab_application::read(m); const TString & table_name = get_tabname(); if (table_name == TAB_NOTECLI) glue_string(); return err; } int CGTTable_application::write(const TMask& m) { const TString & table_name = get_tabname(); if (table_name == TAB_NOTECLI) fragment_string(); return Tab_application::write(m); } int CGTTable_application::rewrite(const TMask& m) { const TString & table_name = get_tabname(); if (table_name == TAB_NOTECLI) fragment_string(); return Tab_application::rewrite(m); } // - note cliente-specific -------------------------------------------------------- //folle metodo per suddividere una stringa lunga in piu' stringhe corte da mettere nei campi //stringa delle tabelle (per ora solo tabella %NOT) void CGTTable_application::fragment_string() { TMask& mask = *get_mask(); TString stringone = mask.get(F_NOT_DESC); TRectype& rec = get_relation()->curr(); TString4 fieldname; int tot_length = 0; stringone.replace('\n', (char)0xB6); for (int i = 0; i < 6; i++) { fieldname.format("S%d", i); const int length = rec.length(fieldname); const TString& pezzo = stringone.mid(tot_length, length); rec.put(fieldname, pezzo); tot_length += length; } } void CGTTable_application::glue_string() { TMask& mask = *get_mask(); TString stringone; TRectype& rec = get_relation()->curr(); TString4 fieldname; for (int i = 0; i < 6; i++) { fieldname.format("S%d", i); stringone << rec.get(fieldname); } stringone.replace((char)0xB6, '\n'); mask.set(F_NOT_DESC, stringone); } bool CGTTable_application::desnot_handler(TMask_field& f, KEY k) { if (k == K_ENTER) { const TString& stringone = f.get(); if (stringone.len() > 320) return f.error_box("La nota non puo' superare i 320 caratteri"); } return true; } // - esercizi-specific -------------------------------------------------------- bool CGTTable_application::dataini_handler(TMask_field& f, KEY k) { if (k == K_ENTER && f.mask().is_running() && !f.mask().query_mode()) { TString16 cod = f.mask().get(F_ANNO); TDate s1 = f.mask().get_date(F_DATAINI); TDate f1 = f.mask().get_date(F_DATAFIN); return app().check_esercizio(cod, s1, f1); } return TRUE; } bool CGTTable_application::check_esercizio(TString& cod, TDate s1, TDate f1) { // ----------------------------------------------------------------------------------------- // chiamata prima di registrare. Controlla: // - se non ci sono altri esercizi, ok; // - se ce ne sono altri: // 1) controllo non sovrapposizione date // 2) se ci sono es. con date inferiori, datainizio -1 deve essere = data fine altro es; // 3) se ci sono es. con date superiori, datafine +1 deve essere = data inizio altro // ---------------------------------------------------------------------------------------- byte err = 0x00; bool ret = TRUE; TLocalisamfile& esc = get_relation()->lfile(); bool basta1 = FALSE, basta2 = FALSE; for (esc.first(); !esc.eof(); esc.next()) { if (esc.get("CODTAB") == cod) continue; TDate s2 = esc.get_date("D0"); TDate f2 = esc.get_date("D1"); TDate s1d = s1; --s1d; TDate s2d = s2; --s2d; // check sovrapposizione if (s1 <= f2 && s2 <= f1) err |= 0x01; else { if (!basta1 && f1 < s2 && f1 != s2d) err |= 0x02; if (f1 < s2 && f1 == s2d) { err &= ~0x02; basta1 = TRUE; } if (!basta2 && s1 > f2 && f2 != s1d) err |= 0x04; if (s1 > f2 && f2 == s1d) { err &= ~0x04; basta2 = TRUE; } } } if (err) { ret = FALSE; TString errstr(120); errstr << TR("Date esercizio errate: \n"); // build error string if (err & 0x01) errstr << TR("\n - l'esercizio si sovrappone ad altro gia' esistente"); if (err & 0x02) errstr << TR("\n - l'esercizio non e' contiguo ad esercizi successivi"); if (err & 0x04) errstr << TR("\n - l'esercizio non e' contiguo ad esercizi precedenti"); if (!(err & 0x01)) { errstr << TR("\nSi desidera registrare ugualmente?"); ret = yesno_box(errstr); } else error_box(errstr); } return ret; } void CGTTable_application::check_sheet() { // crea 'nu bellu shit co'tutte le informazion e un messaggino // di error se ce n'e' bisogn TLocalisamfile& esc = get_relation()->lfile(); TArray escarr(10); for (esc.first(); !esc.eof(); esc.next()) escarr.add(new TEsercizio(esc.curr())); escarr.sort(); TArray_sheet as(-1,-1,70,20,TR("Esercizi contabili"), FR("Codice|Inizio@10|Fine@10|Scarico@10|Chiusura@10|Note@20"), 0x10); TDate s1; for (int i = 0; i < escarr.items(); i++) { // sovrapposti non possono essere, perche' non si possono // registrare; possono solo esserci discontinuita' TEsercizio& e = (TEsercizio&)escarr[i]; TToken_string* tt = new TToken_string(80); tt->add(e.codice()); tt->add(e.inizio().string()); tt->add(e.fine().string()); tt->add(e.scarico().string()); tt->add(e.chiusura().string()); if (i > 0 && e.inizio() != ++s1) { TString nc; nc << "***" << TR("non contiguo") << "***"; tt->add(nc); } else tt->add(""); s1 = e.fine(); as.add(tt); } as.run(); } bool CGTTable_application::checkbut_handler(TMask_field& f, KEY k) { if (k == K_SPACE && f.mask().is_running()) app().check_sheet(); return TRUE; } // ------------------------------------------------------------- int cg0600(int argc, char* argv[]) { CGTTable_application a; a.run(argc, argv, TR("Gestione tabelle contabili")); return 0; }