用lotusscript動態重新整理登入頁表單設計

來源:互聯網
上載者:User

用lotusscript動態重新整理登入頁表單設計
1、到伺服器上尋找是否有domcfg.nsf庫,如果沒有,直接把自己設計的domcfg.nsf庫考到伺服器上,如果有,執行2
2、從伺服器的domcfg.nsf庫中尋找登入頁,如果有,先將“$$LoginUserForm”表單導成dxl,然後將form節點下屬的name節點的nodevalue值改成“$$LoginUserForm”+時間,然後再把dxl檔案導到domcfg.nsf庫中(該操作是儲存原有的登入頁表單)。
3、將自己設計的庫中的“$$LoginUserForm”表單導成dxl,然後再匯入到伺服器的domcfg.nsf庫中。

另:
    如果想直接修改某個表單的設計也是同樣的道理。因為domino的資料庫設計、表單、視圖等等都是標準的xml檔案,所以如果要修改表單設計,可以先把表單導成dxl檔案(xml格式),然後,直接對dxl中具體的node作修改,然後重新匯入dxl檔案即可實現對錶單設計的動態修改。

Option Public
Option Compare Nocase

Sub Initialize
 On Error Goto errhandle
 Dim session As notessession
 Dim db1 As notesdatabase
 Dim db2 As notesdatabase
 Dim nc As notesnotecollection
 Dim nc2 As notesnotecollection
 Dim stream As notesstream
 Dim exporter As NotesDXLExporter
 Dim importer As notesdxlimporter
 Dim importer0 As notesdxlimporter
 Dim form As NotesForm
 Dim nid As String
 
 Dim file1 As String
 Dim file2 As String
 Dim file3 As String
 Dim outputFile As String
 
 Dim timeStr As String
 
 Dim inputStream As NotesStream, outputStream As NotesStream
 Dim domParser As NotesDOMParser
 Dim docNode As NotesDOMDocumentNode
 Dim docRootNode As NotesDOMNode
 
 file1 = ""
 file2 = ""
 file3 = ""
 flag = False
 timeStr = Replace(Replace(Replace(Cstr(Now),"-",""),":","")," ","")
 
 Set session = New notessession
 Set db1 = session.currentdatabase
 '先判斷當前伺服器是否有登入庫
 Set db2 = New NotesDatabase(db1.Server, "domcfg.nsf")
 '如果沒有登入庫
 If Not db2.IsOpen Then
  Set db2 = db1.CreateFromTemplate(db1.Server,"domcfg.nsf", True)
 Else
  Set form = db2.GetForm("$$LoginUserForm")
  '如果存在登入頁,首先備份登入頁''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  If Not form Is Nothing Then
   Set nc = db2.createnotecollection(False)
   Call nc.buildcollection
   Set nc2 = db2.createnotecollection(False)
   nc2.SelectForms = True
   Call nc2.BuildCollection
   nid = nc2.GetFirstNoteId 
   '尋找登入頁表單
   Forall f In db2.Forms
    If Not f.IsSubForm Then
     If f.name = "$$LoginUserForm" Then
      nc.Add(nid)
      Exit Forall
     End If
     nid = nc2.GetNextNoteId(nid)
    End If
   End Forall
   '將表單導成dxl檔案,並存在臨時檔案夾中
   Set stream = session.CreateStream
   file2 = "c:templogin_back_" & timeStr & "1.dxl"
   Call stream.Open(file2)
   Set exporter=session.createDXLexporter(nc, stream)
   Call exporter.process
   Call stream.close
   '刪除原有登入頁
   Call form.Remove
   '讀取剛才的dxl檔案(xml格式的檔案),修改登入頁名稱
   file3 = "c:templogin_back_" & timeStr & "2.dxl"
   Set session = New NotesSession
   Set outputStream =session.CreateStream
   outputStream.Open(file3)
   Set inputStream = session.CreateStream
   inputStream.Open (file2)
   If inputStream.Bytes > 0 Then
    Set domParser=session.CreateDOMParser(inputStream)
    Call domParser.Process
    Set docNode = domParser.Document
    Set docRootNode = docNode.DocumentElement
    If Not docRootNode.IsNull Then
     '修改檔案中form節點的下屬節點name的nodevalue的值
     Call ChangeNode(docRootNode,timeStr)
     Call domParser.setoutput(outputStream)
     Call domParser.Serialize
    End If
   End If
   '匯入備份登入頁
   Set importer0=session.createdxlimporter(outputStream, db2)
   importer0.designimportoption = 2
   Call importer0.process
   Set importer0 = Nothing
   Call outputStream.Truncate
   Call inputStream.Truncate
   Call outputStream.Close
   Call inputStream.Close
  End If
  
  '匯入登入頁'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  Set nc = db1.createnotecollection(False)
  Call nc.buildcollection
  Set nc2 = db1.createnotecollection(False)
  nc2.SelectForms = True
  Call nc2.BuildCollection
  nid = nc2.GetFirstNoteId
  '取得當前庫的登入頁表單
  Forall f In db1.Forms
   If Not f.IsSubForm Then
    If f.name = "$$LoginUserForm" Then
     nc.Add(nid)
     Exit Forall
    End If
    nid = nc2.GetNextNoteId(nid)
   End If
  End Forall
  '導成dxl檔案,並存在臨時檔案夾中
  Set stream = session.CreateStream
  file1 = "c:templogin_" & timeStr & ".dxl"
  Call stream.Open(file1)
  '把dxl匯入到domcfg庫中
  Set exporter=session.createDXLexporter(nc, stream)
  Set importer=session.createdxlimporter(stream, db2)
  importer.designimportoption = 2
  Call exporter.process
  Call importer.process
  Call stream.Truncate
  Call stream.close
 End If
 
 Exit Sub
errhandle:
 Msgbox Cstr(Erl) & "  " & Error
End Sub

'修改form節點的name屬性值
Sub ChangeNode(childNode2 As NotesDOMNode, str1 As String )
 On Error Goto errhandle
 Dim docNameMap As NotesDOMNamedNodeMap
 Dim childNode3 As NotesDOMNode
 Dim tempNode As NotesDOMNode
 Dim i As Integer
 
 While Not childNode2.IsNull
  If childNode2.NodeType <> 3 Then
   If childNode2.HasChildNodes Then
    Set childNode3 = childNode2.FirstChild
    While Not childNode3.IsNull
     Call ChangeNode(childNode3,str1)
     If Not childNode3.IsNull Then
      Set childNode3 = childNode3.NextSibling
     End If
    Wend
   End If
  End If
  Set docNameMap = childNode2.Attributes
  For i =1 To docNameMap.NumberOfEntries
   Set tempNode = docNameMap.GetItem(i)
   If tempNode.NodeValue = "$$LoginUserForm" Then
    tempNode.NodeValue="$$LoginUserForm_" & str1
    Exit Sub
   End If
  Next
  Set childNode2 = childNode2.NextSibling
 Wend
 Exit Sub
errhandle:
 Msgbox "ChangeNode:" & Cstr(Erl) & "," & Error$
End Sub

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.