添加用户
添加用户的时候跟之前注册的信息差不多,开始还是先判断各个文本框是否为空----核对密码是否一致----判断数据库里是否有此ID
代码展示
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
删除用户
代码
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
更新用户
更新是指再删除或者添加之后,点击更新按钮会使表格显示删除或添加的东西
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