📄 frmadduser.frm
字号:
VERSION 5.00
Begin VB.Form frmAddUser
BorderStyle = 1 'Fixed Single
Caption = "新用户注册"
ClientHeight = 4545
ClientLeft = 45
ClientTop = 330
ClientWidth = 5175
LinkTopic = "Form1"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 4545
ScaleWidth = 5175
Begin VB.CommandButton Command2
Caption = "取 消"
Height = 495
Left = 3000
TabIndex = 14
Top = 3720
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "注 册"
Height = 495
Left = 1080
TabIndex = 13
Top = 3720
Width = 1215
End
Begin VB.Frame Frame1
Height = 3255
Left = 120
TabIndex = 0
Top = 120
Width = 4575
Begin VB.TextBox txtTime
Enabled = 0 'False
Height = 375
Left = 1920
TabIndex = 12
Top = 2640
Width = 1695
End
Begin VB.ComboBox cmbType
Height = 315
ItemData = "frmAddUser.frx":0000
Left = 1920
List = "frmAddUser.frx":000A
Style = 2 'Dropdown List
TabIndex = 10
Top = 2280
Width = 1695
End
Begin VB.TextBox txtTrueName
Height = 375
Left = 1920
TabIndex = 8
Top = 1800
Width = 1695
End
Begin VB.TextBox txtPwd2
Height = 375
IMEMode = 3 'DISABLE
Left = 1920
PasswordChar = "*"
TabIndex = 6
Top = 1320
Width = 1695
End
Begin VB.TextBox txtPwd
Height = 375
IMEMode = 3 'DISABLE
Left = 1920
PasswordChar = "*"
TabIndex = 4
Top = 840
Width = 1695
End
Begin VB.TextBox txtUser
Height = 375
Left = 1920
TabIndex = 2
Top = 360
Width = 1695
End
Begin VB.Label Label6
Caption = "注册时间:"
Height = 255
Left = 840
TabIndex = 11
Top = 2760
Width = 1095
End
Begin VB.Label Label5
Caption = "用户类型:"
Height = 255
Left = 840
TabIndex = 9
Top = 2400
Width = 975
End
Begin VB.Label Label4
Caption = "真是姓名:"
Height = 255
Left = 840
TabIndex = 7
Top = 1920
Width = 1095
End
Begin VB.Label Label3
Caption = "确认密码:"
Height = 255
Left = 840
TabIndex = 5
Top = 1440
Width = 975
End
Begin VB.Label Label2
Caption = "密 码:"
Height = 375
Left = 840
TabIndex = 3
Top = 960
Width = 975
End
Begin VB.Label Label1
Caption = "用 户 名:"
Height = 375
Left = 840
TabIndex = 1
Top = 480
Width = 975
End
End
End
Attribute VB_Name = "frmAddUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
'先检查用户是否输入了必要的各项值
If txtUser.Text = "" Then
MsgBox "请输入用户名!", vbOKOnly + vbInformation, "注意"
txtUser.SetFocus
Exit Sub
ElseIf txtPwd.Text = "" Then
MsgBox "请输入密码!", vbOKOnly + vbInformation, "注意"
txtPwd.SetFocus
Exit Sub
ElseIf txtPwd2.Text = "" Then
MsgBox "请再次输入密码!", vbOKOnly + vbInformation, "注意"
txtPwd2.SetFocus
Exit Sub
ElseIf txtTrueName.Text = "" Then
MsgBox "请输入您的真实姓名!", vbOKOnly + vbInformation, "注意"
txtTrueName.SetFocus
Exit Sub
ElseIf cmbType.Text = "" Then
MsgBox "请选择用户类型!", vbOKOnly + vbInformation, "注意"
cmbType.SetFocus
Exit Sub
End If
'判断两次输入的密码是否相同
If txtPwd.Text <> txtPwd2.Text Then
MsgBox "两次输入的密码不同,请重新输入密码!", vbOKOnly + vbInformation, "注意"
txtPwd.Text = ""
txtPwd2.Text = ""
txtPwd.SetFocus
Exit Sub
End If
Dim rs_check As New ADODB.Recordset
Dim rs_add As New ADODB.Recordset
Dim strsql As String
strsql = "select * from 用户表 where 用户名 = '" & txtUser.Text & "'"
rs_check.Open strsql, conn, adOpenKeyset, adLockPessimistic
'判断是否已存在此用户名
If rs_check.EOF = False Then
MsgBox "此用户名已存在,请选择其他用户名!", vbOKOnly + vbInformation, "注意"
txtUser.Text = ""
txtUser.SetFocus
rs_check.Close
Exit Sub
End If
'添加新用户信息入用户表
Dim sqladd As String
sqladd = "select * from 用户表"
rs_add.Open sqladd, conn, adOpenKeyset, adLockPessimistic
rs_add.AddNew
rs_add.Fields(0) = txtUser.Text
rs_add.Fields(1) = txtPwd.Text
rs_add.Fields(2) = txtTrueName.Text
rs_add.Fields(3) = cmbType.Text
rs_add.Fields(4) = Val(txtTime.Text)
rs_add.Update
MsgBox "注册成功!祝贺你!", vbOKOnly + vbInformation, "注意"
rs_check.Close
rs_add.Close
Unload Me
End Sub
Private Sub Command2_Click()
txtUser.Text = ""
txtPwd.Text = ""
txtPwd2.Text = ""
txtTrueName.Text = ""
End Sub
Private Sub Form_Load()
Dim X0 As Long
Dim Y0 As Long
'让窗体居中
X0 = Screen.Width
Y0 = Screen.Height
X0 = (X0 - Me.Width) / 2
Y0 = (Y0 - Me.Height) / 2
Me.Move X0, Y0
cmbType.ListIndex = 0 '设置ComboBox的list初始值为listindex=0的值
txtTime.Text = Str(Date)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -