Patch level : 2.0 nopatch
Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunto supporto per IBAN e BBAN git-svn-id: svn://10.65.10.50/trunk@11568 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
2dc2bfdd1e
commit
25c64e75e0
@ -95,6 +95,8 @@
|
|||||||
#define ORA_FUNC 22 0
|
#define ORA_FUNC 22 0
|
||||||
#define SCONTO_FUNC 23 0
|
#define SCONTO_FUNC 23 0
|
||||||
#define CHECK_FIRM_FUNC 24 0
|
#define CHECK_FIRM_FUNC 24 0
|
||||||
|
#define CHECK_IBAN_FUNC 25
|
||||||
|
#define CHECK_BBAN_FUNC 26
|
||||||
|
|
||||||
#define VALEXPR VALIDATE EXPR_FUNC
|
#define VALEXPR VALIDATE EXPR_FUNC
|
||||||
#define NUM_EXPR VALEXPR 0
|
#define NUM_EXPR VALEXPR 0
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include <diction.h>
|
||||||
#include <expr.h>
|
#include <expr.h>
|
||||||
#include <isam.h>
|
#include <isam.h>
|
||||||
#include <mask.h>
|
#include <mask.h>
|
||||||
@ -443,21 +443,18 @@ HIDDEN bool _xt_cf_val(TMask_field& f, KEY key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HIDDEN bool _xtz_cf_val(TMask_field& f, KEY key)
|
HIDDEN bool _xtz_cf_val(TMask_field& f, KEY key)
|
||||||
|
|
||||||
{
|
{
|
||||||
if (f.mask().query_mode()) return TRUE;
|
if (f.mask().query_mode()) return TRUE;
|
||||||
const char* cf = f.get();
|
const char* cf = f.get();
|
||||||
return (*cf == '\0') ? TRUE : _xt_cf_val(f, key);
|
return (*cf == '\0') ? TRUE : _xt_cf_val(f, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HIDDEN bool _notempty_val(TMask_field& f, KEY)
|
HIDDEN bool _notempty_val(TMask_field& f, KEY)
|
||||||
{
|
{
|
||||||
return f.mask().query_mode() || f.get().not_empty();
|
return f.mask().query_mode() || f.get().not_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HIDDEN bool _date_cmp(TMask_field& f, KEY)
|
HIDDEN bool _date_cmp(TMask_field& f, KEY)
|
||||||
{
|
{
|
||||||
TFixed_string s(f.get());
|
TFixed_string s(f.get());
|
||||||
@ -480,7 +477,6 @@ HIDDEN bool _date_cmp(TMask_field& f, KEY)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HIDDEN bool _fixlen_val(TMask_field& f, KEY)
|
HIDDEN bool _fixlen_val(TMask_field& f, KEY)
|
||||||
{
|
{
|
||||||
const TFixed_string s(f.get());
|
const TFixed_string s(f.get());
|
||||||
@ -534,19 +530,6 @@ HIDDEN bool _autoexit_val(TMask_field& f, KEY key)
|
|||||||
if (!m.query_mode() || key == K_ENTER)
|
if (!m.query_mode() || key == K_ENTER)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
/*
|
|
||||||
const int next = m.next_fld();
|
|
||||||
|
|
||||||
if (next != DLG_NULL && next != f.dlg() && m.field(next).in_key(0))
|
|
||||||
{
|
|
||||||
const byte last = m.num_keys();
|
|
||||||
|
|
||||||
for (byte k = 1; k <= last; k++)
|
|
||||||
if (f.in_key(k) && m.field(next).in_key(k))
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const int nparms = get_val_param_num();
|
const int nparms = get_val_param_num();
|
||||||
bool one_not_empty = FALSE;
|
bool one_not_empty = FALSE;
|
||||||
for (int i = nparms; i-- > 0;)
|
for (int i = nparms; i-- > 0;)
|
||||||
@ -783,7 +766,7 @@ HIDDEN bool _ora_val(TMask_field& f, KEY key)
|
|||||||
{
|
{
|
||||||
if ( f.to_check( key ) )
|
if ( f.to_check( key ) )
|
||||||
{
|
{
|
||||||
TFixed_string ora( f.get( ), 6 );
|
TString8 ora = f.get();
|
||||||
if ( ora.not_empty( ) || f.required( ) )
|
if ( ora.not_empty( ) || f.required( ) )
|
||||||
{
|
{
|
||||||
if ( isdigit( ora[ 0 ] ) )
|
if ( isdigit( ora[ 0 ] ) )
|
||||||
@ -814,9 +797,176 @@ HIDDEN bool _ora_val(TMask_field& f, KEY key)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool iban_check(const TString& b, TString& msg)
|
||||||
|
{
|
||||||
|
if (b.len() < 5)
|
||||||
|
{
|
||||||
|
msg = TR("Lunghezza inferiore a 5 caratteri");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isalpha(b[0]) || !isalpha(b[1]))
|
||||||
|
{
|
||||||
|
msg.format(FR("I primi due caratteri (%s) devono essere alfabetici"), (const char*)b.left(2));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isdigit(b[2]) || !isdigit(b[1]))
|
||||||
|
{
|
||||||
|
msg.format(FR("I caratteri 3 e 4 (%s) devono essere numerici"), (const char*)b.mid(2,2));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
TString80 s;
|
||||||
|
s << b.mid(4) << b.left(4);
|
||||||
|
|
||||||
#define MAX_FUNC 24
|
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);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (r != 1)
|
||||||
|
{
|
||||||
|
msg = TR("Codice di controllo errato");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bban_check(const TString& b, TString& msg)
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (b[0] < 'A' || b[0] > 'Z')
|
||||||
|
{
|
||||||
|
msg.format(FR("Il CIN deve essere una lettera maiuscola: '%c'"), b[0]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int a = 1; a <= 10; a++)
|
||||||
|
{
|
||||||
|
if (!isdigit(b[a]))
|
||||||
|
{
|
||||||
|
msg = TR("ABI e CAB devono essere numerici");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (i == 0)
|
||||||
|
kcin = k;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (i & 1) // dispari
|
||||||
|
s += dispari[k];
|
||||||
|
else
|
||||||
|
s += k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s % 26 != kcin)
|
||||||
|
{
|
||||||
|
msg = TR("Codice di controllo (CIN) errato");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
HIDDEN bool _iban_val(TMask_field& f, KEY key)
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
if (f.to_check(key))
|
||||||
|
{
|
||||||
|
const TMask& m = f.mask();
|
||||||
|
TString80 iban;
|
||||||
|
const int nparms = get_val_param_num();
|
||||||
|
for (int i = 0; i < nparms; i++)
|
||||||
|
{
|
||||||
|
const int id = atoi(get_val_param(i));
|
||||||
|
iban << m.get(id);
|
||||||
|
}
|
||||||
|
TString msg;
|
||||||
|
ok = iban_check(iban, msg);
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
msg.insert(TR("Codice IBAN errato:\n"));
|
||||||
|
error_box(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ok = bban_check(iban.mid(5), msg);
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
msg.insert(TR("Codice BBAN errato:\n"));
|
||||||
|
error_box(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
HIDDEN bool _bban_val(TMask_field& f, KEY key)
|
||||||
|
{
|
||||||
|
bool ok = true;
|
||||||
|
if (f.to_check(key))
|
||||||
|
{
|
||||||
|
const TMask& m = f.mask();
|
||||||
|
TString80 bban;
|
||||||
|
const int nparms = get_val_param_num();
|
||||||
|
for (int i = 0; i < nparms; i++)
|
||||||
|
{
|
||||||
|
const int id = atoi(get_val_param(i));
|
||||||
|
bban << m.get(id);
|
||||||
|
}
|
||||||
|
TString msg;
|
||||||
|
ok = bban_check(bban, msg);
|
||||||
|
if (!ok)
|
||||||
|
{
|
||||||
|
msg.insert(TR("Codice BBAN errato:\n"));
|
||||||
|
error_box(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MAX_FUNC 26
|
||||||
|
|
||||||
HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] =
|
HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] =
|
||||||
{
|
{
|
||||||
@ -844,7 +994,8 @@ HIDDEN VAL_FUNC _global_val_func[MAX_FUNC] =
|
|||||||
_not_empty_chkfld_val,
|
_not_empty_chkfld_val,
|
||||||
_ora_val,
|
_ora_val,
|
||||||
_sconto_val,
|
_sconto_val,
|
||||||
|
_iban_val,
|
||||||
|
_bban_val,
|
||||||
};
|
};
|
||||||
|
|
||||||
// @doc INTERNAL
|
// @doc INTERNAL
|
||||||
|
@ -6,7 +6,10 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool validate(int fn, TMask_field& f, KEY k, const TArray& parms);
|
bool validate(int fn, TMask_field& f, KEY k, const TArray& parms);
|
||||||
bool pi_check (const char * stato, const char * cf);
|
|
||||||
bool cf_check (const char * stato, const char * cf);
|
bool pi_check (const char* stato, const char* pi);
|
||||||
|
bool cf_check (const char* stato, const char* cf);
|
||||||
|
bool iban_check(const TString& b, TString& msg);
|
||||||
|
bool bban_check(const TString& b, TString& msg);
|
||||||
|
|
||||||
#endif // __VALIDATE_H
|
#endif // __VALIDATE_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user