2007-12-10 09:48:34 +00:00
|
|
|
|
#include <colors.h>
|
1995-11-07 11:38:23 +00:00
|
|
|
|
#include <mailbox.h>
|
1998-02-24 10:37:28 +00:00
|
|
|
|
#include <msksheet.h>
|
1998-12-10 16:25:48 +00:00
|
|
|
|
#include <postman.h>
|
1997-05-21 09:39:46 +00:00
|
|
|
|
#include <progind.h>
|
1995-11-07 11:38:23 +00:00
|
|
|
|
#include <sheet.h>
|
1997-06-25 07:04:37 +00:00
|
|
|
|
#include <recarray.h>
|
1995-11-07 11:38:23 +00:00
|
|
|
|
#include <relapp.h>
|
2008-07-25 15:13:17 +00:00
|
|
|
|
#include <statbar.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
#include <urldefid.h>
|
1998-05-04 08:51:30 +00:00
|
|
|
|
#include <utility.h>
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TRelation_application
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
TRelation_application::TRelation_application()
|
2003-08-08 12:54:27 +00:00
|
|
|
|
: _mask(NULL), _search_id(-1), _lnflag(0),
|
|
|
|
|
_autodelete(0), _navigating(false)
|
1996-05-08 11:09:13 +00:00
|
|
|
|
{ }
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
TRelation_application::~TRelation_application()
|
1996-05-08 11:09:13 +00:00
|
|
|
|
{ }
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
2003-09-23 14:47:55 +00:00
|
|
|
|
TCursor& TRelation_application::get_filtered_cursor() const
|
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
const TEdit_field& f = get_search_field();
|
|
|
|
|
return *f.browse()->cursor();
|
2003-09-23 14:47:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
void TRelation_application::setkey()
|
|
|
|
|
{
|
|
|
|
|
if (has_filtered_cursor())
|
2003-09-23 14:47:55 +00:00
|
|
|
|
get_filtered_cursor().setkey();
|
2007-03-06 16:37:44 +00:00
|
|
|
|
else
|
|
|
|
|
file().setkey(1);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
|
void TRelation_application::set_key_filter()
|
|
|
|
|
{
|
|
|
|
|
TString rf = get_user_read_filter(); rf.trim();
|
|
|
|
|
if (rf.not_empty())
|
|
|
|
|
{
|
|
|
|
|
TString expr;
|
|
|
|
|
for (int f = _mask->fields()-1; f >= 0; f--)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& fld= _mask->fld(f);
|
|
|
|
|
if (fld.is_edit() && fld.in_key(0))
|
|
|
|
|
{
|
|
|
|
|
TBrowse* b = ((TEdit_field&)fld).browse();
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (b && b->cursor()->relation()->lfile().num() == get_relation()->lfile().num())
|
1998-12-10 16:25:48 +00:00
|
|
|
|
{
|
|
|
|
|
expr = b->get_filter();
|
|
|
|
|
if (expr.find(rf) < 0)
|
|
|
|
|
{
|
|
|
|
|
if (expr.not_empty())
|
|
|
|
|
{
|
|
|
|
|
expr.insert("(", 0);
|
2004-04-26 13:37:16 +00:00
|
|
|
|
expr << ")&&(" << rf << ')';
|
1998-12-10 16:25:48 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
expr = rf;
|
|
|
|
|
b->set_filter(expr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @doc INTERNAL
|
|
|
|
|
|
1996-01-31 17:19:02 +00:00
|
|
|
|
// @mfunc Setta i limiti
|
|
|
|
|
void TRelation_application::set_limits(
|
|
|
|
|
byte what) // @parm tipo di limite da assegnare al record
|
|
|
|
|
|
|
|
|
|
// @comm I limiti possibili sono:
|
|
|
|
|
// @flag 0 | Nessuna operazione
|
|
|
|
|
// @flag 1 | Primo record
|
|
|
|
|
// @flag 2 | Ultimo record
|
|
|
|
|
// @flag 3 | Entrambi
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (has_filtered_cursor())
|
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
const TEdit_field& f = get_search_field();
|
|
|
|
|
if (f.browse() != NULL)
|
|
|
|
|
f.browse()->do_input(true);
|
|
|
|
|
|
|
|
|
|
TCursor& cur = get_filtered_cursor();
|
|
|
|
|
cur.setkey();
|
|
|
|
|
if (cur.items() > 0)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
if (what & 0x1)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
cur = 0;
|
|
|
|
|
_first = cur.file().recno();
|
|
|
|
|
}
|
|
|
|
|
if (what & 0x2)
|
|
|
|
|
{
|
|
|
|
|
cur = cur.items() - 1;
|
|
|
|
|
_last = cur.file().recno();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
|
else
|
|
|
|
|
_first = _last = -1;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
|
else
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
setkey();
|
|
|
|
|
if (!file().empty())
|
|
|
|
|
{
|
|
|
|
|
if (what & 0x1)
|
|
|
|
|
{
|
|
|
|
|
if (file().first() == NOERR)
|
|
|
|
|
_first = file().recno();
|
|
|
|
|
}
|
|
|
|
|
if (what & 0x2)
|
|
|
|
|
{
|
|
|
|
|
if (file().last() == NOERR)
|
|
|
|
|
_last = file().recno();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_first = _last = -1;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-01 13:31:49 +00:00
|
|
|
|
void TRelation_application::set_find_button()
|
|
|
|
|
{
|
2008-07-25 15:13:17 +00:00
|
|
|
|
// Ricalcola posizioni bootoni di navigazione con la vecchia toolbar
|
2008-11-13 12:31:11 +00:00
|
|
|
|
WINDOW bar = _mask->toolbar();
|
|
|
|
|
if (bar != NULL_WIN)
|
|
|
|
|
xvt_toolbar_realize(_mask->toolbar());
|
|
|
|
|
else // Non c'e' la nuova relapbar
|
2008-07-25 15:13:17 +00:00
|
|
|
|
{
|
|
|
|
|
int pos = _mask->id2pos(DLG_FINDREC);
|
|
|
|
|
if (pos >= 0 && _mask->id2pos(DLG_FIRSTREC) >= 0) //se e' un bottone pentapartito...
|
|
|
|
|
{
|
|
|
|
|
TButton_field& f_find = (TButton_field &)_mask->fld(pos);
|
|
|
|
|
RCT rct_base; f_find.get_rect(rct_base);
|
|
|
|
|
const int bwidth = (rct_base.right - rct_base.left);
|
|
|
|
|
const int bheight = (rct_base.bottom - rct_base.top);
|
|
|
|
|
if (bwidth > 3*bheight/2) // Controllo se ho gia' ridimensionato i bottoni in precedenza
|
2007-12-10 09:48:34 +00:00
|
|
|
|
{
|
2008-07-25 15:13:17 +00:00
|
|
|
|
int bx = bwidth / 3;
|
|
|
|
|
int by = bheight / 2;
|
|
|
|
|
|
|
|
|
|
RCT r = rct_base;
|
|
|
|
|
r.left += bx; r.right -= bx;
|
|
|
|
|
if (!NATIVE_CONTROLS)
|
|
|
|
|
{
|
|
|
|
|
r.left -= 2; r.right += 2;
|
|
|
|
|
}
|
|
|
|
|
f_find.set_rect(r); // Ridimensiona il bottone centrale di ricerca
|
|
|
|
|
|
|
|
|
|
if (!NATIVE_CONTROLS)
|
|
|
|
|
{
|
|
|
|
|
bx += 5; by += 3; // Aggiusta dimensioni bottoni sussidiari
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos = _mask->id2pos(DLG_FIRSTREC);
|
|
|
|
|
if (pos >= 0)
|
|
|
|
|
{
|
|
|
|
|
r = rct_base; r.top = r.bottom - by; r.right = r.left + bx;
|
|
|
|
|
_mask->fld(pos).set_rect(r);
|
|
|
|
|
}
|
|
|
|
|
pos = _mask->id2pos(DLG_PREVREC);
|
|
|
|
|
if (pos >= 0)
|
|
|
|
|
{
|
|
|
|
|
r = rct_base; r.bottom = r.top + by; r.right = r.left + bx;
|
|
|
|
|
_mask->fld(pos).set_rect(r);
|
|
|
|
|
}
|
|
|
|
|
pos = _mask->id2pos(DLG_NEXTREC);
|
|
|
|
|
if (pos >= 0)
|
|
|
|
|
{
|
|
|
|
|
r = rct_base; r.bottom = r.top + by; r.left = r.right - bx;
|
|
|
|
|
_mask->fld(pos).set_rect(r);
|
|
|
|
|
}
|
|
|
|
|
pos = _mask->id2pos(DLG_LASTREC);
|
|
|
|
|
if (pos >= 0)
|
|
|
|
|
{
|
|
|
|
|
r = rct_base; r.top = r.bottom - by; r.left = r.right - bx;
|
|
|
|
|
_mask->fld(pos).set_rect(r);
|
|
|
|
|
}
|
2007-12-10 09:48:34 +00:00
|
|
|
|
}
|
2008-07-25 15:13:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-01 13:31:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
bool TRelation_application::create()
|
|
|
|
|
{
|
1998-03-05 14:49:21 +00:00
|
|
|
|
bool ok = user_create();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
write_enable();
|
|
|
|
|
_mask = get_mask(MODE_QUERY);
|
2001-05-09 13:51:45 +00:00
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
filter();
|
1998-12-10 16:25:48 +00:00
|
|
|
|
set_key_filter();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
set_limits();
|
|
|
|
|
}
|
2003-07-01 11:03:08 +00:00
|
|
|
|
return ok ? TSkeleton_application::create() : ok;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::destroy()
|
|
|
|
|
{
|
|
|
|
|
user_destroy();
|
1998-02-24 10:37:28 +00:00
|
|
|
|
return TSkeleton_application::destroy();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TRelation_application::set_fixed()
|
|
|
|
|
{
|
1996-08-05 09:43:06 +00:00
|
|
|
|
TToken_string s(256, '=');
|
2009-10-21 15:06:27 +00:00
|
|
|
|
FOR_EACH_TOKEN(_fixed, f)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
s = f;
|
2009-10-21 15:06:27 +00:00
|
|
|
|
const short id = s.get_int(0);
|
|
|
|
|
if (id > 0 && _mask->id2pos(id) >= 0)
|
|
|
|
|
{
|
|
|
|
|
s = s.get();
|
|
|
|
|
if (s.not_empty())
|
|
|
|
|
_mask->set(id, s);
|
|
|
|
|
|
|
|
|
|
if (_lnflag < 2)
|
|
|
|
|
_mask->disable(id);
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TRelation_application::enable_query()
|
|
|
|
|
{
|
|
|
|
|
const bool query = _mask->query_mode();
|
|
|
|
|
const bool keyon = query || get_relation()->status() == _isreinsert;
|
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
|
for (int i = _mask->fields() - 1; i >= 0; i--)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
|
TMask_field& c = _mask->fld(i);
|
2007-11-20 11:32:14 +00:00
|
|
|
|
|
|
|
|
|
if (c.in_key(0) && c.enabled_default())
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
|
if (c.in_key(1))
|
|
|
|
|
c.enable(keyon);
|
1996-05-13 07:31:27 +00:00
|
|
|
|
if (c.is_edit())
|
|
|
|
|
{
|
|
|
|
|
TEdit_field& e = (TEdit_field&)c;
|
|
|
|
|
if (e.browse() != NULL)
|
|
|
|
|
e.enable_check(query);
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_fixed();
|
|
|
|
|
}
|
|
|
|
|
|
2003-05-22 15:08:27 +00:00
|
|
|
|
void TRelation_application::set_toolbar()
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
2003-05-22 15:08:27 +00:00
|
|
|
|
const int mode = _mask->mode();
|
|
|
|
|
const bool can_edit_some = user_can_write(NULL);
|
2011-02-21 14:15:09 +00:00
|
|
|
|
const bool can_nav = _lnflag == 0 && _curr_transaction != TRANSACTION_LINK;
|
2003-05-22 15:08:27 +00:00
|
|
|
|
|
|
|
|
|
int pos = _mask->id2pos(DLG_SAVEREC);
|
|
|
|
|
if (pos >= 0)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
2003-05-22 15:08:27 +00:00
|
|
|
|
bool enabsave=mode != MODE_QUERY;
|
|
|
|
|
if (enabsave)
|
|
|
|
|
enabsave = user_can_write(get_relation());
|
|
|
|
|
_mask->fld(pos).enable(enabsave);
|
|
|
|
|
}
|
|
|
|
|
pos = _mask->id2pos(DLG_DELREC);
|
|
|
|
|
if (pos >= 0)
|
|
|
|
|
{
|
2011-02-21 14:15:09 +00:00
|
|
|
|
bool enabdel = ((mode == MODE_QUERY && can_edit_some) || (mode == MODE_MOD)) && can_nav;
|
2003-05-22 15:08:27 +00:00
|
|
|
|
if (enabdel && mode == MODE_MOD)
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
2003-05-22 15:08:27 +00:00
|
|
|
|
TRelation& r = *get_relation();
|
|
|
|
|
const TRecnotype oldpos = r.lfile().recno();
|
|
|
|
|
enabdel = !protected_record(r);
|
|
|
|
|
if (r.lfile().recno() != oldpos)
|
|
|
|
|
r.lfile().readat(oldpos);
|
|
|
|
|
}
|
|
|
|
|
_mask->fld(pos).enable(enabdel);
|
|
|
|
|
}
|
1998-05-08 10:40:45 +00:00
|
|
|
|
|
2003-05-22 15:08:27 +00:00
|
|
|
|
pos = _mask->id2pos(DLG_FINDREC);
|
|
|
|
|
if (pos >= 0)
|
|
|
|
|
{
|
|
|
|
|
_mask->fld(pos).enable(_lnflag == 0);
|
|
|
|
|
|
|
|
|
|
const long recno = get_relation()->lfile().recno();
|
|
|
|
|
const bool enable_next_prev = _mask->edit_mode();
|
2003-07-25 14:53:55 +00:00
|
|
|
|
|
|
|
|
|
pos = _mask->id2pos(DLG_FIRSTREC);
|
|
|
|
|
if (pos >= 0)
|
2008-07-25 15:13:17 +00:00
|
|
|
|
_mask->fld(pos).enable(can_nav && (enable_next_prev ? _first != recno : _first > 0));
|
2003-07-25 14:53:55 +00:00
|
|
|
|
pos = _mask->id2pos(DLG_PREVREC);
|
2003-05-22 15:08:27 +00:00
|
|
|
|
if (pos >= 0)
|
2008-07-25 15:13:17 +00:00
|
|
|
|
_mask->fld(pos).enable(can_nav && enable_next_prev && _first > 0 && _first != recno);
|
2003-05-22 15:08:27 +00:00
|
|
|
|
pos = _mask->id2pos(DLG_NEXTREC);
|
|
|
|
|
if (pos >= 0)
|
2008-07-25 15:13:17 +00:00
|
|
|
|
_mask->fld(pos).enable(can_nav && enable_next_prev && _last > 0 && _last != recno);
|
2003-05-22 15:08:27 +00:00
|
|
|
|
pos = _mask->id2pos(DLG_LASTREC);
|
|
|
|
|
if (pos >= 0)
|
2008-07-25 15:13:17 +00:00
|
|
|
|
_mask->fld(pos).enable(can_nav && (enable_next_prev ? _last != recno : _last > 0));
|
2003-05-22 15:08:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos = _mask->id2pos(DLG_NEWREC);
|
|
|
|
|
if (pos >= 0)
|
|
|
|
|
{
|
|
|
|
|
bool enabins = (mode == MODE_QUERY || _lnflag == 0) && can_edit_some;
|
|
|
|
|
_mask->fld(pos).enable(enabins);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
2003-05-22 15:08:27 +00:00
|
|
|
|
|
|
|
|
|
set_find_button();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
enable_query();
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-24 14:54:49 +00:00
|
|
|
|
void TRelation_application::update_navigation_bar()
|
|
|
|
|
{
|
|
|
|
|
if (_mask->query_mode())
|
|
|
|
|
{
|
|
|
|
|
set_limits();
|
|
|
|
|
set_toolbar();
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
bool TRelation_application::save_and_new() const
|
2008-07-25 15:13:17 +00:00
|
|
|
|
{ return false; }
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
2009-09-23 12:04:06 +00:00
|
|
|
|
bool TRelation_application::save_and_quit() const
|
|
|
|
|
{
|
|
|
|
|
return (_autoins_caller.full() || _curr_transaction.not_empty()) && _curr_trans_mode != TM_REMAIN;
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
int TRelation_application::set_mode(int mode)
|
|
|
|
|
{
|
|
|
|
|
static int _mode = NO_MODE;
|
|
|
|
|
if (mode < NO_MODE) mode = _mode;
|
|
|
|
|
|
|
|
|
|
const int m = ((TMaskmode)mode == NO_MODE) ? (int) MODE_QUERY : mode;
|
|
|
|
|
_mask->set_mode(m);
|
|
|
|
|
|
2003-05-22 15:08:27 +00:00
|
|
|
|
set_toolbar();
|
|
|
|
|
_mode = mode;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
const char* t = "";
|
|
|
|
|
switch(mode)
|
|
|
|
|
{
|
|
|
|
|
case MODE_QUERY:
|
2004-05-07 10:25:51 +00:00
|
|
|
|
t = TR("Ricerca"); break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
case MODE_MOD:
|
2004-05-07 10:25:51 +00:00
|
|
|
|
t = TR("Modifica"); break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
case NO_MODE:
|
2004-05-07 10:25:51 +00:00
|
|
|
|
t = TR("Ricerca/Inserimento"); break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
case MODE_INS:
|
2004-05-07 10:25:51 +00:00
|
|
|
|
t = TR("Inserimento"); break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-23 15:57:29 +00:00
|
|
|
|
xvtil_statbar_set(t, TRUE);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
return _mode;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @doc INTERNAL
|
|
|
|
|
|
1996-01-31 17:19:02 +00:00
|
|
|
|
// @mfunc Permette di autonumerare un record
|
|
|
|
|
//
|
|
|
|
|
// @rdesc Ritorna se e' riuscito a creare una nuova autonumerazione:
|
|
|
|
|
//
|
1996-09-09 10:51:20 +00:00
|
|
|
|
// @flag TRUE | La chiave non e' vuota
|
|
|
|
|
// @flag FALSE | Non e' riuscito ad autonumerare il documento
|
1996-01-31 17:19:02 +00:00
|
|
|
|
bool TRelation_application::autonum(
|
1996-05-08 11:09:13 +00:00
|
|
|
|
TMask* m, // @parm Maschera a cui applicare l'autonumerazione
|
1996-09-10 10:43:17 +00:00
|
|
|
|
bool rec) // @parm Indica se registrare la chiave anche sul record corrente
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1998-05-04 07:57:56 +00:00
|
|
|
|
TToken_string k;
|
|
|
|
|
if (!get_next_key(k))
|
|
|
|
|
{
|
|
|
|
|
k = get_next_key();
|
1998-12-10 16:25:48 +00:00
|
|
|
|
/*
|
1998-05-13 15:12:27 +00:00
|
|
|
|
if (k.not_empty())
|
|
|
|
|
NFCHECK("La 'const char* get_next_key()' verra' sostituita dalla 'bool get_next_key(TToken_string&)'");
|
1998-12-10 16:25:48 +00:00
|
|
|
|
*/
|
1998-05-04 07:57:56 +00:00
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
if (!rec && !m->query_mode())
|
|
|
|
|
m->reset();
|
|
|
|
|
_renum_message = "";
|
|
|
|
|
|
|
|
|
|
for (const char* n = k.get(0); n && *n; n = k.get())
|
|
|
|
|
{
|
|
|
|
|
const short id = atoi(n);
|
2001-06-25 10:41:20 +00:00
|
|
|
|
CHECKD (id > 0 && m->id2pos(id) >= 0, "Identificatore di autonumerazione errato: ", id);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
const char* val = k.get();
|
|
|
|
|
TMask_field& f = m->field(id);
|
1996-09-09 10:51:20 +00:00
|
|
|
|
if (rec || f.empty())
|
|
|
|
|
f.set(val);
|
|
|
|
|
if (rec)
|
|
|
|
|
((TEditable_field&)f).autosave(*get_relation());
|
1995-11-07 11:38:23 +00:00
|
|
|
|
if (_renum_message.empty() || f.in_key(1))
|
1999-04-06 15:34:39 +00:00
|
|
|
|
_renum_message.format("L'elemento e' stato registrato con :\n %s = %s", (const char *) f.prompt(), (const char *) f.get());
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
return k.not_empty();
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @doc EXTERNAL
|
|
|
|
|
|
1996-01-31 17:19:02 +00:00
|
|
|
|
// @mfunc Entra in modo di ricerca
|
|
|
|
|
void TRelation_application::query_mode(
|
1996-05-08 11:09:13 +00:00
|
|
|
|
bool pre_ins) // @parm Indica in quale modo andare:
|
|
|
|
|
//
|
|
|
|
|
// @flag TRUE | Entra in modo MODE_QUERY_INSERT
|
|
|
|
|
// @flag FALSE | Entra in modo MODE_QUERY (default)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
TMask* old = _mask;
|
|
|
|
|
const bool was_open = old != NULL && old->is_open();
|
|
|
|
|
const bool changing = changing_mask(MODE_QUERY);
|
|
|
|
|
|
|
|
|
|
if (changing && was_open)
|
|
|
|
|
old->close_modal();
|
|
|
|
|
|
|
|
|
|
_mask = get_mask(MODE_QUERY);
|
|
|
|
|
if (changing)
|
|
|
|
|
{
|
|
|
|
|
if (was_open)
|
|
|
|
|
_mask->open_modal();
|
|
|
|
|
set_limits();
|
|
|
|
|
}
|
1996-07-19 15:13:35 +00:00
|
|
|
|
|
|
|
|
|
_mask->set_mode(pre_ins ? MODE_QUERYINS : MODE_QUERY);
|
2003-03-12 16:40:56 +00:00
|
|
|
|
_mask->reset();
|
|
|
|
|
_mask->disable_page(1); // Nasconde pagine inutili
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
if (pre_ins)
|
|
|
|
|
{
|
|
|
|
|
set_mode(NO_MODE);
|
|
|
|
|
init_query_insert_mode(*_mask);
|
2006-11-27 11:57:55 +00:00
|
|
|
|
enable_query();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
set_mode(MODE_QUERY);
|
|
|
|
|
init_query_mode(*_mask);
|
2007-11-20 11:32:14 +00:00
|
|
|
|
enable_query();
|
2003-05-22 15:08:27 +00:00
|
|
|
|
|
|
|
|
|
// Aggiorna bottoni di ricerca: utile soprattutto per ve0 che imposta CODNUM
|
|
|
|
|
if (has_filtered_cursor())
|
|
|
|
|
{
|
|
|
|
|
set_limits();
|
|
|
|
|
set_toolbar();
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TRelation_application::insert_mode()
|
1996-12-10 08:28:14 +00:00
|
|
|
|
{
|
2007-03-06 16:37:44 +00:00
|
|
|
|
bool try_auto = true;
|
1996-12-10 08:28:14 +00:00
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
if (_mask->query_mode())
|
2007-03-06 16:37:44 +00:00
|
|
|
|
try_auto = !test_key(1, FALSE);
|
1996-12-10 08:28:14 +00:00
|
|
|
|
|
|
|
|
|
if (try_auto && !autonum(_mask, FALSE))
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1996-12-10 08:28:14 +00:00
|
|
|
|
query_insert_mode();
|
|
|
|
|
return;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
1998-12-10 16:25:48 +00:00
|
|
|
|
|
|
|
|
|
TRelation* r = get_relation();
|
2009-01-22 12:00:23 +00:00
|
|
|
|
r->zero();
|
|
|
|
|
_mask->autosave(*r);
|
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
|
if (!user_can_write(r))
|
|
|
|
|
{
|
2009-01-22 12:00:23 +00:00
|
|
|
|
warning_box(FR("L'utente %s non puo' inserire in questo archivio"), (const char*)user());
|
1998-12-10 16:25:48 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
1996-12-10 08:28:14 +00:00
|
|
|
|
const bool changing = changing_mask(MODE_INS);
|
|
|
|
|
TFilename workname; workname.temp("msk");
|
|
|
|
|
if (changing)
|
|
|
|
|
{
|
|
|
|
|
_mask->set_workfile(workname);
|
|
|
|
|
_mask->save();
|
|
|
|
|
_mask->close_modal();
|
|
|
|
|
}
|
|
|
|
|
_mask = get_mask(MODE_INS);
|
|
|
|
|
if (changing)
|
|
|
|
|
{
|
|
|
|
|
_mask->reset();
|
|
|
|
|
_mask->set_workfile(workname);
|
|
|
|
|
_mask->load();
|
2009-01-28 08:59:32 +00:00
|
|
|
|
xvt_fsys_remove_file(workname);
|
1996-12-10 08:28:14 +00:00
|
|
|
|
_mask->open_modal();
|
|
|
|
|
}
|
2003-03-11 09:17:38 +00:00
|
|
|
|
else
|
|
|
|
|
_mask->enable_page(1);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
1996-12-10 08:28:14 +00:00
|
|
|
|
set_mode(MODE_INS);
|
1998-12-10 16:25:48 +00:00
|
|
|
|
r->zero(); // Azzera tutta la relazione!
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
2008-11-14 00:40:30 +00:00
|
|
|
|
_mask->load_defaults();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
init_insert_mode(*_mask);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// ....possibilmente spostare questa chiamata .....
|
2009-09-23 12:04:06 +00:00
|
|
|
|
if (is_transaction() && _curr_transaction == TRANSACTION_INSERT)
|
2002-12-18 10:56:10 +00:00
|
|
|
|
ini2insert_mask();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::modify_mode()
|
|
|
|
|
{
|
1998-12-10 16:25:48 +00:00
|
|
|
|
TRelation* rel = get_relation();
|
|
|
|
|
if (!user_can_read(rel))
|
2003-08-08 12:54:27 +00:00
|
|
|
|
{
|
|
|
|
|
warning_box(TR("I dati non sono accessibili per l'utente %s"), (const char*)user());
|
|
|
|
|
query_mode();
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
1998-12-10 16:25:48 +00:00
|
|
|
|
|
|
|
|
|
const TReclock block = user_can_write(rel) ? _testandlock : _nolock;
|
|
|
|
|
int err = rel->read(_isequal, block);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
if (err != NOERR)
|
|
|
|
|
{
|
|
|
|
|
if (err == _islocked)
|
2007-01-25 15:42:56 +00:00
|
|
|
|
message_box(TR("I dati sono gia' usati da un altro programma"));
|
1995-11-07 11:38:23 +00:00
|
|
|
|
else
|
2007-01-25 15:42:56 +00:00
|
|
|
|
error_box(FR("Impossibile leggere i dati: errore %d"), err);
|
2011-05-16 14:27:49 +00:00
|
|
|
|
if (!is_transaction())
|
|
|
|
|
query_mode();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bool changing = changing_mask(MODE_MOD);
|
|
|
|
|
if (changing)
|
|
|
|
|
_mask->close_modal();
|
|
|
|
|
|
|
|
|
|
_mask = get_mask(MODE_MOD);
|
|
|
|
|
|
|
|
|
|
if (changing)
|
|
|
|
|
_mask->open_modal();
|
2003-03-11 09:17:38 +00:00
|
|
|
|
else
|
|
|
|
|
_mask->enable_page(1);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
set_mode(MODE_MOD);
|
2003-03-11 09:17:38 +00:00
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
err = read(*_mask);
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
{
|
|
|
|
|
query_mode();
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
|
rel->save_status();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
init_modify_mode(*_mask);
|
1998-05-08 10:40:45 +00:00
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// ....possibilmente spostare questa chiamata .....
|
2003-08-08 12:54:27 +00:00
|
|
|
|
// Forse deve essere fatta prima della init_modify_mode()!
|
1998-05-08 10:40:45 +00:00
|
|
|
|
if (_curr_transaction == TRANSACTION_MODIFY)
|
|
|
|
|
ini2insert_mask();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
|
TEdit_field& TRelation_application::get_search_field() const
|
|
|
|
|
{
|
|
|
|
|
short id = _search_id;
|
|
|
|
|
|
2003-05-21 14:26:29 +00:00
|
|
|
|
if (id <= 0 || !_mask->field(id).shown())
|
1996-05-08 11:09:13 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
for (int i = _mask->fields()-1; i >= 0; i--)
|
1996-05-08 11:09:13 +00:00
|
|
|
|
{
|
|
|
|
|
const TMask_field& f = _mask->fld(i);
|
2003-05-21 14:26:29 +00:00
|
|
|
|
if (f.is_edit() && f.in_key(1) && f.shown())
|
1996-05-08 11:09:13 +00:00
|
|
|
|
{
|
|
|
|
|
id = f.dlg();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
1996-05-08 11:09:13 +00:00
|
|
|
|
|
|
|
|
|
return _mask->efield(id);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::search_mode()
|
|
|
|
|
{
|
|
|
|
|
if (_mask->mode() != MODE_QUERY)
|
|
|
|
|
query_mode();
|
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
|
TEdit_field* prima = &get_search_field();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
while (prima)
|
|
|
|
|
{
|
|
|
|
|
if (prima->on_key(K_F9))
|
|
|
|
|
{
|
|
|
|
|
if (find(1))
|
|
|
|
|
return modify_mode();
|
2001-07-24 13:28:55 +00:00
|
|
|
|
else
|
|
|
|
|
break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TMask_field* dopo = &_mask->focus_field();
|
2001-07-24 13:28:55 +00:00
|
|
|
|
if (dopo != prima && dopo->is_edit() && dopo->in_key(0))
|
|
|
|
|
prima = (TEdit_field*)dopo;
|
|
|
|
|
else
|
|
|
|
|
break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
2009-05-22 14:15:33 +00:00
|
|
|
|
return false;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-26 15:58:05 +00:00
|
|
|
|
HIDDEN bool delete_handler(TMask_field& f, KEY k)
|
|
|
|
|
{
|
|
|
|
|
if (k == K_TAB && f.focusdirty() && !f.empty())
|
|
|
|
|
{
|
|
|
|
|
TMask& m = f.mask();
|
|
|
|
|
const bool finale = *f.prompt() == 'A';
|
|
|
|
|
const int pos = m.id2pos(f.dlg());
|
|
|
|
|
if (pos >= 3)
|
|
|
|
|
{
|
|
|
|
|
const TMask_field& e = m.fld(pos - 3);
|
|
|
|
|
if (e.is_edit() && e.get().blank())
|
|
|
|
|
{
|
|
|
|
|
const short id = e.dlg() - (finale ? 200 : 100);
|
|
|
|
|
const TRelation_application& app = (TRelation_application&)main_app();
|
|
|
|
|
const TMask_field& orig = app.curr_mask().field(id);
|
|
|
|
|
bool req = orig.required();
|
|
|
|
|
if (!req && orig.is_edit())
|
|
|
|
|
{
|
|
|
|
|
const TEdit_field& e = (TEdit_field&)orig;
|
|
|
|
|
req = e.validate_func() == 12;
|
|
|
|
|
}
|
|
|
|
|
if (req)
|
|
|
|
|
{
|
2007-01-25 15:42:56 +00:00
|
|
|
|
TString str; str << (finale ? TR("A ") : TR("Da ")) << orig.prompt();
|
|
|
|
|
return f.error_box(FR("Specificare anche il valore %s"), (const char*)str);
|
1999-04-26 15:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (finale && !f.get().blank())
|
|
|
|
|
{
|
|
|
|
|
const TMask_field& p = m.fld(pos - 1);
|
|
|
|
|
TString80 prec = p.get();
|
|
|
|
|
TString80 curr = f.get();
|
|
|
|
|
bool ok;
|
|
|
|
|
switch (p.class_id())
|
|
|
|
|
{
|
|
|
|
|
case CLASS_REAL_FIELD: ok = real(prec) <= real(curr); break;
|
|
|
|
|
case CLASS_DATE_FIELD: ok = TDate(prec) <= TDate(curr); break;
|
|
|
|
|
default : ok = prec <= curr; break;
|
|
|
|
|
}
|
|
|
|
|
if (!ok)
|
2007-01-25 15:42:56 +00:00
|
|
|
|
return f.error_box(FR("Inserire un valore non inferiore a '%s'"), (const char*)prec);
|
1999-04-26 15:58:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-21 09:39:46 +00:00
|
|
|
|
int TRelation_application::delete_mode()
|
|
|
|
|
{
|
|
|
|
|
TEdit_field& fld = get_search_field();
|
1997-08-28 15:57:31 +00:00
|
|
|
|
TBrowse* brw = fld.browse();
|
1998-12-16 07:43:32 +00:00
|
|
|
|
if (brw)
|
1997-05-21 09:39:46 +00:00
|
|
|
|
{
|
1998-12-16 07:43:32 +00:00
|
|
|
|
brw->do_input(TRUE);
|
|
|
|
|
TCursor& cur = *brw->cursor();
|
|
|
|
|
|
1997-05-21 09:39:46 +00:00
|
|
|
|
TToken_string head(brw->head());
|
|
|
|
|
head.insert("@1|", 0);
|
|
|
|
|
TToken_string items(brw->items());
|
|
|
|
|
items.insert(" |", 0);
|
1998-12-16 07:43:32 +00:00
|
|
|
|
|
|
|
|
|
int tab1 = 0, tab2 = 0, y = 0;
|
1999-04-02 11:03:12 +00:00
|
|
|
|
// Nuovo modo basato sugli input
|
|
|
|
|
TToken_string inplist = brw->get_input_fields();
|
|
|
|
|
if (inplist.not_empty())
|
1998-12-16 07:43:32 +00:00
|
|
|
|
{
|
1999-04-02 11:03:12 +00:00
|
|
|
|
FOR_EACH_TOKEN(inplist, tok)
|
|
|
|
|
{
|
|
|
|
|
if (*tok != '"' && strchr(tok, '@') == NULL)
|
1998-12-16 07:43:32 +00:00
|
|
|
|
{
|
1999-04-02 11:03:12 +00:00
|
|
|
|
TMask_field& e = _mask->field(short(atoi(tok)));
|
|
|
|
|
if (e.active())
|
1998-12-16 07:43:32 +00:00
|
|
|
|
{
|
1999-04-02 11:03:12 +00:00
|
|
|
|
const int len = strlen(e.prompt());
|
1998-12-16 07:43:32 +00:00
|
|
|
|
if (len > tab1) tab1 = len;
|
1999-04-02 11:03:12 +00:00
|
|
|
|
const int size = e.size();
|
1998-12-16 07:43:32 +00:00
|
|
|
|
if (size > tab2) tab2 = size;
|
|
|
|
|
y++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tab1 += 5;
|
|
|
|
|
tab2 += tab1+2;
|
|
|
|
|
|
1998-12-22 10:40:23 +00:00
|
|
|
|
cur = 0L;
|
2008-11-13 12:31:11 +00:00
|
|
|
|
TCursor_sheet sht(&cur, items, TR("Eliminazione"), head, 0x4, y);
|
1998-12-16 07:43:32 +00:00
|
|
|
|
|
|
|
|
|
y = -1; // Posizione del campo precedente
|
|
|
|
|
TString prompt; // Prompt del campo corrente
|
1999-04-26 15:58:05 +00:00
|
|
|
|
const short delta = 100;
|
1999-04-02 11:03:12 +00:00
|
|
|
|
|
|
|
|
|
FOR_EACH_TOKEN(inplist, tok)
|
1998-12-16 07:43:32 +00:00
|
|
|
|
{
|
1999-04-02 11:03:12 +00:00
|
|
|
|
if (*tok != '"' && strchr(tok, '@') == NULL)
|
1998-12-16 07:43:32 +00:00
|
|
|
|
{
|
1999-04-26 15:58:05 +00:00
|
|
|
|
TMask_field& e = _mask->field(short(atoi(tok)));
|
1999-04-02 11:03:12 +00:00
|
|
|
|
if (!e.active())
|
|
|
|
|
continue;
|
1999-04-26 15:58:05 +00:00
|
|
|
|
|
|
|
|
|
const short id = e.dlg()+delta;
|
1998-12-16 07:43:32 +00:00
|
|
|
|
prompt = "Da "; prompt << e.prompt();
|
|
|
|
|
sht.add_static(DLG_NULL, 0, prompt, 1, ++y);
|
|
|
|
|
TString16 flags;
|
|
|
|
|
if (e.automagic()) flags << 'A';
|
|
|
|
|
if (e.roman()) flags << 'M';
|
|
|
|
|
if (e.right_justified()) flags << 'R';
|
|
|
|
|
if (e.uppercase()) flags << 'U';
|
|
|
|
|
if (e.zerofilled()) flags << 'Z';
|
|
|
|
|
switch (e.class_id())
|
|
|
|
|
{
|
|
|
|
|
case CLASS_DATE_FIELD:
|
1999-04-26 15:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
TDate_field& d1 = sht.add_date(id, 0, "", tab1, y, flags);
|
|
|
|
|
TDate_field& d2 = sht.add_date(id+delta, 0, "A ", tab2, y, flags);
|
|
|
|
|
d1.set_handler(delete_handler);
|
|
|
|
|
d2.set_handler(delete_handler);
|
|
|
|
|
}
|
1998-12-16 07:43:32 +00:00
|
|
|
|
break;
|
|
|
|
|
case CLASS_REAL_FIELD:
|
1999-04-26 15:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
TReal_field& r1 = sht.add_number(id, 0, "", tab1, y, e.size(), flags);
|
|
|
|
|
TReal_field& r2 = sht.add_number(id+delta, 0, "A ", tab2, y, e.size(), flags);
|
|
|
|
|
r1.set_handler(delete_handler);
|
|
|
|
|
r2.set_handler(delete_handler);
|
|
|
|
|
}
|
1998-12-16 07:43:32 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-04-26 15:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
TEdit_field& e1 = sht.add_string(id, 0, "", tab1, y, e.size(), flags);
|
|
|
|
|
TEdit_field& e2 = sht.add_string(id+delta, 0, "A ", tab2, y, e.size(), flags);
|
|
|
|
|
e1.set_handler(delete_handler);
|
|
|
|
|
e2.set_handler(delete_handler);
|
|
|
|
|
}
|
1998-12-16 07:43:32 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
1998-12-22 10:40:23 +00:00
|
|
|
|
if (y == 0)
|
|
|
|
|
sht.first_focus(id);
|
1998-12-16 07:43:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-02 11:03:12 +00:00
|
|
|
|
sht.open_modal();
|
1999-01-19 09:15:17 +00:00
|
|
|
|
|
|
|
|
|
KEY tasto;
|
|
|
|
|
bool keep_running = TRUE;
|
|
|
|
|
while (keep_running)
|
1998-12-16 07:43:32 +00:00
|
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
|
tasto = sht.run();
|
|
|
|
|
if (tasto == K_ENTER)
|
|
|
|
|
{
|
1999-04-26 15:58:05 +00:00
|
|
|
|
TRectype rec_from(cur.curr()), rec_to(cur.curr());
|
|
|
|
|
rec_from.zero(); rec_to.zero();
|
1999-04-02 11:03:12 +00:00
|
|
|
|
TToken_string fldlist = brw->get_input_field_names();
|
|
|
|
|
TString80 str;
|
|
|
|
|
int fi = 0;
|
|
|
|
|
for (TString80 tok = inplist.get(fi); tok.not_empty(); tok = inplist.get(), fi++)
|
|
|
|
|
{
|
|
|
|
|
const TString16 fn = fldlist.get(fi);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
const TFieldref fr(fn, 0);
|
1999-04-02 11:03:12 +00:00
|
|
|
|
if (*tok == '"')
|
|
|
|
|
{
|
|
|
|
|
str = tok;
|
|
|
|
|
str.ltrim(1); str.rtrim(1);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
fr.write(str, rec_from);
|
|
|
|
|
fr.write(str, rec_to);
|
1999-01-19 09:15:17 +00:00
|
|
|
|
}
|
1999-04-02 11:03:12 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const short id = short(atoi(tok));
|
1999-04-26 15:58:05 +00:00
|
|
|
|
if (sht.id2pos(id+delta) >= 0)
|
1999-04-02 11:03:12 +00:00
|
|
|
|
{
|
1999-04-26 15:58:05 +00:00
|
|
|
|
str = sht.get(id+delta);
|
1999-04-02 11:03:12 +00:00
|
|
|
|
if (str.not_empty())
|
2000-10-03 13:45:12 +00:00
|
|
|
|
fr.write(str, rec_from);
|
1999-04-26 15:58:05 +00:00
|
|
|
|
str = sht.get(id+2*delta);
|
1999-04-02 11:03:12 +00:00
|
|
|
|
if (str.not_empty())
|
2000-10-03 13:45:12 +00:00
|
|
|
|
fr.write(str, rec_to);
|
1999-04-02 11:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
str = _mask->get(id);
|
2000-10-03 13:45:12 +00:00
|
|
|
|
fr.write(str, rec_from);
|
|
|
|
|
fr.write(str, rec_to);
|
1999-04-02 11:03:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-06-18 15:35:05 +00:00
|
|
|
|
}
|
1999-04-02 11:03:12 +00:00
|
|
|
|
|
1999-06-18 15:35:05 +00:00
|
|
|
|
if (rec_from.empty() && rec_to.empty())
|
|
|
|
|
{
|
|
|
|
|
sht.check(-1);
|
1998-12-16 07:43:32 +00:00
|
|
|
|
}
|
1999-06-18 15:35:05 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const long totit = cur.items();
|
|
|
|
|
cur.freeze(TRUE);
|
|
|
|
|
cur.curr() = rec_from;
|
|
|
|
|
cur.read();
|
|
|
|
|
while (cur.pos() < totit && cur.curr() <= rec_to)
|
|
|
|
|
{
|
|
|
|
|
sht.check(cur.pos());
|
|
|
|
|
++cur;
|
|
|
|
|
}
|
|
|
|
|
cur.freeze(FALSE);
|
|
|
|
|
}
|
1999-01-19 09:15:17 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1998-12-16 07:43:32 +00:00
|
|
|
|
{
|
1999-01-19 09:15:17 +00:00
|
|
|
|
keep_running = FALSE;
|
|
|
|
|
if (tasto == K_DEL && sht.checked() == 0)
|
|
|
|
|
{
|
2007-01-25 15:42:56 +00:00
|
|
|
|
error_box(TR("Non e' stato selezionato nessun elemento"));
|
1999-01-19 09:15:17 +00:00
|
|
|
|
sht.select(0);
|
|
|
|
|
keep_running = TRUE;
|
|
|
|
|
}
|
1998-12-16 07:43:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1999-04-02 11:03:12 +00:00
|
|
|
|
sht.close_modal();
|
1998-12-22 10:40:23 +00:00
|
|
|
|
|
1998-12-16 07:43:32 +00:00
|
|
|
|
if (tasto == K_DEL)
|
1997-05-21 09:39:46 +00:00
|
|
|
|
{
|
|
|
|
|
long deleting = sht.checked();
|
1999-01-19 09:15:17 +00:00
|
|
|
|
TString msg;
|
2003-05-22 10:56:04 +00:00
|
|
|
|
msg.format(FR("Confermare l'eliminazione di %d elementi"), deleting);
|
1999-01-19 09:15:17 +00:00
|
|
|
|
bool can_delete = yesno_box(msg);
|
|
|
|
|
if (can_delete && deleting > 100)
|
1997-05-21 09:39:46 +00:00
|
|
|
|
{
|
2003-05-22 10:56:04 +00:00
|
|
|
|
msg.insert(TR("ATTENZIONE: "), 0);
|
1999-01-19 09:15:17 +00:00
|
|
|
|
can_delete = yesno_box(msg);
|
|
|
|
|
}
|
|
|
|
|
if (can_delete)
|
|
|
|
|
{
|
|
|
|
|
TWait_cursor hourglass;
|
1999-04-26 15:58:05 +00:00
|
|
|
|
long skipped = 0; // Record non cancellati perche' protetti
|
1999-01-19 09:15:17 +00:00
|
|
|
|
cur.freeze(TRUE); // Congelo il cursore altrimenti si riaggiorna troppo
|
1999-04-26 15:58:05 +00:00
|
|
|
|
for (long pos = sht.items()-1; deleting > 0; pos--)
|
1999-01-19 09:15:17 +00:00
|
|
|
|
{
|
|
|
|
|
if (sht.checked(pos))
|
|
|
|
|
{
|
|
|
|
|
cur = pos;
|
|
|
|
|
brw->do_output();
|
|
|
|
|
bool can_delete = FALSE;
|
|
|
|
|
if (find(1))
|
1997-05-21 09:39:46 +00:00
|
|
|
|
{
|
1999-02-02 08:43:43 +00:00
|
|
|
|
TRelation& r = *get_relation();
|
1999-01-19 09:15:17 +00:00
|
|
|
|
_autodelete = 0x3;
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (!protected_record(r))
|
1997-08-18 14:11:37 +00:00
|
|
|
|
{
|
1998-12-22 10:40:23 +00:00
|
|
|
|
if (modify_mode())
|
1999-02-02 08:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
r.restore_status();
|
1999-01-19 09:15:17 +00:00
|
|
|
|
can_delete = remove();
|
1999-02-02 08:43:43 +00:00
|
|
|
|
}
|
|
|
|
|
query_mode();
|
1999-04-26 15:58:05 +00:00
|
|
|
|
}
|
1999-01-19 09:15:17 +00:00
|
|
|
|
_autodelete = FALSE;
|
1997-05-21 09:39:46 +00:00
|
|
|
|
}
|
1999-01-19 09:15:17 +00:00
|
|
|
|
if (!can_delete)
|
|
|
|
|
skipped++;
|
|
|
|
|
deleting--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cur.freeze(FALSE);
|
2003-05-22 10:56:04 +00:00
|
|
|
|
set_limits(); // Riaggiorno il numero del primo/ultimo record
|
|
|
|
|
|
1999-01-19 09:15:17 +00:00
|
|
|
|
if (skipped > 0)
|
|
|
|
|
{
|
2003-05-22 10:56:04 +00:00
|
|
|
|
warning_box(FR("%ld elementi non sono stati cancellati in quanto protetti."), skipped);
|
1999-04-26 15:58:05 +00:00
|
|
|
|
query_mode();
|
1999-01-19 09:15:17 +00:00
|
|
|
|
}
|
1997-05-21 09:39:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (search_mode())
|
|
|
|
|
_autodelete = TRUE;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @doc INTERNAL
|
|
|
|
|
|
1996-01-31 17:19:02 +00:00
|
|
|
|
// @mfunc Controlla se una chiave e' completa ed esiste su file
|
|
|
|
|
//
|
|
|
|
|
// @rdesc Ritorna se la chave esiste sul file
|
|
|
|
|
bool TRelation_application::test_key(
|
1998-03-05 13:54:51 +00:00
|
|
|
|
word k, // @parm Chiave da ricercare
|
1996-05-08 11:09:13 +00:00
|
|
|
|
bool err) // @parm Indica se visualizzare eventuali errori occorsi
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
bool onereq = FALSE, onefill = FALSE;
|
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
|
for (TEditable_field* e = _mask->get_key_field(k, TRUE);
|
|
|
|
|
e != NULL;
|
|
|
|
|
e = _mask->get_key_field(k, FALSE))
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1997-08-14 09:20:01 +00:00
|
|
|
|
if (e->required() && e->shown())
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
onereq = TRUE;
|
1996-07-19 15:13:35 +00:00
|
|
|
|
if (e->empty())
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (err)
|
1997-07-02 12:54:03 +00:00
|
|
|
|
{
|
|
|
|
|
TString msg(80);
|
2003-05-22 10:56:04 +00:00
|
|
|
|
msg = TR("Manca un valore indispensabile per la ricerca.");
|
1997-07-02 12:54:03 +00:00
|
|
|
|
#ifdef DBG
|
|
|
|
|
msg << "\nChiave " << int(k) << " - Campo " << e->dlg();
|
|
|
|
|
const TFieldref* fr = e->field();
|
|
|
|
|
if (fr != NULL)
|
|
|
|
|
{
|
|
|
|
|
msg << " - " << fr->name();
|
|
|
|
|
if (fr->to() > 0)
|
|
|
|
|
msg << '[' << fr->from() << ',' << fr->to() << ']';
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
error_box(msg);
|
1996-07-19 15:13:35 +00:00
|
|
|
|
_mask->first_focus(-e->dlg());
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
/* if (k == 1 && !onereq && !onefill && c.get().not_empty()) */
|
1996-05-08 11:09:13 +00:00
|
|
|
|
if (!onereq && !onefill && e->is_edit() && !e->empty())
|
1995-11-07 11:38:23 +00:00
|
|
|
|
onefill = TRUE;
|
|
|
|
|
}
|
|
|
|
|
if (k == 1 && !onereq && !onefill)
|
|
|
|
|
{
|
|
|
|
|
if (err)
|
2003-05-22 10:56:04 +00:00
|
|
|
|
error_box(TR("Manca un valore indispensabile per la ricerca"));
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
return onefill || onereq;
|
|
|
|
|
}
|
|
|
|
|
|
1998-03-05 13:54:51 +00:00
|
|
|
|
bool TRelation_application::find(word k)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
if (k == 0)
|
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
|
for (k = 1; k <= MAX_KEYS && !test_key(k, FALSE); k++);
|
|
|
|
|
if (k > MAX_KEYS)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return test_key(1, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
file().setkey(k);
|
|
|
|
|
file().zero();
|
1996-05-08 11:09:13 +00:00
|
|
|
|
for (TEditable_field* e = _mask->get_key_field(k, TRUE); e; e = _mask->get_key_field(k, FALSE))
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
|
if (e->shown()) // Ignora campi invisibili
|
|
|
|
|
e->autosave(*get_relation());
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int err = file().read(_isequal);
|
|
|
|
|
return err == NOERR;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-07 15:50:52 +00:00
|
|
|
|
void TRelation_application::edit_cancel()
|
|
|
|
|
{
|
|
|
|
|
if (_mask->mode() == MODE_MOD)
|
|
|
|
|
{
|
|
|
|
|
TRelation* rel = get_relation();
|
|
|
|
|
rel->restore_status();
|
|
|
|
|
rel->lfile().reread(_unlock); // Unlock main file
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
bool TRelation_application::save(bool check_dirty)
|
|
|
|
|
{
|
|
|
|
|
static bool was_dirty = FALSE;
|
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
|
int pos = _mask->id2pos(DLG_SAVEREC);
|
2003-05-13 15:12:54 +00:00
|
|
|
|
if (pos < 0 || !_mask->fld(pos).active())
|
2009-01-07 15:50:52 +00:00
|
|
|
|
{
|
|
|
|
|
edit_cancel();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
int err = NOERR;
|
|
|
|
|
const int mode = _mask->mode();
|
|
|
|
|
if (check_dirty)
|
|
|
|
|
{
|
2006-01-09 01:15:53 +00:00
|
|
|
|
const short dirty = _mask->dirty();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
if (mode == MODE_QUERY)
|
|
|
|
|
{
|
2003-12-03 09:41:16 +00:00
|
|
|
|
const bool cont = !dirty || yesno_box(TR("Annullare i dati inseriti?"));
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return cont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!dirty && !was_dirty)
|
|
|
|
|
{
|
2009-01-07 15:50:52 +00:00
|
|
|
|
edit_cancel();
|
|
|
|
|
return true;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const KEY last = _mask->last_key();
|
|
|
|
|
const bool annulla = last == K_ESC || last == K_QUIT || last == K_F9;
|
2003-03-27 12:14:51 +00:00
|
|
|
|
const bool errore = dirty && _mask->field(dirty).dirty() > 1;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
KEY k;
|
|
|
|
|
if (errore)
|
|
|
|
|
{
|
|
|
|
|
if (annulla)
|
|
|
|
|
{
|
2003-06-06 08:57:05 +00:00
|
|
|
|
TString w;
|
|
|
|
|
TMask_field& df = _mask->field(dirty);
|
|
|
|
|
if (df.is_edit())
|
|
|
|
|
w = ((TEdit_field&)df).get_warning();
|
|
|
|
|
if (w.blank())
|
|
|
|
|
{
|
|
|
|
|
w = df.prompt();
|
|
|
|
|
if (!w.blank())
|
|
|
|
|
{
|
|
|
|
|
w.trim();
|
|
|
|
|
w << ' ' << TR("inconsistente.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (w.blank())
|
|
|
|
|
w = TR("Campo inconsistente.");
|
|
|
|
|
w << '\n';
|
1995-11-07 11:38:23 +00:00
|
|
|
|
switch (last)
|
|
|
|
|
{
|
|
|
|
|
case K_ESC:
|
2003-06-06 08:57:05 +00:00
|
|
|
|
w << TR("Si desidera annullare?"); break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
case K_QUIT:
|
2003-06-06 08:57:05 +00:00
|
|
|
|
w << TR("Si desidera uscire?"); break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
default:
|
2003-06-06 08:57:05 +00:00
|
|
|
|
w << TR("Si desidera continuare?"); break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
k = yesno_box(w) ? K_NO : K_ESC;
|
|
|
|
|
if (k == K_ESC)
|
|
|
|
|
_mask->first_focus(-dirty);
|
|
|
|
|
}
|
|
|
|
|
else k = K_ESC;
|
|
|
|
|
}
|
|
|
|
|
else
|
2007-01-25 15:42:56 +00:00
|
|
|
|
k = yesnocancel_box(TR("Si desidera registrare?"));
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
if (k == K_ESC || k == K_NO)
|
2009-01-07 15:50:52 +00:00
|
|
|
|
{
|
|
|
|
|
edit_cancel();
|
|
|
|
|
was_dirty = false;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return k == K_NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (annulla)
|
|
|
|
|
{
|
2003-12-19 08:15:17 +00:00
|
|
|
|
TMask_field& ff = _mask->focus_field();
|
|
|
|
|
if (ff.focusdirty() && ff.is_edit()) // I need simulate tab on the current field!
|
|
|
|
|
{
|
|
|
|
|
if (!ff.on_key(K_TAB))
|
|
|
|
|
{
|
|
|
|
|
_mask->first_focus(-ff.dlg());
|
|
|
|
|
was_dirty = TRUE;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
if (!_mask->check_fields()) // Exit with ESC didn't check values
|
|
|
|
|
{
|
2003-12-19 08:15:17 +00:00
|
|
|
|
// check_fields sets the focus on the blocking field
|
1995-11-07 11:38:23 +00:00
|
|
|
|
_mask->first_focus(-_mask->focus_field().dlg());
|
|
|
|
|
was_dirty = TRUE;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
was_dirty = FALSE;
|
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
|
TWait_cursor hourglass;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
if (mode == MODE_INS)
|
|
|
|
|
{
|
|
|
|
|
bool changed = TRUE;
|
|
|
|
|
bool changed_key = FALSE;
|
|
|
|
|
|
|
|
|
|
while (changed)
|
|
|
|
|
{
|
|
|
|
|
err = write(*_mask);
|
|
|
|
|
if (err == _isreinsert)
|
|
|
|
|
{
|
|
|
|
|
changed = autonum(_mask, TRUE);
|
|
|
|
|
if (!changed)
|
|
|
|
|
{
|
|
|
|
|
_mask->disable_starting_check();
|
|
|
|
|
enable_query(); // Abilita chiave 1 per rinumerazione manuale
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
changed_key = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
changed = FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
if (changed_key)
|
|
|
|
|
message_box(_renum_message);
|
|
|
|
|
get_relation()->save_status();
|
|
|
|
|
set_limits();
|
|
|
|
|
get_relation()->restore_status();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
get_relation()->restore_status();
|
|
|
|
|
err = rewrite(*_mask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(err)
|
|
|
|
|
{
|
|
|
|
|
case NOERR:
|
|
|
|
|
_recins = get_relation()->lfile().recno();
|
1998-12-10 16:25:48 +00:00
|
|
|
|
mask2mail(*_mask);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
break;
|
|
|
|
|
case _isreinsert:
|
2003-05-13 15:12:54 +00:00
|
|
|
|
warning_box(TR("Esiste gia' un elemento con la stessa chiave"));
|
1995-11-07 11:38:23 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2003-05-13 15:12:54 +00:00
|
|
|
|
error_box(FR("Impossibile registrare i dati: errore %d"), err);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return err == NOERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int TRelation_application::read(TMask& m)
|
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
|
const TRelation &r = *get_relation();
|
2007-03-06 16:37:44 +00:00
|
|
|
|
|
|
|
|
|
/* Metodo VECCHIO!
|
1997-05-23 14:08:53 +00:00
|
|
|
|
const int max = m.fields();
|
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
|
{
|
1997-06-16 12:52:23 +00:00
|
|
|
|
if (m.fld(i).is_sheet())
|
|
|
|
|
{
|
|
|
|
|
TSheet_field& f = (TSheet_field&)m.fld(i);
|
|
|
|
|
if (f.record() && !f.external_record())
|
|
|
|
|
f.record()->read(*f.putkey(r));
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-06 16:37:44 +00:00
|
|
|
|
*/
|
|
|
|
|
if (m.sheets() > 0) // Metodo Salvatempo
|
|
|
|
|
{
|
|
|
|
|
FOR_EACH_MASK_SHEET(m, i, s)
|
|
|
|
|
{
|
|
|
|
|
if (s->record() && !s->external_record())
|
|
|
|
|
s->record()->read(*s->putkey(r));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
m.autoload(r);
|
|
|
|
|
return NOERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TRelation_application::write(const TMask& m)
|
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
|
TRelation &r = *get_relation();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
m.autosave(r);
|
2008-08-22 09:04:05 +00:00
|
|
|
|
r.curr().set_creation_info();
|
2001-07-24 13:28:55 +00:00
|
|
|
|
|
1997-06-16 12:52:23 +00:00
|
|
|
|
// write relation and all independent sheets
|
2001-07-24 13:28:55 +00:00
|
|
|
|
int err=r.write();
|
2008-08-22 09:04:05 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1997-05-23 14:08:53 +00:00
|
|
|
|
const int max = m.fields();
|
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
|
{
|
1998-07-20 13:15:59 +00:00
|
|
|
|
if (m.fld(i).is_sheet())
|
|
|
|
|
{
|
1997-05-23 14:08:53 +00:00
|
|
|
|
TSheet_field& f = (TSheet_field& )m.fld(i);
|
|
|
|
|
if (f.record() && !f.external_record())
|
1997-06-16 12:52:23 +00:00
|
|
|
|
err|=f.record()->write(FALSE);
|
1998-07-20 13:15:59 +00:00
|
|
|
|
}
|
1997-05-23 14:08:53 +00:00
|
|
|
|
}
|
2008-08-22 09:04:05 +00:00
|
|
|
|
*/
|
|
|
|
|
FOR_EACH_MASK_SHEET(m, i, s)
|
|
|
|
|
{
|
|
|
|
|
if (s->record() && !s->external_record())
|
|
|
|
|
err |= s->record()->write(false);
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-23 14:08:53 +00:00
|
|
|
|
return err;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int TRelation_application::rewrite(const TMask& m)
|
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
|
TRelation& r = *get_relation();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
m.autosave(r);
|
2008-08-22 09:04:05 +00:00
|
|
|
|
r.curr().set_modify_info();
|
1997-06-16 12:52:23 +00:00
|
|
|
|
// rewrite relation and all independent sheets
|
1996-05-08 11:09:13 +00:00
|
|
|
|
r.rewrite();
|
2005-02-11 15:32:58 +00:00
|
|
|
|
int err=r.status();
|
2008-08-22 09:04:05 +00:00
|
|
|
|
|
|
|
|
|
/*
|
1997-05-23 14:08:53 +00:00
|
|
|
|
const int max = m.fields();
|
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
|
{
|
2005-02-11 15:32:58 +00:00
|
|
|
|
if (m.fld(i).is_sheet())
|
|
|
|
|
{
|
|
|
|
|
TSheet_field& f = (TSheet_field&)m.fld(i);
|
1997-05-23 14:08:53 +00:00
|
|
|
|
if (f.record()&& !f.external_record())
|
1997-06-16 12:52:23 +00:00
|
|
|
|
err|=f.record()->write(TRUE);
|
2005-02-11 15:32:58 +00:00
|
|
|
|
}
|
1997-05-23 14:08:53 +00:00
|
|
|
|
}
|
2008-08-22 09:04:05 +00:00
|
|
|
|
*/
|
|
|
|
|
FOR_EACH_MASK_SHEET(m, i, s)
|
|
|
|
|
{
|
|
|
|
|
if (s->record() && !s->external_record())
|
|
|
|
|
err |= s->record()->write(true);
|
|
|
|
|
}
|
|
|
|
|
|
1997-05-23 14:08:53 +00:00
|
|
|
|
return err;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
|
// @doc INTERNAL
|
|
|
|
|
|
1996-01-31 17:19:02 +00:00
|
|
|
|
// @mfunc Cancella il record corrente
|
1996-02-05 19:00:53 +00:00
|
|
|
|
//
|
1996-01-31 17:19:02 +00:00
|
|
|
|
// @rdesc Ritorna se il record e' stato eliminato
|
1995-11-07 11:38:23 +00:00
|
|
|
|
bool TRelation_application::relation_remove()
|
1996-01-31 17:19:02 +00:00
|
|
|
|
// @comm Se la maschera e' in MODE_MOD non e' possibile cancellare il record e viene
|
1996-05-08 11:09:13 +00:00
|
|
|
|
// emesso un <f CHECK> di errore.
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1997-03-28 12:07:58 +00:00
|
|
|
|
CHECK(_mask->edit_mode(), "You can call remove in edit mode only");
|
1999-10-22 10:00:18 +00:00
|
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
|
TRelation& r = *get_relation();
|
|
|
|
|
r.restore_status();
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (protected_record(r))
|
2003-07-25 14:53:55 +00:00
|
|
|
|
return message_box(TR("Elemento non eliminabile"));
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
2003-05-22 10:56:04 +00:00
|
|
|
|
if (_curr_transaction == TRANSACTION_DELETE || yesno_box(TR("Confermare l'eliminazione")))
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1997-03-28 12:07:58 +00:00
|
|
|
|
r.restore_status();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
const bool ok = remove();
|
2002-12-20 16:15:03 +00:00
|
|
|
|
if (ok || is_transaction())
|
1995-11-07 11:38:23 +00:00
|
|
|
|
set_limits();
|
|
|
|
|
else
|
2003-08-08 12:54:27 +00:00
|
|
|
|
{
|
|
|
|
|
const int err = r.status();
|
|
|
|
|
if (err != NOERR) // Succede nei remove con richiesta di conferma all'utente
|
|
|
|
|
return error_box(FR("Errore di cancellazione %d"), err);
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
|
bool TRelation_application::protected_record(TRelation &r)
|
|
|
|
|
{
|
2004-06-24 10:50:24 +00:00
|
|
|
|
if (user_can_delete(&r))
|
1999-10-22 10:00:18 +00:00
|
|
|
|
return protected_record(r.curr());
|
2004-06-24 10:50:24 +00:00
|
|
|
|
return true;
|
1999-10-22 10:00:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
bool TRelation_application::remove()
|
|
|
|
|
{
|
1997-05-23 14:08:53 +00:00
|
|
|
|
int err = get_relation()->remove();
|
2002-12-20 16:15:03 +00:00
|
|
|
|
if (err == NOERR)
|
1997-05-23 14:08:53 +00:00
|
|
|
|
{
|
2002-12-20 16:15:03 +00:00
|
|
|
|
const int maxf = _mask->fields();
|
|
|
|
|
for (int i = 0; i < maxf; i++)
|
1997-12-04 14:16:30 +00:00
|
|
|
|
{
|
2003-01-10 14:09:13 +00:00
|
|
|
|
const TMask_field& mf = _mask->fld(i);
|
2002-12-20 16:15:03 +00:00
|
|
|
|
if (mf.is_sheet())
|
|
|
|
|
{
|
|
|
|
|
TSheet_field& f = (TSheet_field&)mf;
|
|
|
|
|
if (f.record()&& !f.external_record())
|
|
|
|
|
err |= f.record()->remove();
|
|
|
|
|
}
|
1997-12-04 14:16:30 +00:00
|
|
|
|
}
|
1997-05-23 14:08:53 +00:00
|
|
|
|
}
|
1998-12-10 16:25:48 +00:00
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
2002-12-20 16:15:03 +00:00
|
|
|
|
_mask->set_mode(NO_MODE);
|
|
|
|
|
mask2mail(*_mask);
|
1998-12-10 16:25:48 +00:00
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return err == NOERR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::firm_change_enabled() const
|
|
|
|
|
{
|
|
|
|
|
bool ok = TApplication::firm_change_enabled();
|
1996-05-16 09:49:24 +00:00
|
|
|
|
ok &= (_mask == NULL || _mask->query_mode()) && _lnflag == 0;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1998-02-24 10:37:28 +00:00
|
|
|
|
void TRelation_application::main_loop()
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
|
|
|
|
KEY k;
|
1998-04-30 15:31:34 +00:00
|
|
|
|
do {
|
|
|
|
|
// ciclo delle transazioni
|
|
|
|
|
_recins = -1;
|
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
|
// imposta la maschera in query mode
|
|
|
|
|
query_mode();
|
|
|
|
|
_mask->open_modal();
|
|
|
|
|
|
1998-04-30 15:31:34 +00:00
|
|
|
|
// Provoca l'autopremimento per il messaggio di LINK
|
1998-06-11 13:03:53 +00:00
|
|
|
|
if (_lnflag)
|
1998-04-30 15:31:34 +00:00
|
|
|
|
{
|
1998-06-11 13:03:53 +00:00
|
|
|
|
if (_trans_counter < _ntransactions)
|
|
|
|
|
{
|
1998-11-04 18:04:26 +00:00
|
|
|
|
// la transazione <20> sul .ini : la imposta nelle variabili _curr_transaction...
|
1998-06-11 13:03:53 +00:00
|
|
|
|
if (load_transaction())
|
|
|
|
|
{
|
|
|
|
|
// la transazione necessita di autopremimento
|
|
|
|
|
_autodelete = _curr_transaction == TRANSACTION_DELETE;
|
|
|
|
|
if (_curr_transaction == TRANSACTION_INSERT )
|
|
|
|
|
_mask->send_key(K_CTRL+'N', 0);
|
1998-11-04 18:04:26 +00:00
|
|
|
|
else
|
1998-06-11 13:03:53 +00:00
|
|
|
|
_mask->send_key(K_AUTO_ENTER, 0);
|
1998-11-04 18:04:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // la transazione non <20> sul .ini
|
1998-06-11 13:03:53 +00:00
|
|
|
|
{
|
1998-05-27 13:41:48 +00:00
|
|
|
|
_mask->send_key(K_AUTO_ENTER, 0);
|
1998-06-11 13:03:53 +00:00
|
|
|
|
}
|
1997-05-06 10:26:19 +00:00
|
|
|
|
}
|
1998-08-25 18:07:30 +00:00
|
|
|
|
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (is_transaction())
|
1998-08-25 18:07:30 +00:00
|
|
|
|
ini2query_mask();
|
1998-05-27 13:41:48 +00:00
|
|
|
|
|
1998-04-30 15:31:34 +00:00
|
|
|
|
do
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
const bool change = firm_change_enabled();
|
|
|
|
|
// Dis/abilita cambio ditta
|
|
|
|
|
enable_menu_item(M_FILE_NEW, change);
|
|
|
|
|
|
|
|
|
|
if (_mask->edit_mode())
|
1997-04-10 15:22:15 +00:00
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
if (_autodelete)
|
|
|
|
|
{
|
|
|
|
|
const int pos = _mask->id2pos(DLG_DELREC);
|
|
|
|
|
if (pos >= 0 && _mask->fld(pos).active())
|
|
|
|
|
_mask->send_key(K_CTRL+'E', 0);
|
|
|
|
|
else
|
2003-05-22 10:56:04 +00:00
|
|
|
|
error_box(TR("Elemento non eliminabile."));
|
1998-04-30 15:31:34 +00:00
|
|
|
|
_autodelete = FALSE;
|
|
|
|
|
}
|
1997-04-10 15:22:15 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
|
|
|
|
|
k = _mask->run();
|
|
|
|
|
|
|
|
|
|
switch (k)
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
case K_ESC:
|
|
|
|
|
if (save(TRUE))
|
2009-09-23 12:04:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (save_and_quit())
|
|
|
|
|
k = K_QUIT;
|
2009-12-15 15:22:43 +00:00
|
|
|
|
else
|
|
|
|
|
query_mode();
|
2009-09-23 12:04:06 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case K_QUIT:
|
|
|
|
|
if (!save(TRUE))
|
|
|
|
|
k = K_ENTER;
|
|
|
|
|
break;
|
2008-04-04 16:04:15 +00:00
|
|
|
|
case K_F1:
|
|
|
|
|
dispatch_e_menu(M_HELP_CONTENTS);
|
|
|
|
|
break;
|
|
|
|
|
case K_F2:
|
|
|
|
|
dispatch_e_menu(M_FILE_ABOUT);
|
|
|
|
|
break;
|
1998-04-30 15:31:34 +00:00
|
|
|
|
case K_ENTER:
|
1998-05-08 14:35:36 +00:00
|
|
|
|
if (_lnflag && _curr_transaction != TRANSACTION_RUN)
|
1998-04-30 15:31:34 +00:00
|
|
|
|
{
|
2011-05-16 14:27:49 +00:00
|
|
|
|
if (find(1))
|
2003-07-04 11:16:46 +00:00
|
|
|
|
{
|
2003-07-24 14:36:06 +00:00
|
|
|
|
if (_curr_transaction == TRANSACTION_INSERT)
|
2003-07-04 11:16:46 +00:00
|
|
|
|
_curr_transaction = TRANSACTION_MODIFY;
|
2011-05-16 14:27:49 +00:00
|
|
|
|
if (!modify_mode())
|
|
|
|
|
k = K_QUIT;
|
2003-07-04 11:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2003-07-24 14:36:06 +00:00
|
|
|
|
if (_curr_transaction == TRANSACTION_MODIFY)
|
2003-07-04 11:16:46 +00:00
|
|
|
|
_curr_transaction = TRANSACTION_INSERT;
|
|
|
|
|
insert_mode();
|
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-12-10 16:25:48 +00:00
|
|
|
|
if (find(0))
|
|
|
|
|
modify_mode();
|
|
|
|
|
else
|
|
|
|
|
insert_mode();
|
1998-04-30 15:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
if (_curr_trans_mode == TM_AUTOMATIC)
|
|
|
|
|
_mask->send_key(K_CTRL+'R', 0);
|
|
|
|
|
break;
|
|
|
|
|
case K_SAVE:
|
|
|
|
|
if (save(FALSE))
|
|
|
|
|
{
|
2009-09-23 12:04:06 +00:00
|
|
|
|
if (save_and_quit())
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
k = K_QUIT;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (save_and_new())
|
|
|
|
|
{
|
|
|
|
|
if (_mask->insert_mode())
|
|
|
|
|
insert_mode();
|
|
|
|
|
else
|
|
|
|
|
query_mode();
|
|
|
|
|
}
|
|
|
|
|
else
|
2008-03-21 16:39:47 +00:00
|
|
|
|
{
|
|
|
|
|
const TMask_field & f = _mask->focus_field();
|
|
|
|
|
|
2008-06-20 10:00:16 +00:00
|
|
|
|
_mask->first_focus(-f.dlg(), false);
|
1998-04-30 15:31:34 +00:00
|
|
|
|
modify_mode();
|
2008-03-21 16:39:47 +00:00
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case K_INS:
|
|
|
|
|
if (_mask->query_mode() || save(TRUE))
|
|
|
|
|
{
|
|
|
|
|
const bool trovato = _mask->query_mode() && test_key(1, FALSE) && find(1);
|
|
|
|
|
if (trovato)
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (is_transaction())
|
1998-04-30 15:31:34 +00:00
|
|
|
|
_curr_transaction=TRANSACTION_MODIFY;
|
2002-12-20 16:15:03 +00:00
|
|
|
|
else
|
2003-06-03 12:58:47 +00:00
|
|
|
|
warning_box(TR("Elemento gia' presente"));
|
|
|
|
|
modify_mode();
|
1998-04-30 15:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
insert_mode();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
if (_curr_trans_mode == TM_AUTOMATIC)
|
|
|
|
|
_mask->send_key(K_CTRL+'R', 0);
|
|
|
|
|
break;
|
|
|
|
|
case K_DEL:
|
|
|
|
|
if (_mask->query_mode())
|
|
|
|
|
{
|
|
|
|
|
delete_mode();
|
1996-07-12 14:51:17 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1997-05-06 10:26:19 +00:00
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
if (relation_remove())
|
|
|
|
|
{
|
|
|
|
|
query_mode();
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (_autoins_caller.not_empty() || is_transaction())
|
1998-04-30 15:31:34 +00:00
|
|
|
|
{
|
|
|
|
|
if (_lnflag) _recins = 0;
|
|
|
|
|
k = K_QUIT;
|
|
|
|
|
}
|
|
|
|
|
}
|
1997-05-06 10:26:19 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case K_F9:
|
|
|
|
|
if (_mask->query_mode() || save(TRUE))
|
|
|
|
|
search_mode();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (save(TRUE))
|
1995-11-07 11:38:23 +00:00
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
setkey();
|
|
|
|
|
int err = ~NOERR;
|
|
|
|
|
switch (k)
|
|
|
|
|
{
|
|
|
|
|
case K_HOME:
|
|
|
|
|
err = file().readat(_first, _testandlock);
|
|
|
|
|
break;
|
|
|
|
|
case K_NEXT:
|
|
|
|
|
err = file().reread();
|
2003-09-23 14:47:55 +00:00
|
|
|
|
if (has_filtered_cursor())
|
|
|
|
|
{
|
|
|
|
|
TCursor& cur = get_filtered_cursor();
|
|
|
|
|
cur.curr() = file().curr();
|
|
|
|
|
cur.read();
|
|
|
|
|
++cur;
|
|
|
|
|
file().curr() = cur.curr();
|
|
|
|
|
err = get_relation()->read(_isequal, _testandlock);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
err = file().next(_testandlock);
|
1998-04-30 15:31:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case K_PREV:
|
2003-09-23 14:47:55 +00:00
|
|
|
|
file().reread();
|
|
|
|
|
if (has_filtered_cursor())
|
|
|
|
|
{
|
|
|
|
|
TCursor& cur = get_filtered_cursor();
|
|
|
|
|
cur.curr() = file().curr();
|
|
|
|
|
cur.read();
|
|
|
|
|
--cur;
|
|
|
|
|
file().curr() = cur.curr();
|
|
|
|
|
err = get_relation()->read(_isequal, _testandlock);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
err = file().prev(_testandlock);
|
1998-04-30 15:31:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case K_END:
|
|
|
|
|
err = file().readat(_last, _testandlock);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (err == NOERR || err == _islocked)
|
2003-08-08 12:54:27 +00:00
|
|
|
|
{
|
|
|
|
|
_navigating = true;
|
1998-04-30 15:31:34 +00:00
|
|
|
|
modify_mode();
|
2003-08-08 12:54:27 +00:00
|
|
|
|
_navigating = false;
|
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
else
|
|
|
|
|
query_mode();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
break;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
1998-05-04 08:51:30 +00:00
|
|
|
|
} while (k != K_QUIT);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
1998-05-04 08:51:30 +00:00
|
|
|
|
if (_mask->is_open())
|
|
|
|
|
_mask->close_modal();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
1998-05-04 08:51:30 +00:00
|
|
|
|
_mask->set_mode(NO_MODE);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
1998-05-04 08:51:30 +00:00
|
|
|
|
if (autoins_caller().not_empty() && _recins >= 0)
|
|
|
|
|
{
|
2003-06-06 08:57:05 +00:00
|
|
|
|
NFCHECK("Obsolete LINK message calling convention");
|
1998-05-04 08:51:30 +00:00
|
|
|
|
TString16 num;
|
|
|
|
|
num.format("%ld", _recins);
|
|
|
|
|
TMessage msg(autoins_caller(), _lnflag ? MSG_LN : MSG_AI, num);
|
|
|
|
|
msg.send();
|
1997-03-28 12:07:58 +00:00
|
|
|
|
}
|
2000-10-03 13:45:12 +00:00
|
|
|
|
|
|
|
|
|
if (is_transaction())
|
1998-05-04 08:51:30 +00:00
|
|
|
|
{
|
|
|
|
|
TConfig ini(_trans_ini.row(_trans_counter), "Transaction");
|
1998-05-08 14:35:36 +00:00
|
|
|
|
ini.set("Record", _recins);
|
1998-05-04 08:51:30 +00:00
|
|
|
|
if (_recins >= 0)
|
|
|
|
|
{
|
|
|
|
|
ini.set("Result", "OK");
|
|
|
|
|
ini.set("Error", "0");
|
|
|
|
|
edit_mask2ini();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int err = get_relation()->status();
|
|
|
|
|
ini.set("Result", err == NOERR ? "CANCEL" : "ERROR");
|
|
|
|
|
ini.set("Error", err);
|
|
|
|
|
}
|
1999-04-06 15:34:39 +00:00
|
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
_trans_counter++;
|
|
|
|
|
} while ( _trans_counter < _ntransactions);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::filter()
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
|
|
|
|
if (parse_command_line())
|
2008-12-10 16:52:43 +00:00
|
|
|
|
return true;
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
TMailbox mail;
|
|
|
|
|
TMessage* msg = mail.next_s(MSG_FS);
|
|
|
|
|
|
|
|
|
|
if (msg)
|
|
|
|
|
{
|
|
|
|
|
_mask = get_mask(MODE_MOD);
|
1996-05-16 09:49:24 +00:00
|
|
|
|
TToken_string body(msg->body());
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
|
|
short id = body.get_int();
|
|
|
|
|
while (id > 0)
|
|
|
|
|
{
|
|
|
|
|
_search_id = id;
|
2009-10-21 15:06:27 +00:00
|
|
|
|
TEdit_field& f = _mask->efield(id);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
TCursor* cur = f.browse()->cursor();
|
|
|
|
|
TRectype& rec = cur->curr();
|
|
|
|
|
rec.zero();
|
|
|
|
|
|
|
|
|
|
TString80 t;
|
|
|
|
|
const char* s;
|
|
|
|
|
while((s = body.get()) != NULL)
|
|
|
|
|
{
|
|
|
|
|
t = s;
|
|
|
|
|
const int u = t.find('=');
|
|
|
|
|
if (u < 0)
|
|
|
|
|
{
|
|
|
|
|
id = atoi(t);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
_fixed.add(t);
|
|
|
|
|
const short fid = atoi(t.left(u));
|
|
|
|
|
const TFieldref* campo = _mask->field(fid).field();
|
|
|
|
|
if (campo != NULL)
|
|
|
|
|
campo->write(t.mid(u+1), rec);
|
|
|
|
|
}
|
|
|
|
|
cur->setfilter("");
|
2000-05-05 15:25:49 +00:00
|
|
|
|
cur->setregion(rec, rec, 0x2);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
if (s == NULL) id = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mail.restart();
|
|
|
|
|
msg = mail.next_s(MSG_AI);
|
|
|
|
|
if (msg) _autoins_caller = msg->from();
|
|
|
|
|
|
|
|
|
|
mail.restart();
|
|
|
|
|
msg = mail.next_s(MSG_LN);
|
|
|
|
|
if (msg)
|
|
|
|
|
{
|
|
|
|
|
TToken_string body(msg->body());
|
|
|
|
|
const int key = body.get_int();
|
|
|
|
|
|
|
|
|
|
_autoins_caller = msg->from();
|
|
|
|
|
_lnflag = TRUE;
|
|
|
|
|
|
1998-02-24 10:37:28 +00:00
|
|
|
|
TString str, tmp;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
const char* v = body.get();
|
|
|
|
|
for (int i = 0; v != NULL && i < _mask->fields(); i++)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& f = _mask->fld(i);
|
|
|
|
|
if (f.active() && f.dlg() > 0 && f.in_key(key))
|
|
|
|
|
{
|
1998-02-24 10:37:28 +00:00
|
|
|
|
str = v;
|
|
|
|
|
tmp.format("%d=", f.dlg());
|
|
|
|
|
str.insert(tmp, 0);
|
|
|
|
|
_fixed.add(str);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
v = body.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1996-07-24 08:34:48 +00:00
|
|
|
|
mail.restart();
|
|
|
|
|
msg = mail.next_s(MSG_ED);
|
|
|
|
|
if (msg)
|
|
|
|
|
{
|
|
|
|
|
TToken_string body(msg->body());
|
|
|
|
|
const int key = body.get_int();
|
|
|
|
|
|
|
|
|
|
_autoins_caller = msg->from();
|
1996-08-05 09:43:06 +00:00
|
|
|
|
_lnflag = 2;
|
1996-07-24 08:34:48 +00:00
|
|
|
|
|
|
|
|
|
TAssoc_array field_values;
|
|
|
|
|
const char * s;
|
1998-03-30 13:50:30 +00:00
|
|
|
|
TString t, v;
|
1996-07-24 08:34:48 +00:00
|
|
|
|
|
|
|
|
|
while((s = body.get()) != NULL)
|
|
|
|
|
{
|
|
|
|
|
t = s;
|
|
|
|
|
const int u = t.find('=');
|
|
|
|
|
|
|
|
|
|
CHECKS(u > 0, "Invalid edit message ", (const char *) body);
|
|
|
|
|
if (u > 0)
|
|
|
|
|
{
|
1998-03-30 13:50:30 +00:00
|
|
|
|
v = t.mid(u + 1);
|
1996-07-24 08:34:48 +00:00
|
|
|
|
|
|
|
|
|
t.cut(u);
|
|
|
|
|
field_values.add(t, v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < _mask->fields(); i++)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& f = _mask->fld(i);
|
|
|
|
|
const TFieldref * field = f.field();
|
|
|
|
|
|
|
|
|
|
if (field && f.in_key(key))
|
|
|
|
|
{
|
1996-07-24 12:51:48 +00:00
|
|
|
|
TString16 field_name(field->name());
|
|
|
|
|
const int from = field->from();
|
1996-07-24 15:23:57 +00:00
|
|
|
|
const int to = field->to();
|
1996-07-24 12:51:48 +00:00
|
|
|
|
|
1996-07-24 15:23:57 +00:00
|
|
|
|
if (to >= 0)
|
1996-07-24 12:51:48 +00:00
|
|
|
|
field_name << "[" << (from + 1);
|
1996-07-24 08:34:48 +00:00
|
|
|
|
const TString * v = (const TString *) field_values.objptr(field_name);
|
|
|
|
|
|
1996-08-05 09:43:06 +00:00
|
|
|
|
TString val;
|
|
|
|
|
if (v == NULL && to >= 0)
|
|
|
|
|
{
|
|
|
|
|
v = (const TString *)field_values.objptr(field->name());
|
|
|
|
|
if (v)
|
|
|
|
|
val = v->sub(from, to);
|
|
|
|
|
}
|
|
|
|
|
else
|
1996-09-06 14:16:24 +00:00
|
|
|
|
if (v) val = *v;
|
1996-08-05 09:43:06 +00:00
|
|
|
|
|
2009-10-21 15:06:27 +00:00
|
|
|
|
if (v && f.dlg() > 0)
|
1998-02-24 10:37:28 +00:00
|
|
|
|
{
|
|
|
|
|
t.format("%d=", f.dlg());
|
|
|
|
|
val.insert(t, 0);
|
|
|
|
|
_fixed.add(val);
|
|
|
|
|
}
|
1996-07-24 08:34:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TRelation_application::set_link(TMask & m, const char * keyexpr)
|
|
|
|
|
{
|
|
|
|
|
CHECK(keyexpr != NULL, "Invalid expression");
|
|
|
|
|
TToken_string body(keyexpr);
|
|
|
|
|
const int key = body.get_int();
|
|
|
|
|
|
|
|
|
|
_lnflag = TRUE;
|
|
|
|
|
|
|
|
|
|
const char* v = body.get();
|
|
|
|
|
|
1998-02-24 10:37:28 +00:00
|
|
|
|
TString16 tmp;
|
1995-11-07 11:38:23 +00:00
|
|
|
|
const int max = m.fields();
|
|
|
|
|
for (int i = 0; i < max && v != NULL; i++)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& f = m.fld(i);
|
|
|
|
|
|
|
|
|
|
if (f.active() && f.dlg() > 0 && f.in_key(key))
|
|
|
|
|
{
|
1998-02-24 10:37:28 +00:00
|
|
|
|
TString s(v);
|
|
|
|
|
tmp.format("%d=", f.dlg());
|
|
|
|
|
s.insert(tmp, 0);
|
|
|
|
|
_fixed.add(s);
|
1995-11-07 11:38:23 +00:00
|
|
|
|
v = body.get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
|
bool TRelation_application::parse_command_line()
|
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
_trans_ini.destroy();
|
|
|
|
|
_trans_counter=0;
|
|
|
|
|
_curr_transaction = "";
|
|
|
|
|
_curr_trans_mode = 'I';
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
|
|
|
|
TFilename ini;
|
|
|
|
|
for (int i = argc()-1; i > 0; i--)
|
|
|
|
|
{
|
|
|
|
|
ini = argv(i);
|
2004-04-29 09:59:24 +00:00
|
|
|
|
if ((ini[0] == '-' || ini[0] == '/') && (ini[1] == 'I' || ini[1] == 'i'))
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
1998-11-03 10:27:35 +00:00
|
|
|
|
ini.ltrim(2);
|
|
|
|
|
CHECK(!ini.blank(),"Manca l'indicazione della transazione. Il nome va indicato di seguito al -i, senza interporre spaziatura.");
|
1998-04-30 15:31:34 +00:00
|
|
|
|
if (ini.find('*')>=0)
|
|
|
|
|
{
|
|
|
|
|
// metachars:
|
1998-11-03 10:27:35 +00:00
|
|
|
|
list_files(ini, _trans_ini);
|
1998-04-30 15:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1998-11-03 10:27:35 +00:00
|
|
|
|
_trans_ini.add(ini);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-04-30 15:31:34 +00:00
|
|
|
|
_ntransactions= _trans_ini.items();
|
|
|
|
|
|
|
|
|
|
_lnflag = _ntransactions>0;
|
1998-05-08 10:40:45 +00:00
|
|
|
|
return _lnflag != 0;
|
1998-04-30 15:31:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-11-04 14:49:29 +00:00
|
|
|
|
// il valore di ritorno indica se attivare l'"automagia":
|
|
|
|
|
// spedizione dei tasti e precaricamento della maschera
|
1998-04-30 15:31:34 +00:00
|
|
|
|
bool TRelation_application::load_transaction()
|
|
|
|
|
{
|
1998-05-08 14:35:36 +00:00
|
|
|
|
bool retv = FALSE;
|
1998-04-30 15:31:34 +00:00
|
|
|
|
if (_trans_counter < _ntransactions)
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
1998-04-30 15:31:34 +00:00
|
|
|
|
TConfig cnf(_trans_ini.row(_trans_counter), "Transaction");
|
|
|
|
|
_curr_transaction = cnf.get("Action");
|
|
|
|
|
_curr_transaction.upper();
|
2002-09-13 14:06:05 +00:00
|
|
|
|
_curr_trans_mode = toupper(cnf.get("Mode")[0]);
|
2001-04-30 15:04:10 +00:00
|
|
|
|
_curr_trans_from = cnf.get("From");
|
2003-03-20 10:28:01 +00:00
|
|
|
|
const long firm = cnf.get_long("Firm");
|
2002-12-20 16:15:03 +00:00
|
|
|
|
if (firm > 0)
|
1997-04-08 12:20:57 +00:00
|
|
|
|
{
|
2002-12-18 10:56:10 +00:00
|
|
|
|
bool ok = set_firm(firm);
|
|
|
|
|
if (ok)
|
1998-05-04 07:57:56 +00:00
|
|
|
|
_mask->on_firm_change();
|
2002-12-18 10:56:10 +00:00
|
|
|
|
else
|
2007-01-25 15:42:56 +00:00
|
|
|
|
error_box(FR("La ditta %ld non esiste"), firm);
|
1997-04-08 12:20:57 +00:00
|
|
|
|
}
|
1998-05-08 14:35:36 +00:00
|
|
|
|
if (_curr_transaction == TRANSACTION_RUN)
|
2008-12-09 11:53:05 +00:00
|
|
|
|
retv = false; // Ho gia' finito qui: basta il cambio ditta
|
1997-05-15 14:09:47 +00:00
|
|
|
|
else
|
2008-12-09 11:53:05 +00:00
|
|
|
|
retv = true; // Attiva automagia
|
1997-03-28 12:07:58 +00:00
|
|
|
|
}
|
1998-04-30 15:31:34 +00:00
|
|
|
|
return retv;
|
|
|
|
|
}
|
|
|
|
|
|
2004-11-30 22:02:59 +00:00
|
|
|
|
void TRelation_application::on_firm_change()
|
|
|
|
|
{
|
|
|
|
|
TApplication::on_firm_change();
|
|
|
|
|
if (_mask != NULL)
|
|
|
|
|
{
|
|
|
|
|
set_limits(0x3);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
|
void TRelation_application::ini2query_mask()
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (is_transaction())
|
1998-04-30 15:31:34 +00:00
|
|
|
|
{
|
2003-07-24 14:36:06 +00:00
|
|
|
|
TString8 n; n.format("%d", get_relation()->lfile().num());
|
|
|
|
|
TConfig ini(_trans_ini.row(_trans_counter), n);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
ini2mask(ini, *_mask, TRUE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TRelation_application::ini2insert_mask()
|
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
if (is_transaction())
|
2003-07-24 14:36:06 +00:00
|
|
|
|
{
|
|
|
|
|
TString8 n; n.format("%d", get_relation()->lfile().num());
|
|
|
|
|
TConfig ini(_trans_ini.row(_trans_counter), n);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
ini2mask(ini, *_mask, FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TRelation_application::ini2mask(TConfig& ini, TMask& m, bool query)
|
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
const TString16 defpar = ini.get_paragraph();
|
2008-12-09 11:53:05 +00:00
|
|
|
|
TString tmp;
|
|
|
|
|
|
|
|
|
|
_fixed.cut(0);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
for (int f = m.fields()-1; f >= 0; f--)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& campo = m.fld(f);
|
2001-04-30 15:04:10 +00:00
|
|
|
|
const TFieldref* fref = campo.field();
|
|
|
|
|
if (fref)
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
1998-05-04 07:57:56 +00:00
|
|
|
|
if (!query || campo.in_key(0))
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
const TString& str = fref->read(ini, defpar);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
if (str.not_empty())
|
2008-12-09 11:53:05 +00:00
|
|
|
|
{
|
1997-03-28 12:07:58 +00:00
|
|
|
|
campo.set(str);
|
2008-12-09 11:53:05 +00:00
|
|
|
|
if (query)
|
|
|
|
|
{
|
|
|
|
|
tmp.format("%d=%s", campo.dlg(), (const char *) str);
|
|
|
|
|
_fixed.add(tmp);
|
|
|
|
|
}
|
|
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-30 15:04:10 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!query && campo.is_sheet())
|
|
|
|
|
{
|
|
|
|
|
TSheet_field &sheet=(TSheet_field &)campo;
|
|
|
|
|
ini2sheet(ini, sheet);
|
|
|
|
|
}
|
|
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
|
}
|
|
|
|
|
ini.set_paragraph(defpar);
|
2008-12-09 11:53:05 +00:00
|
|
|
|
if (query)
|
|
|
|
|
set_fixed();
|
1997-03-28 12:07:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TRelation_application::edit_mask2ini()
|
|
|
|
|
{
|
2010-02-15 12:11:55 +00:00
|
|
|
|
const TString& str = _trans_ini.row(_trans_counter);
|
|
|
|
|
if (str.full())
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
2003-07-24 14:36:06 +00:00
|
|
|
|
TString8 head; head.format("%d", get_relation()->lfile().num());
|
2010-02-15 12:11:55 +00:00
|
|
|
|
TConfig ini(str, head);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
mask2ini(*_mask, ini);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
|
void TRelation_application::ini2sheet(TConfig& ini,TSheet_field &sheet)
|
|
|
|
|
{
|
|
|
|
|
if (sheet.record() != NULL)
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
const int lognum = sheet.record()->logic_num();
|
|
|
|
|
const TMask& sm = sheet.sheet_mask();
|
|
|
|
|
|
|
|
|
|
// scrive le righe nello sheet associato
|
|
|
|
|
TString16 defpar;
|
|
|
|
|
|
|
|
|
|
for (int r = 1; ;r++)
|
1997-03-28 12:07:58 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
defpar.format("%d,%d", lognum, r);
|
|
|
|
|
if (ini.set_paragraph(defpar))
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
TToken_string& row = sheet.row(r-1);
|
|
|
|
|
for (int sf = sm.fields()-1; sf >= 0; sf--)
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
TMask_field& campo = sm.fld(sf);
|
|
|
|
|
const TFieldref* fref = campo.field();
|
|
|
|
|
if (fref)
|
|
|
|
|
{
|
|
|
|
|
const TString& str = fref->read(ini, defpar);
|
|
|
|
|
row.add(str, sheet.cid2index(campo.dlg()));
|
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
}
|
2001-04-30 15:04:10 +00:00
|
|
|
|
sheet.check_row(r-1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
break;
|
1997-03-28 12:07:58 +00:00
|
|
|
|
}
|
2001-04-30 15:04:10 +00:00
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TRelation_application::sheet2ini(TSheet_field &sheet,TConfig& ini)
|
|
|
|
|
{
|
|
|
|
|
if (sheet.record() != NULL)
|
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
const int lognum = sheet.record()->logic_num();
|
|
|
|
|
const TMask& sm = sheet.sheet_mask();
|
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
|
// scrive le righe degli sheet associati
|
|
|
|
|
TString16 defpar;
|
2001-04-30 15:04:10 +00:00
|
|
|
|
TString str;
|
2004-03-12 16:01:27 +00:00
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
for (r = 1 ; r <= sheet.items(); r++)
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
defpar.format("%d,%d", lognum, r);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
|
|
|
|
|
TMask_field* fkey;
|
|
|
|
|
sheet.restart_key();
|
2004-03-12 16:01:27 +00:00
|
|
|
|
while ((fkey = sheet.get_key(str)))
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
|
|
|
|
ini.set(str, fkey->get(), defpar);
|
2001-04-30 15:04:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TToken_string& row = sheet.row(r-1);
|
|
|
|
|
const char* value;
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 0, value = row.get(0); value; i++, value = row.get())
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
const TMask_field& campo = sm.field(FIRST_FIELD+i);
|
|
|
|
|
const TFieldref* fr = campo.field();
|
|
|
|
|
if (fr)
|
1999-10-22 10:00:18 +00:00
|
|
|
|
{
|
2001-04-30 15:04:10 +00:00
|
|
|
|
if (value == NULL || *value == '\0')
|
|
|
|
|
value = " ";
|
|
|
|
|
// ini.set(fr->name(), value, defpar);
|
|
|
|
|
fr->write(ini, defpar, value);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-04-30 15:04:10 +00:00
|
|
|
|
for (r = sheet.items()+1; ; r++)
|
|
|
|
|
{
|
|
|
|
|
defpar.format("%d,%d", lognum, r);
|
|
|
|
|
if (ini.set_paragraph(defpar))
|
|
|
|
|
ini.remove_all();
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
|
void TRelation_application::mask2ini(const TMask& m, TConfig& ini)
|
|
|
|
|
{
|
|
|
|
|
ini.set("Firm", get_firm(), "Transaction");
|
2001-06-25 10:41:20 +00:00
|
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
|
int year, release, tag, patch;
|
|
|
|
|
if (get_version_info(year, release, tag, patch))
|
|
|
|
|
{
|
|
|
|
|
TString80 ver;
|
|
|
|
|
ver.format("%d %d.%d-%d", year, release, tag, patch);
|
|
|
|
|
ini.set("Version", ver);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 10:41:20 +00:00
|
|
|
|
const TLocalisamfile& lfile = get_relation()->lfile();
|
|
|
|
|
|
2001-04-30 15:04:10 +00:00
|
|
|
|
TString16 defpar;
|
|
|
|
|
defpar.format("%d", lfile.num());
|
|
|
|
|
ini.set_paragraph(defpar);
|
|
|
|
|
switch (lfile.num())
|
|
|
|
|
{
|
|
|
|
|
case LF_TAB:
|
|
|
|
|
case LF_TABCOM:
|
|
|
|
|
case LF_TABGEN:
|
|
|
|
|
{
|
|
|
|
|
const TString& tabname = lfile.curr().get("COD");
|
|
|
|
|
ini.set("COD", tabname, defpar);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
for (int f = 0; f < m.fields(); f++)
|
|
|
|
|
{
|
|
|
|
|
TMask_field& campo = m.fld(f);
|
|
|
|
|
if (campo.shown())
|
|
|
|
|
{
|
|
|
|
|
const TFieldref* fr = campo.field();
|
|
|
|
|
if (fr)
|
|
|
|
|
{
|
|
|
|
|
if (campo.empty())
|
|
|
|
|
fr->write(ini, defpar, " ");
|
|
|
|
|
else
|
2003-07-24 14:36:06 +00:00
|
|
|
|
{
|
|
|
|
|
if (campo.class_id() == CLASS_DATE_FIELD && campo.right_justified())
|
|
|
|
|
{
|
2004-03-12 16:01:27 +00:00
|
|
|
|
const TDate d(campo.get());
|
2003-07-24 14:36:06 +00:00
|
|
|
|
fr->write(ini, defpar, d.string(ANSI));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
fr->write(ini, defpar, campo.get());
|
|
|
|
|
}
|
2001-04-30 15:04:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (campo.is_sheet())
|
|
|
|
|
{
|
|
|
|
|
TSheet_field &sheet=(TSheet_field &)campo;
|
|
|
|
|
sheet2ini(sheet,ini); // It's virtual
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ini.set_paragraph(defpar); // Reimposta paragrafo standard
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-10 16:25:48 +00:00
|
|
|
|
bool TRelation_application::mask2mail(const TMask& m)
|
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
|
TWait_cursor hourglass;
|
2001-04-30 15:04:10 +00:00
|
|
|
|
bool ok = _curr_trans_from.empty() && ::can_dispatch_transaction(get_relation()->curr());
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (ok)
|
1998-12-10 16:25:48 +00:00
|
|
|
|
{
|
|
|
|
|
TFilename ininame; ininame.temp();
|
2000-05-05 15:25:49 +00:00
|
|
|
|
if (ok) // Test qualunque per usare {}
|
1998-12-10 16:25:48 +00:00
|
|
|
|
{
|
|
|
|
|
TConfig ini(ininame, "Transaction");
|
|
|
|
|
const char* action = "";
|
|
|
|
|
char mode[2] = { TM_AUTOMATIC, '\0' };
|
|
|
|
|
switch (m.mode())
|
|
|
|
|
{
|
|
|
|
|
case NO_MODE:
|
|
|
|
|
action = TRANSACTION_DELETE;
|
|
|
|
|
break;
|
|
|
|
|
case MODE_MOD:
|
|
|
|
|
action = TRANSACTION_MODIFY;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
action = TRANSACTION_INSERT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ini.set("Action", action);
|
|
|
|
|
ini.set("Mode", mode);
|
|
|
|
|
mask2ini(m, ini);
|
|
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
|
ok = ::dispatch_transaction(get_relation()->curr(), ininame);
|
2009-01-28 08:59:32 +00:00
|
|
|
|
xvt_fsys_remove_file(ininame);
|
1998-12-10 16:25:48 +00:00
|
|
|
|
}
|
2000-05-05 15:25:49 +00:00
|
|
|
|
return ok;
|
1998-12-10 16:25:48 +00:00
|
|
|
|
}
|