📄 scoremanage.frm
字号:
VERSION 5.00
Begin VB.Form scoreManage
Caption = "课程成绩管理"
ClientHeight = 3630
ClientLeft = 2910
ClientTop = 2415
ClientWidth = 5265
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3630
ScaleWidth = 5265
Begin VB.CommandButton cmdSea
Caption = "查询"
Height = 375
Left = 3720
TabIndex = 18
Top = 120
Width = 1215
End
Begin VB.CommandButton cmdDelete
Caption = "删除"
Height = 375
Left = 3720
TabIndex = 17
Top = 1080
Width = 1215
End
Begin VB.CommandButton cmdAdd
Caption = "添加"
Height = 375
Left = 3720
TabIndex = 16
Top = 600
Width = 1215
End
Begin VB.TextBox txtRecNo
BeginProperty Font
Name = "微软雅黑"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Left = 360
TabIndex = 14
Top = 1920
Width = 2895
End
Begin VB.TextBox txtName
Height = 375
Left = 1560
Locked = -1 'True
TabIndex = 6
Text = " "
Top = 0
Width = 1695
End
Begin VB.TextBox txtNum
Height = 375
Left = 1560
TabIndex = 9
Text = " "
Top = 480
Width = 1695
End
Begin VB.TextBox txtCourse
Height = 375
Left = 1560
TabIndex = 11
Text = " "
Top = 960
Width = 1695
End
Begin VB.TextBox txtScore
Height = 375
Left = 1560
TabIndex = 13
Text = " "
Top = 1440
Width = 1695
End
Begin VB.CommandButton cmdMove
Caption = "首记录"
Height = 375
Index = 0
Left = 240
TabIndex = 5
Top = 2640
Width = 1095
End
Begin VB.CommandButton cmdMove
Caption = "前一记录"
Height = 375
Index = 1
Left = 1440
TabIndex = 4
Top = 2640
Width = 1095
End
Begin VB.CommandButton cmdMove
Caption = "下一记录"
Height = 375
Index = 2
Left = 2640
TabIndex = 3
Top = 2640
Width = 1095
End
Begin VB.CommandButton cmdMove
Caption = "尾记录"
Height = 375
Index = 3
Left = 3840
TabIndex = 2
Top = 2640
Width = 1095
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 375
Left = 3720
TabIndex = 1
Top = 1560
Width = 1215
End
Begin VB.CommandButton cmdExit
Caption = "关闭"
Height = 375
Left = 3720
TabIndex = 0
Top = 2040
Width = 1215
End
Begin VB.Label Label5
Caption = "姓名框不可修改,为只读属性。所以拒绝输入数据。"
Height = 255
Left = 480
TabIndex = 15
Top = 3240
Width = 4215
End
Begin VB.Label Label1
Caption = "姓名"
Height = 255
Left = 360
TabIndex = 12
Top = 120
Width = 1095
End
Begin VB.Label Label2
Caption = "学号"
Height = 255
Left = 360
TabIndex = 10
Top = 600
Width = 1095
End
Begin VB.Label Label3
Caption = "课程"
Height = 255
Left = 360
TabIndex = 8
Top = 1080
Width = 1095
End
Begin VB.Label Label4
Caption = "成绩"
Height = 255
Left = 360
TabIndex = 7
Top = 1560
Width = 975
End
End
Attribute VB_Name = "scoremanage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim objCourse As Recordset
Dim objStudent As Recordset
Dim objScore As Recordset
Dim objCn As Connection
Dim isadding As Boolean
Private Sub cmdAdd_Click()
txtName = "姓名不可修改"
txtNum = ""
txtCourse = ""
txtScore = ""
txtNum.SetFocus
isadding = True
If isadding Then objScore.AddNew
txtRecNo = "记录添加中……"
objScore.Fields("学号") = Trim(txtNum)
If objStudent.EOF = False Then
objStudent.MoveFirst
End If
objStudent.Find "学号='" & objScore.Fields("学号") & "'"
End Sub
Private Sub cmdDelete_Click()
If isadding Then
isadding = False
If objScore.BOF = objScore.EOF Then
txtRecNo = "当前记录:没有记录"
Else
ShowData
End If
Else
If objScore.RecordCount > 0 Then
If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, "学生成绩管理") = vbYes Then
objScore.Delete
cmdMove(2).Value = True
Else
ShowData
End If
End If
End If
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdSave_Click()
objScore.Fields("学号") = Trim(txtNum)
objScore.Fields("课程") = Trim(txtCourse)
objScore.Fields("成绩") = Val(txtScore)
objScore.Update
MsgBox "成绩保存成功", vbInformation, "成绩管理"
isadding = False
txtRecNo = "记录:" & objScore.AbsolutePosition & "/" & objScore.RecordCount
End Sub
Private Sub cmdSea_Click()
scoremanage.Hide
frmQScore.Show
frmQScore.txtNum.SetFocus
End Sub
Private Sub Form_Load()
Set objCn = New Connection
With objCn
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=db4;PWD=lsc;Data Sourse=(local);" & _
"Initial Catalog=成绩管理"
.Open
End With
Set objScore = New Recordset
With objScore
Set .ActiveConnection = objCn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "SELECT * FROM 成绩记录"
End With
Set objCourse = New Recordset
With objCourse
Set .ActiveConnection = objCn
.CursorLocation = adUseClient
.Open "SELECT * FROM 课程信息"
End With
Set objStudent = New Recordset
With objStudent
Set .ActiveConnection = objCn
.CursorLocation = adUseClient
.Open "SELECT * FROM 学生名单"
End With
cmdMove(0).Value = True
End Sub
Private Sub cmdMove_Click(Index As Integer)
With objScore
Select Case Index
Case 0
If .RecordCount > 0 And Not .BOF Then .MoveFirst
Case 1
If .RecordCount > 0 And Not .BOF Then
.MovePrevious
If .BOF Then .MoveFirst
End If
Case 2
If .RecordCount > 0 And Not .BOF Then
.MoveNext
If .EOF Then .MoveLast
End If
Case 3
If .RecordCount > 0 And Not .EOF Then .MoveLast
End Select
If .RecordCount < 1 Then
txtRecNo = "当前记录:没有"
txtName = ""
txtNum = ""
txtCourse = ""
txtScore = ""
Else
ShowData
End If
End With
End Sub
Private Sub ShowData()
With objScore
'根据学号显示姓名
txtNum = .Fields("学号")
objStudent.MoveFirst
objStudent.Find "学号='" & .Fields("学号") & "'"
txtName = objStudent.Fields("姓名")
'根据课程编号显示课程名称
objCourse.MoveFirst
objCourse.Find "课程='" & .Fields("课程") & "'"
txtCourse = objCourse.Fields("课程")
If IsNull(.Fields("成绩")) Then
txtScore = "No"
Else
txtScore = .Fields("成绩")
End If
txtRecNo = "当前记录:第" & .AbsolutePosition & "条/共" & .RecordCount & "条"
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
objCn.Close
Set objCn = Nothing
Set objScore = Nothing
Set objCourse = Nothing
Set objStudent = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -