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

📄 choosecourse.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;
using System.Data.SqlClient;

public partial class studentdetail : System.Web.UI.Page
{

    SqlConnection connections;
    string strsql;    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user_id"] == null)
        {
            Response.Redirect("default.aspx");
        }
        this.Title = "选课操作";
        lbtnChoose.Enabled = false;
        string connsql = System.Configuration.ConfigurationManager.AppSettings["connstring"];
        connections = new SqlConnection(connsql);        
        string strsql;
        strsql = "select tabcour.Crname,tabcour.Crid,tabtea.Tname,tabcour.Crcre,tabcour.Crper from tabcour,tabtea,tabtea_cour where tabtea_cour.Crid=tabcour.Crid and tabtea_cour.Tid=tabtea.Tid";
        SqlDataAdapter sqlda = new SqlDataAdapter(strsql, connections);
        DataSet dstr = new DataSet();
        sqlda.Fill(dstr);
        DataGrid1.DataSource = dstr;
        DataGrid1.DataBind();
        
    }

    public void DataGrid_Page(object sender, DataGridPageChangedEventArgs e)
    {
        DataGrid1.CurrentPageIndex = e.NewPageIndex;
        string connsql = System.Configuration.ConfigurationManager.AppSettings["connstring"];
        connections = new SqlConnection(connsql);
        string strsql;
        strsql = "select tabcour.Crname,tabcour.Crid,tabtea.Tname,tabcour.Crcre,tabcour.Crper from tabcour,tabtea,tabtea_cour where tabtea_cour.Crid=tabcour.Crid and tabtea_cour.Tid=tabtea.Tid";
        SqlDataAdapter sqlda = new SqlDataAdapter(strsql, connections);
        DataSet dstr = new DataSet();
        sqlda.Fill(dstr);
        DataGrid1.DataSource = dstr;
        DataGrid1.DataBind();
    }



    protected void lbtnQuit_Click(object sender, EventArgs e)
    {
        Session.Clear();
        Response.Redirect("Default.aspx");
    }

    protected void lbtnRepwd_Click(object sender, EventArgs e)
    {
        Response.Redirect("repassword.aspx");
    }

    protected void lbtnCourse_info_Click(object sender, EventArgs e)
    {
        Response.Redirect("stu_course.aspx");
    }
    
    protected void lbtnStuInfo_Click(object sender, EventArgs e)
    {
        Response.Redirect("stu_info.aspx");
    }

    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (txtCourseNo.Text == "" || txtYear.Text == "")
        { 
            lblMsg.Text = "<b>请输入完整的信息!</b>";
            return;
        }
        connections.Open();
        strsql = "select * from tabstu_cour where crid='" + txtCourseNo.Text + " 'and sid=@Sid";
        SqlCommand commnd = new SqlCommand(strsql, connections);
        commnd.Parameters.Add(new SqlParameter("@Sid", SqlDbType.VarChar, 50));
        commnd.Parameters["@Sid"].Value = Session["User_id"].ToString();
        SqlDataReader sdreader = commnd.ExecuteReader();
        if (sdreader.Read())
        {
            lblMsg.Text = "<b>该课程已被选择!</b>";
            return;
        }       
        connections.Close();
        string myuserid, mycrid, myyear;
        myuserid = Session["user_id"].ToString();
        mycrid = txtCourseNo.Text;
        myyear = txtYear.Text;
        strsql = "insert into tabstu_cour(Sid,Crid,Cryear) values('" + myuserid +"','" +  mycrid  + "','" + myyear + "')";        
        SqlCommand commnd1 = new SqlCommand(strsql, connections);
        
        connections.Open();
        try
        {
            commnd1.ExecuteNonQuery();
            lblMsg.Text = "<b>选课成功!</b>";

        }
        catch (SqlException ex)
        {
            lblMsg.Text = "<b>选课失败!</b>";
            Response.Write(ex.Message);


        }

        connections.Close();
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtCourseNo.Text = "";
        txtCourseNo.Focus();
        txtYear.Text = "";
    }
    protected void lbtnChoose_Click(object sender, EventArgs e)
    {

    }
    protected void lbtnGrade_Click(object sender, EventArgs e)
    {
        Response.Redirect("stu_grade.aspx");
    }
}

⌨️ 快捷键说明

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