📄 frmregisters.frm
字号:
VERSION 5.00
Begin VB.Form frmRegisters
BorderStyle = 3 'Fixed Dialog
Caption = "注册用户信息管理"
ClientHeight = 4290
ClientLeft = 45
ClientTop = 330
ClientWidth = 6915
LinkTopic = "Form1"
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 4290
ScaleWidth = 6915
ShowInTaskbar = 0 'False
Begin VB.TextBox txtName
Height = 350
Left = 1853
MaxLength = 20
TabIndex = 17
Text = "Text1"
Top = 247
Width = 4095
End
Begin VB.TextBox txtPWD
Height = 350
Left = 1853
MaxLength = 10
TabIndex = 16
Text = "Text2"
Top = 712
Width = 4095
End
Begin VB.TextBox txtIdentity
Height = 350
Left = 1853
MaxLength = 18
TabIndex = 15
Text = "Text3"
Top = 1162
Width = 4095
End
Begin VB.TextBox txtEmail
Height = 350
Left = 1853
MaxLength = 50
TabIndex = 14
Text = "Text4"
Top = 1627
Width = 4095
End
Begin VB.TextBox txtPhone
Height = 350
Left = 1853
MaxLength = 11
TabIndex = 13
Text = "Text5"
Top = 2092
Width = 4095
End
Begin VB.TextBox txtPostCode
BeginProperty DataFormat
Type = 1
Format = "0"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 1
EndProperty
Height = 350
Left = 1853
MaxLength = 6
TabIndex = 12
Text = "Text6"
Top = 2542
Width = 4095
End
Begin VB.TextBox txtAddress
Height = 350
Left = 1853
MaxLength = 50
ScrollBars = 2 'Vertical
TabIndex = 11
Text = "Text7"
Top = 3007
Width = 4095
End
Begin VB.CommandButton cmdSeek
Caption = "查找"
Height = 300
Left = 3083
TabIndex = 10
Top = 3787
Width = 735
End
Begin VB.CommandButton cmdExit
Caption = "退出"
Height = 300
Left = 4583
TabIndex = 9
Top = 3787
Width = 735
End
Begin VB.CommandButton cmdDelete
Caption = "删除"
Height = 300
Left = 2333
TabIndex = 8
Top = 3787
Width = 735
End
Begin VB.CommandButton cmdAdd
Caption = "添加"
Height = 300
Left = 1583
TabIndex = 7
Top = 3787
Width = 735
End
Begin VB.PictureBox picNavigation
AutoSize = -1 'True
BorderStyle = 0 'None
Height = 345
Left = 2070
ScaleHeight = 345
ScaleWidth = 2760
TabIndex = 1
Top = 3399
Width = 2760
Begin VB.CommandButton cmdMove
Caption = "<"
Height = 300
Index = 1
Left = 375
TabIndex = 6
Top = 15
Width = 360
End
Begin VB.CommandButton cmdMove
Caption = "|<"
Height = 300
Index = 0
Left = 15
TabIndex = 5
Top = 15
Width = 360
End
Begin VB.CommandButton cmdMove
Caption = ">|"
Height = 300
Index = 3
Left = 2370
TabIndex = 4
Top = 15
Width = 360
End
Begin VB.CommandButton cmdMove
Caption = ">"
Height = 300
Index = 2
Left = 2010
TabIndex = 3
Top = 15
Width = 360
End
Begin VB.TextBox txtNews
Height = 300
Left = 720
Locked = -1 'True
TabIndex = 2
TabStop = 0 'False
Top = 15
Width = 1275
End
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 300
Left = 3833
TabIndex = 0
Top = 3787
Width = 735
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "姓名:"
Height = 180
Left = 1313
TabIndex = 24
Top = 337
Width = 540
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "口令:"
Height = 180
Left = 1313
TabIndex = 23
Top = 787
Width = 540
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "身份证:"
Height = 180
Left = 1133
TabIndex = 22
Top = 1252
Width = 720
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "Email:"
Height = 180
Left = 1223
TabIndex = 21
Top = 1717
Width = 630
End
Begin VB.Label Label5
AutoSize = -1 'True
Caption = "联系地址:"
Height = 180
Left = 953
TabIndex = 20
Top = 3097
Width = 900
End
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "联系电话:"
Height = 180
Left = 953
TabIndex = 19
Top = 2167
Width = 900
End
Begin VB.Label Label7
AutoSize = -1 'True
Caption = "邮政编码:"
Height = 180
Left = 953
TabIndex = 18
Top = 2632
Width = 900
End
End
Attribute VB_Name = "frmRegisters"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim isAdding As Boolean '定义操作状态标志
Dim objRegisters As Recordset '用于保存注册用户数据表记录
Dim objCn As Connection '用于建立数据库联接
Private Sub cmdExit_Click()
Unload Me '关闭注册用户管理窗体
End Sub
Private Sub cmdSeek_Click()
Dim strKey$
strKey = InputBox("请输入要查询的用户名称包含字符!", "查询注册用户")
If strKey = "" Then
MsgBox "输入无效!", vbInformation, "注册用户管理"
Else
With objRegisters
If .RecordCount > 0 Then
.MoveFirst
.Find "user_name like '*" & strKey & "*'"
If .EOF Then
MsgBox "无姓名包含 " & strKey & " 的注册用户记录!", _
vbInformation, "注册用户管理"
Else
ShowData '显示当前记录数据
End If
Else
MsgBox "无注册用户记录!", vbInformation, "注册用户管理"
End If
End With
End If
End Sub
Private Sub Form_Load()
'建立数据库联接
Set objCn = New Connection '实例化联接对象
With objCn '建立数据库联接
.Provider = "SQLOLEDB"
.ConnectionString = "User ID=sa;PWD=123;Data Source=(local);" & _
"Initial Catalog=图书销售"
.Open
End With
'获取注册用户记录
Set objRegisters = New Recordset '实例化objRegisters对象
With objRegisters
Set .ActiveConnection = objCn
.CursorLocation = adUseClient '指定使用客户端游标
.CursorType = adOpenStatic '指定使用静态游标
.LockType = adLockOptimistic
.Open "SELECT * FROM 注册用户" '获取注册用户登录信息
End With
'触发按钮单击事件,显示第一个记录
cmdMove(0).Value = True
End Sub
Private Sub cmdMove_Click(Index As Integer)
With objRegisters
Select Case Index '切换当前记录
Case 0 '使第一个记录成为当前记录
If .RecordCount > 0 And Not .BOF Then .MoveFirst
Case 1 '使上一个记录成为当前记录
If .RecordCount > 0 And Not .BOF Then
.MovePrevious
If .BOF Then .MoveFirst
End If
Case 2 '使下一个记录成为当前记录
If .RecordCount > 0 And Not .EOF Then
.MoveNext
If .EOF Then .MoveLast
End If
Case 3 '使最后一个记录成为当前记录
If .RecordCount > 0 And Not .EOF Then .MoveLast
End Select
ShowData
End With
If isAdding Then isAdding = False '改变当前记录则退出当前添加记录状态
End Sub
Private Sub cmdAdd_Click()
txtNews = "添加新记录"
txtName = ""
txtPWD = ""
txtIdentity = ""
txtEmail = ""
txtPhone = ""
txtAddress = ""
txtPostCode = ""
isAdding = True
End Sub
Private Sub cmdDelete_Click()
'根据是否处于添加记录状态执行不同的操作
If isAdding Then
'退出添加记录状态,显示当前记录
isAdding = False
ShowData '显示当前记录数据
Else
If objRegisters.RecordCount > 0 Then
If MsgBox("是否删除当前记录?", vbYesNo + vbQuestion, _
"注册用户管理") = vbYes Then
objRegisters.Delete '执行删除当前记录操作
cmdMove(2).Value = True '显示下一记录数据
Else
ShowData
End If
End If
End If
End Sub
Private Sub cmdSave_Click()
Dim objCopy As New Recordset, Pwd2$
If Trim(txtName) = "" Then
MsgBox "用户名不能为空!", vbCritical, "注册用户管理"
txtName.SetFocus
txtName = ""
ElseIf Trim(txtPWD) = "" Then
MsgBox "口令不能为空!", vbCritical, "注册用户管理"
txtPWD.SetFocus
txtPWD = ""
ElseIf Len(Trim(txtIdentity)) <> 15 And Len(Trim(txtIdentity)) <> 18 Then
MsgBox "身份证号错误!", vbCritical, "注册用户管理"
txtIdentity.SetFocus
txtIdentity = ""
ElseIf InStr(txtEmail, "@") = 0 Then
MsgBox "Email地址无效!", vbCritical, "注册用户管理"
txtEmail.SetFocus
ElseIf Not IsNumeric(Trim(txtPhone)) And Len(Trim(txtPhone)) < 7 Then
MsgBox "联系电话无效,至少7为数字!", vbCritical, "注册用户管理"
txtPhone.SetFocus
ElseIf Not IsNumeric(Trim(txtPostCode)) And Len(Trim(txtPhone)) <> 6 Then
MsgBox "邮政编号无效(6位数字)!", vbCritical, "注册用户管理"
txtPostCode.SetFocus
ElseIf Trim(txtAddress) = "" Then
MsgBox "联系地址不能为空!", vbCritical, "注册用户管理"
txtAddress.SetFocus
txtAddress = ""
Else
With objRegisters
'保存或添加记录
If isAdding Then .AddNew
.Fields!user_name = Trim(txtName)
.Fields!user_pwd = Trim(txtPWD)
.Fields!user_identity = Trim(txtIdentity)
.Fields!user_email = Trim(txtemal)
.Fields!user_phone = Trim(txtPhone)
.Fields!user_address = Trim(txtAddress)
.Fields!user_postCode = Trim(txtPostCode)
.Update
MsgBox "数据保存成功!", vbInformation, "注册用户管理"
isAdding = False
'显示当前记录编号和记录总数
txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount
End With
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
objCn.Close '关闭数据联接
Set objCn = Nothing '释放数据库联接
Set objRegisters = Nothing '释放记录集对象
End Sub
Private Sub ShowData()
On Error Resume Next
Dim objStm As New Stream
With objRegisters
If .RecordCount < 1 Then
txtNews = "记录:无" '显示无记录提示
txtName = ""
txtPWD = ""
txtIdentity = ""
txtEmail = ""
txtPhone = ""
txtAddress = ""
txtPostCode = ""
Else
'显示当前记录数据
txtName = .Fields!user_name
txtPWD = .Fields!user_pwd
txtIdentity = .Fields!user_identity
txtEmail = .Fields!user_email
txtPhone = .Fields!user_phone
txtAddress = .Fields!user_address
txtPostCode = .Fields!user_postCode
'显示当前记录编号和记录总数
txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount
End If
End With
Set objStm = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -