📄 修改&删除课程信息.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form sub_cd
BorderStyle = 1 'Fixed Single
Caption = "课程修改&删除"
ClientHeight = 3495
ClientLeft = 4890
ClientTop = 3885
ClientWidth = 5355
LinkTopic = "Form1"
MaxButton = 0 'False
ScaleHeight = 3495
ScaleWidth = 5355
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 360
Top = 3120
Visible = 0 'False
Width = 1575
_ExtentX = 2778
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=stu_manage"
OLEDBString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=stu_manage"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = "sa"
Password = "manager"
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin VB.CommandButton Command3
Caption = "删除"
Height = 375
Left = 3960
TabIndex = 9
Top = 3000
Width = 1095
End
Begin VB.CommandButton Command2
Caption = "修改"
Height = 375
Left = 2520
TabIndex = 8
Top = 3000
Width = 1095
End
Begin VB.Frame Frame1
Caption = "查询结果"
Height = 2055
Left = 240
TabIndex = 3
Top = 840
Width = 4935
Begin VB.TextBox Text4
Height = 375
Left = 1200
TabIndex = 7
Top = 1440
Width = 3375
End
Begin VB.ComboBox Combo1
Height = 300
Left = 3720
Style = 2 'Dropdown List
TabIndex = 6
Top = 960
Width = 855
End
Begin VB.TextBox Text3
Height = 375
Left = 1200
TabIndex = 5
Top = 900
Width = 1335
End
Begin VB.TextBox Text2
Height = 375
Left = 1200
TabIndex = 4
Top = 360
Width = 2055
End
Begin VB.Label Label5
Caption = "上课地点"
Height = 255
Left = 240
TabIndex = 13
Top = 1560
Width = 855
End
Begin VB.Label Label4
Caption = "课程类别"
Height = 255
Left = 2760
TabIndex = 12
Top = 1080
Width = 735
End
Begin VB.Label Label3
Caption = "授课教师"
Height = 255
Left = 240
TabIndex = 11
Top = 1020
Width = 855
End
Begin VB.Label Label2
Caption = "课程名称"
Height = 255
Left = 240
TabIndex = 10
Top = 480
Width = 855
End
End
Begin VB.CommandButton Command1
Caption = "查询"
Height = 375
Left = 3120
TabIndex = 2
Top = 240
Width = 735
End
Begin VB.TextBox Text1
Height = 375
Left = 1440
TabIndex = 1
Top = 240
Width = 1215
End
Begin VB.Label unshow
Height = 375
Left = 4560
TabIndex = 14
Top = 240
Visible = 0 'False
Width = 495
End
Begin VB.Label Label1
Caption = "课程编号"
Height = 255
Left = 480
TabIndex = 0
Top = 360
Width = 855
End
End
Attribute VB_Name = "sub_cd"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public strS As String '定义一变量
Public rs As New ADODB.Recordset
Public adoconn As New ADODB.Connection 'Connection 对象代表了打开与数据源的连接。
Public adocomm As New ADODB.Command 'Command 对象定义了将对数据源执行的指定命令。
Public ReturnValue As Integer '调用存储过程的返回值
Public sub_id As String
Public sub_name As String
Public teach_name As String
Public type_name As String
Public type_id As Integer
Public address As String
Public Sub connect()
adoconn.ConnectionString = Adodc1.ConnectionString 'Adodc1为窗体中的ADO控件,并已成功连接数据库
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
End Sub
'类别
Private Sub Combo1_Click()
type_name = Combo1.Text
adoconn.Open
rs.Open "select * from type where name='" & type_name & "'", adoconn
If rs.Fields("name") = type_name Then
type_id = rs.Fields("id")
End If
rs.Close
adoconn.Close
End Sub
'查询
Private Sub Command1_Click()
sub_id = Text1.Text
If Len(sub_id) = 0 Then
MsgBox "请先输入课程编号!"
Text1.SetFocus
Exit Sub
Else
Dim i As Integer
adoconn.Open
rs.Open "select * from subject", adoconn
If rs.RecordCount = 0 Then
MsgBox "当前没有任何课程记录,请先添加!"
adoconn.Close
Unload Me
sub_manage.Show
End If
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
If sub_id = rs.Fields("id") Then
GoTo find
End If
rs.MoveNext
Next i
MsgBox "该编号不存在,请重试!"
Call clear
Text1.SetFocus
rs.Close
adoconn.Close
Exit Sub
End If
find:
'为避免未查询直接修改或删除而用
unshow.Caption = ""
sub_name = rs.Fields("name")
teach_name = rs.Fields("teacher")
type_id = rs.Fields("type")
address = rs.Fields("addr")
rs.Close
'获取类别名称
rs.Open "select * from type", adoconn
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
If type_id = rs.Fields("id") Then
type_name = rs.Fields("name")
End If
rs.MoveNext
Next i
rs.Close
adoconn.Close
Call load
Text2.Text = sub_name
Text3.Text = teach_name
Text4.Text = address
Combo1.Text = type_name
End Sub
'加载下拉列表
Private Sub load()
Dim i As Integer
adoconn.Open
'加载课程类别
Combo1.clear
rs.Open "select * from type", adoconn
rs.MoveFirst
For i = 0 To rs.RecordCount - 1
Combo1.AddItem rs.Fields("name")
rs.MoveNext
Next i
rs.Close
adoconn.Close
End Sub
'修改
Private Sub Command2_Click()
Dim r As Integer
sub_id = Text1.Text
'没有输入学号
If Len(sub_id) = 0 Then
MsgBox "请先输入课程编号!"
Text1.SetFocus
Exit Sub
End If
'没有点击“查询”
If Len(unshow) <> 0 Then
MsgBox "请先查询出其所有信息!"
Call clear
Exit Sub
End If
'确认修改
r = MsgBox("是否修改?", 4 + 32 + 0, "确认修改")
If r = 6 Then
'选择是
Dim i As Integer
adoconn.Open
rs.Open "select * from subject where id='" & sub_id & "'", adoconn
If rs.RecordCount = 0 Then
MsgBox "当前没有任何课程记录,请先添加!"
adoconn.Close
Unload Me
sub_manage.Show
End If
rs.MoveFirst
rs.Fields("id") = Text1.Text
rs.Fields("name") = Text2.Text
rs.Fields("teacher") = Text3.Text
rs.Fields("addr") = Text4.Text
rs.Fields("type") = type_id
rs.Update
rs.Close
adoconn.Close
MsgBox "修改成功!"
Call Command1_Click
End If
End Sub
'删除
Private Sub Command3_Click()
Dim r As Integer
sub_id = Text1.Text
'没有输入学号
If Len(sub_id) = 0 Then
MsgBox "请先输入课程编号!"
Text1.SetFocus
Exit Sub
End If
'没有点击“查询”
If Len(unshow) <> 0 Then
MsgBox "请先查询出其所有信息!"
Call clear
Exit Sub
End If
'确认删除
r = MsgBox("是否删除?", 4 + 32 + 0, "确认删除")
If r = 6 Then
'选择是
Dim i As Integer
adoconn.Open
rs.Open "select * from subject", adoconn
If rs.RecordCount = 0 Then
MsgBox "当前没有任何课程记录,请先添加!"
adoconn.Close
Unload Me
sub_manage.Show
End If
rs.Close
rs.Open "delete from subject where id='" & sub_id & "'", adoconn
adoconn.Close
Call clear
MsgBox "删除成功!"
unshow.Caption = "unshow"
End If
End Sub
'清空所有文本框和组合框
Private Sub clear()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text1.SetFocus
End Sub
Private Sub Form_Load()
unshow.Caption = "unshow"
Call connect
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -