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

📄 s_choice_frm.frm

📁 高校学生选课系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form s_choice_frm 
   BackColor       =   &H00404040&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "选课系统"
   ClientHeight    =   5295
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   7005
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   Picture         =   "s_choice_frm.frx":0000
   ScaleHeight     =   5295
   ScaleWidth      =   7005
   Begin VB.ListBox List1 
      Height          =   2400
      Left            =   1680
      TabIndex        =   19
      Top             =   2520
      Width           =   1455
   End
   Begin VB.ComboBox Combo2 
      Height          =   900
      Left            =   4680
      Style           =   1  'Simple Combo
      TabIndex        =   18
      Top             =   2520
      Width           =   1935
   End
   Begin VB.ListBox List2 
      Height          =   1140
      Left            =   4680
      TabIndex        =   17
      Top             =   3840
      Width           =   1935
   End
   Begin VB.CommandButton cmdAddCourse 
      Caption         =   "<<选修"
      Height          =   375
      Left            =   3360
      TabIndex        =   16
      Top             =   2880
      Width           =   1095
   End
   Begin VB.CommandButton cmdDelCourse 
      Caption         =   "退选>>"
      Height          =   375
      Left            =   3360
      TabIndex        =   15
      Top             =   3960
      Width           =   1095
   End
   Begin VB.ListBox List3 
      Height          =   2400
      Left            =   240
      TabIndex        =   14
      Top             =   2520
      Width           =   1455
   End
   Begin VB.ComboBox Combo1 
      Height          =   300
      Left            =   1200
      TabIndex        =   0
      Top             =   240
      Width           =   1335
   End
   Begin VB.Line Line1 
      X1              =   240
      X2              =   6600
      Y1              =   2040
      Y2              =   2040
   End
   Begin VB.Label Label2 
      BackStyle       =   0  'Transparent
      Caption         =   "该门课程有以下老师任教"
      Height          =   255
      Left            =   4680
      TabIndex        =   22
      Top             =   3600
      Width           =   2055
   End
   Begin VB.Label label 
      BackStyle       =   0  'Transparent
      Caption         =   "已经选修的教师编号与课程名称:"
      Height          =   255
      Left            =   240
      TabIndex        =   21
      Top             =   2160
      Width           =   2655
   End
   Begin VB.Label Label4 
      BackStyle       =   0  'Transparent
      Caption         =   "请选择你要选修的课程"
      Height          =   375
      Left            =   4680
      TabIndex        =   20
      Top             =   2160
      Width           =   1815
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "学生学号:"
      Height          =   255
      Left            =   240
      TabIndex        =   13
      Top             =   240
      Width           =   975
   End
   Begin VB.Label Label3 
      BackStyle       =   0  'Transparent
      Caption         =   "学生姓名:"
      Height          =   255
      Left            =   3120
      TabIndex        =   12
      Top             =   240
      Width           =   975
   End
   Begin VB.Label lblstu 
      BackColor       =   &H80000009&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "lblstu"
      Height          =   255
      Index           =   0
      Left            =   4200
      TabIndex        =   11
      Top             =   240
      Width           =   1095
   End
   Begin VB.Label lblstu 
      BackColor       =   &H80000009&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "lblstu"
      Height          =   255
      Index           =   1
      Left            =   1200
      TabIndex        =   10
      Top             =   600
      Width           =   855
   End
   Begin VB.Label lblstu 
      BackColor       =   &H80000009&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "lblstu"
      Height          =   255
      Index           =   2
      Left            =   4200
      TabIndex        =   9
      Top             =   600
      Width           =   1335
   End
   Begin VB.Label lblstu 
      BackColor       =   &H80000009&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "lblstu"
      Height          =   255
      Index           =   3
      Left            =   1200
      TabIndex        =   8
      Top             =   960
      Width           =   1575
   End
   Begin VB.Label lblstu 
      BackColor       =   &H80000009&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "lblstu"
      Height          =   255
      Index           =   4
      Left            =   4200
      TabIndex        =   7
      Top             =   960
      Width           =   2055
   End
   Begin VB.Label Label8 
      BackStyle       =   0  'Transparent
      Caption         =   "电话:"
      Height          =   255
      Left            =   240
      TabIndex        =   6
      Top             =   960
      Width           =   615
   End
   Begin VB.Label Label5 
      BackStyle       =   0  'Transparent
      Caption         =   "家庭地址:"
      Height          =   255
      Left            =   3120
      TabIndex        =   5
      Top             =   960
      Width           =   975
   End
   Begin VB.Label Label7 
      BackStyle       =   0  'Transparent
      Caption         =   "出生年月:"
      Height          =   255
      Left            =   3120
      TabIndex        =   4
      Top             =   600
      Width           =   1005
   End
   Begin VB.Label Label9 
      BackStyle       =   0  'Transparent
      Caption         =   "性别:"
      Height          =   255
      Left            =   240
      TabIndex        =   3
      Top             =   600
      Width           =   675
   End
   Begin VB.Label lblstu 
      BackColor       =   &H80000009&
      BorderStyle     =   1  'Fixed Single
      Caption         =   "lblstu"
      Height          =   615
      Index           =   5
      Left            =   1200
      TabIndex        =   2
      Top             =   1320
      Width           =   3015
   End
   Begin VB.Label Label10 
      BackStyle       =   0  'Transparent
      Caption         =   "备注:"
      Height          =   375
      Left            =   240
      TabIndex        =   1
      Top             =   1320
      Width           =   615
   End
End
Attribute VB_Name = "s_choice_frm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim courseno As String
Private Sub ShowClear()
Dim i As Integer
For i = 0 To 5
    lblstu(i).Caption = ""
Next i
End Sub
Private Sub display()

End Sub
Private Sub cmdAddCourse_Click()
    Dim i, j As Integer
     '查询list2中的每条记录,是否被选中
    For i = 0 To List2.ListCount - 1
        If List2.Selected(i) = True Then
            For j = 0 To List1.ListCount - 1
                If StrComp(Combo2.Text, List1.List(j)) = 0 Then
                    MsgBox "你已经选了《" & Combo2.Text & "》", vbInformation
                    Exit For
                End If
            Next j
            '当j循环结束,表明该学生还未选择该课程,把list2.list(i) 加到list1
            If j = List1.ListCount Then
                If MsgBox("你真的选择" & List2.List(i) & "的课程《" & Combo2.Text & "》", vbOKCancel) = vbOK Then
                    List1.AddItem Combo2.Text
                    '往choice表中添加记录,以及其它数据库操作
                    Dim strSQL1 As String
                    '根据教师姓名,得出教师编号,为添加记录到choice表做好准备
                    strSQL1 = "SELECT tno FROM teacherinfo WHERE tname='" & List2.List(i) & "'"
                    Dim rs1 As New ADODB.Recordset
                    rs1.Open strSQL1, con, adOpenStatic, adLockPessimistic, adCmdText
                    Dim strtno As String
                    strtno = rs1!tno
                    rs1.Close
                    Dim strSQL As String
                    strSQL = "SELECT * FROM choice"
                    Dim rs As New ADODB.Recordset
                    rs.Open strSQL, con, adOpenStatic, adLockPessimistic, adCmdText
                    '添加教师选课记录
                    rs.AddNew
                    rs.Fields("stuno") = Trim(Combo1.Text)
                    rs.Fields("courseno") = courseno
                    rs.Fields("teacherno") = strtno
                    rs.Fields("choicetime") = Date
                    rs.Update
                    rs.Close
                    List3.AddItem strtno
                End If
            End If

        End If
    Next i
End Sub

Private Sub cmdDelCourse_Click()
    Dim i As Integer
    For i = List1.ListCount - 1 To 0 Step -1
        If List1.Selected(i) = True Then
            '对choice 表操作  ,删除记录
            Dim strSQL1 As String
            '根据课程名称,得到课程编号
            strSQL1 = "SELECT cno FROM courseinfo WHERE cname='" & List1.List(i) & "'"
            Dim rs1 As New ADODB.Recordset
            rs1.Open strSQL1, con, adOpenStatic, adLockPessimistic, adCmdText
            Dim strcno As String
            strcno = rs1!cno
            rs1.Close
     
            If MsgBox("你真的要删除课程《" & List1.List(i), vbOKCancel) = vbOK Then
                Dim strSQL As String
                strSQL = "DELETE FROM choice WHERE stuno='" & Combo1.Text & "' AND courseno='" & strcno & "'"
                Dim cmd As New ADODB.Command
                cmd.ActiveConnection = con
                cmd.CommandText = strSQL
                cmd.Execute
                List1.RemoveItem i
                '显示学生所选课程的教师编号
                List3.Clear
                Dim strSQL2 As String
                strSQL2 = "select teacherno from choice where stuno='" & Combo1.Text & "'"
                Dim rs2 As New ADODB.Recordset
                rs2.Open strSQL2, con, adOpenStatic, adLockPessimistic, adCmdText
                While rs2.EOF = False
                    List3.AddItem rs2.Fields(0)
                    rs2.MoveNext
                Wend
                rs2.Close
            End If
        End If
    Next i
