Advertisement
Guest User

Test

a guest
Dec 14th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 KB | None | 0 0
  1. Imports Microsoft.VisualBasic
  2. Imports System.Net
  3. Imports System.IO
  4. Imports System.Xml
  5. Imports Newtonsoft.Json
  6. Imports Newtonsoft.Json.Linq
  7.  
  8. Namespace ThirdParty_Integration_ABX
  9. Public Class Service
  10. 'Use for update/get details
  11. Public sLocalConnStr As String = ""
  12. Public sEntityID As String = ""
  13. Public sCredentialSID As String = "" 'WsUser3rdPartySID
  14. Public sStationSID As String = "" 'WSUserDebtorSID
  15. Public sDBSID As String = "" 'WsUser3rdPartyDBSID
  16. Public Connstr As String = ""
  17.  
  18. Public sCustomerCode As String = ""
  19. Public bIstest As Boolean = False
  20. Dim sEndPointURL As String = "https://abxexpress.com.my/track_web.asp?search=True&itemHAWB"
  21.  
  22. #Region "UserSetting"
  23.  
  24. Property Istest() As Boolean
  25. Get
  26. Return bIstest
  27. End Get
  28. Set(value As Boolean)
  29. bIstest = value
  30. If bIstest = True Then
  31. sEndPointURL = ""
  32. Else
  33. sEndPointURL = "https://abxexpress.com.my/track_web.asp?search=True&itemHAWB="
  34. End If
  35. End Set
  36. End Property
  37.  
  38. Property LocalConnStr() As String
  39. Get
  40. Return sLocalConnStr
  41. End Get
  42. Set(ByVal value As String)
  43. sLocalConnStr = value
  44. End Set
  45. End Property
  46.  
  47. Property DBSID() As String
  48. Get
  49. Return sDBSID
  50. End Get
  51. Set(ByVal value As String)
  52. sDBSID = value
  53. End Set
  54. End Property
  55.  
  56. #End Region
  57.  
  58. Public Function HttpPost(ByVal strRequest As String) As String
  59. Dim returnresult As String = ""
  60.  
  61. Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(strRequest), HttpWebRequest)
  62. myHttpWebRequest.Method = "GET"
  63. 'myHttpWebRequest.ContentType = "text/html"
  64.  
  65. Dim myHttpWebResponse As HttpWebResponse
  66. myHttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
  67. Dim streamResponse As IO.Stream
  68. streamResponse = myHttpWebResponse.GetResponseStream()
  69.  
  70. Dim streamRead As IO.StreamReader
  71. streamRead = New IO.StreamReader(streamResponse)
  72.  
  73. 'read response as string
  74. returnresult = streamRead.ReadToEnd()
  75.  
  76. Return returnresult
  77. End Function
  78.  
  79. Public Function GetTracking(ByVal trackingReq As TrackingRequest) As TrackingResponse()
  80.  
  81. Dim objTrackingResponse(0) As TrackingResponse
  82. Dim clsbss As New cls_business
  83.  
  84. Dim trackinglist(0) As TrackingResponseDetails
  85. Dim Count As Integer = 0
  86.  
  87. Dim requeststring As String = ""
  88. Dim responsestring As String = ""
  89.  
  90. Dim intTempTracking As Long = 0
  91. Dim intStartTracking As Long = 0
  92. Dim intEndTracking As Long = 0
  93. Dim intERR As Long = 0
  94. Dim trackevent As String = ""
  95. Dim trackingdate As String = ""
  96. Dim trackingtime As String = ""
  97. Dim trackdate As String = ""
  98.  
  99. Dim ContinueLoop As Boolean = True
  100.  
  101. requeststring = sEndPointURL & "=" & trackingReq.TrackingNumber
  102. responsestring = HttpPost(requeststring)
  103.  
  104. If responsestring <> "" Then
  105.  
  106. Try
  107.  
  108. intTempTracking = InStr(1, responsestring, "first-list", CompareMethod.Text)
  109.  
  110.  
  111. If intTempTracking > 0 Then
  112.  
  113. intERR = InStr(intTempTracking, responsestring, "<div class=""title"">SORRY</div>", CompareMethod.Text)
  114.  
  115. If intERR = 0 Then
  116.  
  117. Do While ContinueLoop = True
  118.  
  119. ReDim Preserve trackinglist(Count)
  120. trackinglist(Count) = New TrackingResponseDetails
  121.  
  122. If intTempTracking > 0 Then
  123. intTempTracking = InStr(intTempTracking, responsestring, "<div Class=""info"">", CompareMethod.Text)
  124. intStartTracking = intTempTracking + Len("<div Class=""info"">")
  125. intEndTracking = InStr(intStartTracking, responsestring, "</div>", CompareMethod.Text)
  126. trackevent = Mid(responsestring, intStartTracking, intEndTracking - intStartTracking).Trim
  127. End If
  128.  
  129. If intEndTracking > 0 Then
  130. intTempTracking = InStr(intEndTracking, responsestring, "<div class=""time"">", CompareMethod.Text)
  131. intTempTracking = InStr(intTempTracking, responsestring, "<span>", CompareMethod.Text)
  132. intStartTracking = intTempTracking + Len("<span>") 'date start'
  133. intEndTracking = InStr(intStartTracking, responsestring, "</span>", CompareMethod.Text) 'date end'
  134. trackingdate = Mid(responsestring, intStartTracking, intEndTracking - intStartTracking).Trim
  135.  
  136. intTempTracking = InStr(intTempTracking, responsestring, "<span style=""color:grey"">", CompareMethod.Text) 'time start'
  137. intStartTracking = intTempTracking + Len("<span style=""color:grey"">") 'time start'
  138. intEndTracking = InStr(intStartTracking, responsestring, "</span>", CompareMethod.Text) 'time end'
  139. trackingtime = Mid(responsestring, intStartTracking, intEndTracking - intStartTracking).Trim
  140.  
  141. trackdate = (trackingdate & " " & trackingtime)
  142. trackinglist(Count).TrackingDate = CDate(trackdate).ToString("yyyy-MM-dd HH:mm:ss")
  143.  
  144. End If
  145. intEndTracking = InStr(intEndTracking, responsestring, "</ul>", CompareMethod.Text)
  146.  
  147. If intEndTracking = 0 Then
  148. ContinueLoop = False
  149. End If
  150. Count += 1
  151.  
  152. Loop
  153. End If
  154. End If
  155.  
  156. Catch ex As Exception
  157. trackinglist(0) = New TrackingResponseDetails
  158. trackinglist(0).TrackingError &= ex.Message
  159. End Try
  160. End If
  161. objTrackingResponse(0) = New TrackingResponse
  162. objTrackingResponse(0).TrackingDetail = trackinglist
  163. Return objTrackingResponse
  164.  
  165. End Function
  166. End Class
  167. End Namespace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement