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