266 lines
12 KiB
VB.net
266 lines
12 KiB
VB.net
Imports Extensiones
|
|
Imports System.Data
|
|
Partial Class GPS_PuntosDeInteres
|
|
Inherits ClsPaginas
|
|
|
|
#Region " PROPIEDADES "
|
|
Private Property TrazarRuta As Integer
|
|
Get
|
|
Return ViewState("TrazarRuta").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("TrazarRuta") = value
|
|
End Set
|
|
End Property
|
|
Private Property EsEditar As Integer
|
|
Get
|
|
Return ViewState("EsEditar").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("EsEditar") = value
|
|
End Set
|
|
|
|
End Property
|
|
Private Property CvePuntoDeInteres As Integer
|
|
Get
|
|
Return ViewState("CvePuntoDeInteres").ToString.ToEntero
|
|
End Get
|
|
Set(value As Integer)
|
|
ViewState("CvePuntoDeInteres") = 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
|
|
CargaDatos()
|
|
EsEditar = 0
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CargaDatos()
|
|
Dim gps As New ClsGPS
|
|
If gps.PuntoDeInteresGrupoGet(-1, 1) Then
|
|
GvGrupos.DataSource = gps.DtResultados
|
|
Else
|
|
GvGrupos.DataSource = Nothing
|
|
End If
|
|
If gps.PuntoDeInteresGet(-1, UsuarioActual.CveCliente, 1, -1) Then
|
|
GvPuntos.DataSource = gps.DtResultados
|
|
GVPuntosInteres.DataSource = gps.DtResultados
|
|
Else
|
|
GvPuntos.DataSource = Nothing
|
|
GVPuntosInteres.DataSource = Nothing
|
|
End If
|
|
gps.Dispose()
|
|
GvGrupos.DataBind()
|
|
GvPuntos.DataBind()
|
|
GVPuntosInteres.DataBind()
|
|
UpEditar.Update()
|
|
End Sub
|
|
|
|
Protected Sub GvGrupos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvGrupos.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.Attributes.Add("onClick", $"CargaDatosSeleccionados({e.Row.RowIndex}, '{e.Row.DBCampo("CvePuntoDeInteresGrupo").ToString}');")
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Protected Sub BtnAgregarPunto_Click(sender As Object, e As EventArgs) Handles BtnAgregarPunto.Click
|
|
Dim GPS As New ClsGPS
|
|
GPS.IniciaTransacSQL()
|
|
Dim GEOM As String
|
|
Dim HuboError = False
|
|
If EsEditar = 0 Then
|
|
If HdnTipo.Value = "Point" Then
|
|
If Points.Value <> "" Then
|
|
GEOM = Points.Value
|
|
Dim Var = 0
|
|
Dim CoordsPuntos() As String = GEOM.Split(","c)
|
|
For Each coordenada As String In CoordsPuntos
|
|
Var += 1
|
|
If coordenada Is CoordsPuntos.Last Then
|
|
Exit For
|
|
End If
|
|
If Not GPS.PuntoDeInteresAdd($"{TxtNombre.Text} {Var}", UsuarioActual.CveCliente, $"POINT{coordenada}", True, TxtDescripcion.Text, HdnGrupo.Value.ToEntero) Then
|
|
HuboError = True
|
|
End If
|
|
Next
|
|
If Not HuboError Then
|
|
Alert("Los puntos de interés se agregaron correctamente", TipoMensaje.MsgInformacion)
|
|
End If
|
|
Else
|
|
GEOM = $"POINT{CommandArg.Value}"
|
|
If GPS.PuntoDeInteresAdd(TxtNombre.Text, UsuarioActual.CveCliente, GEOM, True, TxtDescripcion.Text, HdnGrupo.Value.ToEntero) Then
|
|
Alert("El punto de interés se agregó correctamente", TipoMensaje.MsgInformacion)
|
|
Else
|
|
HuboError = True
|
|
End If
|
|
End If
|
|
RegistraScript("$('#divAgregarTipo').modal('hide');DeleteMarkers();", "1")
|
|
CargaDatos()
|
|
ElseIf HdnTipo.Value = "PointGroup" Then
|
|
If GPS.PuntoDeInteresGrupoAdd(TxtNombre.Text, UsuarioActual.CveCliente, True, TxtDescripcion.Text) Then
|
|
Alert("El grupo de puntos de guardó correctamente", TipoMensaje.MsgInformacion)
|
|
End If
|
|
RegistraScript("$('#divAgregarTipo').modal('hide');DeleteMarkers();", "1")
|
|
CargaDatos()
|
|
ElseIf HdnTipo.Value = "GroupRoute" Then
|
|
If HdnGrupo.Value = "-1" Then
|
|
Alert("Es necesario seleccionar un grupo de puntos", TipoMensaje.MsgAdvertencia)
|
|
Exit Sub
|
|
End If
|
|
If GPS.PuntoDeInteresGet(-1, -1, 1, HdnGrupo.Value.ToEntero) AndAlso GPS.DtResultados.Rows.Count > 0 Then
|
|
Dim ruta As String = ""
|
|
For Each row As DataRow In GPS.DtResultados.Rows
|
|
ruta += row("Punto").ToString.Replace("POINT (", "").Replace(")", ",")
|
|
Next
|
|
ruta = $"LINESTRING({ruta.Substring(0, ruta.Length - 1)})"
|
|
ruta = SQLToGmaps(ruta, "LINESTRING")
|
|
RegistraScript($"CreaRuta({ruta})")
|
|
Else
|
|
Alert("El grupo seleccionado está vacío", TipoMensaje.MsgAdvertencia)
|
|
End If
|
|
RegistraScript("$('#divAgregarTipo').modal('hide');", "1")
|
|
End If
|
|
Else
|
|
If GPS.PuntoDeInteresUpdate(TxtNombre.Text, UsuarioActual.CveCliente, CvePuntoDeInteres, chkEstatus.Checked, TxtDescripcion.Text, HdnGrupo.Value.ToEntero) Then
|
|
HuboError = False
|
|
Alert("El punto de interés se actualizó correctamente")
|
|
RegistraScript("$('#divAgregarTipo').modal('hide');", "1")
|
|
dvEstatus.Style.Add("display", "none")
|
|
Else
|
|
HuboError = True
|
|
End If
|
|
End If
|
|
TxtDescripcion.Text = ""
|
|
TxtNombre.Text = ""
|
|
UpBodyTipoEquipo.Update()
|
|
If HuboError Then
|
|
GPS.RollBack()
|
|
Else
|
|
GPS.Commit()
|
|
CargaDatos()
|
|
End If
|
|
End Sub
|
|
|
|
Private Function SQLToGmaps(CoordsSQL As String, Tipo As String) As String
|
|
Dim CoordsPoligono As String = CoordsSQL.Replace($"{Tipo}", "").Replace(")", "").Replace("(", "")
|
|
Dim CoordsPuntos() As String = CoordsPoligono.Split(","c)
|
|
Dim Var As String = ""
|
|
For Each coordenada As String In CoordsPuntos
|
|
If coordenada Is CoordsPuntos.Last Then
|
|
Dim latlng() As String = coordenada.Trim.Split(" ")
|
|
Var = $"{Var}{{lat: {latlng(1)}, lng: {latlng(0)} }}"
|
|
Else
|
|
Dim latlng() As String = coordenada.Trim.Split(" ")
|
|
Var = $"{Var}{{lat: {latlng(1)}, lng: {latlng(0)} }},"
|
|
End If
|
|
Next
|
|
|
|
If Tipo = "POLYGON" OrElse Tipo = "LINESTRING" Then
|
|
Var = $"[{Var}]"
|
|
End If
|
|
Return Var
|
|
End Function
|
|
Protected Sub BtnCalcular_Click(sender As Object, e As EventArgs) Handles BtnCalcularR.Click
|
|
Dim GPS As New ClsGPS
|
|
Dim HuboError = False
|
|
Dim ruta As String = ""
|
|
|
|
For Each row As GridViewRow In GvPuntos.Rows
|
|
If row.FCCheckBox("chkGR").Checked Then
|
|
ruta += row.DataKey("Punto").ToString.Replace("POINT (", "").Replace(")", ",")
|
|
End If
|
|
Next
|
|
ruta = $"LINESTRING({ruta.Substring(0, ruta.Length - 1)})"
|
|
ruta = SQLToGmaps(ruta, "LINESTRING")
|
|
RegistraScript($"CreaRuta({ruta})", "1")
|
|
RegistraScript("$('#dvConsulta').modal('hide');", "2")
|
|
|
|
End Sub
|
|
'Protected Sub BtnAgregarRuta_Click(sender As Object, e As EventArgs) Handles BtnAgregarRuta.Click
|
|
' Dim GPS As New ClsGPS
|
|
' Dim GeoRefString As String = CommandArg.Value
|
|
' Dim CoordsPuntos() As String = GeoRefString.Split("+"c)
|
|
' GeoRefString = ""
|
|
' For Each coordenada As String In CoordsPuntos
|
|
' If coordenada Is CoordsPuntos.Last Then
|
|
' Exit For
|
|
' End If
|
|
' coordenada = coordenada.Replace("(", "").Replace(")", "")
|
|
' Dim LatLng() As String = coordenada.Split(","c)
|
|
' GeoRefString = $"{GeoRefString} {LatLng(1).Trim} {LatLng(0).Trim},"
|
|
' Next
|
|
|
|
' GeoRefString = GeoRefString.Substring(0, GeoRefString.Length - 1)
|
|
' GeoRefString = $"LINESTRING({GeoRefString})"
|
|
' If GPS.GeoReferenciaAdd(TxtNomRuta.Text, 7, GeoRefString, "Ruta", True, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, chkLunes.Checked, chkMartes.Checked, chkMiercoles.Checked, chkJueves.Checked, chkViernes.Checked, chkSabado.Checked, chkDomingo.Checked, DateTime.Today, DateTime.Today.AddDays(1), "#0088FF", TxtTolerancia.Text, UsuarioActual.CveCliente) Then
|
|
' Alert("Se agregó correctamente la Ruta", TipoMensaje.MsgInformacion)
|
|
' End If
|
|
|
|
' CommandArg.Value = ""
|
|
' GeoRefString = ""
|
|
' TxtNomRuta.Text = ""
|
|
' TxtTolerancia.Text = ""
|
|
' txtFechaI.Text = ""
|
|
' txtFechaF.Text = ""
|
|
' TxtHoraF.Text = ""
|
|
' TxtHoraI.Text = ""
|
|
' chkLunes.Checked = False
|
|
' chkMartes.Checked = False
|
|
' chkMiercoles.Checked = False
|
|
' chkJueves.Checked = False
|
|
' chkViernes.Checked = False
|
|
' chkSabado.Checked = False
|
|
' chkDomingo.Checked = False
|
|
' UpdatePanel2.Update()
|
|
' GPS.Dispose()
|
|
' RegistraScript("Limpieza();")
|
|
'End Sub
|
|
Protected Sub BtnAlerta_Click(sender As Object, e As EventArgs) Handles BtnAlerta.Click
|
|
Alert("Debido a la falta de caminos entre estos puntos, no es posible calcular la ruta. La siguiente es sólo una representación.", TipoMensaje.MsgAdvertencia)
|
|
End Sub
|
|
Protected Sub imgE_Click(sender As Object, e As EventArgs)
|
|
EsEditar = 1
|
|
Dim Boton = CType(sender, LinkButton)
|
|
Dim GvRow As GridViewRow = DirectCast(Boton.NamingContainer, GridViewRow)
|
|
CvePuntoDeInteres = GvRow.DataKey("CvePuntoDeInteres").ToString.ToEntero
|
|
TxtNombre.Text = GvRow.DataKey("PuntoDeInteres").ToString
|
|
TxtDescripcion.Text = GvRow.DataKey("Descripcion").ToString
|
|
dvEstatus.Style.Add("display", "")
|
|
dvEstatus.Style.Add("display", "")
|
|
chkEstatus.Checked = CBool(GvRow.DataKey("Estatus").ToString)
|
|
RegistraScript($"$('#divAgregarTipo').modal();",1)
|
|
For Each row As GridViewRow In GvGrupos.Rows
|
|
If row.DataKey("CvePuntoDeInteresGrupo").ToString = GvRow.DataKey("CvePuntoDeInteresGrupo").ToString Then
|
|
RegistraScript($"CargaDatosSeleccionados({row.RowIndex}, '{row.DataKey("CvePuntoDeInteresGrupo").ToString}');")
|
|
End If
|
|
Next
|
|
UpBodyTipoEquipo.Update()
|
|
End Sub
|
|
Protected Sub GvDatos_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GVPuntosInteres.RowDeleting
|
|
Dim GPS As New ClsGPS
|
|
Dim CvePuntodeInteres As Integer = GVPuntosInteres.Rows(e.RowIndex).DataKey("CvePuntoDeInteres").ToEntero
|
|
If GPS.PuntoDeInteresDelete(CvePuntodeInteres, UsuarioActual.CveCliente) Then
|
|
Alert("El punto de interés se eliminó correctamente", TipoMensaje.MsgInformacion)
|
|
End If
|
|
GPS.Dispose()
|
|
CargaDatos()
|
|
End Sub
|
|
Protected Sub GvDatos_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GVPuntosInteres.RowDataBound
|
|
If e.Row.RowType = DataControlRowType.DataRow Then
|
|
e.Row.FCLinkButton("ImgE").CommandArgument = e.Row.DataKey("CvePuntoDeInteres").ToString
|
|
End If
|
|
End Sub
|
|
Protected Sub LBMostrar_Click(sender As Object, e As EventArgs) Handles LBMostrar.Click
|
|
For Each row As GridViewRow In GVPuntosInteres.Rows
|
|
If row.FCCheckBox("chkGR").Checked Then
|
|
Dim coords = SQLToGmaps(row.DataKey("Punto"), "POINT")
|
|
RegistraScript($"CreaMarcador({coords}, '{row.DataKey("PuntoDeInteres").ToString}')", row.RowIndex)
|
|
End If
|
|
Next
|
|
RegistraScript("$('#dvEditar').modal('hide');FitBounds();")
|
|
End Sub
|
|
End Class
|