113 lines
2.9 KiB
C++
113 lines
2.9 KiB
C++
|
#include "velib07.h"
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TDocument_cache
|
||
|
///////////////////////////////////////////////////////////
|
||
|
TObject* TDocument_cache::key2obj(const char* key)
|
||
|
{
|
||
|
TToken_string k(key);
|
||
|
const char provv = *k.get(0);
|
||
|
const int anno = k.get_int();
|
||
|
const TString4 codnum= k.get();
|
||
|
const long ndoc = k.get_long();
|
||
|
TDocumento* doc = new TDocumento(provv, anno, codnum, ndoc);
|
||
|
doc->get("IMPONIBILI"); // Bastardata per far funzionare la successiva dirty_fields
|
||
|
doc->dirty_fields();
|
||
|
return doc;
|
||
|
}
|
||
|
|
||
|
TDocumento& TDocument_cache::doc(const TRectype& rec)
|
||
|
{
|
||
|
TToken_string key;
|
||
|
key = rec.get(DOC_PROVV);
|
||
|
key.add(rec.get(DOC_ANNO));
|
||
|
key.add(rec.get(DOC_CODNUM));
|
||
|
key.add(rec.get(DOC_NDOC));
|
||
|
TDocumento& d = *(TDocumento*)objptr(key);
|
||
|
return d;
|
||
|
}
|
||
|
|
||
|
|
||
|
TDocument_cache:: TDocument_cache() : TCache(3)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
TDocument_cache:: ~TDocument_cache()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TDocument_recordset
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
const TVariant& TDocument_recordset::get_field(int num, const char* field) const
|
||
|
{
|
||
|
if (*field != '#')
|
||
|
{
|
||
|
const int idx = relation()->log2ind(num);
|
||
|
if (idx < 0)
|
||
|
return NULL_VARIANT;
|
||
|
const int logic = num > 0 ? num : relation()->file(idx).num();
|
||
|
if (logic == LF_DOC || logic == LF_RIGHEDOC)
|
||
|
{
|
||
|
const TRectype& rec = relation()->file(idx).curr();
|
||
|
// Se non e' un campo standard, ma e' calcolato da una formula...
|
||
|
if (rec.type(field) == _nullfld && strncmp(field, "G1:", 3) != 0)
|
||
|
{
|
||
|
const TDocumento& doc = ((TDocument_cache&)_cache).doc(rec);
|
||
|
TVariant& var = get_tmp_var();
|
||
|
const TFieldref ref(field, logic);
|
||
|
if (logic == LF_DOC)
|
||
|
{
|
||
|
var = ref.read(doc);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
const int nriga = rec.get_int(RDOC_NRIGA);
|
||
|
const TRiga_documento& rdoc = doc[nriga];
|
||
|
var = ref.read(rdoc);
|
||
|
}
|
||
|
return var;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return TISAM_recordset::get_field(num, field);
|
||
|
}
|
||
|
|
||
|
|
||
|
///////////////////////////////////////////////////////////
|
||
|
// TDocument_report
|
||
|
///////////////////////////////////////////////////////////
|
||
|
|
||
|
bool TDocument_report::set_recordset(const TString& query)
|
||
|
{
|
||
|
return TReport::set_recordset(new TDocument_recordset(query));
|
||
|
}
|
||
|
|
||
|
bool TDocument_report::load(const char* name)
|
||
|
{
|
||
|
const bool ok = TReport::load(name);
|
||
|
if (ok)
|
||
|
{
|
||
|
// Purtroppo il recordset delle sottosezioni deve essere reimpostato a mano
|
||
|
for (int i = 11; i <= 999; i++)
|
||
|
{
|
||
|
TReport_section* sec = find_section('B', i);
|
||
|
if (sec != NULL)
|
||
|
{
|
||
|
TRecordset* recset = sec->recordset();
|
||
|
if (recset != NULL)
|
||
|
{
|
||
|
const TString use = recset->query_text();
|
||
|
recset = new TDocument_recordset(use);
|
||
|
sec->set_recordset(recset);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return ok;
|
||
|
}
|
||
|
|
||
|
|