Page 1 sur 1

[LS] - Classe pour compter les documents dans une vue en

MessagePublié: 08 Fév 2005 à 14:05
par oguruma
cette classe permet de compter les documents dans une vue
il faut faire une vue comportant une colonne calculée avec une valeur constante, cette constant sera passée comme clé
cette colonne doit être triée !!! ne pas oublier

exemple d'utilisation
Code : Tout sélectionner
dim cnt as new CountDocuments
..
..
set cnt=new CountDocuments("(maVueCachée)","ZORRO")
msgbox cnt.getCount()
...
...



Code : Tout sélectionner
Public Class CountDocuments
   Private m_session As NotesSession
   Private m_db As NotesDatabase
   Private m_sView As String
   Private m_sKey As String
   Private m_collection As NotesDocumentCollection
   Private m_view As NotesView
   
   Sub new (v As String, key As String)
      m_sView=v
      m_sKey=key
      Call init
   End Sub
   
   Private Sub init
      Set m_session=New NotesSession
      Set m_db=m_session.currentdatabase
      Set m_view=m_db.getView(m_sView)
      Set m_collection=m_view.getAllDocumentsBykey(m_sKey)
   End Sub
   
   Public Function getCount() As Long
      getCount=m_collection.count
   End Function
   
End Class

MessagePublié: 10 Août 2005 à 11:15
par Michael DELIQUE
Une autre manière de faire :

Code : Tout sélectionner
Function NbDocInView(wvwCount As NotesView,wNomView As String)  As Integer
   
   'compte le nombre de document dans une vue
'   wvwView variable contenant la vue a compter
'    wNomView variable contenant le nom de la vue a compter utilisé si la vue n'est pas renseigné
   
   'Déclaration des Variables   
   Dim vwCount As NotesView
   Dim vecCount As NotesViewEntryCollection
   
   On Error Goto ErreurNbDocInView
   
   If DB Is Nothing Or Session Is Nothing Then
      Set Session = New NotesSession
      Set DB = Session.CUrrentdatabase
   End If
   
   If wvwCount Is Nothing Then
      If Trim(wNomView) <> "" Then
         Set vwCount = db.getview(wNomView)
      Else
         NbDocInView = 0
         Exit Function
      End If   
   Else
      Set vwCount = wvwCount
   End If
   
   If vwCount Is Nothing Then
      NbDocInView = 0
      Exit Function
   End If
   
   Set vecCount = vwCount.AllEntries
   
   If vecCount Is Nothing Then
      NbDocInView = 0
      Exit Function
   End If
   
   NbDocInView = Cint(vecCount.count)
   
   Exit Function
ErreurNbDocInView:
   Msgbox "(NbDocInView) Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
   NbDocInView = 0
   Exit Function
End Function