📄 frmreadermanager.frm
字号:
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "性别:"
Height = 180
Left = 360
TabIndex = 29
Top = 1575
Width = 450
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "身份证号码:"
Height = 180
Left = 360
TabIndex = 28
Top = 2745
Width = 990
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "读者类别:"
Height = 180
Left = 4440
TabIndex = 27
Top = 405
Width = 810
End
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "联系电话:"
Height = 180
Left = 4440
TabIndex = 26
Top = 990
Width = 810
End
Begin VB.Label Label7
AutoSize = -1 'True
Caption = "住址:"
Height = 180
Left = 4440
TabIndex = 25
Top = 1575
Width = 450
End
Begin VB.Label Label8
AutoSize = -1 'True
Caption = "单位部门:"
Height = 180
Left = 4440
TabIndex = 24
Top = 2160
Width = 810
End
Begin VB.Label Label9
AutoSize = -1 'True
Caption = "登记日期:"
Height = 180
Left = 4440
TabIndex = 23
Top = 2745
Width = 810
End
Begin VB.Label Label10
AutoSize = -1 'True
Caption = "备注:"
Height = 180
Left = 8640
TabIndex = 22
Top = 960
Width = 450
End
Begin VB.Label Label11
AutoSize = -1 'True
Caption = "借书次数:"
Height = 180
Left = 8280
TabIndex = 21
Top = 405
Width = 810
End
Begin VB.Line Line1
X1 = 12480
X2 = 12480
Y1 = 240
Y2 = 3120
End
End
End
End
Attribute VB_Name = "frmReaderManager"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim intIndex As Long '某类别的读者总数递增号
Private Sub cmdAddNew_Click()
'On Error GoTo AddErr
If ReaderState <> 1 Then cmdEdit.Enabled = Not cmdEdit.Enabled
cmdDelete.Enabled = Not cmdDelete.Enabled
cmdUpdate.Enabled = Not cmdUpdate.Enabled
cmdRefresh.Enabled = Not cmdRefresh.Enabled
If Left(cmdAddNew.Caption, 2) = "新增" Then
cmdAddNew.Caption = "确认(&O)"
cmdClose.Caption = "放弃(&C)"
cmdGenerate.Enabled = True
DBcomReaderSort.Enabled = True
'Data1.Recordset.MoveLast
Data1.Recordset.AddNew
txtName.SetFocus
Else
'输入数据有效性验证
DTRegisterDate.Value = FormatDateTime(Now, vbShortDate)
cmdAddNew.Caption = "新增(&A)"
cmdClose.Caption = "关闭(&C)"
cmdGenerate.Enabled = False
DBcomReaderSort.Enabled = False
If comSex.Text = "" Then
MsgBox "性别为空!"
Exit Sub
End If
'更新数据控件
Data1.Recordset.Update
Data1.Recordset.MoveLast
End If
Exit Sub
AddErr:
MsgBox Err.Description
End Sub
Private Sub cmdClose_Click()
On Error GoTo CloseErr
If Left(cmdClose.Caption, 2) = "放弃" Then
cmdClose.Caption = "关闭(&C)"
cmdGenerate.Enabled = False
DBcomReaderSort.Enabled = False
If ReaderState <> 2 Then
cmdAddNew.Caption = "新增(&A)"
cmdAddNew.Enabled = True
End If
If ReaderState <> 1 Then
cmdEdit.Caption = "修改(&E)"
cmdEdit.Enabled = True
End If
cmdDelete.Enabled = True
cmdUpdate.Enabled = True
cmdRefresh.Enabled = True
Data1.UpdateControls
If Not (Data1.Recordset.BOF And Data1.Recordset.EOF) Then Data1.Recordset.MoveLast '记录不为空,则移到最后
Else
Unload Me
End If
Exit Sub
CloseErr:
MsgBox Err.Description
End Sub
Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
With Data1.Recordset
.Delete
.MoveNext
If .EOF Then .MoveLast
End With
Exit Sub
DeleteErr:
MsgBox Err.Description
End Sub
Private Sub cmdEdit_Click()
On Error GoTo EditErr
If ReaderState <> 2 Then cmdAddNew.Enabled = Not cmdAddNew.Enabled
cmdDelete.Enabled = Not cmdDelete.Enabled
cmdUpdate.Enabled = Not cmdUpdate.Enabled
cmdRefresh.Enabled = Not cmdRefresh.Enabled
If Left(cmdEdit.Caption, 2) = "修改" Then
cmdEdit.Caption = "确认(&O)"
cmdClose.Caption = "放弃(&C)"
Data1.Recordset.Edit
txtName.SetFocus
Else
cmdEdit.Caption = "修改(&E)"
cmdClose.Caption = "关闭(&C)"
'更新数据控件
Data1.Recordset.Update
End If
Exit Sub
EditErr:
MsgBox Err.Description
End Sub
Private Sub cmdFirst_Click()
If Not Data1.Recordset.BOF Then Data1.Recordset.MoveFirst
End Sub
Private Sub cmdGenerate_Click()
On Error GoTo GeneErr
Dim ws As Workspace, db As Database, rs As Recordset
Dim strAppName As String, strSQL As String
strAppName = App.Path & "\读者库.mdb"
Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase(strAppName, False, True)
'找到该类别的类别简称号
Dim strReaderSort As String, strReaderShort As String
strReaderSort = DBcomReaderSort.Text
If strReaderSort = "" Or Asc(strReaderSort) = 32 Then
db.Close
'ws.Close
Set db = Nothing
'Set ws = Nothing
GoTo GeneErr
End If
strSQL = "select 类别简称 from 读者类别表 where 读者类别='" & strReaderSort & "'"
Set rs = db.OpenRecordset(strSQL)
strReaderShort = rs.Fields("类别简称")
rs.Close
Set rs = Nothing
'找到该类别的读者总数,并将新增的读者总数+1
Dim intCount As Long, strIndex As String
strSQL = "select 读者编号 from 读者表 where 读者类别='" & strReaderSort & "'"
Set rs = db.OpenRecordset(strSQL)
If rs.RecordCount = 0 Then
intCount = 0
Else
rs.MoveLast
' strIndex = Trim(rs.Fields("读者编号"))
' intCount = DivideReaderIndex(strIndex)
intCount = rs.RecordCount
End If
intIndex = intCount: intIndex = intIndex + 1
'生成读者编号
txtNo.Text = strReaderShort & ReaderIndex(intIndex)
rs.Close
db.Close
'ws.Close
Set rs = Nothing
Set db = Nothing
'Set ws = Nothing
'总结:由于用对象变量DAO打开数据库和用Data控件打开数据库用的是同一工作区,所以不能关闭工作区。
DBcomReaderSort.Enabled = False
cmdGenerate.Enabled = False
Exit Sub
GeneErr:
MsgBox Err.Description
End Sub
Private Sub cmdLast_Click()
If Not Data1.Recordset.EOF Then Data1.Recordset.MoveLast
End Sub
Private Sub cmdNext_Click()
If Data1.Recordset.BOF And Data1.Recordset.EOF Then Exit Sub '如果记录为空,则退出
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then Data1.Recordset.MoveLast
End Sub
Private Sub cmdPrevious_Click()
If Data1.Recordset.BOF And Data1.Recordset.EOF Then Exit Sub '如果记录为空,则退出
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then Data1.Recordset.MoveFirst
End Sub
Private Sub cmdRefresh_Click()
'只有多用户应用程序需要
On Error GoTo RefreshErr
Data1.Refresh
Exit Sub
RefreshErr:
MsgBox Err.Description
End Sub
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
Data1.UpdateRecord
Exit Sub
UpdateErr:
MsgBox Err.Description
End Sub
Private Sub Data1_Reposition()
Data1.Caption = "读者记录:" & Data1.Recordset.AbsolutePosition + 1
End Sub
Private Sub Form_Activate()
txtName.SetFocus
End Sub
Private Sub Form_Load()
OFFCAT.Play "wave"
If ReaderState = 0 Then
Me.Caption = "读者管理"
SSTab1.Caption = "读者管理"
ElseIf ReaderState = 1 Then
Me.Caption = "新增读者"
SSTab1.Caption = "新增读者"
cmdEdit.Enabled = False
ElseIf ReaderState = 2 Then
Me.Caption = "读者资料修改"
SSTab1.Caption = "读者资料修改"
cmdAddNew.Enabled = False
End If
'添加组合框数据
comSex.AddItem "男"
comSex.AddItem "女"
'打开读者库
Dim strAppName As String, strSQL As String
strAppName = App.Path & "\读者库.mdb"
strSQL = "select * from 读者表"
Data1.DatabaseName = strAppName
Data1.RecordSource = strSQL
strSQL = "select * from 读者类别表"
Data2.DatabaseName = strAppName
Data2.RecordSource = strSQL
strSQL = "select * from 部门表"
Data3.DatabaseName = strAppName
Data3.RecordSource = strSQL
'给字段赋属性值
txtNo.DataField = "读者编号": txtName.DataField = "读者姓名": comSex.DataField = "性别"
txtAge.DataField = "年龄": txtIdentityNo.DataField = "身份证号码": txtPhone.DataField = "联系电话"
txtAddress.DataField = "住址": txtBorrowCount.DataField = "借书次数": txtRemark.DataField = "备注"
DBcomReaderSort.DataField = "读者类别": DBcomReaderSort.BoundColumn = "读者类别": DBcomReaderSort.ListField = "读者类别"
DBcomDepartment.DataField = "单位部门": DBcomDepartment.BoundColumn = "部门": DBcomDepartment.ListField = "部门"
DTRegisterDate.DataField = "登记日期"
End Sub
Private Sub Form_Resize()
SSTab1.Left = (Me.Width - SSTab1.Width) / 2
Frame1.Left = (SSTab1.Width - Frame1.Width) / 2
End Sub
Private Function ReaderIndex(Index As Long) As String '将数字变为6位数的字符串
Dim i, count As Integer
ReaderIndex = Trim(Str(Index))
count = Len(ReaderIndex)
For i = 1 To 6 - count
ReaderIndex = "0" & ReaderIndex
Next i
End Function
Private Function DivideReaderIndex(strIndex As String) As Long '将读者编号分解为数字
Dim strNo As String
strNo = Mid(strIndex, 3)
DivideReaderIndex = Val(strNo)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -