摘要:檢查統一編號是不是正確
01
/// <summary>
02
/// 檢查統一編號是否正確
03
/// </summary>
04
/// <param name="id1">要檢查的統一編號字串</param>
05
/// <returns>Boolean值</returns>
06
public static Boolean isCompanyID(String strIdno)
07
{
08
if (strIdno == null || strIdno.Trim().Length != 8)
09
{
10
return false;
11
}
12
else if (!isInteger(strIdno))
13
{
14
return false;
15
}
16
17
int ii;
18
19
try
20
{
21
ii = Convert.ToInt32(strIdno);
22
}
23
catch (Exception)
24
{
25
return false;
26
}
27
int c1;
28
int c2;
29
int c3;
30
int c4;
31
int c5;
32
int c6;
33
int c7;
34
int c8;
35
try
36
{
37
c1 = Convert.ToInt32(strIdno.Substring(0, 1));
38
c2 = Convert.ToInt32(strIdno.Substring(1, 1));
39
c3 = Convert.ToInt32(strIdno.Substring(2, 1));
40
c4 = Convert.ToInt32(strIdno.Substring(3, 1));
41
c5 = Convert.ToInt32(strIdno.Substring(4, 1));
42
c6 = Convert.ToInt32(strIdno.Substring(5, 1));
43
c7 = Convert.ToInt32(strIdno.Substring(6, 1));
44
c8 = Convert.ToInt32(strIdno.Substring(7, 1));
45
}
46
catch (Exception)
47
{
48
return false;
49
}
50
51
int y = c1 + c3 + c5 + c8;
52
int t = c2 * 2;
53
y = y + t / 10 + t % 10;
54
t = c4 * 2;
55
y = y + t / 10 + t % 10;
56
t = c6 * 2;
57
y = y + t / 10 + t % 10;
58
t = c7 * 4;
59
y = y + t / 10 + t % 10;
60
int k = y;
61
if (y % 10 == 0)
62
{
63
return true;
64
}
65
if (c7 == 7)
66
{
67
y -= 9;
68
return y % 10 == 0;
69
}
70
else
71
{
72
return false;
73
}
74
}
/// <summary> 02
/// 檢查統一編號是否正確 03
/// </summary> 04
/// <param name="id1">要檢查的統一編號字串</param> 05
/// <returns>Boolean值</returns> 06
public static Boolean isCompanyID(String strIdno) 07
{ 08
if (strIdno == null || strIdno.Trim().Length != 8) 09
{ 10
return false; 11
} 12
else if (!isInteger(strIdno)) 13
{ 14
return false; 15
} 16
17
int ii; 18
19
try 20
{ 21
ii = Convert.ToInt32(strIdno); 22
} 23
catch (Exception) 24
{ 25
return false; 26
} 27
int c1; 28
int c2; 29
int c3; 30
int c4; 31
int c5; 32
int c6; 33
int c7; 34
int c8; 35
try 36
{ 37
c1 = Convert.ToInt32(strIdno.Substring(0, 1)); 38
c2 = Convert.ToInt32(strIdno.Substring(1, 1)); 39
c3 = Convert.ToInt32(strIdno.Substring(2, 1)); 40
c4 = Convert.ToInt32(strIdno.Substring(3, 1)); 41
c5 = Convert.ToInt32(strIdno.Substring(4, 1)); 42
c6 = Convert.ToInt32(strIdno.Substring(5, 1)); 43
c7 = Convert.ToInt32(strIdno.Substring(6, 1)); 44
c8 = Convert.ToInt32(strIdno.Substring(7, 1)); 45
} 46
catch (Exception) 47
{ 48
return false; 49
} 50
51
int y = c1 + c3 + c5 + c8; 52
int t = c2 * 2; 53
y = y + t / 10 + t % 10; 54
t = c4 * 2; 55
y = y + t / 10 + t % 10; 56
t = c6 * 2; 57
y = y + t / 10 + t % 10; 58
t = c7 * 4; 59
y = y + t / 10 + t % 10; 60
int k = y; 61
if (y % 10 == 0) 62
{ 63
return true; 64
} 65
if (c7 == 7) 66
{ 67
y -= 9; 68
return y % 10 == 0; 69
} 70
else 71
{ 72
return false; 73
} 74
}