当前位置: 代码迷 >> Lotus >> 取得lotus 嵌入视图 选中的文档
  详细解决方案

取得lotus 嵌入视图 选中的文档

热度:63   发布时间:2016-05-05 06:56:56.0
获得lotus 嵌入视图 选中的文档

原文链接:
http://www.nsftools.com/tips/SelectedDocsList.lss


以下代码自己备份一下


'** Notes C-API functions used by the UnreadDocList class (these are Windows-specific
'** calls -- please adjust as necessary for other operating system platforms)
Declare Function OSPathNetConstruct Lib "nnotes.dll" (Byval portName As Integer, _
Byval serverName As String, Byval fileName As String, Byval pathName As String) As Integer

Declare Function NSFDbOpen Lib "nnotes.dll" (Byval dbName As String, rethDb As Long) As Integer
Declare Function NSFDbClose Lib "nnotes.dll" (Byval hDb As Long) As Integer

Declare Function NIFOpenCollection Lib "nnotes.dll" (Byval hDB As Long, _
Byval hDB As Long, Byval ViewNoteID As Long, Byval openFlags As Integer, _
Byval hUnreadList As Long, hCollection As Long, Byval hNullVal As Long, _
hViewUnid As Long, hCollapsedList As Long, hSelectedList As Long ) As Integer

Declare Function NIFCloseCollection Lib "nnotes.dll" (Byval hCollection As Long) As Integer

Declare Function IDEntries Lib "nnotes" ( Byval hTable As Long ) As Long
Declare Function IDScan Lib "nnotes" ( Byval hTable As Long, Byval tFirstBool As Integer, _
retID As Long) As Integer

Declare Function OSMemFree Lib "nnotes" (Byval handle As Long) As Integer

'** Error code masks
Const ERR_MASK = &H3fff
Const PKG_MASK = &H3f00
Const ERRNUM_MASK = &H00ff

Declare Function OSLoadString Lib "nnotes.dll" (Byval hModule As Long, Byval stringCode As Integer, _
Byval retBuffer As String, Byval bufferLength As Integer) As Integer


Class SelectedDocsList

%REM
The SelectedDocsList class provides a way to programmatically access
the list of selected docs in a view that's currently open in the Notes client
(open in a tab, a frame, or as an embedded view), without relying on an
agent to be running against "Selected docs" in a view.

Because we're calling the C-API, you'll also need to declare several API
functions in the Declarations section of the agent or script library that
holds this class. If you got this class without the related API declarations,
please see the original version of this code at http://www.nsftools.com

Here's an example of getting the selected docs in a view:

Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument

Set db = session.CurrentDatabase
Set view = db.GetView("All docs")

Dim selected As New SelectedDocsList(view)
Print "Count = " & selected.Count

Set doc = selected.GetFirstDocument
Do Until (doc Is Nothing)
Print doc.NoteID & " was created on " & doc.Created
Set doc = selected.GetNextDocument(doc)
Loop


A few things to note about this class:

1. This will ONLY work when running on a local Notes client, while the
client is open. If you try to run it on your server, you may crash it.

2. The docs are NOT returned in the same order they are seen in the view.
They seem to be in order of creation date, starting from the earliest (although
this is just what I've seen in preliminary testing, and might not be true all the time).

3. If the view that you're pointing to is not currently open in the client anywhere,
this class should just return a GetCount value of 0 (not an error or a crash).

4. If you're using this in an agent, you do NOT need to have the agent set
to run against "Selected Docs". However, it's very possible that the agent
has to be run by the user (as opposed to a background agent) -- I haven't
done any testing on background/scheduled agents, but this class is really
meant to be run in the front-end.

5. One way that I used this class was to get the docs that were selected
in a view that was embedded on a Form. Doing this, I could allow actions
and buttons on the Form to access the selected docs in the embedded view
by simply passing a proper handle to the view that was embedded. In other
words, if the embedded view is called "SpecialDocs", you simply create
an instance of the class using db.GetView("SpecialDocs") in the constructor.
You can do this when the form is opened and keep it in memory as a global
object if you want. Just remember to call the RefreshList method before you
try to get the selected docs at any given time, to make sure you have the
current list. However....

6. This does NOT return the proper document list for embedded views that
have "Show Single Category" set.

You can use this code in any way you want, as long as you don't hold me
liable for anything, and you don't pretend you wrote it yourself.

version 1.0
December 29, 2005
Julian Robichaux ( http://www.nsftools.com )
%END REM


Private idArray() As String
Private thisDb As NotesDatabase
Private thisView As NotesView
Private lastError As String
Private lastDoc As NotesDocument
Private lastIndex As Integer


Public Sub New (view As NotesView)
'** We'll allow the user to pass a view when an instance of
'** this class is created, to make things a little easier. If you
'** don't have a valid view handle when you're instantiating
'** this class, just use Nothing as the view parameter.
Call SetView(view)

'** No lazy referencing here. We'll go ahead and try to grab
'** the list of selected docs right away
Call RefreshList()
End Sub


Public Sub SetView (view As NotesView)
'** This can be used to change the view that we're looking at.
Set thisView = view
If (view Is Nothing) Then
Set thisDb = Nothing
Else
Set thisDb = view.Parent
End If

'** reset the internal variables
Call ResetPrivates

'** Notice that RefreshList is NOT called automatically when the
'** view reference is changed. If you want a new list of selected
'** docs, remember to call RefreshList yourself. This is just in case
'** you have code that switches views a lot (like a form with an
'** embedded view or a frameset)
End Sub


Private Sub ResetPrivates ()
'** reset all the internal references and counters
Redim idArray(0) As String
lastError = ""
Set lastDoc = Nothing
lastIndex = 0
End Sub


Public Function GetIDArray () As Variant
'** return the internal list of NoteIDs we're storing as an array of Strings
GetIDArray = idArray
End Function


Public Function Parent () As NotesView
'** return the view that we're currently referencing
Set Parent = thisView
End Function


Public Function Count () As Long
'** How many NoteIDs do we have in our internal array?
Count = Ubound(idArray) - Lbound(idArray) + 1

'** if there's only one item and it's blank, we should consider our
'** array to be empty and return a count of 0
If (Count = 1) And (idArray(Lbound(idArray)) = "") Then
Count = 0
End If
End Function


Public Function GetNthDocument (n As Integer) As NotesDocument
'** return a handle to the Nth document in our array, if possible
Set lastDoc = Nothing

'** exit early for invalid conditions
If (thisDb Is Nothing) Then
'** oops, no database handle
Exit Function
Elseif (n > Ubound(idArray)) Or (n < Lbound(idArray)) Then
'** array out of bounds
Exit Function
Elseif (idArray(n) = "") Then
'** empty value
Exit Function
End If

Set GetNthDocument = thisDb.GetDocumentByID(idArray(n))

'** we store references to the lastDoc and lastIndex for efficiency
'** in the GetNextDocument method
Set lastDoc = GetNthDocument
lastIndex = n
End Function


Public Function GetFirstDocument () As NotesDocument
'** returns a handle to the first doc in our collection
Set GetFirstDocument = GetNthDocument(Lbound(idArray))
End Function


Public Function GetLastDocument () As NotesDocument
'** returns a handle to the last doc in our collection
Set GetLastDocument = GetNthDocument(Ubound(idArray))
End Function


Public Function GetNextDocument (doc As NotesDocument) As NotesDocument
'** returns a handle to the next selected doc after the one that
'** the user passes us, just like GetNextDocument in NotesView
'** or NotesDocumentCollection (remember that the docs on
'** our list aren't in the same order as the View itself, though)
Dim i As Integer

'** for efficiency, see if the doc the user passed as a parameter is
'** the same as the last doc we gave them (which is almost always
'** the case, because this will normally be called in a Do
  相关解决方案