campo-sirio/ce/ce0100.cpp
alex 96f33c01ee Patch level : 4.0 979
Files correlati     : ve6.exe
Ricompilazione Demo : [ ]
Commento            :

Riportata la versione 3.1 patch 979


git-svn-id: svn://10.65.10.50/trunk@15623 c028cbd2-c16b-5b4b-a496-9718f37d4682
2007-09-17 15:33:04 +00:00

336 lines
8.1 KiB
C++
Executable File

#include <automask.h>
#include <execp.h>
#include <mailbox.h>
#include <tabutil.h>
#include <tabapp.h>
#include "ce0.h"
#include "cetbtmc.h"
#include "cetbcac.h"
#include "cetbcce.h"
#include "cetbccb.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;
}
///////////////////////////////////////////////////////////
// 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)
{
TString 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);
virtual void init_query_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)
{
if (m == NULL)
{
if (get_tabname() == "%TMC")
m = new TTMC_mask();
else
if (get_tabname() == "%CAC")
m = new TCAC_mask();
else
if (get_tabname() == "CCE")
m = new TCCE_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)
{
if (get_tabname() == "%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 (get_tabname() == "%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::init_query_mode(TMask& m)
{
if (get_tabname() == "CCE")
m.disable(DLG_ATTIV);
if (get_tabname() == "CCB")
{
m.show(F_CODSP_CCB);
m.hide(F_CODATT_CCB);
}
}
void TCEtables::init_query_insert_mode(TMask& m)
{
if (get_tabname() == "CCB")
{
m.hide(F_CODSP_CCB);
m.show(F_CODATT_CCB);
}
}
void TCEtables::init_modify_mode(TMask& m)
{
if (get_tabname() == "CCE")
{
m.enable(DLG_ATTIV);
}
}
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;
}