campo-sirio/cg/cg3601.cpp

134 lines
3.4 KiB
C++

#include <automask.h>
#include <treectrl.h>
#include <statbar.h>
#include "cgsalda3.h"
#include "cg3601.h"
#include "../sc/sc0200b.h"
class TPartitario : public TAutomask
{
TPartite_array _games;
TSolder_tree _tree;
long _numreg;
protected:
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TPartitario(const TBill& bill);
};
bool TPartitario::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch (o.dlg())
{
case F_TUTTE:
if (e == fe_init || e == fe_modify)
{
TBill bill;
const char tipo = get(F_TIPO)[0];
const short dlg = tipo == 'C' ? F_CLIENTE : (tipo == 'F' ? F_FORNITORE : F_SOTTOCONTO);
bill.get(*this, F_GRUPPO, F_CONTO, dlg, F_TIPO, dlg+1);
const TString& codval = get(F_CODVAL);
const real cambio = UNO;
const TSolder_tree_flags flags = (TSolder_tree_flags)atoi(o.get());
_tree.set_root(_games, bill, 0, 0, codval, cambio, flags);
tfield(F_PARTITE).set_tree(&_tree);
_numreg = 0L;
disable(DLG_EDIT);
}
break;
case DLG_USER:
if (e == fe_button)
{
TWait_cursor hourglass;
if (_tree.expanded())
_tree.shrink_all();
else
_tree.expand_all();
tfield(F_PARTITE).win().force_update();
}
break;
case F_PARTITE:
if (e == fe_modify || e == fe_button)
{
_numreg = 0L;
TTree_field& tree = tfield(F_PARTITE);
tree.goto_selected();
TToken_string node; _tree.curr_id(node);
int level = node.items();
if (level >= 2)
{
TPartita& game = *_tree.partita();
const int nriga = node.get_int(1);
const int nrata = node.get_int();
int nrigp = node.get_int();
if (nrigp <= 0 && nriga == TPartita::UNASSIGNED)
nrigp = game.unassigned().first_row();
long numreg = 0;
if (nrigp > 0 && game.esiste(nrigp))
{
const TRiga_partite& rigp = game.riga(nrigp);
_numreg = rigp.get_long(PART_NREG);
} else
if (nriga > 0 && nriga < TPartita::UNASSIGNED && game.esiste(nriga))
{
TRiga_partite& riga = game.riga(nriga);
_numreg = riga.get_long(PART_NREG);
}
}
enable(DLG_EDIT, _numreg > 0L);
}
if (e == fe_button && _numreg > 0)
{
TRectype mov(LF_MOV);
mov.put("NUMREG", _numreg);
mov.edit();
}
break;
case DLG_EDIT:
if (e == fe_button && _numreg > 0)
{
TRectype mov(LF_MOV);
mov.put("NUMREG", _numreg);
mov.edit();
}
break;
default:
break;
}
return true;
}
TPartitario::TPartitario(const TBill& bill) : TAutomask("sc0200b")
{
WINDOW tb = toolbar();
xvt_toolbar_remove_control(tb, DLG_NEWREC);
xvt_toolbar_remove_control(tb, DLG_EDIT);
const real cambio = UNO;
const TSolder_tree_flags flags = sct_all_games;
switch (bill.tipo())
{
case 'C': bill.set(*this, F_GRUPPO, F_CONTO, F_CLIENTE); break;
case 'F': bill.set(*this, F_GRUPPO, F_CONTO, F_FORNITORE); break;
default : bill.set(*this, F_GRUPPO, F_CONTO, F_SOTTOCONTO); break;
}
}
bool popup_games(const TBill& bill)
{
TBill conto = bill;
bool go = conto.find();
if (go)
{
TPartitario part(conto);
go = part.run() == K_ENTER;
}
return go;
}