using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test_01
{
public partial class My_Frm01 : Form
{
public My_Frm01()
{
InitializeComponent();
}
/*1.设计一个窗体,窗体里面有一个文本框、一个标签和一个按钮。当在文本框里面输入一个身份证号码,
* 单击按钮后在标签里面显示这个身份证号码的出生年月日、性别,并显示出生肖。
*提示:身份证在第七位到第十位为年份
* 第十一位到第第十二位为月份
* 第十三位到第十四位为日
* 倒数第二位判断奇偶数,奇数为男性,偶数为女性
*然后根据“鼠牛虎兔龙蛇马羊猴鸡狗猪”这个顺序来求生肖,
*以2009年为牛年作为标准。当年份 % 12的时候,余数大于3,则减3。否则加9。
*要求:文本框只能输入18位,前17位必须为数字,最后一位只能是数字或者是大写X和大写Y。
*/
private void btnshow_Click(object sender, EventArgs e)
{
if (this.txtGetID.Text.Length != 18)
{
MessageBox.Show("你输入的身份证不合法 请重新输入", "警告");
this.txtGetID.Text = "";
}
else
{
string strID = this.txtGetID.Text;
string strYear = strID.Substring(6,4);
string strMonth = strID.Substring(10,2);
string strDays = strID.Substring(12,2);
int intSex = int.Parse(strID.Substring(16,1));
string strSex = string.Empty;
if (intSex % 2 == 0)
{
strSex = "女";
}
else
{
strSex = "男";
}
this.labMessage.Text = string.Format("你是{0}年{1}月{2}日出生的,性别为{3}。",strYear,strMonth,strDays,strSex);
//string strshengxiao = "鼠牛虎兔龙蛇马羊猴鸡狗猪";
int intYear = int.Parse(strYear);
int i = intYear % 12;
int a = 0;
if (i - 3 > 0)
{
a = i - 3;
}
else
{
a = i + 9;
}
this.picBox.Image = Image.FromFile(Application.StartupPath + @"/pic/" + a + ".gif");
}
}
private void txtGetID_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar >= 48 && e.KeyChar <= 57 || e.KeyChar == 8)
{
}
else if ((e.KeyChar == (char)Keys.X || e.KeyChar == (char)Keys.Y) && this.txtGetID.Text.Length == 17)
{
}
else
{
e.KeyChar = '/0';
}
}
}
}