日期:2008-11-30  浏览次数:20349 次


问题的提出:
在现代社会中,一个人总是离不开数字。人在社会上总要有一个身份证号码,学生在学校里读书一定会有一个学号,而且这些号码不都是一些无意义的数字。我写的这个程序是用来分析这些数字,并把其中有意义的意思表达出来。

编程环境:
VS.NET

实现技术:
ASP.NET

关键:
String.Substring(Int32,Int32)方法的运用,Literal控件的使用,switch语句的使用。

正文:
在Web窗体上,放上一个Label控件,一个Literal控件,一个TextBox控件,一个Button控件。设置Label控件的Text属性为“您的学号:”,Literal控件的Visible属性设置为“False”。我主要是对Button控件的Click()事件进行编码。当点击一下按钮后,对输入的数字进行分析,然后把分析的内容用Literal控件显示出来。

Button控件的Click()事件:

            string studentNo = txtNo.Text;    // 将学号赋给studentNo字符串

            if (!studentInfo.Visible)
            {
                studentInfo.Visible = true;    // 如果Literal控件是不可见的,则显示它.
            }

            try
            {
                // 取子串操作
                string strStartYear = studentNo.Substring(0,2);        // 入学年份
                string strTotalYears = studentNo.Substring(2,1);    // 学制
                string strSchool = studentNo.Substring(3,2);        // 学院
                string strClass = studentNo.Substring(5,1);            // 班级
                string strNumber = studentNo.Substring(6,2);        // 号码
            
                // 将数字跟文字对应起来
                // 内容纯属虚构
                switch (strSchool)
                {
                    case "01":
                        strSchool = "文学院";
                        break;
                    case "02":
                        strSchool = "理学院";
                        break;