Cancellaggio partite inutili

git-svn-id: svn://10.65.10.50/trunk@1143 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1995-03-17 11:47:29 +00:00
parent c40612059d
commit 7151add9d7
5 changed files with 186 additions and 134 deletions

View File

@ -7,20 +7,37 @@
#include <scadenze.h> #include <scadenze.h>
#include <partite.h> #include <partite.h>
#include <lffiles.h> #include <lffiles.h>
#include <assoc.h>
#include "sc1100.h" #include "sc1100.h"
class _BoolObj : public TObject
{
public:
bool _val;
int _count;
_BoolObj() { _val = FALSE; _count = 0; }
virtual ~_BoolObj() {}
};
class TDeletepart_app : public TApplication class TDeletepart_app : public TApplication
{ {
static TDate _datalimite; TDate _datalimite;
protected: protected:
virtual bool create(); virtual bool create();
virtual bool destroy(); virtual bool destroy();
virtual bool menu(MENU_TAG m); virtual bool menu(MENU_TAG m);
static bool partchiuseal(const TRelation *r); static bool partchiuseal(const TRelation *r);
static TDeletepart_app& app() { return (TDeletepart_app&)main_app(); }
public: public:
TDate& datalimite() { return _datalimite; }
TDeletepart_app() {}; TDeletepart_app() {};
~TDeletepart_app() {}; ~TDeletepart_app() {};
}; };
@ -39,7 +56,8 @@ bool TDeletepart_app::destroy()
bool TDeletepart_app::partchiuseal(const TRelation *r) bool TDeletepart_app::partchiuseal(const TRelation *r)
{ {
return (r->lfile().get_bool(PART_CHIUSA) && (r->lfile().get_date(PART_DATAREG) <= _datalimite)); return (/* r->lfile().get_bool(PART_CHIUSA) && */
(app().datalimite() >= r->lfile().get_date(PART_DATAREG)));
} }
bool TDeletepart_app::menu(MENU_TAG) bool TDeletepart_app::menu(MENU_TAG)
@ -48,6 +66,7 @@ bool TDeletepart_app::menu(MENU_TAG)
TRelation partite(LF_PARTITE); TRelation partite(LF_PARTITE);
TCursor cur(&partite); TCursor cur(&partite);
TLocalisamfile scadenze(LF_SCADENZE); TLocalisamfile scadenze(LF_SCADENZE);
TAssoc_array to_zap;
while (m.run() != K_QUIT) while (m.run() != K_QUIT)
{ {
@ -59,9 +78,23 @@ bool TDeletepart_app::menu(MENU_TAG)
TRecnotype total = 0; TRecnotype total = 0;
int lastanno = -1; int lastanno = -1;
TString16 lastpart = ""; TString16 lastpart = "";
TToken_string id(12);
for (cur = 0; cur.pos() <= last; ++cur) for (cur = 0; cur.pos() <= last; ++cur)
{ {
// build key
id = cur.curr().get(PART_ANNO);
id.add(cur.curr().get(PART_NUMPART));
if (!to_zap.is_key(id))
to_zap.add(id, new _BoolObj);
_BoolObj& bobj = (_BoolObj&)to_zap[id];
bobj._count ++;
if (cur.curr().get_bool(PART_CHIUSA))
bobj._val = TRUE;
if (lastanno != cur.curr().get_int(PART_ANNO) || if (lastanno != cur.curr().get_int(PART_ANNO) ||
lastpart != cur.curr().get(PART_NUMPART)); lastpart != cur.curr().get(PART_NUMPART));
{ {
@ -70,9 +103,16 @@ bool TDeletepart_app::menu(MENU_TAG)
lastpart = cur.curr().get(PART_NUMPART); lastpart = cur.curr().get(PART_NUMPART);
} }
} }
if (total == 0)
{
warning_box("Nessuna partita da cancellare");
return FALSE;
}
TString80 caption("Cancellazione di "); TString80 caption("Cancellazione di ");
caption.add_plural(total, "cur.curr()"); caption.add_plural(total, "partita");
if (!yesno_box(caption) || total < 1) if (!yesno_box(caption) || total < 1)
continue; continue;
@ -81,52 +121,64 @@ bool TDeletepart_app::menu(MENU_TAG)
cur.freeze(); cur.freeze();
lastanno = -1; lastanno = -1;
int err = NOERR; int err = NOERR;
for (cur = 0; cur.pos() <= last; ++cur) for (cur = 0; cur.pos() <= last; ++cur)
{ {
const int anno = cur.curr().get_int(PART_ANNO); const int anno = cur.curr().get_int(PART_ANNO);
const TString16 partita = cur.curr().get(PART_NUMPART); const TString16 partita = cur.curr().get(PART_NUMPART);
id = cur.curr().get(PART_ANNO);
id.add(cur.curr().get(PART_NUMPART));
_BoolObj& bobj = (_BoolObj&)to_zap[id];
err = cur.lock(); err = cur.lock();
if (err == NOERR && (lastanno != cur.curr().get_int(PART_ANNO) || if (err == NOERR && bobj._val == TRUE);
lastpart != cur.curr().get(PART_NUMPART)));
{ {
for (int rig = 1; err == NOERR; rig++) for (int rig = 1; err == NOERR; rig++)
{ {
scadenze.put(PART_ANNO, lastanno); scadenze.zero();
scadenze.put(PART_NUMPART, lastpart); scadenze.put(SCAD_ANNO, anno);
scadenze.put(PART_NRIGA, rig); scadenze.put(SCAD_NUMPART, partita);
if (scadenze.read(_isequal, _lock) == NOERR) scadenze.put(SCAD_NRATA, rig);
err = scadenze.remove(); if ((err = scadenze.read(_isequal, _lock)) == NOERR)
if (err != NOERR) if (scadenze.remove() != NOERR)
caption.format("riga scadenza %d", rig); {
caption.format("riga scadenza %d", rig);
break;
}
} }
pi.addstatus(1); pi.addstatus(1);
lastanno = cur.curr().get_int(PART_ANNO);
lastpart = cur.curr().get(PART_NUMPART); err = cur.file().remove();
if (err != NOERR)
caption = "riga partite";
} }
if (err == NOERR) } // eliminate partite e scadenze scelte
{
err = cur.file().remove(); // cerca scadenze senza partita
if (err != NOERR) TLocalisamfile& part = cur.file();
caption = "riga %d";
} for (scadenze.first(); !scadenze.eof() && err == NOERR; scadenze.next())
else
{
error_box("Errore %d nella cancellazione della %s della partita %d/%s",
err, (const char*)caption, anno, partita);
break;
}
}
for (int rig = 1; lastanno > 0 && err == NOERR; rig++)
{ {
scadenze.put(SCAD_ANNO, lastanno); part.zero();
scadenze.put(SCAD_NUMPART, lastpart); part.put(PART_ANNO, scadenze.get(SCAD_ANNO));
scadenze.put(SCAD_NRATA, rig); part.put(PART_NUMPART, scadenze.get(SCAD_NUMPART));
if (scadenze.read(_isequal, _lock) == NOERR)
// se non c'e'
if (part.read(_isgteq) != NOERR)
err = scadenze.remove(); err = scadenze.remove();
if (err != NOERR) if (err != NOERR)
caption.format("riga scadenza %d", rig); caption = "riga scadenze";
} }
if (err != NOERR)
{
error_box("Errore %d nella cancellazione della %s della partita %d/%s",
err, (const char*)caption, lastanno, lastpart);
break;
}
cur.freeze(FALSE); cur.freeze(FALSE);
} }
@ -137,6 +189,6 @@ bool TDeletepart_app::menu(MENU_TAG)
int sc1100(int argc, char** argv) int sc1100(int argc, char** argv)
{ {
TDeletepart_app a; TDeletepart_app a;
a.run(argc, argv, "Eliminazione partita chiuse"); a.run(argc, argv, "Eliminazione partite chiuse");
return 0; return 0;
} }

View File

@ -1,25 +1,21 @@
#include "sc1100.h" #include "sc1100.h"
PAGE "Eliminazione Partite Chiuse" -1 -1 42 9 PAGE "Eliminazione Partite Chiuse" -1 -1 48 10
TEXT DLG_NULL 40 3 TEXT DLG_NULL
BEGIN BEGIN
PROMPT 1 1 "Attenzione " PROMPT 2 1 " ATTENZIONE"
FLAGS "UM"
END END
TEXT DLG_NULL TEXT DLG_NULL
BEGIN BEGIN
PROMPT 19 1 "ATTENZIONE" PROMPT 1 3 "La cancellazione della partite puo' richiedere"
END END
TEXT DLG_NULL TEXT DLG_NULL
BEGIN BEGIN
PROMPT 2 3 "La cancellazione della partite puo' richiedere" PROMPT 1 4 " tempo. Siate certi di voler proseguire."
END
TEXT DLG_NULL
BEGIN
PROMPT 6 4 "tempo. Siate certi di voler proseguire."
END END
DATE F_DATE DATE F_DATE
@ -28,6 +24,7 @@ BEGIN
HELP "Data Sino a cui eliminare le partite" HELP "Data Sino a cui eliminare le partite"
CHECKTYPE REQUIRED CHECKTYPE REQUIRED
WARNING "Si deve specificare la data sino a cui eliminare le partite chiuse" WARNING "Si deve specificare la data sino a cui eliminare le partite chiuse"
FLAGS "A"
END END
BUTTON DLG_OK 10 2 BUTTON DLG_OK 10 2

View File

@ -5,6 +5,8 @@
#include <saldi.h> #include <saldi.h>
#include <partite.h> #include <partite.h>
#include <scadenze.h> #include <scadenze.h>
#include <lffiles.h>
#include <relation.h>
#include "sc1200.h" #include "sc1200.h"
@ -34,36 +36,37 @@ bool TCreatepart_app::destroy()
bool TCreatepart_app::menu(MENU_TAG) bool TCreatepart_app::menu(MENU_TAG)
{ {
TMask m("sc1200a"); TMask m("sc1200a");
TRelation saldi(LF_SALDI); TRelation saldi(LF_SALDI);
TLocalisamfile conti(LF_CONTI); TLocalisamfile conti(LF_PCON);
saldi.zero();
saldi.zero();
while (m.run() != K_QUIT) while (m.run() != K_QUIT)
{ {
const int anno = m.get_int(F_ANNO); const int anno = m.get_int(F_ANNO);
saldi.put(SLD_ANNO, anno); // saldi.curr().put(SLD_ANNO, anno);
TCursor cur(&saldi, "", 1, saldi.curr(), saldi.curr()); TCursor cur(&saldi, "", 1, &saldi.curr(), &saldi.curr());
const int items = cur.items(); const long items = cur.items();
long npart = 0L; long npart = 0L;
if (items > 0) // if (items > 0)
{ // {
for (cur = 0 ; cur.pos() < items; cur++) // for (cur = 0 ; cur.pos() < items; ++cur)
{ // {
if (is_clifo(cur.curr().get_int(SLD_GRUPPO), cur.curr().get_int(SLD_CONTO)) // if (is_clifo(cur.curr().get_int(SLD_GRUPPO), cur.curr().get_int(SLD_CONTO)))
{ // {
TSaldo s(????); // TSaldo s(????);
Timporto saldo(s.saldo??); // Timporto saldo(s.saldo??);
if (saldo != ZERO) // if (saldo != ZERO)
{ // {
} // }
} // }
} // }
} // else
else // message_box("Nessun saldo presente per l'anno %d", anno);
message_box("Nessun saldo presente per l'anno %d", anno);
} // while run
return FALSE; return FALSE;
} }