一个应用中常常有各种配置数据,比如报销科目、数据库路径、审批人员等等。在Lotus Notes中可以很方便地维护和引用这些配置数据。每一个稍有经验的Notes程序员都会按自己的喜好开发出这样的功能,然后反复使用。其基本设计都差不多,只需要一个表单和一个视图,再加上从其它地方引用的公式,这里给新手介绍的就是。
表单和视图等设计元素本来不好用文本的形式表现,虽然可以导出到XML,但是导入恢复还需要专门写程序,保真程度也有待提高。不过从8.5版本开始Designer带有了Edit with XML的功能,在Database Navigator里选中一个设计元素,右键菜单里就有这一项,编辑XML时可以随时保存并切换到设计视图检查。于是我就将表单和视图的XML粘贴在此。我使用的Designer版本是9.0,所以DXL的版本也是9.0,不过估计在8.5里使用也没问题。表单的XML:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE form SYSTEM 'xmlschemas/domino_9_0.dtd'> <form name='Keyword' alias='Keyword' xmlns='http://www.lotus.com/dxl' version='9.0' replicaid='482572F200128E23' nocompose='true' publicaccess='false' designerversion='8.5.3' comment='ScriptLib2' renderpassthrough='true'> <noteinfo noteid='6a2' unid='9935C1845F4576E248257ACA002F815F' sequence='1'> <created><datetime>20121204T163853,11+08</datetime></created> <modified><datetime>20121204T163856,54+08</datetime></modified> <revised><datetime>20121204T163856,53+08</datetime></revised> <lastaccessed><datetime>20121204T163856,54+08</datetime></lastaccessed> <addedtofile><datetime>20121204T163856,54+08</datetime></addedtofile></noteinfo> <updatedby><name>CN=Starrow Pan/OU=ABC/O=ABC</name></updatedby> <wassignedby><name>CN=Starrow Pan/OU=ABC/O=ABC</name></wassignedby> <globals><code event='options'><lotusscript>Option Public Option Declare Use "Commons" </lotusscript></code></globals><code event='windowtitle'><formula>"Keyword"</formula></code><code event='querysave'><lotusscript>Sub Querysave(Source As Notesuidocument, Continue As Variant) Dim validator1 As New Validator() With validator1 Call .Add("Keyword","Keyword") Call .Add("Values","Values") End With If Not validator1.Validate() Then continue=False End If End Sub</lotusscript></code> <actionbar bgcolor='#ece9d8' bordercolor='black'> <actionbuttonstyle bgcolor='#ece9d8'/><font color='system'/><border style='solid' width='0px 0px 1px'/> <sharedactionref id='1'> <action title='Close' icon='112' hide='preview previewedit'><code event='click'><formula >@Command([FileCloseWindow])</formula></code></action></sharedactionref> <sharedactionref id='2'> <action title='Save' icon='117' hide='preview read previewedit'><code event='click'><formula >@Command([FileSave])</formula></code></action></sharedactionref></actionbar> <body><richtext> <pardef id='1' hide='notes'/> <par def='1'><run><font color='red'/>Reader:</run><field type='readers' kind='editable' name='Readers'><code event='defaultvalue'><formula>"*"</formula></code></field><run ><font color='red'/></run></par> <par def='1'><run><font color='red'/>Writers:</run><field type='authors' kind='editable' name='Writers'><code event='defaultvalue'><formula>"[Admin]"</formula></code></field></par> <par def='1'/> <pardef id='2'/> <par def='2'>Keyword</par> <par def='2'/> <table widthtype='fitmargins' refwidth='6.7292in'><tablecolumn width='24.8299%'/><tablecolumn width='75.1701%'/> <tablerow> <tablecell borderwidth='1px 0px'> <pardef id='4' keepwithnext='true' keeptogether='true'/> <par def='4'>Status:</par></tablecell> <tablecell borderwidth='1px 0px'> <pardef id='5' keepwithnext='true' keeptogether='true'/> <par def='5'><field borderstyle='none' lookupeachchar='false' lookupaddressonrefresh='false' type='keyword' kind='editable' name='Status'><keywords helperbutton='false' columns='2' ui='radiobutton'><textlist><text>Active</text><text>Inactive</text></textlist></keywords><code event='defaultvalue'><formula>"Active"</formula></code></field></par></tablecell></tablerow> <tablerow> <tablecell borderwidth='1px 0px'> <par def='4'><run><font color='red'/>*</run>Keyword:</par></tablecell> <tablecell borderwidth='1px 0px'> <par def='5'><field type='text' kind='editable' name='Keyword'/><compositedata type='98' prevtype='65418' nexttype='222' afterparcount='6' containertype='65418' aftercontainercount='1' afterbegincount='3'> Yg4BAIQAAAAAAAAAAAA= </compositedata></par></tablecell></tablerow> <tablerow> <tablecell borderwidth='1px 0px'> <par def='4'><run><font color='red'/>*</run>Values:</par></tablecell> <tablecell borderwidth='1px 0px'> <par def='5'><field type='text' allowmultivalues='true' kind='editable' name='Values' listinputseparators='newline' listdisplayseparator='newline'/><compositedata type='98' prevtype='65418' nexttype='222' afterparcount='6' containertype='65418' aftercontainercount='1' afterbegincount='3'> Yg4BAIQAAAAAAAAAAAA= </compositedata> <run><font style='italic' color='gray'/>separate multiple values with new line</run></par></tablecell></tablerow></table> <par def='2'/></richtext></body> <item name='$$ScriptName' summary='false' sign='true'><text>Keyword</text></item></form>
上面的代码前面的部分是关于表单的基本信息,比如名称、修改时间和签名。将从<globals><code event='options'><lotusscript>OptionPublic这一行开始替换掉你的表单里对应的部分。运气好的话,在设计视图你看到的就和我的一样了。其实这个表单也很简单。一个读者域,保证所有人都能读。一个作者域,使得特定角色的人才能写。一个Status域,可以选择此设置文档为Active或Inactive。一个Keyword域,标记用于查找此设置的关键字。一个Values域,用于保存对应于关键字的数据。表单因用Commons脚本库,包含用于校验的Validator类。
视图的XML:
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE view SYSTEM 'xmlschemas/domino_9_0.dtd'> <view name='Configuration\Keyword' alias='vwKeyValues' xmlns='http://www.lotus.com/dxl' version='9.0' replicaid='482572F200128E23' showinmenu='false' publicaccess='false' designerversion='8.5.3' comment='ScriptLib2' unreadmarks='none' onopengoto='lastopened' onrefresh='displayindicator' headers='beveled' opencollapsed='false' showresponsehierarchy='true' showmargin='true' shrinkrows='true' extendlastcolumn='true' showhierarchies='false' unreadcolor='black' rowlinecount='9' headerlinecount='1' rowspacing='1' bgcolor='white' totalscolor='black' headerbgcolor='white' boldunreadrows='false' evaluateactions='false' allownewdocuments='false' allowcustomizations='true' hidemarginborder='false' marginwidth='0px' marginbgcolor='white' uniquekeys='false'> <noteinfo noteid='69e' unid='53B3CDFD583CA93B48257ACA002F31F5' sequence='1'> <created><datetime>20121204T163529,81+08</datetime></created> <modified><datetime>20121204T163531,15+08</datetime></modified> <revised><datetime>20121204T163531,14+08</datetime></revised> <lastaccessed><datetime>20121204T163531,15+08</datetime></lastaccessed> <addedtofile><datetime>20121204T163531,15+08</datetime></addedtofile></noteinfo> <updatedby><name>CN=Starrow Pan/OU=ABC/O=ABC</name></updatedby> <wassignedby><name>CN=Starrow Pan/OU=ABC/O=ABC</name></wassignedby><code event='selection'><formula>SELECT Form="Keyword"</formula></code> <actionbar bgcolor='#ece9d8' bordercolor='black'> <actionbuttonstyle bgcolor='#ece9d8'/><font color='system'/><border style='solid' width='0px 0px 1px'/> <action title='New' icon='5'><code event='click'><formula>@Command([Compose];"";"Keyword")</formula></code><code event='hidewhen'><formula>@IsNotMember("[Admin]";@UserRoles)</formula></code></action></actionbar> <column sort='ascending' hidedetailrows='false' itemname='Keyword' width='10' resizable='true' separatemultiplevalues='true' sortnoaccent='true' sortnocase='true' showaslinks='false'><font color='#2f2f2f' name='Arial' pitch='variable' truetype='true' familyid='20'/><columnheader title='Keyword'><font size='9pt' style='bold' name='Helvetica' truetype='false' familyid='0'/></columnheader></column> <column hidedetailrows='false' itemname='Values' width='31.2500' resizable='true' separatemultiplevalues='false' sortnoaccent='false' sortnocase='true' showaslinks='false'><font color='#2f2f2f' name='Arial' pitch='variable' truetype='true' familyid='20'/><columnheader title='Values'><font size='9pt' style='bold' name='Helvetica' truetype='false' familyid='0'/></columnheader></column> <column hidedetailrows='false' itemname='Status' width='10' resizable='true' separatemultiplevalues='false' sortnoaccent='false' sortnocase='true' showaslinks='false'><font color='#2f2f2f' name='Arial' pitch='variable' truetype='true' familyid='20'/><columnheader title='Status'><font size='9pt' style='bold'/></columnheader></column></view>
同样<code
event='selection'><formula>SELECT Form="Keyword"</formula></code>之前的是基本信息和视图选项,将之后的部分替换掉你的视图的对应部分。视图的第一列是对应Keyword域的排序列,第二列对应Values域。
之后,在其它表单的选择型字段的选项公式里就可以写上类似这样的公式引用配置的数据:
list:=@DbLookup("";"";"vwKeyValues";"Education";2);
@If(@IsError(list);"";list)