Option Strict On Option Explicit On Imports System.Data Imports Extensiones Partial Class GPS_GeoReferencias Inherits ClsPaginas Public Property DtVehiculos() As Data.DataTable Get Return DirectCast(ViewState("DtVehiculos"), DataTable) End Get Set(ByVal value As Data.DataTable) ViewState("DtVehiculos") = value End Set End Property Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not Page.IsPostBack Then CargaDispositivos() CargaGrupos() CreaTmpDT() End If End Sub Protected Sub CreaTmpDT() DtVehiculos = New DataTable Dim pk = DtVehiculos.Columns.Add("CveDispositivo", GetType(Integer)) DtVehiculos.Columns.Add("NoEconomico", GetType(String)) DtVehiculos.Columns.Add("CveDispositivoGeoReferenciaDetalle", GetType(Integer)) DtVehiculos.PrimaryKey = New DataColumn() {pk} GvDispositivos.DataSource = DtVehiculos GvDispositivos.DataBind() UpAgregar.Update() End Sub Private Sub CargaDispositivos() DdlEquipo.DataSource = GlobalDTDispositivosUsuarios(UsuarioActual.CveCliente, UsuarioActual.CveUsuario).FiltraParametros("Estatus = 1") DdlEquipo.DataBind() DdlEquipo.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub Private Sub CargaGrupos() Using ObjGPS As New ClsGPS If ObjGPS.GruposGet(-1, UsuarioActual.CveCliente) Then DdlGrupo.DataSource = ObjGPS.DtResultados DdlGrupo.DataBind() End If End Using DdlGrupo.Items.Insert(0, New ListItem("Seleccione", "-1")) End Sub Protected Sub GvDispositivos_RowDeleting(sender As Object, e As GridViewDeleteEventArgs) DtVehiculos.Rows.RemoveAt(e.RowIndex) GvDispositivos.DataSource = DtVehiculos GvDispositivos.DataBind() UpAgregar.Update() End Sub Protected Sub LnkAgregarDisp_Click(sender As Object, e As EventArgs) Dim CveDispositivo As Integer = DdlEquipo.SelectedValue.ToEntero If CveDispositivo > 0 Then Dim NoEconomico As String = DdlEquipo.SelectedItem.Text If Not DtVehiculos.Select($"CveDispositivo={CveDispositivo}").Any() Then Dim Dr As DataRow = DtVehiculos.NewRow Dr("CveDispositivo") = CveDispositivo Dr("NoEconomico") = NoEconomico Dr("CveDispositivoGeoReferenciaDetalle") = -1 DtVehiculos.Rows.Add(Dr) DtVehiculos.AcceptChanges() Else Alert($"El dispositivo '{NoEconomico} ya existe en la tabla.'", TipoMensaje.MsgAdvertencia) End If GvDispositivos.DataSource = DtVehiculos GvDispositivos.DataBind() End If UpAgregar.Update() RegistraScript("CargaPickersHora();", "1") End Sub Protected Sub LnkAgregarGrupo_Click(sender As Object, e As EventArgs) Dim CveGrupo As Integer = DdlGrupo.SelectedValue.ToEntero Using ObjGPS As New ClsGPS If ObjGPS.GruposDetallesGet(CveGrupo) Then Dim Query = From dr In ObjGPS.DtResultados Select CveDispositivo = dr("CveDispositivo").ToString.ToEntero, NoEconomico = dr("NoEconomico").ToString, CveDispositivoGeoReferenciaDetalle = -1 Dim dt As DataTable = Query.QueryToDataTable(True) dt.PrimaryKey = New DataColumn() {dt.Columns(0)} DtVehiculos.Merge(dt, True, MissingSchemaAction.Ignore) End If End Using GvDispositivos.DataSource = DtVehiculos GvDispositivos.DataBind() UpAgregar.Update() RegistraScript("CargaPickersHora();", "1") End Sub Protected Sub BtnCrear_Click(sender As Object, e As EventArgs) Dim TieneError As Boolean = False Dim ObjGPS As New ClsGPS ObjGPS.IniciaTransacSQL() Dim GeoRefString As String Try If HdnTipo.Value = "Georuta" Then GeoRefString = 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 ObjGPS.GeoReferenciaAdd(TxtNombre.Text, -1, GeoRefString, "Ruta", True, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, chkLunes.Checked, chkMartes.Checked, chkMiercoles.Checked, chkJueves.Checked, chkViernes.Checked, chkSabado.Checked, chkDomingo.Checked, ($"{Date.Now.ToShortDateString} {TxtHoraI.Text}").ToDateTime, ($"{Date.Now.ToShortDateString} {TxtHoraF.Text}").ToDateTime, hdnColor.Value, TxtTolerancia.Text.ToEntero, UsuarioActual.CveCliente) Then For Each Dr As GridViewRow In GvDispositivos.Rows If Dr.RowType = DataControlRowType.DataRow Then If Not ObjGPS.AddGeoReferenciaDetalle(ObjGPS.CveGeoReferencia, Dr.DataKey("CveDispositivo").ToString.ToEntero) Then TieneError = True Exit For End If End If Next Else TieneError = True End If 'RegistraScript("CreaRuta();") ElseIf HdnTipo.Value = "Geocerca" Then GeoRefString = $"POLYGON(({GeoCerca.Value} {CommandArg.Value}))" If ObjGPS.GeoReferenciaAdd(TxtNombre.Text, -1, GeoRefString, "Geocerca", True, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate, chkLunes.Checked, chkMartes.Checked, chkMiercoles.Checked, chkJueves.Checked, chkViernes.Checked, chkSabado.Checked, chkDomingo.Checked, ($"{Date.Now.ToShortDateString} {TxtHoraI.Text}").ToDateTime, ($"{Date.Now.ToShortDateString} {TxtHoraF.Text}").ToDateTime, hdnColor.Value, TxtTolerancia.Text.ToEntero, UsuarioActual.CveCliente) Then For Each Dr As GridViewRow In GvDispositivos.Rows If Dr.RowType = DataControlRowType.DataRow Then If Not ObjGPS.AddGeoReferenciaDetalle(ObjGPS.CveGeoReferencia, Dr.DataKey("CveDispositivo").ToString.ToEntero) Then TieneError = True Exit For End If End If Next End If End If Catch ex As Exception TieneError = False OnError("Ocurrió un error al agregar la GeoReferencia.", ex) Finally If TieneError Then ObjGPS.RollBack() Else ObjGPS.Commit() Alert("Se agregó correctamente la Ruta", TipoMensaje.MsgInformacion) End If ObjGPS.Dispose() RegistraScript("Limpieza();") GeoRefString = "" TxtNombre.Text = "" DdlEquipo.SelectedValue = "-1" txtFechaI.Text = "" txtFechaF.Text = "" TxtTolerancia.Text = "" chkLunes.Checked = False chkMartes.Checked = False chkMiercoles.Checked = False chkJueves.Checked = False chkViernes.Checked = False chkSabado.Checked = False chkDomingo.Checked = False TxtHoraI.Text = "" TxtHoraF.Text = "" End Try UpBodyTipoEquipo.Update() End Sub Private Function GetControlThatCausedPostBack(ByVal page As Page) As Control 'initialize a control and set it to null Dim ctrl As Control = Nothing 'get the event target name and find the control Dim ctrlName As String = page.Request.Params.Get("__EVENTTARGET") If Not String.IsNullOrEmpty(ctrlName) Then ctrl = page.FindControl(ctrlName) End If 'return the control to the calling method Return ctrl End Function End Class