campo-sirio/ha/ha0200.cpp
luca e0762200f6 Patch level :
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :


git-svn-id: svn://10.65.10.50/branches/R_10_00@21167 c028cbd2-c16b-5b4b-a496-9718f37d4682
2010-11-23 15:28:56 +00:00

181 lines
3.9 KiB
C++
Executable File

#include <automask.h>
#include <confapp.h>
#include <relation.h>
#include "ha0200a.h"
///////////////////////////////////////////////////
// Maschera
///////////////////////////////////////////////////
class TConf_Hardy_mask : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
void config_loader(TSheet_field& sf, const char* paragrafo);
void config_setter(TSheet_field& sf, const char* paragrafo);
TConf_Hardy_mask(const TFilename& f);
virtual ~TConf_Hardy_mask(){};
};
bool TConf_Hardy_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
/*switch (o.dlg())
{
default:
break;
}*/
return true;
}
TConf_Hardy_mask::TConf_Hardy_mask(const TFilename& f) : TAutomask (f)
{
}
///////////////////////////////////////////////////
// Applicazione
///////////////////////////////////////////////////
class TConf_Hardy : public TConfig_application
{
TMask* _ch;
protected:
virtual TMask* create_mask(const TFilename& f);
virtual TMask* get_mask();
virtual void load_mask();
virtual void save_mask(bool tosave);
public:
virtual bool preprocess_config (TMask& mask, TConfig& config);
virtual bool postprocess_config (TMask& mask, TConfig& config);
virtual bool user_create( );
virtual bool user_destroy( );
TConf_Hardy() : TConfig_application(CONFIG_DITTA), _ch(NULL) { }
virtual ~TConf_Hardy() { }
};
TMask* TConf_Hardy::get_mask()
{
return _ch;
}
TMask* TConf_Hardy::create_mask(const TFilename& f)
{
if (_ch == NULL)
_ch = new TConf_Hardy_mask(f);
return _ch;
}
bool TConf_Hardy::preprocess_config (TMask& mask, TConfig& config)
{
return true;
}
bool TConf_Hardy::postprocess_config (TMask& mask, TConfig& config)
{
return true;
}
//questa serve per caricare gli sheet della maschera
void TConf_Hardy::load_mask()
{
TMask* m = get_mask();
if (m != NULL)
{
TConfig_application::load_mask();
//dopo aver caricato la maschera principale, fa il giro sugli sheet presenti
FOR_EACH_MASK_SHEET((*m), i, s)
{
s->destroy();
//carica la maschera del singolo sheet
TMask& sm = s->sheet_mask();
bool found = true;
for (int r = 0; found; r++)
{
//giro sui campi della maschera di sheet
FOR_EACH_MASK_FIELD(sm, j, f)
{
const TFieldref* fr = f->field();
//deve caricare solo i campi che hanno un field
if(fr != NULL)
{
const TString& value = get_config()->get(fr->name(), NULL, r);
if (value.empty() && f->dlg() == 101)
{
found = false;
break;
}
s->row(r).add(value, s->cid2index(f->dlg()));
}
}
if (found)
s->check_row(r, 1);
}
s->force_update();
}
}
}
//questa serve per salvare gli sheet della maschera (tipo quello con i codici iva)
void TConf_Hardy::save_mask(bool tosave)
{
TConfig* cnf = get_config();
if (!tosave || cnf == NULL)
return;
TConfig_application::save_mask(tosave);
TAssoc_array& v = cnf->list_variables("ha");
FOR_EACH_ASSOC_STRING(v, h, k, str)
{
const TFixed_string name = k;
if (name.find('(') > 0 && !name.starts_with("IVA"))
v.remove(name);
}
TConf_Hardy_mask& m = (TConf_Hardy_mask&) *get_mask();
FOR_EACH_MASK_SHEET(m, i, s)
{
TMask& sm = s->sheet_mask();
FOR_EACH_SHEET_ROW(*s, j, row)
{
FOR_EACH_MASK_FIELD(sm, k, f)
{
const TFieldref* fr = f->field();
if (fr != NULL)
{
const char* value = row->get(s->cid2index(f->dlg()));
cnf->set(fr->name(), value, NULL, true, j);
}
}
}
}
cnf->set_paragraph("ha");
}
bool TConf_Hardy::user_create( )
{
TConfig cfg(CONFIG_DITTA, "ha");
cfg.set("EdMask", "ha0200a");
return true;
}
bool TConf_Hardy::user_destroy( )
{
if (_ch != NULL)
delete _ch;
return true;
}
int ha0200(int argc, char* argv[])
{
TConf_Hardy configapp;
configapp.run(argc, argv, TR("Configurazione modulo"));
return 0;
}