📄 clsadmin.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 = "clsAdmin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
Private mvarAccount As String '账号
Private mvarPwd As String '密码
Private mvarIsDefault As Boolean '是否是默认用户
Public Property Let IsDefault(ByVal vData As Boolean)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.IsDefault = 5
mvarIsDefault = vData
End Property
Public Property Get IsDefault() As Boolean
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.IsDefault
IsDefault = mvarIsDefault
End Property
Public Property Let Pwd(ByVal vData As String)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.Pwd = 5
mvarPwd = vData
End Property
Public Property Get Pwd() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.Pwd
Pwd = mvarPwd
End Property
Public Property Let Account(ByVal vData As String)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.Account = 5
mvarAccount = vData
End Property
Public Property Get Account() As String
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.Account
Account = mvarAccount
End Property
Public Function AddNew() As gxcAddNew
Dim strSQL As String
'检测输入名称是否存在
If ExistByName("Admins", "A_Account_S", Me.Account) Then
AddNew = DuplicateName_AddNew
Exit Function
End If
strSQL = "INSERT INTO Admins(A_Account_S, A_PWD_S) "
strSQL = strSQL & " VALUES("
strSQL = strSQL & "'" & Me.Account & "'" '账号
strSQL = strSQL & ",'" & Me.Pwd & "'" '密码
strSQL = strSQL & ")"
'执行SQL语句,并提交事务
g_Conn.Execute strSQL
'如果发生错误,则返回FALSE,表示未成功添加
If Err.Number = 0 Then
AddNew = AddNewOK
Else
AddNew = AddNewFail
End If
End Function
Public Function Update() As gxcUpdate
Dim strSQL As String
'通过ID判断是否存在该记录,即该记录是否被其它商品端删除
'如果不存在该记录,则返回相应的操作结果给调用者
If Not ExistByName("Admins", "A_Account_S", Me.Account) Then
Update = RecordNotExist
Exit Function
End If
'构造SQL语句,注意需调用RealString函数去除字符串中的单引号
strSQL = "Update Admins SET "
strSQL = strSQL & "A_PWD_S='" & Me.Pwd & "' "
strSQL = strSQL & " WHERE A_Account_S=" & Me.Account
End Function
Public Function Delete(Optional strAccount As String = "") As gxcDelete
Dim strSQL As String
'如果调用该函数时传入了ID,则更新该对象的ID
If strAccount <> "" Then Me.Account = strAccount
'执行删除操作并返回操作结果
strSQL = "DELETE FROM Admins "
strSQL = strSQL & " WHERE A_Account_S='" & Me.Account & "'"
g_Conn.Execute strSQL
Delete = IIf(Err.Number = 0, DeleteOK, DeleteFail)
End Function
Public Function DeleteEx() As gxcDelete
Call Delete(Me.Account)
End Function
'验证密码
Public Function CheckPwd(strAccount As String, strPwd As String) As Boolean
Dim rs As Recordset
Dim strSQL As String
strSQL = " SELECT * FROM Admins "
strSQL = strSQL & " WHERE "
strSQL = strSQL & " A_Account_S='" & RealString(strAccount) & "'"
'执行SQL语句
Err.Clear
Set rs = g_Conn.Execute(strSQL)
If Err.Number <> 0 Or rs.RecordCount = 0 Then
CheckPwd = False
Exit Function
End If
'密码比较区分大小写,所以这里要用字符串类型的比较
If strPwd <> rs("A_PWD_S").Value Then
CheckPwd = False
Exit Function
End If
CheckPwd = True
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -