Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub CadastraAnexo_Execute(Batch)
- Dim strFiles
- Dim X
- Dim UltimoArquivo
- Dim IsArray
- Dim api
- Dim id
- Dim n
- Dim nomedoc
- Dim posicao
- Dim props
- Dim fname
- Dim InicioArquivo
- Dim objDocs
- Dim objdoc
- Dim cn
- Dim rs
- Dim objFSO
- Dim txtsaida
- Dim FileFound
- Dim strRev
- Dim posExtensao
- Dim strExtensao
- Dim strNome_Sem_Extensao
- Dim docAnexo
- FileFound = False
- If Not Document Is Nothing Then
- Set api = AMCreateObject("ICMeridianAPI.Connection", True)
- execute("set cn = CreateObject (""ADODB.Connection"")")
- execute("set rs = CreateObject (""ADODB.Recordset"")")
- cn.ConnectionString = ConstringAux_MDB
- cn.Open
- Set objFSO = Createobject("Scripting.FileSystemObject")
- If objFSO.FileExists("F:\log\Log.txt") Then
- Set txtSaida = objFSO.OpenTextFile("F:\log\Log.txt",8,TristateFalse)
- Else
- Set txtSaida = objFSO.CreateTextFile("F:\log\Log.txt",True)
- End If
- rs.open "SELECT * from IMPORT where dbo.IMPORT.[Código unificado] = '" & Document.DadosDeOrigem_CodigoUnificado &"'", cn
- Do Until rs.EOF
- If Not IsNull(rs("Caminho comentário")) And INSTR(1,rs("Caminho comentário"),"-") > 1 Then
- 'If INSTR(1,rs("Caminho comentário"),chr(10)) > 0 Or INSTR(1,rs("Caminho comentário"),chr(13)) Or INSTR(1,rs("Caminho comentário"),"|") > 0 Then
- If INSTR(1,rs("Caminho comentário"),"|") > 0 Then
- strFiles = Split(Replace(Replace(rs("Caminho comentário"),chr(10),""),chr(13),""),"|")
- UltimoArquivo= Ubound(strFiles)
- InicioArquivo=0
- IsArray = True
- Else
- strFiles = Replace(Replace(rs("Caminho comentário"),chr(10),""),chr(13),"")
- UltimoArquivo = 1
- InicioArquivo = 1
- IsArray = False
- End If
- props = api.GetAllPropertyNames(vault.Name)
- For X = InicioArquivo To UltimoArquivo
- If IsArray Then
- nomedoc = split(strFiles(X),"\")
- posicao = ubound(nomedoc)
- nomedoc = split(strFiles(X),"\")(posicao)
- strRev = split(strFiles(X),"\")(posicao - 1)
- strExtensao = FileExtension(nomedoc)
- posExtensao = Instr(1,nomedoc,strExtensao )
- strNome_Sem_Extensao = MID(nomedoc,1,posExtensao-1)
- If objFSO.FileExists(strFiles(X)) Then
- If Not Document.IsUniqueValue("CommonPropertySet._DISPLAYNAME",nomedoc & "-" & strRev & strExtensao) Then
- For Each docAnexo in vault.FindDocuments(nomedoc & "-" & strRev & strExtensao)
- If Not Document.GetReferences("Anexo").Exist (docAnexo.ID) Then
- Document.GetReferences("Anexo").Add (docAnexo.ID)
- Document.ApplyPropertyValues
- End If
- Next
- Else
- id = api.CreateNewDocument(vault.Name , Document.ParentFolder.Path,nomedoc & "-" & strRev & strExtensao,"Anexo",strFiles(X))
- FileFound = True
- End If
- Else
- txtSaida.write rs("Código Unificado") & ";" & Document.NumeroEletronorte & ";" & nomedoc &";"& strFiles(X) & vbCrLf
- FileFound = False
- End If
- Else
- nomedoc = split(strFiles,"\")
- posicao = ubound(nomedoc)
- nomedoc = split(strFiles,"\")(posicao)
- strRev = split(strFiles,"\")(posicao - 1)
- strExtensao = FileExtension(nomedoc)
- posExtensao = Instr(1,nomedoc,strExtensao )
- strNome_Sem_Extensao = MID(nomedoc,1,posExtensao-1)
- If objFSO.FileExists(strfiles) Then
- If Not Document.IsUniqueValue("CommonPropertySet._DISPLAYNAME",nomedoc & "-" & strRev & strExtensao) Then
- For Each docAnexo in vault.FindDocuments(nomedoc & "-" & strRev & strExtensao)
- If Not Document.GetReferences("Anexo").Exist (docAnexo.ID) Then
- Document.GetReferences("Anexo").Add (docAnexo.ID)
- Document.ApplyPropertyValues
- End If
- Next
- Else
- id = api.CreateNewDocument(vault.Name, Document.ParentFolder.Path,nomedoc & "-" & strRev & strExtensao,"Anexo",strFiles)
- FileFound = True
- End If
- Else
- txtSaida.write rs("Código Unificado") & ";" & Document.NumeroEletronorte & ";" & nomedoc &";"& strFiles & vbCrLf
- FileFound = False
- End If
- End If
- 'Para copiar os atributos do documento Pai
- If FileFound Then
- For n = 0 To ubound(props)
- If split (props(n),".")(0) = "Custom" _
- Or split (props(n),".")(0) = "DadosDeOrigem" _
- Or split (props(n),".")(0) = "AMVersionablePropertySet"_
- Or split (props(n),".")(0) = "FieldPath" _
- Or split (props(n),".")(0) = "ECET"_
- Or split (props(n),".")(0) = "EETP"_
- Or split (props(n),".")(0) = "EETS"_
- Or split (props(n),".")(0) = "EETL"_
- Or split (props(n),".")(0) = "BCRenditionPropertySet" Then
- Select Case props(n)
- 'Case "FieldPath.zDir1"
- 'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir1)
- 'Case "FieldPath.zDir2"
- 'Nao faz Nada
- 'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir2)
- 'Case "FieldPath.zDir3"
- 'If Document.FieldPath_zDir0 = "EETP" Then
- ' api.UpdateDocument vault.Name, id,, Array(props(n)), Array("61 - RELATÓRIO DE ÁNALISE TÉCNICA")
- 'ElseIf Document.FieldPath_zDir0 = "EETL" Then
- ' api.UpdateDocument vault.Name, id,, Array(props(n)), Array("43 - Relatório de Ánalise Técnica")
- 'Else
- ' api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.Property(props(n)))
- 'End If
- 'Case "FieldPath.zDir4"
- 'If Document.FieldPath_zDir0 = "ECET" Then
- ' api.UpdateDocument vault.Name, id,, Array(props(n)), Array("RA - Relatório de Análise")
- 'ElseIf Document.FieldPath_zDir0 = "EETS" And Document.FieldPath_zDir1 = "EQUIPAMENTO" Then
- ' api.UpdateDocument vault.Name, id,, Array(props(n)), Array("RAT - Relatório de Ánalise Técnica")
- 'ElseIf Document.FieldPath_zDir0 = "EETS" And Document.FieldPath_zDir1 = "EMPREENDIMENTO" Then
- ' api.UpdateDocument vault.Name, id,, Array(props(n)), Array("RAT - Relatório de Ánalise Técnica")
- 'Else
- ' api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.Property(props(n)))
- 'End If
- 'Case "FieldPath.zDir5"
- 'api.UpdateDocument vault.Name, id,, Array("FieldPath.zDir5"), Array("")
- 'Case "FieldPath.zDir6"
- 'api.UpdateDocument vault.Name, id,, Array("FieldPath.zDir6"), Array("")
- 'Case "FieldPath.zDir1"
- 'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir1)
- 'Case "FieldPath.zDir2"
- 'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir2)
- Case "DadosDeOrigem.Area"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEW AREA"))
- Case "DadosDeOrigem.CodigodaRevisao"
- api.UpdateDocument vault.Name , id,, Array(props(n)), Array(rs("Código da revisão"))
- Case "DadosDeOrigem.CodigoUnificado"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Código unificado"))
- 'Case "DadosDeOrigem.Comentario"
- 'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(CStr(rs("Comentário")))
- Case "DadosDeOrigem.ComentarioMemo"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(CStr(rs("Comentário")))
- Case "DadosDeOrigem.CaminhoComentarioMemo"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(CStr(rs("Caminho comentário")))
- Case "DadosDeOrigem.ComoConstruido"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Como construído"))
- Case "DadosDeOrigem.Destinatario"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Destinatário"))
- Case "DadosDeOrigem.Emissao"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Emissão"))
- Case "DadosDeOrigem.Empresa"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWEMPRESA"))
- Case "DadosDeOrigem.EstruturaFisica"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEW ESTRUTURAFISICA"))
- Case "DadosDeOrigem.Fechamento"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Fechamento"))
- Case "DadosDeOrigem.Natureza"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWNATUREZA"))
- Case "DadosDeOrigem.NumeroEletronorte"
- If Document.DocumentType = "Documentos para Equipamentos EETS" Then
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Código unificado"))
- Else
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Número eletronorte"))
- End If
- Case "DadosDeOrigem.NumeroEmitente"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Número emitente"))
- Case "DadosDeOrigem.Ramo"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWRAMO"))
- Case "DadosDeOrigem.StatusEmissao"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Status Emissão"))
- Case "DadosDeOrigem.TipodeDocumento"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEW TIPO DOCUMENTO"))
- Case "DadosDeOrigem.Titulo"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWTITULO"))
- Case "ECET.Codigo"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(nomedoc)
- Case "EETL.CodManual"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(nomedoc)
- Case "EETP.CodManual"
- api.UpdateDocument vault.Name , id,, Array(props(n)), Array(nomedoc)
- Case "AMVersionablePropertySet._VERSIONNUMBER"
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(MID(strRev,LEN(strRev)-2,LEN(strRev)))
- Case "Custom.DocumentoPai"
- If Document.DocumentType = "Documentos ECET" Then
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.ECET_Codigo)
- End If
- If Document.DocumentType = "Desenho EETP" Then
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.EETP_CodManual)
- End If
- If Document.DocumentType = "Desenho EETL" Then
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.EETL_CodManual)
- End If
- If Document.DocumentType = "Documentos para Empreendimentos EETS" Or Document.DocumentType = "Documentos para Equipamentos EETS" Then
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.EETS_Desenho)
- End If
- Case Else
- If InSTR(1,props(n),"AMVersionablePropertySet") = 0 Then
- api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.Property(props(n)))
- End If
- End Select
- End If
- Next
- If Document.DocumentType = "Documentos ECET" Then
- fname = api.CallVBScript (vault.Name, id, "TrocaTipoDocumentoECET", Empty)
- End If
- If Document.DocumentType = "Desenho EETP" Then
- fname = api.CallVBScript (vault.Name, id, "TrocaTipoDocumentoEETP", Empty)
- End If
- If Document.DocumentType = "Documentos EETL" Then
- fname = api.CallVBScript (vault.Name, id, "TrocaTipoDocumentoEETL", Empty)
- End If
- If Document.DocumentType = "Documentos para Empreendimentos EETS" Then
- fname = api.CallVBScript (vault.Name, id, "TrocaTipoDocumentoEETSEmpr", Empty)
- End If
- If Document.DocumentType = "Documentos para Equipamentos EETS" Then
- fname = api.CallVBScript (vault.Name, id, "TrocaTipoDocumentoEETSEqp", Empty)
- End If
- api.CreateReference vault.Name,Document.GlobalID,id,"Anexo" ' Cria o relacionemnato entre os documento
- End If
- Next
- End If
- 'Next
- rs.movenext
- Loop
- ElseIf Not Folder Is Nothing Then
- 'Insira o seu código para objetos de pasta
- End If
- txtSaida.close
- api.dispose()
- Set api = Nothing
- cn.close
- Set rs = Nothing
- client.Refresh AS_RF_CHANGED_CURRENTFOLDER
- client.Refresh AS_RF_CHANGED_CURRENTVIEW
- End Sub
- Set api = AMCreateObject("ICMeridianAPI.Connection", True)
- id = api.CreateNewDocument(vault.Name , Document.ParentFolder.Path,nomedoc & "-" & strRev & strExtensao,"Anexo",strFiles(X))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement