面向對象的LotusScript

上次提到使用面向對象的LotusScript的好處,這裡再給出兩個樣例。

 

DialogBox是NotesUIWorkspace的一個方法,用於顯示一個指定表單的對話框,在開發中很有用。不過對話框繁多的設置都通過方法的參數傳遞,難記難用。下面就用一個自定義類包裝瞭DialogBox的功能,默認情況下隻需要傳入一個表單或者文檔參數,就可以調用Show()方法顯示一個對話框。對話框的顯示可以通過設置屬性調整。原有的參數按照其意義進行瞭分類,可以更方便地設置。比如Fit屬性可以控制HorizonalFit和VerticalFit設置,AllowUpdate屬性可以控制NoFieldUpdate和NoNewFields。如果必要,也可以通過公開的字段更精細地修改原有的參數。

 

[vb]  

%REM  

    Class DialogBox  

    Description: Wraps the ws.Dialogbox() method.  

%END REM  

Public Class DialogBox  

    Public FormName As String   

    Public HorizonalFit As Boolean  

    Public VerticalFit As Boolean  

    Public NoCancel As Boolean  

    Public NoNewFields As Boolean  

    Public NoFieldUpdate As Boolean  

    Public  ReadOnly As Boolean  

    Public Title As String  

    Public Document As NotesDocument  

    Public SizeToTable As Boolean  

    Public NoOKCancel As Boolean  

    Public OKCancelAtBottom As Boolean  

      

    %REM  

        Property Set Fit  

        Description: Wraps the HorizonalFit and VerticalFit fields  

    %END REM  

    Property Set Fit As Boolean  

        me.HorizonalFit=Fit  

        me.VerticalFit=Fit  

    End Property  

      

    %REM  

        Property Set AllowUpdate  

        Description: Wraps the NoFieldUpdate and NoNewFields fields  

    %END REM  

    Property Set AllowUpdate As Boolean  

        me.NoFieldUpdate=Not AllowUpdate  

        me.NoNewFields=Not AllowUpdate  

    End Property  

      

    %REM  

        Property Set DefaultButton  

        Description: Wraps the NoCancel and NoOKCancel fields  

    %END REM  

    Property Set DefaultButton As Boolean  

        me.NoCancel=Not DefaultButton  

        me.NoOKCancel=Not DefaultButton  

    End Property  

      

    %REM  

    Sub New  

    Description: The argument info is either a string of a form name or a document to be shown  

    %END REM  

    Public Sub New(info As Variant)  

        'stop  

        'Default values  

        me.HorizonalFit=False  

        me.VerticalFit=False  

        me.NoCancel=False  

        me.NoFieldUpdate=False  

        me.NoNewFields=False  

        me.NoOKCancel=False  

        me.OKCancelAtBottom=False  

        me.ReadOnly=False  

        me.SizeToTable=False  

        me.Title="Lotus Notes"  

          

        Select Case TypeName(info)  

            Case "NOTESDOCUMENT"  

                Set me.Document=info  

                me.FormName=info.Form(0)  

            Case "STRING"  

                'info is the form name  

                me.FormName=info  

                Set me.Document=CreateDoc(me.FormName)  

        End Select  

  

    End Sub   

      

    %REM  

    Function Show  

    Description: Show the dialogbox.  

    %END REM  

    Public Function Show() As Boolean  

        Dim ws As New NotesUIWorkspace  

        Show = ws.Dialogbox(Me.FormName, Me.HorizonalFit, Me.VerticalFit, Me.NoCancel, Me.NoNewFields, Me.NoFieldUpdate, Me.ReadOnly, Me.Title, Me.Document, Me.SizeToTable, Me.NoOKCancel, Me.OKCancelAtBottom)  

    End Function  

End Class  

下面這個自定義類對Picklistcollection也做瞭類似的包裝。默認情況下打開當前數據庫的某個視圖,分別通過SelectDocs和SelectDoc進行多選和單選。

 

[vb]  

%REM  

    Class PickBox  

    Description: Wraps the ws.Picklistcollection() method.  

%END REM  

Public Class PickBox  

    Private ws As NotesUIWorkspace  

    Private s As NotesSession  

    Private db As NotesDatabase  

      

    Public MultiSelect As Boolean  

    Public Server As String  

    Public DBPath As String  

    Public Title As String  

    Public Prompt As String  

    Public SingleCategory As String  

      

    %REM  

        Sub New  

        Description: Comments for Sub  

    %END REM  

    Sub New()  

        Set ws=New NotesUIWorkspace  

        Set s=New NotesSession  

        Set db=s.Currentdatabase  

        'Default to open a view in the current db.  

        Server=db.Server  

        DBPath=db.Filepath  

        Title="Lotus Notes"  

        Prompt="Please select the document(s)."  

    End Sub  

      

    %REM  

        Function SelectDocs  

        Description: MultiSelect, return a NotesDocumentCollection  

    %END REM  

    Public Function SelectDocs(viewName As String) As NotesDocumentCollection  

        Set SelectDocs = ws.Picklistcollection(PICKLIST_CUSTOM, MultiSelect, Server, DBPath, ViewName, Title, Prompt, Singlecategory)  

    End Function  

      

    %REM  

        Function SelectDoc  

        Description: Return a single NotesDocument.  

    %END REM  

    Public Function SelectDoc(viewName As String) As NotesDocument  

        me.MultiSelect=False   

        Set SelectDoc=me.SelectDocs(viewName).Getfirstdocument()  

    End Function  

End Class  

下面是使用上述兩個類的簡單樣例:

 

[vb]  

Dim dlgbox As New DialogBox("formName")  

With dlgbox  

    .DefaultButton=True  

    .AllowUpdate=False   

End With  

Dim result As Boolean  

result=dlgbox.Show()  

  

Dim pb As New PickBox  

Dim doc As NotesDocument  

Set doc=pb.SelectDoc("viewName")  

 

發佈留言