Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub pData()
  2. Dim aData As ADODB.Recordset
  3. Dim aConn As ADODB.Connection
  4. Dim xSQL As String
  5. Dim xA As String, xL As String
  6.  
  7. Dim aV(27)
  8. aV(1) = "LEAVDATE"
  9. aV(2) = "LEAVTIME"
  10. aV(3) = "TRUFWGHT"
  11. aV(4) = "TRAFWGHT"
  12. aV(5) = "TRUSWGHT"
  13. aV(6) = "TRASWGHT"
  14. aV(7) = "NETWGHT"
  15. aV(8) = "LOADNUMB"
  16. aV(9) = "REGNUMBR"
  17. aV(10) = "FIRMA"
  18. aV(11) = "FIRMANAM"
  19. aV(12) = "CUSTOMCO"
  20. aV(13) = "CUSTCONA"
  21. aV(14) = "PRODCODE"
  22. aV(15) = "PRODCONA"
  23. aV(16) = "CARRCODE"
  24. aV(17) = "CARRCONA"
  25. aV(18) = "JOBSITE"
  26. aV(19) = "JOBSITNA"
  27. aV(20) = "ADDINFO"
  28. aV(21) = "EXTRA1"
  29. aV(22) = "CUBICM"
  30. aV(23) = "HUMIDITY"
  31. aV(24) = "DRYCALOR"
  32. aV(25) = "ASH"
  33. aV(26) = "ISWBYHND"
  34. aV(27) = "TEXTTAG"
  35.  
  36. xA = Format(vAA.StartDate, "yyyy-mm-dd 00:00:00.0")
  37. xL = Format(vAA.EndDate + 1, "yyyy-mm-dd 00:00:00.0")
  38.    
  39. Set aConn = New ADODB.Connection
  40. Set aData = New ADODB.Recordset
  41.  
  42. Set oL = Sheets("AA")
  43. Rem *** Päis ***
  44. With oL.Range(oL.Cells(1, 1), oL.Cells(1, 30)).Interior
  45.   .ColorIndex = 6
  46.   .Pattern = xlSolid
  47. End With
  48. oL.Cells(1, 1).FormulaR1C1 = "KAAL"
  49. oL.Cells(1, 2).FormulaR1C1 = "KELL"
  50. For xV = 1 To 27
  51.   oL.Cells(1, 2 + xV).FormulaR1C1 = aV(xV)
  52. Next
  53.  
  54. aConn.Open "DRIVER={AspenTech SQLplus};HOST=topidb;PORT=10014;"
  55.  
  56. Rem *** Vanade andmete kirjutamine kahte esimesse ritta ***
  57. For xR = 1 To 2
  58. For xV = 3 To 27
  59.   xSQL = "select name, cast(ip_trend_time as char FORMAT 'YYYY-MM-DD HH:MI:SS') as aeg, ip_trend_value from ip_" + fT(xV) + "def " + _
  60.          "where name like '10SCALES0" + IIf(xR = 1, "02", "52") + aV(xV) + "' and ip_trend_time<=cast(timestamp'" + xA + "' as timestamp) order by aeg desc"
  61.   DoEvents
  62.   aData.Open xSQL, aConn, , , -1
  63.   DoEvents
  64.  
  65.   If Not aData.EOF Then
  66.     oL.Cells(xR + 1, 1).Value = Left(aData.fields(0).Value, 11)
  67.     oL.Cells(xR + 1, 2).Value = aData.fields(1).Value
  68.     oL.Cells(xR + 1, xV + 2).Value = aData.fields(2).Value
  69.     oL.Cells(xR + 1, xV + 2).Interior.ColorIndex = 7
  70.   End If
  71.  
  72.   DoEvents
  73.   aData.Close
  74.   DoEvents
  75. Next
  76. Next
  77.  
  78. xSQL = "select name, cast(ip_trend_time as char FORMAT 'YYYY-MM-DD HH:MI:SS') as aeg, ip_trend_value, ip_trend_qstatus from ip_analogdef " & _
  79.        "where name like '10SCALES%' and ip_trend_time>cast(timestamp'" + xA + "' as timestamp) and ip_trend_time<cast(timestamp'" + xL + "' as timestamp) " & _
  80.        "union all " & _
  81.        "select name, cast(ip_trend_time as char FORMAT 'YYYY-MM-DD HH:MI:SS') as aeg, ip_trend_value, ip_trend_qstatus from ip_textdef " & _
  82.        "where name like '10SCALES%' and ip_trend_time>cast(timestamp'" + xA + "' as timestamp) and ip_trend_time<cast(timestamp'" + xL + "' as timestamp) order by aeg, name"
  83. DoEvents
  84. aData.Open xSQL, aConn, , , -1
  85. DoEvents
  86.    
  87. xAeg = "": xK = ""
  88. Do While (Not aData.EOF)
  89.  
  90. Rem Uus rida
  91. If xAeg <> aData.fields(1).Value Or xK <> Left(aData.fields(0).Value, 11) Then
  92.   xAeg = aData.fields(1).Value
  93.   xK = Left(aData.fields(0).Value, 11)
  94.   xR = xR + 1
  95.   oL.Cells(xR, 1).Value = Left(aData.fields(0).Value, 11)
  96.   oL.Cells(xR, 2).Value = aData.fields(1).Value
  97. End If
  98.  
  99. For xV = 1 To 26
  100.   If Mid(aData.fields(0).Value, 12, 20) = aV(xV) Then
  101.     If Not IsNull(aData.fields(2).Value) Then oL.Cells(xR, xV + 2).Value = aData.fields(2).Value
  102.     Exit For
  103.   End If
  104. Next
  105. oL.Cells(xR, xV + 2).Interior.ColorIndex = 7
  106.  
  107. aData.MoveNext
  108. Loop
  109. DoEvents
  110. aData.Close
  111. DoEvents
  112.  
  113. Rem *** Viimasesse veergu üleveokaalu andmete kirjutamine ***
  114. xSQL = "select name, cast(ip_trend_time as char FORMAT 'YYYY-MM-DD HH:MI:SS') as aeg, ip_trend_value, ip_trend_qstatus from ip_analogdef " & _
  115.        "where name like '10ECA62CF102' and ip_trend_time>cast(timestamp'" + xA + "' as timestamp) and ip_trend_time<cast(timestamp'" + xL + "' as timestamp) order by aeg"
  116.  
  117. DoEvents
  118. aData.Open xSQL, aConn, , , -1
  119. DoEvents
  120.    
  121. oL.Cells(1, 30).Value = "Lindi kaal"
  122. If Not aData.EOF Then
  123. xR = 3: xAeg = CDate(aData.fields(1).Value)
  124. Do While oL.Cells(xR, 1).Value <> Empty
  125.   xR = xR + 1: xMaht = 0
  126.  
  127.   Rem Uus rida
  128.   Do While CDate(aData.fields(1).Value) < oL.Cells(xR, 2).Value + fKaaluNihe(oL.Cells(xR, 2).Value)
  129.     xMaht = xMaht + aData.fields(2).Value * (CDate(aData.fields(1).Value) - xAeg)
  130.     xAeg = CDate(aData.fields(1).Value)
  131.     aData.MoveNext
  132.     If aData.EOF Then Exit Do
  133.   Loop
  134.   If aData.EOF Then Exit Do
  135.   oL.Cells(xR, 30).Value = xMaht * 24
  136. Loop
  137. End If
  138.  
  139. DoEvents
  140. aData.Close
  141. DoEvents
  142. DoEvents
  143. aConn.Close
  144. DoEvents
  145.  
  146. Set aData = Nothing
  147. Set aConn = Nothing
  148. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement