1995-11-07 11:38:23 +00:00
|
|
|
#include <mailbox.h>
|
1997-05-21 09:39:46 +00:00
|
|
|
#include <progind.h>
|
1995-11-07 11:38:23 +00:00
|
|
|
#include <sheet.h>
|
1997-05-23 14:08:53 +00:00
|
|
|
#include <msksheet.h>
|
1995-11-07 11:38:23 +00:00
|
|
|
#include <urldefid.h>
|
|
|
|
#include <relapp.h>
|
|
|
|
#include <utility.h>
|
1997-01-17 11:07:43 +00:00
|
|
|
|
1996-05-16 09:49:24 +00:00
|
|
|
#define XVT_INCL_NATIVE
|
1997-01-17 11:07:43 +00:00
|
|
|
#define STRICT
|
1995-11-07 11:38:23 +00:00
|
|
|
#include <xvtility.h>
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TRelation_application
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TRelation_application::TRelation_application()
|
1997-05-06 10:26:19 +00:00
|
|
|
: _mask(NULL), _search_id(-1), _lnflag(FALSE),
|
|
|
|
_autodelete(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
|
|
|
|
|
|
|
void TRelation_application::setkey()
|
|
|
|
{
|
|
|
|
if (has_filtered_cursor())
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
TEdit_field& f = get_search_field();
|
|
|
|
TCursor* cur = f.browse()->cursor();
|
1995-11-07 11:38:23 +00:00
|
|
|
cur->setkey();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
file().setkey(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
TEdit_field& f = get_search_field();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
TBrowse* b = f.browse();
|
|
|
|
TCursor* cur = b != NULL ? b->cursor() : NULL;
|
1995-11-07 11:38:23 +00:00
|
|
|
if (cur)
|
|
|
|
{
|
|
|
|
cur->setkey();
|
1996-05-08 11:09:13 +00:00
|
|
|
f.browse()->do_input(TRUE);
|
1995-11-07 11:38:23 +00:00
|
|
|
if (cur->items() == 0) _first = _last = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (what & 0x1)
|
|
|
|
{
|
|
|
|
*cur = 0;
|
|
|
|
_first = cur->file().recno();
|
|
|
|
}
|
|
|
|
if (what & 0x2)
|
|
|
|
{
|
|
|
|
*cur = cur->items() - 1;
|
|
|
|
_last = cur->file().recno();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file().setkey(1);
|
|
|
|
if (what & 0x1)
|
|
|
|
{
|
|
|
|
if (file().empty()) _first = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file().first();
|
|
|
|
_first = file().recno();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (what & 0x2)
|
|
|
|
{
|
|
|
|
if (file().empty()) _last = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file().last();
|
|
|
|
_last = file().recno();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRelation_application::create()
|
|
|
|
{
|
1997-03-24 16:51:54 +00:00
|
|
|
bool ok = TApplication::create();
|
|
|
|
if (ok)
|
|
|
|
ok = user_create();
|
1995-11-07 11:38:23 +00:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
write_enable();
|
|
|
|
_mask = get_mask(MODE_QUERY);
|
|
|
|
filter();
|
|
|
|
set_limits();
|
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::menu(MENU_TAG m)
|
|
|
|
{
|
|
|
|
if (m == BAR_ITEM(1))
|
|
|
|
return main_loop();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::destroy()
|
|
|
|
{
|
|
|
|
user_destroy();
|
|
|
|
return TApplication::destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TRelation_application::set_fixed()
|
|
|
|
{
|
1996-08-05 09:43:06 +00:00
|
|
|
TToken_string s(256, '=');
|
1995-11-07 11:38:23 +00:00
|
|
|
for (const char* f = _fixed.get(0); f && *f; f = _fixed.get())
|
|
|
|
{
|
|
|
|
s = f;
|
1996-08-05 09:43:06 +00:00
|
|
|
const int id = s.get_int(0);
|
|
|
|
s = s.get();
|
|
|
|
if (s.not_empty())
|
|
|
|
_mask->set(id, s);
|
|
|
|
|
1996-08-14 15:38:54 +00:00
|
|
|
if (_lnflag < 2)
|
1996-08-05 09:43:06 +00:00
|
|
|
_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);
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TRelation_application::set_toolbar(bool all)
|
|
|
|
{
|
|
|
|
const int mode = _mask->mode();
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
if (all)
|
|
|
|
{
|
|
|
|
pos = _mask->id2pos(DLG_SAVEREC);
|
|
|
|
if (pos >= 0) _mask->fld(pos).enable(mode != MODE_QUERY);
|
|
|
|
pos = _mask->id2pos(DLG_DELREC);
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
1997-05-06 10:26:19 +00:00
|
|
|
bool enabdel = mode != MODE_INS;
|
|
|
|
if (mode == MODE_MOD)
|
1995-11-07 11:38:23 +00:00
|
|
|
{
|
|
|
|
TRelation& r = *get_relation();
|
|
|
|
const TRecnotype oldpos = r.lfile().recno();
|
|
|
|
enabdel = !protected_record(r.curr());
|
|
|
|
if (r.lfile().recno() != oldpos)
|
|
|
|
r.lfile().readat(oldpos);
|
|
|
|
}
|
|
|
|
_mask->fld(pos).enable(enabdel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_query();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::save_and_new() const
|
|
|
|
{ return FALSE; }
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (mode == _mode)
|
|
|
|
{
|
|
|
|
set_toolbar(FALSE); // Fast buttons update
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_toolbar(TRUE); // Full buttons update
|
|
|
|
_mode = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* t = "";
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case MODE_QUERY:
|
|
|
|
t = "Ricerca"; break;
|
|
|
|
case MODE_MOD:
|
|
|
|
t = "Modifica"; break;
|
|
|
|
case NO_MODE:
|
|
|
|
t = "Ricerca/Inserimento"; break;
|
|
|
|
case MODE_INS:
|
|
|
|
t = "Inserimento"; break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xvt_statbar_set(t, TRUE);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
TToken_string k(get_next_key());
|
|
|
|
|
|
|
|
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);
|
|
|
|
CHECKD (id > 0, "Identificatore di autonumerazione errato: ", id);
|
|
|
|
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))
|
|
|
|
_renum_message.format("Il documento e' stato registrato con :\n %s = %s", (const char *) f.prompt(), (const char *) f.get());
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
_mask->reset();
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
if (pre_ins)
|
|
|
|
{
|
|
|
|
set_mode(NO_MODE);
|
|
|
|
init_query_insert_mode(*_mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_mode(MODE_QUERY);
|
|
|
|
init_query_mode(*_mask);
|
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
|
|
if (_transaction.not_empty())
|
|
|
|
ini2query_mask();
|
1995-11-07 11:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TRelation_application::insert_mode()
|
1996-12-10 08:28:14 +00:00
|
|
|
{
|
|
|
|
bool try_auto = TRUE;
|
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
if (_mask->query_mode())
|
1996-12-10 08:28:14 +00:00
|
|
|
try_auto = test_key(1, FALSE) == FALSE;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
::remove(workname);
|
|
|
|
_mask->open_modal();
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
1996-12-10 08:28:14 +00:00
|
|
|
set_mode(MODE_INS);
|
1995-11-07 11:38:23 +00:00
|
|
|
get_relation()->zero(); // Azzera tutta la relazione!
|
1997-03-28 12:07:58 +00:00
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
init_insert_mode(*_mask);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
|
|
if (_transaction == "INSERT")
|
|
|
|
ini2insert_mask();
|
1995-11-07 11:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TRelation_application::modify_mode()
|
|
|
|
{
|
|
|
|
int err = get_relation()->read(_isequal, _testandlock);
|
|
|
|
if (err != NOERR)
|
|
|
|
{
|
|
|
|
if (err == _islocked)
|
1997-03-24 16:51:54 +00:00
|
|
|
message_box("I dati sono gia' usati da un altro programma");
|
1995-11-07 11:38:23 +00:00
|
|
|
else
|
|
|
|
error_box("Impossibile leggere i dati: errore %d", err);
|
|
|
|
query_mode();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool changing = changing_mask(MODE_MOD);
|
|
|
|
if (changing)
|
|
|
|
_mask->close_modal();
|
|
|
|
|
|
|
|
_mask = get_mask(MODE_MOD);
|
|
|
|
|
|
|
|
if (changing)
|
|
|
|
_mask->open_modal();
|
|
|
|
|
|
|
|
set_mode(MODE_MOD);
|
1996-06-07 16:19:46 +00:00
|
|
|
|
1995-11-07 11:38:23 +00:00
|
|
|
err = read(*_mask);
|
|
|
|
if (err != NOERR)
|
|
|
|
{
|
|
|
|
query_mode();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
get_relation()->save_status();
|
|
|
|
init_modify_mode(*_mask);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
TEdit_field& TRelation_application::get_search_field() const
|
|
|
|
{
|
|
|
|
short id = _search_id;
|
|
|
|
|
|
|
|
if (id <= 0)
|
|
|
|
{
|
|
|
|
const int max = _mask->fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
const TMask_field& f = _mask->fld(i);
|
|
|
|
if (f.in_key(1) && f.required())
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
TMask_field* dopo = &_mask->focus_field();
|
1996-05-08 11:09:13 +00:00
|
|
|
prima = (dopo == prima || !dopo->is_edit()) ? NULL : (TEdit_field*)dopo;
|
1995-11-07 11:38:23 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1997-05-21 09:39:46 +00:00
|
|
|
int TRelation_application::delete_mode()
|
|
|
|
{
|
|
|
|
TEdit_field& fld = get_search_field();
|
|
|
|
TBrowse* brw = fld.browse();
|
|
|
|
TCursor* cur = brw ? brw->cursor() : NULL;
|
|
|
|
|
|
|
|
if (cur)
|
|
|
|
{
|
|
|
|
TToken_string head(brw->head());
|
|
|
|
head.insert("@1|", 0);
|
|
|
|
TToken_string items(brw->items());
|
|
|
|
items.insert(" |", 0);
|
|
|
|
TCursor_sheet sht(cur, items, "Eliminazione", head, 0, 1);
|
|
|
|
if (sht.run() == K_ENTER)
|
|
|
|
{
|
|
|
|
long deleting = sht.checked();
|
|
|
|
if (deleting == 0)
|
|
|
|
{
|
|
|
|
sht.check(sht.selected());
|
|
|
|
deleting++;
|
|
|
|
}
|
|
|
|
TString msg(80);
|
|
|
|
msg = "Confermate l'eliminazione de";
|
|
|
|
if (deleting == 1)
|
|
|
|
msg << "l documento selezionato?";
|
|
|
|
else
|
|
|
|
msg << "i " << deleting << " documenti selezionati?";
|
|
|
|
if (yesno_box(msg))
|
|
|
|
{
|
|
|
|
TWait_cursor hourglass;
|
|
|
|
cur->freeze(TRUE); // Congelo il cursore altrimenti si riaggiorna troppo
|
|
|
|
for (long pos = 0; deleting > 0; pos++)
|
|
|
|
{
|
|
|
|
if (sht.checked(pos))
|
|
|
|
{
|
|
|
|
*cur = pos;
|
|
|
|
brw->do_output();
|
|
|
|
if (find(1) && modify_mode())
|
|
|
|
{
|
1997-05-21 09:44:37 +00:00
|
|
|
_autodelete = 0x3;
|
1997-05-21 09:39:46 +00:00
|
|
|
if (protected_record(get_relation()->curr()))
|
|
|
|
warning_box("Documento non eliminabile");
|
|
|
|
else
|
|
|
|
remove();
|
|
|
|
_autodelete = FALSE;
|
|
|
|
query_mode();
|
|
|
|
}
|
|
|
|
deleting--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cur->freeze(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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(
|
1996-05-08 11:09:13 +00:00
|
|
|
byte k, // @parm Chiave da ricercare
|
|
|
|
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
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
if (e->required())
|
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)
|
|
|
|
{
|
|
|
|
error_box("Manca un valore indispensabile per la ricerca");
|
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)
|
|
|
|
error_box("Manca un valore indispensabile per la ricerca");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return onefill || onereq;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRelation_application::find(byte k)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::save(bool check_dirty)
|
|
|
|
{
|
|
|
|
static bool was_dirty = FALSE;
|
|
|
|
|
|
|
|
int err = NOERR;
|
|
|
|
const int mode = _mask->mode();
|
|
|
|
|
|
|
|
if (check_dirty)
|
|
|
|
{
|
|
|
|
const int dirty = _mask->dirty();
|
|
|
|
|
|
|
|
const char* ms = (mode == MODE_MOD) ? "le modifiche" : "i dati inseriti";
|
|
|
|
|
|
|
|
if (mode == MODE_QUERY)
|
|
|
|
{
|
|
|
|
const bool cont = !dirty || yesno_box("Annullare %s?", ms);
|
|
|
|
return cont;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dirty && !was_dirty)
|
|
|
|
{
|
|
|
|
if (mode == MODE_MOD)
|
|
|
|
{
|
|
|
|
get_relation()->restore_status();
|
|
|
|
get_relation()->lfile().reread(_unlock); // Unlock main file
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const KEY last = _mask->last_key();
|
|
|
|
const bool annulla = last == K_ESC || last == K_QUIT || last == K_F9;
|
|
|
|
const bool errore = dirty && _mask->field(dirty).dirty() > TRUE;
|
|
|
|
|
|
|
|
KEY k;
|
|
|
|
if (errore)
|
|
|
|
{
|
|
|
|
if (annulla)
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
TString w(80);
|
|
|
|
if (_mask->field(dirty).is_edit())
|
|
|
|
w = _mask->efield(dirty).get_warning();
|
|
|
|
if (w.empty())
|
|
|
|
w = "Campo inconsistente";
|
1995-11-07 11:38:23 +00:00
|
|
|
w << ": si desidera ";
|
|
|
|
switch (last)
|
|
|
|
{
|
|
|
|
case K_ESC:
|
|
|
|
w << "annullare?"; break;
|
|
|
|
case K_QUIT:
|
|
|
|
w << "uscire?"; break;
|
|
|
|
default:
|
|
|
|
w << "continuare?"; break;
|
|
|
|
}
|
|
|
|
k = yesno_box(w) ? K_NO : K_ESC;
|
|
|
|
if (k == K_ESC)
|
|
|
|
_mask->first_focus(-dirty);
|
|
|
|
}
|
|
|
|
else k = K_ESC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
k = yesnocancel_box("Registrare %s?", ms);
|
|
|
|
|
|
|
|
if (k == K_ESC || k == K_NO)
|
|
|
|
{
|
|
|
|
if (mode == MODE_MOD)
|
|
|
|
{
|
|
|
|
get_relation()->restore_status();
|
|
|
|
get_relation()->lfile().reread(_unlock); // Unlock main file
|
|
|
|
}
|
|
|
|
was_dirty = FALSE;
|
|
|
|
return k == K_NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (annulla)
|
|
|
|
{
|
|
|
|
if (!_mask->check_fields()) // Exit with ESC didn't check values
|
|
|
|
{
|
|
|
|
_mask->first_focus(-_mask->focus_field().dlg());
|
|
|
|
was_dirty = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
was_dirty = FALSE;
|
|
|
|
|
|
|
|
begin_wait();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
end_wait();
|
|
|
|
|
|
|
|
switch(err)
|
|
|
|
{
|
|
|
|
case NOERR:
|
|
|
|
_recins = get_relation()->lfile().recno();
|
|
|
|
break;
|
|
|
|
case _isreinsert:
|
|
|
|
warning_box("Esiste gia' un documento con la stessa chiave");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error_box("Impossibile registrare i dati: errore %d", err);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TRelation_application::read(TMask& m)
|
|
|
|
{
|
1996-05-08 11:09:13 +00:00
|
|
|
const TRelation &r = *get_relation();
|
1997-05-23 14:08:53 +00:00
|
|
|
const int max = m.fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
m.autoload(r);
|
|
|
|
return NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TRelation_application::write(const TMask& m)
|
|
|
|
{
|
1997-05-23 14:08:53 +00:00
|
|
|
int err;
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
TRelation &r = *get_relation();
|
1995-11-07 11:38:23 +00:00
|
|
|
m.autosave(r);
|
1997-05-23 14:08:53 +00:00
|
|
|
// write relation and all independent sheets
|
1996-05-08 11:09:13 +00:00
|
|
|
r.write();
|
1997-05-23 14:08:53 +00:00
|
|
|
err=r.status();
|
|
|
|
const int max = m.fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
if (m.fld(i).is_sheet()) {
|
|
|
|
TSheet_field& f = (TSheet_field& )m.fld(i);
|
|
|
|
if (f.record() && !f.external_record())
|
|
|
|
err|=f.record()->write(FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
1995-11-07 11:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TRelation_application::rewrite(const TMask& m)
|
|
|
|
{
|
1997-05-23 14:08:53 +00:00
|
|
|
int err;
|
|
|
|
|
1996-05-08 11:09:13 +00:00
|
|
|
TRelation& r = *get_relation();
|
1995-11-07 11:38:23 +00:00
|
|
|
m.autosave(r);
|
1997-05-23 14:08:53 +00:00
|
|
|
// rewrite relation and all independent sheets
|
1996-05-08 11:09:13 +00:00
|
|
|
r.rewrite();
|
1997-05-23 14:08:53 +00:00
|
|
|
err=r.status();
|
|
|
|
const int max = m.fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
if (m.fld(i).is_sheet()) {
|
|
|
|
TSheet_field& f = (TSheet_field& )m.fld(i);
|
|
|
|
if (f.record()&& !f.external_record())
|
|
|
|
err|=f.record()->write(TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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");
|
|
|
|
TRelation& r = *get_relation();
|
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
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
if (protected_record(r.curr()))
|
1997-05-21 09:39:46 +00:00
|
|
|
return message_box("Documento non eliminabile");
|
1995-11-07 11:38:23 +00:00
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
if (_transaction == "DELETE" || yesno_box("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();
|
|
|
|
if (ok)
|
|
|
|
set_limits();
|
|
|
|
else
|
1997-03-28 12:07:58 +00:00
|
|
|
return error_box("Errore di cancellazione %d", r.status());
|
1995-11-07 11:38:23 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TRelation_application::remove()
|
|
|
|
{
|
1997-05-23 14:08:53 +00:00
|
|
|
TMask &m=*_mask;
|
|
|
|
int err = get_relation()->remove();
|
|
|
|
const int max = m.fields();
|
|
|
|
for (int i = 0; i < max; i++)
|
|
|
|
{
|
|
|
|
if (m.fld(i).is_sheet()) {
|
|
|
|
TSheet_field& f = (TSheet_field& )m.fld(i);
|
|
|
|
if (f.record()&& !f.external_record())
|
|
|
|
err|=f.record()->remove();
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRelation_application::main_loop()
|
|
|
|
{
|
|
|
|
_recins = -1;
|
|
|
|
|
|
|
|
query_mode();
|
|
|
|
_mask->open_modal();
|
|
|
|
|
|
|
|
KEY k;
|
|
|
|
|
|
|
|
// Provoca l'autopremimento per il messaggio di LINK
|
1997-03-28 12:07:58 +00:00
|
|
|
if (_lnflag)
|
|
|
|
{
|
|
|
|
if (_transaction == "INSERT")
|
|
|
|
_mask->send_key(K_CTRL+'N', 0);
|
1997-05-06 10:26:19 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
_autodelete = _transaction == "DELETE";
|
1997-03-28 12:07:58 +00:00
|
|
|
_mask->send_key(K_AUTO_ENTER, 0);
|
1997-05-06 10:26:19 +00:00
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
const bool change = firm_change_enabled();
|
|
|
|
// Dis/abilita cambio ditta
|
|
|
|
enable_menu_item(M_FILE_NEW, change);
|
|
|
|
// Dis/abilita cambio parametri
|
|
|
|
enable_menu_item(M_FILE_REVERT, change);
|
1997-03-28 12:07:58 +00:00
|
|
|
|
1997-05-06 10:26:19 +00:00
|
|
|
if (_mask->edit_mode() && _autodelete)
|
|
|
|
{
|
|
|
|
const int pos = _mask->id2pos(DLG_DELREC);
|
|
|
|
if (pos >= 0 && _mask->fld(pos).active())
|
|
|
|
_mask->send_key(K_CTRL+'E', 0);
|
|
|
|
else
|
|
|
|
error_box("Documento non eliminabile.");
|
|
|
|
_autodelete = FALSE;
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
k = _mask->run();
|
|
|
|
|
|
|
|
switch (k)
|
|
|
|
{
|
|
|
|
case K_ESC:
|
|
|
|
if (save(TRUE))
|
|
|
|
query_mode();
|
|
|
|
if (_lnflag)
|
|
|
|
k = K_QUIT;
|
|
|
|
break;
|
|
|
|
case K_QUIT:
|
|
|
|
if (!save(TRUE))
|
|
|
|
k = K_ENTER;
|
|
|
|
break;
|
|
|
|
case K_ENTER:
|
1997-04-10 15:22:15 +00:00
|
|
|
if (_lnflag)
|
|
|
|
{
|
|
|
|
for (k = 1; k <= MAX_KEYS && !test_key(k, FALSE); k++);
|
|
|
|
if (k <= MAX_KEYS && find(k))
|
|
|
|
modify_mode();
|
|
|
|
else
|
|
|
|
k = K_QUIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (find(0)) modify_mode();
|
|
|
|
else insert_mode();
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
break;
|
|
|
|
case K_SAVE:
|
|
|
|
if (save(FALSE))
|
|
|
|
{
|
1997-03-28 12:07:58 +00:00
|
|
|
if (_autoins_caller.not_empty() || _transaction.not_empty())
|
1995-11-07 11:38:23 +00:00
|
|
|
{
|
|
|
|
k = K_QUIT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (save_and_new())
|
|
|
|
{
|
|
|
|
if (_mask->insert_mode())
|
|
|
|
insert_mode();
|
|
|
|
else
|
|
|
|
query_mode();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
modify_mode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case K_INS:
|
|
|
|
if (_mask->query_mode() || save(TRUE))
|
1996-07-12 14:51:17 +00:00
|
|
|
{
|
|
|
|
const bool trovato = _mask->query_mode() && test_key(1, FALSE) && find(1);
|
|
|
|
if (trovato)
|
|
|
|
{
|
|
|
|
modify_mode();
|
|
|
|
warning_box("Documento gia' presente");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
insert_mode();
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
break;
|
|
|
|
case K_DEL:
|
1997-05-06 10:26:19 +00:00
|
|
|
if (_mask->query_mode())
|
1997-05-21 09:39:46 +00:00
|
|
|
{
|
|
|
|
delete_mode();
|
1997-05-06 10:26:19 +00:00
|
|
|
}
|
|
|
|
else
|
1997-03-28 12:07:58 +00:00
|
|
|
{
|
1997-05-06 10:26:19 +00:00
|
|
|
if (relation_remove())
|
|
|
|
{
|
|
|
|
query_mode();
|
|
|
|
if (_autoins_caller.not_empty() || _transaction.not_empty())
|
|
|
|
{
|
|
|
|
if (_lnflag) _recins = 0;
|
|
|
|
k = K_QUIT;
|
|
|
|
}
|
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
break;
|
1996-05-08 11:09:13 +00:00
|
|
|
case K_F9:
|
1996-07-12 14:51:17 +00:00
|
|
|
if (_mask->query_mode() || save(TRUE))
|
1995-11-07 11:38:23 +00:00
|
|
|
search_mode();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (save(TRUE))
|
|
|
|
{
|
|
|
|
setkey();
|
|
|
|
int err = ~NOERR;
|
|
|
|
switch (k)
|
|
|
|
{
|
|
|
|
case K_HOME:
|
|
|
|
err = file().readat(_first, _testandlock);
|
|
|
|
break;
|
|
|
|
case K_NEXT:
|
|
|
|
err = file().reread();
|
|
|
|
err = file().next(_testandlock);
|
|
|
|
break;
|
|
|
|
case K_PREV:
|
|
|
|
err = file().reread();
|
|
|
|
err = file().prev(_testandlock);
|
|
|
|
break;
|
|
|
|
case K_END:
|
|
|
|
err = file().readat(_last, _testandlock);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
if (err == NOERR || err == _islocked)
|
|
|
|
modify_mode();
|
|
|
|
else
|
|
|
|
query_mode();
|
1995-11-07 11:38:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (k != K_QUIT);
|
|
|
|
|
|
|
|
if (_mask->is_open())
|
|
|
|
_mask->close_modal();
|
|
|
|
|
|
|
|
_mask->set_mode(NO_MODE);
|
|
|
|
|
|
|
|
if (autoins_caller().not_empty() && _recins >= 0)
|
1996-07-24 08:34:48 +00:00
|
|
|
{
|
1996-07-24 09:52:16 +00:00
|
|
|
TMessage msg(autoins_caller(), _lnflag ? MSG_LN : MSG_AI, format("%ld", _recins));
|
1995-11-07 11:38:23 +00:00
|
|
|
msg.send();
|
|
|
|
}
|
1997-03-28 12:07:58 +00:00
|
|
|
|
|
|
|
if (_transaction.not_empty())
|
|
|
|
{
|
|
|
|
TConfig ini(_ini, "Transaction");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
1995-11-07 11:38:23 +00:00
|
|
|
|
|
|
|
return k != K_QUIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRelation_application::filter()
|
1997-03-28 12:07:58 +00:00
|
|
|
{
|
|
|
|
if (parse_command_line())
|
|
|
|
return TRUE;
|
|
|
|
|
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;
|
|
|
|
TEdit_field& f = (TEdit_field&)_mask->field(id);
|
|
|
|
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("");
|
|
|
|
cur->setregion(rec, rec);
|
|
|
|
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;
|
|
|
|
|
|
|
|
const char* v = body.get();
|
|
|
|
TString80 s;
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
s = v;
|
|
|
|
_fixed.add(format("%d=%s", f.dlg(), (const char*)s));
|
|
|
|
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;
|
|
|
|
TString80 t;
|
|
|
|
|
|
|
|
while((s = body.get()) != NULL)
|
|
|
|
{
|
|
|
|
t = s;
|
|
|
|
const int u = t.find('=');
|
|
|
|
|
|
|
|
CHECKS(u > 0, "Invalid edit message ", (const char *) body);
|
|
|
|
if (u > 0)
|
|
|
|
{
|
|
|
|
const TString v(t.mid(u + 1));
|
|
|
|
|
|
|
|
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
|
|
|
|
1996-07-24 08:34:48 +00:00
|
|
|
if (v)
|
1996-08-05 09:43:06 +00:00
|
|
|
_fixed.add(format("%d=%s", f.dlg(), (const char*)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();
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
const TString s(v);
|
|
|
|
_fixed.add(format("%d=%s", f.dlg(), (const char*) s));
|
|
|
|
v = body.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
bool TRelation_application::parse_command_line()
|
|
|
|
{
|
|
|
|
_ini = _transaction = "";
|
|
|
|
|
|
|
|
TFilename ini;
|
|
|
|
for (int i = argc()-1; i > 0; i--)
|
|
|
|
{
|
|
|
|
ini = argv(i);
|
|
|
|
ini.upper();
|
1997-04-08 12:20:57 +00:00
|
|
|
if (ini.left(2) == "-I" || ini.left(2) == "/I")
|
1997-03-28 12:07:58 +00:00
|
|
|
{
|
|
|
|
_ini = ini.mid(2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-05-15 14:09:47 +00:00
|
|
|
if (_ini.not_empty())
|
1997-03-28 12:07:58 +00:00
|
|
|
{
|
|
|
|
TConfig cnf(_ini, "Transaction");
|
|
|
|
_transaction = cnf.get("Action");
|
|
|
|
_transaction.upper();
|
1997-04-08 12:20:57 +00:00
|
|
|
|
|
|
|
long firm = cnf.get_long("Firm");
|
|
|
|
if (firm > 0)
|
|
|
|
{
|
|
|
|
bool ok = set_firm(firm);
|
|
|
|
_mask->on_firm_change();
|
|
|
|
if (!ok)
|
|
|
|
error_box("Ditta inesistente: %ld", firm);
|
|
|
|
}
|
1997-05-15 14:09:47 +00:00
|
|
|
|
|
|
|
if (_transaction == "RUN")
|
|
|
|
_lnflag = 0; // Ho gia' finito qui: basta il cambio ditta
|
|
|
|
else
|
|
|
|
_lnflag = 1; // Attiva automagia
|
1997-03-28 12:07:58 +00:00
|
|
|
}
|
1997-05-15 14:09:47 +00:00
|
|
|
|
1997-03-28 12:07:58 +00:00
|
|
|
return _lnflag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRelation_application::ini2query_mask()
|
|
|
|
{
|
|
|
|
if (_transaction.not_empty())
|
|
|
|
{
|
|
|
|
TConfig ini(_ini, format("%d", get_relation()->lfile().num()));
|
|
|
|
ini2mask(ini, *_mask, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRelation_application::ini2insert_mask()
|
|
|
|
{
|
|
|
|
if (_transaction.not_empty())
|
|
|
|
{
|
|
|
|
TConfig ini(_ini, format("%d", get_relation()->lfile().num()));
|
|
|
|
ini2mask(ini, *_mask, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRelation_application::ini2mask(TConfig& ini, TMask& m, bool query)
|
|
|
|
{
|
|
|
|
const TString defpar = ini.get_paragraph();
|
|
|
|
TString str;
|
|
|
|
for (int f = m.fields()-1; f >= 0; f--)
|
|
|
|
{
|
|
|
|
TMask_field& campo = m.fld(f);
|
|
|
|
if (campo.field())
|
|
|
|
{
|
|
|
|
if (!query || campo.in_key(1))
|
|
|
|
{
|
|
|
|
str = campo.field()->read(ini, defpar);
|
|
|
|
if (str.not_empty())
|
|
|
|
campo.set(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ini.set_paragraph(defpar);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRelation_application::edit_mask2ini()
|
|
|
|
{
|
|
|
|
if (_ini.not_empty())
|
|
|
|
{
|
|
|
|
TString head;
|
|
|
|
head.format("%d", get_relation()->lfile().num());
|
|
|
|
TConfig ini(_ini, head);
|
|
|
|
mask2ini(*_mask, ini);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRelation_application::mask2ini(TMask& m, TConfig& ini)
|
|
|
|
{
|
|
|
|
const TString defpar = ini.get_paragraph();
|
|
|
|
TString str;
|
|
|
|
for (int f = m.fields()-1; f >= 0; f--)
|
|
|
|
{
|
|
|
|
TMask_field& campo = m.fld(f);
|
|
|
|
if (campo.field() && campo.shown())
|
|
|
|
{
|
|
|
|
str = campo.get();
|
|
|
|
campo.field()->write(ini, defpar, str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|