文档库 最新最全的文档下载
当前位置:文档库 › 驾照理论考试模拟系统

驾照理论考试模拟系统

驾照理论考试模拟系统代码 (C#)

using System;
using System.Collections.Generic;
using https://www.wendangku.net/doc/0116606878.html,ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace LoginFrame
{
static class Program
{
///


/// 应用程序的主入口点。
///

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}



public partial class Form1 : Form
{
public Form1()
{

InitializeComponent();
comboBox1.Items.Add("请选择");
comboBox1.Items.Add("管理员");
comboBox1.Items.Add("考生");
comboBox1.SelectedIndex = 0;


}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{

string result = "";
result = comboBox1.SelectedItem.ToString();
if (result.Equals("请选择"))
{
MessageBox.Show("请选择身份", "选择提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Hand);
}
else if (result == "管理员")
{
Hide();
Form2 frm2 = new Form2();
frm2.Show();

}
else
{
Hide();
Form考生进入 frm4 = new Form考生进入();
frm4.Show();
}

}

private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void button3_Click(object sender, EventArgs e)
{
Form系统信息 frmm = new Form系统信息();
frmm.Show();
}


}


public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Form3录入 frm3 = new Form3录入();
frm3.Show();
}

private void button4_Click(object sender, EventArgs e)
{
Form查看题目 frm5 = new Form查看题目();
frm5.Show();
}

private void button6_Click(object sender, EventArgs e)
{

// Application.Exit();
Form1 form22 = new Form1();
form22.Show();
this.Close();


}

private void button5_Click(object sender, EventArgs e)
{
Form6查看考生资料 frm6 = new Form6查

看考生资料();
frm6.Show();
}

private void button2_Click(object sender, EventArgs e)
{
Del_Exam delfrm = new Del_Exam();
delfrm.Show();
}




}


public partial class Form3录入 : Form
{

public Form3录入()
{
InitializeComponent();

}



private void button2_Click(object sender, EventArgs e)
{
this.Close();
}

private void button1_Click(object sender, EventArgs e)
{

}

private void button1_Click_1(object sender, EventArgs e)
{

string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
string sql = String.Format("insert into No_Exam(题号,内容,A,B,C,D,答案) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", textBox1.Text, textBox7.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text,textBox6.Text);



SqlConnection connection = new SqlConnection(connString);
SqlCommand comm = new SqlCommand(sql, connection);
connection.Open();

try
{

int a = comm.ExecuteNonQuery();

if (a > 0)
{
MessageBox.Show("试题录入成功!");
}
}
catch (System.Exception ex)
{
MessageBox.Show("试题录入失败!");
}
finally
{
connection.Close();
}
}


private void label3_Click(object sender, EventArgs e)
{

}


}


public partial class Form5做题 : Form
{
string kaohao;
string xingming;
private int flag = 0;
string an = "";//储存正确答案
int error = 0;//错误数
int score = 100;
int Sum = 0;
public Form5做题()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
SqlConnection connection = new SqlConnection(connString);
connection.Open();



try
{
Random myNum = new Random();
int i = myNum.Next(1, 100);
string sql = String.Format("SELECT 内容 ,A,B,C,D,答案 FROM No_Exam WHERE 题号 ='{0}'", i);

SqlCommand command = new SqlCommand(sql, connection);



SqlDataReader reader = command.ExecuteReader();//记录类 reader为

记录对象

reader.Read();//读取下一行
label6.Text = reader[0].ToString();//获得记录集
label1.Text = reader[1].ToString();
label2.Text = reader[2].ToString();
label3.Text = reader[3].ToString();
label4.Text = reader[4].ToString();
an = reader[5].ToString();
Sum++;
}
catch (System.Exception ex)
{
MessageBox.Show("连接数据库失败,检查是否存在此数据库");
}
finally
{

connection.Close();

}


}

private void Form5做题_Load(object sender, EventArgs e)
{

}



private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
flag = 1;
}

private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
flag = 2;
}

private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
flag = 3;
}

private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
flag = 4;
}

private void button2_Click(object sender, EventArgs e)
{

switch (flag)
{
case 1: if (an.Equals(flag.ToString())) MessageBox.Show("回答正确!"); else { MessageBox.Show("选择错误,正确答案为:" + an); error++; score -= 10;} break;
case 2: if (an.Equals(flag.ToString())) MessageBox.Show("回答正确!"); else { MessageBox.Show("选择错误,正确答案为:" + an); error++; score -= 10; } break;
case 3: if (an.Equals(flag.ToString())) MessageBox.Show("回答正确!"); else { MessageBox.Show("选择错误,正确答案为:" + an); error++; score -= 10; }break;
case 4: if (an.Equals(flag.ToString())) MessageBox.Show("回答正确!"); else { MessageBox.Show("选择错误,正确答案为:" + an); error++; score -= 10; } break;
default: MessageBox.Show("请先选择答案!"); break;
}

string connString1 = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
SqlConnection connection1 = new SqlConnection(connString1);

try
{

connection1.Open();
Random myNum = new Random();
int i = myNum.Next(1, 100);
string sql = String.Format("SELECT 内容 ,A,B,C,D,答案 FROM No_Exam WHERE 题号 ='{0}'", i);

SqlCommand

command1 = new SqlCommand(sql, connection1);
SqlDataReader reader = command1.ExecuteReader();//记录类 reader为记录对象

reader.Read();//读取下一行
label6.Text = reader[0].ToString();//获得记录集
label1.Text = reader[1].ToString();
label2.Text = reader[2].ToString();
label3.Text = reader[3].ToString();
label4.Text = reader[4].ToString();
an = reader[5].ToString();
Sum++;

}
catch (System.Exception ex)
{
MessageBox.Show("连接数据库失败,检查是否存在此数据库");
}
finally
{

connection1.Close();


}

if (Sum == 10)
{
MessageBox.Show(" 答题结束,共回答10道题,错误题目数: " + error + " 分数为: " + score);
// string connString2 = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
SqlConnection connection2 = new SqlConnection(connString1);
string sql2 = String.Format("update Info set 分数={0} where 考生号={1}", score, kaohao);
try
{

connection2.Open();
SqlCommand command2 = new SqlCommand(sql2, connection2);
int i = command2.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("您的成绩已经记入档案!");
}

}
catch (System.Exception ex)
{
MessageBox.Show("连接数据库失败!");
}
finally
{

connection2.Close();
button2.Visible = false;
button4.Visible = true;


}


}


}

private void button3_Click(object sender, EventArgs e)
{
kaohao = textBox1.Text;

string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
string sql = String.Format("select 考生号 ,姓名 from Info where 考生号='{0}'", textBox1.Text);

SqlConnection connection = new SqlConnection(connString);

connection.Open();
try
{


SqlCommand command1 = new SqlCommand(sql, connection);

SqlDataReader reader = command1.ExecuteReader();//记录类 reader为记录对象

reader.Read();//读取

下一行

kaohao = reader[0].ToString();
xingming = reader[1].ToString();
label7.Text = ("当前考生:"+kaohao + xingming );
button1 .Visible =true ;
textBox1.Visible = false;





}

catch (System.Exception ex)
{
MessageBox.Show("您还没有注册,请先注册!!");
this.Close();
Form考生进入 frm4 = new Form考生进入();
frm4.Show();

}
finally
{
connection.Close();

}


}

private void button4_Click(object sender, EventArgs e)
{
Form1 form22 = new Form1();
form22.Show();
this.Close();

}



}


public partial class Form6查看考生资料 : Form
{
public Form6查看考生资料()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
DataSet dataset = new DataSet();
SqlConnection connection = new SqlConnection(connString);
try
{
SqlDataAdapter DataAdapter = new SqlDataAdapter("select * from Info", connection);
DataAdapter.Fill(dataset, "Infoo");
dataGridView1.DataSource = dataset;
dataGridView1.DataMember = "Infoo";
}

catch (Exception ex)
{
MessageBox.Show(ex.ToString());

}
finally
{
connection.Close();
connection.Dispose();
dataset.Dispose();
}

}

private void button3_Click(object sender, EventArgs e)
{
this.Close();
}

private void button2_Click(object sender, EventArgs e)
{
string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
DataSet dataset = new DataSet();
SqlConnection connection = new SqlConnection(connString);
string sql=String.Format("select * from Info where 考生号= '{0}'",textBox1.Text);
try
{
SqlDataAdapter DataAdapter = new SqlDataAdapter(sql, connection);

DataAdapter.Fill(dataset, "Infooo");
dataGridView1.DataSource = dataset;
dataGridView1.DataMember = "Infooo";
}

catch (Exception ex)
{
MessageBox.Show(ex.ToString());


}
finally
{
connection.Close();
connection.Dispose();
dataset.Dispose();
}

}
}


