#include #include #include "in0.h" #include "in0700a.h" #include "inlib01.h" /////////////////////////////////////////////////////////// // TRettifiche_mask /////////////////////////////////////////////////////////// class TRettifiche_mask : public TIntra_mask { protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); virtual short type_field() const { return F_TIPO; } void inventa_cambio_intra(); public: virtual short period_field() const { return F_PERIODO_M; } virtual int anno() const { return get_int(F_ANNO); } public: TRettifiche_mask(); virtual ~TRettifiche_mask() { } }; void TRettifiche_mask::inventa_cambio_intra() { const TString& codval = get(F_VALUTA); if (is_true_value(codval)) { TCurrency eur; get_currency(F_AMMONTARE, eur); TCurrency val; get_currency(F_AMM_VALUTA, val); if (eur.is_zero() && !val.is_zero()) { val.change_to_firm_val(); set(F_AMMONTARE, val); } else if (val.is_zero() && !eur.is_zero()) { const TExchange exc(codval); eur.change_value(exc); set(F_AMM_VALUTA, eur); } } } bool TRettifiche_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { bool ok = TIntra_mask::on_field_event(o, e, jolly); if (ok) switch (o.dlg()) { case O_ANNO: if (e == fe_init || e == fe_modify) { const char freq = frequenza(atoi(o.get())); show(O_PERIODO_M, freq == 'M'); show(O_PERIODO_T, freq == 'T'); show(O_PERIODO_A, freq == 'A'); } break; case F_VALORE_STAT: if (e == fe_init) { TMask& m = o.mask(); TString key ; key << main_app().get_firm(); const bool req = frequenza(anno()) == 'M' && !cache().get(LF_NDITTE, key).get_bool("NONOBBSTAT"); const CheckType chk = req ? CHECK_REQUIRED : CHECK_NORMAL; m.field(F_VALORE_STAT).check_type(chk); } break; case F_NOMENCLATURA2: if (e == fe_modify) { TString4 str; str = o.get(); if (str.len() != 2) { str.format("%02d", atoi(str)); o.set(str); } } break; case O_NUM_RIG: if ((e == fe_init || e == fe_modify) && !o.empty()) { TEdit_field& ef = (TEdit_field&)o; ef.check(); TCursor& cur = *ef.browse()->cursor(); bool ok = cur.ok(); if (e == fe_modify && insert_mode()) { for (short dlg = O_STATO; dlg <= O_NOMENCLATURA3; dlg++) { switch (dlg) { case O_NUM_RIG: // Non riportare il nmumero riga! break; default: const int pos = id2pos(dlg); if (pos >= 0) set(dlg + F_STATO - O_STATO, fld(pos).get()); break; } } } } break; case O_AMM_VALUTA: if (e == fe_close && o.empty()) { const TString& codval = get(O_VALUTA); if (is_true_value(codval)) return error_box(FR("Inserire l'ammontare in valuta %s"), (const char*)codval); } break; case F_AMMONTARE: if (e == fe_modify && !o.empty() && field(F_AMM_VALUTA).empty()) inventa_cambio_intra(); break; case F_VALUTA: if (e == fe_init || e == fe_modify) { const bool tv = is_true_value(o.get()); if (!tv) reset(F_AMM_VALUTA); enable(F_AMM_VALUTA, tv); } break; case F_AMM_VALUTA: if (e == fe_modify && !field(F_VALUTA).empty() && field(F_AMMONTARE).empty()) inventa_cambio_intra(); break; default: break; } return ok; } TRettifiche_mask::TRettifiche_mask() :TIntra_mask("in0700a") { first_focus(F_TIPO); } /////////////////////////////////////////////////////////// // Applicazione principale /////////////////////////////////////////////////////////// class TRettifiche_intra : public TRelation_application { TRelation* _rel; TRettifiche_mask* _msk; TToken_string _str; // jolly string protected: virtual bool user_create(); virtual TRelation* get_relation() const { return _rel; } virtual TMask* get_mask(int) { return _msk; } virtual bool changing_mask(int mode) { return FALSE; } virtual bool user_destroy(); virtual const char* get_next_key(); virtual void init_query_mode(TMask& m); virtual void init_insert_mode(TMask& m); virtual void init_modify_mode(TMask& m); void init_mask(TMask& m, bool keyon); public: }; bool TRettifiche_intra::user_create() { open_files(LF_TABCOM, LF_TAB, LF_CLIFO, LF_RIEPRETT, 0); _rel = new TRelation(LF_RIEPRETT); _msk = new TRettifiche_mask; return TRUE; } bool TRettifiche_intra::user_destroy() { delete _msk; delete _rel; return TRUE; } void TRettifiche_intra::init_mask(TMask& m, bool keyon) { m.enable(O_ANNO, keyon); m.enable(O_PERIODO_M, keyon); m.enable(O_PERIODO_T, keyon); m.enable(O_PERIODO_A, keyon); m.enable(O_NUM_RIG, keyon); } void TRettifiche_intra::init_query_mode(TMask& m) { init_mask(m, FALSE); } void TRettifiche_intra::init_insert_mode(TMask& m) { init_mask(m, TRUE); } void TRettifiche_intra::init_modify_mode(TMask& m) { init_mask(m, TRUE); } const char* TRettifiche_intra::get_next_key() { TRectype& curr = _rel->curr(); curr.put("TIPO", _msk->tipo()); curr.put("ANNO", _msk->anno()); curr.put("PERIODO", _msk->periodo_str()); TCursor cur(_rel, "", 1, &curr, &curr); const long items = cur.items(); int last_row = 0; if (items > 0) { cur = items-1; last_row = curr.get_int("NUMRIG"); } _str.cut(0); _str.add(F_TIPO); _str.add(curr.get("TIPO")); _str.add(F_ANNO); _str.add(curr.get("ANNO")); _str.add(F_PERIODO_M); _str.add(curr.get("PERIODO")); _str.add(F_NUM_RIG); _str.add(last_row+1); return _str; } int in0700(int argc, char* argv[]) { TRettifiche_intra a; a.run(argc, argv, TR("Rettifiche INTRA")); return 0; }