1997-01-10 14:04:33 +00:00
|
|
|
#include <prefix.h>
|
1995-05-09 16:06:12 +00:00
|
|
|
#include <relapp.h>
|
1997-01-10 14:04:33 +00:00
|
|
|
|
1996-08-26 08:22:26 +00:00
|
|
|
#include <nditte.h>
|
1997-01-10 14:04:33 +00:00
|
|
|
|
1995-05-09 16:06:12 +00:00
|
|
|
#include "batbinl.h"
|
|
|
|
|
|
|
|
class TIndici_app : public TRelation_application
|
|
|
|
{
|
|
|
|
TRelation* _indici;
|
|
|
|
TMask* _maschera;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool user_create();
|
|
|
|
virtual bool user_destroy();
|
|
|
|
|
|
|
|
virtual bool changing_mask(int) { return FALSE; }
|
|
|
|
virtual TMask* get_mask(int) { return _maschera; }
|
|
|
|
virtual TRelation* get_relation() const { return _indici; }
|
|
|
|
|
1998-05-04 09:42:27 +00:00
|
|
|
virtual bool get_next_key(TToken_string& key);
|
1996-08-26 08:22:26 +00:00
|
|
|
virtual bool save_and_new() const { return TRUE; }
|
|
|
|
virtual int read(TMask& m);
|
1997-02-21 09:54:33 +00:00
|
|
|
virtual void init_query_mode(TMask& m);
|
1996-08-26 08:22:26 +00:00
|
|
|
|
|
|
|
static bool ditta_handler(TMask_field& f, KEY key);
|
|
|
|
static TIndici_app& app() { return (TIndici_app&) main_app(); }
|
1995-05-09 16:06:12 +00:00
|
|
|
|
|
|
|
public:
|
1998-05-04 09:42:27 +00:00
|
|
|
TIndici_app() { }
|
1997-01-10 14:04:33 +00:00
|
|
|
virtual ~TIndici_app() { }
|
1995-05-09 16:06:12 +00:00
|
|
|
};
|
1996-08-26 08:22:26 +00:00
|
|
|
|
|
|
|
bool TIndici_app::ditta_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
1997-02-21 09:54:33 +00:00
|
|
|
/*
|
1997-01-10 14:04:33 +00:00
|
|
|
if (key == K_TAB && f.to_check(key, TRUE) && f.empty())
|
1996-08-26 08:22:26 +00:00
|
|
|
{
|
1997-01-10 14:04:33 +00:00
|
|
|
TMask& m = f.mask();
|
|
|
|
m.reset(F_CODREG); m.reset(F_DESCREG);
|
|
|
|
m.disable(F_CODREG); m.disable(F_DESCREG);
|
|
|
|
return TRUE;
|
1996-08-26 08:22:26 +00:00
|
|
|
}
|
1997-02-21 09:54:33 +00:00
|
|
|
*/
|
|
|
|
if ((key == K_TAB && f.to_check(key)/*f.focusdirty()*/) || key == K_ENTER)
|
1996-08-26 08:22:26 +00:00
|
|
|
{
|
|
|
|
const long ditta = atol(f.get());
|
1997-01-10 14:04:33 +00:00
|
|
|
if (ditta == 0L)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
TMask& m = f.mask();
|
1996-08-26 08:22:26 +00:00
|
|
|
if (prefix().exist(ditta))
|
|
|
|
{
|
|
|
|
app().set_firm(ditta);
|
|
|
|
m.enable(F_CODREG); m.enable(F_DESCREG);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m.reset(F_CODREG);m.reset(F_DESCREG);
|
|
|
|
m.disable(F_CODREG); m.disable(F_DESCREG);
|
1997-01-10 14:04:33 +00:00
|
|
|
return f.error_box("La ditta %5ld non e' abilitata in contabilita'", ditta);
|
1996-08-26 08:22:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1997-02-21 09:54:33 +00:00
|
|
|
void TIndici_app::init_query_mode(TMask& m)
|
|
|
|
{
|
|
|
|
m.enable(F_CODREG);m.enable(F_DESCREG);
|
|
|
|
}
|
|
|
|
|
1996-08-26 08:22:26 +00:00
|
|
|
int TIndici_app::read(TMask& m)
|
|
|
|
{
|
|
|
|
int r = TRelation_application::read(m);
|
|
|
|
long ditta = m.get_long(F_DITTA);
|
|
|
|
if (ditta > 0L)
|
|
|
|
if (prefix().exist(ditta))
|
|
|
|
set_firm(ditta);
|
|
|
|
else
|
1997-02-21 09:54:33 +00:00
|
|
|
{
|
|
|
|
error_box("Ditta %5ld non abilitata in contabilita'",ditta);
|
|
|
|
//m.reset(F_CODREG);m.reset(F_DESCREG);
|
|
|
|
m.disable(F_CODREG); m.disable(F_DESCREG);
|
|
|
|
}
|
1996-08-26 08:22:26 +00:00
|
|
|
return r;
|
|
|
|
}
|
1995-05-09 16:06:12 +00:00
|
|
|
|
|
|
|
bool TIndici_app::user_create()
|
|
|
|
{
|
1996-08-26 08:22:26 +00:00
|
|
|
if (get_firm() == 0) // Se e' posizionato nel direttorio comune, setta la prima ditta abilitata in contabilita'
|
|
|
|
{
|
|
|
|
TLocalisamfile ditte(LF_NDITTE);
|
1997-01-10 14:04:33 +00:00
|
|
|
|
|
|
|
bool found = FALSE;
|
1996-08-26 08:22:26 +00:00
|
|
|
long ditta = 0L;
|
1996-09-12 12:58:34 +00:00
|
|
|
for (ditte.first(); !found && !ditte.eof(); ditte.next())
|
1996-08-26 08:22:26 +00:00
|
|
|
{
|
|
|
|
ditta = ditte.get_long(NDT_CODDITTA);
|
1997-01-10 14:04:33 +00:00
|
|
|
found = prefix().exist(ditta);
|
1996-08-26 08:22:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
error_box("Abilitare almeno una ditta in contabilita'.");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
set_firm(ditta);
|
|
|
|
}
|
1995-05-09 16:06:12 +00:00
|
|
|
_indici = new TRelation(LF_INDLIB);
|
|
|
|
_maschera = new TMask("batbinl");
|
1996-08-26 08:22:26 +00:00
|
|
|
_maschera->set_handler(F_DITTA, ditta_handler);
|
1995-05-09 16:06:12 +00:00
|
|
|
return TRUE;
|
1996-09-12 12:58:34 +00:00
|
|
|
}
|
1995-05-09 16:06:12 +00:00
|
|
|
|
|
|
|
bool TIndici_app::user_destroy()
|
|
|
|
{
|
|
|
|
delete _maschera;
|
|
|
|
delete _indici;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-05-04 09:42:27 +00:00
|
|
|
bool TIndici_app::get_next_key(TToken_string& key)
|
1995-05-09 16:06:12 +00:00
|
|
|
{
|
|
|
|
const int anno = _maschera->get_int(F_ANNO);
|
|
|
|
const TString16 libro = _maschera->get(F_CODLIB);
|
|
|
|
if (anno == 0 || libro.empty())
|
1998-05-04 09:42:27 +00:00
|
|
|
return TRUE;
|
1995-05-09 16:06:12 +00:00
|
|
|
|
|
|
|
TLocalisamfile index(LF_INDLIB);
|
|
|
|
index.zero();
|
|
|
|
index.put("ANNO", anno);
|
|
|
|
index.put("CODLIB", libro);
|
|
|
|
index.put("NUMREG", 9999999L);
|
|
|
|
|
|
|
|
long cod = 0;
|
|
|
|
int err = index.read(_isgteq);
|
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
case _iseof:
|
|
|
|
index.last();
|
|
|
|
err = NOERR;
|
|
|
|
break;
|
|
|
|
case NOERR:
|
|
|
|
index.prev();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
if (index.get_int("ANNO") == anno && index.get("CODLIB") == libro)
|
|
|
|
cod = index.get_long("NUMREG") + 1;
|
|
|
|
}
|
1995-11-23 14:18:44 +00:00
|
|
|
|
|
|
|
if (cod > 0)
|
1998-05-04 09:42:27 +00:00
|
|
|
key.format("%d|%d|%d|%s|%d|%ld", F_ANNO, anno, F_CODLIB, (const char*)libro, F_INDEX, cod);
|
1995-11-23 14:18:44 +00:00
|
|
|
|
1998-05-04 09:42:27 +00:00
|
|
|
return TRUE;
|
1995-05-09 16:06:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ba3900(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TIndici_app app;
|
|
|
|
app.run(argc, argv, "Indici libro unico");
|
|
|
|
return 0;
|
|
|
|
}
|