frmaddscore.frm
来自「数据库课程设计」· FRM 代码 · 共 248 行
FRM
248 行
VERSION 5.00
Begin VB.Form frmAddScore
Caption = "成绩管理-添加"
ClientHeight = 2490
ClientLeft = 60
ClientTop = 345
ClientWidth = 6570
LinkTopic = "Form1"
ScaleHeight = 2490
ScaleWidth = 6570
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdCancel
Caption = "返回(&N)"
Height = 375
Left = 3120
TabIndex = 7
Top = 1920
Width = 1215
End
Begin VB.CommandButton cmdOK
Caption = "添加(&Y)"
Height = 375
Left = 1560
TabIndex = 6
Top = 1920
Width = 1335
End
Begin VB.Frame Frame1
Caption = "课程基本信息"
Height = 1575
Left = 120
TabIndex = 0
Top = 120
Width = 6375
Begin VB.TextBox txtCourseName
Height = 285
Left = 4440
TabIndex = 12
Text = "Text1"
Top = 720
Width = 1815
End
Begin VB.TextBox txtName
Enabled = 0 'False
Height = 285
Left = 4440
TabIndex = 10
Text = "Text1"
Top = 360
Width = 1815
End
Begin VB.ComboBox cboCourseNo
Height = 315
Left = 1440
TabIndex = 8
Text = "Combo1"
Top = 720
Width = 1815
End
Begin VB.TextBox txtScore
Height = 285
Left = 1440
TabIndex = 2
Text = "Text2"
Top = 1080
Width = 1815
End
Begin VB.TextBox txtStuNo
Height = 285
Left = 1440
TabIndex = 1
Text = "Text3"
Top = 360
Width = 1815
End
Begin VB.Label Label4
Caption = "课程名称:"
Height = 255
Left = 3480
TabIndex = 11
Top = 720
Width = 975
End
Begin VB.Label Label2
Caption = "学生姓名:"
Height = 255
Left = 3480
TabIndex = 9
Top = 360
Width = 975
End
Begin VB.Label Label5
Caption = "课程成绩:"
Height = 255
Left = 480
TabIndex = 5
Top = 1080
Width = 975
End
Begin VB.Label Label3
Caption = "学生学号:"
Height = 255
Left = 480
TabIndex = 4
Top = 360
Width = 975
End
Begin VB.Label Label1
Caption = "课程编号:"
Height = 255
Left = 480
TabIndex = 3
Top = 720
Width = 975
End
End
End
Attribute VB_Name = "frmAddScore"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public sqlStr As String
Public msgText As String
Private Sub cboCourseNo_Click()
Dim rstCourseName As ADODB.Recordset
sqlStr = "select course_name from courseInfo where course_no='" & Trim(cboCourseNo.Text) & "'"
Set rstCourseName = ExecuteSQL(sqlStr, msgText)
If Not rstCourseName.EOF Then
txtCourseName = rstCourseName!course_name
Else
MsgBox "没有找到相关数据!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstCourseName.Close
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
Dim rstScore As ADODB.Recordset
Dim stuNo As String
Dim courseNo As String
Dim score As String
'获取数据
stuNo = Trim(txtStuNo.Text)
courseNo = Trim(cboCourseNo.Text)
score = Trim(txtScore.Text)
If stuNo = "" Or score = "" Then
MsgBox "请将信息补充完整", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
'添加新记录
sqlStr = "select * from scoreInfo"
Set rstScore = ExecuteSQL(sqlStr, msgText)
rstScore.AddNew
rstScore.Fields("stu_no") = stuNo
rstScore.Fields("course_no") = courseNo
rstScore.Fields("course_score") = score
rstScore.Update
rstScore.Close
MsgBox "成绩信息添加完成!", vbOKOnly + vbExclamation, "警告"
initForm
End Sub
Private Sub Form_Load()
'窗体居中显示
Me.Top = (Screen.Height - Me.Height) \ 2
Me.Left = (Screen.Width - Me.Width) \ 2
initForm
End Sub
Private Sub txtStuNo_KeyPress(KeyAscii As Integer)
Dim rstStudent As ADODB.Recordset
If KeyAscii = 13 Then
sqlStr = "select name from studentInfo"
Set rstStudent = ExecuteSQL(sqlStr, msgText)
If Not rstStudent.EOF Then
txtName = rstStudent.Fields(0)
Else
MsgBox "未找到学生的信息记录!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstStudent.Close
End If
End Sub
Sub initCourseNo()
Dim rstCourseNo As ADODB.Recordset
'从数据库中读取所有课程编号并添加到组合列表框中
'方便录入时进行选择
sqlStr = "select course_no from courseInfo"
Set rstCourseNo = ExecuteSQL(sqlStr, msgText)
cboCourseNo.Clear
If Not rstCourseNo.EOF Then
Do While Not rstCourseNo.EOF
cboCourseNo.AddItem Trim(rstCourseNo.Fields(0))
rstCourseNo.MoveNext
Loop
cboCourseNo.ListIndex = 0
Else
MsgBox "请添加数据!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstCourseNo.Close
End Sub
Sub initForm()
txtStuNo = ""
txtName = ""
txtCourseName = ""
txtScore = ""
initCourseNo
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?