用lotusscript动态刷新登录页表单设计

用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

posted @ 2008-12-02 20:21  hannover  阅读(922)  评论(0编辑  收藏  举报