自己写的十二生肖验证

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。

      */
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值