这怎么做啊?
解决方案 »
- 急!急!急!急! 怎么打开服务器上制定盘符上文件
- 关于windows server 2008 IIS的会话超时问题
- 收银页面求职~!!!请高手进
- 请问怎样用JMail发送附件
- 怎样写一个显示在工具箱上的复合控件
- DataList 模板,如何去掉行与行之间的空隙呢?(模板套用table...)
- 在CSDN看了些还是没的明白.关于动态加载控件的问题.
- 关于类的静态与非静态构造函数
- 给分啦
- visual stadio.net 里面有很多所见既所得的东东,比如连接数据库什么的,直接拖进来
- 创建WEB项目时,本地系统与IIS方式--图片路径的差异??
- VS2005中的“网站发布”和“运行浏览”问题!!!! 谢谢!!!!!!!!!!!
using System;
using System.Diagnostics;namespace tm
{
///
/// Class1 的摘要说明。
///
public class IDCode
{
public DateTime Birthday;
public string Sex=null;
public string IDCode18;
public string 地区="";
public string 地区代码=""; public IDCode(string code)
{
Birthday=DateTime.Today; try
{
if(code.Length==15)
{
string ts="";
if(Convert.ToInt32(code.Substring(6,2))>20)
ts="19";
else
ts="20";
IDCode18=code.Substring(0,6)+ts+code.Substring(6); int[] wi={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1};
string[] wf={"1","0","X","9","8","7","6","5","4","3","2"};
int s=0;
for(int i=0;i<17;i++)
{
s+=wi[i] * Convert.ToInt32(IDCode18.Substring(i,1));
}
IDCode18+=wf[Convert.ToInt32(s)%11];
Debug.Write(IDCode18);
}
else
{
IDCode18=code;
} Sex= Convert.ToInt32(IDCode18.Substring(16,1))%2==1?"男":"女";
Birthday=Convert.ToDateTime(IDCode18.Substring(6,4)+"-"+IDCode18.Substring(10,2)+"-"+IDCode18.Substring(12,2));
地区代码=IDCode18.Substring(0,6);
}
catch(Exception ex)
{
Debug.Write(ex.Message); IDCode18=code;
}
}
}}
using System;
using System.Diagnostics;namespace tm
{
///
/// Class1 的摘要说明。
///
public class IDCode
{
public DateTime Birthday;
public string Sex=null;
public string IDCode18;
public string 地区="";
public string 地区代码=""; public IDCode(string code)
{
Birthday=DateTime.Today; try
{
if(code.Length==15)
{
string ts="";
if(Convert.ToInt32(code.Substring(6,2))>20)
ts="19";
else
ts="20";
IDCode18=code.Substring(0,6)+ts+code.Substring(6); int[] wi={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1};
string[] wf={"1","0","X","9","8","7","6","5","4","3","2"};
int s=0;
for(int i=0;i<17;i++)
{
s+=wi[i] * Convert.ToInt32(IDCode18.Substring(i,1));
}
IDCode18+=wf[Convert.ToInt32(s)%11];
Debug.Write(IDCode18);
}
else
{
IDCode18=code;
} Sex= Convert.ToInt32(IDCode18.Substring(16,1))%2==1?"男":"女";
Birthday=Convert.ToDateTime(IDCode18.Substring(6,4)+"-"+IDCode18.Substring(10,2)+"-"+IDCode18.Substring(12,2));
地区代码=IDCode18.Substring(0,6); try
{
tmDataReader dr=new tmDataReader("select 名称 from TABLE_行政区划代码 where 编码='"+IDCode18.Substring(0,2)+"'");
if(dr.Read())
this.地区=(string)dr[0];
dr.Close();
dr=new tmDataReader("select 名称 from TABLE_行政区划代码 where 编码='"+IDCode18.Substring(0,4)+"'");
if(dr.Read())
this.地区+=(string)dr[0];
dr.Close();
dr=new tmDataReader("select 名称 from TABLE_行政区划代码 where 编码='"+IDCode18.Substring(0,6)+"'");
if(dr.Read())
this.地区+=(string)dr[0];
dr.Close();
}
catch(Exception ex)
{
Debug.WriteLine("连接数据库取地区代码时出错!");
}
}
catch(Exception ex)
{
Debug.Write(ex.Message); IDCode18=code;
}
}
}}
SQL函数实现的具体代码:------------------------------------------------------------------------------------------------------
create function id15to18 (@id15 char(15))
returns char(18) as
begin
declare @id18 char(18)
declare @s1 as integer
declare @s2 as integer
declare @s3 as integer
declare @s4 as integer
declare @s5 as integer
declare @s6 as integer
declare @s7 as integer
declare @s8 as integer
declare @s9 as integer
declare @s10 as integer
declare @s11 as integer
declare @s12 as integer
declare @s13 as integer
declare @s14 as integer
declare @s15 as integer
declare @s16 as integer
declare @s17 as integer
declare @s18 as integerset @s1 = substring(@id15,1,1)
set @s2 = substring(@id15,2,1)
set @s3 = substring(@id15,3,1)
set @s4 = substring(@id15,4,1)
set @s5 = substring(@id15,5,1)
set @s6 = substring(@id15,6,1)
set @s7 = 1
set @s8 = 9
set @s9 = substring(@id15,7,1)
set @s10 = substring(@id15,8,1)
set @s11 = substring(@id15,9,1)
set @s12 = substring(@id15,10,1)
set @s13 = substring(@id15,11,1)
set @s14 = substring(@id15,12,1)
set @s15 = substring(@id15,13,1)
set @s16 = substring(@id15,14,1)
set @s17 = substring(@id15,15,1)set @s18 = ( (@s1*7) + (@s2*9) + (@s3*10) + (@s4*5) + (@s5*8) +
(@s6*4) + (@s7*2) + (@s8*1) + (@s9*6) + (@s10*3) +
(@s11*7) + (@s12*9) + (@s13*10) + (@s14*5) + (@s15*8) +
(@s16*4) + (@s17*2) ) % 11set @id18 = substring(@id15,1,6) + '19' + substring(@id15,7,9) +
case
when @s18 = 0 then '1'
when @s18 = 1 then '0'
when @s18 = 2 then 'x'
when @s18 = 3 then '9'
when @s18 = 4 then '8'
when @s18 = 5 then '7'
when @s18 = 6 then '6'
when @s18 = 7 then '5'
when @s18 = 8 then '4'
when @s18 = 9 then '3'
when @s18 = 10 then '2'
endreturn @id18
end
UPDATE 员工表 SET 身份证号=
SUBSTRING(身份证号,1,6)+'18'+SUBSTRING(身份证号,7,9)+
SUBSTRING('10X98765432',
(
CAST(SUBSTRING(身份证号, 1,1) AS INT)*7
+CAST(SUBSTRING(身份证号, 2,1) AS INT)*9
+CAST(SUBSTRING(身份证号, 3,1) AS INT)*10
+CAST(SUBSTRING(身份证号, 4,1) AS INT)*5
+CAST(SUBSTRING(身份证号, 5,1) AS INT)*8
+CAST(SUBSTRING(身份证号, 6,1) AS INT)*4
+1*2
+8*1
+CAST(SUBSTRING(身份证号, 7,1) AS INT)*6
+CAST(SUBSTRING(身份证号, 8,1) AS INT)*3
+CAST(SUBSTRING(身份证号, 9,1) AS INT)*7
+CAST(SUBSTRING(身份证号,10,1) AS INT)*9
+CAST(SUBSTRING(身份证号,11,1) AS INT)*10
+CAST(SUBSTRING(身份证号,12,1) AS INT)*5
+CAST(SUBSTRING(身份证号,13,1) AS INT)*8
+CAST(SUBSTRING(身份证号,14,1) AS INT)*4
+CAST(SUBSTRING(身份证号,15,1) AS INT)*2
)
% 11 + 1, 1)
WHERE LEN(身份证号)=15 AND SUBSTRING(身份证号,13,3) IN ('999','998','997','996')-- 15位身份证号升级为18位,适用于19xx年出生的公民
UPDATE 员工表 SET 身份证号=
SUBSTRING(身份证号,1,6)+'19'+SUBSTRING(身份证号,7,9)+
SUBSTRING('10X98765432',
(
CAST(SUBSTRING(身份证号, 1,1) AS INT)*7
+CAST(SUBSTRING(身份证号, 2,1) AS INT)*9
+CAST(SUBSTRING(身份证号, 3,1) AS INT)*10
+CAST(SUBSTRING(身份证号, 4,1) AS INT)*5
+CAST(SUBSTRING(身份证号, 5,1) AS INT)*8
+CAST(SUBSTRING(身份证号, 6,1) AS INT)*4
+1*2
+9*1
+CAST(SUBSTRING(身份证号, 7,1) AS INT)*6
+CAST(SUBSTRING(身份证号, 8,1) AS INT)*3
+CAST(SUBSTRING(身份证号, 9,1) AS INT)*7
+CAST(SUBSTRING(身份证号,10,1) AS INT)*9
+CAST(SUBSTRING(身份证号,11,1) AS INT)*10
+CAST(SUBSTRING(身份证号,12,1) AS INT)*5
+CAST(SUBSTRING(身份证号,13,1) AS INT)*8
+CAST(SUBSTRING(身份证号,14,1) AS INT)*4
+CAST(SUBSTRING(身份证号,15,1) AS INT)*2
)
% 11 + 1, 1)
WHERE LEN(身份证号)=15 AND SUBSTRING(身份证号,13,3) NOT IN ('999','998','997','996')
最后一位校验码
校验码
(1)十七位数字本体码加权求和公式
S = Sum(Ai * Wi), i = 0, ... , 16 ,先对前17位数字的权求和
Ai:表示第i位置上的身份证号码数字值
Wi:表示第i位置上的加权因子
Wi: 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 (2)计算模
Y = mod(S, 11) (3)通过模得到对应的校验码
Y: 0 1 2 3 4 5 6 7 8 9 10
校验码: 1 0 X 9 8 7 6 5 4 3 2
private string per15To18(string perIDSrc)
{
int iS = 0;
//加权因子常数
int[] iW=new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
//校验码常数
string LastCode="10X98765432";
//新身份证号
string perIDNew;
perIDNew=perIDSrc.Substring(0,6);
//填在第6位及第7位上填上‘1’,‘9’两个数字
perIDNew += "19";
perIDNew += perIDSrc.Substring(6,9);
//进行加权求和
for( int i=0; i<17; i++)
{
iS += int.Parse(perIDNew.Substring(i,1)) * iW[i];
}
//取模运算,得到模值
int iY = iS%11;
//从LastCode中取得以模为索引号的值,加到身份证的最后一位,即为新身份证号。
perIDNew += LastCode.Substring(iY,1); return perIDNew;
}
1,先将15位的号码变成18位
private string per15To18(string perIDSrc)
{
int iS = 0;
//加权因子常数
int[] iW=new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
//校验码常数
string LastCode="10X98765432";
//新身份证号
string perIDNew;
System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d{15}$");
System.Text.RegularExpressions.Match mc = rg.Match(perIDSrc);
if(!mc.Success)
{
MessageBox.Show("位数不正确!");
return "";
}
perIDNew=perIDSrc.Substring(0,6);
//填在第6位及第7位上填上‘1’,‘9’两个数字
perIDNew += "19";
perIDNew += perIDSrc.Substring(6,9);
//进行加权求和
for( int i=0; i<17; i++)
{
iS += int.Parse(perIDNew.Substring(i,1)) * iW[i];
}
//取模运算,得到模值
int iY = iS%11;
//从LastCode中取得以模为索引号的值,加到身份证的最后一位,即为新身份证号。
perIDNew += LastCode.Substring(iY,1);
MessageBox.Show(perIDNew);
return perIDNew;
} 2,校验号码
private string CheckCidInfo(string cid)
{
string[] aCity = new string[]{null,null,null,null,null,null,null,null,null,null,null,"北京","天津","河北","山西","内蒙古",null,null,null,null,null,"辽宁","吉林","黑龙江",null,null,null,null,null,null,null,"上海","江苏","浙江","安微","福建","江西","山东",null,null,null,"河南","湖北","湖南","广东","广西","海南",null,null,null,"重庆","四川","贵州","云南","西藏",null,null,null,null,null,null,"陕西","甘肃","青海","宁夏","新疆",null,null,null,null,null,"台湾",null,null,null,null,null,null,null,null,null,"香港","澳门",null,null,null,null,null,null,null,null,"国外"};
double iSum=0;
string info="";
System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^\d{17}(\d|X|x)$");
System.Text.RegularExpressions.Match mc = rg.Match(cid);
if(!mc.Success)
{
MessageBox.Show("位数不正确!");
return "";
}
cid = cid.ToLower();
cid = cid.Replace("x","a");
if(aCity[int.Parse(cid.Substring(0,2))]==null)
{
MessageBox.Show("非法地区");
return "非法地区";
}
try
{
DateTime.Parse(cid.Substring(6,4)+"-"+cid.Substring(10,2)+"-"+cid.Substring(12,2));
}
catch
{
MessageBox.Show("非法生日");
return "非法生日";
}
for(int i=17;i>=0;i--)
{
iSum +=(System.Math.Pow(2,i)%11)*int.Parse(cid[17-i].ToString(),System.Globalization.NumberStyles.HexNumber);
}
if(iSum%11!=1)
{
MessageBox.Show("非法证号");
return("非法证号");
}
MessageBox.Show((aCity[int.Parse(cid.Substring(0,2))]+","+cid.Substring(6,4)+"-"+cid.Substring(10,2)+"-"+cid.Substring(12,2)+","+(int.Parse(cid.Substring(16,1))%2==1?"男":"女")));
return(aCity[int.Parse(cid.Substring(0,2))]+","+cid.Substring(6,4)+"-"+cid.Substring(10,2)+"-"+cid.Substring(12,2)+","+(int.Parse(cid.Substring(16,1))%2==1?"男":"女"));
// return null;
}3,完成