campo-sirio/ha/ha0100.cpp
guy ce161a46a0 Aggiunto programma per calcolo ed invio storico consumi a terminalini
git-svn-id: svn://10.65.10.50/branches/R_10_00@22756 c028cbd2-c16b-5b4b-a496-9718f37d4682
2012-11-06 10:55:40 +00:00

231 lines
5.1 KiB
C++
Executable File
Raw Blame History

// gestione tabelle di modulo hardy
#include <automask.h>
#include <modtbapp.h>
#include <recset.h>
#include <tabutil.h>
#include "halib.h"
#include "hatbatt.h"
#include "hatbcau.h"
#include "hatbcel.h"
///////////////////////////////////////////////////////////
// Maschera generica di gestione tabelle hardy
///////////////////////////////////////////////////////////
class THA_table_mask : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field &o, TField_event e, long jolly);
public:
THA_table_mask(const char* name) : TAutomask(name) {}
};
bool THA_table_mask::on_field_event(TOperable_field &o, TField_event e, long jolly)
{
return true;
}
///////////////////////////////////////////////////////////
// Applicazione generica di gestione tabelle hardy
///////////////////////////////////////////////////////////
// applicazione per la gestione delle tabelle di lavanderia
class THA_table_app : public TTable_module_application
{
bool _trans_done;
private:
int update_gcg(const TRectype& att);
protected: // TRelation_application
virtual bool protected_record(TRectype& record);
virtual void init_query_mode(TMask& m);
virtual void init_query_insert_mode(TMask& m);
virtual void init_insert_mode(TMask& m);
virtual void init_modify_mode(TMask& m);
virtual int write(const TMask& m);
virtual int rewrite(const TMask& m);
virtual bool get_next_key(TToken_string& key);
public:
THA_table_app() : _trans_done(false) {}
};
bool THA_table_app::get_next_key(TToken_string& key)
{
//casino per la tabella attrezzature "&ATT"
const TFixed_string name = get_relation()->file(0).name();
if (name == "ATT")
{
const TString& codart = curr_mask().get(F_CODART);
if (codart.full())
{
const TString& codtab = hd_get_next_att_key(codart);
//riempie la token_string con i dati richiesti
key.add(F_CODART);
key.add(codart);
key.add(F_PROGRESSIVO);
key.add(codtab.mid(5));
return true;
}
}
return TTable_module_application::get_next_key(key);
}
bool THA_table_app::protected_record(TRectype& record)
{
const TFixed_string name = get_relation()->file(0).name();
//tabella delle attrezzature
//non si pu<70> eliminare una attrezzatura se la medesima ha una storia! rispettiamo gli anziani!
if (name == "ATT")
{
const TString80 codattr = record.get("CODTAB");
//controlla che l'attrezzatura non abbia record nella tabella della storia attrezzature
TString query;
query << "USE &HIS";
query << "\nFROM CODTAB=#CODATTR";
query << "\nTO CODTAB=#CODATTR";
TISAM_recordset attr_recset(query);
attr_recset.set_var("#CODATTR", codattr);
const long items = attr_recset.items();
return items > 0;
}
return false;
}
void THA_table_app::init_insert_mode(TMask& m)
{
const TFixed_string name = get_relation()->file(0).name();
if (name == "ATT")
{
m.hide(-2);
m.show(-1);
}
}
void THA_table_app::init_modify_mode(TMask& m)
{
const TFixed_string name = get_relation()->file(0).name();
if (name == "ATT")
{
m.hide(-2);
m.show(-1);
}
}
void THA_table_app::init_query_mode(TMask& m)
{
const TFixed_string name = get_relation()->file(0).name();
if (name == "CEL")
{
m.hide(F_CODCLI1);
m.show(F_CODCLI);
} else
if (name == "ATT") //inizialmente vedo il gruppo 2 di SEARCH e non quello 1 di NEW
{
m.hide(-1);
m.show(-2);
}
if (!_trans_done && argc() > 3)
{
_trans_done = true;
const TFixed_string a = argv(3);
if (a.starts_with("CODTAB="))
{
const TString& codtab = a.after("=");
get_relation()->curr().put("CODTAB", codtab);
FOR_EACH_MASK_FIELD(m, i, f) if (f->active() && f->field() != NULL && f->in_key(1))
{
const TFieldref* fref = f->field();
if (fref->name() == "CODTAB")
{
const TString& val = fref->read(*get_relation());
f->set(val);
}
}
m.send_key(K_AUTO_ENTER, 0);
}
}
}
void THA_table_app::init_query_insert_mode(TMask& m)
{
const TFixed_string name = get_relation()->file(0).name();
if (name == "CEL")
{
m.hide(F_CODCLI);
m.show(F_CODCLI1);
}
if (name == "ATT")
{
m.hide(-2); //in caso di 'nuovo' vedo il gruppo di NEW
m.show(-1);
}
}
int THA_table_app::update_gcg(const TRectype& att)
{
TTable gcg("GCG");
TString str;
str << '1' << att.get("CODTAB");
gcg.put("CODTAB", str);
str = TR("Matricola ");
str << att.get("S0").mid(20,15);
gcg.put("S0", str);
const int err = gcg.rewrite_write();
return err;
}
int THA_table_app::write(const TMask& m)
{
const int err = TTable_module_application::write(m);
if (err == NOERR)
{
const TFixed_string name = get_relation()->file(0).name();
if (name == "ATT")
update_gcg(get_relation()->curr());
}
return err;
}
int THA_table_app::rewrite(const TMask& m)
{
const int err = TTable_module_application::rewrite(m);
if (err == NOERR)
{
const TFixed_string name = get_relation()->file(0).name();
if (name == "ATT")
update_gcg(get_relation()->curr());
}
return err;
}
int ha0100(int argc, char* argv[])
{
THA_table_app a;
a.run(argc, argv, TR("Tabella Hardy"));
return 0;
}