campo-sirio/include/tabmod.cpp
alex 01eec09eae Patch level : 10.0 noptach
Files correlati     :
Ricompilazione Demo : [ ]
Commento           :

Tabelle di modulo


git-svn-id: svn://10.65.10.50/trunk@16926 c028cbd2-c16b-5b4b-a496-9718f37d4682
2008-07-23 15:37:50 +00:00

300 lines
6.5 KiB
C++
Executable File

#include <applicat.h>
#include <checks.h>
#include <tabmod.h>
#include <config.h>
#include <extcdecl.h>
#include <scanner.h>
#include <utility.h>
TModule_table::TModule_table(const char* tabname, const char * module, long customer)
: TLocalisamfile(LF_TABGEN), _tabname(tabname), _module(module), _customer(customer)
{
TFilename app = main_app().argv(0); app.ext("");
const TString16 appname = app.name();
if (_module.blank())
_module = appname.left(2);
_tabname.upper();
_module.lower();
if (_customer == 0L && real::is_natural(app.mid(3)))
_customer = atol(app.mid(2));
_des_mod_loaded = FALSE;
}
// @cmember Vuota tutto il record usando il carattere <p c>
void TModule_table::zero(char c)
{
zero(curr(), c);
}
void TModule_table::zero(TRectype & rec, char c)
{
rec.zero(c);
rec.put("COD", _tabname);
rec.put("MOD", _module);
rec.put("CUST", _customer);
}
bool TModule_table::in_table() const
{
const TRectype & rec = curr();
return _tabname == rec.get("COD") && _module == rec.get("MOD") && _customer == rec.get_long("CUST");
}
int TModule_table::skip(TRecnotype nrec, word lockop)
{
if (!nrec) return NOERR;
TBaseisamfile::skip(nrec, lockop);
if (not_in_table())
{
if (nrec > 0)
{
if (lockop == _lock)
TBaseisamfile::reread(_unlock);
last(lockop);
setstatus(_iseof);
}
else
{
if (lockop == _lock)
TBaseisamfile::reread(_unlock);
first(lockop);
setstatus(_isbof);
}
}
return status();
}
int TModule_table::_read(TRectype& rec, word op, word lockop)
{
if (op == _isfirst)
{
zero(rec);
TBaseisamfile::_read(rec, _isgteq, lockop);
if (not_in_table())
setstatus(_isemptyfile);
if (bad())
zero(rec);
}
else
if (op == _islast)
{
zero(rec);
put("CODTAB", "\xFF");
TBaseisamfile::_read(rec, _isgteq);
if (!eof())
TBaseisamfile::_read(rec, _isprev, lockop);
else
setstatus(NOERR);
if (bof())
setstatus(NOERR);
if (not_in_table())
setstatus(_isemptyfile);
if (bad())
zero(rec);
}
else
if (op == _isprev)
{
const TRecnotype nrec = recno();
TBaseisamfile::_read(rec, _isprev, lockop);
if (not_in_table())
{
if (lockop == _lock) reread(_unlock);
readat(rec, nrec, lockop);
setstatus(_isbof);
}
}
else
if (op == _isnext)
{
const TRecnotype nrec = recno();
TBaseisamfile::_read(rec, _isnext, lockop);
if (not_in_table())
{
if (lockop == _lock) reread(_unlock);
readat(rec, nrec, lockop);
setstatus(_iseof);
}
}
else
{
rec.put("COD", _tabname);
rec.put("MOD", _module);
rec.put("CUST", _customer);
TBaseisamfile::_read(rec, op, lockop);
if (not_in_table())
{
if (lockop == _lock) reread(_unlock);
last(lockop);
setstatus(_iseof);
}
}
return status();
}
int TModule_table::_readat(TRectype& rec ,TRecnotype nrec, word lockop)
{
TBaseisamfile::_readat(rec, nrec, lockop);
CHECKS(in_table(), "Invalid position : Table ", (const char *)_tabname);
return status();
}
bool TModule_table::empty()
{
return read(_isfirst) != NOERR;
}
void TModule_table::load_module_description()
{
// Setta il modulo al quale appartiene la tabella e la relativa descrizione.
// Cerca prima in RECDESC il relativo file di descrizione: D<TAB_NAME>.DES
// Se il file esiste, se il paragrafo [TabDescr] esiste e se esiste la
// variabile Module ne prende il valore.
// Se non si verificano le suddette condizioni procede come segue:
// cerca se esiste il file ??<TAB_NAME>.MSK tramite la funzione list_files(),
// ne estrae il module dai primi 2 caratteri e la descrizione dalla intestazione
// della prima pagina.
_des_mod_loaded = TRUE;
TFilename n;
n << "recdesc/d" << _tabname;
n.ext("des");
n.lower();
if (n.exist())
{
TConfig des(n, "TabDescr");
_module = des.get("Module");
}
n = "??tb";
n << _tabname;
n.ext("msk");
n.lower();
TString_array f;
if (list_files(n, f) == 1)
{
n = f.row(0);
if (!n.exist())
n.overwrite("ba",0);
if (n.exist())
{
if (_module.empty())
{
_module = n.left(2);
_module.lower();
}
TScanner m(n);
bool ok = TRUE;
while (ok)
{
const TString& l2 = m.line().left(2);
if (l2.empty())
ok = FALSE;
else
if (l2 == "PA")
break;
}
if (ok)
{
const int apicia = m.token().find('"')+1;
const int apicic = m.token().find('"', apicia);
_description = m.token().sub(apicia, apicic);
}
}
else
_module = "ba";
}
else
_module = "ba";
}
const char* TModule_table::module()
{
if (!_des_mod_loaded)
load_module_description();
return _module;
}
const char* TModule_table::description()
{
if (!_des_mod_loaded)
load_module_description();
return _description;
}
struct TCallbackTableinfo
{
TString16 _var1, _var2, _var3;
TString4 _module;
TFilename _tabapp, _relapp;
};
HIDDEN int find_relapp(TConfig& cfg, void* jolly)
{
TCallbackTableinfo& info = *((TCallbackTableinfo*)jolly);
if (cfg.exist(info._var1))
{
info._tabapp = cfg.get(info._var1);
if (info._tabapp.not_empty())
return 1;
}
if (cfg.get_paragraph().compare(info._module, 2, TRUE) == 0)
{
if (cfg.exist(info._var2))
{
info._relapp = cfg.get(info._var2);
if (info._relapp.not_empty())
return 2;
}
if (cfg.exist(info._var3))
{
info._relapp = cfg.get(info._var3);
if (info._relapp.not_empty())
return 3;
}
}
return 0;
}
bool TModule_table::get_relapp(TString& app) const
{
TConfig ini("install.ini");
TCallbackTableinfo fi;
fi._var1.format("Edit_%s", (const char*)_tabname);
fi._var2.format("Edit_%d", num());
fi._var3.format("Edit_%d", num() == LF_TAB ? LF_TABCOM : LF_TAB);
fi._module = ((TModule_table*)this)->module();
ini.for_each_paragraph(find_relapp, &fi);
app = fi._tabapp;
if (app.empty())
app = fi._relapp;
if (app.empty())
{
app = "ba3 -0";
if (fi._module.compare("ba", 2, TRUE) != 0)
{
TConfig c(CONFIG_STUDIO, fi._module);
if (c.exist("TabPrg"))
app = c.get("TabPrg");
}
}
app << ' ';
if (num() == LF_TABCOM)
app << '%';
app << _tabname;
return app.not_empty();
}