//Web版的身份证信息查询
//Default.aspx
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"
UICulture="zh-CN"Culture="zh-CN"%>

<%@ImportNamespace="System.Data"%>
<%@ImportNamespace="System.Data.OleDb"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>身份证查询-Madebyiceman</title>

<scriptlanguage="C#"runat="server">
publicstringstrIDCardNum;
publicboolwrongFlag=false;
privatevoidPage_Load(Objectsender,EventArgse)

...{
TextIDNUM.Focus();
}
privatevoidSubmit_Click(Objectsender,EventArgse)

...{
wrongFlag=false;


TextAddr.Value="";
TextBirth.Value="";
TextSex.Value="";
TextCheckInfor.Value="";
Label6.Visible=false;

//textBoxAddr.Text=null;
//textBoxBirth.Text=null;
//textBoxSex.Text=null;
//textBoxCheckInfor.Text=null;

strIDCardNum=TextIDNUM.Value;
if(string.IsNullOrEmpty(strIDCardNum))

...{
//MessageBox.Show("请输入你要查询的身份证号码!");
TextCheckInfor.Value="请输入你要查询的身份证号码!";
Label6.Visible=true;
TextIDNUM.Focus();
return;
}
elseif(strIDCardNum.Length==15)

...{
//MessageBox.Show("对不起,该软件暂不支持15位的身份证号码!");
TextCheckInfor.Value="暂不支持15位的身份证号码!";
Label6.Visible=true;
TextIDNUM.Focus();
return;
}
elseif(strIDCardNum.Length<18)

...{
//MessageBox.Show("请检查你输入的身份证号码是否为18位!");
TextCheckInfor.Value="请检查你输入的号码是否为18位!";
Label6.Visible=true;
TextIDNUM.Focus();
return;
}
elseif(strIDCardNum.Substring(2,2)=="00"||strIDCardNum.Substring(4,2)=="00")

...{
//MessageBox.Show("请输入有效的身份证号码!");
TextCheckInfor.Value="请输入有效的身份证号码!";
Label6.Visible=true;
TextIDNUM.Focus();
return;
}
else

...{
for(inti=0;i<=16;i++)

...{
if(strIDCardNum[i]<'0'||strIDCardNum[i]>'9')

...{
//MessageBox.Show("您输入的身份证号码中含有非法数字或字符,请检查!");
TextCheckInfor.Value="号码中含有非法数字或字符,请检查!";
Label6.Visible=true;
TextIDNUM.Focus();
return;
}
}

if((strIDCardNum[17]>='0'&&strIDCardNum[17]<='9')||strIDCardNum[17]=='x'||strIDCardNum[17]=='X')

...{
GetAddr();
GetBirth();
GetSex();
GetCheckInfor();
}
}
}
privatevoidGetAddr()//从身份证号码中取出地址码(第1-第6位)

...{
stringstrAddr=null;
stringstrProvince,strCity,strTown;

strProvince=strIDCardNum.Substring(0,2)+"0000";
strCity=strIDCardNum.Substring(0,4)+"00";
strTown=strIDCardNum.Substring(0,6);

ConnectionStringSettingssettings;
settings=ConfigurationManager.ConnectionStrings["addrConnectionString"];
OleDbConnectionconn=newOleDbConnection(settings.ConnectionString+";JetOLEDB:databasepassword=icemanstudio2006");
DataSetds=newDataSet();

conn.Open();

stringSQLstr="SELECT*FROMProvinceWHERECode='"+strProvince+"'";
OleDbDataAdapterOleDbDA=newOleDbDataAdapter(SQLstr,conn);
OleDbDA.Fill(ds);

if(ds!=null)

...{
DataRowCollectionRows=ds.Tables[0].Rows;
if(Rows.Count<=0)

...{//MessageBox.Show("没检索到此记录,请检查你的输入是否有误!");
TextCheckInfor.Value="无此记录,请检查输入是否有误!";
Label6.Visible=true;
TextIDNUM.Focus();
wrongFlag=true;
return;
}
if(Rows.Count>0)

...{
strAddr=Rows[0]["Address"].ToString();//取出省
ds.Clear();


SQLstr="SELECT*FROMCityWHERECode='"+strCity+"'";
OleDbDA=newOleDbDataAdapter(SQLstr,conn);
OleDbDA.Fill(ds);

if(ds!=null)

...{
Rows=ds.Tables[0].Rows;
if(Rows.Count<=0)

...{//MessageBox.Show("没检索到此记录,请检查你的输入是否有误!");
TextCheckInfor.Value="无此记录,请检查输入是否有误!";
Label6.Visible=true;
TextIDNUM.Focus();
wrongFlag=true;
return;
}
if(Rows.Count>0)

...{
strAddr+=Rows[0]["Address"].ToString();//取出市
ds.Clear();


SQLstr="SELECT*FROMTownWHERECode='"+strTown+"'";
OleDbDA=newOleDbDataAdapter(SQLstr,conn);
OleDbDA.Fill(ds);

if(ds!=null)

...{
Rows=ds.Tables[0].Rows;
if(Rows.Count<=0)

...{//MessageBox.Show("没检索到此记录,请检查你的输入是否有误!");
TextCheckInfor.Value="无此记录,请检查输入是否有误!";
Label6.Visible=true;
TextIDNUM.Focus();
wrongFlag=true;
return;
}
if(Rows.Count>0)

...{
stringtemp;
temp=Rows[0]["Address"].ToString();
strAddr+=temp.Trim('');//取出省+市+县
ds.Clear();
conn.Close();

TextAddr.Value=strAddr;
}
}
}
}
}
}
}

