《在线考试系统代码.ppt》由会员分享,可在线阅读,更多相关《在线考试系统代码.ppt(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、L/O/G/O一个在线考试系统的代码设计 www.kasong-,www.youlvjing-,www.a-,www.a-,(1)登陆页面 protected void btnlogin_Click(object sender,EventArgs e)if(txtCode.Text.Trim()!=Sessionverify.ToString()Response.Write(alert(验证码错误);location=Login.aspx);else if(this.ddlstatus.SelectedValue=学生学生)if(BaseClass.CheckStudent(txtNum.Te
2、xt.Trim(),txtPwd.Text.Trim()SessionID=txtNum.Text.Trim();Response.Redirect(student/studentexam.aspx);else Response.Write(alert(您不是学生或者用您不是学生或者用户名和密名和密码错误 );location=Login.aspx);if(this.ddlstatus.SelectedValue=教教师)if(BaseClass.CheckTeacher(txtNum.Text.Trim(),txtPwd.Text.Trim()Sessionteacher=txtNum.Te
3、xt;Response.Redirect(teacher/TeacherManage.aspx);else Response.Write(alert(您不是教您不是教师或者用或者用户名和密名和密码错误 );location=Login.aspx);if(this.ddlstatus.SelectedValue=管理管理员)if(BaseClass.CheckAdmin(txtNum.Text.Trim(),txtPwd.Text.Trim()Sessionadmin=txtNum.Text;Response.Redirect(admin/AdminManage.aspx);else Respo
4、nse.Write(alert(您不是管理您不是管理员或者用或者用户名和密名和密码错误);location=Login.aspx);protected void btnconcel_Click(object sender,EventArgs e)RegisterStartupScript(提示提示,window.close(););(2)添加信息学生代码 protected void Page_Load(object sender,EventArgs e)if(Sessionadmin=null)Response.Redirect(./Login.aspx);protected void bt
5、nSubmit_Click(object sender,EventArgs e)if(txtName.Text=|txtNum.Text=|txtPwd.Text=)MessageBox.Show(请将信息填写完整将信息填写完整);return;else SqlConnection conn=BaseClass.DBCon();conn.Open();SqlCommand cmd=new SqlCommand(select count(*)from tb_Student where StudentNum=+txtNum.Text+,conn);int i=Convert.ToInt32(cmd
6、.ExecuteScalar();if(i 0)MessageBox.Show(此学号已此学号已经存在存在);return;else cmd=new SqlCommand(insert into tb_Student(StudentNum,StudentName,StudentSex,StudentPwd)values(+txtNum.Text.Trim()+,+txtName.Text.Trim()+,+rblSex.SelectedValue.ToString()+,+txtPwd.Text.Trim()+),conn);cmd.ExecuteNonQuery();conn.Close()
7、;MessageBox.Show(添加成功添加成功);btnConcel_Click(sender,e);protected void btnConcel_Click(object sender,EventArgs e)txtName.Text=;txtNum.Text=;txtPwd.Text=;public partial class admin_ChangeStudentInfo:System.Web.UI.Page private static int id;protected void Page_Load(object sender,EventArgs e)if(Sessionadm
8、in=null)Response.Redirect(./Login.aspx);if(!IsPostBack)id=Convert.ToInt32(Request.QueryStringstuid);SqlConnection conn=BaseClass.DBCon();conn.Open();SqlCommand cmd=new SqlCommand(select*from tb_Student where ID=+id,conn);SqlDataReader sdr=cmd.ExecuteReader();sdr.Read();txtStuName.Text=sdrStudentName
9、.ToString();txtStuNum.Text=sdrStudentNum.ToString();txtStuPwd.Text=sdrStudentPwd.ToString();rblSex.SelectedValue=sdrStudentSex.ToString();sdr.Close();conn.Close();protected void btnSava_Click(object sender,EventArgs e)if(txtStuName.Text.Trim()=|txtStuPwd.Text.Trim()=)MessageBox.Show(请将信息填写完整将信息填写完整)
10、;return;else string str=update tb_Student set StudentName=+txtStuName.Text.Trim()+,StudentPwd=+txtStuPwd.Text.Trim()+,StudentSex=+rblSex.SelectedItem.Text+where ID=+id;BaseClass.OperateData(str);Response.Redirect(StudentInfo.aspx);protected void btnConcel_Click(object sender,EventArgs e)Response.Red
11、irect(StudentInfo.aspx);(3)修改学生信息)修改学生信息(4)添加试题)添加试题添加试题信息代码如下:添加试题信息代码如下:protected void Page_Load(object sender,EventArgs e)if(Sessionadmin=null)Response.Redirect(./Login.aspx);if(!IsPostBack)SqlConnection conn=BaseClass.DBCon();conn.Open();SqlCommand cmd=new SqlCommand(select*from tb_Lesson,conn);
12、SqlDataReader sdr=cmd.ExecuteReader();this.ddlkm.DataSource=sdr;this.ddlkm.DataTextField=LessonName;this.ddlkm.DataValueField=ID;this.ddlkm.DataBind();this.ddlkm.SelectedIndex=0;conn.Close();protected void btnconfirm_Click(object sender,EventArgs e)if(txtsubject.Text=|txtAnsA.Text=|txtAnsB.Text=|txt
13、AnsC.Text=|txtAnsD.Text=)MessageBox.Show(请将信息填写完整请将信息填写完整);return;else string isfb=;if(cbFB.Checked=true)isfb=1;else isfb=0;string str=insert into tb_test(testContent,testAns1,testAns2,testAns3,testAns4,rightAns,pub,testCourse)values(+txtsubject.Text.Trim()+,+txtAnsA.Text.Trim()+,+txtAnsB.Text.Trim(
14、)+,+txtAnsC.Text.Trim()+,+txtAnsD.Text.Trim()+,+rblRightAns.SelectedValue.ToString()+,+isfb+,+ddlkm.SelectedItem.Text+);BaseClass.OperateData(str);btnconcel_Click(sender,e);protected void btnconcel_Click(object sender,EventArgs e)txtsubject.Text=;txtAnsD.Text=;txtAnsC.Text=;txtAnsB.Text=;txtAnsA.Text=;(4)数据库连接代码)数据库连接代码add name=connstring connectionString=Data Source=.;initial catalog=Exam;User ID=sa;Password=123456L/O/G/Owww.kasong-,www.youlvjing-,www.a-,www.a-,Thank You!