public partial class Form查看题目 : Form
{
public Form查看题目()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{


string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
DataSet dataset = new DataSet();
SqlConnection connection = new SqlConnection(connString);
string sql = String.Format("select * from No_Exam where 题号= '{0}'", textBox1.Text);
try
{
SqlDataAdapter DataAdapter = new SqlDataAdapter(sql, connection);
DataAdapter.Fill(dataset, "EXAM");
dataGridView1.DataSource = dataset;
dataGridView1.DataMember = "EXAM";
}

catch (Exception ex)
{
MessageBox.Show(ex.ToString());

}
finally
{
connection.Close();
connection.Dispose();
dataset.Dispose();
}


}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}

private void label1_Click(object sender, EventArgs e)
{

}

private void button3_Click(object sender, EventArgs e)
{
string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
DataSet dataset = new DataSet();
SqlConnection connection = new SqlConnection(connString);

try
{
SqlDataAdapter DataAdapter = new SqlDataAdapter("select * from No_Exam", connection);
DataAdapter.Fill(dataset, "EXAM");
dataGridView1.DataSource = dataset;
dataGridView1.DataMember = "EXAM";
}

catch (Exception ex)
{
MessageBox.Show(ex.ToString());

}
finally
{
//connection.Close();
connection.Dispose();
dataset.Dispose();
}
}

private void button2_Click(object sender, EventArgs e)
{
string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
DataSet dataset = new DataSet();
SqlConnection connection = new SqlConnection(connString);
string sql = String.Format("select * from No_Exam where 内容 like '%{0}%'", textBox2.Text);
try
{

SqlDataAdapter DataAdapter = new SqlDataAdapter(sql, connection);
DataAdapter.Fill(dataset, "EXAM");
dataGridView1.DataSource = dataset;
dataGridView1.DataMember = "EXAM";

}

catch (Exception ex)
{
MessageBox.Show("查无此题!");

}
finally
{
connection.Close();
connection.Dispose();
dataset.Dispose();
}
}

private void button4_Click(object sender, EventArgs e)
{
this.Close();

}

private void button7_Click(object sender, EventArgs e)
{
label3.Visible = true;
label4.Visible = true;
textBox3.Visible = true;
textBox4.Visible = true;
button6.Visible = true;
}

private void button6_Click(object sender, EventArgs e)
{

string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
// DataSet dataset = new DataSet();
SqlConnection connection = new SqlConnection(connString);
string sql = String.Format("update No_Exam set 答案={0} where 题号={1}",textBox4.Text ,textBox3 .Text);
connection.Open();
try
{

SqlCommand command = new SqlCommand(sql, connection);
int i = command.ExecuteNonQuery();
if (i > 0)
{
MessageBox.Show("答案修改成功!");
}

}
catch (System.Exception ex)
{
MessageBox.Show("题库中没有此题!");
}
finally
{

connection.Close();

label3.Visible =false ;
label4.Visible = false ;
textBox3.Visible = false;
textBox4.Visible = false;
button6.Visible = false;


}

}


}


public partial class Form考生进入 : Form
{

public Form考生进入()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{

int paochu;
string connString = "Data Source =.\\SQLEXPRESS;Initial Catalog=驾照考试系统数据库;Integrated Security=True";
string sql = String.Format("insert into Info(考生号,姓名,性别) values('{0}','{1}','{2}')",textBox1.Text,textBox2.Text,textBox3.Text);



SqlConnection connection = new SqlConnection(connString);

connection.Open();

try
{
if (textBox1.Text == null || textBox2 == null || textBox3.Te

xt == null)
{
SqlCommand comm22 = new SqlCommand(null, connection);
}
SqlCommand comm = new SqlCommand(sql, connection);
int a = comm.ExecuteNonQuery();

if (a > 0)
{
MessageBox.Show("注册成功!");
}

}
catch (System.Exception ex)
{
MessageBox.Show("请正确输入信息!");
}
finally
{
connection.Close();
}



}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}

private void textBox2_TextChanged(object sender, EventArgs e)
{

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void textBox3_TextChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
Hide();
Form5做题 frm5 = new Form5做题();
frm5.Show();


}

private void label3_Click(object sender, EventArgs e)
{

}
}
}


相关文档
相关文档 最新文档