日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

录入学员的身份证后控件焦点转移时根据身份证号码获得生日和性别

發布時間:2024/4/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 录入学员的身份证后控件焦点转移时根据身份证号码获得生日和性别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
自從接觸了報名系統,認證系統,才知道身份證號碼里面的信息大有乾坤,以18位的身份證來說,前面六位代表了你戶籍所在地,第七位到第十四位代表了你的出生年月,第十五位到第十七為代表了你的性別(偶數為女,奇數為男),根據這一信息,我在系統開發的錄入學員的身份證后控件焦點轉移時根據身份證號碼獲得生日和性別,用C#寫的代碼如下:
?

?
///?<summary>
///在控件驗證?textBox_IdentityCard?的?Validated事件中定義身份證號碼的合法性并根據身份證號碼得到生日和性別

///?</summary>???????

???????
private?void?textBox_IdentityCard_Validated(object?sender,?EventArgs?e)

???????{
???????????
try
???????????{
???????????????
string?identityCard?=?textBox_IdentityCard.Text.Trim();//獲取得到輸入的身份證號碼

???????????????
if?(string.IsNullOrEmpty(identityCard))
???????????????{
???????????????????MessageBox.Show(
"身份證號碼不能為空!");//身份證號碼不能為空,如果為空返回
???????????????????if?(textBox_IdentityCard.CanFocus)
???????????????????{

???????????????????????textBox_IdentityCard.Focus();
//設置當前輸入焦點為textBox_IdentityCar

???????????????????}
???????????????????
return;
???????????????????}
???????????????
else
???????????????{
???????????????????
if?(identityCard.Length?!=?15?&&?identityCard.Length?!=?18)//身份證號碼只能為15位或18位其它不合法
???????????????????{

???????????????????????MessageBox.Show(
"身份證號碼為15位或18位,請檢查!");

???????????????????????
if?(textBox_IdentityCard.CanFocus)
???????????????????????{
???????????????????????????textBox_IdentityCard.Focus();
???????????????????????}
???????????????????????
return;
????????????????????}
???????????????}

???????????????
string?birthday?=?"";
???????????????
string?sex?=?"";
???????????????
if?(identityCard.Length?==?18)//處理18位的身份證號碼從號碼中得到生日和性別代碼
??????????????{
???????????????????birthday?
=?identityCard.Substring(6,?4)?+?"-"?+?identityCard.Substring(10,?2)?+?"-"?+?identityCard.Substring(12,?2);
???????????????????sex?
=?identityCard.Substring(14,?3);
???????????????}
???????????????
if?(identityCard.Length?==?15)
???????????????{

???????????????????birthday?
=?"19"?+?identityCard.Substring(6,?2)?+?"-"?+?identityCard.Substring(8,?2)?+?"-"?+?identityCard.Substring(10,?2);
???????????????????sex?
=?identityCard.Substring(12,?3);
???????????????}
???????????????textBox_Birthday.Text?
=?birthday;
???????????????
if?(int.Parse(sex)?%?2?==?0)//性別代碼為偶數是女性奇數為男性
???????????????{
???????????????????
this.comboBox_Sex.Text?=?"";

??????????????}
???????????????
else
???????????????{
???????????????????
this.comboBox_Sex.Text?=?"";
???????????????}
???????????}
???????????
catch?(Exception?ex)
???????????{
???????????????MessageBox.Show(
"身份證號碼輸入有誤");
???????????????
if?(textBox_IdentityCard.CanFocus)
???????????????{
???????????????????textBox_IdentityCard.Focus();
???????????????}
???????????????
return;
???????????}
???????}

轉載于:https://www.cnblogs.com/wwl3325/archive/2009/03/02/1401540.html

總結

以上是生活随笔為你收集整理的录入学员的身份证后控件焦点转移时根据身份证号码获得生日和性别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。