1465 lines
62 KiB
Plaintext
1465 lines
62 KiB
Plaintext
<%@ WebService Language="VB" Class="WSGPSApp" %>
|
|
Option Strict On
|
|
|
|
Imports System.Web
|
|
Imports System.Web.Services
|
|
Imports System.Web.Services.Protocols
|
|
Imports System.Data
|
|
Imports Extensiones
|
|
Imports Newtonsoft.Json
|
|
Imports Newtonsoft.Json.Linq
|
|
Imports System.Globalization
|
|
Imports System.Web.Script.Services
|
|
Imports System.Web.Script.Serialization
|
|
Imports ADGPSModels
|
|
Imports System.IO
|
|
Imports System.Net.Http
|
|
|
|
|
|
Public Class AuthHeader
|
|
Inherits SoapHeader
|
|
Public Property Username As String
|
|
Public Property Password As String
|
|
End Class
|
|
|
|
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
|
|
' <System.Web.Script.Services.ScriptService()> _
|
|
<WebService(Namespace:="http://tempuri.org/")>
|
|
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
|
|
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
|
Public Class WSGPSApp
|
|
Inherits System.Web.Services.WebService
|
|
|
|
Private Const LongValue As Long = &H100000000
|
|
Public Property Credentials As AuthHeader
|
|
|
|
#Region "G L O B A L S"
|
|
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(Application("GlobalDTDispositivos"), DataTable), Str.ToString, "", DataViewRowState.CurrentRows)
|
|
GlobalDTDispositivos = Dv.ToTable
|
|
Dv.Dispose()
|
|
Else
|
|
GlobalDTDispositivos = DirectCast(Application("GlobalDTDispositivos"), DataTable)
|
|
End If
|
|
|
|
End Get
|
|
Set(value As DataTable)
|
|
Application("GlobalDTDispositivos") = value
|
|
End Set
|
|
End Property
|
|
Property GlobalDTUsuarios(Optional CveUsuario As Integer = -1, Optional CveEmpresa As Integer = -1, Optional CveCliente As Integer = -1, Optional CveProveedor As Integer = -1) As DataTable
|
|
Get
|
|
Dim Str As New StringBuilder
|
|
If CveUsuario <> -1 Then Str.AppendFormat("CveUsuario = {0}", CveUsuario)
|
|
If CveEmpresa <> -1 Then Str.AppendFormat(" {0} CveEmpresa = {1}", If(Str.Length > 0, "AND", ""), CveEmpresa)
|
|
If CveCliente <> -1 Then Str.AppendFormat(" {0} CveCliente = {1}", If(Str.Length > 0, "AND", ""), CveCliente)
|
|
If CveProveedor <> -1 Then Str.AppendFormat(" {0} CveProveedor = {1}", If(Str.Length > 0, "AND", ""), CveProveedor)
|
|
|
|
If CveUsuario <> -1 OrElse CveEmpresa <> -1 Then
|
|
Dim Dv As New DataView(DirectCast(Application("GlobalDTUsuarios"), DataTable), Str.ToString, "", DataViewRowState.CurrentRows)
|
|
GlobalDTUsuarios = Dv.ToTable
|
|
Dv.Dispose()
|
|
Else
|
|
GlobalDTUsuarios = DirectCast(Application("GlobalDTUsuarios"), DataTable)
|
|
End If
|
|
End Get
|
|
Set(value As DataTable)
|
|
Application("GlobalDTUsuarios") = value
|
|
End Set
|
|
End Property
|
|
Property GlobalDTDispositivosUsuarios(CveCliente As Integer, Optional CveUsuario As Integer = -1) As DataTable
|
|
Get
|
|
Dim Str As StringBuilder = New StringBuilder()
|
|
If CveUsuario <> -1 Then Str.AppendFormat("CveUsuario = {0}", CveUsuario)
|
|
If CveCliente <> -1 Then Str.AppendFormat(" {0} CveCliente = {1}", If(Str.Length > 0, "AND", ""), CveCliente)
|
|
If CveUsuario <> -1 OrElse CveCliente <> -1 Then
|
|
Dim Dv As New DataView(DirectCast(Application("GlobalDTDispositivosUsuarios"), DataTable), Str.ToString, "", DataViewRowState.CurrentRows)
|
|
GlobalDTDispositivosUsuarios = Dv.ToTable
|
|
Dv.Dispose()
|
|
Else
|
|
GlobalDTDispositivosUsuarios = DirectCast(Application("GlobalDTDispositivosUsuarios"), DataTable)
|
|
End If
|
|
End Get
|
|
Set(value As DataTable)
|
|
Application("GlobalDTDispositivosUsuarios") = value
|
|
End Set
|
|
End Property
|
|
#End Region
|
|
Private Sub CreaObjetoEmpresa(ByRef UsuarioActual As Usuario)
|
|
|
|
Dim ObjEmpresa As New ClsSisEmpresas()
|
|
If ObjEmpresa.GetEmpresas(UsuarioActual.CveEmpresa, "-1", "-1", "-1", "-1") Then
|
|
If ObjEmpresa.GetEmpresasFuncionalidades(UsuarioActual.CveEmpresa) Then
|
|
Dim dttmp As Data.DataTable = ObjEmpresa.DtResultados
|
|
|
|
Dim EmpresasFuncionalidades As New HybridDictionary
|
|
For Each Row As Data.DataRow In dttmp.Rows
|
|
EmpresasFuncionalidades.Add(Convert.ToInt32(Row("CveFuncionalidad")), Row("Valor").ToString)
|
|
Next
|
|
ObjEmpresa.Empresa.SetFuncionalidades(EmpresasFuncionalidades)
|
|
End If
|
|
|
|
UsuarioActual.Empresa = ObjEmpresa.Empresa
|
|
End If
|
|
ObjEmpresa.Dispose()
|
|
End Sub
|
|
|
|
<SoapHeader("Credentials")>
|
|
<WebMethod>
|
|
Public Function Login(params As String) As String
|
|
Dim Retorno As String = ""
|
|
Dim ObjUsuarios As New ClsSisUsuarios
|
|
Try
|
|
Dim json = Decripta(params, "AES")
|
|
Dim Datos As MWSLogin2 = JsonConvert.DeserializeObject(Of MWSLogin2)(json)
|
|
Dim UsuarioActual = ObjUsuarios.ValidaUsuario(Decripta(Datos.Usuario, "AES"), Encripta(Decripta(Datos.Contraseña, "AES")))
|
|
|
|
If UsuarioActual IsNot Nothing Then
|
|
Dim UsuarioRetorno As New WSUSER2
|
|
UsuarioRetorno.CveUsuario = UsuarioActual.CveUsuario
|
|
UsuarioRetorno.CveEmpresa = UsuarioActual.CveEmpresa
|
|
UsuarioRetorno.CveCliente = UsuarioActual.CveCliente
|
|
UsuarioRetorno.Usuario = UsuarioActual.Usuario
|
|
UsuarioRetorno.Nombre = UsuarioActual.Nombre
|
|
UsuarioRetorno.CveRol = UsuarioActual.CveRol
|
|
UsuarioRetorno.Rol = UsuarioActual.Rol
|
|
UsuarioRetorno.Contrasenia = UsuarioActual.Contraseña
|
|
UsuarioRetorno.CveSubProyecto = UsuarioActual.CveSubProyecto
|
|
UsuarioRetorno.Procesos = UsuarioActual.Procesos.Values.Cast(Of String).ToList()
|
|
|
|
Dim UsuariosModulos As New List(Of WsModulos)
|
|
Dim Empresas As New List(Of WsEmpresa)
|
|
Dim Clientes As New List(Of WsClientePortalGPS)
|
|
|
|
If ObjUsuarios.GetUsuariosModulos(UsuarioRetorno.CveUsuario, -1) Then
|
|
Dim DtModulos As DataTable = ObjUsuarios.DtResultados.FiltraParametros("CvePlataforma = 5 AND Permitir = 1")
|
|
For Each Row As DataRow In DtModulos.Rows
|
|
UsuariosModulos.Add(New WsModulos With {.CveModulo = Row("CveModulo").ToString.ToEntero, .CvePadre = Row("CvePadre").ToString.ToEntero, .CvePlataforma = 5, .Estilo = Row("Estilo").ToString, .Liga = Row("Liga").ToString, .Modulo = Row("Modulo").ToString, .Parametros = Row("Parametros").ToString})
|
|
Next
|
|
DtModulos.Dispose()
|
|
DtModulos = Nothing
|
|
End If
|
|
UsuarioRetorno.Modulos = UsuariosModulos
|
|
Dim DtClientes As DataTable = GlobalDTUsuarios(UsuarioActual.CveUsuario).FiltraParametros("CvePlataforma = 3 AND CveCliente IS NOT NULL", "Empresa")
|
|
If DtClientes IsNot Nothing Then
|
|
If DtClientes.Rows.Count > 0 Then
|
|
For Each Row As DataRow In DtClientes.Rows
|
|
Clientes.Add(New WsClientePortalGPS With {.CveCliente = Row("CveCliente").ToString.ToEntero, .Cliente = Row("Cliente").ToString})
|
|
Next
|
|
If UsuarioActual.CveCliente <= 0 AndAlso Clientes.Any() Then
|
|
UsuarioRetorno.CveCliente = Clientes.FirstOrDefault().CveCliente
|
|
If UsuarioRetorno.CveCliente > 0 Then
|
|
CreaObjetoEmpresa(UsuarioActual)
|
|
If UsuarioActual.Empresa.Funcionalidad(704).Contiene(UsuarioRetorno.CveCliente.ToString()) OrElse UsuarioActual.CveUsuario = 3612 Then
|
|
UsuarioRetorno.RastreoSoloInicio = True
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
'MARCA PARA EL RASTREO SOLO INICIO
|
|
If UsuarioRetorno.CveUsuario = 3612 Then
|
|
UsuarioRetorno.RastreoSoloInicio = True
|
|
End If
|
|
|
|
UsuarioRetorno.Clientes = Clientes
|
|
DtClientes.Dispose()
|
|
DtClientes = Nothing
|
|
Retorno = Encripta(JsonConvert.SerializeObject(UsuarioRetorno), "AES")
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
OnError("Ocurrio un error al iniciar sesion.", ex)
|
|
Finally
|
|
ObjUsuarios.Dispose()
|
|
End Try
|
|
Return Retorno
|
|
|
|
End Function
|
|
'<SoapHeader("Credentials")>
|
|
<WebMethod>
|
|
Public Function Login2(params As String) As String
|
|
Dim Retorno As String = ""
|
|
Dim ObjUsuarios As New ClsSisUsuarios
|
|
Try
|
|
Dim json = Decripta(params, "AES")
|
|
Dim Datos As MWSLogin2 = JsonConvert.DeserializeObject(Of MWSLogin2)(json)
|
|
Dim UsuarioActual = ObjUsuarios.ValidaUsuario(Decripta(Datos.Usuario, "AES"), Encripta(Decripta(Datos.Contraseña, "AES")))
|
|
|
|
If UsuarioActual IsNot Nothing Then
|
|
Dim UsuarioRetorno As New WSUSER2
|
|
UsuarioRetorno.CveUsuario = UsuarioActual.CveUsuario
|
|
UsuarioRetorno.CveEmpresa = UsuarioActual.CveEmpresa
|
|
UsuarioRetorno.CveCliente = UsuarioActual.CveCliente
|
|
UsuarioRetorno.Usuario = UsuarioActual.Usuario
|
|
UsuarioRetorno.Nombre = UsuarioActual.Nombre
|
|
UsuarioRetorno.CveRol = UsuarioActual.CveRol
|
|
UsuarioRetorno.Rol = UsuarioActual.Rol
|
|
UsuarioRetorno.Contrasenia = UsuarioActual.Contraseña
|
|
UsuarioRetorno.CveSubProyecto = UsuarioActual.CveSubProyecto
|
|
UsuarioRetorno.Procesos = UsuarioActual.Procesos.Values.Cast(Of String).ToList()
|
|
|
|
Dim UsuariosModulos As New List(Of WsModulos)
|
|
Dim Empresas As New List(Of WsEmpresa)
|
|
Dim Clientes As New List(Of WsClientePortalGPS)
|
|
|
|
If ObjUsuarios.GetUsuariosModulos(UsuarioRetorno.CveUsuario, -1) Then
|
|
Dim DtModulos As DataTable = ObjUsuarios.DtResultados.FiltraParametros("CvePlataforma = 5 AND Permitir = 1")
|
|
For Each Row As DataRow In DtModulos.Rows
|
|
UsuariosModulos.Add(New WsModulos With {.CveModulo = Row("CveModulo").ToString.ToEntero, .CvePadre = Row("CvePadre").ToString.ToEntero, .CvePlataforma = 5, .Estilo = Row("Estilo").ToString, .Liga = Row("Liga").ToString, .Modulo = Row("Modulo").ToString, .Parametros = Row("Parametros").ToString})
|
|
Next
|
|
DtModulos.Dispose()
|
|
DtModulos = Nothing
|
|
End If
|
|
|
|
UsuarioRetorno.Modulos = UsuariosModulos
|
|
Dim DtClientes As DataTable = GlobalDTUsuarios(UsuarioActual.CveUsuario).FiltraParametros("CvePlataforma = 3 AND CveCliente > 0", "Empresa")
|
|
If DtClientes IsNot Nothing Then
|
|
If DtClientes.Rows.Count > 0 Then
|
|
For Each Row As DataRow In DtClientes.Rows
|
|
Clientes.Add(New WsClientePortalGPS With {.CveCliente = Row("CveCliente").ToString.ToEntero, .Cliente = Row("Cliente").ToString})
|
|
Next
|
|
If UsuarioActual.CveCliente <= 0 AndAlso Clientes.Any() Then
|
|
UsuarioRetorno.CveCliente = Clientes.FirstOrDefault().CveCliente
|
|
If UsuarioActual.CveCliente <= 0 AndAlso Clientes.Any() Then
|
|
UsuarioRetorno.CveCliente = Clientes.FirstOrDefault().CveCliente
|
|
If UsuarioRetorno.CveCliente > 0 Then
|
|
CreaObjetoEmpresa(UsuarioActual)
|
|
If UsuarioActual.Empresa.Funcionalidad(704).Contiene(UsuarioRetorno.CveCliente.ToString()) OrElse UsuarioActual.CveUsuario = 3612 Then
|
|
UsuarioRetorno.RastreoSoloInicio = True
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
End If
|
|
|
|
'MARCA PARA EL RASTREO SOLO INICIO
|
|
If UsuarioRetorno.CveUsuario = 3612 Then
|
|
UsuarioRetorno.RastreoSoloInicio = True
|
|
End If
|
|
|
|
UsuarioRetorno.Clientes = Clientes
|
|
DtClientes.Dispose()
|
|
DtClientes = Nothing
|
|
Retorno = Encripta(JsonConvert.SerializeObject(UsuarioRetorno), "AES")
|
|
Else
|
|
Dim UsuarioError As New WSUSER2
|
|
UsuarioError.CveUsuario = -2
|
|
UsuarioError.CveEmpresa = -1
|
|
UsuarioError.CveCliente = -1
|
|
UsuarioError.Usuario = ""
|
|
UsuarioError.Nombre = ""
|
|
UsuarioError.CveRol = -1
|
|
UsuarioError.Rol = ""
|
|
UsuarioError.Contrasenia = ""
|
|
UsuarioError.CveSubProyecto = -1
|
|
|
|
Retorno = Encripta(JsonConvert.SerializeObject(UsuarioError), "AES")
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
Retorno = ""
|
|
OnError("Ocurrio un error al iniciar sesion.", ex)
|
|
Finally
|
|
ObjUsuarios.Dispose()
|
|
End Try
|
|
Return Retorno
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetPosicionesEquipos(strParams As String) As String
|
|
Dim json = "[]"
|
|
Dim Retorno As String = ""
|
|
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveCliente] = -1,
|
|
Key .[CveUsuario] = -1,
|
|
Key .[Ticks] = ""
|
|
}
|
|
|
|
Dim decripParams As String = Decripta(strParams)
|
|
Dim Ent = JsonConvert.DeserializeAnonymousType(decripParams, Estructura)
|
|
|
|
If IsCurrentDate(Ent.Ticks) Then
|
|
Dim Datos As New List(Of MWSDispositivo2)
|
|
Dim DTEqupos = GlobalDTDispositivosUsuarios(Ent.CveCliente, Ent.CveUsuario).FiltraParametros("Estatus = 1").AsEnumerable().Take(10)
|
|
|
|
'Dim ObjGPS As New ClsGPS()
|
|
'For Each row As DataRow In DTEqupos.Rows
|
|
' Dim CveDispositivo = row("CveDispositivo").ToString.ToEntero
|
|
' If ObjGPS.GetPosicionEquipoApp(CveDispositivo) Then
|
|
' If ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
' Dim dispo As New MWSDispositivo2
|
|
' Dim Coord As MWSGeolocation2 = SQLToGmaps(ObjGPS.DtResultados.Rows(0)("Posicion").ToString, "POINT")
|
|
' dispo.CveDispositivo = CveDispositivo
|
|
' dispo.Geolocation = Coord
|
|
' dispo.CveTrama = ObjGPS.DtResultados.Rows(0)("CveTrama").ToString.ToEntero()
|
|
' dispo.FechaTrama = ObjGPS.DtResultados.Rows(0)("FechaTrama").ToString
|
|
' dispo.NombreVehiculo = ObjGPS.DtResultados.Rows(0)("NombreVehiculo").ToString
|
|
' dispo.Conductor = ObjGPS.DtResultados.Rows(0)("Conductor").ToString()
|
|
' dispo.Conductor = ObjGPS.DtResultados.Rows(0)("Conductor").ToString
|
|
' dispo.Velocidad = ObjGPS.DtResultados.Rows(0)("SPD").ToString.ToDouble()
|
|
' dispo.AñoVehiculo = ObjGPS.DtResultados.Rows(0)("AñoVehiculo").ToString
|
|
' dispo.OtrosDetalles = ObjGPS.DtResultados.Rows(0)("DetallesVehiculo").ToString
|
|
' Datos.Add(dispo)
|
|
' End If
|
|
' End If
|
|
'Next
|
|
'ObjGPS.Dispose()
|
|
|
|
|
|
Dim SbEquipos = New StringBuilder()
|
|
For Each row As DataRow In DTEqupos
|
|
SbEquipos.Append($"{row("CveDispositivo")};")
|
|
Next
|
|
|
|
Dim ObjGPS As New ClsGPS()
|
|
If ObjGPS.UltimaPosicionEquipoGet(SbEquipos.ToString, Ent.CveCliente) Then
|
|
If ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
For Each Dr As DataRow In ObjGPS.DtResultados.Rows
|
|
Dim CveDispositivo = Dr("CveDispositivo").ToString.ToEntero
|
|
|
|
Dim dispo As New MWSDispositivo2
|
|
Dim Coord As MWSGeolocation2 = SQLToGmaps(Dr("Posicion").ToString, "POINT")
|
|
|
|
dispo.CveDispositivo = CveDispositivo
|
|
dispo.Geolocation = Coord
|
|
dispo.CveTrama = Dr("CveTrama").ToString.ToEntero()
|
|
dispo.FechaTrama = Dr("FechaTrama").ToString
|
|
dispo.NombreVehiculo = Dr("NombreVehiculo").ToString
|
|
dispo.Conductor = Dr("Conductor").ToString()
|
|
dispo.Conductor = Dr("Conductor").ToString
|
|
dispo.Velocidad = Dr("SPD").ToString.ToDouble()
|
|
dispo.AñoVehiculo = "" 'Dr("AñoVehiculo").ToString
|
|
dispo.OtrosDetalles = "" 'Dr("DetallesVehiculo").ToString
|
|
|
|
Datos.Add(dispo)
|
|
Next
|
|
End If
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
If Datos.Count > 0 Then
|
|
json = JsonConvert.SerializeObject(Datos)
|
|
Retorno = Encripta(json)
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrio un error al obterner las posiciones", ex)
|
|
End Try
|
|
|
|
Return Retorno
|
|
|
|
|
|
End Function
|
|
'<WebMethod>
|
|
'Public Function TestNotificaciones() As String
|
|
' Dim Retorno As String = "[]"
|
|
' Using ObjGPS As New ClsSisNotificaciones
|
|
' ObjGPS.ObtenerNotificaciones()
|
|
' End Using
|
|
' Return Retorno
|
|
'End Function
|
|
<WebMethod>
|
|
Public Function GetGPSMarcas() As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.GetMarca(-1, 1) Then
|
|
Retorno = ObjGPS.DtResultados.ToJson()
|
|
End If
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetGPSModelos() As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.ModeloGet(-1, 1) Then
|
|
Retorno = ObjGPS.DtResultados.ToJson()
|
|
End If
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetLineasTelefono(CveEmpresa As Integer, CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.ProveedoresComunicacionCuentasGet(-1, CveEmpresa, CveCliente) Then
|
|
Retorno = ObjGPS.DtResultados.FiltraParametros("CveDispositivo is NULL").ToJson()
|
|
End If
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetUltimaPosicion(CveDispositivo As Integer, CveUsuario As Integer, CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.GetUltimaPosicionEquiposApp(CveDispositivo, CveUsuario, CveCliente)
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetUltimaPosicion2(CveDispositivo As Integer, CveUsuario As Integer, CveCliente As Integer, TieneCombustible As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.GetUltimaPosicionEquiposApp(CveDispositivo, CveUsuario, CveCliente, TieneCombustible)
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function BuscarEquipo(Nombre As String, CveUsuario As Integer, CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.GetBuscarDispositivosApp(Nombre, CveUsuario, CveCliente)
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetRepCombustible(CveDispositivo As Integer, FechaI As String, FechaF As String) As String
|
|
Dim Datos As New JObject()
|
|
Using ObjGPS As New ClsGPS
|
|
Dim JsonArray As JArray = JArray.Parse(ObjGPS.GetRepCombustibleApp(CveDispositivo, FechaI.ToDateTime(), FechaF.ToDateTime()))
|
|
Datos.Add(New JProperty("Datos", JsonArray(0)(0)))
|
|
Datos.Add(New JProperty("Historico", JsonArray(1)))
|
|
Datos.Add(New JProperty("Cargas", JsonArray(2)))
|
|
Datos.Add(New JProperty("Descargas", JsonArray(3)))
|
|
End Using
|
|
Return Datos.ToString()
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetGeoReferencias(CveDispositivo As Integer, CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.GetGeoReferenciasDetalleApp(-1, -1, CveDispositivo, CveCliente)
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetDashboard(CveCliente As Integer, FechaI As String, FechaF As String) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.GetDashboard(CveCliente, FechaI.ToDateTime(), FechaF.ToDateTime())
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function AddTramaApp(DevID As String, Lat As Double, Lng As Double, FechaTrama As DateTime, SO As String, Speed As Double) As Boolean
|
|
Dim Retorno As Boolean = False
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.AddTrama(DevID, "", Lat, Lng, FechaTrama, Speed)
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetDispositivosTemp(CveCliente As Integer) As String
|
|
Dim Retorno As String = ""
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.DispositivosGet(-1, 1, CveCliente) Then
|
|
Retorno = ObjGPS.DtResultados.ToJson()
|
|
End If
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function AddDispositivo(p As String) As Integer
|
|
Dim Retorno As Integer = -1
|
|
Dim ObjGPS As New ClsGPS
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
.TipoDispostivo = -1,
|
|
.CveCliente = -1,
|
|
.CveModelo = -1,
|
|
.DevID = "",
|
|
.IMEI = "",
|
|
.Serie = "",
|
|
.NumTelefono = "",
|
|
.CveProveedorComunicacionCuenta = -1,
|
|
.NombreVehiculo = "",
|
|
.SerieVehiculo = "",
|
|
.NumEconomico = "",
|
|
.Anio = ""
|
|
}
|
|
Dim JsonParams = Decripta(p)
|
|
Dim Ent = JsonConvert.DeserializeAnonymousType(JsonParams, Estructura)
|
|
If ObjGPS.DispositivoAdd(Ent.TipoDispostivo, Ent.NumTelefono, Ent.CveModelo, Ent.CveProveedorComunicacionCuenta, Ent.CveCliente, Ent.IMEI, Ent.Serie, 1, Ent.SerieVehiculo, "", Ent.NombreVehiculo, Ent.NombreVehiculo, Ent.DevID, 0, "", Ent.Anio, "", "", False, 100D, "", 0D, "", "", 100, "") Then
|
|
Retorno = ObjGPS.CveDispositivo
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al agregar el dispostiivo", ex)
|
|
Retorno = -1
|
|
Finally
|
|
ObjGPS.Dispose()
|
|
CargaGlobalDispositivos()
|
|
End Try
|
|
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function SaveDispositivo(p As String) As Integer
|
|
Dim Retorno As Integer = -1
|
|
Dim ObjGPS As New ClsGPS
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
.CveDispositivo = -1,
|
|
.TipoDispostivo = -1,
|
|
.CveCliente = -1,
|
|
.CveModelo = -1,
|
|
.DevID = "",
|
|
.IMEI = "",
|
|
.Serie = "",
|
|
.NumTelefono = "",
|
|
.CveProveedorComunicacionCuenta = -1,
|
|
.NombreVehiculo = "",
|
|
.SerieVehiculo = "",
|
|
.NumEconomico = "",
|
|
.Anio = ""
|
|
}
|
|
Dim JsonParams = Decripta(p)
|
|
Dim Ent = JsonConvert.DeserializeAnonymousType(JsonParams, Estructura)
|
|
|
|
If Ent.CveDispositivo > 0 Then
|
|
If ObjGPS.DispositivosUpdate(Ent.TipoDispostivo, Ent.NumTelefono, Ent.CveDispositivo, Ent.CveModelo, Ent.CveProveedorComunicacionCuenta, Ent.CveCliente, Ent.IMEI, Ent.Serie, 1, Ent.SerieVehiculo, "", Ent.NombreVehiculo, Ent.NombreVehiculo, Ent.DevID, 0, "", Ent.Anio, "", "", False, 100D, "", 0D, "", "", 100, "") Then
|
|
Retorno = Ent.CveDispositivo
|
|
End If
|
|
Else
|
|
If ObjGPS.DispositivoAdd(Ent.TipoDispostivo, Ent.NumTelefono, Ent.CveModelo, Ent.CveProveedorComunicacionCuenta, Ent.CveCliente, Ent.IMEI, Ent.Serie, 1, Ent.SerieVehiculo, "", Ent.NombreVehiculo, Ent.NombreVehiculo, Ent.DevID, 0, "", Ent.Anio, "", "", False, 100D, "", 0D, "", "", 100, "") Then
|
|
Retorno = ObjGPS.CveDispositivo
|
|
End If
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al agregar el dispostiivo", ex)
|
|
Retorno = -1
|
|
Finally
|
|
ObjGPS.Dispose()
|
|
CargaGlobalDispositivos()
|
|
End Try
|
|
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function AddImagenDispositivo(params As String) As Boolean
|
|
Dim TieneError As Boolean = False
|
|
Dim Estructura = New With {.CveDispositivo = -1, .Imagen = New With {.Base64Archivo = "", .Directorio = "", .Descripcion = ""}}
|
|
Dim ObjBitacora As New ClsGPS
|
|
ObjBitacora.IniciaTransacSQL()
|
|
Try
|
|
Dim item = JsonConvert.DeserializeAnonymousType(params, Estructura)
|
|
If item.CveDispositivo > 0 Then
|
|
Dim FileExtension = ""
|
|
If Not String.IsNullOrEmpty(item.Imagen.Directorio) Then
|
|
FileExtension = System.IO.Path.GetExtension(item.Imagen.Directorio)
|
|
End If
|
|
Dim CveImagenDispositivo As Integer = ObjBitacora.AddImagenDispositivo(item.CveDispositivo, "", item.Imagen.Descripcion)
|
|
If CveImagenDispositivo > 0 Then
|
|
If Not String.IsNullOrEmpty(FileExtension) Then
|
|
Dim CveEmpresa As Integer = -1
|
|
If ObjBitacora.DispositivosGet(item.CveDispositivo, 1, -1) Then
|
|
If ObjBitacora.DtResultados.Rows.Count > 0 Then
|
|
CveEmpresa = ObjBitacora.DtResultados.Rows(0)("CveEmpresa").ToString().ToEntero()
|
|
End If
|
|
End If
|
|
If CveEmpresa > 0 Then
|
|
Dim Archivo As String = String.Format("{0}{1}", CveImagenDispositivo, FileExtension)
|
|
Dim Directorio As String = String.Format("{0}\Empresas\{1}\Dispositivos\{2}\Imagenes\", ModExtensiones.DirectorioBaseEmpresas, CveEmpresa, item.CveDispositivo)
|
|
If Not Directory.Exists(Directorio) Then
|
|
Directory.CreateDirectory(Directorio)
|
|
End If
|
|
File.WriteAllBytes(String.Format("{0}{1}", Directorio, Archivo), Convert.FromBase64String(item.Imagen.Base64Archivo))
|
|
If Not ObjBitacora.UpdateImagenDispositivo(CveImagenDispositivo, Archivo) Then
|
|
TieneError = True
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
Catch ex As Exception
|
|
TieneError = True
|
|
OnError("Ocurrió un error al agregar las imagenes", ex)
|
|
Finally
|
|
If TieneError Then
|
|
ObjBitacora.RollBack()
|
|
Else
|
|
ObjBitacora.Commit()
|
|
End If
|
|
ObjBitacora.Dispose()
|
|
End Try
|
|
Return Not TieneError
|
|
End Function
|
|
|
|
Private Sub CargaGlobalDispositivos()
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.DispositivosGet(-1, -1, -1, -1) Then
|
|
GlobalDTDispositivos(-1) = ObjGPS.DtResultados
|
|
End If
|
|
If ObjGPS.DispositivosUsuariosGet(-1, -1, -1, -1, -1) Then
|
|
GlobalDTDispositivosUsuarios(-1, -1) = ObjGPS.DtResultados
|
|
End If
|
|
|
|
ObjGPS.Dispose()
|
|
End Sub
|
|
<WebMethod>
|
|
Public Function GetPosicionEquipo(params As String) As String
|
|
Dim Retorno As String = ""
|
|
Dim json As String = ""
|
|
Dim ObjGPS As New ClsGPS()
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveDispositivo] = -1,
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim jsonParams As String = Decripta(params)
|
|
Dim parametros = JsonConvert.DeserializeAnonymousType(jsonParams, Estructura)
|
|
|
|
If IsCurrentDate(parametros.Ticks) Then
|
|
|
|
Dim dispo As New MWSDispositivo2
|
|
|
|
If ObjGPS.UltimaPosicionEquipoGet(parametros.CveDispositivo, MinFecha, MaxFecha) Then
|
|
If ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
Dim Coord As MWSGeolocation2 = SQLToGmaps(ObjGPS.DtResultados.Rows(0)("Posicion").ToString, "POINT")
|
|
dispo.CveDispositivo = parametros.CveDispositivo
|
|
dispo.Geolocation = Coord
|
|
dispo.CveTrama = ObjGPS.DtResultados.Rows(0)("CveTrama").ToString.ToEntero()
|
|
dispo.FechaTrama = ObjGPS.DtResultados.Rows(0)("FechaTrama").ToString
|
|
dispo.NombreVehiculo = ObjGPS.DtResultados.Rows(0)("NombreVehiculo").ToString
|
|
dispo.Conductor = ObjGPS.DtResultados.Rows(0)("Conductor").ToString()
|
|
dispo.AñoVehiculo = ObjGPS.DtResultados.Rows(0)("AñoVehiculo").ToString
|
|
dispo.OtrosDetalles = ObjGPS.DtResultados.Rows(0)("DetallesVehiculo").ToString
|
|
dispo.Velocidad = ObjGPS.DtResultados.Rows(0)("SPD").ToString.ToDouble()
|
|
End If
|
|
End If
|
|
|
|
json = JsonConvert.SerializeObject(dispo)
|
|
Retorno = Encripta(json)
|
|
End If
|
|
Catch ex As Exception
|
|
GuardaLog(ex.ToString())
|
|
End Try
|
|
ObjGPS.Dispose()
|
|
Return Retorno
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetHistoricoPosicionesEquipo(params As String) As String
|
|
Dim Retorno As String = ""
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveDispositivo] = -1,
|
|
Key .[FechaI] = ClsPaginas.NowADS(),
|
|
Key .[FechaF] = ClsPaginas.NowADS(),
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim jsonParams As String = Decripta(params)
|
|
Dim parametros = JsonConvert.DeserializeAnonymousType(jsonParams, Estructura)
|
|
|
|
Dim FechaI As DateTime = StartOfDay(parametros.FechaI)
|
|
Dim FechaF As DateTime = EndOfDay(parametros.FechaF)
|
|
|
|
Dim coords As New List(Of MWSGeolocation2)
|
|
Dim DtRetorno As DataTable = Nothing
|
|
|
|
Using ObjGPS As New ClsGPS()
|
|
If ObjGPS.GetPosicionEquipo(parametros.CveDispositivo, FechaI, FechaF) Then
|
|
DtRetorno = ObjGPS.DtResultados.Copy()
|
|
End If
|
|
End Using
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
|
|
Dim Direcciones As JArray = ConsultarDirecciones(DtRetorno)
|
|
|
|
For Each Dir As JObject In Direcciones
|
|
DtRetorno.Rows(Dir("Indice").ToEntero())("Direccion") = Dir("Direccion").ToString()
|
|
Next
|
|
|
|
For Each Row As DataRow In DtRetorno.Rows
|
|
Dim Coord As MWSGeolocation2 = SQLToGmaps(Row("Posicion").ToString, "POINT")
|
|
Coord.Velocidad = Row("Velocidad").ToString().ToDouble().RoundSQL(0)
|
|
Coord.FechaTrama = Row("FechaTrama").ToString
|
|
Coord.Direccion = Row("Direccion").ToString
|
|
Coord.Combustible = Row("Combustible").ToString().ToDouble().RoundSQL(2)
|
|
coords.Add(Coord)
|
|
Next
|
|
End If
|
|
|
|
If coords.Count > 0 Then
|
|
Retorno = JsonConvert.SerializeObject(coords)
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrio un error al obtener las posiciones historicas de un dispositivo.", ex)
|
|
End Try
|
|
|
|
Return Retorno
|
|
End Function
|
|
|
|
<WebMethod>
|
|
Public Function GetHistoricoPosicionesEquipo2(params As String) As String
|
|
Dim Retorno As String = ""
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveDispositivo] = -1,
|
|
Key .[FechaI] = ClsPaginas.NowADS(),
|
|
Key .[FechaF] = ClsPaginas.NowADS(),
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim jsonParams As String = Decripta(params)
|
|
Dim parametros = JsonConvert.DeserializeAnonymousType(jsonParams, Estructura)
|
|
|
|
Dim FechaI As DateTime = parametros.FechaI
|
|
Dim FechaF As DateTime = parametros.FechaF
|
|
|
|
Dim coords As New List(Of MWSGeolocation2)
|
|
Dim DtRetorno As DataTable = Nothing
|
|
|
|
Using ObjGPS As New ClsGPS()
|
|
If ObjGPS.GetPosicionEquipo(parametros.CveDispositivo, FechaI, FechaF) Then
|
|
DtRetorno = ObjGPS.DtResultados.Copy()
|
|
End If
|
|
End Using
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
|
|
Dim Direcciones As JArray = ConsultarDirecciones(DtRetorno)
|
|
|
|
For Each Dir As JObject In Direcciones
|
|
DtRetorno.Rows(Dir("Indice").ToEntero())("Direccion") = Dir("Direccion").ToString()
|
|
Next
|
|
|
|
For Each Row As DataRow In DtRetorno.Rows
|
|
Dim Coord As MWSGeolocation2 = SQLToGmaps(Row("Posicion").ToString, "POINT")
|
|
Coord.Velocidad = Row("Velocidad").ToString().ToDouble().RoundSQL(0)
|
|
Coord.FechaTrama = Row("FechaTrama").ToString
|
|
Coord.Direccion = Row("Direccion").ToString
|
|
Coord.Combustible = Row("Combustible").ToString().ToDouble().RoundSQL(2)
|
|
coords.Add(Coord)
|
|
Next
|
|
End If
|
|
|
|
If coords.Count > 0 Then
|
|
Retorno = JsonConvert.SerializeObject(coords)
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrio un error al obtener las posiciones historicas de un dispositivo.", ex)
|
|
End Try
|
|
|
|
Return Retorno
|
|
End Function
|
|
|
|
Public Function ConsultarDirecciones(Dt As DataTable) As JArray
|
|
Dim retorno As JArray = Nothing
|
|
Dim posicionesArray = New JArray(From Row As DataRow In Dt
|
|
Select New JObject(
|
|
New JProperty("indice", Dt.Rows().IndexOf(Row)),
|
|
New JProperty("cveTrama", -1),
|
|
New JProperty("lat", Row("lat").ToString()),
|
|
New JProperty("lon", Row("lon").ToString())
|
|
))
|
|
|
|
Dim Base64array = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(posicionesArray.ToString()))
|
|
|
|
Using wc As New HttpClient()
|
|
Try
|
|
wc.Timeout = New TimeSpan(0, 0, 15)
|
|
Dim Url = New Uri(String.Format("{0}nominatim/reverseMultiple.php", ClsPaginas.UrlDirecciones))
|
|
Dim FormStuff = String.Format("formato=json&posiciones={0}", Base64array)
|
|
Dim content = New StringContent(FormStuff, Encoding.UTF8, "application/x-www-form-urlencoded")
|
|
Dim response = wc.PostAsync(Url, content).Result
|
|
Dim result = response.Content.ReadAsStringAsync().Result
|
|
retorno = JArray.Parse(result)
|
|
response.Dispose()
|
|
content = Nothing
|
|
Url = Nothing
|
|
FormStuff = Nothing
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al obtener las direcciones", ex)
|
|
End Try
|
|
End Using
|
|
Return retorno
|
|
End Function
|
|
|
|
Public Function EndOfDay(ByVal fecha As DateTime) As DateTime
|
|
Return New DateTime(fecha.Year, fecha.Month, fecha.Day, 23, 59, 59, 999)
|
|
End Function
|
|
|
|
Public Function StartOfDay(ByVal fecha As DateTime) As DateTime
|
|
Return New DateTime(fecha.Year, fecha.Month, fecha.Day, 0, 0, 0, 0)
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetEquipoMasCercano(params As String) As String
|
|
Dim json = "[]"
|
|
Dim Retorno As String = ""
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveCliente] = -1,
|
|
Key .[Punto] = New MWSGeolocation2(),
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim decripParams As String = Decripta(params)
|
|
Dim parametros = JsonConvert.DeserializeAnonymousType(decripParams, Estructura)
|
|
|
|
If IsCurrentDate(parametros.Ticks) Then
|
|
Dim disp As New MWSDispositivo2
|
|
Dim GPS As New ClsGPS
|
|
Dim sqlpunto = $"POINT({parametros.Punto.Longitud} {parametros.Punto.Latitud})"
|
|
If GPS.GetPuntoMasCercano(sqlpunto, parametros.CveCliente) Then
|
|
If GPS.DtResultados.Rows.Count > 0 Then
|
|
disp.Geolocation = SQLToGmaps(GPS.DtResultados.Rows(0)("Posicion").ToString, "POINT")
|
|
disp.NombreVehiculo = GPS.DtResultados.Rows(0)("Vehiculo").ToString
|
|
disp.CveDispositivo = GPS.DtResultados.Rows(0)("CveEquipoPosicion").ToString.ToEntero
|
|
disp.FechaTrama = GPS.DtResultados.Rows(0)("FechaTrama").ToString
|
|
disp.Conductor = GPS.DtResultados.Rows(0)("Conductor").ToString
|
|
End If
|
|
End If
|
|
GPS.Dispose()
|
|
json = JsonConvert.SerializeObject(disp)
|
|
Retorno = Encripta(json)
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetDispositivoMasCercano(Lat As Double, Lng As Double, CveUsuario As Integer, CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.GetPuntoMasCercanoApp($"POINT({Lng} {Lat})", CveUsuario, CveCliente)
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetGeolocationEquipo(params As String) As String
|
|
Dim json = "[]"
|
|
Dim Retorno As String = ""
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveDispositivo] = -1,
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim decripParams As String = Decripta(params)
|
|
Dim parametros = JsonConvert.DeserializeAnonymousType(decripParams, Estructura)
|
|
|
|
If IsCurrentDate(parametros.Ticks) Then
|
|
Dim ObjGPS As New ClsGPS()
|
|
Dim coords As New MWSGeolocation2
|
|
If ObjGPS.GetPosicionEquipoApp(parametros.CveDispositivo) Then
|
|
If ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
coords = SQLToGmaps(ObjGPS.DtResultados.Rows(0)("Posicion").ToString, "POINT")
|
|
coords.FechaTrama = ObjGPS.DtResultados.Rows(0)("FechaTrama").ToString
|
|
coords.Velocidad = ObjGPS.DtResultados.Rows(0)("SPD").ToString.ToDouble()
|
|
End If
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
json = JsonConvert.SerializeObject(coords)
|
|
Retorno = Encripta(json)
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
OnError("Ocurrio un error al obtener la posicion de un dispositivo.", ex)
|
|
End Try
|
|
|
|
Return Retorno
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetDispositivos(params As String) As String
|
|
Dim Retorno As String = ""
|
|
Dim json As String = "[]"
|
|
Try
|
|
Dim request = Decripta(params)
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveCliente] = -1,
|
|
Key .[CveUsuario] = -1,
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim datos = JsonConvert.DeserializeAnonymousType(request, Estructura)
|
|
If IsCurrentDate(datos.Ticks) Then
|
|
json = GetJson(GlobalDTDispositivosUsuarios(datos.CveCliente, datos.CveUsuario))
|
|
Retorno = Encripta(json, "AES")
|
|
End If
|
|
Catch ex As Exception
|
|
Retorno = ""
|
|
OnError("Ocurrio un error al obtener los dispositivos.", ex)
|
|
End Try
|
|
Return Retorno
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function EjecutarComando(EncripDatos As String) As String
|
|
Dim json As String = Decripta(EncripDatos)
|
|
Dim msg As String = ""
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveComando] = -1,
|
|
Key .[CveUsuario] = -1,
|
|
Key .[NombreComando] = "",
|
|
Key .[CveDispositivo] = -1,
|
|
Key .[Valor] = "",
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim cmd = JsonConvert.DeserializeAnonymousType(json, Estructura)
|
|
|
|
If IsCurrentDate(cmd.Ticks) Then
|
|
Dim ObjGPSHerramientas As New ClsGPSHerramientas
|
|
ObjGPSHerramientas.EjecutarComandoGPRS(cmd.CveComando, cmd.CveDispositivo, cmd.CveUsuario, cmd.Valor)
|
|
msg = $"El comando {cmd.NombreComando} se ha ejecutado correctamente"
|
|
ObjGPSHerramientas.Dispose()
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
msg = $"Ocurrio un error al ejecutar el comando"
|
|
OnError("Ocurrio un error al ejecutar un comando", ex)
|
|
End Try
|
|
Return msg
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function EjecutarComandoGPRS(EncripDatos As String) As String
|
|
Dim json As String = Decripta(EncripDatos)
|
|
Dim msg As String = ""
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveComando] = -1,
|
|
Key .[CveUsuario] = -1,
|
|
Key .[NombreComando] = "",
|
|
Key .[CveDispositivo] = -1,
|
|
Key .[Valor] = "",
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim cmd = JsonConvert.DeserializeAnonymousType(json, Estructura)
|
|
|
|
If IsCurrentDate(cmd.Ticks) Then
|
|
Dim ObjGPSHerramientas As New ClsGPSHerramientas
|
|
ObjGPSHerramientas.EjecutarComandoGPRS(cmd.CveComando, cmd.CveDispositivo, cmd.CveUsuario, cmd.Valor)
|
|
msg = $"El comando {cmd.NombreComando} se ha ejecutado correctamente"
|
|
ObjGPSHerramientas.Dispose()
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
msg = $"Ocurrio un error al ejecutar el comando"
|
|
OnError("Ocurrio un error al ejecutar un comando", ex)
|
|
End Try
|
|
Return msg
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetComandosUsuarios(EncripDatos As String) As String
|
|
Dim json As String = Decripta(EncripDatos)
|
|
Dim jsonRetorno As String = ""
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .CveUsuario = -1,
|
|
Key .CveDispositivo = -1,
|
|
Key .EsFavorito = 1,
|
|
Key .Ticks = ""
|
|
}
|
|
Dim Ent = JsonConvert.DeserializeAnonymousType(json, Estructura)
|
|
|
|
If IsCurrentDate(Ent.Ticks) Then
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.GetComandosModeloDispositivoUsuarios(Ent.CveDispositivo, Ent.CveUsuario, Ent.EsFavorito) Then
|
|
jsonRetorno = ObjGPS.DtResultados.ToJson
|
|
End If
|
|
ObjGPS.Dispose()
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
jsonRetorno = "[]"
|
|
End Try
|
|
Return Encripta(jsonRetorno)
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function Dashboard(encriptDatos As String) As MWSDashboard2
|
|
Dim dash As MWSDashboard2 = Nothing
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveCliente] = -1,
|
|
Key .[FechaI] = ClsPaginas.NowADS(),
|
|
Key .[FechaF] = ClsPaginas.NowADS(),
|
|
Key .[Ticks] = ""
|
|
}
|
|
Dim json As String = Decripta(encriptDatos)
|
|
Dim Datos = JsonConvert.DeserializeAnonymousType(json, Estructura)
|
|
|
|
If IsCurrentDate(Datos.Ticks) Then
|
|
dash = CargarEventos(Datos.CveCliente, Datos.FechaI, Datos.FechaF)
|
|
dash.KilometrajeUnidades = CargarKilometrajeUnidades(Datos.CveCliente, Datos.FechaI, Datos.FechaF)
|
|
dash.MejoresConductores = CargaMejoresConductores(Datos.CveCliente)
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrio un error al obtener los datos del dashboard.", ex)
|
|
End Try
|
|
Return dash
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GuardaDeviceToken(params As String) As Boolean
|
|
Dim Retorno = False
|
|
Dim TieneError = False
|
|
Try
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[Token] = "",
|
|
Key .[CveUsuario] = -1,
|
|
Key .[DeviceId] = "",
|
|
Key .[SO] = ""
|
|
}
|
|
Dim decripParams As String = Decripta(params)
|
|
Dim parametros = JsonConvert.DeserializeAnonymousType(decripParams, Estructura)
|
|
If parametros IsNot Nothing Then
|
|
Dim ObjGPS As New ClsGPS()
|
|
ObjGPS.IniciaTransacSQL()
|
|
Dim DtTokens As DataTable = Nothing
|
|
|
|
If ObjGPS.GetDeviceTokens(parametros.CveUsuario, parametros.DeviceId, parametros.SO) Then
|
|
DtTokens = ObjGPS.DtResultados
|
|
End If
|
|
|
|
If DtTokens IsNot Nothing AndAlso DtTokens.Rows.Count > 0 Then
|
|
TieneError = Not ObjGPS.UpdateDeviceToken(DtTokens.Rows(0)("CveToken").ToString.ToEntero, parametros.Token)
|
|
Else
|
|
If Not ObjGPS.AddDeviceToken(parametros.Token, parametros.CveUsuario, parametros.DeviceId, parametros.SO) Then
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
|
|
If Not TieneError Then
|
|
ObjGPS.Commit()
|
|
Retorno = True
|
|
Else
|
|
ObjGPS.RollBack()
|
|
End If
|
|
|
|
ObjGPS.Dispose()
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
OnError("Ocurrio un error al guardar los tokens", ex)
|
|
End Try
|
|
Return Retorno
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function UpdateNotificacionesPedientes(datos As String) As Boolean
|
|
Dim Retorno As Boolean = False
|
|
Try
|
|
Dim json = Decripta(datos)
|
|
Dim Estructura = New With
|
|
{
|
|
Key .[CveToken] = -1,
|
|
Key .[CveUsuario] = -1,
|
|
Key .[SO] = "",
|
|
Key .[DeviceId] = "",
|
|
Key .[Badge] = 0
|
|
}
|
|
Dim data = JsonConvert.DeserializeAnonymousType(json, Estructura)
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.UpdateNotificacionesPendientesDeviceToken(data.CveToken, data.CveUsuario, data.DeviceId, data.SO, data.Badge) Then
|
|
Retorno = True
|
|
End If
|
|
Catch ex As Exception
|
|
Retorno = False
|
|
OnError("Ocurrio un error al actualizar las notificaciones del movil.", ex)
|
|
End Try
|
|
|
|
Return Retorno
|
|
|
|
End Function
|
|
|
|
<WebMethod>
|
|
Public Function GetArrastre(CveDispositivo As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.GPS_ArrastreGET(CveDispositivo) Then
|
|
Retorno = ObjGPS.DtResultados.DataTableToJSONIPP()
|
|
End If
|
|
End Using
|
|
Return Retorno
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function ActivarDesactivarArrastre(CveDispositivo As Integer, Activo As Boolean) As Boolean
|
|
Dim Retorno As Boolean = False
|
|
Using ObjGPS As New ClsGPS
|
|
Retorno = ObjGPS.GPS_ArrastreActivarDesactivar(CveDispositivo, Activo)
|
|
End Using
|
|
Return Retorno
|
|
End Function
|
|
|
|
<WebMethod>
|
|
Public Function GetTrayectos(CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
|
|
|
|
Return Retorno
|
|
|
|
End Function
|
|
|
|
<WebMethod>
|
|
Public Function GetEstatusTrayectos(CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
|
|
|
|
Return Retorno
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetEstatusTrayectosHistorial(CveCliente As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
|
|
|
|
Return Retorno
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetTrayectosEstatusHistorial(CveTrayecto As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
|
|
|
|
Return Retorno
|
|
|
|
End Function
|
|
|
|
|
|
<WebMethod>
|
|
Public Function GetGeoRutas(CveCliente As Integer, CveDispositivo As Integer) As String
|
|
Dim CveGeoReferencia As Integer = -1
|
|
Dim DtRutas As DataTable = Nothing
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.GetReferenciaDetalle(-1, -1, CveDispositivo, CveCliente) Then
|
|
CveGeoReferencia = ObjGPS.DtResultados.FiltroPrimeroValor("CveGeoReferencia", "Tipo = 'Ruta'").ToEntero()
|
|
End If
|
|
If CveGeoReferencia > 0 Then
|
|
If ObjGPS.GeoReferenciaGet(CveGeoReferencia, -1, "Ruta", CveCliente) Then
|
|
DtRutas = ObjGPS.DtResultados.Copy()
|
|
End If
|
|
End If
|
|
End Using
|
|
|
|
Dim Rutas As New List(Of Object)
|
|
If CveGeoReferencia > 0 Then
|
|
|
|
For Each Row As DataRow In DtRutas.Rows
|
|
Dim Coordenadas As List(Of MWSGeolocation2) = SQLToGmapsPolyline(Row("Coordenadas").ToString())
|
|
|
|
Rutas.Add(New With {
|
|
.CveRuta = CveGeoReferencia,
|
|
.Ruta = Row("GeoReferencia").ToString(),
|
|
.Folio = "",
|
|
.Fecha = Row("FechaInicio").ToString(),
|
|
.CveDispositivo = CveDispositivo,
|
|
.CveUsuarioIngreso = -1,
|
|
.Coordenadas = Coordenadas
|
|
})
|
|
Next
|
|
|
|
End If
|
|
|
|
Return JsonConvert.SerializeObject(Rutas)
|
|
|
|
End Function
|
|
<WebMethod>
|
|
Public Function GetRutas(CveCliente As Integer, CveRuta As Integer, MostrarPuntos As Boolean) As String
|
|
Dim DtRutas As DataTable = Nothing
|
|
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.GetRutas(CveRuta, CveCliente) Then
|
|
DtRutas = ObjGPS.DtResultados.Copy()
|
|
End If
|
|
End Using
|
|
|
|
Dim Rutas As New List(Of Object)
|
|
If DtRutas IsNot Nothing Then
|
|
For Each Row As DataRow In DtRutas.Rows
|
|
Dim Coordenadas As List(Of MWSGeolocation2) = Nothing
|
|
If MostrarPuntos Then
|
|
Coordenadas = SQLToGmapsPolyline(Row("Poligono").ToString())
|
|
End If
|
|
|
|
Rutas.Add(New With {
|
|
.CveRuta = Row("CveRuta").ToString().ToEntero(),
|
|
.Ruta = Row("Ruta").ToString(),
|
|
.Folio = Row("Folio").ToString(),
|
|
.Fecha = Row("FechaIng").ToString(),
|
|
.CveDispositivo = Row("CveDispositivo").ToString().ToEntero(),
|
|
.CveUsuarioIngreso = Row("CveUsuarioIngreso").ToString().ToEntero(),
|
|
.Coordenadas = Coordenadas
|
|
})
|
|
Next
|
|
End If
|
|
|
|
Return JsonConvert.SerializeObject(Rutas)
|
|
|
|
End Function
|
|
|
|
<WebMethod>
|
|
Public Function GetRutaPuntosRecoleecion(CveRuta As Integer) As String
|
|
Dim Retorno As String = "[]"
|
|
|
|
Using ObjGPS As New ClsGPS
|
|
If ObjGPS.GetRutasPuntosRecoleecion(CveRuta) Then
|
|
Retorno = ObjGPS.DtResultados.DataTableToJSONIPP()
|
|
End If
|
|
End Using
|
|
Return Retorno
|
|
|
|
End Function
|
|
|
|
|
|
#Region "F U N C I O N E S"
|
|
Private Function CargarEventos(CveCliente As Integer, FechaI As DateTime, FechaF As DateTime) As MWSDashboard2
|
|
Dim ObjGPS As New ClsGPS
|
|
Dim dash As New MWSDashboard2
|
|
|
|
If ObjGPS.GetEventosDashboard(CveCliente, FechaI, FechaF) AndAlso ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
dash.Panicos = ObjGPS.DtResultados(0)("BotonPanico").ToString.ToDouble
|
|
dash.DesconexionBateria = ObjGPS.DtResultados(0)("DesconexionBateria").ToString.ToDouble
|
|
End If
|
|
If ObjGPS.GetRalentiDashboard(CveCliente, FechaI.Add(ClsPaginas.NowADS().TimeOfDay).ToDateTime, FechaF.Add(ClsPaginas.NowADS().TimeOfDay).ToDateTime) AndAlso ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
dash.Ralenti = ObjGPS.DtResultados(0)("Ralenti").ToString.ToDouble
|
|
End If
|
|
If ObjGPS.GetUnidadesReportando(CveCliente) AndAlso ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
Dim Reportando = ObjGPS.DtResultados(0)("Reportando").ToString.ToDouble
|
|
Dim Total = ObjGPS.DtResultados(0)("Total").ToString.ToDouble
|
|
Dim Porcentaje = Math.Round(Reportando / Total, 2).ToString.ToDouble
|
|
|
|
dash.UnidadesReportando = Reportando
|
|
dash.TotalUnidades = Total
|
|
dash.PorcentajeUnidades = Porcentaje
|
|
End If
|
|
|
|
ObjGPS.Dispose()
|
|
Return dash
|
|
End Function
|
|
Private Function CargarKilometrajeUnidades(CveCliente As Integer, FechaI As DateTime, FechaF As DateTime, Optional Top As Integer = 5) As List(Of MCategoria2)
|
|
Dim ObjGPS As New ClsGPS
|
|
Dim lista As New List(Of MCategoria2)
|
|
|
|
If ObjGPS.GetKilometrajeDispositivos(CveCliente, FechaI, FechaF, Top) AndAlso ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
For Each row As DataRow In ObjGPS.DtResultados.Rows
|
|
Dim data As New MCategoria2
|
|
data.Nombre = row("NoEconomico").ToString
|
|
data.Valor = row("Dist").ToString.ToDouble
|
|
lista.Add(data)
|
|
Next
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
Return lista
|
|
End Function
|
|
Private Function CargaMejoresConductores(CveCliente As Integer, Optional Top As Integer = 5) As List(Of MCategoria2)
|
|
Dim ObjGPS As New ClsGPS
|
|
Dim lista As New List(Of MCategoria2)
|
|
Dim Valor As Integer = 1
|
|
|
|
If ObjGPS.GetMejoresConductores(CveCliente, Top) AndAlso ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
For Each row As DataRow In ObjGPS.DtResultados.Rows
|
|
Dim data As New MCategoria2
|
|
data.Nombre = row("Conductor").ToString
|
|
data.Valor = row("Total").ToString.ToDouble
|
|
lista.Add(data)
|
|
Next
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
Return lista
|
|
End Function
|
|
Private Function SQLToGmaps(CoordsSQL As String, Tipo As String) As MWSGeolocation2
|
|
Dim CoordsPoligono As String = CoordsSQL.Replace($"{Tipo}", "").Replace(")", "").Replace("(", "")
|
|
Dim CoordsPuntos() As String = CoordsPoligono.Split(","c)
|
|
Dim Var As New MWSGeolocation2
|
|
For Each coordenada As String In CoordsPuntos
|
|
If coordenada Is CoordsPuntos.Last Then
|
|
Dim latlng() As String = coordenada.Trim.Split(" "c)
|
|
Var.Latitud = latlng(1).ToDouble()
|
|
Var.Longitud = latlng(0).ToDouble()
|
|
Else
|
|
Dim latlng() As String = coordenada.Trim.Split(" "c)
|
|
Var.Latitud = latlng(1).ToDouble()
|
|
Var.Longitud = latlng(0).ToDouble()
|
|
End If
|
|
Next
|
|
Return Var
|
|
End Function
|
|
Private Function SQLToGmapsPolyline(CoordsSQL As String) As List(Of MWSGeolocation2)
|
|
Dim CoordsPoligono As String = CoordsSQL.Replace($"LINESTRING", "").Replace(")", "").Replace("(", "")
|
|
Dim CoordsPuntos() As String = CoordsPoligono.Split(","c)
|
|
|
|
Dim puntos As New List(Of MWSGeolocation2)
|
|
For Each coordenada As String In CoordsPuntos
|
|
Dim Var As New MWSGeolocation2
|
|
If coordenada Is CoordsPuntos.Last Then
|
|
Dim latlng() As String = coordenada.Trim.Split(" "c)
|
|
Var.Latitud = latlng(1).ToDouble()
|
|
Var.Longitud = latlng(0).ToDouble()
|
|
Else
|
|
Dim latlng() As String = coordenada.Trim.Split(" "c)
|
|
Var.Latitud = latlng(1).ToDouble()
|
|
Var.Longitud = latlng(0).ToDouble()
|
|
End If
|
|
|
|
puntos.Add(Var)
|
|
Next
|
|
|
|
Return puntos
|
|
End Function
|
|
Private Function GetJson(ByVal dt As DataTable) As String
|
|
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
|
|
Dim rows As New List(Of Dictionary(Of String, Object))()
|
|
Dim row As Dictionary(Of String, Object) = Nothing
|
|
For Each dr As DataRow In dt.Rows
|
|
row = New Dictionary(Of String, Object)()
|
|
For Each dc As DataColumn In dt.Columns
|
|
row.Add(dc.ColumnName.Trim(), dr(dc))
|
|
Next
|
|
rows.Add(row)
|
|
Next
|
|
Return serializer.Serialize(rows)
|
|
End Function
|
|
Private Function IsCurrentDate(StrFecha As String) As Boolean
|
|
Return True '(ReturnTimeOnServer(StrFecha) > (ClsPaginas.NowADS()).AddMinutes(-15) And ReturnTimeOnServer(StrFecha) < (ClsPaginas.NowADS()).AddMinutes(15))
|
|
End Function
|
|
Public Function ReturnTimeOnServer(clientString As String) As DateTime
|
|
Dim format As String = "dd/MM/yyyy H:m:s zzz"
|
|
Try
|
|
Dim clientTime As DateTimeOffset = DateTimeOffset.ParseExact(clientString, format, CultureInfo.InvariantCulture)
|
|
Dim serverTime As DateTimeOffset = TimeZoneInfo.ConvertTime(clientTime, TimeZoneInfo.Local)
|
|
Return serverTime.DateTime
|
|
Catch e As FormatException
|
|
Return DateTimeOffset.MinValue.DateTime
|
|
End Try
|
|
End Function
|
|
Private Function ValidaCredenciales() As Boolean
|
|
If Credentials.Username = ".&_siggps_app_service&." And Credentials.Password = "$app$gps$service$" Then
|
|
Return True
|
|
Else
|
|
OnError("Acceso no autorizado", New SoapException("Unauthorized", SoapException.ClientFaultCode))
|
|
Return False
|
|
End If
|
|
End Function
|
|
#End Region
|
|
End Class
|
|
Namespace ADGPSModels
|
|
Public Class WSUSER2
|
|
Public Property CveUsuario As Integer
|
|
Public Property CveCliente As Integer
|
|
Public Property Usuario As String
|
|
Public Property CveEmpresa As Integer
|
|
Public Property Procesos As List(Of String)
|
|
Public Property Empresas As List(Of WsEmpresa)
|
|
Public Property Modulos As List(Of WsModulos)
|
|
Public Property Clientes As List(Of WsClientePortalGPS)
|
|
Public Property Nombre As String
|
|
Public Property CveRol As Integer
|
|
Public Property Rol As String
|
|
Public Property CveSubProyecto As Integer
|
|
Public Property Contrasenia As String
|
|
|
|
Public Property TienePermisoOC As Boolean
|
|
Public Property TienePermisoPS As Boolean
|
|
Public Property RastreoSoloInicio As Boolean = False
|
|
|
|
End Class
|
|
<Serializable>
|
|
Public Class WsClientePortalGPS
|
|
Public Property CveCliente As Integer
|
|
Public Property Cliente As String
|
|
End Class
|
|
<Serializable>
|
|
Public Class MWSDispositivo2
|
|
Public Property CveDispositivo As Integer
|
|
Public Property CveTrama As Integer
|
|
Public Property FechaTrama As String
|
|
Public Property Geolocation As MWSGeolocation2
|
|
Public Property NombreVehiculo As String
|
|
Public Property Conductor As String
|
|
Public Property Velocidad As Double
|
|
Public Property AñoVehiculo As String
|
|
Public Property OtrosDetalles As String
|
|
|
|
End Class
|
|
<Serializable>
|
|
Public Class MWSGeolocation2
|
|
Public Property Latitud As Double
|
|
Public Property Longitud As Double
|
|
Public Property FechaTrama As String
|
|
Public Property Velocidad As Double
|
|
Public Property Combustible As Double
|
|
Public Property Direccion As String
|
|
End Class
|
|
<Serializable>
|
|
Public Class MPosicion2
|
|
Public Property Posicion As String
|
|
Public Property FechaIng As DateTime
|
|
Public Property CveTrama As Integer
|
|
End Class
|
|
|
|
<Serializable>
|
|
Public Class MWSLogin2
|
|
Public Property Usuario As String
|
|
Public Property Contraseña As String
|
|
Public Property Ticks As String
|
|
End Class
|
|
<Serializable>
|
|
Public Class MWSDashboard2
|
|
Public Property KilometrajeUnidades As List(Of MCategoria2)
|
|
Public Property MejoresConductores As List(Of MCategoria2)
|
|
Public Property Panicos As Double
|
|
Public Property Ralenti As Double
|
|
Public Property UnidadesReportando As Double
|
|
Public Property TotalUnidades As Double
|
|
Public Property DesconexionBateria As Double
|
|
Public Property TiemposMuertos As Double
|
|
Public Property PorcentajeUnidades As Double
|
|
|
|
End Class
|
|
<Serializable>
|
|
Public Class MCategoria2
|
|
Public Property Nombre As String
|
|
Public Property Valor As Double
|
|
End Class
|
|
Public Class WsModulos
|
|
Public Property CveModulo As Integer
|
|
Public Property CvePadre As Integer
|
|
Public Property CvePlataforma As Integer
|
|
Public Property Modulo As String
|
|
Public Property Liga As String
|
|
Public Property Estilo As String
|
|
Public Property Parametros As String
|
|
End Class
|
|
Public Class WsEmpresa
|
|
Public Property CveEmpresa As Integer
|
|
Public Property Empresa As String
|
|
End Class
|
|
End Namespace
|