예제 #1
0
        private void showBlank()
        {
            blankPanel.BringToFront();
            Blank b = (Blank)blankList[curNum - choiceAmount];

            blankQuestion.Text = b.questionDesc;

            // 根据填空题的空格数量来显示输入框
            int size = textList.Count;

            for (int i = 0; i < b.blankNum; ++i)                                             // 需要显示的输入框, 则清空之前输入的数据
            {
                textList[i].Visible = true;                                                  // 显示
                textList[i].Text    = null == blankAnswer[curNum - choiceAmount, i] ?
                                      "" : blankAnswer[curNum - choiceAmount, i].ToString(); // 清空之前的数据
            }

            // 隐藏多余的输入框
            for (int i = b.blankNum; i < size; ++i)
            {
                textList[i].Visible = false; // 隐藏多余的输入框
            }
        }
예제 #2
0
        private void readBlankData()
        {
            // 读取 blank.txt 嵌入资源文件
            Assembly     asm    = Assembly.GetExecutingAssembly();
            Stream       stream = asm.GetManifestResourceStream("ExamSystem.resource.blank.txt");
            StreamReader reader = new StreamReader(stream);

            String line  = null;
            Blank  b     = new Blank();
            int    count = 0;

            blankList = new ArrayList();
            while ((line = reader.ReadLine()) != null)
            {
                ++count;
                switch (count)
                {
                case 1:
                    b.questionDesc = line;
                    break;

                case 2:
                    b.blankNum = Convert.ToInt32(line);
                    break;

                case 3:
                    string[] blanks = line.Split(',');     // 分割得到答案
                    b.blankA = blanks[0];

                    // 赋值给答案
                    if (blanks.Length >= 2)
                    {
                        b.blankB = blanks[1];
                    }

                    if (blanks.Length >= 3)
                    {
                        b.blankC = blanks[2];
                    }

                    if (blanks.Length == 4)
                    {
                        b.blankD = blanks[3];
                    }
                    break;

                default:
                    break;
                }

                if ("" == line || "end" == line)
                {
                    count = 0;
                    blankList.Add(b);
                    b = new Blank();
                }
            }

            blankAmount = blankList.Count;
            reader.Close();
        }
예제 #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            // 判断是否已经提交过
            if (System.IO.File.Exists(dirPath + fileName))
            {
                MessageBox.Show("已经提交答案,不能再次提交!");

                return;
            }

            // 计算成绩
            totalScore = 0;
            // 遍历用户选择题答案
            for (int i = 0; i < choiceAmount; ++i)
            {
                if (choiceAnswer[i] == ((Choice)choiceList[i]).answer)
                {
                    totalScore += choiceScore;
                }
            }

            // 遍历填空题进行比较
            for (int i = 0; i < blankAmount; ++i) // 遍历每道填空题
            {
                Blank b = (Blank)blankList[i];
                for (int j = 0; j < b.blankNum; ++j)       // 遍历用户第 i 题的回答的答案(不分顺序)
                {
                    string userAnswer = blankAnswer[i, j]; // 用户回答的答案

                    // 不分顺序, 则判断用户回答的答案是否在正确答案中
                    if ("" != userAnswer && null != userAnswer) // 判断用户是否回答该问题
                    {
                        // 用户回答了该问题, 则判断是否在正确答案中
                        userAnswer = userAnswer.Trim();
                        if (userAnswer == b.blankA)
                        {
                            totalScore += blankScore;
                        }
                        else if (userAnswer == b.blankB)
                        {
                            totalScore += blankScore;
                        }
                        else if (userAnswer == b.blankC)
                        {
                            totalScore += blankScore;
                        }
                        else if (userAnswer == b.blankD)
                        {
                            totalScore += blankScore;
                        }
                    }
                }
            }

            string score = "最终成绩为: " + totalScore;

            MessageBox.Show(score); // 对话框显示
            scoreLabel.Text = "成绩:" + totalScore;

            // 判断是否有该目录, 如果没有该目录, 则创建目录
            if (!System.IO.Directory.Exists(dirPath))
            {
                System.IO.Directory.CreateDirectory(dirPath);
            }
            File.WriteAllText(dirPath + fileName, score);


            // MessageBox.Show("textBlank1.Text is: " + textBlank1.Text + ",textBlank1.Text == \"\"" + (textBlank1.Text == ""));
        }