📄 frmmodigrade.frm
字号:
_ExtentY = 582
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Stud97.mdb;Persist Security Info=False"
OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Stud97.mdb;Persist Security Info=False"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = ""
Caption = "adoEdit"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
Begin MSAdodcLib.Adodc adoNoName
Height = 330
Left = 2760
Top = 3480
Visible = 0 'False
Width = 1575
_ExtentX = 2778
_ExtentY = 582
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 8
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 1
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Stud97.mdb;Mode=Share Deny None;Persist Security Info=False"
OLEDBString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Stud97.mdb;Mode=Share Deny None;Persist Security Info=False"
OLEDBFile = ""
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = ""
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
End
Attribute VB_Name = "frmModiGrade"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'修改成绩窗体frmModiGrade
Option Explicit
Dim strGrade As String
'在“选择学生”数据网格中选择学生时,显示当前记录内容
Private Sub adoNoName_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
If adoNoName.Recordset.BOF Or adoNoName.Recordset.EOF Then
txtNo.Text = ""
txtName.Text = ""
txtGrade.Text = ""
Exit Sub
End If
'显示当前学号、姓名
txtNo.Text = adoNoName.Recordset("学号").Value
txtName.Text = adoNoName.Recordset("姓名").Value
'查询成绩表中当前学生的各科成绩
Dim sql As String
sql = "SELECT * FROM 成绩 WHERE 学号='" & txtNo.Text & "'"
adoEdit.RecordSource = sql
adoEdit.Refresh
'填充课程组合框
cboCourse.Clear
With adoEdit.Recordset
Do Until .EOF
cboCourse.AddItem .Fields("课程").Value
.MoveNext
Loop
End With
If cboCourse.ListCount > 0 Then
cboCourse.ListIndex = 0
Else
txtGrade.Text = ""
End If
End Sub
Private Sub cboClass_Click() '单击班级组合框
Dim sqlN As String
'DISTINCT 关键字过滤重复记录
sqlN = "SELECT DISTINCT 成绩.学号 AS 学号,姓名 " _
& " FROM 成绩,学籍 " _
& " WHERE 学籍.学号=成绩.学号 AND 班级 ='" _
& cboClass.Text & "' ORDER BY 成绩.学号"
'打开记录集
adoNoName.RecordSource = sqlN
adoNoName.Refresh
'设置数据网格控件
With dgdNoName
Set .DataSource = adoNoName
.Columns(0).Width = 1100
.Columns(1).Width = 1100
End With
End Sub
Private Sub cboCourse_Click() '单击课程组合框
If Trim$(txtNo.Text) = "" Or Trim$(cboCourse.Text) = "" Then
txtGrade.Text = ""
Exit Sub
Else
With adoEdit.Recordset '显示分数
If .RecordCount > 0 Then .MoveFirst
.Find "课程='" & cboCourse.Text & "'"
If .EOF Then Exit Sub
txtGrade.Text = .Fields("分数").Value
End With
End If
End Sub
Private Sub cmdCancel_Click() '取消
txtGrade.Text = strGrade
Call MyLock(True)
End Sub
Private Sub cmdDelete_Click() '删除
If Trim$(txtNo.Text) = "" Or Trim$(cboCourse.Text) = "" Then Exit Sub
Dim Response As Integer
Response = MsgBox("删除当前记录吗?", vbQuestion + vbYesNo, "询问")
If Response = vbYes Then
With adoEdit.Recordset
.Delete
.Update
'延时,以便完成数据库后台更新
Dim sngWait As Single
sngWait = Timer
Do Until Timer - sngWait > 1#
fraWait.Visible = True
DoEvents
Loop
fraWait.Visible = False
If .RecordCount = 0 Then
MsgBox "成绩表中已无该学生的成绩。", vbInformation, "提示"
Else
MsgBox "成绩删除成功。", vbInformation, "提示"
End If
adoNoName.Refresh
dgdNoName.Columns(0).Width = 1100
dgdNoName.Columns(1).Width = 1100
End With
End If
Call MyLock(True)
End Sub
Private Sub cmdEdit_Click() '修改
If Trim$(txtNo.Text) = "" Or Trim$(cboCourse.Text) = "" Then Exit Sub
strGrade = txtGrade.Text '暂存当前成绩
Call MyLock(False) '成绩框解锁
Call FocusBack(txtGrade) '焦点返回
End Sub
Private Sub cmdExit_Click() '退出
Unload Me
End Sub
Private Sub cmdUpdate_Click() '更新
'成绩框若为空白,提示重新输入
If Trim$(txtGrade.Text) = "" Then
MsgBox "请输入成绩!若无成绩,请将该记录删除。", vbExclamation, "提示"
Call cmdCancel_Click
txtGrade.SetFocus
Exit Sub
End If
'更新
With adoEdit.Recordset
.Fields("分数").Value = Val(txtGrade.Text)
.Update
End With
MsgBox "成绩修改成功。", vbInformation
Call MyLock(True) '锁定
End Sub
Private Sub Form_Load() '窗体加载
Call MyLock(True) '锁定相关控件
Call AddClassItem(cboClass) '填充班级组合框
fraWait.Top = 1200
fraWait.Left = 1600
dgdNoName.AllowUpdate = False
End Sub
Private Sub Form_Unload(Cancel As Integer) '窗体卸载时
frmMain.Show
End Sub
'自定义过程:锁定/解锁相关控件
Private Sub MyLock(ByVal bLock As Boolean)
txtGrade.Locked = bLock 'True=分数锁定
cboClass.Locked = Not bLock 'False=班级解锁
cboCourse.Locked = Not bLock 'False=课程解锁
cmdEdit.Enabled = bLock 'True=修改按钮有效
cmdCancel.Enabled = Not bLock 'False=取消按钮无效
cmdUpdate.Enabled = Not bLock 'False=更新按钮无效
dgdNoName.Enabled = bLock 'True
End Sub
Private Sub txtGrade_KeyPress(KeyAscii As Integer) '成绩框按键
'按键非数字或回删键,取消
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -