Advertisement
Guest User

Untitled

a guest
Feb 16th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 16.69 KB | None | 0 0
  1. Sub CadastraAnexo_Execute(Batch)
  2.  
  3.         Dim strFiles
  4.         Dim X
  5.         Dim UltimoArquivo
  6.         Dim IsArray
  7.         Dim api
  8.         Dim id
  9.         Dim n
  10.         Dim nomedoc
  11.         Dim posicao
  12.         Dim props
  13.         Dim fname
  14.         Dim InicioArquivo
  15.         Dim objDocs
  16.         Dim objdoc
  17.         Dim cn
  18.         Dim rs
  19.         Dim objFSO
  20.         Dim txtsaida
  21.         Dim FileFound
  22.         Dim strRev
  23.         Dim posExtensao
  24.         Dim strExtensao
  25.         Dim strNome_Sem_Extensao
  26.         Dim docAnexo
  27.        
  28.    
  29.  
  30.  
  31.     FileFound = False
  32.     If Not Document Is Nothing Then
  33.       Set api = AMCreateObject("ICMeridianAPI.Connection", True)
  34.         execute("set cn = CreateObject (""ADODB.Connection"")")  
  35.         execute("set rs = CreateObject (""ADODB.Recordset"")")
  36.         cn.ConnectionString = ConstringAux_MDB
  37.         cn.Open
  38.        
  39.       Set objFSO = Createobject("Scripting.FileSystemObject")
  40.       If objFSO.FileExists("F:\log\Log.txt") Then
  41.         Set txtSaida = objFSO.OpenTextFile("F:\log\Log.txt",8,TristateFalse)
  42.        Else
  43.         Set txtSaida = objFSO.CreateTextFile("F:\log\Log.txt",True)
  44.        End If
  45.        
  46.       rs.open "SELECT * from IMPORT where dbo.IMPORT.[Código unificado] = '" & Document.DadosDeOrigem_CodigoUnificado &"'", cn
  47.  
  48.       Do Until rs.EOF
  49.      If Not IsNull(rs("Caminho comentário")) And  INSTR(1,rs("Caminho comentário"),"-") > 1  Then
  50.        '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
  51.       If INSTR(1,rs("Caminho comentário"),"|") > 0  Then
  52.             strFiles = Split(Replace(Replace(rs("Caminho comentário"),chr(10),""),chr(13),""),"|")
  53.             UltimoArquivo= Ubound(strFiles)
  54.             InicioArquivo=0
  55.             IsArray = True
  56.  
  57.         Else
  58.             strFiles = Replace(Replace(rs("Caminho comentário"),chr(10),""),chr(13),"")
  59.             UltimoArquivo = 1
  60.             InicioArquivo = 1
  61.             IsArray = False
  62.         End If
  63.        
  64.        
  65.             props = api.GetAllPropertyNames(vault.Name)
  66.  
  67.  
  68.       For X = InicioArquivo To UltimoArquivo
  69.        If IsArray Then
  70.             nomedoc = split(strFiles(X),"\")
  71.             posicao = ubound(nomedoc)
  72.             nomedoc = split(strFiles(X),"\")(posicao)
  73.             strRev = split(strFiles(X),"\")(posicao - 1)
  74.             strExtensao = FileExtension(nomedoc)
  75.  
  76.             posExtensao = Instr(1,nomedoc,strExtensao )
  77.             strNome_Sem_Extensao = MID(nomedoc,1,posExtensao-1)
  78.             If objFSO.FileExists(strFiles(X)) Then
  79.                 If Not Document.IsUniqueValue("CommonPropertySet._DISPLAYNAME",nomedoc & "-" & strRev & strExtensao) Then
  80.                     For Each docAnexo in vault.FindDocuments(nomedoc & "-" & strRev & strExtensao)
  81.                         If Not Document.GetReferences("Anexo").Exist (docAnexo.ID) Then
  82.                             Document.GetReferences("Anexo").Add (docAnexo.ID)
  83.                             Document.ApplyPropertyValues
  84.                         End If
  85.                      Next                  
  86.                 Else
  87.                     id = api.CreateNewDocument(vault.Name , Document.ParentFolder.Path,nomedoc & "-" & strRev & strExtensao,"Anexo",strFiles(X))
  88.                     FileFound = True
  89.                 End If
  90.             Else
  91.                 txtSaida.write rs("Código Unificado") & ";" & Document.NumeroEletronorte & ";" & nomedoc &";"& strFiles(X) & vbCrLf
  92.                 FileFound = False
  93.            End If
  94.            
  95.         Else
  96.             nomedoc = split(strFiles,"\")
  97.             posicao = ubound(nomedoc)
  98.             nomedoc = split(strFiles,"\")(posicao)
  99.             strRev = split(strFiles,"\")(posicao - 1)
  100.             strExtensao = FileExtension(nomedoc)
  101.  
  102.             posExtensao = Instr(1,nomedoc,strExtensao )
  103.             strNome_Sem_Extensao = MID(nomedoc,1,posExtensao-1)
  104.            If objFSO.FileExists(strfiles) Then
  105.                 If Not Document.IsUniqueValue("CommonPropertySet._DISPLAYNAME",nomedoc & "-" & strRev & strExtensao) Then
  106.                    For Each docAnexo in vault.FindDocuments(nomedoc & "-" & strRev & strExtensao)
  107.                         If Not Document.GetReferences("Anexo").Exist (docAnexo.ID) Then
  108.                             Document.GetReferences("Anexo").Add (docAnexo.ID)
  109.                             Document.ApplyPropertyValues
  110.                         End If
  111.                      Next
  112.                 Else
  113.                     id = api.CreateNewDocument(vault.Name, Document.ParentFolder.Path,nomedoc & "-" & strRev & strExtensao,"Anexo",strFiles)
  114.                     FileFound = True  
  115.                 End If
  116.            Else
  117.                txtSaida.write rs("Código Unificado") & ";" & Document.NumeroEletronorte & ";" & nomedoc &";"& strFiles & vbCrLf
  118.                FileFound = False
  119.            End If
  120.          
  121.         End If
  122.              'Para copiar os atributos do documento Pai
  123.             If FileFound Then
  124.                 For n = 0 To ubound(props)
  125.                             If split (props(n),".")(0) = "Custom" _
  126.                                 Or split (props(n),".")(0) = "DadosDeOrigem" _
  127.                                 Or split (props(n),".")(0) = "AMVersionablePropertySet"_
  128.                                 Or split (props(n),".")(0) = "FieldPath" _
  129.                                 Or split (props(n),".")(0) = "ECET"_
  130.                                 Or split (props(n),".")(0) = "EETP"_
  131.                                 Or split (props(n),".")(0) = "EETS"_
  132.                                 Or split (props(n),".")(0) = "EETL"_
  133.                                 Or split (props(n),".")(0) = "BCRenditionPropertySet" Then
  134.                                 Select Case props(n)
  135.                                     'Case "FieldPath.zDir1"
  136.                                         'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir1)
  137.                                    'Case "FieldPath.zDir2"
  138.                                         'Nao faz Nada
  139.                                         'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir2)
  140.                                    'Case "FieldPath.zDir3"
  141.                                         'If Document.FieldPath_zDir0 = "EETP" Then
  142.                                         '   api.UpdateDocument vault.Name, id,, Array(props(n)), Array("61 - RELATÓRIO DE ÁNALISE TÉCNICA")
  143.                                        'ElseIf Document.FieldPath_zDir0 = "EETL" Then
  144.                                         '   api.UpdateDocument vault.Name, id,, Array(props(n)), Array("43 - Relatório de Ánalise Técnica")
  145.                                         'Else  
  146.                                        '   api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.Property(props(n)))
  147.                                        'End If
  148.                                    'Case "FieldPath.zDir4"
  149.                                         'If Document.FieldPath_zDir0 = "ECET" Then
  150.                                         '   api.UpdateDocument vault.Name, id,, Array(props(n)), Array("RA - Relatório de Análise")
  151.                                        'ElseIf Document.FieldPath_zDir0 = "EETS" And Document.FieldPath_zDir1 = "EQUIPAMENTO" Then
  152.                                         '   api.UpdateDocument vault.Name, id,, Array(props(n)), Array("RAT - Relatório de Ánalise Técnica")
  153.                                        'ElseIf Document.FieldPath_zDir0 = "EETS" And Document.FieldPath_zDir1 = "EMPREENDIMENTO" Then
  154.                                            
  155.                                         '   api.UpdateDocument vault.Name, id,, Array(props(n)), Array("RAT - Relatório de Ánalise Técnica")
  156.                                         'Else  
  157.                                        '    api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.Property(props(n)))
  158.                                        'End If                                  
  159.                                    'Case "FieldPath.zDir5"
  160.                                         'api.UpdateDocument vault.Name, id,, Array("FieldPath.zDir5"), Array("")
  161.                                    'Case "FieldPath.zDir6"
  162.                                         'api.UpdateDocument vault.Name, id,, Array("FieldPath.zDir6"), Array("")
  163.  
  164.                                     'Case "FieldPath.zDir1"
  165.                                         'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir1)
  166.                                    'Case "FieldPath.zDir2"
  167.                                         'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.FieldPath_zDir2)    
  168.                                    Case  "DadosDeOrigem.Area"
  169.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEW AREA"))
  170.                                     Case  "DadosDeOrigem.CodigodaRevisao"
  171.                                         api.UpdateDocument vault.Name , id,, Array(props(n)), Array(rs("Código da revisão"))
  172.                                     Case  "DadosDeOrigem.CodigoUnificado"
  173.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Código unificado"))
  174.                                     'Case  "DadosDeOrigem.Comentario"
  175.                                         'api.UpdateDocument vault.Name, id,, Array(props(n)), Array(CStr(rs("Comentário")))
  176.                                    Case  "DadosDeOrigem.ComentarioMemo"
  177.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(CStr(rs("Comentário")))
  178.                                     Case  "DadosDeOrigem.CaminhoComentarioMemo"
  179.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(CStr(rs("Caminho comentário")))    
  180.                                     Case  "DadosDeOrigem.ComoConstruido"
  181.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Como construído"))
  182.                                     Case  "DadosDeOrigem.Destinatario"
  183.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Destinatário"))
  184.                                     Case  "DadosDeOrigem.Emissao"
  185.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Emissão"))
  186.                                     Case  "DadosDeOrigem.Empresa"
  187.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWEMPRESA"))
  188.                                     Case  "DadosDeOrigem.EstruturaFisica"
  189.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEW ESTRUTURAFISICA"))
  190.                                     Case  "DadosDeOrigem.Fechamento"
  191.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Fechamento"))
  192.                                     Case  "DadosDeOrigem.Natureza"
  193.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWNATUREZA"))
  194.                                     Case  "DadosDeOrigem.NumeroEletronorte"
  195.                                         If Document.DocumentType = "Documentos para Equipamentos EETS" Then
  196.                                             api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Código unificado"))
  197.                                         Else
  198.                                             api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Número eletronorte"))
  199.                                         End If
  200.                                        
  201.                                     Case  "DadosDeOrigem.NumeroEmitente"
  202.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Número emitente"))
  203.                                     Case  "DadosDeOrigem.Ramo"
  204.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWRAMO"))
  205.                                     Case  "DadosDeOrigem.StatusEmissao"
  206.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("Status Emissão"))
  207.                                     Case  "DadosDeOrigem.TipodeDocumento"
  208.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEW TIPO DOCUMENTO"))
  209.                                     Case  "DadosDeOrigem.Titulo"
  210.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(rs("NEWTITULO"))  
  211.                                      
  212.                                     Case  "ECET.Codigo"
  213.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(nomedoc)
  214.                                     Case  "EETL.CodManual"
  215.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(nomedoc)
  216.                                     Case  "EETP.CodManual"
  217.                                         api.UpdateDocument vault.Name , id,, Array(props(n)), Array(nomedoc)
  218.                                     Case  "AMVersionablePropertySet._VERSIONNUMBER"
  219.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(MID(strRev,LEN(strRev)-2,LEN(strRev)))
  220.                                     Case  "Custom.DocumentoPai"
  221.                                         If Document.DocumentType = "Documentos ECET" Then
  222.                                             api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.ECET_Codigo)
  223.                                         End If
  224.                                         If Document.DocumentType = "Desenho EETP" Then
  225.                                             api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.EETP_CodManual)
  226.                                         End If
  227.                                         If Document.DocumentType = "Desenho EETL" Then
  228.                                             api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.EETL_CodManual)
  229.                                         End If
  230.                                          If Document.DocumentType = "Documentos para Empreendimentos EETS" Or Document.DocumentType = "Documentos para Equipamentos EETS"  Then
  231.                                             api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.EETS_Desenho)
  232.                                         End If                                    
  233.                                     Case Else
  234.                                        If InSTR(1,props(n),"AMVersionablePropertySet") = 0 Then
  235.                                         api.UpdateDocument vault.Name, id,, Array(props(n)), Array(Document.Property(props(n)))
  236.                                        End If
  237.                                 End Select                              
  238.                                    
  239.                              End If
  240.                         Next
  241.                                              
  242.                         If Document.DocumentType = "Documentos ECET" Then
  243.                             fname = api.CallVBScript (vault.Name, id,  "TrocaTipoDocumentoECET", Empty)
  244.                         End If
  245.                        
  246.                         If Document.DocumentType = "Desenho EETP" Then
  247.                             fname = api.CallVBScript (vault.Name, id,  "TrocaTipoDocumentoEETP", Empty)
  248.                         End If                        
  249.                         If Document.DocumentType = "Documentos EETL" Then
  250.                             fname = api.CallVBScript (vault.Name, id,  "TrocaTipoDocumentoEETL", Empty)
  251.                         End If                        
  252.  
  253.                         If Document.DocumentType = "Documentos para Empreendimentos EETS" Then
  254.                             fname = api.CallVBScript (vault.Name, id,  "TrocaTipoDocumentoEETSEmpr", Empty)
  255.                         End If                        
  256.  
  257.                         If Document.DocumentType = "Documentos para Equipamentos EETS" Then
  258.                             fname = api.CallVBScript (vault.Name, id,  "TrocaTipoDocumentoEETSEqp", Empty)
  259.                         End If                        
  260.  
  261.                         api.CreateReference vault.Name,Document.GlobalID,id,"Anexo" ' Cria o relacionemnato entre os documento
  262.  
  263.        End If
  264.        Next
  265.        
  266.        End If
  267.      'Next
  268.     rs.movenext
  269.       Loop
  270.      
  271.        
  272.     ElseIf Not Folder Is Nothing Then
  273.         'Insira o seu código para objetos de pasta
  274.     End If
  275.    
  276.     txtSaida.close
  277.     api.dispose()
  278.     Set api = Nothing
  279.     cn.close
  280.     Set rs = Nothing
  281.  
  282.      client.Refresh AS_RF_CHANGED_CURRENTFOLDER
  283.      client.Refresh AS_RF_CHANGED_CURRENTVIEW
  284.    
  285.    
  286.  
  287. End Sub
  288.  
  289.  
  290.  
  291. Set api = AMCreateObject("ICMeridianAPI.Connection", True)
  292. id = api.CreateNewDocument(vault.Name , Document.ParentFolder.Path,nomedoc & "-" & strRev & strExtensao,"Anexo",strFiles(X))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement