Files
SIG/GPS/RepPuntosDeInteres.aspx.vb

213 lines
10 KiB
VB.net

Option Strict On
Imports Extensiones
Imports System.Data
Imports Microsoft.Reporting.WebForms
Partial Class GPS_RepPuntosDeInteres
Inherits ClsPaginas
#Region "P R O P I E D A D E S "
Private Property DispositivosLista As List(Of String)
Get
Return If(IsNothing(ViewState("DispositivosLista")), Nothing, CType(ViewState("DispositivosLista"), List(Of String)))
End Get
Set(value As List(Of String))
ViewState("DispositivosLista") = value
End Set
End Property
Private Property DtDatosReporte As DataTable
Get
Return If(IsNothing(ViewState("DtDatosReporte")), Nothing, CType(ViewState("DtDatosReporte"), DataTable))
End Get
Set(value As DataTable)
ViewState("DtDatosReporte") = 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()
End If
End Sub
Private Sub CargaDatos()
txtFechaF.Text = Now.ToString("dd/MM/yyyy")
txtFechaI.Text = Now.AddDays(-7).ToString("dd/MM/yyyy")
CargaDispositivos()
Dim ObjGPS As New ClsGPS
If ObjGPS.PuntoDeInteresGet(-1, UsuarioActual.CveCliente, 1, -1) Then
GvPuntos.DataSource = ObjGPS.DtResultados
Else
GvPuntos.DataSource = Nothing
End If
ObjGPS.Dispose()
GvPuntos.DataBind()
End Sub
Private Sub CargaDispositivos()
GvDispositivos.DataSource = GlobalDTDispositivosUsuarios(UsuarioActual.CveCliente, UsuarioActual.CveUsuario).FiltraParametros("Estatus = 1 ")
GvDispositivos.DataBind()
End Sub
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs) Handles BtnConsultar.Click
Dim sb As New StringBuilder
DispositivosLista = New List(Of String)
RegistraScript("DeleteMarkers();", "0")
For Each row As GridViewRow In GvDispositivos.Rows
If row.FCCheckBox("chkDis").Checked Then
sb.Append($"{row.DataKey("CveDispositivo").ToString},")
DispositivosLista.Add(row.DataKey("CveDispositivo").ToString)
End If
Next
ReportePuntos(sb.ToString)
RegistraScript("$('#dvConsulta').modal('hide');", "00")
End Sub
Private Sub ReportePuntos(Dispositivos As String)
Dim FechaI, FechaF As Date
Dim SBBody As New StringBuilder
Dim CoordsPoligono = ""
Dim Coords = ""
Dim Titulo = ""
Dim Info = ""
Dim COUNT = 0
Dim GeoCercas = ""
Dim Color = ""
FechaI = If(txtFechaI.Text.Trim = "", MinFecha, txtFechaI.Text.Trim.ToDate)
FechaF = If(txtFechaF.Text.Trim = "", MaxFecha, txtFechaF.Text.Trim.ToDate)
Dim ObjGPS As New ClsGPS
Try
For Each row As GridViewRow In GvPuntos.Rows
SBBody.Clear()
If row.FCCheckBox("chkGR").Checked Then
If ObjGPS.RepPuntosGet(row.DataKey("CvePuntoDeInteres").ToEntero, Dispositivos, txtFechaI.Text.ToDateTime, txtFechaF.Text.ToDateTime, UsuarioActual.CveCliente) Then
DtDatosReporte = ObjGPS.DtResultados.Copy()
GvBarra.DataSource = DtDatosReporte
Coords = SQLToGmaps(row.DataKey("Punto").ToString, "POINT")
SBBody.Append($"<div>")
SBBody.Append($"<div><h5><b> Punto: {row.DataKey("PuntoDeInteres")}</b></h5></div>")
If ObjGPS.DtResultados.Rows.Count > 0 Then
Color = "#26C281"
SBBody.Append($"<div><table>")
For Each Cve As String In DispositivosLista
If ObjGPS.DtResultados.FiltraParametros($"CveDispositivo = {Cve} ").Rows.Count > 0 Then
SBBody.Append($"<tr><td><b>{ObjGPS.DtResultados.FiltroPrimeroValor("Vehiculo", $"CveDispositivo = {Cve}")}:</b> <a onclick=""CargaGV({Cve}, {row.DataKey("CvePuntoDeInteres")} )"">{ObjGPS.DtResultados.FiltroPrimeroValor("Visitas", $"CveDispositivo = {Cve}")} visitas<a></td></tr>")
SBBody.Append($"<tr><td>Última Visita: {ObjGPS.DtResultados.FiltroPrimeroValor("UltimaVisita", $"CveDispositivo = {Cve}")}</td></tr>")
End If
Next
SBBody.Append($"</table></div>")
Else
Color = "#e82929"
SBBody.Append($"<tr><td><b>Este punto de interés no fue visitado en las fechas seleccionadas.</b></td></tr>")
End If
SBBody.Append($"</div>")
RegistraScript($"CreaCirculo({Coords},'{Color}');CreaMarcador({Coords},'{row.DataKey("PuntoDeInteres")}','{SBBody.ToString}');", row.DataKey("CvePuntoDeInteres"))
End If
End If
Next
Catch ex As Exception
OnError("Ocurrió un error al consultar los puntos de interes", ex)
End Try
ObjGPS.Dispose()
GvBarra.DataBind()
UPGV.Update()
End Sub
'If GPS.GeoReferenciasEntradasSalidas(GVRow.DataKey("CveDispositivo").ToString.ToEntero, row.DataKey("CveGeoReferencia").ToString.ToEntero, FechaI, FechaF) Then
' SBBody.Append($"<div><table>")
' SBBody.Append($"<tr><td>Fecha : {rr("FechaTrama").ToString}</td></tr>")
' SBBody.Append($"<tr><td>Conductor : {rr("Conductor").ToString}</td></tr>")
' SBBody.Append($"<tr><td>Serie Vehículo: {GVRow.DataKey("SerieVehiculo").ToString}</td></tr>")
' If GPS.DtResultados.Rows.Count > 0 Then
' CoordsPoligono = SQLToGmaps(row.DataKey("Coordenadas").ToString, "POLYGON")
' For Each rr As DataRow In GPS.DtResultados.Rows
' Coords = SQLToGmaps(rr("Posicion").ToString, "POINT")
' SBBody.Clear()
' SBBody.Append($"<div>")
' SBBody.Append($"<div><h4><b>{rr("Evento")}</b></h4></div>")
' SBBody.Append($"</table></div><div></div></div>")
' Info = SBBody.ToString
' RegistraScript($"CreaMarcador({Coords},'{GVRow.DataKey("SerieVehiculo").ToString}', '{Info}');", $"{rr("CveDispositivoEvento").ToString}{COUNT.ToString}")
' COUNT += 1
' Next
' RegistraScript($"creaPoligono([{CoordsPoligono}], '{row.DataKey("Color").ToString}')", $"{row.DataKey("CveGeoReferencia").ToString.ToEntero}{COUNT.ToString}")
' Else
' GeoCercas = $"{GeoCercas} {row.DataKey("GeoReferencia").ToString},"
' End If
' End If
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(" "c)
Var = $"{Var}{{lat: {latlng(1)}, lng: {latlng(0)} }}"
Else
Dim latlng() As String = coordenada.Trim.Split(" "c)
Var = $"{Var}{{lat: {latlng(1)}, lng: {latlng(0)} }},"
End If
Next
Return Var
End Function
Protected Sub BtnCargarGV_Click(sender As Object, e As EventArgs) Handles BtnCargarGV.Click
Dim GPS As New ClsGPS
If GPS.RepPuntosDetalleGet(HdnPunto.Value.ToEntero, HdnDispositivo.Value.ToEntero, txtFechaI.Text.ToDateTime, txtFechaF.Text.ToDateTime, UsuarioActual.CveCliente) Then
GVHistorico.DataSource = GPS.DtResultados.FiltraParametros("CveEvento = 106")
Else
GVHistorico.DataSource = Nothing
End If
GPS.Dispose()
GVHistorico.DataBind()
UpdatePanel3.Update()
RegistraScript("$('#dvHistorico').modal()")
End Sub
'Protected Sub GvBarra_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GvBarra.RowDataBound
' If e.Row.RowType = DataControlRowType.DataRow Then
' Dim RowID As String = $"row{e.Row.RowIndex}"
' e.Row.Attributes("id") = RowID
' Dim IndexGvBarra As Integer = If(String.IsNullOrEmpty(HdnIndexGvBarra.Value), -1, HdnIndexGvBarra.Value.ToEntero)
' RegistraScript($"GetDireccionesGV({e.Row.DBCampo("Posicion").ToString}, {e.Row.RowIndex}, 1);", $"{RowID}")
' End If
'End Sub
Protected Sub btnImprimir_Click(sender As Object, e As EventArgs)
Dim Btn As Button = CType(sender, Button)
Dim Format = Btn.CommandArgument
EnviarReporteProgramado(Format)
End Sub
Public Sub EnviarReporteProgramado(Format As String)
Dim RutaReporte = "Empresas/Grales/ReportesProgramados/RPTPuntosInteres.rdlc"
Dim NombreReporte = "ReportePuntosInteres"
Try
Dim RptParametro As New List(Of ReportParameter)
RptParametro.Add(New ReportParameter("FechaInicio", txtFechaI.Text))
RptParametro.Add(New ReportParameter("FechaFin", txtFechaF.Text))
RptParametro.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario))
RptParametro.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString))
Dim retorno = StreamPDF(RutaReporte, DtDatosReporte, RptParametro, $"{NombreReporte}{Date.Now.ToShortDateString}", Format, MR:=Nothing, RDSName:="DsOC")
ImprimirbytesPDF(retorno, $"{NombreReporte}{Date.Now.ToShortDateString}", Format)
Catch ex As Exception
GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex))
End Try
End Sub
End Class