模拟考试系统C#源码.docx
- 文档编号:23712739
- 上传时间:2023-05-20
- 格式:DOCX
- 页数:39
- 大小:60.17KB
模拟考试系统C#源码.docx
《模拟考试系统C#源码.docx》由会员分享,可在线阅读,更多相关《模拟考试系统C#源码.docx(39页珍藏版)》请在冰豆网上搜索。
模拟考试系统C#源码
模拟考试系统C#源码
开始窗体
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
usingSystem;
usingSystem.Collections.Generic;usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceExam
{
publicpartialclassExamForm:
Form
{
publicExamForm()
{
InitializeComponent();
}
///
///ExamForm
///
///
///
privatevoidExamForm_Load(objectsender,EventArgse)
{
CenterToScreen();
Text="模拟考试系统";
this.Width=360;
this.Height=230;
this.progressBar1.Width=360;
this.progressBar1.Height=10;
this.progressBar1.Left=0;
this.progressBar1.Top=220;
this.timer1.Start();
}
inti=8;
privatevoidtimer1_Tick(objectsender,EventArgse)
{
this.progressBar1.PerformStep();
i--;
if(i==0)
{
this.timer1.Stop();
FormExamf=newFormExam();
f.Show();
this.Hide();
}
}
}
}
数据库辅助类
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
usingSystem;
usingSystem.Collections.Generic;usingSystem.Linq;
usingSystem.Text;
usingSystem.Data;
usingSystem.Data.SqlClient;
namespaceExam
{
publicclassDataBase
{
publicstringconnString=
@"DataSource=XUTAO;InitialCatalog=Exam;IntegratedSecurity=True";
privateSqlConnectionconn;
///
///SqlConnection
///
publicSqlConnectionConn
{
get
{
if(conn==null)
{
conn=newSqlConnection(connString);
}
returnconn;
}
}
///
///打开数据库
///
publicvoidopenData()
{
if(Conn.State==ConnectionState.Closed)
{
Conn.Open();
}
elseif(Conn.State==ConnectionState.Broken)
{
Conn.Close();
Conn.Open();
}
}
///
///关闭数据库
///
publicvoidcloseData()
{
if(Conn.State==ConnectionState.Open||
Conn.State==ConnectionState.Broken)
{
Conn.Close();
}
}
}
}
主窗体
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
usingSystem;
usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;usingSystem.Data.SqlClient;
namespaceExam
{
publicpartialclassFormExam:
Form
{
publicFormExam()
{
InitializeComponent();
}
///
///调用数据库
///
DataBasedb=newDataBase();
///
///ExamForm
///
///
///
privatevoidFormExam_Load(objectsender,EventArgse)
{
CenterToScreen();
this.Cursor=Cursors.Hand;
this.Text="模拟考试系统";
this.tscmbExamType.SelectedIndex=0;
this.timerDate.Start();
this.Width=1000;
this.Height=600;
this.MaximizeBox=false;
this.Top=50;
this.groupBox1.Top=40;
this.groupBox1.Left=10;
this.groupBox1.Height=250;
this.groupBox1.Width=200;
this.listExam.GridLines=true;
this.listExam.FullRowSelect=true;
this.groupBox2.BackColor=Color.Transparent;
this.groupBox2.Text="试题题干";
this.groupBox2.Height=250;
this.groupBox2.Width=755;
this.groupBox2.Left=215;
this.groupBox2.Top=40;
this.groupBox2.ForeColor=Color.White;
this.rtbExam.ReadOnly=true;
this.groupBox3.Text="试题选项";
this.groupBox3.ForeColor=Color.White;
this.groupBox3.BackColor=Color.Transparent;
this.groupBox3.Left=215;
this.groupBox3.Width=755;
this.groupBox3.Height=250;
this.groupBox3.Top=295;
this.groupBox4.Text="操作区域";
this.groupBox4.ForeColor=Color.White;
this.groupBox4.BackColor=Color.Transparent;
this.groupBox4.Width=200;
this.groupBox4.Height=250;
this.groupBox4.Top=295;
this.groupBox4.Left=10;
this.button1.Text="开始答题";
this.button1.Top=40;
this.button1.Left=50;
this.button1.Width=90;
this.button1.Height=25;
this.button1.ForeColor=Color.Blue;
this.button2.Text="上一试题";
this.button2.Top=80;
this.button2.Left=50;
this.button2.Width=90;
this.button2.Height=25;
this.button2.ForeColor=Color.Blue;
this.button3.Text="下一试题";
this.button3.Top=120;
this.button3.Left=50;
this.button3.Width=90;
this.button3.Height=25;
this.button3.ForeColor=Color.Blue;
this.button4.Text="停止答题";
this.button4.Top=160;
this.button4.Left=50;
this.button4.Width=90;
this.button4.Height=25;
this.button4.ForeColor=Color.Blue;
this.button5.Text="提交试题";
this.button5.Top=200;
this.button5.Left=50;
this.button5.Width=90;
this.button5.Height=25;
this.button5.ForeColor=Color.Blue;
this.radioButton1.Text="A";
this.radioButton1.Left=5;
this.radioButton1.Top=50;
this.radioButton1.ForeColor=Color.GreenYellow;
this.radioButton1.Enabled=false;
this.radioButton2.Text="B";
this.radioButton2.Left=5;
this.radioButton2.Top=100;
this.radioButton2.ForeColor=Color.GreenYellow;
this.radioButton2.Enabled=false;
this.radioButton3.Text="C";
this.radioButton3.Left=5;
this.radioButton3.Top=150;
this.radioButton3.ForeColor=Color.GreenYellow;
this.radioButton3.Enabled=false;
this.radioButton4.Text="D";
this.radioButton4.Left=5;
this.radioButton4.Top=200;
this.radioButton4.ForeColor=Color.GreenYellow;
this.radioButton4.Enabled=false;
this.label1.Left=40;
this.label1.Top=52;
this.label1.Text="";
this.label2.Left=40;
this.label2.Top=102;
this.label2.Text="";
this.label3.Left=40;
this.label3.Top=152;
this.label3.Text="";
this.label4.Left=40;
this.label4.Top=202;
this.label4.Text="";
this.label5.Left=5;
this.label5.Top=20;
this.label5.Text="";
this.label5.ForeColor=Color.Red;
this.label6.Left=35;
this.label6.Top=20;
this.label6.Text="";
this.listExam.Enabled=false;
this.button2.Enabled=false;
this.button3.Enabled=false;
this.button4.Enabled=false;
this.button5.Enabled=false;
this.toolStripButton1.Enabled=false;
}
///
///时间
///
///
///
privatevoidtimerDate_Tick(objectsender,EventArgse)
{
this.toolStripLabel2.Text=DateTime.Now.ToString();
}
intj=600;
///
///计时器
///
///
///
privatevoidtimerP_Tick(objectsender,EventArgse)
{
j--;
this.toolStripLabel4.Text=j.ToString();
if(j>60)
{
this.toolStripLabel4.ForeColor=Color.GreenYellow;
}
else
{
this.toolStripLabel4.ForeColor=Color.Red;
}
if(j==0)
{
this.timerP.Stop();
this.radioButton1.Enabled=false;
this.radioButton2.Enabled=false;
this.radioButton3.Enabled=false;
this.radioButton4.Enabled=false;
this.label1.Enabled=false;
this.label2.Enabled=false;
this.label3.Enabled=false;
this.label4.Enabled=false;
this.listExam.Enabled=false;
this.button1.Enabled=false;
this.button2.Enabled=false;
this.button3.Enabled=false;
this.button4.Enabled=false;
this.button5.Enabled=true;
MessageBox.Show("时间到,请提交试题~");
return;
}
}
///
///开始答题
///
///
///
privatevoidbutton1_Click(objectsender,EventArgse)
{
this.timerP.Start();
this.radioButton1.Enabled=true;
this.radioButton2.Enabled=true;
this.radioButton3.Enabled=true;
this.radioButton4.Enabled=true;
this.label1.Enabled=true;
this.label2.Enabled=true;
this.label3.Enabled=true;
this.label4.Enabled=true;
this.listExam.Enabled=true;
this.listExam.Focus();//第一行默认选中
this.listExam.Items[0].Selected=true;
this.button1.Enabled=false;
this.button2.Enabled=true;
this.button3.Enabled=true;
this.button4.Enabled=true;
this.button5.Enabled=true;
}
///
///停止答题
///
///
///
privatevoidbutton4_Click(objectsender,EventArgse)
{
this.timerP.Stop();
this.radioButton1.Enabled=false;
this.radioButton2.Enabled=false;
this.radioButton3.Enabled=false;
this.radioButton4.Enabled=false;
this.label1.Enabled=false;
this.label2.Enabled=false;
this.label3.Enabled=false;
this.label4.Enabled=false;
this.listExam.Enabled=false;
this.button1.Enabled=true;
this.button2.Enabled=false;
this.button3.Enabled=false;
this.button4.Enabled=false;
this.button5.Enabled=false;
}
///
///显示试题表数据
///
publicvoidListShow()
{
Randomrandom=newRandom();
intrand=random.Next(0,190);
stringsql=string.Format(@"selecttop10
ExamPaper.SubjectNo,
ExamPaper.SubjectName,
ExamResult.A,ExamResult.B,
ExamResult.C,ExamResult.D,
ExamPaper.TypeID
fromExamPaper
innerjoin
ExamResult
on
ExamPaper.TypeID=ExamResult.TypeID
and
ExamPaper.SubjectNo=ExamResult.SubjectNo
whereExamPaper.SubjectNo
notin
(selecttop{0}ExamPaper.SubjectNofromExamPaper)
andExamResult.TypeID=
(selectTypeIDfromExamPaperType
where
ExamPaperType.TypeNamelike'%{1}%')",
rand,this.tscmbExamType.Text.Substring(0,3));
try
{
db.openData();
SqlCommandcomm=newSqlCommand(sql,db.Conn);
SqlDataReaderreader=comm.ExecuteReader();
if(!
reader.HasRows)
{
return;
}
else
{
while(reader.Read())
{
stringSubjectNo=reader["SubjectNo"].ToString();//题号
stringSubjectName=reader["SubjectName"].ToString();//题干
stringTypeID=r
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 模拟考试 系统 C# 源码