353 lines
16 KiB
VB.net
353 lines
16 KiB
VB.net
Option Strict On
|
|
|
|
Imports System.Data
|
|
Imports System.IO
|
|
Imports System.Net
|
|
Imports Extensiones
|
|
Imports Microsoft.Reporting.WebForms
|
|
Imports Newtonsoft.Json.Linq
|
|
|
|
Partial Class GPS_Rastreo
|
|
Inherits ClsPaginas
|
|
|
|
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 Filtrado As Boolean
|
|
Get
|
|
Return CType(ViewState("Filtrado"), Boolean)
|
|
End Get
|
|
Set(value As Boolean)
|
|
ViewState("Filtrado") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property DtDatos As DataTable
|
|
Get
|
|
Return CType(ViewState("DtDatos"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtDatos") = value
|
|
End Set
|
|
End Property
|
|
|
|
|
|
Private Property FechaI As DateTime
|
|
Get
|
|
Return CType(ViewState("FechaI"), DateTime)
|
|
End Get
|
|
Set(value As DateTime)
|
|
ViewState("FechaI") = value
|
|
End Set
|
|
End Property
|
|
|
|
Private Property FechaF As DateTime
|
|
Get
|
|
Return CType(ViewState("FechaF"), DateTime)
|
|
End Get
|
|
Set(value As DateTime)
|
|
ViewState("FechaF") = 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
|
|
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
CargaDispositivos()
|
|
CargaGeoReferencias()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaDispositivos()
|
|
GvDispositivos.DataSource = GlobalDTDispositivosUsuarios(UsuarioActual.CveCliente, UsuarioActual.CveUsuario).FiltraParametros("Estatus = 1 ")
|
|
GvDispositivos.DataBind()
|
|
End Sub
|
|
|
|
Private Sub CargaGeoReferencias()
|
|
Dim GPS As New ClsGPS
|
|
If GPS.GeoReferenciaGet(-1, 1, "-1", UsuarioActual.CveCliente) Then
|
|
GVGeoreferencias.DataSource = GPS.DtResultados.FiltraParametros("Tipo = 'Geocerca'")
|
|
Else
|
|
GVGeoreferencias.DataSource = Nothing
|
|
End If
|
|
GPS.Dispose()
|
|
GVGeoreferencias.DataBind()
|
|
End Sub
|
|
|
|
Protected Sub GvGeoreferencias_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVGeoreferencias.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.FCLinkButton("imgColor").Style.Add("background-color", e.Row.DBCampo("Color").ToString)
|
|
End If
|
|
End Sub
|
|
|
|
Protected Sub BtnCosultar_Click(sender As Object, e As EventArgs) Handles BtnRastrear.Click
|
|
RegistraScript("DeleteMarkers();", "0")
|
|
CreaDataTable()
|
|
For Each row As GridViewRow In GvDispositivos.Rows
|
|
If row.FCCheckBox("chkDis").Checked Then
|
|
RastrearEquipo(row, "1")
|
|
End If
|
|
Next
|
|
RegistraScript("$('#dvConsulta').modal('hide');", "00")
|
|
End Sub
|
|
|
|
Private Sub RastrearEquipo(GVRow As GridViewRow, Opcion As String)
|
|
Dim GPS As New ClsGPS
|
|
Dim LastCoord As String = ""
|
|
Dim DtPosiciones As New DataTable
|
|
Dim Info = ""
|
|
Dim SBBody As New StringBuilder
|
|
Dim Icono As String = "/Imagenes/rsz_11rsz_car.png"
|
|
Dim CoordsPoligono = ""
|
|
Dim Coords = ""
|
|
Dim Titulo = ""
|
|
Dim COUNT = 0
|
|
Dim GeoCercas = ""
|
|
|
|
FechaI = If(txtFechaI.Text.Trim = "", MinFecha, txtFechaI.Text.Trim.ToDate)
|
|
FechaF = If(txtFechaF.Text.Trim = "", MaxFecha, txtFechaF.Text.Trim.ToDate)
|
|
|
|
For Each row As GridViewRow In GVGeoreferencias.Rows
|
|
If row.FCCheckBox("chkGR").Checked Then
|
|
If GPS.GeoReferenciasEntradasSalidas(GVRow.DataKey("CveDispositivo").ToString.ToEntero, row.DataKey("CveGeoReferencia").ToString.ToEntero, FechaI, FechaF) Then
|
|
If GPS.DtResultados.Rows.Count > 0 Then
|
|
CoordsPoligono = SQLToGmaps(row.DataKey("Coordenadas").ToString, "POLYGON")
|
|
For Each rr As DataRow In GPS.DtResultados.Rows
|
|
Coords = SQLToGmaps(rr("Posicion").ToString, "POINT")
|
|
|
|
Info = InfoWindow(rr("Evento").ToString, If(rr("Pasajeros").ToString = "", $"<tr><td>Vehículo: {GVRow.DataKey("NombreVehiculo").ToString}</td></tr>", $"<tr><td>Vehículo: {GVRow.DataKey("NombreVehiculo").ToString}</td></tr><tr><td>Pasajeros: {rr("Pasajeros").ToString}</td></tr>"), GVRow.DataKey("CveDispositivo").ToString.ToEntero, rr)
|
|
RegistraScript($"CreaMarcador({Coords},'{GVRow.DataKey("SerieVehiculo").ToString}', '{Info}', '{Icono}');", $"{rr("CveDispositivoEvento").ToString}{COUNT.ToString}")
|
|
COUNT += 1
|
|
Dim DrNew = DtDatos.NewRow()
|
|
|
|
DrNew("Unidad") = GVRow.DataKey("NombreVehiculo").ToString
|
|
DrNew("Fecha") = rr("FechaTrama").ToString
|
|
DrNew("Conductor") = rr("Conductor").ToString
|
|
DrNew("Geocerca") = row.DataKey("GeoReferencia").ToString
|
|
DrNew("Liga") = rr("Liga").ToString.Replace("&path=", $"&path={EncodeGeocercaString(row.DataKey("Coordenadas").ToString)}")
|
|
DrNew("Evento") = rr("Evento").ToString
|
|
DrNew("Direccion") = ""
|
|
DrNew("Lat") = rr("Lat").ToString
|
|
DrNew("Lng") = rr("Lng").ToString
|
|
|
|
DtDatos.Rows.Add(DrNew)
|
|
Next
|
|
RegistraScript($"creaPoligono([{CoordsPoligono}], '{row.DataKey("Color").ToString}')", $"{row.DataKey("CveGeoReferencia").ToString.ToEntero}{COUNT.ToString}")
|
|
Else
|
|
GeoCercas = $"{GeoCercas} {row.DataKey("GeoReferencia").ToString},"
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
If GeoCercas <> "" Then
|
|
Alert($"No se encontraron resultados para el Vehículo {GVRow.DataKey("SerieVehiculo").ToString} en las siguientes GeoCercas: {GeoCercas.Substring(0, GeoCercas.Length - 1)} ")
|
|
End If
|
|
GPS.Dispose()
|
|
End Sub
|
|
|
|
|
|
#Region "Carga Fechas Predeterminadas"
|
|
'Protected Sub BtnUltimas2_Click(sender As Object, e As EventArgs) Handles BtnUltimas2.Click
|
|
' CargaFechasPredeterminadas("2")
|
|
'End Sub
|
|
'Protected Sub BtnUltimas8_Click(sender As Object, e As EventArgs) Handles BtnUltimas8.Click
|
|
' CargaFechasPredeterminadas("8")
|
|
'End Sub
|
|
'Protected Sub BtnHoy_Click(sender As Object, e As EventArgs) Handles BtnHoy.Click
|
|
' CargaFechasPredeterminadas("24")
|
|
'End Sub
|
|
'Protected Sub BtnAyer_Click(sender As Object, e As EventArgs) Handles BtnAyer.Click
|
|
' CargaFechasPredeterminadas("48")
|
|
'End Sub
|
|
'Protected Sub BtnSemana_Click(sender As Object, e As EventArgs) Handles BtnSemana.Click
|
|
' CargaFechasPredeterminadas("Week")
|
|
'End Sub
|
|
'Protected Sub BtnMes_Click(sender As Object, e As EventArgs) Handles BtnMes.Click
|
|
' CargaFechasPredeterminadas("Month")
|
|
'End Sub
|
|
|
|
|
|
|
|
'Private Sub CargaFechasPredeterminadas(Opcion As String)
|
|
' If Opcion = "2" Then
|
|
' txtFechaI.Text = DateTime.Now.AddHours(-2).ToString("dd/MM/yyyy hh:mm")
|
|
' txtFechaF.Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm")
|
|
' ElseIf Opcion = "8" Then
|
|
' txtFechaI.Text = DateTime.Now.AddHours(-8).ToString("dd/MM/yyyy hh:mm")
|
|
' txtFechaF.Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm")
|
|
' ElseIf Opcion = "24" Then
|
|
' txtFechaI.Text = $"{DateTime.Now.ToString("dd/MM/yyyy")} 0:00"
|
|
' txtFechaF.Text = $"{DateTime.Now.ToString("dd/MM/yyyy")} 23:59"
|
|
' ElseIf Opcion = "48" Then
|
|
' txtFechaI.Text = $"{DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy")} 0:00"
|
|
' txtFechaF.Text = $"{DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy")} 23:59"
|
|
' ElseIf Opcion = "Week" Then
|
|
' txtFechaI.Text = $"{DateTime.Now.AddDays(-7).ToString("dd/MM/yyyy")} 0:00"
|
|
' txtFechaF.Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm")
|
|
' ElseIf Opcion = "Month" Then
|
|
' txtFechaI.Text = $"{New DateTime(Now.Year, Now.Month, 1).ToString("dd/MM/yyyy")} 0:00"
|
|
' txtFechaF.Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm")
|
|
' End If
|
|
|
|
' RegistraScript("CargaPickers();")
|
|
' upFechas.Update()
|
|
'End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "IMPRESION"
|
|
|
|
Public Sub CreaDataTable()
|
|
DtDatos = New DataTable()
|
|
DtDatos.Columns.Add("Unidad", GetType(String))
|
|
DtDatos.Columns.Add("Fecha", GetType(String))
|
|
DtDatos.Columns.Add("Conductor", GetType(String))
|
|
DtDatos.Columns.Add("Geocerca", GetType(String))
|
|
DtDatos.Columns.Add("Direccion", GetType(String))
|
|
DtDatos.Columns.Add("Liga", GetType(String))
|
|
DtDatos.Columns.Add("Evento", GetType(String))
|
|
DtDatos.Columns.Add("Lat", GetType(String))
|
|
DtDatos.Columns.Add("Lng", GetType(String))
|
|
End Sub
|
|
|
|
|
|
|
|
Public Sub EnviarReporteProgramado()
|
|
If DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 Then
|
|
Dim DireccionJSON As String = ""
|
|
Dim request As WebRequest
|
|
Dim js As JObject = Nothing
|
|
|
|
For Each Row As DataRow In DtDatos.Rows
|
|
Try
|
|
request = WebRequest.Create(String.Format("{0}nominatim/reverse.php?format=jsonv2&lat={1}&lon={2}", ClsPaginas.UrlDirecciones, Row("Lat"), Row("Lng")))
|
|
request.Method = "GET" ' set default credentials
|
|
Dim response As WebResponse = Request.GetResponse() ' fire this puppy off
|
|
Dim inputstream1 As Stream = response.GetResponseStream() ' define the stream(must be stream
|
|
Dim reader As New StreamReader(inputstream1) ' get the data stream set
|
|
DireccionJSON = reader.ReadToEnd ' get all the chucks
|
|
inputstream1.Dispose() ' get rid of the stream, we no longer need it
|
|
reader.Close() ' house keeping
|
|
response.Close()
|
|
request = Nothing
|
|
js = JObject.Parse(DireccionJSON)
|
|
If js IsNot Nothing Then
|
|
Row("Direccion") = js("display_name").ToString()
|
|
End If
|
|
Catch ex As Exception
|
|
GuardaLog(ex.ToString)
|
|
End Try
|
|
Next
|
|
|
|
Dim retorno As Byte()
|
|
Dim RutaReporte = "Empresas/Grales/ReportesProgramados/RPGeocercas.rdlc"
|
|
|
|
Try
|
|
Dim RptParametro As New List(Of ReportParameter)
|
|
RptParametro.Add(New ReportParameter("FechaInicio", FechaI.ToShortDateString))
|
|
RptParametro.Add(New ReportParameter("FechaFin", FechaF.ToShortDateString))
|
|
RptParametro.Add(New ReportParameter("MapaURL", ""))
|
|
RptParametro.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario))
|
|
RptParametro.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString))
|
|
|
|
retorno = StreamPDF(RutaReporte, DtDatos, RptParametro, "ReporteProgramado", "PDF", MR:=Nothing, RDSName:="DsOC")
|
|
|
|
ImprimirbytesPDF(retorno, "ReporteGeocercas")
|
|
|
|
DtDatos.Clear()
|
|
|
|
Catch ex As Exception
|
|
GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex))
|
|
End Try
|
|
Else
|
|
Alert("No se pudo imprimir el pdf, ya que no se ha hecho una consulta, o ésta no arrojó resultados.", TipoMensaje.MsgInformacion)
|
|
End If
|
|
|
|
End Sub
|
|
Public Sub EnviarReporteProgramadoDetallado()
|
|
If DtDatos IsNot Nothing AndAlso DtDatos.Rows.Count > 0 Then
|
|
Dim DireccionJSON As String = ""
|
|
Dim request As WebRequest
|
|
Dim js As JObject = Nothing
|
|
|
|
For Each Row As DataRow In DtDatos.Rows
|
|
Try
|
|
request = WebRequest.Create(String.Format("{0}nominatim/reverse.php?format=jsonv2&lat={1}&lon={2}", ClsPaginas.UrlDirecciones, Row("Lat"), Row("Lng")))
|
|
request.Method = "GET" ' set default credentials
|
|
Dim response As WebResponse = request.GetResponse() ' fire this puppy off
|
|
Dim inputstream1 As Stream = response.GetResponseStream() ' define the stream(must be stream
|
|
Dim reader As New StreamReader(inputstream1) ' get the data stream set
|
|
DireccionJSON = reader.ReadToEnd ' get all the chucks
|
|
inputstream1.Dispose() ' get rid of the stream, we no longer need it
|
|
reader.Close() ' house keeping
|
|
response.Close()
|
|
request = Nothing
|
|
js = JObject.Parse(DireccionJSON)
|
|
If js IsNot Nothing Then
|
|
Row("Direccion") = js("display_name").ToString()
|
|
End If
|
|
Catch ex As Exception
|
|
GuardaLog(ex.ToString)
|
|
End Try
|
|
Next
|
|
|
|
Dim retorno As Byte()
|
|
Dim RutaReporte = "Empresas/Grales/ReportesProgramados/ReporteGRDetallado.rdlc"
|
|
|
|
Try
|
|
Dim RptParametro As New List(Of ReportParameter)
|
|
RptParametro.Add(New ReportParameter("FechaInicio", FechaI.ToShortDateString))
|
|
RptParametro.Add(New ReportParameter("FechaFin", FechaF.ToShortDateString))
|
|
RptParametro.Add(New ReportParameter("MapaURL", ""))
|
|
RptParametro.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario))
|
|
RptParametro.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString))
|
|
|
|
retorno = StreamPDF(RutaReporte, DtDatos, RptParametro, "ReporteProgramado", "PDF", MR:=Nothing, RDSName:="DsOC")
|
|
|
|
' Dim ObjMail As New ClsSisMail()
|
|
|
|
'Dim ObjEmpresa As New ClsSisEmpresas()
|
|
'ObjEmpresa.GetEmpresas(1, "-1", "-1", "-1", "-1")
|
|
|
|
|
|
'Dim ResultadoMail As Integer = 0
|
|
|
|
'Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
|
|
|
|
'LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = retorno, .NombreArchivo = "ReporteProgramado.pdf"})
|
|
'LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.Ruta = Xml})
|
|
|
|
ImprimirbytesPDF(retorno, "ReporteGeocercas")
|
|
|
|
DtDatos.Clear()
|
|
|
|
Catch ex As Exception
|
|
GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex))
|
|
End Try
|
|
Else
|
|
Alert("No se pudo imprimir el pdf, ya que no se ha hecho una consulta, o ésta no arrojó resultados.", TipoMensaje.MsgInformacion)
|
|
End If
|
|
|
|
End Sub
|
|
#End Region
|
|
Protected Sub LnkPDF_Click(sender As Object, e As EventArgs)
|
|
EnviarReporteProgramado()
|
|
End Sub
|
|
Protected Sub LnkPDFDetallado_Click(sender As Object, e As EventArgs)
|
|
EnviarReporteProgramadoDetallado()
|
|
End Sub
|
|
End Class
|