📄 frmaddgrade.frm
字号:
Private Sub Command1_Click()
On Error GoTo errh
If Combo1.Text <> "" Then
If Combo2.Text <> "" Then
If Text2.Text <> "" Then
If Text3.Text <> "" Then
If Combo3.Text <> "" Then
If checkclass Then
If checkcourse Then
If match = True Then
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("课程号").Value = Combo1.Text
Adodc1.Recordset.Fields("学号").Value = Text2.Text
Adodc1.Recordset.Fields("成绩").Value = Text3.Text
Adodc1.Recordset.Fields("课程名称").Value = Combo2.Text
Adodc1.Recordset.Fields("备注").Value = Combo3.Text
Adodc1.Recordset.Update
MsgBox "添加成功!"
Combo1.Text = ""
Combo2.Text = ""
Combo3.Text = ""
Text2.Text = ""
Text3.Text = ""
Else
MsgBox "成绩和备注不匹配,请核对!"
End If
Else
MsgBox "没有这个课程,不能添加!"
Combo3.Text = ""
Text2.Text = ""
Text3.Text = ""
Combo1.Text = ""
Combo2.Text = ""
Combo1.SetFocus
End If
Else
MsgBox "这个成绩已经有了,不能再添加!"
End If
Else
MsgBox "成绩不能为空!"
Text3.SetFocus
End If
Else
MsgBox "备注不能为空,请输入备注!"
End If
Else
MsgBox "学号不能为空,请输入学号!"
Text2.SetFocus
End If
Else
MsgBox "课程名称不能为空,请输入课程名称!"
Combo2.SetFocus
End If
Else
MsgBox "课程号不能为空,请输入课程号!"
Combo1.SetFocus
End If
Exit Sub
errh:
MsgBox Err.Description
End Sub
Private Sub Command2_Click()
On Error GoTo errh
If Text2.Text <> "" Then
If Text3.Text <> "" Then
If Combo1.Text <> "" Then
If Combo2.Text <> "" Then
If Combo3.Text <> "" Then
If checkclass = False Then
If match Then
rs.LockType = adLockOptimistic
rs.CursorType = adOpenKeyset
rs.Open "select * from 成绩表 where 课程号='" & Trim(Combo1.Text) & "' and 课程名称='" & Trim(Combo2.Text) & "' and 学号='" & Trim(Text2.Text) & "' ", cn, , , adCmdText
rs.Fields("成绩").Value = Text3.Text
rs.Fields("备注").Value = Combo3.Text
rs.Update
rs.Close
MsgBox "修改成功!"
Combo1.Text = ""
Combo2.Text = ""
Combo3.Text = ""
Text2.Text = ""
Text3.Text = ""
Combo1.SetFocus
Else
MsgBox "成绩和备注不匹配,请核对!"
End If
Else
MsgBox "没有该课程成绩,不能修改!"
End If
Else
MsgBox "该项不能为空,请输入备注!"
End If
Else
MsgBox "该项不能为空,请输入课程名称!"
End If
Else
MsgBox "该项不能为空,请输入课程号!"
End If
Else
MsgBox "该项不能为空,请输入成绩!"
End If
Else
MsgBox "该项不能为空,请输入学号!"
End If
Exit Sub
errh:
MsgBox Err.Description
'rs.Close
End Sub
Private Sub Command3_Click()
On Error GoTo errh
If MsgBox("你的操作将会删除当前的纪录,你确信吗?", vbOKCancel, "警告") = vbOK Then
rs.Open "SELECT * FROM 成绩表 WHERE 课程名称='" & Trim(Combo2.Text) & "'AND 课程号='" & Trim(Combo1.Text) & "' and 学号='" & Trim(Text2.Text) & "'", cn, adOpenDynamic, adLockOptimistic, adCmdText
If rs.EOF Then
'Adodc2.Recordset.Close
rs.Close
MsgBox "没有这条记录,无法删除!"
Exit Sub
End If
'Adodc2.Recordset.Delete
'Adodc2.Recordset.Update
'Adodc2.Recordset.Close
rs.Delete
rs.Update
rs.Close
MsgBox "删除成功!"
Text2.Text = ""
Text3.Text = ""
Combo1.Text = ""
Combo2.Text = ""
Combo3.Text = ""
End If
Exit Sub
errh:
rs.Close
MsgBox Err.Description
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Form_Load()
On Error GoTo errh
MakeCenter frmAddGrade
Set rs = cn.Execute("SELECT 课程名称,课程号 FROM 课程表")
rs.MoveFirst
Do
Combo1.AddItem rs.Fields(1).Value
Combo2.AddItem rs.Fields(0).Value
rs.MoveNext
Loop Until rs.EOF
'rs.Close
Combo3.AddItem "优异"
Combo3.AddItem "良好"
Combo3.AddItem "中等"
Combo3.AddItem "及格"
Combo3.AddItem "不及格"
Exit Sub
errh:
rs.Close
MsgBox Err.Description
End Sub
Private Function checkcourse() As Boolean
On Error GoTo errh
Set rs = cn.Execute("select * from 课程表 where 课程号='" & Trim(Combo1.Text) & "' and 课程名称='" & Trim(Combo2.Text) & "'")
'If Adodc2.Recordset.EOF Then
'Adodc2.Recordset.Close
If rs.EOF Then
rs.Close
checkcourse = False
Exit Function
End If
checkcourse = True
rs.Close
Exit Function
errh:
rs.Close
MsgBox Err.Description
End Function
Private Function checkclass() As Boolean '检测添加的课程是否重复
On Error GoTo errh
' Adodc2.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=db5.MDB;" & _
"DefaultDir=" & CheckPath(App.path) & ";" & _
"UID=;PWD=;"
Set rs = cn.Execute("SELECT 课程名称 FROM 成绩表 WHERE 课程名称='" & Trim(Combo2.Text) & "'AND 课程号='" & Trim(Combo1.Text) & "' and 学号='" & Trim(Text2.Text) & "' And 成绩 Is Not Null ")
' Adodc2.RecordSource = "select * from 课程 where 课程号='" & Trim(Text1.Text) & "' and 课程名称='" & Trim(Text2.Text) & "' "
If rs.EOF Then
rs.Close
checkclass = True
Exit Function
End If
checkclass = False
rs.Close
Exit Function
errh:
rs.Close
MsgBox Err.Description
End Function
Private Function match() As Boolean
On Error GoTo Error
If Text3.Text < 60 Then
If Combo3.Text = "不及格" Then
match = True
Else
match = False
End If
End If
If Text3.Text < 70 And Text3.Text >= 60 Then
If Combo3.Text = "及格" Then
match = True
Else
match = False
End If
End If
If Text3.Text < 80 And Text3.Text >= 70 Then
If Combo3.Text = "中等" Then
match = True
Else
match = False
End If
End If
If Text3.Text < 90 And Text3.Text >= 80 Then
If Combo3.Text = "良好" Then
match = True
Else
match = False
End If
End If
If Text3.Text <= 100 And Text3.Text >= 90 Then
If Combo3.Text = "优异" Then
match = True
Else
match = False
End If
End If
Exit Function
Error:
MsgBox Err.descirption
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -