122 lines
2.3 KiB
C++
122 lines
2.3 KiB
C++
|
#include <effetti.h>
|
||
|
#include <cession.h>
|
||
|
#include "ef0101.h"
|
||
|
|
||
|
/////////////////////////////////////////////////////////////
|
||
|
|
||
|
|
||
|
TEffObb::TEffObb():TRelation(LF_EFFETTI), _oldobbligati(0)
|
||
|
{
|
||
|
add(LF_CESS,"NPROGTR=NPROGTR");
|
||
|
}
|
||
|
|
||
|
void TEffObb::destroy_rows()
|
||
|
{
|
||
|
_obbligati.destroy();
|
||
|
}
|
||
|
|
||
|
TRectype& TEffObb::obbligato(int i)
|
||
|
{
|
||
|
TRectype *r=(TRectype*)_obbligati.objptr(i);
|
||
|
|
||
|
if (r == NULL)
|
||
|
{
|
||
|
r = new TRectype(LF_CESS);
|
||
|
_obbligati.add(r,i);
|
||
|
}
|
||
|
return *r;
|
||
|
}
|
||
|
|
||
|
int TEffObb::read_obbligati()
|
||
|
{
|
||
|
const TLocalisamfile& robb = lfile(LF_CESS);
|
||
|
|
||
|
position_rels();
|
||
|
destroy_rows();
|
||
|
for (bool ok=is_first_match(LF_CESS);ok;ok=next_match(LF_CESS))
|
||
|
{
|
||
|
const int nriga=robb.get_int(CES_NRIGA) -1;
|
||
|
obbligato(nriga)=robb.curr();
|
||
|
}
|
||
|
_oldobbligati=obbligati_items();
|
||
|
return NOERR;
|
||
|
}
|
||
|
|
||
|
int TEffObb::read(TIsamop op, TReclock lockop, TDate& atdate)
|
||
|
{
|
||
|
int err=file().read(op,lockop,atdate);
|
||
|
if (err==NOERR) read_obbligati();
|
||
|
return err;
|
||
|
}
|
||
|
|
||
|
int TEffObb::write_rec(bool re, const TRectype& rec, TLocalisamfile& f)
|
||
|
{
|
||
|
if (re)
|
||
|
{
|
||
|
const bool scrivi= (f.rewrite(rec)!=NOERR);
|
||
|
if (scrivi) f.write(rec);
|
||
|
} else
|
||
|
f.write(rec);
|
||
|
return f.status();
|
||
|
}
|
||
|
|
||
|
int TEffObb::cancella(TLocalisamfile& f, int da, int a)
|
||
|
{
|
||
|
const long nprogtr=lfile().get_long(EFF_NPROGTR);
|
||
|
|
||
|
for (int i=da; i<=a;i++)
|
||
|
{
|
||
|
f.zero();
|
||
|
f.put(CES_NPROGTR,nprogtr);
|
||
|
f.put(CES_NRIGA,i);
|
||
|
if (f.read(_isequal,_lock)==NOERR)
|
||
|
f.remove();
|
||
|
}
|
||
|
return f.status();
|
||
|
}
|
||
|
|
||
|
int TEffObb::registra(bool re, bool force)
|
||
|
{
|
||
|
TLocalisamfile& c=lfile(LF_EFFETTI);
|
||
|
int err=write_rec(re,c.curr(),c);
|
||
|
if (err!=NOERR) return err;
|
||
|
|
||
|
TLocalisamfile& robb=lfile(LF_CESS);
|
||
|
const long nprogtr=c.get_long(CES_NPROGTR);
|
||
|
|
||
|
for (int i=0; i<obbligati_items(); i++)
|
||
|
{
|
||
|
if (!re)
|
||
|
obbligato(i).put(CES_NPROGTR,nprogtr);
|
||
|
err=write_rec(TRUE,obbligato(i),robb);
|
||
|
}
|
||
|
if (i<_oldobbligati)
|
||
|
cancella(robb,i+1,_oldobbligati);
|
||
|
_oldobbligati=obbligati_items();
|
||
|
return err;
|
||
|
}
|
||
|
|
||
|
int TEffObb::write(bool force, TDate&)
|
||
|
{
|
||
|
_oldobbligati=0;
|
||
|
return registra(FALSE,force);
|
||
|
}
|
||
|
|
||
|
int TEffObb::rewrite(bool force, TDate&)
|
||
|
{
|
||
|
return registra(TRUE,force);
|
||
|
}
|
||
|
|
||
|
int TEffObb::remove(TDate&)
|
||
|
{
|
||
|
TLocalisamfile& c=lfile(LF_EFFETTI);
|
||
|
|
||
|
c.remove();
|
||
|
|
||
|
TLocalisamfile& robb=lfile(LF_CESS);
|
||
|
cancella(robb,1,_oldobbligati);
|
||
|
_oldobbligati=0;
|
||
|
|
||
|
return c.status();
|
||
|
}
|