张亮的博客园

联系方式:131280660812 微信号:131280660812 邮箱:1796969389@qq.com qq号:1796969389
黑马程序员+Winform基础(下)

13.练习:修改密码
        /// <summary>

        /// 修改密码

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)

        {

            string oldPwd = txtoldpwd.Text.Trim();

            string newPwd1= txtnewpwd1.Text.Trim();

            string newPwd2 = txtnewpwd2.Text.Trim();

            if (oldPwd.Equals("888888"))

            {

                if (newPwd1.Equals(oldPwd))

                {

                    MessageBox.Show("新密码与旧密码一样,重新输入!");

                    txtnewpwd1.Text = "";

                }

               else if (newPwd1.Equals(newPwd2))

                {

                    MessageBox.Show("修改成功!");

                }

                else

                {

                    MessageBox.Show("两次输入的新密码不一致!");

                    txtnewpwd1.Text = "";

                    txtnewpwd2.Text = "";

                }

            }

            else

            {

                MessageBox.Show("旧密码不正确!");

                txtoldpwd.Text = "";

                txtnewpwd1.Text = "";

                txtnewpwd2.Text = "";

            }

        }

13  练习:
       
 /// <summary>

        /// 统计ListBox中的最高得分者的姓名和分数

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void btnresult_Click(object sender, EventArgs e)

        {

           string[] lines= txtScore.Lines;

           int maxScore=-1;

           string maxName = "";

 

           for (int i = 0; i < lines.Length; i++)

           {

               string[] str=lines[i].Split('=');

               string name = str[0];//姓名

               string strScore = str[1];//分数

               int score = Convert.ToInt32(strScore);

               if (score>maxScore)

               {//更新最大成绩学员的姓名和分数

                   maxName = name;

                   maxScore = score;

               }

           }

           MessageBox.Show(string.Format("最高得分者是{0},得分为{1}",maxName,maxScore));

 

        }

 

14 练习:
         /// <summary>

        /// 四则运算

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)

        {

            string num1 = txtNum1.Text.Trim();

            string num2 = txtNum2.Text.Trim();

            int i1, i2;

            //转换成int

            if (!int.TryParse(num1,out i1))

            {

                MessageBox.Show("第一个数不合法");

                txtNum1.Text = "";

            }

            else if (!int.TryParse(num2,out i2))

            {

                MessageBox.Show("第二个数不合法");

                txtNum2.Text = "";

            }

            else

            {

                switch (cbOper.SelectedIndex)

                {

                    case 0: //+

                        MessageBox.Show(string.Format("{0}+{1}={2}", i1, i2, i1 + i2));

                        break;

                    case 1: //-

                        MessageBox.Show(string.Format("{0}-{1}={2}", i1, i2, i1 - i2));

                       

                        break;

                    case 2: //*

                        MessageBox.Show(string.Format("{0}*{1}={2}", i1, i2, i1 *i2));

                       

                        break;

                    case 3: // /

                        if (i2==0)

                        {

                            MessageBox.Show(string.Format("第二个数不能为0")); 

                        }

                        else

                        {

                            MessageBox.Show(string.Format("{0}/{1}={2}", i1, i2, i1 / i2));

                        }

                        break;

                    default:

                        throw new Exception("不合法运算符");

                }

            }

        }

15练习:
        /// <summary>

        /// 省市选择关联器

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void cbCity_SelectedIndexChanged(object sender, EventArgs e)

        {

            List<string> list = new List<string>();

            string[] anhui = {"合肥","安庆","蚌埠" };

            string[] guangdong = { "广州","深圳" };

            string[] shanghai = { "场圃" };

            cbCountry.Items.Clear();//清空之前数据

            switch (cbCity.SelectedIndex)

            {

                case 0: //安徽

                    cbCountry.Items.AddRange(anhui);

                    break;

                case 1: //广东

                    cbCountry.Items.AddRange(guangdong);

                    break;

                case 2: //上海

                    cbCountry.Items.AddRange(shanghai);

                    break;

                default:

                    break;

            }

        }

 

posted on 2013-11-03 19:39  张亮13128600812  阅读(104)  评论(0编辑  收藏  举报