- Code : Tout sélectionner
'--------------------------------------------------------------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------------------------------------------------------------
' Classe NotesViewDocumentCollection :
' Par : Stéphane HUET
' Créer le : 12/07/2004
' Dernière modif le : 09/09/2004
' Cette classe est l'equivalent d'une NotesViewEntryCollection mais avec des documents a la place des Entries.
' C'est une NotesDocumentCollection mais dont les documents sont trié selon leur ordre dans une vue.
Class NotesViewDocumentCollection
' Private vContainer () As NotesDocument
' Public Count As Long
' Public Sub new (VueRech As NotesView, vCle As Variant)
' Public Function getContainer () As Variant
' Public Function FindDocument (RechDoc As NotesDocument) As Integer
' Public Function getnthDocument (iIndice As Integer) As NotesDocument
' Public Function getFirstDocument () As NotesDocument
' Public Function getLastDocument () As NotesDocument
' Public Function getNextDocument (doc As NotesDocument) As NotesDocument
' Public Function getPrevDocument (doc As NotesDocument) As NotesDocument
' Public Function DeleteDocument (iIndice As Integer) As Integer
' Public Function DeleteAllDocuments () As Integer
' Public Function RemoveDocumentFromCollection (iIndice As Integer) As Integer
' Public Function RemoveAllDocumentsFromCollection () As Integer
' Public Function IsVide () As Integer
'End Class
'--------------------------------------------------------------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------------------------------------------------------------
' Conteneur de documents ( = collection)
Private vContainer As Variant
' Nombre de documents dans la collection
Public Count As Long
' Nom de la vue ayant permis de construire la collection
Private sNomVue As String
' Cle ayant permis de construire la collection
Private vCle As String
' Permet d'attribuer un état à la collection. Cet etat doit etre geré par l'utilisateur de cette classe. Il n'est que purement informatif au sein de cette classe
Private sState As String
'---------------------------------------------------------------------------------------------------------------------------------------
' Constructeur.
' Si vCle = "" alors la collection contient tous les docs de la vue
' Si vCle = "SELECT" alors la collection contient tous les docs selectionnés de la vue
' Sinon vCle est une clé ou un tableau de cle (identique à la cle du getDocumentByKey)
Public Sub new (VueRech As NotesView, vCle As Variant)
'---------------------------------------------------------------------------------------------------------------------------------------
Dim s As New NotesSession
Dim db As NotesDatabase
Dim ColEntry As NotesViewEntryCollection
Dim CurseurEntry As NotesViewEntry
Dim i As Integer
Set ColEntry = Nothing
On Error Resume Next
VueRech.refresh
Me.sState = ""
Me.vCle = vCle
Me.sNomVue = VueRech.name
If Datatype (vCle) = V_STRING And vCle = "" Then
Set ColEntry = VueRech.AllEntries
Else
Set ColEntry = VueRech.getAllEntriesByKey (vCle)
End If
On Error Goto 0
If Not ColEntry Is Nothing Then
If ColEntry.count > 0 Then
Me.Count = ColEntry.count
Redim vContainer (ColEntry.count - 1)
Set CurseurEntry = ColEntry.getFirstEntry ()
While Not CurseurEntry Is Nothing
If CurseurEntry.IsDocument Then
Set vContainer (i) = CurseurEntry.document
i = i + 1
End If
Set CurseurEntry = ColEntry.getNextEntry (CurseurEntry)
Wend
Else
Redim vContainer (0)
Me.Count = ColEntry.count
Set vContainer (0) = Nothing
End If
Else
Redim vContainer (0)
Me.Count = 0
Set vContainer (0) = Nothing
End If
End Sub
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Permet de récupérer tout le conteneur (la collection)
Public Function getContainer () As Variant
'---------------------------------------------------------------------------------------------------------------------------------------
Dim vContainerVide As Variant
If IsVide () Then
getContainer = vContainerVide
Else
getContainer = vContainer
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Permet de récupérer l'attribut sState de la collection
Public Property Get State () As String
'---------------------------------------------------------------------------------------------------------------------------------------
State = Me.sState
End Property
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Permet de récupérer l'attribut sState de la collection
Public Property Set State As String
'---------------------------------------------------------------------------------------------------------------------------------------
Me.sState = State
End Property
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methode permet de retirer du conteneur (collection) les docs supprimer de la vue et d'ajouter ceux qui ont été créé.
' Cette methode ne modifie pas les documents déja présent dans la collection.
Public Function Refresh () As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim Vue As NotesView
Dim curseurDoc As NotesDocument
Dim curseurDocTempo As NotesDocument
Dim TempoColDoc As NotesViewDocumentCollection
Dim i As Integer
Dim j As Integer
Dim k As Integer
' Retire de la collection les documents qui ont ete supprimés
Me.compacte
If sNomVue <> "" Then
Set Vue = db.getView (sNomVue)
Vue.refresh
Set TempoColDoc = New NotesViewDocumentCollection (Vue, Me.vCle)
If Me.count <> TempoColDoc.count Then
For i = 0 To TempoColDoc.count - 1
Set CurseurDoc = Me.getnthDocument (i)
Set CurseurDocTempo = TempoColDoc.getnthDocument (i)
If Not CurseurDoc Is Nothing Then
If CurseurDoc.Universalid <> CurseurDocTempo.Universalid Then
k = Me.FindDocument (CurseurDocTempo)
If k <> -1 Then
Set vContainer (i) = vContainer (k)
Set vContainer (k) = CurseurDoc
Else
Call addDocument (CurseurDocTempo, i)
End If
End If
Else
Call addDocument (CurseurDocTempo, i)
End If
Next i
End If
If Not IsSynchro Then
Print "Le refresh de la collection de doc ne s'est pas effectué convenablement."
Me.Refresh = False
Else
Me.Refresh = True
End If
Else
Me.Refresh = True
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Permet de retourner l'indice d'un document dans le conteneur (dans la collection).
' Si le document est absent, -1 est retourné.
Public Function FindDocument (RechDoc As NotesDocument) As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim i As Integer
If Not IsVide () And Not RechDoc Is Nothing Then
i = 0
Forall doc In vContainer
If Not doc Is Nothing Then
If RechDoc.Universalid = doc.Universalid Then
FindDocument = i
Exit Function
Else
i = i + 1
End If
Else
i = i + 1
End If
End Forall
End If
FindDocument = -1
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Récupérer le n ieme document du conteneur. (de la collection)
Public Function getnthDocument (iIndice As Integer) As NotesDocument
'---------------------------------------------------------------------------------------------------------------------------------------
If Not IsVide () Then
If iIndice > Ubound (vContainer) Or iIndice < Lbound (vContainer) Then
Set getnthDocument = Nothing
Else
Set getnthDocument = vContainer (iIndice)
End If
Else
Set getnthDocument = Nothing
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Récupérer le premier document du conteneur. (de la collection)
Public Function getFirstDocument () As NotesDocument
'---------------------------------------------------------------------------------------------------------------------------------------
If Not IsVide () Then
Set getFirstDocument = vContainer (0)
Else
Set getFirstDocument = Nothing
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Récupérer le dernier document du conteneur. (de la collection)
Public Function getLastDocument () As NotesDocument
'---------------------------------------------------------------------------------------------------------------------------------------
If Not IsVide () Then
Set getLastDocument = vContainer (Ubound (vContainer))
Else
Set getLastDocument = Nothing
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Récupérer le document qui suit, dans le conteneur, le document en parametre.
Public Function getNextDocument (doc As NotesDocument) As NotesDocument
'---------------------------------------------------------------------------------------------------------------------------------------
Dim iIndice As Integer
If Not IsVide () Then
iIndice = FindDocument (doc)
Set getNextDocument = getnthDocument (iIndice + 1)
Else
Set getNextDocument = Nothing
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Récupérer le document qui precede, dans le conteneur, le document en parametre.
Public Function getPrevDocument (doc As NotesDocument) As NotesDocument
'---------------------------------------------------------------------------------------------------------------------------------------
Dim iIndice As Integer
iIndice = FindDocument (doc)
Set getPrevDocument = getnthDocument (iIndice - 1)
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methode permet de supprimer un document precis du conteneur (de la collection)
Public Function DeleteDocument (iIndice As Integer) As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim docASup As NotesDocument
If Not IsVide () And iIndice < Ubound (vContainer) + 1 And iIndice > Lbound (vContainer) - 1 Then
Set DocASup = vContainer (iIndice)
If RemoveDocumentFromCollection (iIndice) Then
If Not DocASup Is Nothing Then
docASup.remove True
End If
DeleteDocument = True
Else
DeleteDocument = False
End If
Else
DeleteDocument = False
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methode permet de supprimer tous les documents du conteneur (de la collection)
Public Function DeleteAllDocuments () As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim i As Integer
If Not IsVide () Then
For i = 0 To Ubound (vContainer)
If Not vContainer (i) Is Nothing Then
vContainer (i).remove True
End If
Next i
Redim vContainer (0)
Me.Count = 0
DeleteAllDocuments = True
Else
DeleteAllDocuments = False
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methode permet de retirer un document precis du conteneur (de la collection)
Public Function RemoveDocumentFromCollection (iIndice As Integer) As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim i As Integer
If Not IsVide () And iIndice < Ubound (vContainer) + 1 And iIndice > Lbound (vContainer) - 1 Then
For i = iIndice To Ubound (vContainer) - 1
Set vContainer (i) = vContainer (i + 1)
Next i
If Ubound (vContainer) > 0 Then
Redim Preserve vContainer (Ubound (vContainer) - 1)
Else
Redim vContainer (0)
End If
Me.Count = Me.Count - 1
RemoveDocumentFromCollection = True
Else
RemoveDocumentFromCollection = False
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methode permet de retirer tous les documents du conteneur (de la collection)
Public Function RemoveAllDocumentsFromCollection () As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Redim vContainer (0)
Me.Count = 0
RemoveAllDocumentsFromCollection = True
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methodce permet de determiner si la collection est vide
Public Function IsVide () As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
If Isarray (vContainer) Then
If Isobject (vContainer (0)) And Me.Count = 0 Then
IsVide = vContainer (0) Is Nothing
Elseif Me.Count = 0 Then
IsVide = True
Else
IsVide = False
End If
Else
IsVide = True
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methode permet de determiner si la collection est toujours conforme à la vue
Public Function IsSynchro () As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim Vue As NotesView
Dim curseurDoc As NotesDocument
Dim curseurDocTempo As NotesDocument
Dim TempoColDoc As NotesViewDocumentCollection
Dim i As Integer
IsSynchro = True
Set Vue = db.getView (sNomVue)
Vue.refresh
Set TempoColDoc = New NotesViewDocumentCollection (Vue, Me.vCle)
For i = 0 To TempoColDoc.count - 1
Set CurseurDoc = Me.getnthDocument (i)
Set CurseurDocTempo = TempoColDoc.getnthDocument (i)
If CurseurDoc Is Nothing Then
IsSynchro = False
Exit Function
Else
If CurseurDoc.Universalid <> CurseurDocTempo.Universalid Then
IsSynchro = False
Exit Function
End If
End If
Next i
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methodce permet de retirer de la collection les doc qui ont été supprimé ( = nothing)
Private Function Compacte () As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim curseurDoc As NotesDocument
Dim TempoColDoc As NotesViewDocumentCollection
Dim i As Integer
Dim j As Integer
For i = 0 To count - 1
Set CurseurDoc = getnthDocument (i)
If CurseurDoc Is Nothing Then
Call RemoveDocumentFromCollection (i)
End If
Next i
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methodce permet d'ajouter un doc à un emplacement precis dans la collection
Public Function addDocument (Doc As NotesDocument, iIndice As Integer) As Integer
'---------------------------------------------------------------------------------------------------------------------------------------
Dim i, k As Integer
Dim bAugmente As Integer
If Not Isarray (vContainer) Then
Redim vContainer (0) As NotesDocument
End If
If iIndice > Ubound (vContainer) Or iIndice < Lbound (vContainer) Then
If Isobject (vContainer (Ubound (vContainer))) Then
If Not vContainer (Ubound (vContainer)) Is Nothing Then
bAugmente = True
iIndice = Ubound (vContainer) + 1
Else
bAugmente = False
iIndice = Ubound (vContainer)
End If
Else
bAugmente = False
iIndice = Ubound (vContainer)
End If
Else
If Isobject (vContainer (iIndice)) Then
bAugmente = Not vContainer (iIndice) Is Nothing
Else
bAugmente = False
End If
End If
If Not bAugmente Then
Set vContainer (iIndice) = Doc
count = count + 1
Else
Redim Preserve vContainer (Ubound (vContainer) + 1)
count = count + 1
For k = count - 2 To iIndice Step -1
Set vContainer (k + 1) = vContainer (k)
Next k
Set vContainer (iIndice) = Doc
End If
End Function
'---------------------------------------------------------------------------------------------------------------------------------------
' BUT :
' Cette methodce permet d'ajouter un doc à un emplacement precis dans la collection
Public Sub ReplaceCollection (Collection As NotesViewDocumentCollection)
'---------------------------------------------------------------------------------------------------------------------------------------
Me.vContainer = Collection.getContainer ()
Me.count = Collection.count
Me.sNomVue = Collection.sNomVue
Me.vCle = Collection.vCle
Me.sState = Collection.sState
End Sub
End Class