📄 t_choice_frm.frm
字号:
VERSION 5.00
Begin VB.Form t_choice_frm
BorderStyle = 1 'Fixed Single
Caption = "教师选课"
ClientHeight = 4530
ClientLeft = 45
ClientTop = 435
ClientWidth = 7500
FillColor = &H00FF0000&
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
Picture = "t_choice_frm.frx":0000
ScaleHeight = 4530
ScaleWidth = 7500
Begin VB.ListBox List2
Height = 1680
Left = 4320
MultiSelect = 2 'Extended
TabIndex = 13
Top = 2640
Width = 2295
End
Begin VB.CommandButton cmddelcourse
Caption = ">>>去除"
Height = 375
Left = 2880
MouseIcon = "t_choice_frm.frx":27A2
Picture = "t_choice_frm.frx":4614
TabIndex = 12
Top = 3120
Width = 1215
End
Begin VB.CommandButton cmdaddcourse
BackColor = &H8000000D&
Caption = "<<<选择"
Height = 375
Left = 2880
MaskColor = &H00FF0000&
Picture = "t_choice_frm.frx":230E56
TabIndex = 11
Top = 2640
Width = 1215
End
Begin VB.ListBox List1
Height = 1680
Left = 360
MultiSelect = 2 'Extended
TabIndex = 10
Top = 2640
Width = 2295
End
Begin VB.ComboBox Combo1
Height = 300
Left = 1440
TabIndex = 0
Top = 480
Width = 1455
End
Begin VB.Label Label1
BorderStyle = 1 'Fixed Single
Caption = "Label1"
Height = 15
Left = 240
TabIndex = 16
Top = 2160
Width = 7095
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "已经选择的课程:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Left = 360
TabIndex = 15
Top = 2280
Width = 1695
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "全部课程名称"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 255
Left = 4320
TabIndex = 14
Top = 2280
Width = 1695
End
Begin VB.Label Label7
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "教师编号:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 180
Left = 360
TabIndex = 9
Top = 480
Width = 975
End
Begin VB.Label Label8
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "教师职称:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 180
Left = 360
TabIndex = 8
Top = 960
Width = 975
End
Begin VB.Label Label9
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "备注:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 180
Left = 360
TabIndex = 7
Top = 1440
Width = 945
End
Begin VB.Label Label10
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "联系电话:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 180
Left = 3480
TabIndex = 6
Top = 960
Width = 975
End
Begin VB.Label Label12
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "教师姓名:"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00FF0000&
Height = 180
Left = 3480
TabIndex = 5
Top = 480
Width = 975
End
Begin VB.Label lblteacher
BackColor = &H80000009&
BorderStyle = 1 'Fixed Single
Caption = "lblstu"
Height = 495
Index = 3
Left = 1440
TabIndex = 4
Top = 1440
Width = 3855
End
Begin VB.Label lblteacher
BackColor = &H80000009&
BorderStyle = 1 'Fixed Single
Caption = "lblstu"
Height = 255
Index = 2
Left = 4560
TabIndex = 3
Top = 960
Width = 1095
End
Begin VB.Label lblteacher
BackColor = &H80000009&
BorderStyle = 1 'Fixed Single
Caption = "lblstu"
Height = 255
Index = 1
Left = 1440
TabIndex = 2
Top = 960
Width = 1095
End
Begin VB.Label lblteacher
BackColor = &H80000009&
BorderStyle = 1 'Fixed Single
Caption = "lblstu"
Height = 300
Index = 0
Left = 4560
TabIndex = 1
Top = 480
Width = 1095
End
End
Attribute VB_Name = "t_choice_frm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub ShowClear()
Dim i As Integer
For i = 0 To 3
lblteacher(i).Caption = ""
Next i
End Sub
Private Sub cmdAddCourse_Click()
Dim i, j As Integer
For i = 0 To List2.ListCount - 1 '查询list2中的每条记录,是否被选中
If List2.Selected(i) = True Then
For j = 0 To List1.ListCount - 1
If StrComp(List2.List(i), List1.List(j)) = 0 Then
MsgBox "你已经选了《" & List2.List(i) & "》", vbInformation
Exit For
End If
Next j
'当j循环结束,表明该教师还未选择该课程,把list2.list(i) 加到list1
If j = List1.ListCount Then
List1.AddItem List2.List(i)
'往course_teacher表中添加记录,以及其它数据库操作
Dim strSQL1 As String
strSQL1 = "SELECT cno FROM courseinfo WHERE cname='" & List2.List(i) & "'"
Dim rs1 As New ADODB.Recordset
rs1.Open strSQL1, con, adOpenStatic, adLockPessimistic, adCmdText
'根据课程名,得出课程编号,为添加记录做好准备
Dim strcno As String
strcno = rs1!cno
rs1.Close
Dim strSQL As String
strSQL = "SELECT * FROM course_teacher"
Dim rs As New ADODB.Recordset
rs.Open strSQL, con, adOpenStatic, adLockPessimistic, adCmdText
rs.AddNew '添加教师选课记录
rs.Fields(1) = strcno
rs.Fields(2) = Trim(Combo1.Text)
rs.Update
rs.Close
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
'对course_teacher表操作 ,删除记录
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
Dim strSQL As String
strSQL = "DELETE FROM course_teacher WHERE tno='" & Combo1.Text & "' AND cno='" & strcno & "'"
Dim cmd As New ADODB.Command
cmd.ActiveConnection = con
cmd.CommandText = strSQL
cmd.Execute
List1.RemoveItem i
End If
Next i
End Sub
Private Sub Combo1_Click()
List1.Clear '清空原来的数据
ShowClear
Dim strSQL1 As String
strSQL1 = "SELECT * FROM teacherinfo WHERE tno='" & Combo1.Text & "'"
Dim rs1 As New ADODB.Recordset
rs1.Open strSQL1, con, adOpenStatic, adLockPessimistic, adCmdText
If rs1.EOF = True Then
MsgBox "没有该老师,请重新输入教师编号", vbExclamation, "注意"
Combo1.SetFocus
rs1.Close
Exit Sub
Else
Dim i As Integer
For i = 0 To 3
lblteacher(i).Caption = rs1.Fields(i + 1)
Next i
rs1.Close
End If
Dim strSQL As String
strSQL = "SELECT DISTINCT courseinfo.cname,teacherinfo.tname " & _
"FROM course_teacher,courseinfo,teacherinfo " & _
"WHERE courseinfo.cno=course_teacher.cno AND course_teacher.tno=teacherinfo.tno AND course_teacher.tno= '" & Combo1.Text & "'"
Dim rs As New ADODB.Recordset
rs.Open strSQL, con, adOpenStatic, adLockPessimistic, adCmdText
If rs.EOF = True Then
MsgBox "你还没有选择课程", vbInformation, "注意"
Else
lblteacher(0).Caption = rs!tname '显示教师姓名
While rs.EOF = False ' 往list2中添加courseinfo表的课程名
List1.AddItem rs!cname
rs.MoveNext
Wend
End If
rs.Close
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo1_Click
End If
End Sub
Private Sub Form_Load()
Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2
'往combo1中添加teacherinfo表的教师编号
Dim rs As New ADODB.Recordset
Dim str As String
str = "SELECT * FROM teacherinfo"
rs.Open str, con, adOpenStatic, adLockPessimistic, adCmdText
While rs.EOF = False
Combo1.AddItem rs!tno
rs.MoveNext
Wend
rs.Close
'往list2中添加courseinfo表的课程名
Dim rs2 As New ADODB.Recordset
Dim str2 As String
str2 = "select * from courseinfo"
rs2.Open str2, con, adOpenStatic, adLockPessimistic, adCmdText
While rs2.EOF = False
List2.AddItem rs2!cname
rs2.MoveNext
Wend
rs2.Close
'清空
ShowClear
List1.Clear
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -