最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2016年08月24日 10:45:02   作者:※WYF※  
這篇文章主要為大家詳細(xì)介紹了C#根據(jù)身份證號碼判斷出生日期和性別的方法,感興趣的小伙伴們可以參考一下

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

用C#寫的代碼如下:

/// <summary>
/// 在控件驗(yàn)證 textBox_IdentityCard 的 Validated事件中定義身份證號碼的合法性并根據(jù)身份證號碼得到生日和性別 
/// </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();//設(shè)置當(dāng)前輸入焦點(diǎn)為textBox_IdentityCard

      }

      return;

    }

    else

    {

      //身份證號碼只能為15位或18位其它不合法

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

      {

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

        if (textBox_IdentityCard.CanFocus)

        {

          textBox_IdentityCard.Focus();

        }

        return;

      }

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

    }<br>

    //處理15位的身份證號碼從號碼中得到生日和性別代碼
    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("身份證號碼輸入有誤");
    if (textBox_IdentityCard.CanFocus)
    {
      textBox_IdentityCard.Focus();
    }
    return;
  }
}

 以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

石楼县| 宁武县| 蓬莱市| 吴江市| 阳原县| 长顺县| 固安县| 白玉县| 盘锦市| 峡江县| 永济市| 天门市| 常宁市| 正镶白旗| 乐都县| 宁海县| 汶川县| 永兴县| 清原| 阿克苏市| 文成县| 辽阳市| 武乡县| 页游| 彩票| 凤翔县| 宾川县| 南汇区| 东乌| 淳安县| 西乡县| 卓尼县| 鱼台县| 马边| 朝阳区| 宁陕县| 吉水县| 华容县| 紫云| 桑日县| 定日县|