Commit inicial Ventas Productivo
This commit is contained in:
218
Ashx/SIGGPS.ashx
Normal file
218
Ashx/SIGGPS.ashx
Normal file
@@ -0,0 +1,218 @@
|
||||
<%@ WebHandler Language="VB" Class="SIGGPS" %>
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports System
|
||||
Imports System.Web
|
||||
Imports System.Data
|
||||
Imports Newtonsoft.Json.Linq
|
||||
Imports Extensiones
|
||||
Imports System.IO
|
||||
|
||||
Public Class SIGGPS : Implements IHttpHandler, IRequiresSessionState
|
||||
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
||||
context.Response.ContentType = "text/plain"
|
||||
Try
|
||||
If context.Request("metodo") IsNot Nothing Then
|
||||
Select Case context.Request("metodo")
|
||||
Case "getimginstalacion"
|
||||
GetImgInstalacion(context)
|
||||
End Select
|
||||
ElseIf context.Request.InputStream IsNot Nothing Then
|
||||
Using reader As New StreamReader(context.Request.InputStream)
|
||||
Dim json = reader.ReadToEnd
|
||||
Dim JsonRequest As JObject = JObject.Parse(json)
|
||||
If JsonRequest IsNot Nothing Then
|
||||
Select Case JsonRequest("Metodo").ToString
|
||||
Case "UpdateNotificacion"
|
||||
UpdateNotificacion(context, JsonRequest)
|
||||
Case "RastreoContinuoAF"
|
||||
RastreoContinuoAF(context, JsonRequest)
|
||||
End Select
|
||||
End If
|
||||
End Using
|
||||
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
ex.GuardaLog(ex.Message)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
||||
Get
|
||||
Return False
|
||||
End Get
|
||||
End Property
|
||||
|
||||
ReadOnly Property UsuarioActual(ByVal context As HttpContext) As Usuario
|
||||
Get
|
||||
UsuarioActual = DirectCast(context.Session("UsuarioSIG"), Usuario)
|
||||
End Get
|
||||
End Property
|
||||
Private Function Parametros(Cadena As String) As Hashtable
|
||||
Dim P1() As String = Cadena.Split("&"c)
|
||||
Dim Tmp As String
|
||||
Dim P2() As String
|
||||
|
||||
Dim URLParametros As New Hashtable
|
||||
|
||||
For Each Tmp In P1
|
||||
P2 = Tmp.Replace("%26%", "&").Split("="c)
|
||||
URLParametros.Add(P2(0).ToString.ToUpper, P2(1))
|
||||
Next
|
||||
Return URLParametros
|
||||
End Function
|
||||
|
||||
Private Sub GetImgInstalacion(ByVal context As HttpContext)
|
||||
Dim params As String = Decripta(context.Request("r").ToString)
|
||||
Dim Parametros = Me.Parametros(params)
|
||||
Dim Archivo As String = Parametros("ARCHIVO").ToString()
|
||||
Dim CveDispositivo As Integer = Parametros("CVEDISPOSITIVO").ToString().ToEntero()
|
||||
Dim Extension As String = Path.GetExtension(Archivo).Replace(".", "")
|
||||
Dim Usuario As Usuario = UsuarioActual(context)
|
||||
|
||||
If Not IsNothing(Usuario) Then
|
||||
Dim Url = String.Format("{0}\Empresas\{1}\Dispositivos\{2}\Imagenes\{3}", AppDomain.CurrentDomain.BaseDirectory, Usuario.CveEmpresa, CveDispositivo, Archivo)
|
||||
|
||||
If File.Exists(Url) Then
|
||||
context.Response.ContentType = String.Format("image/{0}", Extension)
|
||||
context.Response.Flush()
|
||||
context.Response.WriteFile(Url)
|
||||
context.Response.End()
|
||||
End If
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub UpdateNotificacion(ByVal context As HttpContext, ByVal Json As JObject)
|
||||
|
||||
Dim CveBitacora As Integer = Json("Params")("CveBitacora").ToEntero
|
||||
Dim CveUsuario As Integer = Json("Params")("Cve").ToEntero
|
||||
|
||||
Dim Notificaciones As New StringBuilder
|
||||
Dim countNotificaciones = 0
|
||||
|
||||
If CveUsuario > 0 Then
|
||||
|
||||
Using ObjNoti As New ClsSisNotificaciones
|
||||
If CveBitacora > 0 Then
|
||||
ObjNoti.UpdateNotificacionesCampanaNotifico(CveBitacora, 1)
|
||||
End If
|
||||
ObjNoti.GetNotificacionesCampanaPendientes(CveUsuario)
|
||||
|
||||
For Each row As DataRow In ObjNoti.DtResultados.Rows
|
||||
countNotificaciones += row("NumNotificaciones").ToString.ToEntero
|
||||
Dim TipoMensaje = If(row("TipoMensaje").ToString = "EMG", $"Hay {row("NumNotificaciones")} notificaciones de Emergencia", $"Hay {row("NumNotificaciones")} notificaciones de Alerta")
|
||||
Dim Icono = If(row("TipoMensaje").ToString = "EMG", "fa fa-exclamation-triangle", "fa fa-bullhorn")
|
||||
Dim Tipo = If(row("TipoMensaje").ToString = "EMG", "danger", "warning")
|
||||
Notificaciones.Append(ItemNotificaciones(TipoMensaje, "Hoy", Icono, Tipo, $"/GPS/Notificaciones.aspx?Tipo={row("TipoMensaje")}"))
|
||||
Next
|
||||
End Using
|
||||
|
||||
End If
|
||||
|
||||
Dim Retorno As New JObject(
|
||||
New JProperty("Titulo", $"({countNotificaciones}) SIG GPS"),
|
||||
New JProperty("NumNotificaciones", countNotificaciones),
|
||||
New JProperty("CssClass", If(countNotificaciones > 0, "badge-danger", "badge-default")),
|
||||
New JProperty("Html", Notificaciones.ToString())
|
||||
)
|
||||
|
||||
context.Response.Write(Retorno.ToString())
|
||||
End Sub
|
||||
|
||||
Private Sub RastreoContinuoAF(ByVal context As HttpContext, ByVal Json As JObject)
|
||||
Dim CveDispositivo As Integer = Json("Params")("CveDispositivo").ToEntero
|
||||
Dim CveCliente As Integer = Json("Params")("CveCliente").ToEntero
|
||||
Dim FechaCliente As DateTime = Json("Params")("FechaCliente").ToDateTime
|
||||
Dim PoscionesAnteriores As JArray = JArray.Parse(Json("Params")("Posiciones").ToString())
|
||||
|
||||
Dim CoordActual As JObject = Nothing
|
||||
Dim SBJS As New StringBuilder
|
||||
|
||||
Dim ObjGPS As New ClsGPS
|
||||
Try
|
||||
Dim Fecha = "", Vehiculo = "", Icono = "", Info As String = ""
|
||||
If ObjGPS.UltimaPosicionEquipoGet(String.Format("{0};", CveDispositivo), CveCliente) Then
|
||||
If ObjGPS.DtResultados.Rows.Count > 0 Then
|
||||
For Each Row As DataRow In ObjGPS.DtResultados.Rows
|
||||
CoordActual = JObject.Parse(SQLToGmapsJArray(Row("Posicion").ToString, "POINT")(0).ToString())
|
||||
Fecha = Row("FechaTrama").ToString
|
||||
Vehiculo = Row("Vehiculo").ToString
|
||||
Info = InfoWindowCombustible(String.Format(" Vehículo: {0}", Vehiculo), "", CveDispositivo, Row, False)
|
||||
|
||||
Dim Diferencia As Long = DateDiff(DateInterval.Minute, Fecha.ToDateTime(), FechaCliente)
|
||||
|
||||
If Diferencia >= 30 AndAlso Diferencia < 120 Then
|
||||
Icono = "/Imagenes/rsz_11rsz_car_disconnected.png"
|
||||
ElseIf Diferencia >= 120 Then
|
||||
Icono = "/Imagenes/rsz_11rsz_car_disable.png"
|
||||
Else
|
||||
If Row("SPD").ToString.ToDouble > 1 Then
|
||||
Icono = String.Format("/Imagenes/{0}green.png", Row("Icono").ToString)
|
||||
Else
|
||||
Icono = String.Format("/Imagenes/{0}.png", Row("Icono").ToString)
|
||||
End If
|
||||
End If
|
||||
PoscionesAnteriores.Add(CoordActual)
|
||||
SBJS.AppendFormat("creaPolylineRastreo({0},'#4B77BE','{1}',{2},'{3}','{4}',{5}, 1); DeleteMarkersRastreo();", PoscionesAnteriores.ToString(), Info, CoordActual.ToString(), Vehiculo, Icono, CveDispositivo)
|
||||
Next
|
||||
End If
|
||||
End If
|
||||
Catch ex As Exception
|
||||
GuardaLog(ex.ToString())
|
||||
Finally
|
||||
ObjGPS.Dispose()
|
||||
End Try
|
||||
Dim Retorno As New JObject(
|
||||
New JProperty("CoordActual", CoordActual),
|
||||
New JProperty("JS", SBJS.ToString())
|
||||
)
|
||||
|
||||
context.Response.Write(Retorno.ToString())
|
||||
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><b>{Header}</b></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
|
||||
'If PermisoComandos Then
|
||||
'SBuilder.Append($"<tr><td><a href=""javascript:;"" onclick=""CargaComandos(\'{row("Vehiculo").ToString}\',{CveDispositivo});"">Comandos</a></td></tr>")
|
||||
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)
|
||||
'End If
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
SBuilder.Append($"</table></div><div></div></div>")
|
||||
Return SBuilder.ToString
|
||||
End Function
|
||||
Private Function SQLToGmapsJArray(CoordsSQL As String, Tipo As String) As JArray
|
||||
Dim CoordsPoligono As String = CoordsSQL.Replace($"{Tipo}", "").Replace(")", "").Replace("(", "")
|
||||
Dim CoordsPuntos() As String = CoordsPoligono.Split(","c)
|
||||
|
||||
Dim Json As New JArray(From coord In CoordsPuntos
|
||||
Let c = coord.Trim.Split(" "c)
|
||||
Select New JObject(
|
||||
New JProperty("lat", c(1).ToDouble),
|
||||
New JProperty("lng", c(0).ToDouble)
|
||||
)
|
||||
)
|
||||
|
||||
Return Json
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user