344 lines
15 KiB
VB.net
344 lines
15 KiB
VB.net
Option Strict On
|
|
Option Explicit On
|
|
|
|
Imports System.Data
|
|
Imports System.IO
|
|
Imports System.Net
|
|
Imports Extensiones
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports Newtonsoft.Json.Linq
|
|
Imports System.Linq
|
|
|
|
Partial Class GPS_RastreoTrayectos
|
|
Inherits Page
|
|
|
|
#Region "P R O P I E D A D E S"
|
|
Private Property TrazarLineaContinuo As Boolean
|
|
Get
|
|
Return CType(ViewState("TrazarLineaContinuo"), Boolean)
|
|
End Get
|
|
Set(value As Boolean)
|
|
ViewState("TrazarLineaContinuo") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveTrayecto As Integer
|
|
Get
|
|
Return IfNull(ViewState("CveTrayecto"), -1, ViewState("CveTrayecto").ToString().ToEntero()).ToString().ToEntero()
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveTrayecto") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveDispositivo As Integer
|
|
Get
|
|
Return IfNull(ViewState("CveDispositivo"), -1, ViewState("CveDispositivo").ToString().ToEntero()).ToString().ToEntero()
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveDispositivo") = value
|
|
End Set
|
|
End Property
|
|
Private Property CveCliente As Integer
|
|
Get
|
|
Return IfNull(ViewState("CveCliente"), -1, ViewState("CveCliente").ToString().ToEntero()).ToString().ToEntero()
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CveCliente") = value
|
|
End Set
|
|
End Property
|
|
Private Property DtCoordenadasContinuas As DataTable
|
|
Get
|
|
Return CType(ViewState("DtCoordenadasContinuas"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtCoordenadasContinuas") = value
|
|
End Set
|
|
End Property
|
|
Private Property DtPosiciones As DataTable
|
|
Get
|
|
Return CType(ViewState("DtPosiciones"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtPosiciones") = value
|
|
End Set
|
|
End Property
|
|
|
|
Property GlobalDTDispositivos(CveCliente As Integer) As DataTable
|
|
Get
|
|
Dim Str As StringBuilder = New StringBuilder()
|
|
|
|
If CveCliente <> -1 Then Str.AppendFormat(" {0} CveCliente = {1}", If(Str.Length > 0, "AND", ""), CveCliente)
|
|
|
|
|
|
If CveCliente <> -1 Then
|
|
Dim Dv As New DataView(DirectCast(HttpContext.Current.Application("GlobalDTDispositivos"), DataTable), Str.ToString, "", DataViewRowState.CurrentRows)
|
|
GlobalDTDispositivos = Dv.ToTable
|
|
Dv.Dispose()
|
|
Else
|
|
GlobalDTDispositivos = DirectCast(HttpContext.Current.Application("GlobalDTDispositivos"), DataTable)
|
|
End If
|
|
|
|
End Get
|
|
Set(value As DataTable)
|
|
HttpContext.Current.Application("GlobalDTDispositivos") = value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
RegistraScript("$('#SideNav').click();initMap();")
|
|
Me.CveTrayecto = 97
|
|
|
|
CreaDTPosiciones()
|
|
CargaDatos()
|
|
RastrearEquipos()
|
|
CargaTabla()
|
|
End If
|
|
End Sub
|
|
Private Sub CreaDTPosiciones()
|
|
DtPosiciones = Nothing
|
|
|
|
Dim dt As New DataTable
|
|
dt.Columns.Add("CveDispositivo", Type.GetType("System.Int32"))
|
|
dt.Columns.Add("Vehiculo", Type.GetType("System.String"))
|
|
dt.Columns.Add("Fecha", Type.GetType("System.String"))
|
|
dt.Columns.Add("Evento", Type.GetType("System.String"))
|
|
dt.Columns.Add("TiempoDetenido", Type.GetType("System.Double"))
|
|
dt.Columns.Add("Velocidad", Type.GetType("System.Double"))
|
|
dt.Columns.Add("Posicion", Type.GetType("System.String"))
|
|
dt.Columns.Add("KMRecorridos", Type.GetType("System.Double"))
|
|
dt.Columns.Add("Icono", Type.GetType("System.String"))
|
|
|
|
DtPosiciones = dt
|
|
End Sub
|
|
Private Sub CreaDTCoordenadas()
|
|
|
|
Dim dt As New DataTable
|
|
dt.Columns.Add("CveDispositivo", Type.GetType("System.Int32"))
|
|
dt.Columns.Add("Coord", Type.GetType("System.String"))
|
|
|
|
DtCoordenadasContinuas = dt
|
|
End Sub
|
|
Private Sub CargaDatos()
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.GetTrayectos(CveTrayecto, -1, -1) AndAlso ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
Dim Row As DataRow = ObjGPS.DtResultados.Rows(0)
|
|
Me.CveDispositivo = Row("CveDispositivo").ToString().ToEntero()
|
|
Me.CveCliente = Row("CveCliente").ToString().ToEntero()
|
|
End If
|
|
End Using
|
|
TrazarLineaContinuo = True
|
|
CreaDTCoordenadas()
|
|
End Sub
|
|
Protected Sub TimmerRefresh_Tick(sender As Object, e As EventArgs)
|
|
DtPosiciones.Rows.Clear()
|
|
RegistraScript("DeleteMarkers();")
|
|
Dim LastCoord As String = ""
|
|
Dim TmpDT As New DataTable
|
|
Dim Info = ""
|
|
Dim Direccion = ""
|
|
Dim SBBody As New StringBuilder
|
|
Dim Icono As String = "/Imagenes/rsz_11rsz_car.png"
|
|
Dim Fecha, Vehiculo As String
|
|
|
|
Dim ObjGPS As New ClsGPS
|
|
Try
|
|
Dim RowVehiculo As DataRow = GlobalDTDispositivos(CveCliente).FiltroPrimero($"CveDispositivo = {CveDispositivo}")
|
|
|
|
If ObjGPS.UltimaPosicionEquipoGet(CveDispositivo, MinFecha, MaxFecha) Then
|
|
If ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
Dim Coord As String = SQLToGmaps(ObjGPS.DtResultados.Rows(0)("Posicion").ToString, "POINT")
|
|
Fecha = ObjGPS.DtResultados.Rows(0)("FechaTrama").ToString
|
|
Vehiculo = ObjGPS.DtResultados.Rows(0)("Vehiculo").ToString
|
|
Info = InfoWindowCombustible($" Vehículo: {Vehiculo}", "-1", CveDispositivo, ObjGPS.DtResultados.Rows(0), False)
|
|
|
|
If ObjGPS.DtResultados.Rows(0)("SPD").ToString.ToDouble > 1 Then
|
|
Icono = $"/Imagenes/{RowVehiculo("Icono")}green.png"
|
|
Else
|
|
Icono = $"/Imagenes/{RowVehiculo("Icono")}.png"
|
|
End If
|
|
|
|
AddRowCoordenadasContinuas(Coord, CveDispositivo)
|
|
|
|
Dim POLYPATH As String = "["
|
|
|
|
For Each RCC As DataRow In DtCoordenadasContinuas.FiltraParametros($"CveDispositivo = {CveDispositivo}", DistinctColumns:={"CveDispositivo", "Coord"}).Rows
|
|
POLYPATH = $"{POLYPATH}{RCC("Coord").ToString},"
|
|
Next
|
|
POLYPATH = $"{POLYPATH.Substring(0, POLYPATH.Length - 1)}]"
|
|
RegistraScript($"creaPolyline({POLYPATH}, '{RowVehiculo("ColorTrazo")}', '{Info}', {Coord}, '{RowVehiculo("NombreVehiculo")}', '{Icono}',{CveDispositivo}, 1)", $"{CveDispositivo}{DtCoordenadasContinuas.Rows.Count}")
|
|
|
|
RegistraScript($"setTimeout(function(){{ CreaMarcador({Coord},'{RowVehiculo("NombreVehiculo").ToString()}', '{Info}', '{Icono}');}}, 1000);", CveDispositivo.ToString())
|
|
AddRowPosiciones(Vehiculo, Coord, ObjGPS.DtResultados.Rows(0)("SPD").ToString.ToDouble, Fecha, CveDispositivo, ObjGPS.DtResultados(0)("TiempoDetenido").ToString.ToDouble)
|
|
End If
|
|
End If
|
|
|
|
TimmerRefresh.Enabled = True
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al rastrear equipo", ex)
|
|
End Try
|
|
End Sub
|
|
Private Sub RastrearEquipos()
|
|
Dim LastCoord As String = ""
|
|
Dim TmpDT As New DataTable
|
|
Dim Info = ""
|
|
Dim Direccion = ""
|
|
Dim SBBody As New StringBuilder
|
|
Dim Icono As String = "/Imagenes/rsz_11rsz_car.png"
|
|
Dim Fecha, Vehiculo As String
|
|
|
|
Dim ObjGPS As New ClsGPS
|
|
Try
|
|
Dim RowVehiculo As DataRow = GlobalDTDispositivos(CveCliente).FiltroPrimero($"CveDispositivo = {CveDispositivo}")
|
|
|
|
If ObjGPS.UltimaPosicionEquipoGet(CveDispositivo, MinFecha, MaxFecha) Then
|
|
If ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
Dim Coord As String = SQLToGmaps(ObjGPS.DtResultados.Rows(0)("Posicion").ToString, "POINT")
|
|
Fecha = ObjGPS.DtResultados.Rows(0)("FechaTrama").ToString
|
|
Vehiculo = ObjGPS.DtResultados.Rows(0)("Vehiculo").ToString
|
|
Info = InfoWindowCombustible($" Vehículo: {Vehiculo}", "-1", CveDispositivo, ObjGPS.DtResultados.Rows(0), False)
|
|
|
|
If ObjGPS.DtResultados.Rows(0)("SPD").ToString.ToDouble > 1 Then
|
|
Icono = $"/Imagenes/{RowVehiculo("Icono")}green.png"
|
|
Else
|
|
Icono = $"/Imagenes/{RowVehiculo("Icono")}.png"
|
|
End If
|
|
|
|
AddRowCoordenadasContinuas(Coord, CveDispositivo)
|
|
|
|
RegistraScript($"setTimeout(function(){{ CreaMarcador({Coord},'{RowVehiculo("NombreVehiculo").ToString()}', '{Info}', '{Icono}');}}, 1000);", CveDispositivo.ToString())
|
|
AddRowPosiciones(Vehiculo, Coord, ObjGPS.DtResultados.Rows(0)("SPD").ToString.ToDouble, Fecha, CveDispositivo, ObjGPS.DtResultados(0)("TiempoDetenido").ToString.ToDouble)
|
|
End If
|
|
End If
|
|
|
|
TimmerRefresh.Enabled = True
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al rastrear equipo", ex)
|
|
End Try
|
|
ObjGPS.Dispose()
|
|
End Sub
|
|
|
|
Private Sub CargaTabla()
|
|
If DtPosiciones IsNot Nothing Then
|
|
GvBarra.DataSource = DtPosiciones
|
|
GvBarra.DataBind()
|
|
End If
|
|
|
|
If GvBarra.HeaderRow IsNot Nothing Then
|
|
GvBarra.HeaderRow.Cells(3).Style.Add("display", "")
|
|
GvBarra.HeaderRow.Cells(4).Style.Add("display", "none !important")
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub AddRowCoordenadasContinuas(Coord As String, CveDispositivo As Integer)
|
|
Dim dr As DataRow = DtCoordenadasContinuas.NewRow()
|
|
dr("CveDispositivo") = CveDispositivo
|
|
dr("Coord") = Coord
|
|
DtCoordenadasContinuas.Rows.Add(dr)
|
|
End Sub
|
|
Private Sub AddRowPosiciones(Vehiculo As String, Posicion As String, Velocidad As Double, Fecha As String, CveDispositivo As Integer, Optional TiempoDetenido As Double = 0, Optional Evento As String = "", Optional KMRecorridos As Double = 0, Optional Icono As String = "/Imagenes/rsz_11rsz_car.png")
|
|
Dim dr As DataRow = DtPosiciones.NewRow()
|
|
dr("Vehiculo") = Vehiculo
|
|
dr("Fecha") = Fecha
|
|
dr("TiempoDetenido") = TiempoDetenido
|
|
dr("Velocidad") = Velocidad
|
|
dr("Posicion") = Posicion
|
|
dr("CveDispositivo") = CveDispositivo
|
|
dr("Evento") = Evento
|
|
dr("KMRecorridos") = KMRecorridos
|
|
dr("Icono") = Icono
|
|
|
|
DtPosiciones.Rows.Add(dr)
|
|
End Sub
|
|
Public Function InfoWindowCombustible(Header As String, ExtraBody As String, CveDispositivo As Integer, row As DataRow, Optional PermisoComandos As Boolean = True) As String
|
|
Dim SBuilder As New StringBuilder
|
|
SBuilder.Clear()
|
|
SBuilder.Append($"<div>")
|
|
SBuilder.Append($"<div><h5><a target=\'_blank\' href=\'\'><b>{Header}</b></a></h5></div>")
|
|
SBuilder.Append($"<div><table>")
|
|
Try
|
|
SBuilder.Append($"<tr><td>Fecha : {row("FechaTrama")} </td></tr>")
|
|
SBuilder.Append($"<tr><td>Conductor : {row("Conductor").ToString}</td></tr>")
|
|
If row.Table.Columns.Contains("Combustible") Then
|
|
SBuilder.Append($"<tr><td>Combustible : {IfNull(row("Combustible"), "NO DISPONIBLE", $"{row("Combustible").ToString.FormatoNumero} lts").ToString}</td></tr>")
|
|
End If
|
|
If row("SPD").ToString <> "-1" Then
|
|
SBuilder.Append($"<tr><td>Velocidad : {row("SPD").ToString} KM/H </td></tr>")
|
|
End If
|
|
If ExtraBody <> "" AndAlso ExtraBody <> "-1" Then
|
|
SBuilder.Append(ExtraBody)
|
|
End If
|
|
SBuilder.AppendFormat("<tr><td><a target=\'_blank\' href=\'https://www.google.com/maps/search/{0},{1}/\'>Ver en google maps</a></td></tr>", row("Lat").ToString, row("Lng").ToString)
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al consultar", ex)
|
|
End Try
|
|
SBuilder.Append($"</table></div><div></div></div>")
|
|
Return SBuilder.ToString
|
|
End Function
|
|
Protected Sub btnPagePrev_Click(sender As Object, e As EventArgs)
|
|
Dim TotalRegistros As Integer = DtPosiciones.Rows.Count
|
|
Dim TotalRowsPage As Integer = GvBarra.PageSize
|
|
Dim PrevIndex As Integer = HdnIndexPage.Value.ToEntero - 1
|
|
Dim CurrentIndex As Integer = PrevIndex + 1
|
|
|
|
Dim PrevIndexDT As Integer = (TotalRowsPage) * PrevIndex
|
|
Dim CurrentIndexDT As Integer = (TotalRowsPage) * CurrentIndex
|
|
|
|
HdnIndexPage.Value = PrevIndex.ToString
|
|
|
|
If Not btnPageNext.Enabled Then
|
|
btnPageNext.Enabled = True
|
|
End If
|
|
|
|
If PrevIndexDT <= 0 Then
|
|
btnPagePrev.Enabled = False
|
|
GvBarra.DataSource = DtPosiciones.FiltraPorIndices(0, CurrentIndexDT)
|
|
LblRegistros.Text = $"Distribución de datos desde 0 hasta {CurrentIndexDT.ToString.FormatoNumero(0)}. Total de registros: {DtPosiciones.Rows.Count.ToString.FormatoNumero(0)}"
|
|
Else
|
|
LblRegistros.Text = $"Distribución de datos desde {PrevIndexDT.ToString.FormatoNumero(0)} hasta {CurrentIndexDT.ToString.FormatoNumero(0)}. Total de registros: {DtPosiciones.Rows.Count.ToString.FormatoNumero(0)}"
|
|
GvBarra.DataSource = DtPosiciones.FiltraPorIndices(PrevIndexDT, CurrentIndexDT)
|
|
End If
|
|
|
|
GvBarra.DataBind()
|
|
UPGV.Update()
|
|
|
|
RegistraScript("setTimeout(function(){OpcionesHistorico();},500);")
|
|
End Sub
|
|
Protected Sub btnPageNext_Click(sender As Object, e As EventArgs)
|
|
Dim TotalRegistros As Integer = DtPosiciones.Rows.Count
|
|
Dim TotalRowsPage As Integer = GvBarra.PageSize
|
|
Dim Index As Integer = HdnIndexPage.Value.ToEntero + 1
|
|
Dim NextIndex As Integer = Index + 1
|
|
|
|
Dim CurrentIndexDT As Integer = (TotalRowsPage) * Index
|
|
Dim NextIndexDT As Integer = (TotalRowsPage) * NextIndex
|
|
|
|
HdnIndexPage.Value = Index.ToString
|
|
|
|
If Not btnPagePrev.Enabled Then
|
|
btnPagePrev.Enabled = True
|
|
End If
|
|
|
|
If NextIndexDT >= TotalRegistros Then
|
|
btnPageNext.Enabled = False
|
|
GvBarra.DataSource = DtPosiciones.FiltraPorIndices(CurrentIndexDT, TotalRegistros - 1)
|
|
LblRegistros.Text = $"Distribución de datos desde {CurrentIndexDT.ToString.FormatoNumero(0)} hasta {DtPosiciones.Rows.Count.ToString.FormatoNumero(0)}. Total de registros: {DtPosiciones.Rows.Count.ToString.FormatoNumero(0)}"
|
|
Else
|
|
GvBarra.DataSource = DtPosiciones.FiltraPorIndices(CurrentIndexDT, NextIndexDT)
|
|
LblRegistros.Text = $"Distribución de datos desde {CurrentIndexDT.ToString.FormatoNumero(0)} hasta {NextIndexDT.ToString.FormatoNumero(0)}. Total de registros: {DtPosiciones.Rows.Count.ToString.FormatoNumero(0)}"
|
|
End If
|
|
|
|
GvBarra.DataBind()
|
|
UPGV.Update()
|
|
|
|
RegistraScript("setTimeout(function(){OpcionesHistorico();},500);")
|
|
End Sub
|
|
|
|
|
|
Public Sub RegistraScript(Script As String, Optional valuetick As String = "")
|
|
Dim Rdm As Random = New Random()
|
|
ScriptManager.RegisterStartupScript(Page, Me.GetType(), String.Format("{0}{1}{2}", (DateTime.Now.Ticks + 1), Rdm.Next(), valuetick), String.Format("<script type='text/javascript' language='javascript'>{0}</script>", Script), False)
|
|
End Sub
|
|
|
|
End Class
|