End Sub
Private Sub Combo1_Click()
    List1.Clear
    ShowClear

    Dim strSQL1 As String
    Dim rsstu As New ADODB.Recordset
    strSQL1 = "SELECT * FROM studentinfo WHERE sno='" & Combo1.Text & "'"
    rsstu.Open strSQL1, con, adOpenStatic, adLockPessimistic, adCmdText
    If rsstu.EOF = True Then
        MsgBox "没有该学生,请重新输入学生编号", vbExclamation, "注意"
        Combo1.SetFocus
        rsstu.Close
        Exit Sub
    Else
        Dim i As Integer
        For i = 0 To 5
            lblstu(i).Caption = rsstu.Fields(i + 1)
        Next i
        rsstu.Close
    End If

    Dim strSQL As String
    strSQL = "SELECT DISTINCT courseinfo.cname,studentinfo.sname " & _
             "FROM choice,courseinfo,studentinfo " & _
             "WHERE courseinfo.cno=choice.courseno AND choice.stuno=studentinfo.sno AND " & _
             "choice.stuno= '" & Combo1.Text & "'"

    Dim rs As New ADODB.Recordset
    rs.Open strSQL, con, adOpenStatic, adLockPessimistic, adCmdText


    If rs.EOF = True Then
        MsgBox "你还没有选择课程"
    Else
        lblstu(0).Caption = rs!sname
        While rs.EOF = False
            List1.AddItem rs!cname
            rs.MoveNext
        Wend
    End If
    rs.Close

    '显示学生所选课程的教师编号
    List3.Clear
    Dim strSQL2 As String
    strSQL2 = "SELECT teacherno FROM choice WHERE stuno='" & Combo1.Text & "'"
    Dim rs2 As New ADODB.Recordset
    rs2.Open strSQL2, con, adOpenStatic, adLockPessimistic, adCmdText
    While rs2.EOF = False
        List3.AddItem rs2.Fields(0)
        rs2.MoveNext
    Wend
    rs2.Close
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Combo1_Click
    End If
End Sub

Private Sub Combo2_Click()
    List2.Clear
    Dim strSQL As String
    strSQL = "SELECT DISTINCT teacherinfo.tname,courseinfo.cno " & _
             "FROM course_teacher,courseinfo,teacherinfo " & _
             "WHERE courseinfo.cno=course_teacher.cno AND course_teacher.tno=teacherinfo.tno AND " & _
             "courseinfo.cname= '" & Combo2.Text & "'"
    
    Dim rs As New ADODB.Recordset
    rs.Open strSQL, con, adOpenStatic, adLockPessimistic, adCmdText
    If rs.EOF = True Then
        MsgBox "没有老师任教这门课", vbInformation
    Else
        '往list2中添加courseinfo表的课程名
        While rs.EOF = False
            List2.AddItem rs!tname
            courseno = rs.Fields(1)
            rs.MoveNext
        Wend
    End If
    rs.Close
End Sub

Private Sub Form_Load()
    Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
    Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2
    '往combo1中添加studentinfo表的学生编号
    Dim rs As New ADODB.Recordset
    Dim strSQL As String
    strSQL = "SELECT * FROM studentinfo"
    rs.Open strSQL, con, adOpenStatic, adLockPessimistic, adCmdText
    While rs.EOF = False
        Combo1.AddItem rs!sno
        rs.MoveNext
    Wend
    rs.Close
    '往list2中添加courseinfo表的课程名
    Dim rs2 As New ADODB.Recordset
    Dim strSQL2 As String
    strSQL2 = "select * from courseinfo"
    rs2.Open strSQL2, con, adOpenStatic, adLockPessimistic, adCmdText
    While rs2.EOF = False
        Combo2.AddItem rs2!cname
        rs2.MoveNext
    Wend
    rs2.Close
    lblstu(0).Caption = ""
    List1.Clear
End Sub
Private Sub m_addcourse_Click()
    cmdAddCourse_Click
End Sub
Private Sub m_delcourse_Click()
    cmdDelCourse_Click
End Sub



⌨️ 快捷键说明

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