456 lines
20 KiB
VB.net
456 lines
20 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
|
|
Imports System.Net.Http
|
|
|
|
Partial Class GPS_Trayectos
|
|
Inherits ClsPaginas
|
|
|
|
#Region "P R O P I E D A D E S"
|
|
Private Property DtGeocercasAgregar As DataTable
|
|
Get
|
|
Return CType(ViewState("DtGeocercasAgregar"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtGeocercasAgregar") = value
|
|
End Set
|
|
End Property
|
|
Private Property DtGeocercas As DataTable
|
|
Get
|
|
Return CType(ViewState("DtGeocercas"), DataTable)
|
|
End Get
|
|
Set(value As DataTable)
|
|
ViewState("DtGeocercas") = 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
|
|
#End Region
|
|
|
|
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
If Not Page.IsPostBack Then
|
|
DirectCast(Master.FindControl("TSM"), ScriptManager).EnablePageMethods = True
|
|
CargaDatos()
|
|
TimmerRefresh.Enabled = ChkTimmer.Checked
|
|
End If
|
|
End Sub
|
|
Private Sub CargaDatos()
|
|
CargaDispositivos()
|
|
CargaGeoReferencias()
|
|
CargaEstatus()
|
|
CargaDdlTrayectos()
|
|
|
|
CargaTrayectos()
|
|
End Sub
|
|
Public Sub CargaDispositivos()
|
|
DdlDispositivo.DataSource = GlobalDTDispositivosUsuarios(UsuarioActual.CveCliente, UsuarioActual.CveUsuario)
|
|
DdlDispositivo.DataBind()
|
|
DdlDispositivo.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
|
|
DdlDispositivoNuevo.DataSource = GlobalDTDispositivosUsuarios(UsuarioActual.CveCliente, UsuarioActual.CveUsuario)
|
|
DdlDispositivoNuevo.DataBind()
|
|
DdlDispositivoNuevo.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
|
|
|
|
DdlDispositivoFiltro.DataSource = GlobalDTDispositivosUsuarios(UsuarioActual.CveCliente, UsuarioActual.CveUsuario)
|
|
DdlDispositivoFiltro.DataBind()
|
|
DdlDispositivoFiltro.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
|
|
UpAgregar.Update()
|
|
End Sub
|
|
Public Sub CargaGeoReferencias()
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.GeoReferenciaGet(-1, 1, "-1", UsuarioActual.CveCliente) Then
|
|
DtGeocercasAgregar = ObjGPS.DtResultados.Copy()
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
DdlGeocerca.DataSource = DtGeocercasAgregar
|
|
DdlGeocerca.DataBind()
|
|
DdlGeocerca.Items.Insert(0, New ListItem("Seleccione", "-1"))
|
|
|
|
End Sub
|
|
Public Sub CargaTrayectos()
|
|
Dim FechaI As String = If(IsDate(txtFechaI.Text), txtFechaI.Text, "-1")
|
|
Dim FechaF As String = If(IsDate(txtFechaF.Text), txtFechaF.Text, "-1")
|
|
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.GetTrayectos(-1, DdlDispositivoFiltro.SelectedValue.ToEntero(), UsuarioActual.CveCliente, DdlEstatusTrayecto.SelectedValue.ToEntero(), FechaI, FechaF) Then
|
|
If ChkActivas.Checked Then
|
|
GvBarra.DataSource = ObjGPS.DtResultados.FiltraParametros($"EsFin = False")
|
|
Else
|
|
GvBarra.DataSource = ObjGPS.DtResultados
|
|
End If
|
|
End If
|
|
ObjGPS.Dispose()
|
|
GvBarra.DataBind()
|
|
UPGV.Update()
|
|
End Sub
|
|
Public Sub CargaDdlTrayectos()
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.GetTrayectos(-1, -1, UsuarioActual.CveCliente) Then
|
|
DdlTrayecto.DataSource = ObjGPS.DtResultados.FiltraParametros("EsFin = True")
|
|
End If
|
|
ObjGPS.Dispose()
|
|
DdlTrayecto.DataBind()
|
|
|
|
UpAgregar.Update()
|
|
End Sub
|
|
Public Sub CargaEstatus()
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.GetEstatusTrayectos(-1, UsuarioActual.CveCliente) Then
|
|
GvEstatus.DataSource = ObjGPS.DtResultados.FiltraParametros("CveCliente > 0")
|
|
GvEstatusNuevo.DataSource = ObjGPS.DtResultados
|
|
DdlEstatusTrayecto.DataSource = ObjGPS.DtResultados
|
|
End If
|
|
ObjGPS.Dispose()
|
|
GvEstatus.DataBind()
|
|
GvEstatusNuevo.DataBind()
|
|
|
|
DdlEstatusTrayecto.DataBind()
|
|
DdlEstatusTrayecto.Items.Insert(0, New ListItem("Todos", "-1"))
|
|
|
|
End Sub
|
|
Protected Sub GvEstatus_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.FCDropDownList("DdlGeocerca").DataSource = DtGeocercasAgregar
|
|
e.Row.FCDropDownList("DdlGeocerca").DataBind()
|
|
|
|
Dim EsInicio As Boolean = CBool(If(String.IsNullOrEmpty(e.Row.DBCampo("EsInicio")), "False", e.Row.DBCampo("EsInicio")))
|
|
Dim EsFin As Boolean = CBool(If(String.IsNullOrEmpty(e.Row.DBCampo("EsFin")), "False", e.Row.DBCampo("EsFin")))
|
|
|
|
If EsInicio OrElse EsFin Then
|
|
e.Row.FCCheckBox("chkDis").Checked = True
|
|
e.Row.FCCheckBox("chkDis").Enabled = False
|
|
Else
|
|
e.Row.FCCheckBox("chkDis").CssClass = "ChkAllEvt"
|
|
End If
|
|
|
|
e.Row.FCLinkButton("imgE").OnClientClick = $"CargaModalGeo({e.Row.RowIndex}); return false;"
|
|
End If
|
|
End Sub
|
|
Protected Sub GvEstatusNuevo_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.FCDropDownList("DdlGeocerca").DataSource = DtGeocercasAgregar
|
|
e.Row.FCDropDownList("DdlGeocerca").DataBind()
|
|
|
|
Dim EsInicio As Boolean = CBool(If(String.IsNullOrEmpty(e.Row.DBCampo("EsInicio")), "False", e.Row.DBCampo("EsInicio")))
|
|
Dim EsFin As Boolean = CBool(If(String.IsNullOrEmpty(e.Row.DBCampo("EsFin")), "False", e.Row.DBCampo("EsFin")))
|
|
|
|
If EsInicio OrElse EsFin Then
|
|
e.Row.FCCheckBox("chkDis").Checked = True
|
|
e.Row.FCCheckBox("chkDis").Enabled = False
|
|
Else
|
|
e.Row.FCCheckBox("chkDis").CssClass = "ChkAllEvt"
|
|
End If
|
|
|
|
If DtGeocercas IsNot Nothing Then
|
|
Dim CveEstatus = e.Row.DataKey("CveEstatusTrayecto")
|
|
Dim CveGeoReferencia = DtGeocercas.FiltroPrimeroValor("CveGeoReferencia", $"CveEstatusTrayecto={CveEstatus}")
|
|
If Not String.IsNullOrEmpty(CveGeoReferencia) Then
|
|
e.Row.FCDropDownList("DdlGeocerca").SelectedValue = CveGeoReferencia
|
|
e.Row.FCCheckBox("chkDis").Checked = True
|
|
End If
|
|
End If
|
|
|
|
End If
|
|
End Sub
|
|
Protected Sub BtnAgregar_Click(sender As Object, e As EventArgs)
|
|
If GvEstatus.Rows.Count > 0 Then
|
|
Dim Nombre As String = TxtNombre.Text
|
|
Dim CveDispositivo As Integer = DdlDispositivo.SelectedValue.ToEntero
|
|
Dim Rows = GvBarra.Rows.Cast(Of GridViewRow).Where(Function(x) x.RowType = DataControlRowType.DataRow)
|
|
|
|
Dim TieneFilas As Boolean = True ' Rows.Any(Function(z) z.FCCheckBox("chkDis").Checked)
|
|
'Dim Filas = From Dr In GvBarra.Rows
|
|
' Where Dr.Row
|
|
' Select Row
|
|
|
|
If TieneFilas Then
|
|
Dim TieneError As Boolean = False
|
|
Dim ObjGPS As New ClsGPS
|
|
ObjGPS.IniciaTransacSQL()
|
|
|
|
Try
|
|
Dim CveTrayecto As Integer = ObjGPS.AddTrayecto(Nombre, DateTime.Now, "", CveDispositivo, UsuarioActual.CveCliente, EnviarNotificacion:=ChkNotificacion.Checked,
|
|
CorreosNotificacion:=TxtCorreoNot.Text, Intervalo:=If(ChkNotificacion.Checked, DdlIntervalo.SelectedValue.ToEntero(), 0),
|
|
EnviarLiga:=ChkEnviarLiga.Checked)
|
|
|
|
If CveTrayecto > 0 Then
|
|
For Each Row As GridViewRow In GvEstatus.Rows
|
|
If Row.RowType = DataControlRowType.DataRow Then
|
|
If Row.FCCheckBox("chkDis").Checked Then
|
|
Dim CveGeoReferencia As Integer = Row.FCDropDownList("DdlGeocerca").SelectedValue.ToEntero
|
|
Dim CveEstatusTrayecto As Integer = Row.DataKey("CveEstatusTrayecto").ToEntero
|
|
If Not ObjGPS.AddTrayectoGeoReferencia(CveTrayecto, CveGeoReferencia, CveEstatusTrayecto) Then
|
|
TieneError = True
|
|
Exit For
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al agregar el trayecto.", ex)
|
|
End Try
|
|
If TieneError Then
|
|
ObjGPS.RollBack()
|
|
Alert("Ocurrió un error al agregar el trayecto.", TipoMensaje.MsgError)
|
|
Else
|
|
ObjGPS.Commit()
|
|
Alert("El trayecto se agrego correctamente.")
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
RegistraScript("$('#DivAgregar').modal('hide');")
|
|
Else
|
|
Alert("No ha seleccionado ningun estatus para este trayecto.", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
|
|
Else
|
|
Alert("No hay estatus seleccionables para este trayecto.", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
CargaDatos()
|
|
End Sub
|
|
Protected Sub LnkCrear_Click(sender As Object, e As EventArgs)
|
|
Dim CveTrayecto As Integer = DdlTrayecto.SelectedValue.ToEntero
|
|
If CveTrayecto > 0 Then
|
|
Dim ObjGPS As New ClsGPS
|
|
Dim TieneError As Boolean = False
|
|
ObjGPS.IniciaTransacSQL()
|
|
Try
|
|
Dim Nombre As String = TxtNombreNuevo.Text
|
|
Dim CveDispositivo As Integer = DdlDispositivoNuevo.SelectedValue.ToEntero
|
|
If CveDispositivo > 0 Then
|
|
Dim CveTrayectoNuevo As Integer = ObjGPS.AddTrayecto(Nombre, DateTime.Now, "", CveDispositivo, UsuarioActual.CveCliente)
|
|
If CveTrayectoNuevo > 0 Then
|
|
For Each Row As GridViewRow In GvEstatusNuevo.Rows
|
|
If Row.RowType = DataControlRowType.DataRow Then
|
|
If Row.FCCheckBox("chkDis").Checked Then
|
|
Dim CveGeoReferencia As Integer = Row.FCDropDownList("DdlGeocerca").SelectedValue.ToEntero
|
|
Dim CveEstatusTrayecto As Integer = Row.DataKey("CveEstatusTrayecto").ToEntero
|
|
If Not ObjGPS.AddTrayectoGeoReferencia(CveTrayectoNuevo, CveGeoReferencia, CveEstatusTrayecto) Then
|
|
TieneError = True
|
|
Exit For
|
|
End If
|
|
End If
|
|
End If
|
|
Next
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al agregar el trayecto.", ex)
|
|
End Try
|
|
|
|
If TieneError Then
|
|
ObjGPS.RollBack()
|
|
Alert("Ocurrió un error al agregar el trayecto.", TipoMensaje.MsgError)
|
|
Else
|
|
ObjGPS.Commit()
|
|
Alert("El trayecto se agrego correctamente.")
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
RegistraScript("$('#DivCrearApatir').modal('hide');")
|
|
Else
|
|
Alert("Debe seleccionar un trayecto.", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
CargaTrayectos()
|
|
End Sub
|
|
Private Sub LimpiaCampos()
|
|
TxtNombre.Text = ""
|
|
DdlDispositivo.SelectedIndex = 0
|
|
End Sub
|
|
|
|
#Region "C O N S U L T A "
|
|
Protected Sub LnkConsultar_Click(sender As Object, e As EventArgs)
|
|
CargaTrayectos()
|
|
End Sub
|
|
#End Region
|
|
Protected Sub GvBarra_RowDataBound(sender As Object, e As GridViewRowEventArgs)
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.ID = String.Format("row{0}", e.Row.RowIndex)
|
|
e.Row.Attributes.Add("idgv", e.Row.RowIndex.ToString)
|
|
If e.Row.DBCampo("EsFin") = "True" Then
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-primary"
|
|
ElseIf e.Row.DBCampo("EsInicio") = "True" Then
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-success"
|
|
ElseIf e.Row.DBCampo("EsInicio") = "False" AndAlso e.Row.DBCampo("EsFin") = "False" Then
|
|
e.Row.FCLabel("LblEstatus").CssClass = "badge badge-secondary"
|
|
End If
|
|
If CBool(e.Row.DBCampo("EnviarNotificacion")) Then
|
|
e.Row.FCLinkButton("LnkEnviar").Visible = True
|
|
End If
|
|
End If
|
|
End Sub
|
|
Protected Sub DdlTrayecto_SelectedIndexChanged(sender As Object, e As EventArgs)
|
|
Dim CveTrayecto As Integer = DdlTrayecto.SelectedValue.ToEntero
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.GetTrayectosGeoReferencias(CveTrayecto) Then
|
|
DtGeocercas = ObjGPS.DtResultados
|
|
End If
|
|
If ObjGPS.GetTrayectos(CveTrayecto, -1, UsuarioActual.CveCliente) Then
|
|
If ObjGPS.DtResultados.Rows.Count > 0 Then
|
|
DdlDispositivoNuevo.SelectedValueExist(ObjGPS.DtResultados.Rows(0)("CveDispositivo"))
|
|
End If
|
|
End If
|
|
ObjGPS.Dispose()
|
|
CargaEstatus()
|
|
End Sub
|
|
Protected Sub BtnAgregarGeoreferencia_Click(sender As Object, e As EventArgs)
|
|
If String.IsNullOrEmpty(TxtNombreGeo.Text.Trim) Then
|
|
Alert("El campo 'Nombre' es necesario favor de introducirlo.", TipoMensaje.MsgAdvertencia)
|
|
RegistraScript("setTimeout(function(){ initMapGeo(); DeletemarkersGeo();},1000);")
|
|
Return
|
|
End If
|
|
If String.IsNullOrEmpty(GeoCerca.Value.Trim) Then
|
|
Alert("La GeoReferencia no tiene una geocerca dibujada.", TipoMensaje.MsgAdvertencia)
|
|
RegistraScript("setTimeout(function(){ initMapGeo(); DeletemarkersGeo();},1000);")
|
|
Return
|
|
End If
|
|
Dim Importe As Decimal = 0
|
|
|
|
Dim GeoRefString = $"POLYGON(({GeoCerca.Value} {CommandArg.Value}))"
|
|
|
|
Dim TieneError As Boolean = False
|
|
Dim ObjGPS As New ClsGPS
|
|
ObjGPS.IniciaTransacSQL()
|
|
Dim CveGeoReferencia As Integer = -1
|
|
If ObjGPS.AddGeoReferencia(TxtNombreGeo.Text, -1, GeoRefString, "Geocerca", True, "-1", "-1", -1, -1, -1, -1, -1, -1, -1, "-1", "-1", hdnColor.Value, -1, Importe, UsuarioActual.CveCliente, EsParada:=False) Then
|
|
CveGeoReferencia = ObjGPS.CveGeoReferencia
|
|
Else
|
|
TieneError = True
|
|
End If
|
|
|
|
If TieneError Then
|
|
ObjGPS.RollBack()
|
|
Alert("Ocurrió un error al crear la GeoReferencia", TipoMensaje.MsgInformacion)
|
|
Else
|
|
ObjGPS.Commit()
|
|
Alert("La GeoReferencia se agregó correctamente", TipoMensaje.MsgInformacion)
|
|
End If
|
|
ObjGPS.Dispose()
|
|
|
|
UpGeocercas.Update()
|
|
CargaGeoReferencias()
|
|
|
|
Dim index As Integer = HdnIndexEstatus.Value.ToEntero()
|
|
If index > -1 AndAlso CveGeoReferencia > 0 Then
|
|
For Each GvRow As GridViewRow In GvEstatus.Rows
|
|
If GvRow.RowType = DataControlRowType.DataRow Then
|
|
GvRow.FCDropDownList("DdlGeocerca").DataSource = DtGeocercasAgregar
|
|
GvRow.FCDropDownList("DdlGeocerca").DataBind()
|
|
End If
|
|
Next
|
|
GvEstatus.Rows(index).FCDropDownList("DdlGeocerca").SelectedValueExist(CveGeoReferencia)
|
|
End If
|
|
UpAgregar.Update()
|
|
RegistraScript("$('#DivGeocercas').modal('hide');")
|
|
|
|
End Sub
|
|
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
|
CargaTrayectos()
|
|
End Sub
|
|
Protected Sub GvBarra_RowDeleting1(sender As Object, e As GridViewDeleteEventArgs)
|
|
Dim CveTrayecto As Integer = GvBarra.Rows(e.RowIndex).DataKey("CveTrayecto").ToEntero()
|
|
If CveTrayecto > 0 Then
|
|
Dim ObjGPS As New ClsGPS()
|
|
Dim TieneError As Boolean = Not ObjGPS.RemoveTrayecto(CveTrayecto)
|
|
ObjGPS.Dispose()
|
|
If Not TieneError Then
|
|
Alert("El trayecto se eliminó correctamente.")
|
|
RegistraScript("DeleteMarkers();")
|
|
CargaTrayectos()
|
|
End If
|
|
Else
|
|
Alert("No se pudo eliminar el trayecto", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
|
|
<Web.Services.WebMethod()> <Script.Services.ScriptMethodAttribute()>
|
|
Public Shared Function WsGeocercas(ByVal Id As System.String) As System.String
|
|
Dim CveGeoReferencia As Integer = Id.ToEntero
|
|
Dim Retorno As String = "{}"
|
|
|
|
If CveGeoReferencia > 0 Then
|
|
Dim ObjGPS As New ClsGPS
|
|
If ObjGPS.GeoReferenciaGet(CveGeoReferencia, 1, "-1", -1) Then
|
|
Try
|
|
Dim DrGeocercas As DataRow = ObjGPS.DtResultados.Rows(0)
|
|
If DrGeocercas IsNot Nothing Then
|
|
Dim Coords = ModExtensiones.SQLToGmapsJArray(DrGeocercas("Coordenadas").ToString, "POLYGON")
|
|
Dim Json As New JObject(New JProperty("Posiciones", Coords))
|
|
Retorno = Json.ToString
|
|
End If
|
|
Catch ex As Exception
|
|
ModExtensiones.GuardaLog("Ocurrió un error al obtener la geocerca " + ex.ToString)
|
|
End Try
|
|
End If
|
|
ObjGPS.Dispose()
|
|
End If
|
|
Return Retorno
|
|
End Function
|
|
|
|
Protected Sub ChkNotificacion_CheckedChanged(sender As Object, e As EventArgs)
|
|
DivNotificaciones.Visible = ChkNotificacion.Checked
|
|
UpAgregar.Update()
|
|
End Sub
|
|
Protected Sub LnkEnviar_Click(sender As Object, e As EventArgs)
|
|
Dim GvRow As GridViewRow = DirectCast(DirectCast(sender, LinkButton).NamingContainer, GridViewRow)
|
|
|
|
Dim CveTrayecto As Integer = GvRow.DataKey("CveTrayecto").ToEntero()
|
|
If CveTrayecto > 0 Then
|
|
Dim Url = New Uri(String.Format("{0}/ashx/SIGGPS.ashx?metodo=EjecutaTrayectos&CveTrayecto={1}", "http://gps.signalsgps.com", CveTrayecto))
|
|
Dim Retorno As String = "{}"
|
|
Try
|
|
Using httpClient = New HttpClient()
|
|
httpClient.Timeout = New TimeSpan(0, 0, 15)
|
|
Using request = New HttpRequestMessage(HttpMethod.Get, Url)
|
|
Dim response = httpClient.SendAsync(request).Result
|
|
If response.StatusCode = Net.HttpStatusCode.OK Then
|
|
Retorno = response.Content.ReadAsStringAsync().Result
|
|
End If
|
|
End Using
|
|
End Using
|
|
|
|
Dim Resp = JObject.Parse(Retorno)
|
|
If CBool(Resp("EnvioCorreo").ToString()) Then
|
|
Alert(Resp("Mensaje").ToString(), TipoMensaje.MsgInformacion)
|
|
Else
|
|
Alert(Resp("Mensaje").ToString(), TipoMensaje.MsgError)
|
|
End If
|
|
Catch ex As Exception
|
|
OnError("Ocurrió un error al enviar el correo", ex)
|
|
End Try
|
|
Else
|
|
Alert("No se pudo identificar el trayecto", TipoMensaje.MsgError)
|
|
End If
|
|
End Sub
|
|
Protected Sub TimmerRefresh_Tick(sender As Object, e As EventArgs)
|
|
CargaTrayectos()
|
|
End Sub
|
|
Protected Sub ChkTimmer_CheckedChanged(sender As Object, e As EventArgs)
|
|
TimmerRefresh.Enabled = ChkTimmer.Checked
|
|
|
|
UPGV.Update()
|
|
End Sub
|
|
End Class
|