150 lines
3.3 KiB
C++
Executable File
150 lines
3.3 KiB
C++
Executable File
//***********************************
|
|
//* Rinumerazione numero protocollo *
|
|
//***********************************
|
|
#include <mov.h>
|
|
#include "cg1300.h"
|
|
#include "cg1303.h"
|
|
|
|
HIDDEN TAgg_nprot& app() { return (TAgg_nprot&) main_app(); }
|
|
|
|
bool TAgg_nprot::filtra_mov(const TRelation* r)
|
|
{
|
|
TLocalisamfile& mov = r->lfile();
|
|
|
|
const int annoiva = mov.get_int(MOV_ANNOIVA);
|
|
const TString16 reg = mov.get(MOV_REG);
|
|
|
|
if (app()._anno == annoiva && app()._reg == reg)
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
bool TAgg_nprot::create()
|
|
{
|
|
TApplication::create();
|
|
|
|
_tabreg = new TTable("REG");
|
|
|
|
dispatch_e_menu (BAR_ITEM(1));
|
|
return TRUE;
|
|
}
|
|
|
|
bool TAgg_nprot::destroy()
|
|
{
|
|
delete _tabreg;
|
|
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
bool TAgg_nprot::menu(MENU_TAG m)
|
|
{
|
|
TMask msk("cg1300b");
|
|
|
|
TConfig conf(CONFIG_DITTA);
|
|
int annoiva = conf.get_int("AnLiIv");
|
|
|
|
msk.set(F_ANNO, annoiva);
|
|
|
|
while (msk.run() == K_ENTER)
|
|
{
|
|
_anno = msk.get_int(F_ANNO);
|
|
_reg = msk.get(F_REG);
|
|
_prot = msk.get_long(F_PROT);
|
|
|
|
rinumera_prot();
|
|
|
|
msk.reset(F_REG);
|
|
msk.reset(F_PROT);
|
|
//return TRUE;
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
int TAgg_nprot::rinumera_prot()
|
|
{
|
|
TRelation rel (LF_MOV);
|
|
TLocalisamfile& mov = rel.lfile();
|
|
|
|
//TString80 filter;
|
|
//filter.format("ANNOIVA=%04d && REG=\"%s\"", _anno, (const char*)_reg);
|
|
//TCursor cursor(&rel, filter, 2);
|
|
|
|
TCursor cursor(&rel, "", 2);
|
|
cursor.set_filterfunction(filtra_mov);
|
|
|
|
cursor = 0L;
|
|
const long nitems = cursor.items();
|
|
|
|
//TProgind p(nitems ? nitems : 1, "Elaborazione in corso..." , TRUE, TRUE, 70);
|
|
TProgind* p = NULL;
|
|
|
|
if (nitems > 0L)
|
|
p = new TProgind (nitems, "Elaborazione in corso..." , TRUE, TRUE, 70);
|
|
|
|
long protiva, uprotiva;
|
|
|
|
for (; cursor.pos() < cursor.items(); ++cursor)
|
|
{
|
|
if (p) p->addstatus(1);
|
|
protiva = mov.get_long(MOV_PROTIVA);
|
|
uprotiva = mov.get_long(MOV_UPROTIVA);
|
|
if (protiva != _prot && uprotiva != _prot) continue;
|
|
else
|
|
{
|
|
if (uprotiva != 0l)
|
|
_prot = uprotiva;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (protiva != _prot && uprotiva != _prot) //sono alla fine del file
|
|
{
|
|
delete p;
|
|
return message_box("Non trovato record con protocollo indicato: rinumerazione non avvenuta");
|
|
}
|
|
|
|
++cursor;
|
|
|
|
long nprot,uprot,dprot;
|
|
dprot = uprot = 0L;
|
|
nprot = _prot;
|
|
|
|
for (; cursor.pos() < cursor.items(); ++cursor)
|
|
{
|
|
if (p) p->addstatus(1);
|
|
protiva = mov.get_long(MOV_PROTIVA);
|
|
uprotiva = mov.get_long(MOV_UPROTIVA);
|
|
|
|
nprot = nprot+1+dprot; //stile RPG
|
|
dprot = 0L;
|
|
uprot = 0L;
|
|
dprot = (uprotiva == 0L) ? 0L : (uprotiva - protiva);
|
|
uprot = (uprotiva == 0L) ? 0L : (nprot + dprot);
|
|
|
|
mov.put(MOV_PROTIVA, nprot);
|
|
mov.put(MOV_UPROTIVA, uprot);
|
|
mov.rewrite();
|
|
}
|
|
|
|
TTable reg("REG");
|
|
TString16 s; s.format("%04d%s", _anno, (const char*)_reg);
|
|
reg.zero();
|
|
reg.put("CODTAB", s);
|
|
if (reg.read() == NOERR)
|
|
{
|
|
reg.put("I5", nprot + dprot);
|
|
reg.rewrite();
|
|
}
|
|
else
|
|
{
|
|
delete p;
|
|
return error_box("Impossibile leggere il registro %s anno %s",
|
|
(const char*)_reg, (const char*)_anno);
|
|
}
|
|
delete p;
|
|
return message_box("Rinumerazione numero protocollo completata");
|
|
}
|
|
|