19. Notes客户机中的校验
来源:互联网 发布:2017年最污的网络热词 编辑:程序博客网 时间:2024/05/21 06:59
在开发传统Notes客户机应用时,校验是最常见的功能需求之一。在检查一张表单的输入时,能够使用的方法和呈现给用户的方式很有限。一般我们不会使用域的输入验证公式,因为那样做太分散、重复又不够灵活。更好的方案是将所有的检查集中在一起,在文档保存或者执行某个操作时调用。校验有可能包含对输入做各种检查,最普遍的还是简单的非空性检查。对此,我们可以写一个简单的校验类:
Private Const MESSAGE="Please input the field "Public Class ValidatorPrivate fields List As StringPrivate m_uidoc As NotesUIDocumentPrivate m_doc As NotesDocumentPublic Sub new()Dim ws As New NotesUIWorkspaceSet m_uidoc=ws.CurrentDocumentSet m_doc=m_uidoc.DocumentEnd SubPublic Sub Add(fieldName As String,label As String)If label="" Thenlabel=fieldNameEnd Iffields(label)=fieldNameEnd SubPublic Function Validate() As BooleanForall f In fieldsIf m_uidoc.FieldGetText(f)="" ThenMessagebox MESSAGE & {"} & Listtag(f) & {"},64,"Lotus Notes"If m_uidoc.EditMode ThenCall m_uidoc.GotoField(f)End IfValidate=FalseExit FunctionEnd IfEnd ForallValidate=TrueEnd FunctionEnd Class
在这个类中,Add()方法像要检查的域名和对应的对用户的名称添加到一个List中。Validate()方法检查这些域的值是否为空;如果是,则给用户一个提示,将焦点转移到该域中,并返回False;如果所有域值都不为空,就返回True。这样调用的程序就可以根据Validate()方法的结果判断是否继续执行以后的逻辑。
下面这段代码就是在一个文档的Querysave事件中根据条件添加了若干个需要校验的域,并且根据校验的结果决定是否保存文档。
Sub Querysave(Source As NotesUIDocument, Continue As Variant)Dim validator1 As New Validator()With validator1Call .Add("ActionName","Action Name")Call .Add("NodeName","Node Name")If Source.FieldGetText("MultipleNext")="" ThenCall .Add("NextNode","Next Node")End IfIf source.FieldGetText("NeedExpression")><"" ThenCall .Add("Expression", "Action Expression")End IfIf Source.FieldGetText("NeedMail")="1" ThenCall .Add("Subject","Mail Subject")End IfEnd WithIf Not validator1.Validate() ThenContinue=FalseEnd IfEnd Sub
上面的校验都是针对普通域,如果要校验一个富文本域(RichTextItem)是否包含附件,就必须先保存当前Notes文档,然后可以使用下列函数:
Public Function CheckRTFAttachment(curDoc As NotesDocument,fieldName As String) As Boolean'fieldnum is the index of RTF item name in the CheckItems arrayCheckRTFAttachment=FalseDim vChkItem As VariantDim vObject As VariantDim intObject As IntegerSet vChkItem=curDoc.GetFirstItem(fieldName)vObject=vChkItem.EmbeddedObjectsIf Not IsEmpty(vObject) Then For intObject=0 To UBound(vObject)If vObject(intObject).Type=1454 Then'1454 means attachmentCheckRTFAttachment=TrueExit FunctionEnd IfNextEnd IfEnd Function
函数参数中的curDoc为包含要校验的富文本域的文档,fieldName为域名。如果包含附件则返回True;反之False。
- 19. Notes客户机中的校验
- notes中的 "+" and "&"
- 和Notes有关的跨系统的密码校验
- 导出lotus notes中的数据
- Lotus Domino/Notes 中的安全技术
- Struts2中的输入校验
- Struts2中的校验框架
- Struts中的校验框架
- Struts2中的校验框架
- Struts2中的校验框架
- Struts2中的校验框架
- Struts2中的校验器
- Struts2中的校验框架
- C#中的crc16校验
- struts2中的校验器
- struts2_12_struts2中的输入校验
- 去掉Myeclipse中的校验
- Rails中的validate校验
- 单例
- 旋转卡壳小结
- Java_TCPIP_Socket编程(doc)下载
- 他隐藏的最深!!白夜行中的秋吉雄一!!!
- 转自沈乐杨的新浪博客----秋吉雄一
- 19. Notes客户机中的校验
- office 2010 安装出错
- javascript 实例:评分系统
- 找出数组中唯一出现一次的数
- 求二叉树的镜像
- A10开篇之作
- 那些年我们一起学的汇编----之寻址方式
- ASP.NET MVC4 中整合 NHibernate3.3、Spring.NET2.0、ExtJS4 笔记一:简介
- 轻量级jQuery图片放大镜插件 - mlens