模拟考试系统C#源码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
模拟考试系统C#源码
开始窗体
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
using System;
using System.Collections.Generic; using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Exam
{
public partial class ExamForm : Form
{
public ExamForm()
{
InitializeComponent();
}
///
/// ExamForm
///
///
///
private void ExamForm_Load(object sender, EventArgs e)
{
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();
}
int i = 8;
private void timer1_Tick(object sender, EventArgs e)
{
this.progressBar1.PerformStep();
i--;
if (i==0)
{
this.timer1.Stop();
FormExam f = new FormExam();
f.Show();
this.Hide();
}
}
}
}
数据库辅助类
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
using System;
using System.Collections.Generic; using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace Exam
{
public class DataBase
{
public string connString =
@"Data Source=XUTAO;Initial Catalog=Exam;Integrated Security=True";
private SqlConnection conn;
///
/// SqlConnection
///
public SqlConnection Conn
{
get
{
if (conn == null)
{
conn = new SqlConnection(connString);
}
return conn;
}
}
///
/// 打开数据库
///
public void openData()
{
if (Conn.State == ConnectionState.Closed)
{
Conn.Open();
}
else if (Conn.State == ConnectionState.Broken)
{
Conn.Close();
Conn.Open();
}
}
///
/// 关闭数据库
///
public void closeData()
{
if (Conn.State == ConnectionState.Open ||
Conn.State == ConnectionState.Broken)
{
Conn.Close();
}
}
}
}
主窗体
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
using System;
using System.Collections.Generic; using System.ComponentModel; using
System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; using System.Data.SqlClient;
namespace Exam
{
public partial class FormExam : Form
{
public FormExam()
{
InitializeComponent();
}
///
/// 调用数据库
///
DataBase db = new DataBase();
///
/// ExamForm
///
///
///
private void FormExam_Load(object sender, EventArgs e)
{
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;