⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classuser.cls

📁 关于工业设备型号数量库存价格等信息的管理系统的课程设计
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ClassUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'用户管理类

Option Explicit

Private m_UID As Long
Private m_UserName As String
Private m_Password As String
Private m_Level As Integer

Private m_isDirty As Boolean


Private Sub Class_Initialize()

    m_isDirty = False
    
End Sub

Public Property Get isDirty() As Boolean

    isDirty = m_isDirty
    
End Property

Public Property Get uid() As Long

    uid = m_UID
    
End Property

Public Property Get UserName() As String

    UserName = m_UserName
    
End Property

Public Property Let UserName(value As String)

    m_UserName = value
    
    m_isDirty = True
    
End Property

Public Property Get Password() As String

    Password = m_Password
    
End Property

Public Property Let Password(value As String)

    m_Password = value
    
    m_isDirty = True
    
End Property

Public Property Get Level() As Integer

    Level = m_Level
    
End Property

Public Property Let Level(value As Integer)

    m_Level = value
    
    m_isDirty = True
    
End Property

'根据SQL语句取用户记录
Private Function loadData(strSQL As String) As Boolean


    Dim rsUser As ADODB.Recordset
    
    On Error GoTo err_handle
    
    Set rsUser = gConn.Execute(strSQL)
    If rsUser.EOF Then
        loadData = False
        rsUser.Close
        Set rsUser = Nothing
    End If
    
    m_UID = rsUser("UID").value
    m_UserName = rsUser("login").value
    m_Password = rsUser("pwd").value
    m_Level = rsUser("userlevel").value
    
    m_isDirty = False
    
    rsUser.Close
    Set rsUser = Nothing
    
    loadData = True
    
    Exit Function
    
err_handle:
    Set rsUser = Nothing
    loadData = False

End Function

'根据用户名取用户记录
Public Function loadDataByName(name As String) As Boolean

    loadDataByName = loadData("SELECT * FROM tblUser WHERE login='" & Replace(name, "'", "''") & "'")
    
End Function

'根据用户ID取用户记录
Public Function loadDataByID(uid As String) As Boolean

    loadDataByID = loadData("SELECT * FROM tblUser WHERE UID=" & uid)

End Function

'执行用户增加操作
Public Function addData() As Boolean

    Dim strSQL As String
    
    strSQL = "INSERT INTO tblUser (login,pwd,userlevel) VALUES ("
    strSQL = strSQL & "'" & Replace(m_UserName, "'", "''") & "',"
    strSQL = strSQL & "'" & Replace(m_Password, "'", "''") & "',"
    strSQL = strSQL & m_Level & ")"
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    m_isDirty = False
    
    addData = loadDataByName(m_UserName)
    
    Exit Function
    
err_handle:
    addData = False
    
End Function

'执行保存用户操作
Public Function saveData() As Boolean

    Dim strSQL As String
    
    If m_isDirty = False Then
        saveData = True
        Exit Function
    End If
    
    strSQL = "UPDATE tblUser SET"
    strSQL = strSQL & " login='" & Replace(m_UserName, "'", "''") & "',"
    strSQL = strSQL & "pwd='" & Replace(m_Password, "'", "''") & "',"
    strSQL = strSQL & "userlevel=" & m_Level & " WHERE UID=" & m_UID
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    saveData = True
    
    m_isDirty = False
    
    Exit Function
    
err_handle:
    saveData = False

End Function

'执行删除用户操作
Public Function deleteData(uid As String) As Boolean

    Dim strSQL As String
    
    strSQL = "DELETE FROM tblUser WHERE UID=" & uid
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    deleteData = True
    
    Exit Function
    
err_handle:
    deleteData = False

End Function


'执行重设用户密码操作
Public Function resetPassword(Password As String) As Boolean
    
    Dim strSQL As String
    
    strSQL = "UPDATE tblUser SET PWD='" & Password & "' WHERE UID=" & m_UID
    
    On Error GoTo err_handle
    
    gConn.Execute strSQL
    
    resetPassword = loadDataByID(CStr(m_UID))
    
    Exit Function
    
err_handle:
    resetPassword = False

End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -