Add user
When adding a user, it is similar to the information registered before. At the beginning, it is necessary to determine whether each text box is empty-check whether the password is consistent-determine whether there is this ID in the database
Code display
Private Sub cmdOK_Click()
Dim user As ADODB.Recordset
Dim txtSQL As String
Dim Msgtext As String
If txtUserName.Text = "" Then
MsgBox "?用户名不能为空", vbOKOnly + vbExclamation, "提示"
txtUserName.SetFocus
Exit Sub
Else
If Combo1.Text = "" Then
MsgBox "请选择用户级别", vbOKOnly + vbExclamation, "提示"
Exit Sub
Else
If txtName.Text = "" Then
MsgBox "姓名不能为空", vbOKOnly + vbExclamation, "提示"
txtName.SetFocus
Exit Sub
End If
End If
End If
If PassWord.Text = "" Then
MsgBox "请填写密码", vbOKOnly + vbExclamation, "提示"
PassWord.SetFocus
Exit Sub
Else
If password1.Text = "" Then
MsgBox "确认密码不能为空", vbOKOnly + vbExclamation, "提示"
password1.SetFocus
Exit Sub
Else
If PassWord.Text <> password1.Text Then
MsgBox "密码和确认密码不一致", vbOKOnly + vbExclamation, "提示"
End If
End If
End If
txtSQL = "select * from User_info"
Set user = ExecuteSQL(txtSQL, Msgtext)
If user.EOF = True Then
MsgBox "已有此用户名,请重新输入"
Else
user.AddNew
user.Fields(0) = Trim(txtUserName.Text)
user.Fields(1) = Trim(PassWord.Text)
user.Fields(2) = Trim(Combo1.Text)
user.Fields(3) = Trim(txtName.Text)
user.Fields(4) = UserName
MsgBox "添加成功", vbOKOnly + vbExclamation, "提示"
user.Update
user.Close
End If
End Sub
delete users
Code
Private Sub cmdDelete_Click()
Dim txtSQL As String
Dim Msgtext As String
Dim mrc As ADODB.Recordset
If MSHFlexGrid1.RowSel = 0 Then '选择的行数
MsgBox "请选择数据", vbOKOnly + vbExclamation, "提示"
Exit Sub
Else
'判断用户是否正在登录
a = MSHFlexGrid1.RowSel
If Trim(MSHFlexGrid1.TextMatrix(a, 0)) = UserName Then
MsgBox "该用户正在登录,不能删除", vbOKOnly + vbExclamation, "提示"
Exit Sub
Else
b = MsgBox("确定要删除该用户吗", vbYesNo, "提示")
If b = 6 Then
MSHFlexGrid1.RemoveItem a + 1
Else
Exit Sub
End If
txtSQL = "delete from User_info where userID='" & MSHFlexGrid1.TextMatrix(a, 0) & "'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
MsgBox "删除成功", vbOKOnly + vbExclamation, "提示"
End If
End If
End Sub
Update user
Update means that after deleting or adding, clicking the update button will make the table display the deleted or added things
Private Sub cmdUpdate_Click()
Dim txtSQL As String
Dim Msgtext As String
Dim user As ADODB.Recordset
txtSQL = "select * from User_info where Level='" & Combo1.Text & "'"
Set user = ExecuteSQL(txtSQL, Msgtext)
If Combo1.Text = "" Then
MsgBox "请选择用户类型!", vbOKOnly + vbExclamation, "提示"
Exit Sub
End If
If user.EOF Then
MsgBox "没有数据", vbOKOnly + vbExclamation, "提示"
Else
With MSHFlexGrid1
.CellAlignment = 4
.Rows = 1
.TextMatrix(0, 0) = "?????"
.TextMatrix(0, 1) = "????"
.TextMatrix(0, 2) = "??????"
Do While Not user.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = user.Fields(0)
.TextMatrix(.Rows - 1, 1) = user.Fields(3)
.TextMatrix(.Rows - 1, 2) = user.Fields(4)
user.MoveNext
Loop
End With
End If
End Sub