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

📄 s_class_infor.aspx.vb

📁 教务实验室选课系统
💻 VB
📖 第 1 页 / 共 2 页
字号:
Public Class s_class_infor
    Inherits System.Web.UI.Page

#Region " Web 窗体设计器生成的代码 "

    '该调用是 Web 窗体设计器所必需的。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents Label2 As System.Web.UI.WebControls.Label
    Protected WithEvents HyperLink10 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink11 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink9 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink13 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink14 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink15 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink8 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink1 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents HyperLink5 As System.Web.UI.WebControls.HyperLink
    Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
    Protected WithEvents Image1 As System.Web.UI.WebControls.Image
    Protected WithEvents spWelMessage As System.Web.UI.HtmlControls.HtmlGenericControl
    Protected WithEvents Button3 As System.Web.UI.WebControls.Button
    Protected WithEvents RadioButton1 As System.Web.UI.WebControls.RadioButton
    Protected WithEvents RadioButton2 As System.Web.UI.WebControls.RadioButton
    Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents DropDownList3 As System.Web.UI.WebControls.DropDownList
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList

    '注意: 以下占位符声明是 Web 窗体设计器所必需的。
    '不要删除或移动它。
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
        '不要使用代码编辑器修改它。
        InitializeComponent()
    End Sub

#End Region
    Dim dsn As String
    Dim conn As New SqlClient.SqlConnection
    Dim cmd As New SqlClient.SqlCommand
    Dim ds1 As DataSet = New DataSet
    Dim mydap1 As New SqlClient.SqlDataAdapter
    Dim student_id As String '取出学生登录s_id
    Dim class_student_num As Integer '计算班级中学生人数
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '在此处放置初始化页的用户代码
        '显示欢迎信息
        student_id = Request.Cookies("userInf").Values("userID")
        If DateTime.Now.Hour >= 6 And DateTime.Now.Hour < 12 Then
            spWelMessage.InnerHtml = "早上好," & Request.Cookies("userInf").Values("userID") & Request.Cookies("userInf").Values("userIdent")
        ElseIf DateTime.Now.Hour >= 12 And DateTime.Now.Hour < 18 Then
            spWelMessage.InnerHtml = "下午好," & Request.Cookies("userInf").Values("userID") & Request.Cookies("userInf").Values("userIdent")
        Else
            spWelMessage.InnerHtml = "晚上好," & Request.Cookies("userInf").Values("userID") & Request.Cookies("userInf").Values("userIdent")
        End If
        '连接数据库()
        dsn = ConfigurationSettings.AppSettings("DSN_student")
        conn.ConnectionString = dsn
        cmd.Connection = conn
        mydap1.SelectCommand = cmd
        '初始化label2控件的text属性
        Label2.Text = ""
        If RadioButton1.Checked Then
            DropDownList2.Enabled = True
            DropDownList3.Enabled = True
            Button2.Enabled = True
            Button3.Enabled = False
        ElseIf RadioButton2.Checked Then
            DropDownList2.Enabled = False
            DropDownList3.Enabled = False
            Button2.Enabled = False
            Button3.Enabled = True
        End If
    End Sub

    Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Redirect("../login.aspx")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        datagrid1_bind() ' 此函数完成的功能:将数据在datagrid1中显示出来
        '计算该班的人数
        cmd.CommandText = "select * from class_student where class_id='" + DropDownList1.SelectedItem.Value + "'"
        Try
            conn.Open()
            mydap1.Fill(ds1, "class_student_count")
            Label1.Text = ds1.Tables("class_student_count").Rows.Count
            class_student_num = ds1.Tables("class_student_count").Rows.Count
        Catch
            Label2.Text = "读取班级学生表失败,可能是服务器出现错误,请稍后再试!非常抱歉影响了您的工作!"
        Finally
            conn.Close()
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        '加入该班,
        '步骤为:首先判断该学生是否已经选择了班级,如果是的话,就提示她不能在选择或者先退出原来的班级在进行选择,
        '如果还没有选择班级,则可以选择组号和座号,如果选择的组号和座号已经存在,则无法加入该班;
        '如果选择的组号和座号没有存在,则可以加入该班
        Dim bool1 As Boolean = False '记录学生是否已经选择过班级
        Dim bool2 As Boolean = False '记录学生选择的组号和座号是否已经存在
        Dim bool3 As Boolean = False '记录是否已经将学生选班信息添加到班级学生表中

        '下面代码判断该学生是否已经加入某个班级
        cmd.CommandText = "select * from student_login where s_id='" + student_id + "'and sl_ifclass='1'"
        Try
            conn.Open()
            Dim reader As IDataReader
            reader = cmd.ExecuteReader()
            If reader.Read Then '如果此学生已经加入某个班级
                Label2.Text = "您已经加入了某个班级,无法再次添加!"
                bool1 = False
            Else
                '如果此学生还没有加入任何班级,判断该班级人数是否已经超过上限64人
                If class_student_num < 64 Then
                    bool1 = True
                Else
                    bool1 = False
                    Label2.Text = "该班级人数已经超过64人,您无法再次加入!"
                End If
            End If
        Catch
            Label2.Text = "读取学生登录表失败,可能是服务器出现错误,请稍后再试!非常抱歉影响了您的工作!"
        Finally
            conn.Close()
        End Try

        '如果该学生没有选择班级,则下面代码判断该学生选择的组号和座号是否已经存在
        If bool1 Then
            cmd.CommandText = "select * from class_student where class_id='" + DropDownList1.SelectedItem.Value + "' and group_id='" + DropDownList2.SelectedItem.Value + "' and seat_id='" + DropDownList3.SelectedItem.Value + "'"
            Try
                conn.Open()
                Dim reader2 As IDataReader
                reader2 = cmd.ExecuteReader()
                If reader2.Read Then '如果此学生选择的组号座号已经存在
                    Label2.Text = "您选择的组号和座号已经存在,无法再次添加!"
                    bool2 = False
                Else

⌨️ 快捷键说明

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