privatevoidGetBirth()//从身份证号码中取出生日期码(第7-第14位)

...{
if(wrongFlag)return;

stringstrYear,strMonth,strDay;

strYear=strIDCardNum.Substring(6,4);
strMonth=strIDCardNum.Substring(10,2);
strDay=strIDCardNum.Substring(12,2);
TextBirth.Value=strYear+"年"+strMonth+"月"+strDay+"日";
}

privatevoidGetSex()//从身份证号码中取顺序码(第15-第17位)从而判定性别

...{
if(wrongFlag)return;

stringstrSex;

strSex=strIDCardNum.Substring(16,1);
if(System.Convert.ToInt16(strSex)%2==0)

...{
TextSex.Value="女";
}
else

...{
TextSex.Value="男";
}
}

privatevoidGetCheckInfor()//从身份证号码中取校验码(第18位)从而判断该身份证号码是否合法

...{
if(wrongFlag)return;

stringstrCheck;

string[]strWi=...{"7","9","10","5","8","4","2","1","6","3","7","9","10","5","8","4","2","1"};
inti,check=0;
stringstrCheckFlag=null;

strCheck=strIDCardNum.Substring(17,1);
if(strCheck=="X")strCheck="x";
for(i=0;i<=16;i++)

...{
check+=System.Convert.ToInt16(strIDCardNum.Substring(i,1))*System.Convert.ToInt16(strWi[i]);
check%=11;
}
switch(check)

...{
case0:strCheckFlag="1";break;
case1:strCheckFlag="0";break;
case2:strCheckFlag="x";break;
case3:strCheckFlag="9";break;
case4:strCheckFlag="8";break;
case5:strCheckFlag="7";break;
case6:strCheckFlag="6";break;
case7:strCheckFlag="5";break;
case8:strCheckFlag="4";break;
case9:strCheckFlag="3";break;
case10:strCheckFlag="2";break;
}
if(strCheck==strCheckFlag)

...{
TextCheckInfor.Value="校验码正确!应该是合法身份证。";
}
else

...{
TextCheckInfor.Value="校验码错误!可能是非法身份证。";
}
}
</script>

</head>
<bodystyle="font-size:20px;">
<formid="form1"runat="server">
<divalign="center">
<tablestyle="width:380px;background-color:#dfefef;">
<tr>
<td>
<tablestyle="background-color:#d4e6ea"cellspacing="10"cellpadding="10">
<tr>
<tdstyle="color:#ff0000;font-weight:bold;font-size:25px;height:46px;width:354px;">
一个简单的身份证查询程序<br/>
<hrstyle="color:#ffffff"/>
</td>
</tr>
<tronmouseover="this.style.backgroundColor='#d0e0ee'"onmouseout="this.style.backgroundColor='#d4e6ea'">
<tdalign="left"style="height:46px;width:354px;">
<asp:LabelID="Label1"runat="server"Text="IDNum:"></asp:Label>
<inputid="TextIDNUM"type="text"maxlength="18"runat="server"tabindex="1"title="YourIDnumberhere"
style="width:127px"/>
<inputid="Submit1"type="submit"value="Search"runat="server"onserverclick="Submit_Click"
tabindex="2"/>
</td>
</tr>
<tr>
<tdalign="left"style="height:40px;width:354px;">
<asp:LabelID="Label2"runat="server"Text="Address:"></asp:Label>
<inputid="TextAddr"type="text"runat="server"readonly="readOnly"style="width:193px"
tabindex="3"/>
</td>
</tr>
<tr>
<tdalign="left"style="height:40px;width:354px;">
<asp:LabelID="Label3"runat="server"Text="Birthday:"></asp:Label>
<inputid="TextBirth"type="text"runat="server"readonly="readOnly"style="width:95px"
tabindex="4"/>
</td>
</tr>
<tr>
<tdalign="left"style="height:40px;width:354px;">
<asp:LabelID="Label4"runat="server"Text="Sex:"></asp:Label> <inputid="TextSex"
type="text"runat="server"readonly="readOnly"style="width:15px"tabindex="5"/>
</td>
</tr>
<tr>
<tdalign="left"style="height:40px;width:354px;">
<asp:LabelID="Label5"runat="server"Text="Infor:"></asp:Label>
<inputid="TextCheckInfor"type="text"runat="server"style="width:193px"readonly="readOnly"
tabindex="6"value="在IDNUM输入你要查询的号码!"/>
<asp:LabelID="Label6"runat="server"ForeColor="Red"Text="*"Visible="False"></asp:Label></td>
</tr>
</table>
</td>
</tr>
</table>
<br/>
Copyright©2006-2007iceman,AllRightsReserved<br/>
<ahref="mailto:happyboylxl@yahoo.com.cn">sendE-mailtome</a>
</div>
</form>
</body>
</html>
//Web.config
<?xmlversion="1.0"encoding="utf-8"?>

<!--注意:除了手动编辑此文件以外,您还可以使用Web管理工具来
配置应用程序的设置。可以使用VisualStudio中的“网站”->“ASP.NET配置”
选项。
设置和注释的完整列表在
machine.config.comments中,该文件通常位于WindowsMicrosoft.NETFrameworkv2.0.xxxxxConfig中
-->

<configuration>

<appSettings/>
<connectionStrings>
<addname="addrConnectionString"connectionString="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=|DataDirectory|addr.mdb"providerName="System.Data.OleDb"/>
</connectionStrings>

<system.web>

<!--
设置compilationdebug="true"将调试符号插入已编译的页面中。
但由于这会影响性能,因此只在开发过程中将此值设置为true。
-->
<compilationdebug="false"/>


<!--
通过<authentication>节可以配置ASP.NET使用的
安全身份验证模式,以标识传入的用户。
-->
<authenticationmode="Windows"/>


<!--
如果在执行请求的过程中出现未处理的错误,则通过<customErrors>节
可以配置相应的处理步骤。具体说来,开发人员通过该节可以
配置要显示的html错误页以代替错误堆栈跟踪。
-->
<customErrorsmode="RemoteOnly"defaultRedirect="GenericErrorPage.htm">
<!--
<errorstatusCode="403"redirect="NoAccess.htm"/>
<errorstatusCode="404"redirect="FileNotFound.htm"/>
-->
</customErrors>


<!--
完全限定客户端重定向的URL
有些移动设备要求对客户端重定向的URL进行完全限定。
-->
<httpRuntimeuseFullyQualifiedRedirectUrl="true"/>


<!--
指定无Cookie的数据字典类型
这将使字典内容出现在本地请求url查询字符串中。
这是在无Cookie的设备上进行Forms身份验证所必需的。
-->
<mobileControlscookielessDataDictionaryType="System.Web.Mobile.CookielessData"/>


<deviceFilters>
<filtername="isJPhone"compare="Type"argument="J-Phone"/>
<filtername="isHTML32"compare="PreferredRenderingType"argument="html32"/>
<filtername="isWML11"compare="PreferredRenderingType"argument="wml11"/>
<filtername="isCHTML10"compare="PreferredRenderingType"argument="chtml10"/>
<filtername="isGoAmerica"compare="Browser"argument="Go.Web"/>
<filtername="isMME"compare="Browser"argument="MicrosoftMobileExplorer"/>
<filtername="isMyPalm"compare="Browser"argument="MyPalm"/>
<filtername="isPocketIE"compare="Browser"argument="PocketIE"/>
<filtername="isUP3x"compare="Type"argument="Phone.com3.xBrowser"/>
<filtername="isUP4x"compare="Type"argument="Phone.com4.xBrowser"/>
<filtername="isEricssonR380"compare="Type"argument="EricssonR380"/>
<filtername="isNokia7110"compare="Type"argument="Nokia7110"/>
<filtername="prefersGIF"compare="PreferredImageMIME"argument="image/gif"/>
<filtername="prefersWBMP"compare="PreferredImageMIME"argument="image/vnd.wap.wbmp"/>
<filtername="supportsColor"compare="IsColor"argument="true"/>
<filtername="supportsCookies"compare="Cookies"argument="true"/>
<filtername="supportsJavaScript"compare="Javascript"argument="true"/>
<filtername="supportsVoiceCalls"compare="CanInitiateVoiceCall"argument="true"/>
</deviceFilters>
<!--
<globalizationrequestEncoding="gb2312"responseEncoding="gb2312"/>

-->

</system.web>
</configuration>