Example #1
0
        }  //else 結尾

        private void btnsearch_Click(object sender, EventArgs e)
        {
            a6StuCls student = new a6StuCls();

            if (textname.Text == string.Empty)
            {
                MessageBox.Show("請輸入", "姓名");
                textname.Text = "";
                textname.Focus();
            }
            string subch  = "";
            string subeng = "";
            string subma  = "";
            bool   check  = false;

            foreach (a6StuCls x in studentlist)// x在studentlist裡
            {
                if (x.stuName == textname.Text)
                {
                    student.stuName    = x.stuName;
                    student.stuChinese = x.stuChinese;
                    student.stuEnglish = x.stuEnglish;
                    student.stuMath    = x.stuMath;
                    check = !check;
                    break;
                }
            }
            if (check && student.stuName == textname.Text)
            {
                if (student.stuChinese < 60)
                {
                    subch = ",不及格";
                }
                if (student.stuEnglish < 60)
                {
                    subeng = ",不及格";
                }
                if (student.stuMath < 60)
                {
                    subma = ",不及格";
                }

                labelsingle.Text = $"\n查詢結果:\n" +
                                   $"姓名:{student.stuName}\n" +
                                   $"國文:{student.stuChinese}{subch}\n" +
                                   $"英文:{student.stuEnglish}{subeng}\n" +
                                   $"數學:{student.stuMath}{subma}" +
                                   $"\n平均:{Math.Round((student.stuMath + student.stuChinese + student.stuEnglish) / 3)}" +
                                   $"\n------------------------------------------\n";
            }
            else
            {
                MessageBox.Show("找不到學生成績", "錯誤");
            }
        }
Example #2
0
        private void btnkeyIN_Click(object sender, EventArgs e)//輸入成績
        {
            checknull();
            bool   check = false;
            double schinese, smath, seng;

            if (double.TryParse(textchinese.Text, out schinese) == false)
            {
                MessageBox.Show("請輸入數字", "國文成績");
                textchinese.Text = "";
                textchinese.Focus();
            }  //輸入國文成績判斷格式
            else if (double.TryParse(textenglish.Text, out smath) == false)
            {
                MessageBox.Show("請輸入數字", "英文成績");
                textenglish.Text = "";
                textenglish.Focus();
            }  //輸入英文成績判斷格式
            else if (double.TryParse(textmath.Text, out seng) == false)
            {
                MessageBox.Show("請輸入數字", "數學成績");
                textmath.Text = "";
                textmath.Focus();
            }   //輸入數學成績判斷格式
            foreach (a6StuCls x in studentlist)
            {
                if (x.stuName == textname.Text)
                {
                    MessageBox.Show("重複輸入", "學生成績");
                    check = !check;
                    break;
                }
            }
            if (check == false)
            {
                checknull();
                a6StuCls student = new a6StuCls();
                student.stuName    = textname.Text;
                student.stuChinese = double.Parse(textchinese.Text);
                student.stuMath    = double.Parse(textmath.Text);
                student.stuEnglish = double.Parse(textenglish.Text);

                studentlist.Add(student);

                dataGridView1.Refresh();
                dataGridView1.DataSource = studentlist;
            }
        }  //else 結尾