十二生肖

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';

            }

        }

    }

}

 

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值