campo-sirio/mr/mr0100.cpp
guy 899baaebcb Patch level :
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
mr0100.cpp       Gestione tabelle IMP ed LNP
mrplib.*         Gestione calendari: lettura, scrittura, cancellazione
mrtbimp.uml      Tabella impianti
mrtblnp.uml      Tabella linee di produzione
mrtblnp.h        Simboli comuni alle due tabelle precedenti


git-svn-id: svn://10.65.10.50/trunk@7160 c028cbd2-c16b-5b4b-a496-9718f37d4682
1998-09-29 08:36:35 +00:00

264 lines
5.5 KiB
C++
Executable File

#include <tabapp.h>
#include "mr0.h"
#include "mrplib.h"
#include "mrtblnp.h"
#ifndef TTable_application
#define TTable_application Tab_application
#endif
TTable_application& app() { return (TTable_application&)main_app(); }
///////////////////////////////////////////////////////////
// TMRP_mask
///////////////////////////////////////////////////////////
class TMRP_mask : public TCalendar_mask
{
TMRP_calendar* _calendar;
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
bool init_calendar();
bool save_calendar() const;
bool remove_calendar() const;
TMRP_mask(const char* name, int num = 0);
virtual ~TMRP_mask();
};
bool TMRP_mask::init_calendar()
{
bool changed = FALSE;
TString16 lin, imp;
if (app().get_tabname() == "LNP")
{
switch (get(F_TYPE)[0])
{
case 'L': lin = get(F_CODICE); imp = get(F_IMPIANTO); break;
case 'I': imp = get(F_IMPIANTO); break;
default : break;
}
}
else
{
if (get(F_TYPE) == "I")
imp = get(F_CODICE);
}
TCalendar_field& cf = (TCalendar_field&)field(F_CALENDAR);
if (_calendar == NULL)
{
_calendar = new TMRP_calendar(lin, imp);
changed = TRUE;
}
else
{
if (_calendar->linea() != lin || _calendar->impianto() != imp)
{
if (cf.dirty())
{
TString str(80);
str = "Il calendario ";
switch (_calendar->tipo())
{
case 'L': str << "della linea " << _calendar->linea(); break;
case 'I': str << "del impianto " << _calendar->impianto(); break;
default : str << "standard"; break;
}
str << " e' stato modificato:\nsi desidera salvare le modifiche effettuate?";
if (yesno_box(str))
_calendar->rewrite();
}
_calendar->set(lin, imp);
cf.set_dirty(FALSE);
changed = TRUE;
}
}
cf.set_calendar(_calendar, get_int(F_YEAR));
return changed;
}
bool TMRP_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
const TString& tn = app().get_tabname();
if (tn == "IMP" || tn == "LNP")
{
switch (o.dlg())
{
case F_IMPIANTO:
if (e == fe_close && o.empty())
{
TConfig ini(CONFIG_DITTA, "mr");
bool gestione_impianti = ini.get_bool("GESTIMPIANTI");
if (gestione_impianti)
return error_box("E' necessario specificare un impianto");
}
case F_CODICE:
case F_TYPE:
if (e == fe_modify)
{
if (init_calendar())
{
TCalendar_field& cf = (TCalendar_field&)field(F_CALENDAR);
cf.win().force_update();
}
}
break;
case F_YEAR:
if (e == fe_init || e == fe_modify)
{
TCalendar_field& cf = (TCalendar_field&)field(F_CALENDAR);
cf.set_calendar(_calendar, get_int(F_YEAR));
if (is_running())
cf.win().force_update();
}
break;
default:
break;
}
}
return TRUE;
}
bool TMRP_mask::save_calendar() const
{
if (_calendar != NULL)
{
TCalendar_field& cf = (TCalendar_field&)field(F_CALENDAR);
if (cf.dirty())
_calendar->rewrite();
}
return TRUE;
}
bool TMRP_mask::remove_calendar() const
{
if (_calendar != NULL)
{
const TString& tn = app().get_tabname();
const char tipo = tn[0];
if (_calendar->tipo() != tipo)
{
if (tipo == 'L')
_calendar->set(get(F_CODICE), get(F_IMPIANTO));
else
_calendar->set(NULL, get(F_CODICE));
CHECK(_calendar->tipo() == tipo, "Tipo calendario incongruente");
}
_calendar->remove();
}
return TRUE;
}
TMRP_mask::TMRP_mask(const char* name, int num)
: TCalendar_mask(name, num), _calendar(NULL)
{
}
TMRP_mask::~TMRP_mask()
{
if (_calendar)
delete _calendar;
}
///////////////////////////////////////////////////////////
// TMRPtables
///////////////////////////////////////////////////////////
class TMRPtables : public TTable_application
{
protected:
virtual TString& get_mask_name(TString& name) const;
virtual TMask* set_mask(TMask* m);
virtual int write(const TMask& m);
virtual int rewrite(const TMask& m);
virtual bool remove();
public:
void save_calendar(const TMask& m);
void remove_calendar(const TMask& m);
};
TString& TMRPtables::get_mask_name(TString& name) const
{
name = get_tabname();
name.insert("mrtb", 0);
return name;
}
TMask* TMRPtables::set_mask(TMask* m)
{
if (m == NULL)
{
TString name; get_mask_name(name);
m = new TMRP_mask(name);
}
return TTable_application::set_mask(m);
}
void TMRPtables::save_calendar(const TMask& m)
{
const TString& tn = get_tabname();
if (tn == "IMP" || tn == "LNP")
{
const TMRP_mask& cm = (const TMRP_mask&)m;
cm.save_calendar();
}
}
void TMRPtables::remove_calendar(const TMask& m)
{
const TString& tn = get_tabname();
if (tn == "IMP" || tn == "LNP")
{
const TMRP_mask& cm = (const TMRP_mask&)m;
cm.remove_calendar();
}
}
int TMRPtables::write(const TMask& m)
{
const int err = TTable_application::write(m);
if (err == NOERR)
save_calendar(m);
return err;
}
int TMRPtables::rewrite(const TMask& m)
{
const int err = TTable_application::rewrite(m);
if (err == NOERR)
save_calendar(m);
return err;
}
bool TMRPtables::remove()
{
const bool ok = TTable_application::remove();
if (ok)
remove_calendar(curr_mask());
return ok;
}
int mr0100(int argc, char* argv[])
{
if (argc > 2)
{
TString name;
name << "Tabella " << argv[2];
TMRPtables a;
a.run(argc, argv, name);
}
return 0;
}