Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 15.65 KB | None | 0 0
  1. Global all, tip, cpf1, nome1 As String
  2. Global nametf, cp, col As Boolean
  3. Global c1, n1 As String
  4. Global id1, id2, id3, id4, id5, id6, id7, id8 As String
  5. Global id_g, id_hist As Integer
  6. Global login, senha As String
  7. Public Function lista(ByVal all As String)
  8.            
  9.     Dim conexao As ADODB.Connection
  10.     Set conexao = New ADODB.Connection
  11.     Dim cquery, cquery2 As Variant
  12.     Dim rst As ADODB.Recordset
  13.     Dim warr() As String
  14.    
  15.     login = Sheets("MAIN").Range("IT65533").Value
  16.     senha = Sheets("MAIN").Range("IT65534").Value
  17.            
  18.     strconexao = "Provider=SQLOLEDB.1;" & _
  19.                 "Persist Security Info=False;" & _
  20.                 "Initial Catalog=Aquila;" & _
  21.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  22.                 "User ID=" & login & ";Password=" & senha & ";"
  23.  
  24.     conexao.ConnectionString = strconexao
  25.     conexao.Open
  26.    
  27.     Worksheets("MAIN").Range("A4:AB60000").ClearContents
  28.                                                                                
  29.     Set rst = conexao.Execute("Select * from [Aquila].[dbo].[tb_clientes_n]")
  30.        
  31.     If col = True Then
  32.         warr = Split(all, ";")
  33.        
  34.         For i = LBound(warr) To UBound(warr)
  35.            
  36.             Sheet1.Cells(4, i + 1) = warr(i)
  37.            
  38.         Next i
  39.        
  40.         j = 1
  41.         k = 5
  42.        
  43.         Do Until rst.EOF
  44.             Do Until j = i + 2
  45.                 colll = Sheet1.Cells(4, j).Value
  46.                
  47.                 Sheet1.Cells(k, j) = rst.Fields(colll).Value
  48.                
  49.                 j = j + 1
  50.             Loop
  51.             j = 1
  52.             k = k + 1
  53.             rst.MoveNext
  54.         Loop
  55.     Else:
  56.         i = 5
  57.         Do Until rst.EOF
  58.             Sheet1.Cells(i, 1) = rst.Fields(LCase(Sheet1.Cells(4, 1).Value))
  59.             Sheet1.Cells(i, 2) = rst.Fields(LCase(Sheet1.Cells(4, 2).Value))
  60.             Sheet1.Cells(i, 3) = rst.Fields(Sheet1.Cells(4, 3).Value)
  61.             Sheet1.Cells(i, 4) = rst.Fields(Sheet1.Cells(4, 4).Value)
  62.             Sheet1.Cells(i, 5) = rst.Fields(Sheet1.Cells(4, 5).Value)
  63.             Sheet1.Cells(i, 6) = rst.Fields(Sheet1.Cells(4, 6).Value)
  64.             Sheet1.Cells(i, 7) = rst.Fields(Sheet1.Cells(4, 7).Value)
  65.             If rst.Fields(Sheet1.Cells(4, 8).Value) = "True" Then
  66.                 Sheet1.Cells(i, 8) = "Sim"
  67.             Else:
  68.                 If rst.Fields(Sheet1.Cells(4, 8).Value) = "False" Then
  69.                     Sheet1.Cells(i, 8) = "Não"
  70.                 End If
  71.             End If
  72.             Sheet1.Cells(i, 9) = rst.Fields(Sheet1.Cells(4, 9).Value)
  73.             Sheet1.Cells(i, 10) = rst.Fields(Sheet1.Cells(4, 10).Value)
  74.             Sheet1.Cells(i, 11) = rst.Fields(Sheet1.Cells(4, 11).Value)
  75.             Sheet1.Cells(i, 12) = rst.Fields(Sheet1.Cells(4, 12).Value)
  76.             Sheet1.Cells(i, 13) = rst.Fields(Sheet1.Cells(4, 13).Value)
  77.             Sheet1.Cells(i, 14) = rst.Fields(Sheet1.Cells(4, 14).Value)
  78.             Sheet1.Cells(i, 15) = rst.Fields(Sheet1.Cells(4, 15).Value)
  79.             Sheet1.Cells(i, 16) = rst.Fields(Sheet1.Cells(4, 16).Value)
  80.            
  81.             i = i + 1
  82.             rst.MoveNext
  83.         Loop
  84.     End If
  85.    
  86.     conexao.Close
  87.  
  88. End Function
  89. Function pesquisa(ByVal all As String)
  90.  
  91.     Dim conexao As ADODB.Connection
  92.     Set conexao = New ADODB.Connection
  93.     Dim cquery, cquery2 As Variant
  94.     Dim rst As ADODB.Recordset
  95.    
  96.     login = Sheets("MAIN").Range("IT65533").Value
  97.     senha = Sheets("MAIN").Range("IT65534").Value
  98.    
  99.     strconexao = "Provider=SQLOLEDB.1;" & _
  100.                 "Persist Security Info=False;" & _
  101.                 "Initial Catalog=Aquila;" & _
  102.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  103.                 "User ID=" & login & ";Password=" & senha & ";"
  104.  
  105.     conexao.ConnectionString = strconexao
  106.     conexao.Open
  107.    
  108.     Worksheets("MAIN").Range("A4:AB60000").ClearContents
  109.            
  110.     If cp = True Then
  111.         Set rst = conexao.Execute("Select * from [Aquila].[dbo].[tb_clientes_n] WHERE [cpf] = '" & Replace(Replace(Trim(cpf1), ".", ""), "-", "") & "'")
  112.        
  113.         If col = True Then
  114.             warr = Split(all, ";")
  115.        
  116.             For i = LBound(warr) To UBound(warr)
  117.                
  118.                 Sheet1.Cells(4, i + 1) = warr(i)
  119.                
  120.             Next i
  121.            
  122.             j = 1
  123.             k = 5
  124.            
  125.             Do Until rst.EOF
  126.                 Do Until j = i
  127.                     colll = Sheet1.Cells(4, j).Value
  128.                    
  129.                     Sheet1.Cells(k, j) = rst.Fields(colll).Value
  130.                    
  131.                     j = j + 1
  132.                 Loop
  133.                 j = 1
  134.                 k = k + 1
  135.                 rst.MoveNext
  136.             Loop
  137.         Else:
  138.             Do Until rst.EOF
  139.                 j = 1
  140.                 k = 5
  141.                 Do Until j = 29
  142.                     colll = Sheet2.Cells(1, j).Value
  143.                    
  144.                     Sheet1.Cells(k, j) = rst.Fields(colll).Value
  145.                    
  146.                     j = j + 1
  147.                 Loop
  148.                 j = 1
  149.                 k = k + 1
  150.                 rst.MoveNext
  151.             Loop
  152.         End If
  153.     End If
  154.     If nametf = True Then
  155.         Set rst = conexao.Execute("Select * from [Aquila].[dbo].[tb_clientes_n] WHERE [nome] LIKE '%" & Trim(nome1) & "%'")
  156.        
  157.         If col = True Then
  158.             warr = Split(all, ";")
  159.        
  160.             For i = LBound(warr) To UBound(warr)
  161.                
  162.                 Sheet1.Cells(4, i + 1) = warr(i)
  163.                
  164.             Next i
  165.            
  166.             j = 1
  167.             k = 5
  168.            
  169.             Do Until rst.EOF
  170.                 Do Until j = i
  171.                     colll = Sheet1.Cells(4, j).Value
  172.                    
  173.                     Sheet1.Cells(k, j) = rst.Fields(colll).Value
  174.                    
  175.                     j = j + 1
  176.                 Loop
  177.                 j = 1
  178.                 k = k + 1
  179.                 rst.MoveNext
  180.             Loop
  181.         Else:
  182.                                    
  183.             j = 1
  184.             k = 5
  185.             Do Until j = 29
  186.                 colll = Sheet2.Cells(j, 1).Value
  187.                 Sheet1.Cells(4, j) = colll
  188.                
  189.                 j = j + 1
  190.             Loop
  191.            
  192.             j = 1
  193.             k = 5
  194.            
  195.             Do Until rst.EOF
  196.                 Do Until j = 29
  197.                     colll = Sheet2.Cells(j, 1).Value
  198.                     Sheet1.Cells(k, j) = rst.Fields(colll).Value
  199.                    
  200.                     j = j + 1
  201.                 Loop
  202.                                                
  203.                 rst.MoveNext
  204.                 k = k + 1
  205.                 j = 1
  206.             Loop
  207.         End If
  208.     End If
  209.    
  210.     conexao.Close
  211.  
  212. End Function
  213. Function getname(ByVal id As String)
  214.  
  215.     Dim conexao As ADODB.Connection
  216.     Set conexao = New ADODB.Connection
  217.     Dim cquery, cquery2 As Variant
  218.     Dim rst As ADODB.Recordset
  219.    
  220.     login = Sheets("MAIN").Range("IT65533").Value
  221.     senha = Sheets("MAIN").Range("IT65534").Value
  222.    
  223.     strconexao = "Provider=SQLOLEDB.1;" & _
  224.                 "Persist Security Info=False;" & _
  225.                 "Initial Catalog=Aquila;" & _
  226.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  227.                 "User ID=" & login & ";Password=" & senha & ";"
  228.  
  229.     conexao.ConnectionString = strconexao
  230.     conexao.Open
  231.    
  232.     Set rst = conexao.Execute("SELECT [nome] FROM [Aquila].[dbo].[tb_clientes_n] WHERE [id_cliente] = '" & id & "'")
  233.    
  234.     n1 = rst.Fields("nome").Value
  235.  
  236. End Function
  237. Function getid(ByVal cpp As String)
  238.  
  239.     Dim conexao As ADODB.Connection
  240.     Set conexao = New ADODB.Connection
  241.     Dim cquery, cquery2 As Variant
  242.     Dim rst As ADODB.Recordset
  243.    
  244.     login = Sheets("MAIN").Range("IT65533").Value
  245.     senha = Sheets("MAIN").Range("IT65534").Value
  246.    
  247.     strconexao = "Provider=SQLOLEDB.1;" & _
  248.                 "Persist Security Info=False;" & _
  249.                 "Initial Catalog=Aquila;" & _
  250.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  251.                 "User ID=" & login & ";Password=" & senha & ";"
  252.  
  253.     conexao.ConnectionString = strconexao
  254.     conexao.Open
  255.    
  256.     Set rst = conexao.Execute("SELECT [id_cliente] FROM [Aquila].[dbo].[tb_clientes_n] WHERE [cpf] = '" & cpp & "'")
  257.    
  258.     c1 = rst.Fields("id_cliente").Value
  259.  
  260. End Function
  261. Function getcontact(ByVal id As String)
  262.  
  263.     Dim conexao As ADODB.Connection
  264.     Set conexao = New ADODB.Connection
  265.     Dim cquery, cquery2 As Variant
  266.     Dim rst As ADODB.Recordset
  267.    
  268.     login = Sheets("MAIN").Range("IT65533").Value
  269.     senha = Sheets("MAIN").Range("IT65534").Value
  270.    
  271.     strconexao = "Provider=SQLOLEDB.1;" & _
  272.                 "Persist Security Info=False;" & _
  273.                 "Initial Catalog=Aquila;" & _
  274.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  275.                 "User ID=" & login & ";Password=" & senha & ";"
  276.  
  277.     conexao.ConnectionString = strconexao
  278.     conexao.Open
  279.    
  280.     Set rst = conexao.Execute("SELECT * FROM [Aquila].[dbo].[tb_hist_cont] WHERE [id_cliente] = '" & id & "'")
  281.    
  282.     xy = 1
  283.    
  284.     Do Until rst.EOF
  285.    
  286.         If xy = 1 Then
  287.             contato.Label7.Caption = rst.Fields("data").Value
  288.             id1 = rst.Fields("id_historico").Value
  289.         End If
  290.         If xy = 2 Then
  291.             contato.Label8.Caption = rst.Fields("data").Value
  292.             id2 = rst.Fields("id_historico").Value
  293.         End If
  294.         If xy = 3 Then
  295.             contato.Label9.Caption = rst.Fields("data").Value
  296.             id3 = rst.Fields("id_historico").Value
  297.         End If
  298.         If xy = 4 Then
  299.             contato.Label10.Caption = rst.Fields("data").Value
  300.             id4 = rst.Fields("id_historico").Value
  301.         End If
  302.         If xy = 5 Then
  303.             contato.Label11.Caption = rst.Fields("data").Value
  304.             id5 = rst.Fields("id_historico").Value
  305.         End If
  306.         If xy = 6 Then
  307.             contato.Label12.Caption = rst.Fields("data").Value
  308.             id6 = rst.Fields("id_historico").Value
  309.         End If
  310.         If xy = 7 Then
  311.             contato.Label13.Caption = rst.Fields("data").Value
  312.             id7 = rst.Fields("id_historico").Value
  313.         End If
  314.         If xy = 8 Then
  315.             contato.Label14.Caption = rst.Fields("data").Value
  316.             id8 = rst.Fields("id_historico").Value
  317.         End If
  318.        
  319.         xy = xy + 1
  320.         rst.MoveNext
  321.        
  322.     Loop
  323.  
  324. End Function
  325. Function getcontactinfo(ByVal id_c As String)
  326.  
  327.     Dim conexao As ADODB.Connection
  328.     Set conexao = New ADODB.Connection
  329.     Dim cquery, cquery2 As Variant
  330.     Dim rst As ADODB.Recordset
  331.    
  332.     login = Sheets("MAIN").Range("IT65533").Value
  333.     senha = Sheets("MAIN").Range("IT65534").Value
  334.    
  335.     strconexao = "Provider=SQLOLEDB.1;" & _
  336.                 "Persist Security Info=False;" & _
  337.                 "Initial Catalog=Aquila;" & _
  338.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  339.                 "User ID=" & login & ";Password=" & senha & ";"
  340.  
  341.     conexao.ConnectionString = strconexao
  342.     conexao.Open
  343.    
  344.     Set rst = conexao.Execute("SELECT * FROM [Aquila].[dbo].[tb_hist_cont] WHERE [id_historico] = '" & id_c & "'")
  345.        
  346.     telaconsulta.Label1.Caption = rst.Fields("id_cliente")
  347.     telaconsulta.Label2.Caption = rst.Fields("id_unidade")
  348.     telaconsulta.Label3.Caption = rst.Fields("id_sucessor")
  349.     telaconsulta.Label4.Caption = rst.Fields("titulo")
  350.     telaconsulta.Label5.Caption = rst.Fields("contratado")
  351.     telaconsulta.Label6.Caption = rst.Fields("origem_conta")
  352.     telaconsulta.Label7.Caption = rst.Fields("data_recebimento_doc")
  353.     telaconsulta.Label8.Caption = rst.Fields("data")
  354.     telaconsulta.Label9.Caption = rst.Fields("sistema")
  355.     telaconsulta.Label10.Caption = rst.Fields("tipo_contato")
  356.     telaconsulta.Label11.Caption = rst.Fields("meio_contato")
  357.     telaconsulta.Label12.Caption = rst.Fields("detalhe_meio_contato")
  358.     telaconsulta.Label13.Caption = rst.Fields("data_retornar_contato")
  359.     telaconsulta.Label14.Caption = rst.Fields("melhor_horario")
  360.     telaconsulta.Label15.Caption = rst.Fields("descricao")
  361.  
  362. End Function
  363. Function sendcontact()
  364.  
  365.     Dim conexao As ADODB.Connection
  366.     Set conexao = New ADODB.Connection
  367.     Dim cquery, cquery2 As Variant
  368.     Dim rst As ADODB.Recordset
  369.    
  370.     login = Sheets("MAIN").Range("IT65533").Value
  371.     senha = Sheets("MAIN").Range("IT65534").Value
  372.    
  373.     strconexao = "Provider=SQLOLEDB.1;" & _
  374.                 "Persist Security Info=False;" & _
  375.                 "Initial Catalog=Aquila;" & _
  376.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  377.                 "User ID=" & login & ";Password=" & senha & ";"
  378.  
  379.     conexao.ConnectionString = strconexao
  380.     conexao.Open
  381.            
  382.     cquery = "INSERT INTO [dbo].[tb_hist_cont]" & _
  383.         "([id_historico]" & _
  384.         ",[id_cliente]" & _
  385.         ",[data]" & _
  386.         ",[descricao]" & _
  387.         ",[id_unidade]" & _
  388.         ",[titulo]" & _
  389.         ",[origem_conta]" & _
  390.         ",[meio_contato]" & _
  391.         ",[detalhe_meio_contato]" & _
  392.         ",[contratado]" & _
  393.         ",[tipo_contato]" & _
  394.         ",[sistema]" & _
  395.         ",[id_sucessor]" & _
  396.         ",[data_recebimento_doc]" & _
  397.         ",[data_retornar_contato]" & _
  398.         ",[melhor_horario])"
  399.      cquery2 = " Values (" & id_hist & _
  400.         ",'" & UserForm1.TextBox1.Value & "'" & _
  401.         ",'" & UserForm1.TextBox9.Value & "'" & _
  402.         ",'" & UserForm1.TextBox6.Value & "'" & _
  403.         ",'" & UserForm1.TextBox2.Value & "'" & _
  404.         ",'" & UserForm1.TextBox4.Value & "'" & _
  405.         ",'" & UserForm1.TextBox14.Value & "'" & _
  406.         ",'" & UserForm1.TextBox11.Value & "'" & _
  407.         ",'" & UserForm1.TextBox7.Value & "'" & _
  408.         ",'" & UserForm1.TextBox5.Value & "'" & _
  409.         ",'" & UserForm1.TextBox10.Value & "'" & _
  410.         ",'" & UserForm1.TextBox8.Value & "'" & _
  411.         ",'" & UserForm1.TextBox3.Value & "'" & _
  412.         ",'" & UserForm1.TextBox15.Value & "'" & _
  413.         ",'" & UserForm1.TextBox12.Value & "'" & _
  414.         ",'" & UserForm1.TextBox13.Value & "')"
  415.        
  416.         conexao.Execute cquery & cquery2
  417.    
  418. End Function
  419. Function testasql(login, senha)
  420.  
  421.     On Error GoTo handler
  422.    
  423.     Dim conexao As ADODB.Connection
  424.     Set conexao = New ADODB.Connection
  425.     Dim cquery, cquery2 As Variant
  426.     Dim rst As ADODB.Recordset
  427.    
  428.     strconexao = "Provider=SQLOLEDB.1;" & _
  429.                 "Persist Security Info=False;" & _
  430.                 "Initial Catalog=Aquila;" & _
  431.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  432.                 "User ID=" & login & ";Password=" & senha & ";"
  433.  
  434.     conexao.ConnectionString = strconexao
  435.     conexao.Open
  436.    
  437.     zt = True
  438.     MsgBox "Login efetuado com sucesso", vbInformation
  439.     Sheets("MAIN").Range("IT65533").Value = login
  440.     Sheets("MAIN").Range("IT65534").Value = senha
  441.    
  442. handler:
  443. If zt <> True Then
  444. MsgBox "Credenciais inválidas!", vbCritical
  445. End If
  446. Exit Function
  447.  
  448. End Function
  449. Function newid()
  450.  
  451.     Dim conexao As ADODB.Connection
  452.     Set conexao = New ADODB.Connection
  453.     Dim cquery, cquery2 As Variant
  454.     Dim rst As ADODB.Recordset
  455.    
  456.     strconexao = "Provider=SQLOLEDB.1;" & _
  457.                 "Persist Security Info=False;" & _
  458.                 "Initial Catalog=Aquila;" & _
  459.                 "Data Source=DESKTOP-9CLNCT1\LDB;" & _
  460.                 "User ID=" & login & ";Password=" & senha & ";"
  461.  
  462.     conexao.ConnectionString = strconexao
  463.     conexao.Open
  464.    
  465.     Set rst = conexao.Execute("SELECT MAX(id_historico) FROM [Aquila].[dbo].[tb_hist_cont]")
  466.    
  467.     id_hist = (rst.Fields("id_historico").Value) + 1
  468.  
  469. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement