获取并排序数据库中的所有视图

时间:2014-05-28 17:19:06

标签: lotus-notes lotusscript

我有一些代码可以获取数据库中所有视图和文件夹的列表。问题是一切都很糟糕。视图列表显示几乎是随机的,虽然我假设有一些顺序......

有没有办法获取对话框提示中显示的所有视图的列表,然后按字母顺序对列表进行排序?

Sub Initialize
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim dbSource As NotesDatabase, dbDest As NotesDatabase
Dim source As NotesView, dest As NotesView
Dim vc As NotesViewEntryCollection
Dim docDest As NotesDocument
Dim ve As NotesViewEntry
Dim folders() As String
Dim i As Integer
Dim ret, rez

Set dbSource = s.CurrentDatabase

ForAll v In dbSource.Views
    If v.IsFolder Then
        i = i + 1
        ReDim Preserve folders( i - 1 ) As String
        folders( i - 1 ) = v.Name
    End If
End ForAll

ret = w.Prompt( PROMPT_OKCANCELLISTMULT, "Folder selection", "Select one or more folders to move.", folders(0), folders )
If IsEmpty( ret ) Then
    MessageBox "User canceled", , "Folder not selected"
    Exit Sub
Else


      rez = w.Prompt( 13, "Database selection", "Choose the database to move the folder to" )


      ForAll f In ret  


        Set source = dbSource.GetView( f )
        Set vc = source.AllEntries





          Set dbDest = s.GetDatabase( rez(0), rez(1), False )
          Call dbDest.EnableFolder( f )

          Set ve = vc.GetFirstEntry
          Do Until ve Is Nothing
              Set docDest = ve.Document.CopyToDatabase( dbDest )
              Call docDest.PutInFolder( f )
              Set ve = vc.GetNextEntry( ve )
        Loop

        Call vc.RemoveAllFromFolder( f )
             Call source.Remove
         End ForAll
End If

End Sub

3 个答案:

答案 0 :(得分:3)

您可以添加此子例程,以便在将folders数组包含在提示方法中之前对其进行排序。

只需在使用w.Prompt();

的行前调用ShellSort(folders)
Sub ShellSort( ar( ) As String )
   Dim Lower As Integer
   Dim Upper As Integer
   Dim botMax As Integer
   Dim i As Integer
   Dim k As Integer
   Dim h As Integer
   Dim v As String

   Lower% = Lbound( ar$( ) )
   Upper% = Ubound( ar$( ) )

   h% = 1
   Do
      h% = (3*h%) + 1
      Loop Until h% > Upper%-Lower%+1
         Do
            h% = h% \ 3
            botMax% = Lower% + h% - 1
            For i% = botMax% + 1 To Upper%
               v$ = ar$( i% )
               k% = i%
               While ar$( k% - h% ) > v$
                  ar$( k% ) = ar$( k% - h% )
                  k% = k% - h%
                  If (k% <= botMax%) Then Goto wOut
               Wend
wOut:
   If (k% <> i%) Then ar$(k%) = v$
      Next
      Loop Until h% = 1
End Sub

(来源:http://www.dominoexperts.com/articles/Very-fast-sorting-algorithm

答案 1 :(得分:2)

您可以在Evaluate调用中使用@Sort来对文件夹名称进行排序。

Dim foldersList As String
Dim folders As Variant
...
ForAll v In dbSource.Views
    If v.IsFolder Then
        foldersList = foldersList + |:"| + Replace(Replace(v.Name, |\|, |\\|), |"|, |\"|) + |"|
    End If
End ForAll
If foldersList <> "" then
    folders = Evaluate(|@Sort(| + StrRight(foldersList, ":") + |)|)
    ...

上面的代码就是这样的:

首先将字符串中的所有文件夹名称收集为公式列表,如

"xyz":"abc":"mno":"def"

确保文件夹名称中的引号被\"替换,子文件夹的反斜杠替换为\\

第二次使用@Sort("xyz":"abc":"mno":"def")评估公式。

结果是一个排序的变体字符串数组,您可以像之前一样在w.Prompt(..., ..., folders(0), folders )中使用。

此解决方案的好处是代码非常短,而且速度也很快。

答案 2 :(得分:1)

如果使用列表而不是数组,则值将自动按排序顺序放置。例如。

Dim folders List As Boolean
ForAll v In dbSource.Views
  If (v.IsFolder) Then folders(v.Name) = True 
End ForAll