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

📄 clsopuser.cls

📁 VB数据库设计的代码。需要根据自己的数据库再作调整
💻 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 = "clsOpuser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit

'保持属性值的局部变量
Private mvaruserName As String '局部复制
Private mvaruserPwd As String '局部复制
Private mvaruserRank As Integer '局部复制
'保持属性值的局部变量
Private mvarshopId As Long '局部复制
'保持属性值的局部变量
Private mvarshopName As String '局部复制
Public Property Let shopName(ByVal vData As String)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.shopName = 5
    mvarshopName = vData
End Property


Public Property Get shopName() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.shopName
    shopName = mvarshopName
End Property



Public Property Let shopId(ByVal vData As Long)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.shopId = 5
    mvarshopId = vData
End Property


Public Property Get shopId() As Long
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.shopId
    shopId = mvarshopId
End Property



Public Property Let userRank(ByVal vData As Integer)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.userRank = 5
    mvaruserRank = vData
End Property


Public Property Get userRank() As Integer
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.userRank
    userRank = mvaruserRank
End Property



Public Property Let userPwd(ByVal vData As String)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.userPwd = 5
    mvaruserPwd = vData
End Property


Public Property Get userPwd() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.userPwd
    userPwd = mvaruserPwd
End Property



Public Property Let userName(ByVal vData As String)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.userName = 5
    mvaruserName = vData
End Property


Public Property Get userName() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.userName
    userName = mvaruserName
End Property

'***********************************************************************
'* 函数名:IsExist
'* 功  能:当前操作人员是否已存在于数据库中
'* 参  数:
'* 返回值:Boolean                  True 存在 False 不存在或数据查询错误
'* 版  本:2006.01.01 颜志军 初版
'***********************************************************************
Private Function IsExist() As Boolean
    '变量定义
    Dim sql As String           'SQL
    Dim rs As ADODB.Recordset   '记录集
    
    '生成查询SQL
    sql = "SELECT * FROM view_UserShop WHERE userName = '" & userName & "'"
    
    '执行查询
    IsExist = False
    On Error GoTo FUNEND
    Set rs = g_conn.Execute(sql)
    If Not rs.EOF Then
        IsExist = True
    End If
    rs.Close
    Set rs = Nothing
FUNEND:
End Function

'***********************************************************************
'* 函数名:IsOnlyAdmin
'* 功  能:是否是最后一位总经理帐号码
'* 参  数:
'* 返回值:Boolean                  True 是 False 不是
'* 版  本:2006.01.01 颜志军 初版
'***********************************************************************
Private Function IsOnlyAdmin() As Boolean
    '变量定义
    Dim sql As String           'SQL
    Dim rs As ADODB.Recordset   '记录集
    
    '生成查询SQL
    sql = "SELECT COUNT(*) FROM view_UserShop WHERE userRank = 1"
    
    '执行查询
    IsOnlyAdmin = False
    On Error GoTo FUNEND
    Set rs = g_conn.Execute(sql)
    If Not rs.EOF Then
        If rs(0) = 1 Then
            IsOnlyAdmin = True
        End If
    End If
    rs.Close
    Set rs = Nothing
FUNEND:
End Function

'***********************************************************************
'* 函数名:AppendNew
'* 功  能:追加当前操作人员信息到数据库
'* 参  数:
'* 返回值:DbOpResult                   数据库操作结果
'* 版  本:2006.01.01 颜志军 初版
'***********************************************************************
Public Function AppendNew() As DbOpResult
    '变量定义
    Dim sql As String       'SQL
    Dim affectLines As Long '影响行数
    
    '检查用户名是否已存在
    If IsExist() Then
        AppendNew = DbOpRecExist
        Exit Function
    End If
    
    '生成SQL
    sql = "INSERT INTO opuser(userName, userPwd, userRank, shopId) VALUES('" & _
        userName & "','" & userPwd & "'," & CStr(userRank) & "," & CStr(shopId) & ")"
        
    '执行插入
    AppendNew = DbOpNG
    On Error Resume Next
    g_conn.Execute sql, affectLines
    If affectLines = 1 Then
        AppendNew = DbOpOk
    End If
End Function

'***********************************************************************
'* 函数名:Update
'* 功  能:更新当前操作人员信息到数据库
'* 参  数:
'* 返回值:DbOpResult                   数据库操作结果
'* 版  本:2006.01.01 颜志军 初版
'***********************************************************************
Public Function Update() As DbOpResult
    '变量定义
    Dim sql As String       'SQL
    Dim affectLines As Long '影响行数
    
    '修正级别与店ID对应关系
    If userRank < 4 Then
        shopId = 1
    End If
    
    '检查当前操作人员登录名是否存在
    If Not IsExist() Then
        Update = DbOpRecNoExist
        Exit Function
    End If
    
    '生成SQL
    sql = "UPDATE opuser SET userPwd = '" & userPwd & "'"
    sql = sql & ", userRank = " & CStr(userRank)
    sql = sql & ", shopId = " & CStr(shopId)
    sql = sql & " WHERE userName ='" & userName & "'"
        
    '执行更新
    Update = DbOpNG
    On Error Resume Next
    g_conn.Execute sql, affectLines
    If affectLines = 1 Then
        Update = DbOpOk
    End If
End Function

'***********************************************************************
'* 函数名:Delete
'* 功  能:从数据库中删除当前操作人员信息
'* 参  数:
'* 返回值:DbOpResult                   数据库操作结果
'* 版  本:2006.01.01 颜志军 初版
'***********************************************************************
Public Function Delete() As DbOpResult
    '最后一个总经理帐号拒绝删除
    If userRank = 1 And IsOnlyAdmin() Then
        Delete = DbOpOnlyRec
        Exit Function
    End If

    '变量定义
    Dim sql As String       'SQL
    Dim affectLines As Long '影响行数
    
    '生成SQL
    sql = "DELETE FROM opuser WHERE userName = '" & userName & "'"
        
    '执行删除
    Delete = DbOpNG
    On Error Resume Next
    g_conn.Execute sql, affectLines
    If affectLines = 1 Then
        Delete = DbOpOk
    End If
End Function

'***********************************************************************
'* 函数名:LoadByUserName
'* 功  能:从数据库中载入指定操作人员信息
'* 参  数:String                       登陆用户名
'* 返回值:DbOpResult                   数据库操作结果
'* 版  本:2006.01.01 颜志军 初版
'***********************************************************************
Public Function LoadByUserName(ByVal loginUser As String) As DbOpResult
    '变量定义
    Dim sql As String           'SQL
    Dim rs As ADODB.Recordset   '记录集
    
    '生成查询SQL
    sql = "SELECT * FROM view_UserShop WHERE userName = '" & Trim(loginUser) & "'"
    
    '执行查询
    LoadByUserName = DbOpNG
    On Error Resume Next
    Set rs = g_conn.Execute(sql)
    If Not rs.EOF Then
        Me.userName = rs("userName")
        Me.userPwd = rs("userPwd")
        Me.userRank = rs("userRank")
        Me.shopId = rs("shopId")
        Me.shopName = rs("shopName")
        LoadByUserName = DbOpRecExist
    Else
        LoadByUserName = DbOpRecNoExist
    End If
    rs.Close
    Set rs = Nothing
End Function

⌨️ 快捷键说明

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