[C#+JavaScript+SQL Server] Implementing Web-side Examination System Six: Background Management Module Design (with source code and resources)

If you need source code and resources, please like and follow the collection and leave a private message in the comment area~~~

1. Overview of background management module

In the online examination system, the background administrator module has the highest authority. After successfully logging in through the login module, the administrator can manage the information of test questions, teacher information, examinee information, test subject information and test results, making system maintenance more convenient and quick

 

 2. Manage the basic information of students

This web page is mainly used to query, modify and delete the basic information of students, and the main controls used in it are as follows

1: Query student information

Call the BindDG method to get all student information from the data table and display it on the GridView control

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["admin"] == null)									//禁止匿名登录
    {
        Response.Redirect("../Login.aspx");
    }
    if (!IsPostBack)
    {
        string strsql = "select * from tb_Student order by ID desc";	//检索所有学生信息
        BaseClass.BindDG(gvStuInfo, "ID", strsql, "stuinfo");		//绑定控件
    }
}

If you want to query student information, you first need to select the query criteria, then enter keywords in the text box, click the View button, and the Click event code of the View button is as follows

protected void btnserch_Click(object sender, EventArgs e)
{
    if (txtKey.Text == "")										//检查是否输入了关键字
    {
        string strsql = "select * from tb_Student order by ID desc";	//检索所有学生信息
        BaseClass.BindDG(gvStuInfo, "ID", strsql, "stuinfo");		//绑定控件
    }
    else
    {
        string stype = ddlType.SelectedItem.Text;					//获取查询范围
        string strsql = "";
        switch (stype)
        {
            case "学号":											//如果查询范围是“学号”
                strsql = "select * from tb_Student where StudentNum like '%" + txtKey.Text.Trim() 
+ "%'";
                BaseClass.BindDG(gvStuInfo, "ID", strsql, "stuinfo"); ;
                break;
            case "姓名":											//如果查询范围是“姓名”
                strsql = "select * from tb_Student where StudentName like '%" + 
txtKey.Text.Trim() + "%'";
                BaseClass.BindDG(gvStuInfo, "ID", strsql, "stuinfo");
                break;
        }
    }
}

2: Add student information

After entering the student information to be added on the page of adding student information, click the Add button, use the ExecuteNonQuery method of the Sqlcommand object to execute the SQL statement for adding students, so as to realize the function of adding student information to the data table, and add the Click event code of the button as follows

 

protected void btnSubmit_Click(object sender, EventArgs e)
{
    long iloing = 0;
    if (!long.TryParse(txtNum.Text, out iloing))
    {
        MessageBox.Show("考生编号请输入数字");
        return;
    }
    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.ExecuteScalar());				//获取返回值
        if (i > 0)												//如果返回值大于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();											//关闭连接
            MessageBox.Show("添加成功");								//提示添加成功
            btnConcel_Click(sender, e);
        }
    }
}

 

3: Modify student information

After setting the student information on the modify student information page, click the save button, first determine whether the student number, name and password have been set, if they have been set, call the OperateData method to realize the modification function of the student information, and save the Click event code of the button as follows

protected void btnSava_Click(object sender, EventArgs e)
{
    long iloing = 0;//临时变量
    if (!long.TryParse(txtStuNum.Text, out iloing))//判断学生编号是否为数字,如果不是,输出0
    {
        MessageBox.Show("考生编号请输入数字");
        return;
    }
    //判断学生姓名和密码文本框是否为空
    if (txtStuName.Text.Trim() == "" || txtStuPwd.Text.Trim() == "") 
    {
        MessageBox.Show("请将信息填写完整");
        return;
    }
    else
    {
        //定义更新学生信息的SQL语句
        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");//返回学生信息页面
    }
}

4: Delete student information

The RowDeleting event is fired after the delete button is clicked

protected void gvStuInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    int id = (int)gvStuInfo.DataKeys[e.RowIndex].Value;			//记录要删除的学生编号
    string str = "delete from tb_Student where ID=" + id;		//定义删除学生信息的SQL语句
    BaseClass.OperateData(str);								//执行删除学生信息操作
    string strsql = "select * from tb_Student order by ID desc";//获取学生信息表中的最新记录
    BaseClass.BindDG(gvStuInfo, "ID", strsql, "stuinfo");		//显示最新的学生信息
}

3. Management of examination subjects

This web page is mainly used to display, add and delete test subject information. When the test subject management page is loaded, first determine whether the administrator has logged in, and if so, execute the SQL query statement to retrieve all subject information and display it on the ListBox control

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["admin"] == null)						//禁止匿名登录
    {
        Response.Redirect("../Login.aspx");
    }
    if (!IsPostBack)
    {
        SqlConnection conn = BaseClass.DBCon();			//连接数据库
        conn.Open();									//打开连接
        SqlCommand cmd = new SqlCommand("select * from tb_Lesson", conn);
        SqlDataReader sdr = cmd.ExecuteReader();
        while (sdr.Read())
        {
            ListBox1.Items.Add(sdr["LessonName"].ToString());
        }
    }
}

After entering the new subject information, click the Add button to add the entered subject information to the data table

protected void btnAdd_Click(object sender, EventArgs e)
{
    if (txtKCName.Text == "")							//判断是否输入课程名称
    {
        MessageBox.Show("请输入课程名称");				//弹出提示信息
        return;
    }
    else
    {
        string systemTime = DateTime.Now.ToString();	//获取当前系统时间
        string strsql = "insert into tb_Lesson(LessonName,LessonDataTime) values('" + 
txtKCName.Text.Trim() + "','" + systemTime + "')";		//将信息插入数据库中的课程信息表中
        BaseClass.OperateData(strsql);					//执行SQL语句
        txtKCName.Text = "";
        Response.Write("<script>alert('添加成功');location='Subject.aspx'</script>");
    }
}

Select the subject to be deleted in the ListBox control, click the delete button to execute the SQL statement to delete the specified subject, the Click event code of the delete button is as follows

protected void btnDelete_Click(object sender, EventArgs e)
{
    if (ListBox1.SelectedValue.ToString() == "")		//判断是否有选中项
    {
        MessageBox.Show("请选择删除项目后删除");			//弹出提示
        return;
    }
    else
    {
        string strsql = "delete from tb_Lesson where LessonName='" + ListBox1.SelectedItem.Text 
+ "'";												//删除指定的信息
        BaseClass.OperateData(strsql);					//执行SQL语句
        Response.Write("<script>alert('删除成功');location='Subject.aspx'</script>");
    }
}

 

It's not easy to create and find it helpful, please like, follow and collect~~~

Guess you like

Origin blog.csdn.net/jiebaoshayebuhui/article/details/129104557