在线考试系统实训报告
一、需求
分析
定性数据统计分析pdf销售业绩分析模板建筑结构震害分析销售进度分析表京东商城竞争战略分析
1管理员模块
维护本系统用户信息数据库,主要功能:
(1)用户登录
(2) 资格审核
(3)用户信息添加 /修改 / 查询
(4)安全维护
(5)登录验证
(6)考试管理
(7)权限维护等
2教师管理模块
维护
试题
中考模拟试题doc幼小衔接 数学试题 下载云南高中历年会考数学试题下载N4真题下载党史题库下载
数据库,主要功能:
(1)用户登录 / 资格审核
(2)试题添加 / 删除 / 修改 /查询
(3)安考试需求生成每次考试所需试题
3学生管理模块
按年度统计用户考试成绩主要功能:
(1)用户登录
(2)查询功能(查询考试成绩,对应试题
答案
八年级地理上册填图题岩土工程勘察试题省略号的作用及举例应急救援安全知识车间5s试题及答案
等)
(3)参与考试
性能需求
因为考试时面向特定的某些对象的,所以考试者进入系统应该进行身份认证,考试者进入考试系统后,应该能根据自己的需要进行个人信息的修改、考试系统的进入以及分数的查看。
教师可以管理试题库,对里面试题进行增、删、查、改等,对学生进行管理,查看考生的答题情况等。
管理员可以对整个的系统进行维护,可以对相关用户进行增、删、改、等操作。
二、数据库(表)
设计
领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计
总体设计
根据以上需求,设计E-R图,从而设计相关数据库和数据表
Users
Papers表
Questions表
整体E-R图
用户相关表格
Users表
试题相关表格
Papers表
考试卷表(test为例)
试卷类型表格
成绩表
三、页面设计
1、登陆页面default.aspx
相关代码
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.mess.Text = "";
}
protected void loginbut_Click(object sender, EventArgs e)
{
if(this.txtname.Text!="" && this.txtpwd.Text!="")
{
SqlConnection cn = new SqlConnection("Server=localhost;DataBase=tms;Integrated Security=SSPI");
cn.Open();
SqlCommand cmd = cn.CreateCommand();
string aa = this.txtpwd.Text.ToString();
cmd.CommandText = "select count(*) from users where username='"+this.txtname.Text.ToString()+"' and userpwd='"+aa+"'";
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count > 0)
{
this.mess.Text = "OK";
}
else
{
this.mess.Text = "wrong";
}
cmd.Dispose();
cn.Close();
}
else
{
this.mess.Text = "请?输º?入¨?正y确¨¡¤的Ì?用®?户¡ì名?及¡ã密¨¹码?!ê?";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.txtname.Text != "" && this.txtpwd.Text != "")
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = new SqlCommand("userlogin",cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter username = new SqlParameter("@username",SqlDbType.NVarChar,16);
username.Value = this.txtname.Text.ToString();
cmd.Parameters.Add(username);
SqlParameter userpwd = new SqlParameter("@userpwd", SqlDbType.NVarChar, 12);
userpwd.Value = this.txtpwd.Text.ToString();
cmd.Parameters.Add(userpwd);
SqlDataReader dr= cmd.ExecuteReader();
if (dr.Read())
{
Session["username"] = dr["username"].ToString();
Session["userid"]= dr["userid"];
string type = dr["usertype"].ToString();
if (type == "system")
Response.Redirect("admin.aspx");
else if (type == "student")
Response.Redirect("student.aspx");
else if (type == "teacher")
Response.Redirect("teacher.aspx");
else
this.mess.Text = "没?权¨¡§限T进?入¨?系¦Ì统ª3";
}
cmd.Dispose();
cn.Close();
this.mess.Text = "请?输º?入¨?正y确¨¡¤的Ì?用®?户¡ì名?及¡ã密¨¹码?!ê?";
this.txtname.Text = "";
this.txtpwd.Text = "";
}
else
{
this.mess.Text = "请?输º?入¨?正y确¨¡¤的Ì?用®?户¡ì名?及¡ã密¨¹码?!ê?";
this.txtname.Text = "";
this.txtpwd.Text = "";
}
}
}
2、管理员登陆后的管理界面
相关代码
using System.Data.SqlClient;
public partial class admin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
bind_user();
}
public void bind_user()
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "getuser";
cmd.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds, "users");
this.GridView1.DataSource = ds.Tables["users"].DefaultView;
this.GridView1.DataBind();
cmd.Dispose();
da.Dispose();
ds.Dispose();
cn.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
bind_user();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = this.GridView1.DataKeys[e.RowIndex][0].ToString();
if (Session["userid"].ToString() == id)
this.Label1.Text = "该?用®?户¡ì为a当Ì¡À前¡ã登Ì?录?用®?户¡ì,ê?无T法¤¡§删¦?除y!ê?";
else
{
deleteuser(id);
bind_user();
this.Label1.Text = "删¦?除y成¨¦功|!ê?";
}
}
public void deleteuser(string id)
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd1 = new SqlCommand("findpapername", cn);
cmd1.CommandType = CommandType.StoredProcedure;
SqlParameter userid1 = new SqlParameter("@userid", SqlDbType.Int);
userid1.Value = id;
cmd1.Parameters.Add(userid1);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd1);
da.Fill(ds);
DataTable dt = ds.Tables[0];
foreach (DataRow myrow in dt.Rows)
{
string papername = myrow[0].ToString();
SqlCommand cmd2 = new SqlCommand("drop table "+papername,cn);
cmd2.ExecuteNonQuery();
}
SqlCommand cmd = new SqlCommand("deleteuser",cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter userid = new SqlParameter("@userid", SqlDbType.Int);
userid.Value = id;
cmd.Parameters.Add(userid);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception e)
{
Response.Write(e.Message);
}
cmd.Dispose();
cmd1.Dispose();
da.Dispose();
ds.Dispose();
cn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text != "" && this.TextBox2.Text != "")
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = new SqlCommand("userexist", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter username= new SqlParameter("@username", SqlDbType.NVarChar,16);
username.Value = this.TextBox1.Text;
cmd.Parameters.Add(username);
int count = Convert.ToInt32(cmd.ExecuteScalar());
if (count == 1)
this.Label1.Text = "该?用®?户¡ì已°?经-存ä?在¨²";
else
{
cmd.CommandText = "adduser";
SqlParameter userpwd = new SqlParameter("@userpwd", SqlDbType.NVarChar, 12);
userpwd.Value = this.TextBox2.Text;
cmd.Parameters.Add(userpwd);
SqlParameter usertype = new SqlParameter("@usertype", SqlDbType.NVarChar, 50);
usertype.Value = this.DropDownList1.SelectedValue.ToString();
cmd.Parameters.Add(usertype);
cmd.ExecuteNonQuery();
this.Label1.Text = "用®?户¡ì添¬¨ª加¨®成¨¦功|!ê?";
}
this.TextBox1.Text="";
this.TextBox2.Text="";
this.DropDownList1.SelectedValue="system";
this.GridView1.PageIndex=GridView1.PageCount;
bind_user();
cmd.Dispose();
cn.Close();
}
else
this.Label1.Text = "用®?户¡ì名?和¨ª密¨¹码?不?能¨¹为a空?!ê?";
}
protected void Button2_Click(object sender, EventArgs e)
{
Session["userid"] = "";
Session["username"] = "";
Response.Redirect("default.aspx");
}
}
3、教师登陆后的教师页面
相关代码
using System.Data.SqlClient;
public partial class teacher : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session.Count == 0)
Response.Redirect("default.aspx");
else
{
if (!Page.IsPostBack)
{
this.GridView1.Visible = true;
this.GridView2.Visible = false;
bindpapername();
bindgrid();
}
}
}
public void bindpapername()
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = new SqlCommand("papername",cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "papers");
this.DropDownList1.DataSource = ds.Tables["papers"];
this.DropDownList1.DataTextField = "papername";
this.DropDownList1.DataBind();
da.Dispose();
ds.Dispose();
cmd.Dispose();
cn.Close();
}
public void bindgrid()
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "tscore";
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "scores");
this.GridView1.DataSource = ds.Tables["scores"].DefaultView;
this.GridView1.DataBind();
da.Dispose();
ds.Dispose();
cmd.Dispose();
cn.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
bindgrid();
}
protected void Button1_Click(object sender, EventArgs e)
{
this.GridView1.Visible = false;
this.GridView2.Visible = true;
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "tscore1";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter papername = new SqlParameter("@papername", SqlDbType.NVarChar, 50);
papername.Value = this.DropDownList1.SelectedValue.ToString();
cmd.Parameters.Add(papername);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
this.GridView2.DataSource = dr;
this.GridView2.DataBind();
dr.Dispose();
cn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("addpaper.aspx");
}
protected void Button3_Click(object sender, EventArgs e)
{
Session["userid"] = "";
Session["username"] = "";
Response.Redirect("default.aspx");
}
}
当进入页面后点击出题按钮完成页面跳转,跳转至下addpaper出题页面
4.出题页面
相关代码
using System.Data.SqlClient;
using System.Data.Sql;
public partial class addpaper : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
Session["papername"] = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text != "" && this.TextBox2.Text != "" && this.TextBox3.Text != "")
{
if (checkpaper(this.TextBox1.Text))
this.Label1.Text = "试º?卷¨ª存ä?在¨²,ê?可¨¦直¡À接¨®出?题¬a!";
else
addpapers(this.TextBox1.Text, this.TextBox2.Text, this.TextBox3.Text);
this.TextBox1.Text="";
this.TextBox2.Text="";
this.TextBox3.Text="";
Session["papername"] = this.TextBox1.Text;
}
else
{
this.Label1.Text = "请?输º?入¨?正y确¨¡¤数ºy据Y";
}
}
public bool checkpaper(string pname)
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "paperexist";
SqlParameter papername = new SqlParameter("@papername", SqlDbType.NVarChar, 50);
papername.Value = pname;
cmd.Parameters.Add(papername);
if (Convert.ToInt32(cmd.ExecuteScalar()) == 1)
return true;
else
{
return false;
//cmd.Dispose();
cmd.Dispose();
cn.Close();
}
}
public void addpapers(string pname, string ptime, string pscore)
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "addpaper";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter papername = new SqlParameter("@papername", SqlDbType.NVarChar, 50);
papername.Value = pname;
cmd.Parameters.Add(papername);
SqlParameter paperscore = new SqlParameter("@paperscore", SqlDbType.Int);
paperscore.Value = pscore;
cmd.Parameters.Add(paperscore);
SqlParameter teacher = new SqlParameter("@teacher", SqlDbType.NVarChar, 16);
teacher.Value = Session["username"];
cmd.Parameters.Add(teacher);
SqlParameter totaltime = new SqlParameter("@totaltime", SqlDbType.NVarChar, 50);
totaltime.Value = ptime;
cmd.Parameters.Add(totaltime);
cmd.ExecuteNonQuery();
createtable(pname);
cmd.Dispose();
cn.Close();
}
public void createtable(string pname)
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
string createsql = "create table " + pname;
createsql += "(questionid int primary key,questiontype nvarchar(50),";
createsql += "question nvarchar(4000),answer nvarchar(4000),";
createsql += "score int,autoflag int default 0)";
SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = createsql;
cmd.ExecuteNonQuery();
cmd.Dispose();
cn.Close();
this.Label1.Text = "该?试º?卷¨ª已°?经-创ä¡ä建¡§完ª¨º成¨¦,ê?可¨¦以°?出?题¬a了¢?~?";
}
protected void Button2_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text != "" && checkpaper(this.TextBox1.Text))
{
Session["papername"] = this.TextBox1.Text;
Response.Redirect("addtest.aspx");
}
else
this.Label1.Text = "请?输º?入¨?正y确¨¡¤的Ì?试º?卷¨ª名?称?";
}
}
当输入科目后跳转至出题界面
出题页面addtest
相关代码
using System.Data.SqlClient;
public partial class addtest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = Session["username"] + ",您¨²正y在¨²为a" + Session["papername"] + "试º?卷¨ª添¬¨ª加¨®试º?题¬a";
}
protected void Button1_Click(object sender, EventArgs e)
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = new SqlCommand("select max(questionid) from " + Session["papername"], cn);
string id = cmd.ExecuteScalar().ToString ();
if (id == "")
id = "1";
else
id = Convert.ToString(int.Parse(id) + 1);
string sqltext = "insert into " + Session["papername"]+"(questionid,questiontype,question,answer,score)";
sqltext += "values (" +id+ ","+this.DropDownList1.SelectedValue.ToString()+",'"+this.TextBox2.Text.ToString();
sqltext +="','"+this.TextBox3.Text.ToString()+"',"+Convert.ToInt32(this.TextBox1.Text)+")";
cmd.CommandText =sqltext ;
cmd.ExecuteNonQuery();
cmd.Dispose ();
cn.Close();
this.Label2.Text ="此ä?题¬a添¬¨ª加¨®成¨¦功|!";
}
protected void Button2_Click(object sender, EventArgs e)
{
this.TextBox1.Text="";
this.TextBox2.Text="";
this.TextBox3.Text="";
this.Label2.Text="";
this.DropDownList1.SelectedIndex=0;
}
protected void Button3_Click(object sender, EventArgs e)
{
Session["papername"]="";
Response.Redirect ("teacher.aspx");
}
}
完成出题后单击保存,然后通过完成按钮跳转到教师页面
5、学生登录界面
相关代码
using System.Data.SqlClient;
public partial class student : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Label1.Text = Session["username"].ToString ();
bind_papers();
bind_scores();
}
public void bind_papers()
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = new SqlCommand("papersall", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.GridView1.DataBind();
cmd.Dispose();
ds.Dispose();
cn.Close();
}
public void bind_scores()
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
SqlCommand cmd = new SqlCommand("stuscore", cn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter username = new SqlParameter("@username", SqlDbType.NVarChar, 16);
username.Value = Session["username"];
cmd.Parameters.Add(username);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
this.GridView2.DataSource = dr;
this.GridView2.DataBind();
cmd.Dispose();
cn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["username"] = "";
Session["userid"] = "";
Response.Redirect("default.aspx");
}
}
6、当确认信息完成后进入考试界面
相关代码
using System.Data.SqlClient;
public partial class text : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Panel1.Visible = true;
this.Panel2.Visible = false;
}
public DateTime starttime;
protected void Button1_Click(object sender, EventArgs e)
{
this.Panel1.Visible = false;
this.Panel2.Visible = true;
starttime = DateTime.Now;
this.Label2.Text = starttime.ToString();
bind_question();
}
public void bind_question()
{
string setting = Convert.ToString(ConfigurationManager.ConnectionStrings["sql"]);
SqlConnection cn = new SqlConnection(setting);
cn.Open();
string papername = getpaperna