📄 frmadduser.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form frmAddUser
BorderStyle = 1 'Fixed Single
Caption = "添加用户"
ClientHeight = 4410
ClientLeft = 45
ClientTop = 330
ClientWidth = 5475
LinkTopic = "Form2"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 4410
ScaleWidth = 5475
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 1320
Top = 0
Visible = 0 'False
Width = 1455
_ExtentX = 2566
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 3
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "DSN=XiaoQu"
OLEDBString = ""
OLEDBFile = ""
DataSourceName = "XiaoQu"
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = "UserTable"
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
Height = 3135
Left = 480
TabIndex = 6
Top = 240
Width = 4575
Begin VB.TextBox txtUser
DataField = "Username"
DataSource = "Adodc1"
Height = 375
Left = 1920
TabIndex = 0
Top = 360
Width = 2145
End
Begin VB.TextBox txtPwd
DataField = "Password"
DataSource = "Adodc1"
Height = 375
IMEMode = 3 'DISABLE
Left = 1920
PasswordChar = "*"
TabIndex = 1
Top = 840
Width = 2145
End
Begin VB.TextBox txtPwd2
DataField = "Password"
DataSource = "Adodc1"
Height = 375
IMEMode = 3 'DISABLE
Left = 1920
PasswordChar = "*"
TabIndex = 2
Top = 1320
Width = 2145
End
Begin VB.TextBox txtTrueName
DataField = "Truename"
DataSource = "Adodc1"
Height = 375
Left = 1920
TabIndex = 3
Top = 1800
Width = 2145
End
Begin VB.TextBox txtTime
DataField = "Regtime"
DataSource = "Adodc1"
Enabled = 0 'False
Height = 375
Left = 1920
TabIndex = 4
Top = 2400
Width = 2145
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "用 户 名:"
Height = 180
Left = 525
TabIndex = 12
Top = 480
Width = 900
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "密 码:"
Height = 180
Left = 525
TabIndex = 11
Top = 960
Width = 900
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "确认密码:"
Height = 180
Left = 525
TabIndex = 10
Top = 1440
Width = 900
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "真实姓名:"
Height = 180
Left = 525
TabIndex = 9
Top = 1920
Width = 900
End
Begin VB.Label Label6
AutoSize = -1 'True
Caption = "注册时间:"
Height = 180
Left = 525
TabIndex = 8
Top = 2520
Width = 900
End
End
Begin VB.CommandButton Command1
Caption = "注 册"
Height = 435
Left = 960
TabIndex = 5
Top = 3720
Width = 1530
End
Begin VB.CommandButton Command2
Caption = "关 闭"
Height = 435
Left = 3000
TabIndex = 7
Top = 3720
Width = 1530
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
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 UserTable where Username = '" & 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 UserTable"
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) = Val(txtTime.Text)
rs_add.Update
MsgBox "注册成功!祝贺你!", vbOKOnly + vbInformation, "注意"
rs_check.Close
rs_add.Close
Unload Me
End Sub
Private Sub Command2_Click()
Unload Me
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
'txtTime文本框中显示当前日期
txtTime.Text = Str(Date)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -