147 lines
3.5 KiB
C++
147 lines
3.5 KiB
C++
|
#include "at9.h"
|
|||
|
#include "at9600a.h"
|
|||
|
|
|||
|
#include <applicat.h>
|
|||
|
#include <automask.h>
|
|||
|
#include <progind.h>
|
|||
|
#include <recarray.h>
|
|||
|
#include <recset.h>
|
|||
|
#include <relation.h>
|
|||
|
|
|||
|
#include "benem.h"
|
|||
|
#include "soggetti.h"
|
|||
|
#include "sezioni.h"
|
|||
|
|
|||
|
///////////////////////////////////////////////////////////
|
|||
|
// Maschera
|
|||
|
///////////////////////////////////////////////////////////
|
|||
|
|
|||
|
class TSort_benem_mask : public TAutomask
|
|||
|
{
|
|||
|
|
|||
|
public:
|
|||
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|||
|
TSort_benem_mask();
|
|||
|
~TSort_benem_mask();
|
|||
|
};
|
|||
|
|
|||
|
bool TSort_benem_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
TSort_benem_mask::TSort_benem_mask() : TAutomask("at9700a")
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
TSort_benem_mask::~TSort_benem_mask()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
///////////////////////////////////////////////////////////
|
|||
|
// Applicazione
|
|||
|
///////////////////////////////////////////////////////////
|
|||
|
|
|||
|
class TSort_benem_app : public TSkeleton_application
|
|||
|
{
|
|||
|
|
|||
|
protected:
|
|||
|
virtual void main_loop();
|
|||
|
|
|||
|
public:
|
|||
|
void riordina_benemerenze(const TMask& msk) const;
|
|||
|
|
|||
|
};
|
|||
|
|
|||
|
static int compare_benem(const TObject** o1, const TObject** o2)
|
|||
|
{
|
|||
|
TRectype* r1 = (TRectype*)*o1;
|
|||
|
TRectype* r2 = (TRectype*)*o2;
|
|||
|
|
|||
|
const TString b1(r1->get(BEN_TIPOBEN));
|
|||
|
const TString b2(r2->get(BEN_TIPOBEN));
|
|||
|
|
|||
|
int b=0;
|
|||
|
if (b1>b2) b=+1;
|
|||
|
else
|
|||
|
if (b1<b2) b=-1;
|
|||
|
return b;
|
|||
|
}
|
|||
|
|
|||
|
void TSort_benem_app::riordina_benemerenze(const TMask& msk) const
|
|||
|
{
|
|||
|
//seleziona i soggetti delle sezioni/sottosezioni selezionate
|
|||
|
TString query;
|
|||
|
query << "USE SOGGETTI KEY 3\n";
|
|||
|
query << "FROM CODSEZ=#DACODSEZ CODSOT=#DACODSOT\n";
|
|||
|
query << "TO CODSEZ=#ACODSEZ CODSOT=#ACODSOT";
|
|||
|
|
|||
|
TISAM_recordset soggetti(query);
|
|||
|
|
|||
|
const TString4 dacodsez = msk.get(F_SEZINI);
|
|||
|
const TString4 dacodsot = msk.get(F_SOTINI);
|
|||
|
const TString4 acodsez = msk.get(F_SEZFIN);
|
|||
|
const TString4 acodsot = msk.get(F_SOTFIN);
|
|||
|
|
|||
|
soggetti.set_var("#DACODSEZ", dacodsez);
|
|||
|
soggetti.set_var("#ACODSEZ", acodsez);
|
|||
|
soggetti.set_var("#DACODSOT", dacodsot);
|
|||
|
soggetti.set_var("#ACODSOT", acodsot);
|
|||
|
|
|||
|
//giro sui soggetti selezionati
|
|||
|
const long items = soggetti.items();
|
|||
|
TProgind pi(items, "Riordinamento benemerenze...", true, true);
|
|||
|
|
|||
|
const TRectype& rec_sog = soggetti.cursor()->curr();
|
|||
|
for (bool ok = soggetti.move_first(); ok; ok = soggetti.move_next())
|
|||
|
{
|
|||
|
if (!pi.addstatus(1))
|
|||
|
break;
|
|||
|
|
|||
|
//per ogni soggetto deve trovare le benemerenze, di norma ordinate alla cazzo
|
|||
|
const long codice = rec_sog.get_long(SOG_CODICE);
|
|||
|
|
|||
|
TString query_benem;
|
|||
|
query_benem << "USE BENEM\nFROM CODICE=#CODICE\nTO CODICE=#CODICE";
|
|||
|
TISAM_recordset benemerenze(query_benem);
|
|||
|
benemerenze.set_var("#CODICE", codice);
|
|||
|
const long ben_items = benemerenze.items();
|
|||
|
|
|||
|
if (ben_items > 0)
|
|||
|
{
|
|||
|
//aggiunge le benemerenze ad un record_array
|
|||
|
TRecord_array sogg_benem(LF_BENEM, BEN_PROGBEN);
|
|||
|
TRectype rec_ben(LF_BENEM);
|
|||
|
rec_ben.put(BEN_CODICE, codice);
|
|||
|
/*const TRectype& rec_ben = benemerenze.cursor()->curr();
|
|||
|
for (bool ok = benemerenze.move_first(); ok; ok = benemerenze.move_next())
|
|||
|
{
|
|||
|
sogg_benem.add_row(rec_ben);
|
|||
|
}*/
|
|||
|
|
|||
|
sogg_benem.read(rec_ben);
|
|||
|
//magicamente sorta il record_array!
|
|||
|
sogg_benem.sort(compare_benem);
|
|||
|
|
|||
|
for (int i = 1; i <= sogg_benem.rows(); i++)
|
|||
|
sogg_benem[i].put(BEN_PROGBEN, i);
|
|||
|
//ancora pi<70> magicamente riscrive le benemerenze in modo ordinato!
|
|||
|
sogg_benem.rewrite();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void TSort_benem_app::main_loop()
|
|||
|
{
|
|||
|
TSort_benem_mask m;
|
|||
|
while (m.run() == K_ENTER)
|
|||
|
riordina_benemerenze(m);
|
|||
|
}
|
|||
|
|
|||
|
int at9700(int argc, char* argv[])
|
|||
|
{
|
|||
|
TSort_benem_app app;
|
|||
|
app.run(argc, argv, TR("Riordinamento straordinario benemerenze"));
|
|||
|
return 0;
|
|||
|
}
|