campo-sirio/ci/ci0300.cpp

217 lines
5.1 KiB
C++
Raw Normal View History

#include <applicat.h>
#include <automask.h>
#include <sheet.h>
#include <utility.h>
#include <doc.h>
#include "ci0.h"
#include "cilib.h"
#include "ci0300.h"
#include "../ve/velib.h"
///////////////////////////////////////////////////////////
// TConfigurazioneIndustriale_mask
///////////////////////////////////////////////////////////
void TConfigurazioneIndustriale_mask::moveup_element(long selrow)
{
if (items()<=1)
return;
if (selrow<=0)
return;
if (selrow>items()-1)
return;
rows_array().swap(selrow,selrow - 1);
sheet().check_row(selrow - 1);
sheet().check_row(selrow);
sheet().force_update();
sheet().select(selrow-1);
}
void TConfigurazioneIndustriale_mask::movedown_element(long selrow)
{
if (items()<=1)
return;
if (selrow<0)
return;
if (selrow>=items()-1)
return;
rows_array().swap(selrow,selrow+1);
sheet().check_row(selrow);
sheet().check_row(selrow + 1);
sheet().force_update();
sheet().select(selrow+1);
}
bool TConfigurazioneIndustriale_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_MOVEUP:
moveup_element(sheet().selected());
break;
case F_MOVEDN:
movedown_element(sheet().selected());
break;
case FR_TIPODOC:
if (e == fe_modify)
{
TCodice_numerazione cod_num(o.mask().get(FR_NUM));
const TString& tipo = o.get();
int last = cod_num.ntipi_doc();
for (int i = 0; i < last; i++ )
{
const TString16 curtipo(cod_num.tipo_doc(i));
if (curtipo == tipo)
return true;
}
return o.error_box( "Tipo non valido per la numerazione selezionata!" );
}
case FR_COLL:
if (e == fe_modify && !o.mask().is_running())
{
TMask & row_mask = o.mask();
row_mask.set(FR_NUM, "");
row_mask.set(FR_TIPODOC, "");
row_mask.set(FR_STATO, "");
row_mask.set(FR_VAR, "");
row_mask.set(FR_MODCOLL, "");
const int row = sheet().selected();
sheet().update_row(row);
sheet().check_row(row);
sheet().force_update(row);
}
default:
break;
}
return true;
}
///////////////////////////////////////////////////////////
// TConfigurazioneIndustriale_app
///////////////////////////////////////////////////////////
// Overrides
bool TConfigurazioneIndustriale_app::create()
{
_mask = new TConfigurazioneIndustriale_mask();
file_to_sheet();
return TSkeleton_application::create();
}
bool TConfigurazioneIndustriale_app::destroy()
{
delete _mask;
return TSkeleton_application::destroy();
}
void TConfigurazioneIndustriale_app::main_loop()
{
KEY exitval;
while ((exitval=_mask->run()) != K_QUIT)
{
switch(exitval)
{
case K_ESC:
return;
default:
break;
}
}
sheet_to_file();
}
// Conversione Array <-> File
void TConfigurazioneIndustriale_app::file_to_sheet()
{
TConfig configfile(CONFIG_DITTA, "ci");
int item = 0;
while (configfile.exist("Descr",item))
{
TToken_string & t = mask().sheet().row(item);
t.add(configfile.get("Filter", NULL,item, "F01"));
t.add(configfile.get("Descr", NULL,item, "Fatture"));
t.add(configfile.get("InsertRemain", NULL,item, ""));
t.add(configfile.get("ModifyRemain", NULL,item, ""));
t.add(configfile.get("DocColl", NULL, item, ""));
t.add(configfile.get("NumColl", NULL, item, ""));
t.add(configfile.get("TipoColl", NULL, item, ""));
t.add(configfile.get("StatoColl", NULL, item, ""));
t.add(configfile.get("ModColl", NULL, item, ""));
t.add(configfile.get("Var", NULL, item, ""));
mask().sheet().check_row(item);
item++;
}
mask().sheet().force_update();
}
void TConfigurazioneIndustriale_app::sheet_to_file()
{
TConfig configfile(CONFIG_DITTA, "ci");
int totlen = 0;
int items;
items = mask().items();
configfile.remove_all();
if (items>_maxelem)
{
message_box("Il massimo numero di filtri gestibili <20> pari a %d, pertanto verranno considerate solamente le prime %d righe", _maxelem, _maxelem);
items=16;
}
for (int i=0;i<items;i++)
{
TString currdesc(mask().row(i).get(1));
configfile.set("Filter", mask().row(i).get(0), NULL, true, i);
configfile.set("Descr", currdesc, NULL, true, i);
configfile.set("InsertRemain", mask().row(i).get(2), NULL, true, i);
configfile.set("ModifyRemain", mask().row(i).get(3), NULL, true, i);
configfile.set("DocColl", mask().row(i).get(4), NULL, true, i);
configfile.set("NumColl", mask().row(i).get(5), NULL, true, i);
configfile.set("TipoColl", mask().row(i).get(6), NULL, true, i);
configfile.set("StatoColl", mask().row(i).get(7), NULL, true, i);
configfile.set("ModColl", mask().row(i).get(8), NULL, true, i);
configfile.set("Var", mask().row(i).get(9), NULL, true, i);
totlen+=currdesc.len();
}
if (totlen>_maxlen)
message_box("E' probabile che la lunghezza delle descrizioni inserite ne impedisca la totale visualizzazione sullo schermo");
}
///////////////////////////////////////////////////////////
// Main
///////////////////////////////////////////////////////////
int ci0300(int argc, char* argv[])
{
TConfigurazioneIndustriale_app a ;
a.run(argc, argv, TR("Contabilit<EFBFBD> Industriale"));
return 0;
}