文档附件更新和追加接口代码
需求描述:
客户管理中销售报价更新后,需要在销售立项中展示最新的报价信息,包括最新的报价文件附件信息。销售报价信息发布后,需更新主文档的相关信息以及附件。
解决方案:
标准的附件接口无法满足,后台附件的替换和更新需求,需要编写附件更新接口,满足实际的业务。
前置条件:
1、表单中必须引入附件相关子表单
A.附件上载 | SF_AttachmentOCX
2、部署附件时,需要指定附件的序号,不指定控件会自动分派,减少不安定因素,约定好
例如:AttachmentObject.Create(9);
相关接口程序:
Function Attach_CopyAttach(orgDoc As notesDocument,desDoc As notesDocument,orgAttIndex As String,desAttIndex As String,replaceAtt As String) As String
'===========================================
'
'功 能:拷贝当前指点标签下的附件到指定文档中
'作 者:庄伟斌
'日 期:2012/09/25
'描 述 : 报价管理过程中立项文档和报价文档的附件拷贝
'版 本:1.0
'接口:
' orgDoc 源文档
' desDoc 目标文档
' orgAttIndex 源文档附件组ID
' desAttIndex 目标文档附件组ID
' replaceAtt 是否删除目标文档的原有附件 ' 1:删除原有; 其它值:追加到附件列表中
'===========================================
On Error Goto errhandle
%REM
1、检测源文档,是否部署附件机制,如F_AttachmentList不存在,退出
2、F_AttachmentList存在,解析F_AttachmentList(2|abc.doc)中,是否存在attachindex的信息,不存在,退出
3、存在,新建临时文档,将源文档的附件$file的信息拷贝过来,通过2中解析的附件名称队列,将无关的附件删除
4、拷贝临时文档的附件至目标文档中,设置F_AttachmentList,将新增的附件进行补充,end~
%END REM
Dim copyOrgAList As Variant '源文档需要拷贝的附件 1|abc.doc
Dim otherOrgAList As Variant '源文档无需拷贝的附件 2|abc.doc
Dim copyDesAList As Variant '目标文档待替换的附件 1|abc.doc
Dim otherDesAList As Variant '目标文档无需替换的附件 2|abc.doc
Dim flagstr As String
Dim tmpList As Variant
Dim attachobj As NotesEmbeddedObject
If orgDoc Is Nothing Or desDoc Is Nothing Then Exit Function
'检测是否不出附件机制
If Not orgDoc.HasItem("F_AttachmentList") Then Exit Function
Call Attach_GetAttachInfo(copyOrgAList ,otherOrgAList,orgDoc,orgAttIndex)
Call Attach_GetAttachInfo(copyDesAList ,otherDesAList,desDoc,desAttIndex)
If Isempty(copyOrgAList) Then Goto exitfun '无需处理的附件,直接退出
'生成一个临时文档,将源文档的信息拷贝一份
Dim tDoc As notesdocument '临时文档
Set tDoc = desDoc.Parentdatabase.createdocument()
Call orgDoc.CopyAllItems(tDoc,False)
'只保留附件信息,清除其他信息
Forall v In tDoc.Items
If v.Name <> "$FILE" Then
Call v.Remove
End If
End Forall
'处理掉不需要的附件信息,根据其他附件列表
If Not Isempty(otherOrgAList) Then
Forall k In otherOrgAList
If Len(k) > 0 Then
tmpList = Split(k,"|")
Set attachobj = tDoc.GetAttachment(tmpList(1))
If Not attachobj Is Nothing Then
Call attachobj.Remove
End If
End If
End Forall
End If
'如果需要替换,先把对附件组件ID的附件删除,再将临时文档中的附件拷贝过来,减少附件重名
If replaceAtt = "1" Then
Forall z In copyDesAList
tmpList = Split(z,"|")
Set attachobj = desDoc.GetAttachment(tmpList(1))
If Not attachobj Is Nothing Then
Call attachobj.Remove
End If
End Forall
End If
Call tDoc.CopyAllItems(desDoc,False)
If Isempty(otherDesAList) Then
flagstr = Join(copyOrgAList,":")
Else
flagstr = Join(copyOrgAList,":") & ":" & Join(otherDesAList,":")
End If
desDoc.F_AttachmentList = flagstr
Call DocumentSave(desDoc,"",True)
Set Tdoc = Nothing
Attach_CopyAttach = ""
Exit Function
exitfun:
Attach_CopyAttach = ""
Exit Function
errhandle:
Msgbox "error:Attach_CopyAttach()" & Erl() & Error()
Resume exitfun
End Function
Function Attach_GetAttachInfo(surceList As Variant , otherList As Variant,orgDoc As NotesDocument,attachIndex As String)
'===========================================
'
'功 能:解析目标文档中的附件信息,返回目标附件、其他附件信息
'作 者:庄伟斌
'日 期:2012/09/26
'描 述 : 解析文档中的附件信息,分门别类
'接口:
' surceList 所需附件列表
' otherList 无关附件列表
' orgDoc 源文档
' attachIndex 源文档附件组ID
'版 本:1.0
'===========================================
On Error Goto errhandle
Dim attachList As Variant
Dim copyattachList() As String '需要拷贝的文档列表
Dim i As Integer
Dim flagstr As String
Dim tmp(1) As String
tmp(0)=""
If Len(orgDoc.F_AttachmentList(0)) = 0 Then Goto exitfun
attachList = Split(orgDoc.F_AttachmentList(0),":")
'分析附件列表,解析出所需的附件信息
i=-1
Forall x In attachList
flagstr=Attach_IsInString(Cstr(x), attachIndex+"|")
If flagstr = "in" Then
i=i+1
Redim copyattachList(i)
copyattachList(i) = x
x=""
End If
End Forall
'解析出无需处理的附件信息列表
attachList=Com_ArrayDelete(attachList, c
补充:综合编程 , 其他综合 ,