当前位置:首页 > 在线考试系统的设计与实现毕业论文 - 图文
学员先进行注册同时会把数据存储到建好的数据库中,然后再点击“在线答题”控件,则弹跳出试题选择窗体,考生看完说明后,选择所考科目,根据考试的科目会弹跳出相符的页面。主要代码如下。
string sql = \try {
SqlCommand command =
new SqlCommand(sql, DBHelper.connection); DBHelper.connection.Open(); // 执行查询
SqlDataReader dataReader = command.ExecuteReader();
// 循环添加到组合框中
while (dataReader.Read()) {
cboSubjects.Items.Add(dataReader[\ }
dataReader.Close(); }
// ……
3.3.2随机抽题: 自定义 SetSelectedQuestionIds() 方法 Random random = new Random();
int questionIndex = 0; // 随机产生的问题的索引值
// 抽取每一道题并保存抽出的题目的Id int i = 0; // 记录抽取了几道题 while (i < QuizHelper.questionNum) {
// 在所有问题的数量范围内抽题产生随机数
questionIndex = random.Next(QuizHelper.allQuestionIds.Length); // 如果没有被选中过,可以选择
if (QuizHelper.selectedStates[questionIndex] == false) {
QuizHelper.selectedQuestionIds[i] =
QuizHelper.allQuestionIds[questionIndex]; QuizHelper.selectedStates[questionIndex] = true; i++; }
}
3.3.3在线考试的“回答问题”页面的设计
在新建的页面里面添加时间(tmrCostTime),控制整个考试时间,代码如下: private void tmrCostTime_Tick(object sender, EventArgs e) {
int minute; // 当前的分钟 int second; // 秒
// 如果还有剩余时间,就显示剩余的分钟和秒数 if (QuizHelper.remainSeconds > 0) {
QuizHelper.remainSeconds--;
minute = QuizHelper.remainSeconds / 60; second = QuizHelper.remainSeconds % 60;
lblTimer.Text = string.Format(\minute, second); // 补充知识点 }
// 否则,就提示交卷 else {
tmrCostTime.Stop();
MessageBox.Show(\时间到了,该交卷了!\提示\MessageBoxButtons.OK, MessageBoxIcon.Warning);
QuizResultForm quizResultForm = new QuizResultForm(); quizResultForm.MdiParent = this.MdiParent; quizResultForm.Show(); this.Close(); }
3.3.4 CheckOption() 方法:
switch (QuizHelper.studentAnswers[questionIndex]) {
case \
rdoOptionA.Checked = true; break; case \
rdoOptionB.Checked = true; break; case \
rdoOptionC.Checked = true; break; case \
rdoOptionD.Checked = true; break; default:
// 四个选项的 Checked 都设为 false break;
}
3.3.5记录学员的答案:
四个单选按钮共用一个 Click 事件处理方法 // 选择答案时,记录答案
private void rdoOption_Click(object sender, EventArgs e) {
QuizHelper.studentAnswers[questionIndex] =
Convert.ToString( ( (RadioButton)sender ).Tag); }
3.4在线考试答题卡页面的设计 3.4.1窗体加载时,显示答案: // 窗体的 Load 事件
private void AnswerCardForm_Load(object sender, EventArgs e) {
int index = 0;
foreach (Control item in this.Controls) {
if (item is Label ) // 如果是标签 {
index = Convert.ToInt32(item.Tag); if (index != -1) {
item.Text = QuizHelper.studentAnswers[index];
} } }
tmrCostTime.Start(); // 启动倒计时的计时器 }
3.4.2点击题号,返回修改答案
20个题号按钮共用一个 Click 事件处理方法,代码如下所示: private void btnQuestion_Click(object sender, EventArgs e) {
// 获得当前点击的按钮对应的题目索引 int questionIndex =
Convert.ToInt32(((Button)sender).Tag);
// 打开答题窗体
AnswerQuestionForm answerQuestionForm = new AnswerQuestionForm(); // 设置答题窗体显示的题目索引
answerQuestionForm.questionIndex = questionId; answerQuestionForm.MdiParent = this.MdiParent; answerQuestionForm.Show(); this.Close(); }
3.4显示结果窗体
图13答题结果窗体
分数的显示代码如下:
private void QuizResultForm_Load(object sender, EventArgs e) {
int correctNum = 0; // 答对的题目数量
for (int i = 0; i < QuizHelper.questionNum; i++) {
if (QuizHelper.studentAnswers[i]
==QuizHelper.correctAnswers[i])
{
correctNum++; } }
// 计算得分
int score = correctNum * 100 / QuizHelper.questionNum; lblMark.Text = score.ToString()+\分\
共分享92篇相关文档