Imports System.Data.SqlClient
Imports System.Net
Imports System.IO
Imports System.Runtime.Serialization.Json
Imports System.Web.Script.Serialization
Public Class user_postcarddetail
Inherits System.Web.UI.Page
Public strURL As String
Public dbcCharges As Double
Public dbRate As Double
Public strCreated As String
Public strExpectedDeliveryDate As String
Public strConfirmationID As String
Public sbRPT As StringBuilder
Public strBufferRPT As String
Public sbFinalRPT As StringBuilder
Public sbTrackingRPT As StringBuilder
Public strTrackingBufferRPT As String
Public sbTrackingFinalRPT As StringBuilder
Public strRPTFooter As String
Public strTrackingReportHtml As String
Public strReportHtml As String
Public strCarrier As String
Public strInfoDigit As String
Public strCarrierPrefix As String
Public drViewPostcard As SqlDataReader
Public dbTotalMinute As Double
Public dbTotalCharges As Double
Public strTrackingCreatedDate, strTrackingFromDate, strTrackingToDate,
strDestinationZipCode, strEventName, strEventZip, strEventDatetime As String
Protected WithEvents cvControlNumber As System.Web.UI.WebControls.CompareValidator
Public blnFlag As Boolean
Public intCounter As Integer
Public strUserName As String
Public strAuthCode As String
Public strFromDate As String
Public strToDate As String
Public strCriteria As String
Protected WithEvents rfvCardCategory As System.Web.UI.WebControls.RequiredFieldValidator
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Session("UserName") = "indiasupport5"
If Session("UserName") = "" Then
If Request.QueryString("username") = "" Then
Me.pnlUserName.Visible = True
Me.pnlTrackingDetails.Visible = False
Me.pnlReport.Visible = False
Return
Else
strUserName = Request.QueryString("username")
End If
Else
strUserName = Session("UserName")
End If
Dim connCMS As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("JCCCALL").ConnectionString)
Dim strSql As String = "s_PostCard"
Dim cmdViewPostcard As SqlCommand = New SqlCommand(strSql, connCMS)
Try
cmdViewPostcard.CommandType = CommandType.StoredProcedure
cmdViewPostcard.Parameters.Add(New SqlParameter("@username", SqlDbType.VarChar, 25))
cmdViewPostcard.Parameters("@username").Value = strUserName
cmdViewPostcard.Parameters.Add(New SqlParameter("@Operation", SqlDbType.VarChar, 20))
cmdViewPostcard.Parameters("@Operation").Value = "JailGetPostCards"
cmdViewPostcard.Connection.Open()
dbTotalMinute = 0
dbTotalCharges = 0
drViewPostcard = cmdViewPostcard.ExecuteReader()
If drViewPostcard.Read() Then
intCounter = 1
blnFlag = True
pnlNoReport.Visible = False
Else
blnFlag = False
pnlReport.Visible = False
pnlTrackingDetails.Visible = False
pnlNoReport.Visible = True
End If
While (blnFlag)
Do
If Not IsDBNull(drViewPostcard("Created")) Then
strCreated = drViewPostcard("Created")
End If
If Not IsDBNull(drViewPostcard("expected_delivery_date")) Then
strExpectedDeliveryDate = drViewPostcard("expected_delivery_date")
End If
If Not IsDBNull(drViewPostcard("confirmation_id")) Then
strConfirmationID = drViewPostcard("confirmation_id")
End If
If Not IsDBNull(drViewPostcard("carrier")) Then
strCarrier = drViewPostcard("carrier")
End If
If Not IsDBNull(drViewPostcard("URL")) Then
strURL = drViewPostcard("URL")
End If
If Not IsDBNull(drViewPostcard("amount")) Then
dbcCharges = drViewPostcard("amount")
End If
sbRPT = New StringBuilder
sbRPT = GetReportBody()
strBufferRPT = strBufferRPT & sbRPT.ToString()
If (drViewPostcard.Read()) Then
intCounter = intCounter + 1
blnFlag = True
Else
blnFlag = False
End If
Loop While (blnFlag)
strReportHtml = strReportHtml + strBufferRPT.ToString
strBufferRPT = ""
dbTotalMinute = 0
dbTotalCharges = 0
End While
strCriteria = "PIN: " & strAuthCode & " From " & strFromDate & " To " & strToDate
Catch exp As SqlException
Response.Write(exp)
Finally
drViewPostcard.Close()
cmdViewPostcard.Connection.Close()
End Try
If Request.QueryString("postcard") = "" Then
pnlTrackingDetails.Visible = False
Else
pnlTrackingDetails.Visible = True
'if successfully charged send it
Dim strLOBAPIKey, postData As String
Dim APIResponse As HttpWebResponse
Dim APIRequest As HttpWebRequest
Dim httpresponse As HttpWebResponse = Nothing
Dim reader As StreamReader
Dim data As StringBuilder
Dim byteData() As Byte
Dim postStream As Stream = Nothing
Dim str_response, front_text, back_text, strMailText As String
Dim ser As DataContractJsonSerializer
Dim RESTEndpoint As Uri
Dim PostCardResponse_data As New PostCardTrackingResult
'attempt to get list of DID
'RESTEndpoint = New Uri("https://api.lob.com/v1/postcards/psc_4d66b7b9974c9626")
'RESTEndpoint = New Uri("https://api.lob.com/v1/postcards/psc_6683382559573c50")
RESTEndpoint = New Uri("https://api.lob.com/v1/postcards/" & Request.QueryString("postcard"))
Dim sb As New StringBuilder
'text limits not handled by lob
APIRequest = WebRequest.Create(RESTEndpoint)
strLOBAPIKey = ConfigurationManager.AppSettings("LOBAPIKey").ToString()
Dim networkCredential As New NetworkCredential(strLOBAPIKey, "")
APIRequest.Credentials = networkCredential
APIRequest.UserAgent = ".NET Framework Client"
APIRequest.Method = "GET"
APIRequest.ContentType = "application/x-www-form-urlencoded"
'byteData = UTF8Encoding.UTF8.GetBytes()
'' Set the content length in the request headers
'APIRequest.ContentLength = byteData.Length
'postStream = APIRequest.GetRequestStream()
'postStream.Write(byteData, 0, byteData.Length)
'postStream.Close()
Try
' Get response
httpresponse = DirectCast(APIRequest.GetResponse(), HttpWebResponse)
' Get the response stream into a reader
reader = New StreamReader(httpresponse.GetResponseStream())
' Console application output
str_response = reader.ReadToEnd.ToString
Dim jss = New JavaScriptSerializer()
PostCardResponse_data = jss.Deserialize(Of PostCardTrackingResult)(str_response)
strTrackingCreatedDate = PostCardResponse_data.date_created
strTrackingFromDate = PostCardResponse_data.from.name
strTrackingToDate = PostCardResponse_data.to.name
strDestinationZipCode = PostCardResponse_data.to.address_zip
If PostCardResponse_data.tracking_events.Count > 0 Then
intCounter = 0
Dim events_cnt As Integer
events_cnt = PostCardResponse_data.tracking_events.Count
strTrackingReportHtml = ""
While events_cnt > 0
strEventName = PostCardResponse_data.tracking_events(intCounter).name
'MsgBox(intCounter)
'MsgBox(PostCardResponse_data.tracking.events(intCounter).name)
strEventZip = PostCardResponse_data.tracking_events(intCounter).location
strEventDatetime = PostCardResponse_data.tracking_events(intCounter).time
sbTrackingRPT = New StringBuilder
sbTrackingRPT = GetTrackingReportBody()
strTrackingReportHtml = strTrackingReportHtml & sbTrackingRPT.ToString()
intCounter = intCounter + 1
events_cnt = events_cnt - 1
'strTrackingReportHtml = strTrackingReportHtml + strTrackingBufferRPT.ToString
End While
End If
Catch webexception As WebException
Return
Finally
If Not httpresponse Is Nothing Then httpresponse.Close()
End Try
End If
pnlReport.Visible = True
intCounter = 0
End Sub
Public Function GetReportBody() As StringBuilder
Dim strColor As String
'strColor = "#003471"
If intCounter Mod 2 = 0 Then
strColor = "#fff3ed"
Else
strColor = "#FFFFFF"
End If
Dim sbRptBody As StringBuilder = New StringBuilder
Dim strReportBody As String = ""
strReportBody &= "
"
strReportBody &= "" & strCreated & " | "
strReportBody &= "" & strExpectedDeliveryDate & " | "
strReportBody &= "" & strCarrier & " | "
strReportBody &= "View | "
strReportBody &= "" & dbcCharges.ToString() & " | "
strReportBody &= "
"
sbRptBody.Append(strReportBody)
Return sbRptBody
End Function
Public Function GetTrackingReportBody() As StringBuilder
Dim strColor As String
'strColor = "#003471"
If intCounter Mod 2 = 0 Then
strColor = "#fff3ed"
Else
strColor = "#FFFFFF"
End If
Dim sbTrackingRptBody As StringBuilder = New StringBuilder
Dim strTrackingReportBody As String = ""
strTrackingReportBody &= ""
strTrackingReportBody &= "" & strEventName & " | "
strTrackingReportBody &= "" & strEventZip & " | "
strTrackingReportBody &= "" & strEventDatetime & " | "
strTrackingReportBody &= "
"
sbTrackingRptBody.Append(strTrackingReportBody)
Return sbTrackingRptBody
End Function
Public Function GetInvoiceFooter() As String
Dim strFooter As String = ""
strFooter &= ""
strFooter &= ""
strFooter &= ""
strFooter &= " "
strFooter &= " | "
strFooter &= "
"
strFooter &= ""
strFooter &= " | "
strFooter &= ""
strFooter &= "Total :"
strFooter &= " | "
strFooter &= ""
strFooter &= "" & dbTotalMinute.ToString() & ""
strFooter &= " | "
'dbTotalCharges = FormatNumber(dbTotalCharges, 2, , , TriState.False)
strFooter &= ""
strFooter &= "$" & dbTotalCharges.ToString() & ""
strFooter &= " | "
strFooter &= "
"
strFooter &= ""
strFooter &= ""
strFooter &= " "
strFooter &= " | "
strFooter &= "
"
Return strFooter
End Function
Sub fillDropdown()
Dim strSql As String
Dim cmdFillServiceName As SqlCommand
Dim drFillServiceName As SqlDataReader
Dim conn = New SqlConnection(ConfigurationManager.ConnectionStrings("JCCCALL").ConnectionString)
strSql = "s_Offernder"
Try
cmdFillServiceName = New SqlCommand(strSql, conn)
cmdFillServiceName.CommandType = CommandType.StoredProcedure
cmdFillServiceName.Parameters.Add(New SqlParameter("@UserName", SqlDbType.NVarChar, 25))
cmdFillServiceName.Parameters("@UserName").Value = Session("UserName")
cmdFillServiceName.Parameters.Add(New SqlParameter("@Operation", SqlDbType.VarChar, 20))
cmdFillServiceName.Parameters("@Operation").Value = "SHOWPINS"
cmdFillServiceName.Connection.Open()
drFillServiceName = cmdFillServiceName.ExecuteReader()
While (drFillServiceName.Read())
Dim strText = drFillServiceName("Authcode")
' Me.ddlauthcode.Items.Add(New ListItem(strText))
End While
' Me.ddlauthcode.SelectedIndex = 0
drFillServiceName.Close()
Catch Ex As Exception
Response.Write(Ex.Message)
Finally
cmdFillServiceName.Connection.Close()
End Try
End Sub
Protected Sub btnSetUsername_Click(sender As Object, e As EventArgs) Handles btnSetUsername.Click
Response.Redirect("user-postcarddetail.aspx?username=" & Me.txtUsername.Text)
End Sub
End Class
Public Class TrackingEvent
Public Property name() As String
Get
Return m_name
End Get
Set(value As String)
m_name = value
End Set
End Property
Private m_name As String
Public Property location() As String
Get
Return m_location
End Get
Set(value As String)
m_location = value
End Set
End Property
Private m_location As String
Public Property time() As String
Get
Return m_time
End Get
Set(value As String)
m_time = value
End Set
End Property
Private m_time As String
Public Property date_created() As String
Get
Return m_date_created
End Get
Set(value As String)
m_date_created = value
End Set
End Property
Private m_date_created As String
Public Property date_modified() As String
Get
Return m_date_modified
End Get
Set(value As String)
m_date_modified = value
End Set
End Property
Private m_date_modified As String
End Class
Public Class TrackingThumbnails
Public Property small() As String
Get
Return m_small
End Get
Set(value As String)
m_small = value
End Set
End Property
Private m_small As String
Public Property medium() As String
Get
Return m_medium
End Get
Set(value As String)
m_medium = value
End Set
End Property
Private m_medium As String
Public Property large() As String
Get
Return m_large
End Get
Set(value As String)
m_large = value
End Set
End Property
Private m_large As String
End Class
Public Class TrackingTracking
Public Property id() As String
Get
Return m_id
End Get
Set(value As String)
m_id = value
End Set
End Property
Private m_id As String
Public Property tracking_number() As String
Get
Return m_tracking_number
End Get
Set(value As String)
m_tracking_number = value
End Set
End Property
Private m_tracking_number As String
Public Property carrier() As String
Get
Return m_carrier
End Get
Set(value As String)
m_carrier = value
End Set
End Property
Private m_carrier As String
Public Property link() As String
Get
Return m_link
End Get
Set(value As String)
m_link = value
End Set
End Property
Private m_link As String
Public Property events() As List(Of TrackingEvent)
Get
Return m_events
End Get
Set(value As List(Of TrackingEvent))
m_events = value
End Set
End Property
Private m_events As List(Of TrackingEvent)
End Class
Public Class TrackingAddress
Public Property id() As String
Get
Return m_id
End Get
Set(value As String)
m_id = value
End Set
End Property
Private m_id As String
Public Property description() As String
Get
Return m_description
End Get
Set(value As String)
m_description = value
End Set
End Property
Private m_description As String
Public Property name() As String
Get
Return m_name
End Get
Set(value As String)
m_name = value
End Set
End Property
Private m_name As String
Public Property phone() As String
Get
Return m_phone
End Get
Set(value As String)
m_phone = value
End Set
End Property
Private m_phone As String
Public Property email() As String
Get
Return m_email
End Get
Set(value As String)
m_email = value
End Set
End Property
Private m_email As String
Public Property company() As String
Get
Return m_company
End Get
Set(value As String)
m_company = value
End Set
End Property
Private m_company As String
Public Property address_line1() As String
Get
Return m_address_line1
End Get
Set(value As String)
m_address_line1 = value
End Set
End Property
Private m_address_line1 As String
Public Property address_line2() As String
Get
Return m_address_line2
End Get
Set(value As String)
m_address_line2 = value
End Set
End Property
Private m_address_line2 As String
Public Property address_city() As String
Get
Return m_address_city
End Get
Set(value As String)
m_address_city = value
End Set
End Property
Private m_address_city As String
Public Property address_state() As String
Get
Return m_address_state
End Get
Set(value As String)
m_address_state = value
End Set
End Property
Private m_address_state As String
Public Property address_zip() As String
Get
Return m_address_zip
End Get
Set(value As String)
m_address_zip = value
End Set
End Property
Private m_address_zip As String
Public Property address_country() As String
Get
Return m_address_country
End Get
Set(value As String)
m_address_country = value
End Set
End Property
Private m_address_country As String
End Class
Public Class PostCardTrackingEvent
Public Property id() As String
Get
Return m_id
End Get
Set(value As String)
m_id = value
End Set
End Property
Private m_id As String
Public Property name() As String
Get
Return m_name
End Get
Set(value As String)
m_name = value
End Set
End Property
Private m_name As String
Public Property location() As String
Get
Return m_location
End Get
Set(value As String)
m_location = value
End Set
End Property
Private m_location As String
Public Property time() As String
Get
Return m_time
End Get
Set(value As String)
m_time = value
End Set
End Property
Private m_time As String
Public Property date_created() As String
Get
Return m_date_created
End Get
Set(value As String)
m_date_created = value
End Set
End Property
Private m_date_created As String
Public Property date_modified() As String
Get
Return m_date_modified
End Get
Set(value As String)
m_date_modified = value
End Set
End Property
Private m_date_modified As String
Public Property [object]() As String
Get
Return m_object
End Get
Set(value As String)
m_object = value
End Set
End Property
Private m_object As String
End Class
Public Class PostCardTrackingResult
Public Property id() As String
Get
Return m_id
End Get
Set(value As String)
m_id = value
End Set
End Property
Private m_id As String
Public Property description() As String
Get
Return m_description
End Get
Set(value As String)
m_description = value
End Set
End Property
Private m_description As String
Public Property [to]() As Address
Get
Return m_to
End Get
Set(value As Address)
m_to = value
End Set
End Property
Private m_to As Address
Public Property from() As Address
Get
Return m_from
End Get
Set(value As Address)
m_from = value
End Set
End Property
Private m_from As Address
Public Property message() As String
Get
Return m_message
End Get
Set(value As String)
m_message = value
End Set
End Property
Private m_message As String
Public Property url() As String
Get
Return m_url
End Get
Set(value As String)
m_url = value
End Set
End Property
Private m_url As String
Public Property tracking() As TrackingTracking
Get
Return m_tracking
End Get
Set(value As TrackingTracking)
m_tracking = value
End Set
End Property
Private m_tracking As TrackingTracking
Public Property thumbnails() As List(Of Thumbnails)
Get
Return m_thumbnails
End Get
Set(value As List(Of Thumbnails))
m_thumbnails = value
End Set
End Property
Private m_thumbnails As List(Of Thumbnails)
Public Property size() As String
Get
Return m_size
End Get
Set(value As String)
m_size = value
End Set
End Property
Private m_size As String
Public Property date_created() As String
Get
Return m_date_created
End Get
Set(value As String)
m_date_created = value
End Set
End Property
Private m_date_created As String
Public Property date_modified() As String
Get
Return m_date_modified
End Get
Set(value As String)
m_date_modified = value
End Set
End Property
Private m_date_modified As String
Public Property expected_delivery_date() As String
Get
Return m_expected_delivery_date
End Get
Set(value As String)
m_expected_delivery_date = value
End Set
End Property
Private m_expected_delivery_date As String
Public Property send_date() As String
Get
Return m_send_date
End Get
Set(value As String)
m_send_date = value
End Set
End Property
Private m_send_date As String
Public Property tracking_events() As List(Of TrackingEvent)
Get
Return m_tracking_events
End Get
Set(value As List(Of TrackingEvent))
m_tracking_events = value
End Set
End Property
Private m_tracking_events As List(Of TrackingEvent)
End Class
Public Class TrackingRootObject
Public Property address() As Address
Get
Return m_address
End Get
Set(value As Address)
m_address = value
End Set
End Property
Private m_address As Address
End Class