?? cclienttypes.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 = "CTypes"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Private mCol As Collection
'往集合中加入一個“客戶類型”對象
Public Sub Add(objType As CType)
mCol.Add objType, "A" & objType.ID
'在加入對象是,最好同時加入其“KEY”屬性
'“KEY”屬性不可以是數字型,因此在前面隨便加
'一個字母,此處加了一個“A”
End Sub
Public Property Get Item(vntIndexKey As Variant) As CType
Set Item = mCol(vntIndexKey)
End Property
Public Property Get Count() As Long
Count = mCol.Count
End Property
Public Sub Remove(vntIndexKey As Variant)
mCol.Remove vntIndexKey
End Sub
Public Property Get NewEnum() As IUnknown
'本屬性允許用 For...Each 語法枚舉該集合。
Set NewEnum = mCol.[_NewEnum]
End Property
'清除集合中的全部元素
Public Sub Clear()
'注意!在清除時必須倒序清除,否則要出錯!
Dim i As Long
For i = mCol.Count To 1 Step -1
mCol.Remove i
Next i
End Sub
Private Sub Class_Initialize()
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
Set mCol = Nothing
End Sub
'按條件查找客戶類型,以集合類的方式返回
Public Function Find(Optional lngID As Long = 0, _
Optional lngSuperID As Long = -1) As CTypes
'按輸入的參數查詢,并返回一個集合類
Dim strSQL As String
'構造SQL語句
strSQL = "Select * from ClientType where "
If lngID <> 0 Then strSQL = strSQL & "TypeID=" & lngID & " and "
If lngSuperID <> -1 Then
' If lngSuperID = 0 Then '如果傳入0,則表示沒有上級客戶類型
' strSQL = strSQL & "SuperID is null and "
' Else
strSQL = strSQL & "SuperID=" & lngSuperID & " and "
' End If
End If
strSQL = strSQL & "TypeID>0"
'清空當前集合
Me.Clear
Dim rs As Recordset
Set rs = g_Conn.Execute(strSQL)
'往集合中添加查詢結果
Dim i As Long
Dim objType As CType
For i = 1 To rs.RecordCount
Set objType = New CType
With objType
.ID = rs("TypeID").Value
.TypeName = Trim(rs("TypeName").Value)
.SuperID = IIf(IsNull(rs("SuperID").Value), 0, rs("SuperID").Value)
End With
Me.Add objType
Set objType = Nothing
rs.MoveNext
Next i
Set rs = Nothing
Set Find = Me
End Function
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -