Nulla facisse, ma iddu committesse

git-svn-id: svn://10.65.10.50/trunk@2286 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
villa 1995-12-14 10:45:54 +00:00
parent c163b8e1e7
commit 26813394d6

View File

@ -1,299 +1,299 @@
#include "scselect.h" #include "scselect.h"
TSelection_mask::TSelection_mask(const char* name) TSelection_mask::TSelection_mask(const char* name)
: TMask(name), _who('C'), _key(1), _clifo_rel(NULL), : TMask(name), _who('C'), _key(1), _clifo_rel(NULL),
_cli_cur_k1(NULL), _cli_cur_k2(NULL), _for_cur_k1(NULL), _for_cur_k2(NULL) _cli_cur_k1(NULL), _cli_cur_k2(NULL), _for_cur_k1(NULL), _for_cur_k2(NULL)
{ {
// crea relazioni, cursori e cursor_sheets // crea relazioni, cursori e cursor_sheets
_clifo_rel = new TRelation(LF_CLIFO); _clifo_rel = new TRelation(LF_CLIFO);
TRectype filter(LF_CLIFO); TRectype filter(LF_CLIFO);
filter.put("TIPOCF", "C"); filter.put("TIPOCF", "C");
_cli_cur_k1 = new TCursor(_clifo_rel, "", 1, &filter, &filter); _cli_cur_k1 = new TCursor(_clifo_rel, "", 1, &filter, &filter);
_cli_cur_k2 = new TCursor(_clifo_rel, "", 2, &filter, &filter); _cli_cur_k2 = new TCursor(_clifo_rel, "", 2, &filter, &filter);
_cli_sh_k1 = new TCursor_sheet(_cli_cur_k1, " |CODCF|RAGSOC", "Selezione clienti per codice", _cli_sh_k1 = new TCursor_sheet(_cli_cur_k1, " |CODCF|RAGSOC", "Selezione clienti per codice",
"@1|Codice|Ragione Sociale@50"); "@1|Codice|Ragione Sociale@50");
_cli_sh_k2 = new TCursor_sheet(_cli_cur_k2, " |RAGSOC|CODCF", "Selezione clienti per ragione sociale", _cli_sh_k2 = new TCursor_sheet(_cli_cur_k2, " |RAGSOC|CODCF", "Selezione clienti per ragione sociale",
"@1|Ragione Sociale@50|Codice"); "@1|Ragione Sociale@50|Codice");
if (id2pos(SC_CLIFO) >= 0) if (id2pos(SC_CLIFO) >= 0)
{ {
filter.put("TIPOCF", "F"); filter.put("TIPOCF", "F");
_for_cur_k1 = new TCursor(_clifo_rel, "", 1, &filter, &filter); _for_cur_k1 = new TCursor(_clifo_rel, "", 1, &filter, &filter);
_for_cur_k2 = new TCursor(_clifo_rel, "", 2, &filter, &filter); _for_cur_k2 = new TCursor(_clifo_rel, "", 2, &filter, &filter);
_for_sh_k1 = new TCursor_sheet(_for_cur_k1, " |CODCF|RAGSOC", "Selezione fornitori per codice", _for_sh_k1 = new TCursor_sheet(_for_cur_k1, " |CODCF|RAGSOC", "Selezione fornitori per codice",
"@1|Codice|Ragione Sociale@50"); "@1|Codice|Ragione Sociale@50");
_for_sh_k2 = new TCursor_sheet(_for_cur_k2, " |RAGSOC|CODCF", "Selezione fornitori per ragione sociale", _for_sh_k2 = new TCursor_sheet(_for_cur_k2, " |RAGSOC|CODCF", "Selezione fornitori per ragione sociale",
"@1|Ragione Sociale@50|Codice"); "@1|Ragione Sociale@50|Codice");
} }
set_handler(SC_CLIFO, rclifo_handler); set_handler(SC_CLIFO, rclifo_handler);
set_handler(SC_SORTCF, rsortcf_handler); set_handler(SC_SORTCF, rsortcf_handler);
set_handler(SC_CFBUTFR, bfrom_handler); set_handler(SC_CFBUTFR, bfrom_handler);
set_handler(SC_CFBUTTO, bto_handler); set_handler(SC_CFBUTTO, bto_handler);
set_handler(SC_SELECT, bselect_handler); set_handler(SC_SELECT, bselect_handler);
set_handler(SC_RESET, breset_handler); set_handler(SC_RESET, breset_handler);
set_handler(SC_CFCODFR, ffrom_handler); set_handler(SC_CFCODFR, ffrom_handler);
set_handler(SC_CFCODTO, fto_handler); set_handler(SC_CFCODTO, fto_handler);
} }
TSelection_mask::~TSelection_mask() TSelection_mask::~TSelection_mask()
{ {
delete _for_sh_k2; delete _for_sh_k2;
delete _for_sh_k1; delete _for_sh_k1;
delete _for_cur_k2; delete _for_cur_k2;
delete _for_cur_k1; delete _for_cur_k1;
delete _cli_sh_k2; delete _cli_sh_k2;
delete _cli_sh_k1; delete _cli_sh_k1;
delete _cli_cur_k2; delete _cli_cur_k2;
delete _cli_cur_k1; delete _cli_cur_k1;
delete _clifo_rel; delete _clifo_rel;
} }
void TSelection_mask::set_handler(short fld_id, CONTROL_HANDLER handler) void TSelection_mask::set_handler(short fld_id, CONTROL_HANDLER handler)
{ {
const int pos = id2pos(fld_id); const int pos = id2pos(fld_id);
if (pos >= 0) if (pos >= 0)
fld(pos).set_handler(handler); fld(pos).set_handler(handler);
} }
TCursor_sheet& TSelection_mask::cur_sheet() const TCursor_sheet& TSelection_mask::cur_sheet() const
{ {
TCursor_sheet* cs; TCursor_sheet* cs;
if (get_key() == 1) cs = get_who() == 'C' ? _cli_sh_k1 : _for_sh_k1; if (get_key() == 1) cs = get_who() == 'C' ? _cli_sh_k1 : _for_sh_k1;
else cs = get_who() == 'C' ? _cli_sh_k2 : _for_sh_k2; else cs = get_who() == 'C' ? _cli_sh_k2 : _for_sh_k2;
CHECK(cs, "Can't use a NULL TCursor_sheet"); CHECK(cs, "Can't use a NULL TCursor_sheet");
return *cs; return *cs;
} }
void TSelection_mask::reset_sheets() void TSelection_mask::reset_sheets()
{ {
_cli_sh_k1->uncheck(-1); _cli_sh_k1->uncheck(-1);
_cli_sh_k2->uncheck(-1); _cli_sh_k2->uncheck(-1);
if (_for_sh_k1) if (_for_sh_k1)
{ {
_for_sh_k1->uncheck(-1); _for_sh_k1->uncheck(-1);
_for_sh_k2->uncheck(-1); _for_sh_k2->uncheck(-1);
} }
reset(SC_CFCODFR); reset(SC_CFCODFR);
reset(SC_CFCODTO); reset(SC_CFCODTO);
reset(SC_NSEL); reset(SC_NSEL);
} }
// Seleziona tutti i clienti con codice compreso tra due estremi // Seleziona tutti i clienti con codice compreso tra due estremi
void TSelection_mask::select_clifo_range(long from, long to) void TSelection_mask::select_clifo_range(long from, long to)
{ {
TCursor_sheet& c = cur_sheet(); TCursor_sheet& c = cur_sheet();
const long items = c.items(); const long items = c.items();
const int key = get_key(); const int key = get_key();
TString s_from(50), s_to(50); TString s_from(50), s_to(50);
if (from > to) // Controlla limiti if (from > to) // Controlla limiti
{ {
long tmp = to; long tmp = to;
to = from; to = from;
from = tmp; from = tmp;
} }
s_from = c.row(from).get(3-key); // Legge ragione sociale iniziale s_from = c.row(from).get(3-key); // Legge ragione sociale iniziale
s_to = c.row(to).get(3-key); // ... e finale s_to = c.row(to).get(3-key); // ... e finale
bool cod1ok = FALSE, cod2ok = FALSE; bool cod1ok = FALSE, cod2ok = FALSE;
long last = 0; long last = 0;
long firs = 0; long firs = 0;
for (long i = 0; i < items; i++) for (long i = 0; i < items; i++)
{ {
TToken_string& tt = c.row(i); TToken_string& tt = c.row(i);
const long cod = tt.get_long(key); const long cod = tt.get_long(key);
bool add; bool add;
if (key == 2) if (key == 2)
{ {
const char* s = tt.get(1); const char* s = tt.get(1);
add = s_from <= s && s_to >= s; add = s_from <= s && s_to >= s;
} }
else else
add = cod >= from && cod <= to; add = cod >= from && cod <= to;
if (add) if (add)
{ {
c.check(i); c.check(i);
if (firs == 0) if (firs == 0)
firs = cod; firs = cod;
last = cod; last = cod;
} }
else else
c.uncheck(i); c.uncheck(i);
if (cod == from) cod1ok = TRUE; if (cod == from) cod1ok = TRUE;
if (cod == to) cod2ok = TRUE; if (cod == to) cod2ok = TRUE;
} }
if (!cod1ok) from = firs; if (!cod1ok) from = firs;
if (!cod2ok) to = last; if (!cod2ok) to = last;
set(SC_CFCODFR, from); set(SC_CFCODFR, from);
set(SC_CFCODTO, to); set(SC_CFCODTO, to);
set(SC_NSEL, c.checked()); set(SC_NSEL, c.checked());
} }
// Cerca il primo e l'ultimo cliente selezionati // Cerca il primo e l'ultimo cliente selezionati
void TSelection_mask::set_clifo_limits() void TSelection_mask::set_clifo_limits()
{ {
long first = 0, last = 0, nsel = 0; long first = 0, last = 0, nsel = 0;
TCursor_sheet& c = cur_sheet(); TCursor_sheet& c = cur_sheet();
const long items = c.items(); const long items = c.items();
const int key = get_key(); const int key = get_key();
for (int i = 0; i < items; i++) if (c.checked(i)) for (int i = 0; i < items; i++) if (c.checked(i))
{ {
TToken_string& t = c.row(i); TToken_string& t = c.row(i);
const long kod = t.get_long(key); const long kod = t.get_long(key);
if (first == 0) if (first == 0)
{ {
first = last = kod; first = last = kod;
} }
else else
{ {
if (first > kod) first = kod; if (first > kod) first = kod;
if (last < kod) last = kod; if (last < kod) last = kod;
} }
nsel++; nsel++;
} }
set(SC_CFCODFR, first); set(SC_CFCODFR, first);
set(SC_CFCODTO, last); set(SC_CFCODTO, last);
set(SC_NSEL, nsel); set(SC_NSEL, nsel);
} }
// handlers // handlers
bool TSelection_mask::bfrom_handler(TMask_field& f, KEY k) bool TSelection_mask::bfrom_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
TCursor_sheet& c = m.cur_sheet(); TCursor_sheet& c = m.cur_sheet();
c.disable_check(); c.disable_check();
if (c.run() == K_ENTER) if (c.run() == K_ENTER)
{ {
TToken_string& t = c.row(c.selected()); TToken_string& t = c.row(c.selected());
const long cod1 = t.get_long(m.get_key()); const long cod1 = t.get_long(m.get_key());
const long cod2 = m.get_long(SC_CFCODTO); const long cod2 = m.get_long(SC_CFCODTO);
m.set(SC_CFCODFR, cod1); m.set(SC_CFCODFR, cod1);
m.select_clifo_range(cod1, cod2); m.select_clifo_range(cod1, cod2);
} }
} }
return TRUE; return TRUE;
} }
bool TSelection_mask::bto_handler(TMask_field& f, KEY k) bool TSelection_mask::bto_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
TCursor_sheet& c = m.cur_sheet(); TCursor_sheet& c = m.cur_sheet();
c.disable_check(); c.disable_check();
if (c.run() == K_ENTER) if (c.run() == K_ENTER)
{ {
TToken_string& t = c.row(c.selected()); TToken_string& t = c.row(c.selected());
const long cod2 = t.get_long(m.get_key()); const long cod2 = t.get_long(m.get_key());
const long cod1 = m.get_long(SC_CFCODFR); const long cod1 = m.get_long(SC_CFCODFR);
m.set(SC_CFCODTO, cod2); m.set(SC_CFCODTO, cod2);
m.select_clifo_range(cod1, cod2); m.select_clifo_range(cod1, cod2);
} }
} }
return TRUE; return TRUE;
} }
bool TSelection_mask::ffrom_handler(TMask_field& f, KEY k) bool TSelection_mask::ffrom_handler(TMask_field& f, KEY k)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
if (k == K_TAB && f.focusdirty()) if (k == K_TAB && f.focusdirty())
{ {
const long cod1 = atol(f.get()); const long cod1 = atol(f.get());
const long cod2 = m.get_long(SC_CFCODTO); const long cod2 = m.get_long(SC_CFCODTO);
m.select_clifo_range(cod1, cod2); m.select_clifo_range(cod1, cod2);
} }
else else
if (k == K_F9) if (k == K_F9)
{ {
TMask_field& f = m.field(SC_CFBUTFR); TMask_field& f = m.field(SC_CFBUTFR);
f.on_hit(); f.on_hit();
} }
return TRUE; return TRUE;
} }
bool TSelection_mask::fto_handler(TMask_field& f, KEY k) bool TSelection_mask::fto_handler(TMask_field& f, KEY k)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
if (k == K_TAB && f.focusdirty()) if (k == K_TAB && f.focusdirty())
{ {
const long cod1 = m.get_long(SC_CFCODFR); const long cod1 = m.get_long(SC_CFCODFR);
const long cod2 = atol(f.get()); const long cod2 = atol(f.get());
m.select_clifo_range(cod1, cod2); m.select_clifo_range(cod1, cod2);
} }
else else
if (k == K_F9) if (k == K_F9)
{ {
TMask_field& f = m.field(SC_CFBUTTO); TMask_field& f = m.field(SC_CFBUTTO);
f.on_hit(); f.on_hit();
} }
return TRUE; return TRUE;
} }
bool TSelection_mask::breset_handler(TMask_field& f, KEY k) bool TSelection_mask::breset_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
m.reset_sheets(); m.reset_sheets();
} }
return TRUE; return TRUE;
} }
bool TSelection_mask::bselect_handler(TMask_field& f, KEY k) bool TSelection_mask::bselect_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
TCursor_sheet& c = m.cur_sheet(); TCursor_sheet& c = m.cur_sheet();
c.enable_check(); c.enable_check();
c.run(); c.run();
m.set_clifo_limits(); m.set_clifo_limits();
} }
return TRUE; return TRUE;
} }
bool TSelection_mask::rclifo_handler(TMask_field& f, KEY k) bool TSelection_mask::rclifo_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
m.set_who(f.get()[0]); m.set_who(f.get()[0]);
m.reset_sheets(); m.reset_sheets();
} }
return TRUE; return TRUE;
} }
bool TSelection_mask::rsortcf_handler(TMask_field& f, KEY k) bool TSelection_mask::rsortcf_handler(TMask_field& f, KEY k)
{ {
if (k == K_SPACE) if (k == K_SPACE)
{ {
TSelection_mask& m = (TSelection_mask&)f.mask(); TSelection_mask& m = (TSelection_mask&)f.mask();
m.set_key(atoi(f.get())); m.set_key(atoi(f.get()));
m.reset_sheets(); m.reset_sheets();
} }
return TRUE; return TRUE;
} }