2003-11-05 10:20:31 +00:00
|
|
|
#include <diction.h>
|
1994-11-10 14:17:03 +00:00
|
|
|
#include <expr.h>
|
1999-03-22 15:55:50 +00:00
|
|
|
#include <isam.h>
|
1994-11-10 14:17:03 +00:00
|
|
|
#include <mask.h>
|
|
|
|
#include <validate.h>
|
1999-03-22 15:55:50 +00:00
|
|
|
#include <defmask.h>
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
#include <comuni.h>
|
1994-11-10 14:17:03 +00:00
|
|
|
#include <nditte.h>
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
typedef bool (*VAL_FUNC)(TMask_field&, KEY k);
|
2008-03-20 17:11:59 +00:00
|
|
|
HIDDEN const TString_array* _parms;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2008-02-01 16:38:43 +00:00
|
|
|
HIDDEN int get_val_param_count()
|
|
|
|
{ return _parms->items(); }
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2008-03-20 17:11:59 +00:00
|
|
|
HIDDEN const TString& get_val_param(int i)
|
|
|
|
{
|
|
|
|
const TString* str = (const TString*)_parms->objptr(i);
|
|
|
|
if (str && *str)
|
|
|
|
return *str;
|
|
|
|
return EMPTY_STRING;
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
|
|
|
|
HIDDEN int get_int_val_param(int i)
|
|
|
|
{ return atoi(get_val_param(i)); }
|
|
|
|
|
|
|
|
HIDDEN const TString& get_fld_val_param(const TMask_field& f, int i)
|
|
|
|
{
|
2009-06-11 14:52:46 +00:00
|
|
|
const TString & id = get_val_param(i);
|
|
|
|
return f.evaluate_field(id);
|
2007-09-17 15:33:04 +00:00
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _expr_val(TMask_field& f, KEY)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const TMask& m = f.mask();
|
2009-06-11 14:52:46 +00:00
|
|
|
const TTypeexp type = get_int_val_param(0) == 0 ? _numexpr : _strexpr;
|
2007-09-17 15:33:04 +00:00
|
|
|
TExpression e(get_val_param(1), type);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
for (int i = 0; i < e.numvar(); i++)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
const char* s = e.varname(i);
|
2008-11-14 00:40:30 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
if (s[0] != '#')
|
|
|
|
{
|
2007-07-06 10:17:28 +00:00
|
|
|
TString err; err << TR("Le variabili devono cominciare con #") << ": " << s << '\n' << e;
|
1994-11-10 14:17:03 +00:00
|
|
|
return f.error_box((const char*)err);
|
|
|
|
}
|
2008-11-14 00:40:30 +00:00
|
|
|
if (type == _numexpr)
|
|
|
|
{
|
|
|
|
const real r = f.evaluate_field(s);
|
|
|
|
e.setvar(i, r);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
e.setvar(i, f.evaluate_field(s));
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
return bool(e);
|
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _emptycopy_val(TMask_field& f, KEY)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2003-05-13 15:12:54 +00:00
|
|
|
if (f.empty())
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2008-01-31 15:18:01 +00:00
|
|
|
const TString& val = get_fld_val_param(f, 0);
|
1994-11-10 14:17:03 +00:00
|
|
|
if (val.not_empty())
|
|
|
|
{
|
|
|
|
f.set(val);
|
|
|
|
f.on_hit();
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
2002-05-08 16:25:49 +00:00
|
|
|
bool check_pi_estera(const TString& st, const TString& paiva)
|
|
|
|
{
|
|
|
|
const char* stpi[] = { "AT09", "BE09", "DE09", "DK08", "EL08", "ES09",
|
|
|
|
"FI08", "FR11", "GB05", "GB09", "GB12", "IE08",
|
|
|
|
"LU08", "NL12", "PT09", "SE12", "SM05", NULL };
|
2007-09-17 15:33:04 +00:00
|
|
|
bool lenok = false;
|
|
|
|
bool known = false;
|
2002-05-08 16:25:49 +00:00
|
|
|
|
|
|
|
for (int g = 0; stpi[g] && !lenok; g++)
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (st.compare(stpi[g], 2, true) == 0) // Se lo stato corrisponde
|
2002-05-08 16:25:49 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
known = true;
|
2002-05-08 16:25:49 +00:00
|
|
|
lenok = paiva.len() == atoi(stpi[g]+2); // Confronto lunghezza
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (known) // Inutile cercare ancora
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (known)
|
|
|
|
{
|
|
|
|
if (st=="AT") // Controllo speciale per l'Austria che comincia per U
|
|
|
|
lenok &= (paiva[0] == 'U');
|
|
|
|
}
|
|
|
|
else
|
2007-09-17 15:33:04 +00:00
|
|
|
lenok = true; // Gli stati ignoti hanno sempre lunghezza corretta!
|
2002-05-08 16:25:49 +00:00
|
|
|
return lenok;
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
|
|
|
|
1996-01-31 17:19:02 +00:00
|
|
|
// @func Controlla se la Partita IVA assume un valore valido
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori:
|
|
|
|
//
|
2007-09-17 15:33:04 +00:00
|
|
|
// @flag true | Se il valore della Partita IVA assume un valore corretto
|
|
|
|
// @flag false | Se il valore della Partita IVA non puo' essere valido
|
1996-01-31 17:19:02 +00:00
|
|
|
bool pi_check(
|
1996-05-08 11:09:13 +00:00
|
|
|
const char* st, // @parm Stato di assegnazione della Partita IVA
|
|
|
|
const char* paiva) // @parm Codice della Partita IVA da controllare
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1999-02-02 08:43:43 +00:00
|
|
|
const TFixed_string stato(st);
|
|
|
|
const TFixed_string pi(paiva);
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (pi.blank())
|
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
bool ok = true; // Assumiamo ottimisticamente che tutto va be'
|
1999-02-02 08:43:43 +00:00
|
|
|
|
|
|
|
if (stato.blank() || stato == "IT")
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1999-02-02 08:43:43 +00:00
|
|
|
// Testa partita iva italiana
|
2007-09-17 15:33:04 +00:00
|
|
|
ok = pi.len() == 11 && real::is_natural(pi);
|
1999-02-02 08:43:43 +00:00
|
|
|
if (ok)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1999-02-02 08:43:43 +00:00
|
|
|
int tot = 0, y;
|
|
|
|
for (int i = 0; i <= 9; i++)
|
|
|
|
{
|
|
|
|
if ((i + 1) & 0x0001)
|
|
|
|
tot += (pi[i] - '0');
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y = (pi[i] - '0') * 2;
|
|
|
|
if (y >= 10)
|
|
|
|
{
|
|
|
|
tot += (y / 10);
|
|
|
|
y = y % 10;
|
|
|
|
}
|
|
|
|
tot += y;
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
1999-02-02 08:43:43 +00:00
|
|
|
y = 10 - (tot % 10);
|
|
|
|
if (y == 10) y = 0;
|
|
|
|
ok = (pi[10] == (y + '0'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-05-08 16:25:49 +00:00
|
|
|
{
|
|
|
|
ok = check_pi_estera(stato, pi);
|
1999-02-02 08:43:43 +00:00
|
|
|
}
|
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1999-03-22 15:55:50 +00:00
|
|
|
|
|
|
|
// Controlla la partita iva se e' non vuota ed italiana
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _pi_val(TMask_field& f, KEY)
|
1999-03-22 15:55:50 +00:00
|
|
|
{
|
|
|
|
const TMask& m = f.mask();
|
1999-02-02 08:43:43 +00:00
|
|
|
if (m.query_mode())
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1999-03-22 15:55:50 +00:00
|
|
|
|
2008-03-20 17:11:59 +00:00
|
|
|
const TString& stato = m.get(get_int_val_param(0));
|
1999-02-02 08:43:43 +00:00
|
|
|
const TString& pi = f.get();
|
2002-12-18 10:56:10 +00:00
|
|
|
bool ok = pi_check (stato, pi);
|
1994-11-10 14:17:03 +00:00
|
|
|
if (!ok)
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
if (f.dirty())
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
bool len_error = true;
|
2002-12-18 10:56:10 +00:00
|
|
|
if (stato.blank() || stato == "IT")
|
|
|
|
len_error = pi.len() != 11;
|
2007-09-17 15:33:04 +00:00
|
|
|
TString msg = len_error ? TR("Lunghezza partita IVA errata") : TR("Partita IVA errata");
|
|
|
|
msg << ": " << TR("proseguire ugualmente?");
|
|
|
|
ok = f.yesno_box(msg);
|
|
|
|
if (ok) f.set_dirty(false);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
else ok = true; // Era gia' errata e la ho accettata
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-28 11:33:54 +00:00
|
|
|
HIDDEN bool __cf_check (const char* codcf)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2006-11-28 11:33:54 +00:00
|
|
|
const TFixed_string cf(codcf);
|
|
|
|
if (cf.len() != 16)
|
|
|
|
return false;
|
1994-11-10 14:17:03 +00:00
|
|
|
const TFixed_string tab("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
|
|
|
|
|
|
|
|
int tot = 0, y;
|
|
|
|
|
|
|
|
byte val[36][2];
|
|
|
|
|
|
|
|
val[0][0] = 0; val[0][1] = 1;
|
|
|
|
val[1][0] = 1; val[1][1] = 0;
|
|
|
|
val[2][0] = 2; val[2][1] = 5;
|
|
|
|
val[3][0] = 3; val[3][1] = 7;
|
|
|
|
val[4][0] = 4; val[4][1] = 9;
|
|
|
|
val[5][0] = 5; val[5][1] = 13;
|
|
|
|
val[6][0] = 6; val[6][1] = 15;
|
|
|
|
val[7][0] = 7; val[7][1] = 17;
|
|
|
|
val[8][0] = 8; val[8][1] = 19;
|
|
|
|
val[9][0] = 9; val[9][1] = 21;
|
|
|
|
val[10][0] = 10; val[10][1] = 2;
|
|
|
|
val[11][0] = 11; val[11][1] = 4;
|
|
|
|
val[12][0] = 12; val[12][1] = 18;
|
|
|
|
val[13][0] = 13; val[13][1] = 20;
|
|
|
|
val[14][0] = 14; val[14][1] = 11;
|
|
|
|
val[15][0] = 15; val[15][1] = 3;
|
|
|
|
val[16][0] = 16; val[16][1] = 6;
|
|
|
|
val[17][0] = 17; val[17][1] = 8;
|
|
|
|
val[18][0] = 18; val[18][1] = 12;
|
|
|
|
val[19][0] = 19; val[19][1] = 14;
|
|
|
|
val[20][0] = 20; val[20][1] = 16;
|
|
|
|
val[21][0] = 21; val[21][1] = 10;
|
|
|
|
val[22][0] = 22; val[22][1] = 22;
|
|
|
|
val[23][0] = 23; val[23][1] = 25;
|
|
|
|
val[24][0] = 24; val[24][1] = 24;
|
|
|
|
val[25][0] = 25; val[25][1] = 23;
|
|
|
|
val[26][0] = 0; val[26][1] = 1;
|
|
|
|
val[27][0] = 1; val[27][1] = 0;
|
|
|
|
val[28][0] = 2; val[28][1] = 5;
|
|
|
|
val[29][0] = 3; val[29][1] = 7;
|
|
|
|
val[30][0] = 4; val[30][1] = 9;
|
|
|
|
val[31][0] = 5; val[31][1] = 13;
|
|
|
|
val[32][0] = 6; val[32][1] = 15;
|
|
|
|
val[33][0] = 7; val[33][1] = 17;
|
|
|
|
val[34][0] = 8; val[34][1] = 19;
|
|
|
|
val[35][0] = 9; val[35][1] = 21;
|
|
|
|
|
|
|
|
for (int i = 0; i <= 14; i++)
|
|
|
|
{
|
|
|
|
y = tab.find(cf[i]);
|
|
|
|
if (y >= 0) tot += val[y][(i + 1) & 0x1];
|
|
|
|
}
|
|
|
|
const bool ok = (cf[15] == (tot % 26) + 'A');
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc EXTERNAL
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1996-01-31 17:19:02 +00:00
|
|
|
// @func Controlla se il Codice Fiscale assume un valore valido
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna i seguenti valori:
|
|
|
|
//
|
2007-09-17 15:33:04 +00:00
|
|
|
// @flag true | Se il valore del Codice Fiscale assume un valore corretto
|
|
|
|
// @flag false | Se il valore del Codice Fiscale non puo' essere valido
|
1996-01-31 17:19:02 +00:00
|
|
|
|
|
|
|
bool cf_check (
|
|
|
|
const char* stato, // @parm Stato di assegnazione del Codice Fiscale
|
|
|
|
const char* codcf) // @parm Codice Fiscale da controllare
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
bool ok = true;
|
|
|
|
if (codcf && *codcf)
|
|
|
|
{
|
|
|
|
const TFixed_string cf = codcf;
|
|
|
|
ok = (cf.len() == 11 && isdigit(cf[0])) ? pi_check(stato, cf) : __cf_check(cf);
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _cf_val(TMask_field& f, KEY key)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (f.mask().query_mode())
|
|
|
|
return TRUE;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString& cf = f.get();
|
1994-11-10 14:17:03 +00:00
|
|
|
bool ok = TRUE;
|
|
|
|
|
|
|
|
if (cf.empty()) return TRUE;
|
|
|
|
if (cf.len() == 11 && isdigit(cf[0]))
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString& stato = f.mask().get(atoi(get_val_param(0)));
|
|
|
|
if (stato.full() && stato != "IT")
|
|
|
|
return TRUE;
|
1994-11-10 14:17:03 +00:00
|
|
|
ok = pi_check (stato, cf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ok = __cf_check(cf);
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
if(f.dirty())
|
|
|
|
{
|
2007-01-25 15:42:56 +00:00
|
|
|
ok = f.yesno_box(TR("Codice fiscale errato: lo accetto ugualmente?"));
|
1994-11-10 14:17:03 +00:00
|
|
|
if (ok) f.set_dirty(FALSE);
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
else
|
|
|
|
ok = true; // Era gia' errato al caricamento quindi lo accetto
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
HIDDEN bool _xt_pi_val(TMask_field& f, KEY key)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
TMask& m = f.mask();
|
2007-09-17 15:33:04 +00:00
|
|
|
if (m.query_mode())
|
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TString16 value = f.get();
|
1999-02-02 08:43:43 +00:00
|
|
|
if (value.empty())
|
2007-01-25 15:42:56 +00:00
|
|
|
return f.error_box(TR("Partita IVA obbligatoria"));
|
1999-03-22 15:55:50 +00:00
|
|
|
|
1999-02-02 08:43:43 +00:00
|
|
|
if (!_pi_val(f, key))
|
2009-03-27 14:39:28 +00:00
|
|
|
return true;
|
1999-03-22 15:55:50 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString& stato = get_fld_val_param(f, 0);
|
|
|
|
if (stato.blank() || stato == "IT")
|
1999-03-22 15:55:50 +00:00
|
|
|
{
|
|
|
|
TLocalisamfile c(LF_COMUNI);
|
|
|
|
const int pi = atoi(value.mid(7,3));
|
1999-02-02 08:43:43 +00:00
|
|
|
for (int i = 1 ; i < 3; i++)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString& com = get_fld_val_param(f, i); // Comune residenza fiscale e residenza
|
|
|
|
if (com.full())
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1999-03-22 15:55:50 +00:00
|
|
|
c.zero();
|
|
|
|
c.put("COM", com);
|
|
|
|
if (c.read() == NOERR)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const int s1 = c.get_int(COM_UFFIVA1);
|
|
|
|
const int s2 = c.get_int(COM_UFFIVA2);
|
|
|
|
const int s3 = c.get_int(COM_UFFIVA3);
|
1994-11-10 14:17:03 +00:00
|
|
|
if (pi != s1 && pi != s2 && pi != s3)
|
|
|
|
{
|
1997-08-26 13:56:55 +00:00
|
|
|
TString16 ui; ui.format("%03d", s1);
|
2007-01-25 15:42:56 +00:00
|
|
|
if (f.yesno_box(FR("Ufficio IVA della partita IVA non congruente: correggere in %s?"),
|
1997-08-26 13:56:55 +00:00
|
|
|
(const char*)ui))
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
value.overwrite(ui, 7);
|
|
|
|
f.set(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _xtz_pi_val(TMask_field& f, KEY key)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
return f.empty() || _xt_pi_val(f, key);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _xt_cf_val(TMask_field& f, KEY key)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (f.mask().query_mode())
|
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
TString16 cf = f.get();
|
|
|
|
if (cf.blank())
|
2009-03-27 14:39:28 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (!_cf_val(f, key))
|
|
|
|
return false;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (cf.len() == 11 && real::is_natural(cf))
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
// if (!_xt_pi_val(f, key)) return false;
|
1994-11-10 14:17:03 +00:00
|
|
|
// TString16 stato(f.mask().get(atoi(get_val_param(0))));
|
2007-09-17 15:33:04 +00:00
|
|
|
// if ((stato.not_empty()) && (stato != "IT")) return true;
|
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool passed = __cf_check(cf);
|
2007-09-17 15:33:04 +00:00
|
|
|
if (!passed) return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
TMask& m = f.mask();
|
|
|
|
|
2008-03-20 17:11:59 +00:00
|
|
|
TMask_field& fld_sex = m.field(get_int_val_param(1));
|
|
|
|
TMask_field& fld_dat = m.field(get_int_val_param(2));
|
|
|
|
TMask_field& fld_com = m.field(get_int_val_param(3));
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
const char sesso = fld_sex.get()[0];
|
2007-09-17 15:33:04 +00:00
|
|
|
TString16 data = fld_dat.get();
|
|
|
|
TString4 com = fld_com.get();
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
TString16 wm("LMNPQRSTUV");
|
|
|
|
int p;
|
2007-09-17 15:33:04 +00:00
|
|
|
if ((p = wm.find(cf[ 6])) >= 0) cf[ 6] = '0' + p;
|
|
|
|
if ((p = wm.find(cf[ 7])) >= 0) cf[ 7] = '0' + p;
|
|
|
|
if ((p = wm.find(cf[ 9])) >= 0) cf[ 9] = '0' + p;
|
|
|
|
if ((p = wm.find(cf[10])) >= 0) cf[10] = '0' + p;
|
|
|
|
if ((p = wm.find(cf[12])) >= 0) cf[12] = '0' + p;
|
|
|
|
if ((p = wm.find(cf[13])) >= 0) cf[13] = '0' + p;
|
|
|
|
if ((p = wm.find(cf[14])) >= 0) cf[14] = '0' + p;
|
1994-11-10 14:17:03 +00:00
|
|
|
int gn = atoi(cf.mid(9,2));
|
|
|
|
|
|
|
|
if ((sesso == 'F' && gn < 40) || (sesso == 'M' && gn > 40))
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
passed = passed = fld_sex.yesno_box(TR("Sesso non congruente al codice fiscale:\n"
|
|
|
|
"correzione automatica?"));
|
1994-11-10 14:17:03 +00:00
|
|
|
if (passed) fld_sex.set(sesso == 'M' ? "F" : "M");
|
2007-09-17 15:33:04 +00:00
|
|
|
else return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (gn > 40) gn -= 40; // Aggiusta giorno di nascita delle donne
|
|
|
|
|
|
|
|
// Controllo data di nascita
|
|
|
|
wm = "ABCDEHLMPRST";
|
|
|
|
if (data.not_empty())
|
|
|
|
{
|
|
|
|
const TDate d(data);
|
|
|
|
int err = 0;
|
|
|
|
if ((d.year() % 100) != atoi(cf.mid(6, 2)))
|
|
|
|
err = 1;
|
|
|
|
if (wm[d.month() - 1] != cf[8])
|
|
|
|
err = 2;
|
|
|
|
if (d.day() != gn)
|
|
|
|
err = 3;
|
|
|
|
if (err != 0)
|
|
|
|
{
|
2007-01-25 15:42:56 +00:00
|
|
|
const char* const what = err==1 ? TR("Anno") : (err==2 ? TR("Mese") : TR("Giorno"));
|
|
|
|
passed = fld_dat.yesno_box(FR("%s di nascita non congruente al codice fiscale: correzione automatica?"), what);
|
2007-09-17 15:33:04 +00:00
|
|
|
if (passed) data.cut(0);
|
|
|
|
else return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
if (data.blank())
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
const int mn = wm.find(cf[8]) + 1;
|
|
|
|
if (mn > 0)
|
|
|
|
{
|
|
|
|
const TDate d(gn, mn, 1900 + atoi(cf.mid(6, 2)));
|
|
|
|
fld_dat.set(d.string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Controllo del comune di nascita
|
|
|
|
const char* const codcom = cf.mid(11, 4);
|
2007-09-17 15:33:04 +00:00
|
|
|
if (com.full() && com != codcom)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-01-25 15:42:56 +00:00
|
|
|
passed = fld_com.yesno_box(TR("Comune non congruente al codice fiscale: correzione automatica?"));
|
2007-09-17 15:33:04 +00:00
|
|
|
if (passed) com.cut(0);
|
|
|
|
else return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
if (com.empty())
|
|
|
|
{
|
|
|
|
fld_com.set(codcom);
|
|
|
|
fld_com.on_key(K_TAB);
|
|
|
|
}
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-05 10:20:31 +00:00
|
|
|
HIDDEN bool _xtz_cf_val(TMask_field& f, KEY key)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
return f.empty() || _xt_cf_val(f, key);
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 10:05:30 +00:00
|
|
|
HIDDEN bool _notempty_val(TMask_field& f, KEY)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
return f.mask().query_mode() || !f.empty();
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _date_cmp(TMask_field& f, KEY)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString& s = f.get();
|
|
|
|
if (s.empty())
|
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const TDate d0(s), d1(get_fld_val_param(f, 1));
|
|
|
|
const TFixed_string op(get_val_param(0));
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
if (op == "==") return d0 == d1;
|
|
|
|
if (op == "!=") return d0 != d1;
|
2007-09-17 15:33:04 +00:00
|
|
|
if (op == ">") return d0 > d1;
|
|
|
|
if (op == "<") return d0 < d1;
|
1994-11-10 14:17:03 +00:00
|
|
|
if (op == ">=") return d0 >= d1;
|
|
|
|
if (op == "<=") return d0 <= d1;
|
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
f.error_box("Bad date operator '%s' in field %d", (const char*) op, f.dlg());
|
|
|
|
#endif
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
return false;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
2007-07-06 10:17:28 +00:00
|
|
|
HIDDEN bool _fixlen_val(TMask_field& f, KEY)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-07-06 10:17:28 +00:00
|
|
|
if (f.empty())
|
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-07-06 10:17:28 +00:00
|
|
|
const TString& s = f.get();
|
2008-01-31 15:18:01 +00:00
|
|
|
const int length = get_int_val_param(0);
|
1994-11-10 14:17:03 +00:00
|
|
|
const bool ok = s.len() == length;
|
2007-07-06 10:17:28 +00:00
|
|
|
if (!ok)
|
|
|
|
f.error_box(FR("La lunghezza del campo deve essere %d"), length);
|
1994-11-10 14:17:03 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _mtcheck_val(TMask_field& f, KEY)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
const int month = atoi(f.get());
|
2007-09-17 15:33:04 +00:00
|
|
|
if (month < 1 || month > 13)
|
|
|
|
return false;
|
2001-09-19 14:52:11 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
TLocalisamfile d(LF_NDITTE);
|
1997-08-26 13:56:55 +00:00
|
|
|
d.put(NDT_CODDITTA, prefix().get_codditta());
|
2007-09-17 15:33:04 +00:00
|
|
|
if (d.read() != NOERR)
|
|
|
|
return true;
|
|
|
|
if (d.get_char(NDT_FREQVIVA) == 'M')
|
|
|
|
return true;
|
1996-05-08 11:09:13 +00:00
|
|
|
return month == 13 || (month % 3) == 0;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _reqif_val(TMask_field& f, KEY k)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2005-02-17 18:13:12 +00:00
|
|
|
if (k == K_ENTER && f.empty())
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const int nparms = get_val_param_count();
|
2008-11-14 00:40:30 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
for (int i = 0; i < nparms; i++)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const TString& fld = get_fld_val_param(f, i);
|
|
|
|
if (fld.full())
|
2005-02-17 18:13:12 +00:00
|
|
|
return false;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
}
|
2005-02-17 18:13:12 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _autoexit_val(TMask_field& f, KEY key)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
1999-03-22 15:55:50 +00:00
|
|
|
TMask& m = f.mask();
|
|
|
|
|
|
|
|
if (!m.query_mode() || key == K_ENTER)
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1995-03-29 15:44:53 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const int nparms = get_val_param_count();
|
|
|
|
bool one_not_empty = false;
|
|
|
|
for (int i = nparms-1; i >= 0; i--)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const short id = get_int_val_param(i);
|
|
|
|
const int pos = m.id2pos(id);
|
|
|
|
if (pos >= 0)
|
|
|
|
{
|
|
|
|
const TMask_field& c = m.fld(pos);
|
|
|
|
if (c.empty())
|
|
|
|
{
|
|
|
|
if (c.check_type() != CHECK_NONE || one_not_empty)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
one_not_empty = true;
|
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1995-11-07 10:05:30 +00:00
|
|
|
if (one_not_empty)
|
2007-09-17 15:33:04 +00:00
|
|
|
m.stop_run(K_AUTO_ENTER);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _numcalc_val(TMask_field& f, KEY k)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (k != K_TAB) return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
TExpression e(get_val_param(0), _numexpr);
|
|
|
|
|
2008-03-20 17:11:59 +00:00
|
|
|
for (int i = 0; i < e.numvar(); i++)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
const char* s = e.varname(i);
|
2008-11-14 00:40:30 +00:00
|
|
|
|
|
|
|
if (s[0] != '#')
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2003-11-10 15:01:49 +00:00
|
|
|
TString err; err << "Cannot load variable " << s << " in " << e;
|
1994-11-10 14:17:03 +00:00
|
|
|
return f.error_box((const char*)err);
|
|
|
|
}
|
2008-11-14 00:40:30 +00:00
|
|
|
e.setvar(i, f.evaluate_field(s));
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
2003-11-10 15:01:49 +00:00
|
|
|
const TString& s = e.as_string();
|
1994-11-10 14:17:03 +00:00
|
|
|
f.set(s);
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _strcalc_val(TMask_field& f, KEY k)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
if (k != K_TAB) return true;
|
2003-11-10 15:01:49 +00:00
|
|
|
TExpression e(get_val_param(0), _strexpr);
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
for (int i = 0 ; i < e.numvar(); i++)
|
|
|
|
{
|
|
|
|
const char* s = e.varname(i);
|
|
|
|
if (s[0] != '#')
|
|
|
|
{
|
2003-11-10 15:01:49 +00:00
|
|
|
TString err; err << "Cannot load variable " << s << " in " << e;
|
1994-11-10 14:17:03 +00:00
|
|
|
return f.error_box((const char*)err);
|
|
|
|
}
|
2008-11-14 00:40:30 +00:00
|
|
|
e.setvar(i, f.evaluate_field(s));
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
2003-11-10 15:01:49 +00:00
|
|
|
const TString& s = e.as_string();
|
1994-11-10 14:17:03 +00:00
|
|
|
f.set(s);
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _onereq_val(TMask_field& f, KEY k)
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
2008-01-31 15:18:01 +00:00
|
|
|
if (k != K_ENTER|| f.mask().mode() == MODE_QUERY)
|
|
|
|
return true;
|
|
|
|
|
2007-09-17 15:33:04 +00:00
|
|
|
const int nparms = get_val_param_count();
|
2008-11-14 00:40:30 +00:00
|
|
|
|
1994-11-10 14:17:03 +00:00
|
|
|
for (int i = 0; i < nparms ; i++)
|
|
|
|
{
|
2008-01-31 15:18:01 +00:00
|
|
|
const TString& s = get_fld_val_param(f, i);
|
|
|
|
if (s.full())
|
|
|
|
return true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
return false;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _chkfld_val(TMask_field& f, KEY k)
|
1994-11-29 17:31:11 +00:00
|
|
|
{
|
|
|
|
if (f.to_check(k))
|
|
|
|
{
|
2008-03-20 17:11:59 +00:00
|
|
|
const int fldid = get_int_val_param(0);
|
1995-01-12 18:40:10 +00:00
|
|
|
|
|
|
|
if (fldid == THIS_FIELD)
|
|
|
|
{
|
|
|
|
if (!f.required() && f.get().empty())
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1995-01-12 18:40:10 +00:00
|
|
|
else
|
|
|
|
return f.check();
|
|
|
|
}
|
1994-11-29 17:31:11 +00:00
|
|
|
|
1995-01-12 18:40:10 +00:00
|
|
|
TMask_field & chkfld = f.mask().field(fldid);
|
|
|
|
|
1994-11-29 17:31:11 +00:00
|
|
|
chkfld.set(f.get());
|
|
|
|
return chkfld.check();
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-11-29 17:31:11 +00:00
|
|
|
}
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _filename_val(TMask_field& f, KEY)
|
1994-12-02 13:30:45 +00:00
|
|
|
{
|
|
|
|
const TFilename fn(f.get());
|
1997-10-07 14:29:35 +00:00
|
|
|
return fn.blank() || fn.ok();
|
1994-12-02 13:30:45 +00:00
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _zerofill_val(TMask_field& f, KEY k)
|
1994-12-07 13:41:57 +00:00
|
|
|
{
|
|
|
|
if (f.to_check(k))
|
|
|
|
{
|
2008-03-20 17:11:59 +00:00
|
|
|
const int columns = get_int_val_param(0);
|
1996-05-08 11:09:13 +00:00
|
|
|
const TString& val = f.get();
|
1994-12-07 13:41:57 +00:00
|
|
|
if (val.len() < columns && real::is_natural(val))
|
1996-05-08 11:09:13 +00:00
|
|
|
{
|
|
|
|
TString z(val);
|
|
|
|
z.right_just(columns, '0');
|
|
|
|
f.set(z);
|
1994-12-07 13:41:57 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1994-12-07 13:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _alpha_val(TMask_field& f, KEY k)
|
1995-01-02 09:33:00 +00:00
|
|
|
{
|
|
|
|
if (f.to_check(k))
|
|
|
|
{
|
|
|
|
const TString& s = f.get();
|
|
|
|
for (int i = 0; s[i]; i++)
|
|
|
|
if (!isalpha(s[i]))
|
2007-01-25 15:42:56 +00:00
|
|
|
return f.error_box(TR("Sono ammessi solo caratteri alfabetici"));
|
1995-01-02 09:33:00 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1995-01-02 09:33:00 +00:00
|
|
|
}
|
|
|
|
|
1995-10-06 13:26:53 +00:00
|
|
|
HIDDEN bool _not_empty_chkfld_val(TMask_field& f, KEY k)
|
1995-01-12 18:40:10 +00:00
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
bool ok = true;
|
|
|
|
if (f.to_check(k,true) && f.get().not_empty())
|
1996-05-08 11:09:13 +00:00
|
|
|
{
|
1995-10-06 13:26:53 +00:00
|
|
|
TBrowse * b = ((TEdit_field&)f).browse();
|
1995-09-20 16:08:35 +00:00
|
|
|
if (b != NULL) ok = b->check(k == K_TAB ? RUNNING_CHECK : FINAL_CHECK);
|
|
|
|
}
|
1995-02-09 14:47:31 +00:00
|
|
|
return ok;
|
1995-01-12 18:40:10 +00:00
|
|
|
}
|
|
|
|
|
1995-11-22 13:41:41 +00:00
|
|
|
HIDDEN bool _sconto_val(TMask_field& f, KEY key)
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
bool ok = true;
|
1996-09-26 15:30:11 +00:00
|
|
|
|
1995-11-22 13:41:41 +00:00
|
|
|
if ( f.to_check( key ) )
|
|
|
|
{
|
1996-09-26 15:30:11 +00:00
|
|
|
const TString80 work(f.get());
|
|
|
|
TString80 goodexp;
|
1995-11-22 13:41:41 +00:00
|
|
|
// Elimina gli spazi molesti
|
1996-09-26 15:30:11 +00:00
|
|
|
// work.strip_spaces( );
|
|
|
|
if (work.not_empty())
|
|
|
|
{
|
|
|
|
TString80 num;
|
2007-09-17 15:33:04 +00:00
|
|
|
bool dec = false; // Flag che indica se si attende l'inizio di un numero
|
|
|
|
bool startnum = true; // Flag che indica se siamo all'inizio di un numero
|
1996-09-26 15:30:11 +00:00
|
|
|
int errorchar = ' ';
|
|
|
|
|
|
|
|
// Flag che indica se sono nella parte decimale di un numero
|
|
|
|
for (const char * s = (const char *)work; *s && errorchar == ' '; s++)
|
|
|
|
{
|
|
|
|
const char c = *s;
|
|
|
|
switch(c)
|
1995-11-22 13:41:41 +00:00
|
|
|
{
|
1996-09-26 15:30:11 +00:00
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
// Se ero in in numero ...
|
|
|
|
if( !startnum )
|
|
|
|
goodexp << num;
|
|
|
|
// Inizia il nuovo numero
|
|
|
|
num = (c == '-') ? "-" : "+";
|
2007-09-17 15:33:04 +00:00
|
|
|
startnum = true;
|
|
|
|
dec = false;
|
1996-09-26 15:30:11 +00:00
|
|
|
break;
|
|
|
|
case '0':
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
case '4':
|
|
|
|
case '5':
|
|
|
|
case '6':
|
|
|
|
case '7':
|
|
|
|
case '8':
|
|
|
|
case '9':
|
|
|
|
num << c;
|
2007-09-17 15:33:04 +00:00
|
|
|
startnum = false;
|
1996-09-26 15:30:11 +00:00
|
|
|
break;
|
|
|
|
case '.':
|
|
|
|
case ',':
|
|
|
|
if(!dec)
|
|
|
|
{
|
|
|
|
if( startnum )
|
|
|
|
num << '0'; // Se occorreva un numero ci metto lo 0
|
|
|
|
num << '.'; // Interpreto la virgola come punto
|
2007-09-17 15:33:04 +00:00
|
|
|
dec = true;
|
|
|
|
startnum = true;
|
1996-09-26 15:30:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
errorchar = c; // Se siamo gi` nella parte decimale segnala un errore
|
|
|
|
break;
|
|
|
|
case ' ':
|
1995-11-22 13:41:41 +00:00
|
|
|
break;
|
1996-09-26 15:30:11 +00:00
|
|
|
default:
|
|
|
|
errorchar = c;
|
|
|
|
break;
|
1995-11-22 13:41:41 +00:00
|
|
|
}
|
|
|
|
}
|
1996-09-26 15:30:11 +00:00
|
|
|
// Controlla la validita`
|
|
|
|
ok = errorchar == ' ';
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
goodexp << num; // Assegna la nuova espressione formattata bene
|
|
|
|
f.set(goodexp);
|
|
|
|
}
|
|
|
|
else
|
2007-01-25 15:42:56 +00:00
|
|
|
f.error_box(FR("Espressione di sconto non valida. Errore sul carattere %c"), errorchar);
|
1995-11-22 13:41:41 +00:00
|
|
|
}
|
|
|
|
}
|
1996-09-26 15:30:11 +00:00
|
|
|
return ok;
|
1995-11-22 13:41:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HIDDEN bool _ora_val(TMask_field& f, KEY key)
|
|
|
|
{
|
|
|
|
if ( f.to_check( key ) )
|
|
|
|
{
|
2003-11-05 10:20:31 +00:00
|
|
|
TString8 ora = f.get();
|
2007-09-17 15:33:04 +00:00
|
|
|
if ( ora.full( ) || f.required( ) )
|
1995-11-22 13:41:41 +00:00
|
|
|
{
|
|
|
|
if ( isdigit( ora[ 0 ] ) )
|
|
|
|
{
|
|
|
|
if ( ora[ 2 ] != ':' )
|
|
|
|
{
|
|
|
|
if ( ora.len( ) > 4 )
|
|
|
|
ora.overwrite( ":", 2 );
|
|
|
|
else
|
|
|
|
ora.insert( ":", 2 );
|
|
|
|
}
|
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
bool ok = ((isdigit(ora[0]))&&(isdigit(ora[1]))&&(isdigit(ora[3]))&&(isdigit(ora[4])));
|
1995-11-22 13:41:41 +00:00
|
|
|
ok &= ((atoi(&(ora[0]))<24)&&(atoi(&(ora[3]))<60));
|
2007-09-17 15:33:04 +00:00
|
|
|
if ( ok )
|
1995-11-22 13:41:41 +00:00
|
|
|
f.set( ora );
|
2007-09-17 15:33:04 +00:00
|
|
|
else
|
|
|
|
return f.error_box(TR("Ora errata o formato non valido"));
|
|
|
|
}
|
1995-11-22 13:41:41 +00:00
|
|
|
}
|
2007-09-17 15:33:04 +00:00
|
|
|
return true;
|
1995-11-22 13:41:41 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 15:01:49 +00:00
|
|
|
int iban_check(const TString& b, TString& msg)
|
2003-11-05 10:20:31 +00:00
|
|
|
{
|
|
|
|
if (b.len() < 5)
|
|
|
|
{
|
|
|
|
msg = TR("Lunghezza inferiore a 5 caratteri");
|
2003-11-10 15:01:49 +00:00
|
|
|
return 2;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
if (!isalpha(b[0]) || !isalpha(b[1]))
|
|
|
|
{
|
|
|
|
msg.format(FR("I primi due caratteri (%s) devono essere alfabetici"), (const char*)b.left(2));
|
2003-11-10 15:01:49 +00:00
|
|
|
return 3;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
2003-11-10 15:01:49 +00:00
|
|
|
if (!isdigit(b[2]) || !isdigit(b[3]))
|
2003-11-05 10:20:31 +00:00
|
|
|
{
|
|
|
|
msg.format(FR("I caratteri 3 e 4 (%s) devono essere numerici"), (const char*)b.mid(2,2));
|
2003-11-10 15:01:49 +00:00
|
|
|
return 4;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
1995-01-02 09:33:00 +00:00
|
|
|
|
2003-11-05 10:20:31 +00:00
|
|
|
TString80 s;
|
|
|
|
s << b.mid(4) << b.left(4);
|
1999-03-22 15:55:50 +00:00
|
|
|
|
2003-11-05 10:20:31 +00:00
|
|
|
int r = 0;
|
|
|
|
for (int i = 0; s[i]; i++)
|
|
|
|
{
|
|
|
|
const char c = s[i];
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
{
|
|
|
|
const int k = c - '0';
|
|
|
|
r = (10 * r + k) % 97;
|
|
|
|
} else
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
{
|
|
|
|
const int k = c - 'A' + 10;
|
|
|
|
r = (100 * r + k) % 97;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.format(FR("Carattere non ammesso: '%c'"), c);
|
2003-11-10 15:01:49 +00:00
|
|
|
return 5;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r != 1)
|
|
|
|
{
|
|
|
|
msg = TR("Codice di controllo errato");
|
2003-11-10 15:01:49 +00:00
|
|
|
return 1;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 15:01:49 +00:00
|
|
|
return 0;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 15:01:49 +00:00
|
|
|
int bban_check(const TString& b, TString& msg)
|
2003-11-05 10:20:31 +00:00
|
|
|
{
|
|
|
|
const unsigned char dispari[26] = { 1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18,
|
|
|
|
20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23 };
|
|
|
|
if (b.len() != 23)
|
|
|
|
{
|
|
|
|
msg = TR("Lunghezza diversa da 23 caratteri");
|
2003-11-10 15:01:49 +00:00
|
|
|
return 2;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
if (b[0] < 'A' || b[0] > 'Z')
|
|
|
|
{
|
|
|
|
msg.format(FR("Il CIN deve essere una lettera maiuscola: '%c'"), b[0]);
|
2003-11-10 15:01:49 +00:00
|
|
|
return 2;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
for (int a = 1; a <= 10; a++)
|
|
|
|
{
|
|
|
|
if (!isdigit(b[a]))
|
|
|
|
{
|
|
|
|
msg = TR("ABI e CAB devono essere numerici");
|
2003-11-10 15:01:49 +00:00
|
|
|
return 3;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int s = 0, kcin = 0;
|
|
|
|
for (int i = 0; b[i]; i++)
|
|
|
|
{
|
|
|
|
const char c = b[i];
|
|
|
|
int k = 0;
|
|
|
|
if (isdigit(c))
|
|
|
|
{
|
|
|
|
k = c - '0';
|
|
|
|
} else
|
|
|
|
if (c >= 'A' && c <= 'Z')
|
|
|
|
{
|
|
|
|
k = c - 'A';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg.format(FR("Carattere non ammesso: '%c'"), c);
|
2003-11-10 15:01:49 +00:00
|
|
|
return 4;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
if (i == 0)
|
|
|
|
kcin = k;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i & 1) // dispari
|
|
|
|
s += dispari[k];
|
|
|
|
else
|
|
|
|
s += k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s % 26 != kcin)
|
|
|
|
{
|
2003-11-10 15:01:49 +00:00
|
|
|
msg.format(TR("Codice di controlo (CIN) errato"));
|
|
|
|
return 1;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
|
2003-11-10 15:01:49 +00:00
|
|
|
return 0;
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HIDDEN bool _iban_val(TMask_field& f, KEY key)
|
|
|
|
{
|
|
|
|
bool ok = true;
|
2003-11-10 15:01:49 +00:00
|
|
|
|
2008-06-11 11:19:53 +00:00
|
|
|
if (key == K_TAB || key == K_ENTER)
|
2003-11-05 10:20:31 +00:00
|
|
|
{
|
2008-06-11 11:19:53 +00:00
|
|
|
TMask& m = f.mask();
|
|
|
|
const int nparms = get_val_param_count();
|
|
|
|
CHECKD(nparms == 8, "IBAN_CHECK deve avere 8 parametri: ", nparms);
|
|
|
|
int id[8];
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
id[i] = get_int_val_param(i);
|
|
|
|
|
|
|
|
|
|
|
|
if (f.dlg() == id[1]) // Campo Stato IBAN
|
2003-11-05 10:20:31 +00:00
|
|
|
{
|
2008-06-11 11:19:53 +00:00
|
|
|
if (key == K_TAB && !m.is_running())
|
2003-11-10 15:01:49 +00:00
|
|
|
{
|
2008-06-11 11:19:53 +00:00
|
|
|
const TString& iban = m.get(id[0]);
|
2003-11-10 15:01:49 +00:00
|
|
|
m.set(id[1], iban.left(2));
|
|
|
|
m.set(id[2], iban.mid(2,2));
|
|
|
|
m.set(id[3], iban.mid(4));
|
|
|
|
m.set(id[4], iban.mid(4,1));
|
|
|
|
m.set(id[5], iban.mid(5,5));
|
|
|
|
m.set(id[6], iban.mid(10,5));
|
|
|
|
m.set(id[7], iban.mid(15));
|
|
|
|
}
|
2008-06-11 11:19:53 +00:00
|
|
|
const bool italy = f.empty() || f.get() == "IT";
|
|
|
|
m.show(id[3], !italy);
|
|
|
|
m.show(id[4], italy);
|
|
|
|
m.show(id[5], italy);
|
|
|
|
m.show(id[6], italy);
|
|
|
|
m.show(id[7], italy);
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
2008-06-11 11:19:53 +00:00
|
|
|
if (f.dlg() == id[2])
|
2003-11-10 15:01:49 +00:00
|
|
|
{
|
2008-06-11 11:19:53 +00:00
|
|
|
TString4 stato = m.get(id[1]);
|
|
|
|
if (stato.empty())
|
|
|
|
stato = "IT";
|
|
|
|
const bool italy = stato=="IT";
|
|
|
|
const bool do_test = !m.field(id[italy ? 7 : 3]).empty(); // Faccio il test solo in presenza di conto corrente
|
|
|
|
TString80 iban;
|
|
|
|
if (do_test)
|
|
|
|
{
|
|
|
|
if (f.empty()) // Cifra di controllo vuota
|
|
|
|
{
|
|
|
|
TString msg;
|
|
|
|
TString80 iban;
|
|
|
|
iban << stato << "@@";
|
|
|
|
if (italy)
|
|
|
|
iban << m.get(id[4]) << m.get(id[5]) << m.get(id[6]) << m.get(id[7]);
|
|
|
|
else
|
|
|
|
iban << m.get(id[3]);
|
|
|
|
|
|
|
|
int err = 1;
|
|
|
|
for (int pp = 0; pp <= 99 && err == 1; pp++)
|
|
|
|
{
|
|
|
|
msg.format("%02d", pp);
|
|
|
|
iban.overwrite(msg, 2);
|
|
|
|
err = iban_check(iban, msg);
|
|
|
|
if (err == 0)
|
|
|
|
{
|
|
|
|
m.set(id[1], stato);
|
|
|
|
m.set(id[2], pp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iban << m.get(id[1]) << m.get(id[2]);
|
|
|
|
if (italy)
|
|
|
|
iban << m.get(id[4]) << m.get(id[5]) << m.get(id[6]) << m.get(id[7]);
|
|
|
|
else
|
|
|
|
iban << m.get(id[3]);
|
|
|
|
|
|
|
|
TString msg;
|
|
|
|
const int err = iban_check(iban, msg);
|
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
msg.insert(TR("Codice IBAN errato:\n"));
|
|
|
|
if (err > 1) // Errore grave
|
|
|
|
ok = error_box(msg);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg << '\n' << TR("Si desidera continuare ugualmente?");
|
|
|
|
ok = yesno_box(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (key == K_ENTER)
|
|
|
|
{
|
|
|
|
if (!ok) iban.cut(0);
|
|
|
|
m.set(id[0], iban);
|
|
|
|
}
|
2003-11-10 15:01:49 +00:00
|
|
|
}
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
2003-11-10 15:01:49 +00:00
|
|
|
|
2003-11-05 10:20:31 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
HIDDEN bool _bban_val(TMask_field& f, KEY key)
|
|
|
|
{
|
|
|
|
bool ok = true;
|
2003-11-10 15:01:49 +00:00
|
|
|
|
2008-06-11 11:19:53 +00:00
|
|
|
if (!f.empty() && f.to_check(key))
|
2003-11-05 10:20:31 +00:00
|
|
|
{
|
2003-11-10 15:01:49 +00:00
|
|
|
TMask& m = f.mask();
|
2007-09-17 15:33:04 +00:00
|
|
|
const int nparms = get_val_param_count();
|
2003-11-10 15:01:49 +00:00
|
|
|
CHECKD(nparms == 5, "BBAN_CHECK deve avere 5 parametri: ", nparms);
|
|
|
|
int id[5];
|
|
|
|
for (int i = 0; i < 5; i++)
|
2008-03-20 17:11:59 +00:00
|
|
|
id[i] = get_int_val_param(i);
|
2003-11-10 15:01:49 +00:00
|
|
|
|
2008-06-11 11:19:53 +00:00
|
|
|
if (m.field(id[1]).empty()) // CIN vuoto
|
|
|
|
{
|
|
|
|
TString msg;
|
|
|
|
TString80 bban;
|
|
|
|
bban << "#" << m.get(id[2]) << m.get(id[3]) << m.get(id[4]);
|
|
|
|
int err = 1;
|
|
|
|
for (char cin = 'A'; cin <= 'Z' && err == 1; cin++)
|
|
|
|
{
|
|
|
|
bban[0] = cin;
|
|
|
|
err = bban_check(bban, msg);
|
|
|
|
if (err == 0)
|
|
|
|
{
|
|
|
|
m.set(id[1], bban.left(1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (f.dlg() == id[1] && key == K_ENTER)
|
2003-11-05 10:20:31 +00:00
|
|
|
{
|
2003-11-10 15:01:49 +00:00
|
|
|
TString80 bban;
|
|
|
|
for (int i = 1; i < 5; i++)
|
|
|
|
bban << m.get(id[i]);
|
|
|
|
if (bban.len() > 11)
|
|
|
|
{
|
|
|
|
TString msg;
|
|
|
|
const int err = bban_check(bban, msg);
|
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
msg.insert(TR("Codice BBAN errato:\n"));
|
|
|
|
if (err > 1) // Errore grave
|
|
|
|
ok = error_box(msg);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg << '\n' << TR("Si desidera continuare ugualmente?");
|
|
|
|
ok = yesno_box(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-11-05 10:20:31 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-10 15:01:49 +00:00
|
|
|
|
2003-11-05 10:20:31 +00:00
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_FUNC 26
|
1994-11-10 14:17:03 +00:00
|
|
|
|
|
|
|
HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] =
|
|
|
|
{
|
2003-11-10 15:01:49 +00:00
|
|
|
_expr_val, // 0
|
1994-11-10 14:17:03 +00:00
|
|
|
_emptycopy_val,
|
|
|
|
_pi_val,
|
|
|
|
_cf_val,
|
|
|
|
_notempty_val,
|
2003-11-10 15:01:49 +00:00
|
|
|
_date_cmp, // 5
|
1994-11-10 14:17:03 +00:00
|
|
|
_xt_pi_val,
|
|
|
|
_xt_cf_val,
|
|
|
|
_xtz_pi_val,
|
|
|
|
_xtz_cf_val,
|
2003-11-10 15:01:49 +00:00
|
|
|
_fixlen_val, // 10
|
1994-11-10 14:17:03 +00:00
|
|
|
_mtcheck_val,
|
|
|
|
_reqif_val,
|
|
|
|
_autoexit_val,
|
|
|
|
_numcalc_val,
|
2003-11-10 15:01:49 +00:00
|
|
|
_strcalc_val, // 15
|
1994-11-29 17:31:11 +00:00
|
|
|
_onereq_val,
|
1994-12-02 13:30:45 +00:00
|
|
|
_chkfld_val,
|
1994-12-07 13:41:57 +00:00
|
|
|
_filename_val,
|
1995-01-02 09:33:00 +00:00
|
|
|
_zerofill_val,
|
2003-11-10 15:01:49 +00:00
|
|
|
_alpha_val, // 20
|
1995-11-22 13:41:41 +00:00
|
|
|
_not_empty_chkfld_val,
|
|
|
|
_ora_val,
|
|
|
|
_sconto_val,
|
2003-11-05 10:20:31 +00:00
|
|
|
_iban_val,
|
2003-11-10 15:01:49 +00:00
|
|
|
_bban_val, // 25
|
1995-11-22 13:41:41 +00:00
|
|
|
};
|
1994-11-10 14:17:03 +00:00
|
|
|
|
1996-02-05 19:00:53 +00:00
|
|
|
// @doc INTERNAL
|
1996-01-31 17:19:02 +00:00
|
|
|
|
|
|
|
// @func Effettua i controlli sui campi di una maschera
|
|
|
|
//
|
|
|
|
// @rdesc Ritorna se il controllo ha avuto successo:
|
|
|
|
//
|
2007-09-17 15:33:04 +00:00
|
|
|
// @flag true | Il campo e' positivo al controllo
|
|
|
|
// @flag false | Il campo non ha i requisiti necessari per passare il controllo
|
1996-01-31 17:19:02 +00:00
|
|
|
bool validate(
|
1996-05-08 11:09:13 +00:00
|
|
|
int fn, // @parm Numero della funzione da effettuare
|
|
|
|
TMask_field& f, // @parm Identificatore del campo da controllare
|
|
|
|
KEY k, // @parm Codice del tasto premuto sul campo
|
2008-03-20 17:11:59 +00:00
|
|
|
const TString_array& parms) // @parm Array di parametri per effettuare il controllo
|
1994-11-10 14:17:03 +00:00
|
|
|
{
|
|
|
|
_parms = &parms;
|
2007-09-17 15:33:04 +00:00
|
|
|
return (fn >= 0 && fn < MAX_FUNC) ? _global_val_func[fn](f, k) : true;
|
1994-11-10 14:17:03 +00:00
|
|
|
}
|
|
|
|
|
2008-11-14 00:40:30 +00:00
|
|
|
|