⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 teacher.aspx.cs

📁 这是一个课程设计
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Teacher : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //读取信息
        if (!IsPostBack)
        {

            BindData();
        
        }
    
    }

    //函数BindData用于读取页面基本信息
    private void BindData()
    {

        //将Session实体化
        int userID = Int32.Parse(Session["uid"].ToString());

        //根据用户编号实例化用户信息
        string strSql = "SELECT [userID],[userLoginID],[userPwd],[userName],[userStauts],[scID] FROM [userInfo] WHERE [userID] ='" + userID + "'";
        UserInfo userinfo = new UserInfo();
        userinfo = DBHelper.sqllogin(strSql);

        //显示用户姓名
        txtName.Text = userinfo.UserName;

        //根据用户姓名读取该用户的选课安排,并与GridView绑定
        strSql = "SELECT [scID],[scName],[scContent],[scNum],[scMax] FROM [scInfo] Where [scTeacher] ='" + userinfo.UserName + "'";
        tcGV.DataSource = DBHelper.sqlLoad(strSql);
        tcGV.DataBind();

    }

    //删除单条用户信息
    protected void tcGV_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        //将选择的课程编号实体化
        string scID = tcGV.Rows[e.RowIndex].Cells[0].Text;

        //删除所选择的课程
        string strSql = "DELETE FROM [scInfo] WHERE [scID] ='" + scID + "'";
        int i = DBHelper.sqlinit(strSql);

        //将选此课的学生的选课信息修改为无
        strSql = "UPDATE [userInfo] SET [scID]=0 WHERE [scID] ='" + scID + "'";
        i = DBHelper.sqlinit(strSql);

        if (i > 0)
        {

            txtMsg.Text = "删除成功!";
        
        }

        BindData();
    
    }

    //增加新课程安排
    protected void Button1_Click(object sender, EventArgs e)
    {

        //跳转至“增加新课程安排”页面
        Response.Redirect("Course.aspx");

    }

    //退出
    protected void exitLB_Click(object sender, EventArgs e)
    {

        //清除Session储存内容,并跳转至登录界面
        Session.Clear();
        Response.Redirect("Login.aspx");

    }

    protected void tcGV_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        //读取指令名称
        if (e.CommandName == "edit")
        {

            //将所选取的行号实体化
            int index = int.Parse(e.CommandArgument.ToString());

            //利用Session传递用户编号至编辑页
            Session["scID"] = tcGV.Rows[index].Cells[0].Text;
            Response.Redirect("Course.aspx");

        }

    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -