zoukankan      html  css  js  c++  java
  • 操作Domino数据库的设计元素

    在Domino的数据库中有数据文档和设计文档两种文档。设计文档包括单,视图,代理等,这些组成了
    一个数据库设计。标准的Notes类库能够很容易的访问数据文档,但是却没有提供任何方法来访问设计
    文档。下面的这个DatabaseDesign类可以让我们使用LotusScript来访问设计文档,返回的是NotesDocument
    对象。

    要使用这个类,我们把DBDesign这个script库拷贝到数据库中。
    下面是这个类的代码:

    DatabaseDesign类代码


    创建DatabaseDesign对象的方法

    createDatabaseDesign方法


    我们可以通过类中提供的属性和方法来操作数据库中的设计元素,比如:
    1.使用createDatabaseDesign方法来获取一个DatabaseDesign对象

    Dim session as New NotesSession
    Dim db as NotesDatabase
    Dim dbDesign as DatabaseDesign
    Set db = session.currentDatabase
    Set dbDesign = createDatabaseDesign( db)

    2.通过formDocuments属性来获取所有表单

    Dim forms as variant
    forms 
    = dbDesign.formDocuments

    3.打印出表单的标题

    If Not IsEmpty( forms) Then
    Forall formdoc 
    In forms
    print formdoc.getItemValue( "$Title")(0
    end Forall

    4.通过方法getFormByName获取到指定的表单

    Dim form as NotesDocument
    set form = dbDesign.getFormByName( "MyForm")
    If Not form Is Nothing Then
    'do something with form here
    End If

    5.使用 NotesDocument.copyToDatabase 方法可以拷贝设计元素到其他数据库中

    dim otherdb as new NotesDatabase( "server""file.nsf")
    set form = dbDesign.getFormByName( "FormToCopy")
    If Not form Is Nothing Then
    dim formcopy as NotesDocument
    set formcopy = form.copytodatabase(otherdb)
    call formcopy.save(truetrue)
    End If

    下面一段代码实现使用服务器上指定邮箱模板来更新本地PersonalMailBox的个人邮箱设计:

    Sub Click(Source As Button) 
     
    Dim ss As New NotesSession,ws As New NotesUIWorkspace 
     
    Dim db As NotesDatabase,doc As NotesDocument 
     
    Dim docs As Variant 
            
    '得到personalmailbox的路径 
     Dim   path   As   String   
     path   
    =   ss.getenvironmentstring("directory",True)   
     path
    =path+"\PersonalMailBox\" 
     
            
    '得到当前用户的帐号ID,例如michaelpang 
     namev=ss.UserName 
     namev1
    =Left(namev,Len(namev)-12
     namev2
    =Right(namev1,Len(namev1)-3
     path
    =path+namev2+".nsf" 
     
    Msgbox(path) 
     
     
    Set db = ss.CurrentDatabase 
     
    Set doc = ws.CurrentDocument.Document         
     
    If (Messagebox ("你确定要执行取代设计元素吗?",36,"请确认" )  <> 6 ) Then 
      
    Exit Sub 
     
    End If 
     
     
            
    '清空原始系统的设计原色
     Dim TargetDB As NotesDatabase,TargetDBObj As DatabaseDesign 
     
    Set TargetDB = New NotesDatabase(Local,path) 
     
            
    'If Not TargetDB.IsOpen Then Messagebox "本地邮箱不能打开!!":UpdateBookmark = False :Goto TheEnd 
     Set TargetDBObj = CreateDatabaseDesign(TargetDB)                 
     docs 
    = TargetDBObj.Alldesigndocuments 
     
    If Not Isempty( docs)  Then 
      
    Print "准备删除原始设计文件,共计 " + Cstr(Ubound(docs)+1" 份文件!!" 
      Forall x 
    In docs 
       x.Remove(
    True
      
    End Forall         
      
    Print "完成刪除原系统设计文件!!" 
     
    Else 
      
    Print "原系统已无设计文件!!!" 
     
    End If 
            
    '取得新系统设计文件         
     Dim SourceDB As NotesDatabase,SourceDBObj As DatabaseDesign 
     
    Set SourceDB = New NotesDatabase("testmail02/testserver","mail\michaelpang .nsf"
            
    'If Not SourceDB.IsOpen Then Print "Source DataBase can't open!!":UpdateBookmark = False :Goto TheEnd 
     Set SourceDBObj = CreateDatabaseDesign(SourceDB)         
     docs 
    = SourceDBObj.Alldesigndocuments 
     
    Print  "准备更新系统设计文件,共技 " + Cstr(Ubound(docs)+1" 份文件!!" 
            
    ' 
            '复制设计到目的系统 
     Forall y In docs 
      
    Call y.CopyToDatabase(TargetDB) 
     
    End Forall 
     Messagebox 
    "完成复制设计文件!!" 
    TheEnd: 
     
    Exit Sub 
     
    End Sub
     

    注意:1.使用这段代码的时候,需要将服务器上的模板的软删除功能关闭(”数据库---属性---高级---允许软删除“前的复选框勾掉),否则
    多人同时运行这段代码的时候会出现“Notes error:someone else modified this document at the same time”的错误提示。
    2.上面的方法把原来的设计删除了,又拷贝了新的设计,这样设计的文档ID就变了。

  • 相关阅读:
    手机APP远程空气质量监测应用
    SPI
    2017-10-14
    常量声明
    ios- nil NULL 和 NSNull
    Xcode搭建真机调试环境 图文实例
    ios notification
    集合对象总结
    集合对象(NSSet,NSMutableSet,NSIndexSet)
    词典对象(NSDictionary和NSMutableDictionary)
  • 原文地址:https://www.cnblogs.com/hannover/p/2065206.html
Copyright © 2011-2022 走看看