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 "這個成績已經(jīng)有了,不能再添加!"
End If
Else
MsgBox "成績不能為空!"
Text3.SetFocus
End If
Else
MsgBox "備注不能為空,請輸入備注!"
End If
Else
MsgBox "學(xué)號不能為空,請輸入學(xué)號!"
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 學(xué)生與課程 where 課程號='" & Trim(Combo1.Text) & "' and 課程名稱='" & Trim(Combo2.Text) & "' and 學(xué)號='" & 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 學(xué)生與課程 where 課程號='" & Trim(Combo1.Text) & "' and 課程名稱='" & Trim(Combo2.Text) & "' and 學(xué)號='" & 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 "該項不能為空,請輸入學(xué)號!"
End If
Exit Sub
errh:
MsgBox Err.Description
'rs.Close
End Sub
Private Sub Command3_Click()
On Error GoTo errh
If MsgBox("你的操作將會刪除當(dāng)前的紀(jì)錄,你確信嗎?", 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 學(xué)生與課程 " 'where 課程號='" & Trim(Combo1.Text) & "' and 課程名稱= '" & Trim(Combo2.Text) & "' and 學(xué)號= '" & 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 學(xué)生與課程 WHERE 課程名稱='" & Trim(Combo2.Text) & "'AND 課程號='" & Trim(Combo1.Text) & "' and 學(xué)號='" & Trim(Text2.Text) & "'", cn, adOpenDynamic, adLockOptimistic, adCmdText
'Set rs1 = cn.Execute("SELECT * FROM 學(xué)生與課程 WHERE 課程名稱='" & Trim(Combo2.Text) & "'AND 課程號='" & Trim(Combo1.Text) & "' and 學(xué)號='" & 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 "優(yōu)異"
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 學(xué)生與課程"
' Label1.DataField = "學(xué)生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 '檢測添加的課程是否重復(fù)
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 學(xué)生與課程 WHERE 課程名稱='" & Trim(Combo2.Text) & "'AND 課程號='" & Trim(Combo1.Text) & "' and 學(xué)號='" & 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 = "優(yōu)異" Then
match = True
Else
match = False
End If
End If
Exit Function
error:
MsgBox Err.descirption
End Function
Private Sub Label4_Click()
End Sub