📄 form2.frm
字号:
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
'Set rs = cn.Execute("select 成绩 from 学生与课程 where 课程号='" & Trim(Combo1.Text) & "' and 课程名称='" & Trim(Combo2.Text) & "' and 学号='" & Trim(Text2.Text) & "' ")
'If rs.EOF Then
'rs.Close
'Exit Sub
' End If
'rs.Close
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.Find ("UserName=" & "'" & Text1.Text & "'")
'If rs.Fields("Password").Value = Text2.Text Then
'rs.Fields(0).Value = Text3.Text
'rs.Fields(1).Value = Combo3.Text
'rs.Update
'rs.Update "成绩", Text3.Text
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
'Combo1.DataSource = Adodc2
'Combo2.DataSource = Adodc2
'Combo3.DataSource = Adodc2
'Text2.DataSource = Adodc2
'Text3.DataSource = Adodc2
'SD = True
'Adodc1.Recordset.Delete
' Adodc1.Recordset.MoveFirst
' Dim str As String
' str = " delete from 学生与课程 " 'where 课程号='" & Trim(Combo1.Text) & "' and 课程名称= '" & Trim(Combo2.Text) & "' and 学号= '" & Trim(Text2.Text) & "' and 成绩= '" & Trim(Text3.Text) & "' "
' Dim cmd As New ADODB.Command
' cmd.ActiveConnection = cn
'
' cmd.CommandText = str
' cmd.CommandType = adCmdText
'
' cmd.Execute
'rs.Open
' Dim rs1 As New ADODB.Recordset
'Set rs1 = Nothing
'rs1.CursorType = adOpenDynamic
'rs1.LockType = adLockOptimistic
rs.Open "SELECT * FROM 学生与课程 WHERE 课程名称='" & Trim(Combo2.Text) & "'AND 课程号='" & Trim(Combo1.Text) & "' and 学号='" & Trim(Text2.Text) & "'", cn, adOpenDynamic, adLockOptimistic, adCmdText
'Set rs1 = cn.Execute("SELECT * FROM 学生与课程 WHERE 课程名称='" & Trim(Combo2.Text) & "'AND 课程号='" & Trim(Combo1.Text) & "' and 学号='" & Trim(Text2.Text) & "' And 成绩 = '" & Trim(Text3.Text) & "' ")
'If Adodc2.Recordset.EOF Then
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 "不及格"
'Combo1.Text = "请选择课程"
' Adodc1.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=db5.MDB;" & _
"DefaultDir=" & CheckPath(App.path) & ";" & _
"UID=;PWD=;"
'"PASSWORD=197967yh"
' Adodc1.RecordSource = "SELECT * FROM 学生与课程"
' Label1.DataField = "学生ID"
'Label6.DataField = "课程ID"
'Text4.DataField = "成绩"
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 + -