欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來(lái)到入門(mén)教程網(wǎng)!

C#教程

當(dāng)前位置:主頁(yè) > 軟件編程 > C#教程 >

C#根據(jù)身份證號(hào)碼判斷出生日期和性別

來(lái)源:本站原創(chuàng)|時(shí)間:2020-01-10|欄目:C#教程|點(diǎn)擊: 次

18位的身份證,前面六位代表了你戶籍所在地,第七位到第十四位代表了你的出生年月,第十五位到第十七為代表了你的性別(偶數(shù)為女,奇數(shù)為男),根據(jù)這一信息,我在系統(tǒng)開(kāi)發(fā)的錄入員工的身份證后控件焦點(diǎn)轉(zhuǎn)移時(shí)根據(jù)身份證號(hào)碼獲得生日和性別。 

用C#寫(xiě)的代碼如下:

/// <summary>
/// 在控件驗(yàn)證 textBox_IdentityCard 的 Validated事件中定義身份證號(hào)碼的合法性并根據(jù)身份證號(hào)碼得到生日和性別 
/// </summary>
private void textBox_IdentityCard_Validated(object sender, EventArgs e)
{
  try
  {
    //獲取得到輸入的身份證號(hào)碼
    string identityCard = textBox_IdentityCard.Text.Trim();
    if (string.IsNullOrEmpty(identityCard))

    {

      //身份證號(hào)碼不能為空,如果為空返回

      MessageBox.Show("身份證號(hào)碼不能為空!");

      if (textBox_IdentityCard.CanFocus)

      {

        textBox_IdentityCard.Focus();//設(shè)置當(dāng)前輸入焦點(diǎn)為textBox_IdentityCard

      }

      return;

    }

    else

    {

      //身份證號(hào)碼只能為15位或18位其它不合法

      if (identityCard.Length != 15 && identityCard.Length != 18)

      {

        MessageBox.Show("身份證號(hào)碼為15位或18位,請(qǐng)檢查!");

        if (textBox_IdentityCard.CanFocus)

        {

          textBox_IdentityCard.Focus();

        }

        return;

      }

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

    }<br>

    //處理15位的身份證號(hào)碼從號(hào)碼中得到生日和性別代碼
    if (identityCard.Length == 15)
    {
      birthday = "19" + identityCard.Substring(6, 2) + "-" + identityCard.Substring(8, 2) + "-" + identityCard.Substring(10, 2);
      sex = identityCard.Substring(12, 3);
    }<br>
    textBox_Birthday.Text = birthday;
    //性別代碼為偶數(shù)是女性奇數(shù)為男性
    if (int.Parse(sex) % 2 == 0)
    {
      this.comboBox_Sex.Text = "女";
    }

    else
    {
      this.comboBox_Sex.Text = "男";
    }
  }
  catch (Exception ex)

  {

    MessageBox.Show("身份證號(hào)碼輸入有誤");
    if (textBox_IdentityCard.CanFocus)
    {
      textBox_IdentityCard.Focus();
    }
    return;
  }
}

 以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

網(wǎng)頁(yè)制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語(yǔ)言數(shù)據(jù)庫(kù)服務(wù)器

如果侵犯了您的權(quán)利,請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有