📄 frmmodiess.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form frmModiEss
BorderStyle = 1 'Fixed Single
Caption = "修改学籍信息"
ClientHeight = 3255
ClientLeft = 3210
ClientTop = 3195
ClientWidth = 5865
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3255
ScaleWidth = 5865
Begin MSAdodcLib.Adodc adoGrade
Height = 375
Left = 3600
Top = 2880
Visible = 0 'False
Width = 1335
_ExtentX = 2355
_ExtentY = 661
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 = "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
Begin VB.Frame Frame1
Appearance = 0 'Flat
Caption = "修改记录"
ForeColor = &H80000008&
Height = 2295
Left = 90
TabIndex = 12
Top = 120
Width = 3135
Begin VB.ComboBox cboSex
DataField = "性别"
DataSource = "adoEdit"
Height = 300
ItemData = "frmModiEss.frx":0000
Left = 1080
List = "frmModiEss.frx":000A
TabIndex = 2
Top = 1020
Width = 1815
End
Begin VB.TextBox txtBorn
DataField = "出生日期"
BeginProperty DataFormat
Type = 1
Format = "yyyy-M-d"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 3
EndProperty
DataSource = "adoEdit"
Height = 264
Left = 1080
TabIndex = 3
Top = 1410
Width = 1815
End
Begin VB.TextBox txtName
DataField = "姓名"
DataSource = "adoEdit"
Height = 264
Left = 1080
TabIndex = 1
Top = 660
Width = 1815
End
Begin VB.TextBox txtSID
DataField = "学号"
DataSource = "adoEdit"
Height = 264
Left = 1080
TabIndex = 0
Top = 300
Width = 1815
End
Begin VB.ComboBox cboClass
DataField = "班级"
DataSource = "adoEdit"
Height = 300
Left = 1080
TabIndex = 4
Top = 1770
Width = 1815
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "出生日期"
Height = 180
Left = 240
TabIndex = 17
Top = 1452
Width = 720
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "性 别"
Height = 180
Left = 240
TabIndex = 16
Top = 1080
Width = 750
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "姓 名"
Height = 180
Left = 240
TabIndex = 15
Top = 705
Width = 750
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "学 号"
Height = 180
Left = 240
TabIndex = 14
Top = 342
Width = 750
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "班 级"
Height = 180
Left = 240
TabIndex = 13
Top = 1830
Width = 720
End
End
Begin VB.Frame Frame3
Appearance = 0 'Flat
Caption = "选择班级"
ForeColor = &H80000008&
Height = 2295
Left = 3360
TabIndex = 10
Top = 120
Width = 2385
Begin VB.ComboBox cboSelClass
Height = 1800
Left = 225
Style = 1 'Simple Combo
TabIndex = 11
Top = 300
Width = 1935
End
End
Begin VB.CommandButton cmdExit
Caption = "退出"
Height = 312
Left = 4695
TabIndex = 9
Top = 2580
Width = 1095
End
Begin VB.CommandButton cmdDelect
Caption = "删除记录"
Height = 312
Left = 3540
TabIndex = 8
Top = 2580
Width = 1095
End
Begin VB.CommandButton cmdCancel
Caption = "取消修改"
Height = 312
Left = 2385
TabIndex = 7
Top = 2580
Width = 1095
End
Begin VB.CommandButton cmdUpdate
Caption = "更新数据"
Height = 312
Left = 1230
TabIndex = 6
Top = 2580
Width = 1095
End
Begin VB.CommandButton cmdEdit
Caption = "修改记录"
Height = 312
Left = 75
TabIndex = 5
Top = 2580
Width = 1095
End
Begin MSAdodcLib.Adodc adoEdit
Align = 2 'Align Bottom
Height = 375
Left = 0
Top = 2880
Width = 5865
_ExtentX = 10345
_ExtentY = 661
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 = "select 学号,姓名,性别,出生日期,班级 from 学籍 Order by 学号"
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 = "frmModiEss"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'修改学籍信息窗体frmModiEss
Option Explicit
Dim sNo As String '存学号
Private Sub adoEdit_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, _
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, _
ByVal pRecordset As ADODB.Recordset)
'移动记录指针时显示当前记录位置/总记录数
adoEdit.Caption = "Record: " & _
CStr(adoEdit.Recordset.AbsolutePosition) & _
"/" & adoEdit.Recordset.RecordCount
End Sub
'若班级组合框处于允许编辑状态,失去焦点时检查列表,添加新项
Private Sub cboClass_Click()
If cboClass.Locked = True Then Exit Sub
Call NewClassItem(cboClass)
End Sub
Private Sub cboSelClass_Click() '单击选择班级组合框
Dim sqlN As String
Dim strClass As String
strClass = cboSelClass.Text '获取班级名称
If strClass = "全部" Then strClass = "%" '利用通配符%可包括全体学生
sqlN = "SELECT * FROM 学籍 WHERE 班级 like '" _
& strClass & "' ORDER BY 学号"
'根据所选班级重新打开记录集
adoEdit.RecordSource = sqlN
adoEdit.Refresh
End Sub
Private Sub cmdCancel_Click() '取消
With adoEdit.Recordset
.CancelUpdate '取消更新
.MoveNext
.MovePrevious
End With
Call MyLock(True)
End Sub
Private Sub cmdDelect_Click() '删除
Dim Response As Integer
Response = MsgBox("删除当前记录吗?", vbQuestion + vbYesNo, "询问")
If Response = vbYes Then
With adoEdit.Recordset
.Delete
.MoveNext
If .EOF And .RecordCount > 0 Then .MoveLast
End With
'删除成绩表中的相应记录
Dim sqlG As String
sqlG = "SELECT * FROM 成绩 WHERE 学号='" & Trim$(txtSID.Text) & "'"
adoGrade.RecordSource = sqlG
adoGrade.Refresh
With adoGrade.Recordset
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
.Delete
.MoveNext
Loop
End If
End With
MsgBox "删除成功。", vbInformation, "提示"
End If
End Sub
Private Sub cmdEdit_Click() '修改
sNo = Trim$(txtSID.Text)
Call MyLock(False) '用于输入信息的控件解锁
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdUpdate_Click() '更新
On Error Resume Next
'各输入框若为空白,提示重新输入
If Trim(txtSID.Text) = "" Then
MsgBox "请输入学号!", vbExclamation
txtSID.SetFocus
Exit Sub
End If
If Trim(txtName.Text) = "" Then
MsgBox "请输入姓名!", vbExclamation
txtName.SetFocus
Exit Sub
End If
If Trim(txtBorn.Text) = "" Then
MsgBox "请输入出生日期!", vbExclamation
txtBorn.SetFocus
Exit Sub
End If
If Trim$(cboClass.Text) = "" Then
MsgBox "请选择或输入班级!", vbExclamation
cboClass.SetFocus
Exit Sub
End If
If Not IsDate(txtBorn.Text) Then '出生日期若非日期型,重新输入
MsgBox "出生日期应按日期格式(yyyy-mm-dd)输入!", vbExclamation
With txtBorn
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Else '若日期格式正确
txtBorn.Text = Format(txtBorn.Text, "yyyy-mm-dd") '转换为4位年份
adoEdit.Recordset.Update '更新数据库
If Err = -2147467259 Then '该错误号为主键重复错误
adoEdit.Recordset.CancelUpdate
MsgBox "学号重复,请重新输入!", vbExclamation
Call FocusBack(txtSID) '焦点返回学号框
Exit Sub
End If
'若修改了学号,成绩表中需作相应修改
If Trim$(txtSID.Text) <> sNo Then
Dim sqlG As String
sqlG = "SELECT * FROM 成绩 WHERE 学号='" & sNo & "'"
adoGrade.RecordSource = sqlG
adoGrade.Refresh
With adoGrade.Recordset
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
.Fields("学号") = Trim$(txtSID.Text)
.MoveNext
Loop
End If
End With
End If
MsgBox "学籍信息已成功修改!", vbInformation
Call MyLock(True) '锁定
End If
End Sub
Private Sub Form_Initialize()
ChDrive App.Path
ChDir App.Path
End Sub
Private Sub Form_Load() '窗体加载
Call MyLock(True) '锁定相关控件
Call AddClassItem(cboClass) '填充班级组合框
Call AddClassItem(cboSelClass) '填充选择班级组合框
cboSelClass.AddItem "全部"
cboSelClass.ListIndex = cboSelClass.NewIndex
End Sub
Private Sub Form_Unload(Cancel As Integer) '窗体卸载时
frmMain.Show
End Sub
'自定义过程:锁定/解锁用于输入的控件
Private Sub MyLock(ByVal bLock As Boolean)
txtSID.Locked = bLock 'True
txtName.Locked = bLock 'True
txtBorn.Locked = bLock 'True
cboSex.Locked = bLock 'True
cboClass.Locked = bLock 'True
cboSelClass.Locked = Not bLock 'False
cmdEdit.Enabled = bLock 'True
cmdCancel.Enabled = Not bLock 'False
cmdUpdate.Enabled = Not bLock 'False
cmdDelect.Enabled = bLock 'True
adoEdit.Enabled = bLock 'True
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -