#include #include #include #include #include #include "ce0.h" #include "celib.h" #include "cetbtmc.h" #include "cetbcac.h" #include "cetbcce.h" #include "cetbccb.h" #include "cetbccc.h" #define MIN_CAT_COM 40 #ifndef TTable_application #define TTable_application Tab_application #endif TTable_application& app() { return (TTable_application&)main_app(); } /////////////////////////////////////////////////////////// // TTMC_mask /////////////////////////////////////////////////////////// class TTMC_mask : public TAutomask { public: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); TTMC_mask() : TAutomask("cetbtmc") { } virtual ~TTMC_mask() { } }; bool TTMC_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case F_APPLICABLE1: if (e == fe_close && !query_mode()) { if ((!get_bool(F_APPLICABLE1)) && (!get_bool(F_APPLICABLE2)) && (!get_bool(F_APPLICABLE3))) return error_box(TR("E' necessario specificare almeno un'applicabilita'")); } default: break; } return true; } /////////////////////////////////////////////////////////// // TCAC_mask /////////////////////////////////////////////////////////// class TCAC_mask : public TAutomask { public: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); TCAC_mask() : TAutomask("cetbcac") { } virtual ~TCAC_mask() { } }; bool TCAC_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case F_TIPOCE: if (e == fe_modify) { const int tipo_cesp = get_int(F_TIPOCE); if (tipo_cesp == 1) field(F_TIPOAMMO).on_hit(); } break; case F_NUMANNI: if ((e == fe_close && !query_mode())) { if (get(F_NUMANNI).empty()) { const int tipo_cesp = get_int(F_TIPOCE); const int tipo_vinc = get_int(F_TIPOVINC); const real pmin = get_real(F_PERC_MINAMF2); const real pmax = get_real(F_PERC_MAXAMF2); if (tipo_cesp == 1 || (tipo_cesp == 2 && tipo_vinc != 3 && pmin == ZERO && pmax == ZERO)) return error_box(TR("Numero di anni per ammortamento costi obbligatori")); } } break; case F_CODCAT: if (e == fe_close && query_mode()) { const int codgr = get_int(F_CODGR); const int codsp = get_int(F_CODSP); const int codcat = get_int(F_CODCAT); if (codgr == 0 && codsp == 0) { // categorie comuni if (codcat < MIN_CAT_COM) return error_box(TR("Le categorie comuni non possono avere\n un codice inferiore a %d"), MIN_CAT_COM); } else { // categorie noncomuni if (codcat >= MIN_CAT_COM) return error_box(TR("I codici categoria superiori o uguali\n a %d sono riservati alle Categorie Comuni"),MIN_CAT_COM); } } default: break; } return true; } /////////////////////////////////////////////////////////// // TCCC_mask /////////////////////////////////////////////////////////// class TCCC_mask : public TAutomask { public: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); TCCC_mask() : TAutomask("cetbccc") { } virtual ~TCCC_mask() { } }; bool TCCC_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case F_CODCAT_IN: if (o.active()) { TDitta_cespiti& dc = ditta_cespiti(); bool ok = dc.on_category_event(o, e, jolly); if (ok) { if (e == fe_modify && !o.empty()) { const TRectype& cac = dc.categoria(0, NULL, get_int(F_CODCAT_IN)); if (o.dlg() == F_CODCAT_IN) set(F_DESCCAT, cac.get("S0")); /*else set(F_CODCAT_IN, cac.get("CODTAB");*/ } if (e == fe_close && o.empty()) return error_box(TR("È necessario specificare la categoria!")); } } break; default: break; } return true; } /////////////////////////////////////////////////////////// // TCCE_mask /////////////////////////////////////////////////////////// class TCCE_mask : public TAutomask { protected: bool is_leap(int year) const; real calc_coeff(const TDate& ies, const TDate& fes) const; public: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); TCCE_mask() : TAutomask("cetbcce") { } virtual ~TCCE_mask() { } }; bool TCCE_mask::is_leap(int year) const { TDate d(28,2,year); ++d; return d.day() == 29; } real TCCE_mask::calc_coeff(const TDate& ies, const TDate& fes) const { const real tot_es = fes - ies + 1; real max_es = 365; const int im = ies.month(); const int iy = ies.year(); const int fm = fes.month(); const int fy = fes.year(); if ((im < 3 && (fm >= 3 || fy > iy) && is_leap(iy)) || (fm >= 3 && (im < 3 || iy < fy) && is_leap(fy))) max_es += 1.0; real coeff = tot_es / max_es; coeff.round(9); return coeff; } bool TCCE_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case DLG_ATTIV: if (e == fe_button) { const char* const app = "ce0 -0 CCB"; TMailbox mail; TString body; body.format("%d|%d=%s|%d=%s|%d=%s", F_CODSP_CCB, F_CODESER_CCB, (const char *)get(F_CODESER), F_DATAINI_CCB, (const char *)get(F_DATAINI), F_DATAFINE_CCB, (const char *)get(F_DATAFINE)); TMessage msg(app, MSG_FS, body); mail.send(msg); TExternal_app a(app); a.run(); } break; case F_DURATA: if (e == fe_init && !field(F_CODESER).empty()) { const TDate ies = get_date(F_DATAINI); const TDate fes = get_date(F_DATAFINE); set(F_DURATA, fes-ies+1); set(F_COEFF_DURATA, calc_coeff(ies, fes)); } break; default: break; } return true; } /////////////////////////////////////////////////////////// // TCEtables /////////////////////////////////////////////////////////// class TCEtables : public TTable_application { protected: virtual TString& get_mask_name(TString& name) const; virtual TMask* set_mask(TMask* m); virtual int read(TMask& m); virtual int write(const TMask& m); virtual int rewrite(const TMask& m); virtual bool remove(); virtual bool protected_record(TRectype& rec); void show_hide_ccc_cat(TMask& m, const bool hide_cac); virtual void init_query_mode(TMask& m); virtual void init_insert_mode(TMask& m); virtual void init_query_insert_mode(TMask& m); virtual void init_modify_mode(TMask& m); }; TString& TCEtables::get_mask_name(TString& name) const { name = get_tabname(); if (name[0] == '%') name = name.mid(1); name.insert("cetb", 0); return name; } TMask* TCEtables::set_mask(TMask* m) { const TString& tab = get_tabname(); if (m == NULL) { if (tab == "%TMC") m = new TTMC_mask(); else if (tab == "%CAC") m = new TCAC_mask(); else if (tab == "CCE") m = new TCCE_mask(); else if (tab == "CCC") m = new TCCC_mask(); else { TString name; get_mask_name(name); m = new TMask(name); } } return TTable_application::set_mask(m); } int TCEtables::read(TMask& m) { const int err = TTable_application::read(m); return err; } int TCEtables::write(const TMask& m) { const int err = TTable_application::write(m); return err; } int TCEtables::rewrite(const TMask& m) { const int err = TTable_application::rewrite(m); return err; } bool TCEtables::remove() { const bool ok = TTable_application::remove(); return ok; } bool TCEtables::protected_record(TRectype& rec) { const TString& tab = get_tabname(); if (tab == "%CGR") { TTable cat("%CAT"); const TString16 key(rec.get("CODTAB")); cat.put("CODTAB", key); if (cat.read(_isgteq) == NOERR) return key == cat.get("CODTAB").left(2); } else if (tab == "%CAT") { TTable cac("%CAC"); const TString16 key(rec.get("CODTAB")); cac.put("CODTAB", key); if (cac.read(_isgteq) == NOERR) { TString16 keyfound = cac.get("CODTAB").left(6); keyfound.trim(); return key == keyfound; } } return TTable_application::protected_record(rec); } void TCEtables::show_hide_ccc_cat(TMask& m, const bool hide_cac) { //hide_cac = nasconde i campi che mostrano i record della tabella comune %CAC if (hide_cac) { m.hide(F_CODCAT_IN); m.disable(F_CODCAT_IN); m.show(F_CODCAT); } else { m.hide(F_CODCAT); m.show(F_CODCAT_IN); m.enable(F_CODCAT_IN); } } void TCEtables::init_query_mode(TMask& m) { const TString& tab = get_tabname(); if (tab == "CCE") m.disable(DLG_ATTIV); if (tab == "CCB") { m.show(F_CODSP_CCB); m.hide(F_CODATT_CCB); } if (tab == "CCC") { show_hide_ccc_cat(m, true); } } void TCEtables::init_insert_mode(TMask& m) { const TString& tab = get_tabname(); if (tab == "CCC") { show_hide_ccc_cat(m, true); } } void TCEtables::init_query_insert_mode(TMask& m) { const TString& tab = get_tabname(); if (tab == "CCB") { m.hide(F_CODSP_CCB); m.show(F_CODATT_CCB); } if (tab == "CCC") { show_hide_ccc_cat(m, false); } } void TCEtables::init_modify_mode(TMask& m) { const TString& tab = get_tabname(); if (tab == "CCE") { m.enable(DLG_ATTIV); } if (tab == "CCC") { show_hide_ccc_cat(m, true); } } int ce0100(int argc, char* argv[]) { if (argc > 2) { TString name; name << TR("Tabella") << ' ' << argv[2]; TCEtables a; a.run(argc, argv, name); } return 0; }