diff --git a/App_Code/ClsSisNotificaciones.vb b/App_Code/ClsSisNotificaciones.vb index bcf8af387..c2406c5ee 100644 --- a/App_Code/ClsSisNotificaciones.vb +++ b/App_Code/ClsSisNotificaciones.vb @@ -46,27 +46,45 @@ Public Class ClsSisNotificaciones Private disposedValue As Boolean = False ' Para detectar llamadas redundantes 'PARA REGISTRAR CONEXION - Private CveConexion As Integer = 0 + Private CveConexion As Integer = 0 #End Region - + #Region "P R O P I E D A D E S" - 'Public ReadOnly Property FirebaseWebService As String - ' Get - ' Return ConfigurationManager.AppSettings("FirebaseWebService").ToString() - ' End Get - 'End Property - 'Public ReadOnly Property FirebaseServerKey As String - ' Get - ' Return ConfigurationManager.AppSettings("FirebaseServerKey").ToString() - ' End Get - 'End Property - 'Public ReadOnly Property SenderID As String - ' Get - ' Return ConfigurationManager.AppSettings("SenderID").ToString() - ' End Get - 'End Property - - 'Push Notifications + 'Public ReadOnly Property FirebaseWebService As String + ' Get + ' Return ConfigurationManager.AppSettings("FirebaseWebService").ToString() + ' End Get + 'End Property + 'Public ReadOnly Property FirebaseServerKey As String + ' Get + ' Return ConfigurationManager.AppSettings("FirebaseServerKey").ToString() + ' End Get + 'End Property + 'Public ReadOnly Property SenderID As String + ' Get + ' Return ConfigurationManager.AppSettings("SenderID").ToString() + ' End Get + 'End Property + + 'Push Notifications + ReadOnly Property GlobalDTUsuarios(Optional CveUsuario As Integer = -1, Optional CveEmpresa As Integer = -1, Optional CveCliente As Integer = -1, Optional CveProveedor As Integer = -1) As DataTable + Get + Dim Str As New StringBuilder + If CveUsuario <> -1 Then Str.AppendFormat("CveUsuario = {0}", CveUsuario) + If CveEmpresa <> -1 Then Str.AppendFormat(" {0} CveEmpresa = {1}", If(Str.Length > 0, "AND", ""), CveEmpresa) + If CveCliente <> -1 Then Str.AppendFormat(" {0} CveCliente = {1}", If(Str.Length > 0, "AND", ""), CveCliente) + If CveProveedor <> -1 Then Str.AppendFormat(" {0} CveProveedor = {1}", If(Str.Length > 0, "AND", ""), CveProveedor) + + If CveUsuario <> -1 OrElse CveEmpresa <> -1 Then + Dim Dv As New DataView(DirectCast(HttpContext.Current.Application("GlobalDTUsuarios"), DataTable), Str.ToString, "", DataViewRowState.CurrentRows) + GlobalDTUsuarios = Dv.ToTable + Dv.Dispose() + Else + GlobalDTUsuarios = DirectCast(HttpContext.Current.Application("GlobalDTUsuarios"), DataTable) + End If + End Get + End Property + Public Const FirebaseWebService As String = "https://fcm.googleapis.com/fcm/send" Public Const FirebaseServerKey As String = "AAAAqx0xsBA:APA91bHip_JcMGhNQiIzdnodY9ynkHIjX9wEc4TrLkepXK0Lz1QEar5dys6sa3ourPLGiEJD4fGGnSzrk2M_9aJuQo55LjvSJs2c1bU74u-yArMcbI0F_cKzbYAcOMRc8pbRknuWGsXX" Public Const SenderID As String = "734929203216" @@ -141,10 +159,11 @@ Public Class ClsSisNotificaciones End If - End Sub + End Sub #End Region + #Region "N O T I F I C A C I O N E S" - + Public Sub DispararNotificacion(CveNotificacion As Integer, CvesFiltro As List(Of Object), CveEmpresa As Integer) _CveNotificacion = CveNotificacion _CveEmpresa = CveEmpresa @@ -228,12 +247,48 @@ Public Class ClsSisNotificaciones OnError("Ocurrió error al mandar el Mail", ex) End Try ObjNotificacion.Dispose() - End Sub - + End Sub + #End Region + +#Region "V A L I D A - U S U A R I O" + Private Function ValidaUsuarioSistema(CveEmpresa As Integer) As Usuario + Dim UsuarioActual As Usuario = Nothing + Dim ObjUsuarios As New ClsSisUsuarios + If ObjUsuarios.GetUsuarios(100) Then + If ObjUsuarios.DtResultados.Rows.Count > 0 Then + Dim Usuario = ObjUsuarios.DtResultados.Rows(0)("Usuario").ToString() + Dim Contrasenia = ObjUsuarios.DtResultados.Rows(0)("Contraseña").ToString() + UsuarioActual = ObjUsuarios.ValidaUsuario(Usuario, Contrasenia, IMEI, CveEmpresa) + UsuarioActual.CveEmpresa = CveEmpresa + CreaObjetoEmpresa(UsuarioActual) + End If + End If + ObjUsuarios.Dispose() + Return UsuarioActual + End Function + Private Sub CreaObjetoEmpresa(ByRef UsuarioActual As Usuario) + Dim ObjEmpresa As New ClsSisEmpresas() + If ObjEmpresa.GetEmpresas(UsuarioActual.CveEmpresa, "-1", "-1", "-1", "-1") Then + If ObjEmpresa.GetEmpresasFuncionalidades(UsuarioActual.CveEmpresa) Then + Dim dttmp As Data.DataTable = ObjEmpresa.DtResultados + + Dim EmpresasFuncionalidades As New HybridDictionary + For Each Row As Data.DataRow In dttmp.Rows + EmpresasFuncionalidades.Add(Convert.ToInt32(Row("CveFuncionalidad")), Row("Valor").ToString) + Next + ObjEmpresa.Empresa.SetFuncionalidades(EmpresasFuncionalidades) + End If + + UsuarioActual.Empresa = ObjEmpresa.Empresa + End If + ObjEmpresa.Dispose() + End Sub +#End Region + #Region "N O T I F I C A C I O N E S - M E T O D O S G E N E R A L E S" - + Public Function ObtenerNotificaciones() As Boolean If Not GetNotificacionesBitacoraPendientes(1000) Then @@ -260,21 +315,31 @@ Public Class ClsSisNotificaciones End Function Public Sub ArmarReportesProgramados() - Try + Try + For Each RowReporte As DataRow In DTReportesProgramados.Rows Dim CveReporteProgramado As Integer = RowReporte("CveReporteProgramado").ToString.ToEntero Dim CveNotificacionBitacora As Integer = RowReporte("CveNotificacionBitacora").ToString.ToEntero + Dim Correos As String = RowReporte("Correos").ToString + Dim NombreCliente As String = RowReporte("Cliente").ToString + Dim FechaI As DateTime = RowReporte("FechaI").ToString.ToDateTime Dim FechaF As DateTime = RowReporte("FechaF").ToString.ToDateTime + Dim CveReporte As Integer = RowReporte("CveReporte").ToString.ToEntero Dim CveCliente As Integer = RowReporte("CveCliente").ToString.ToEntero + Dim CveEmpresa As Integer = RowReporte("CveEmpresa").ToString.ToEntero + Dim DtExtras As DataTable = Nothing Dim DtDispositivos As DataTable = Nothing + Dim Formato As String = RowReporte("Formato").ToString + Dim UsuarioActual As Usuario = ValidaUsuarioSistema(CveEmpresa) + Dim ObjGPS As New ClsGPS - If CveReporte.Contiene(1, 2, 3, 4, 5, 6, 7, 8) Then + If CveReporte.Contiene(1, 2, 3, 4, 5, 6, 7, 8, 10) Then If ObjGPS.ReportesProgramadosDispositivosGet(CveReporteProgramado) Then DtDispositivos = ObjGPS.DtResultados.Copy() End If @@ -286,7 +351,7 @@ Public Class ClsSisNotificaciones End If ObjGPS.Dispose() - EnviarReporteProgramado(CveCliente, Formato, Correos, FechaI, FechaF, CveReporte, CveNotificacionBitacora, DtDispositivos, DtExtras) + EnviarReporteProgramado(CveCliente, NombreCliente, Formato, Correos, FechaI, FechaF, CveReporte, CveNotificacionBitacora, DtDispositivos, DtExtras, UsuarioActual) If DtExtras IsNot Nothing Then DtExtras.Clear() @@ -297,6 +362,10 @@ Public Class ClsSisNotificaciones DtDispositivos.Clear() DtDispositivos.Dispose() End If + + If UsuarioActual IsNot Nothing Then + UsuarioActual = Nothing + End If Next Catch ex As Exception OnError("Ocurrió un error al enviar el reporte programado", ex) @@ -311,11 +380,12 @@ Public Class ClsSisNotificaciones ' Return New DataTable() 'End Function - Public Sub EnviarReporteProgramado(CveCliente As Integer, Formato As String, Correos As String, FechaI As DateTime, FechaF As DateTime, CveReporte As Integer, CveNotificacionBitacora As Integer, DtDispositivos As DataTable, DtExtras As DataTable) + Public Sub EnviarReporteProgramado(CveCliente As Integer, NombreCliente As String, Formato As String, Correos As String, FechaI As DateTime, FechaF As DateTime, CveReporte As Integer, CveNotificacionBitacora As Integer, DtDispositivos As DataTable, DtExtras As DataTable, UsuarioActual As Usuario) Dim CveDispositivo As Integer = -1 Dim NombreVehiculo As String = "" Dim RutaReporte As String Dim retorno As Byte() = Nothing + Select Case CveReporte Case 1 'Ultima Posicion Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail) @@ -397,7 +467,7 @@ Public Class ClsSisNotificaciones GuardaLog(String.Format("Ocurrio un error al obtener las direcciones {0}", ex)) End Try If Formato = "PDF" Then - retorno = GenerarReporteHistorico(ObjGPS.DtResultados, RutaReporte, FechaI, FechaF, Correos, NombreReporte) + retorno = GenerarReporteHistorico(ObjGPS.DtResultados, RutaReporte, FechaI, FechaF, Correos, NombreReporte, NombreCliente, UsuarioActual) ElseIf Formato = "Excel" Then ObjGPS.DtResultados.TableName = NombreVehiculo DataSource.Tables.Add(ObjGPS.DtResultados) @@ -496,7 +566,7 @@ Public Class ClsSisNotificaciones Next Dim NombreArchivo As String = "" If Formato = "Excel" Then - retorno = GenerarReporteEventosExcel(ObjGPS.DtResultados, FechaI, FechaF, Correos) + retorno = GenerarReporteEventosExcel(DtDispositivos, ObjGPS.DtResultados, FechaI, FechaF, Correos) NombreArchivo = "ReporteEventos.xlsx" ElseIf Formato = "PDF" Then retorno = GenerarReporteEventos(ObjGPS.DtResultados, RutaReporte, FechaI, FechaF, Correos) @@ -642,96 +712,162 @@ Public Class ClsSisNotificaciones Catch ex As Exception GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex)) End Try + ObjGPS.Dispose() + 'Case 8 ' Subida/Bajada de Pasajeros + ' Dim PasajerosEntrada, PasajerosSalida, Ascensos, Descensos As Integer + ' PasajerosSalida = 0 + ' PasajerosEntrada = 0 + ' Ascensos = 0 + ' Descensos = 0 + + ' If GetCambioPasajeros(RowNotificacion("Valor").ToString.ToEntero, RowNotificacion("CveDispositivoGPS").ToString.ToEntero, RowNotificacion("CveUsuario")) Then + ' If DtResultados.Rows.Count > 0 Then + ' Dim ObjMail As New ClsSisMail() + ' Dim SBuilder As New StringBuilder + ' SBuilder.Append($"
") + ' SBuilder.Append($"
Reporte de pasajeros del dispositivo {DtResultados(0)("NoEconomico").ToString}.
") + ' SBuilder.Append($"
") + ' For Each row In DtResultados.Rows + ' If row("CveEvento").ToString.ToEntero = 103 Then + ' PasajerosEntrada = row("Pasajeros") + ' Ascensos = row("Ascensos").ToString.ToEntero + ' Descensos = row("Descensos").ToString.ToEntero + ' SBuilder.Append($"") + ' Else + ' PasajerosSalida = row("Pasajeros") + PasajerosEntrada + ' Ascensos = row("Ascensos").ToString.ToEntero + ' Descensos = row("Descensos").ToString.ToEntero + ' SBuilder.Append($"") + ' End If + ' Next + ' If PasajerosEntrada <> PasajerosSalida Then + ' SBuilder.Append($"Hubo un {If(PasajerosSalida > PasajerosEntrada, "aumento", "decremento")} de {PasajerosSalida - PasajerosEntrada} pasajeros ({Ascensos} ascenso(s), {Descensos} descenso(s)) ") + ' Else + ' SBuilder.Append($"No hubo cambios en el número de pasajeros ") + ' End If + ' SBuilder.Append($"
Fecha: {row("FechaEvento").ToString}   {row("Evento").ToString} '{row("GeoReferencia").ToString}'   Pasajeros: {row("Pasajeros")}
Fecha: {row("FechaEvento").ToString}   {row("Evento").ToString} '{row("GeoReferencia").ToString}'   Pasajeros: {PasajerosSalida}
") + + ' Dim ResultadoMail As Integer = 0 + + ' If ObjMail.SendMail(ClsPaginas.EmpresaNotificaciones, DtResultados(0)("Correo").ToString, $"Reporte de pasajeros. Geocerca {DtResultados(0)("GeoReferencia").ToString}", SBuilder.ToString) Then + ' UpdateNotificacionesBitacoraNotifico(CveNotificacionBitacora, 1) + ' End If + ' End If + ' End If + 'Case 9 'Reporte de Rutas + ' If ArmarReporteProgramadoParadas(CveNotificacionBitacora) AndAlso DtResultados.Rows.Count > 0 Then + ' RutaReporte = "Empresas/Grales/ReportesProgramados/RPTParadas.rdlc" + ' Dim ObjEmpresa As New ClsSisEmpresas() + ' Dim ObjGPS As New ClsGPS + ' Try + ' Dim RowParada As DataRow = DtResultados.Rows(0) + + ' Dim RptParametro As List(Of ReportParameter) = New List(Of ReportParameter) + + + ' If ObjGPS.GetRepParadas(RowParada("CveGrupo").ToString.ToEntero, RowParada("FechaInicio").ToString.ToDateTime, RowParada("FechaNotificacion").ToString.ToDateTime, RowParada("CveCliente").ToString.ToEntero) Then + ' If ObjGPS.DtResultados.Rows.Count > 0 Then + + ' RptParametro.Add(New ReportParameter("FechaInicio", RowParada("FechaInicio").ToString)) + ' RptParametro.Add(New ReportParameter("FechaFin", RowParada("FechaNotificacion").ToString)) + ' RptParametro.Add(New ReportParameter("UsuarioImprimio", RowParada("UsuarioImprimio").ToString)) + ' RptParametro.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString)) + ' RptParametro.Add(New ReportParameter("Grupo", RowParada("Grupo").ToString)) + + ' Dim RowRep As DataRow = ObjGPS.DtResultados.FiltroPrimero("TipoColumna=1") + ' Dim MejorC As String = ObjGPS.DtResultados.FiltroPrimeroValor("Conductor", "CveConductor IS NOT NULL AND TotalEventos IS NOT NULL", "TotalEventos ASC") + ' RptParametro.Add(New ReportParameter("TotalGeneral", RowRep("Importe").ToString.ToDecimal)) + ' RptParametro.Add(New ReportParameter("NumEventos", RowRep("TotalEventos").ToString.ToEntero)) + ' RptParametro.Add(New ReportParameter("MejorConductor", MejorC)) + ' retorno = StreamPDF(RutaReporte, ObjGPS.DtResultados, RptParametro, "ReporteProgramado", "PDF", MR:=Nothing, RDSName:="DsOC") + ' End If + + ' End If + + ' Dim ObjMail As New ClsSisMail() + + ' Dim ResultadoMail As Integer = 0 + ' Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail) + ' LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = retorno, .NombreArchivo = "ReporteProgramado.pdf"}) + + ' If ObjMail.SendMail(ClsPaginas.EmpresaNotificaciones, DtResultados(0)("Correos").ToString, $"Reporte Programado {Date.Today.ToShortDateString}", "Se adjunta en pdf el Reporte Programado.", "", LSRutasMail) Then + ' UpdateNotificacionesBitacoraNotifico(CveNotificacionBitacora, 1) + ' End If + + ' Catch ex As Exception + ' GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex)) + ' End Try + ' ObjGPS.Dispose() + ' End If + Case 10 'Reporte de Ignicion + Dim ObjGPS As New ClsGPS + Try + RutaReporte = $"{ModExtensiones.DirectorioBaseEmpresas}/Empresas/Grales/ReportesProgramados/RPIgnicion.rdlc" + Dim ObjMail As New ClsSisMail() + Dim ResultadoMail As Integer = 0 + Dim Archivos As New List(Of ClsSisMail.ArchivoMail) + Dim NombreReporte As String = "Reporte" + Dim DataSource As DataSet = Nothing + + If Formato = "Excel" Then + DataSource = New DataSet() + End If + + For Each RowDisp As DataRow In DtDispositivos.Rows + CveDispositivo = RowDisp("CveDispositivo").ToString().ToEntero + NombreVehiculo = RowDisp("NombreVehiculo").ToString() + NombreReporte = $"Reporte_Ignicion_{NombreVehiculo}_{FechaI.ToString("yyyy_MM_dd_HH_mm_ss")}_{ FechaF.ToString("yyyy_MM_dd_HH_mm_ss")}" + + Dim DireccionesInicial As JArray = Nothing, DireccionesFinal As JArray = Nothing + + If ObjGPS.GetRepIgnicion(CveDispositivo, FechaI, FechaF, CveCliente) Then + Try + DireccionesInicial = ConsultarDireccionesIgnicion(ObjGPS.DtResultados, "CveTramaEncendido", "LatitudInicial", "LongitudInicial") + DireccionesFinal = ConsultarDireccionesIgnicion(ObjGPS.DtResultados, "CveTramaApagado", "LatitudFinal", "LongitudFinal") + + For Each Dir As JObject In DireccionesInicial + ObjGPS.DtResultados.Rows(Dir("Indice").ToEntero())("DireccionInical") = Dir("Direccion").ToString() + Next + + For Each Dir As JObject In DireccionesFinal + ObjGPS.DtResultados.Rows(Dir("Indice").ToEntero())("DireccionFinal") = Dir("Direccion").ToString() + Next + Catch ex As Exception + GuardaLog(String.Format("Ocurrio un error al obtener las direcciones {0}", ex)) + End Try + If Formato = "PDF" Then + retorno = GenerarReporteIgnicion(ObjGPS.DtResultados, RutaReporte, FechaI, FechaF, Correos, NombreReporte) + ElseIf Formato = "Excel" Then + ObjGPS.DtResultados.TableName = NombreVehiculo + DataSource.Tables.Add(ObjGPS.DtResultados) + End If + End If + + If retorno IsNot Nothing Then + Archivos.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = retorno, .NombreArchivo = $"{NombreReporte}.pdf"}) + End If + Next + + If DataSource IsNot Nothing Then + NombreReporte = $"Reporte_Ignicion_{FechaI.ToString("yyyy_MM_dd_HH_mm_ss")}_{ FechaF.ToString("yyyy_MM_dd_HH_mm_ss")}" + retorno = GenerarReporteIgnicionExcel(DataSource, RutaReporte, FechaI, FechaF, Correos, NombreReporte) + If retorno IsNot Nothing Then + Archivos.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = retorno, .NombreArchivo = $"{NombreReporte}.xlsx"}) + End If + End If + + If Archivos.Count > 0 Then + If ObjMail.SendMail(ClsPaginas.EmpresaNotificacionesGPS, Correos, $"Reporte Programado {Date.Today.ToShortDateString}", $"Se adjunta el {Formato} en el Reporte Programado.", "", Archivos) Then + UpdateNotificacionesBitacoraNotifico(CveNotificacionBitacora, 1) + End If + End If + Catch ex As Exception + GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex)) + End Try ObjGPS.Dispose() - 'Case 8 ' Subida/Bajada de Pasajeros - ' Dim PasajerosEntrada, PasajerosSalida, Ascensos, Descensos As Integer - ' PasajerosSalida = 0 - ' PasajerosEntrada = 0 - ' Ascensos = 0 - ' Descensos = 0 - - ' If GetCambioPasajeros(RowNotificacion("Valor").ToString.ToEntero, RowNotificacion("CveDispositivoGPS").ToString.ToEntero, RowNotificacion("CveUsuario")) Then - ' If DtResultados.Rows.Count > 0 Then - ' Dim ObjMail As New ClsSisMail() - ' Dim SBuilder As New StringBuilder - ' SBuilder.Append($"
") - ' SBuilder.Append($"
Reporte de pasajeros del dispositivo {DtResultados(0)("NoEconomico").ToString}.
") - ' SBuilder.Append($"
") - ' For Each row In DtResultados.Rows - ' If row("CveEvento").ToString.ToEntero = 103 Then - ' PasajerosEntrada = row("Pasajeros") - ' Ascensos = row("Ascensos").ToString.ToEntero - ' Descensos = row("Descensos").ToString.ToEntero - ' SBuilder.Append($"") - ' Else - ' PasajerosSalida = row("Pasajeros") + PasajerosEntrada - ' Ascensos = row("Ascensos").ToString.ToEntero - ' Descensos = row("Descensos").ToString.ToEntero - ' SBuilder.Append($"") - ' End If - ' Next - ' If PasajerosEntrada <> PasajerosSalida Then - ' SBuilder.Append($"Hubo un {If(PasajerosSalida > PasajerosEntrada, "aumento", "decremento")} de {PasajerosSalida - PasajerosEntrada} pasajeros ({Ascensos} ascenso(s), {Descensos} descenso(s)) ") - ' Else - ' SBuilder.Append($"No hubo cambios en el número de pasajeros ") - ' End If - ' SBuilder.Append($"
Fecha: {row("FechaEvento").ToString}   {row("Evento").ToString} '{row("GeoReferencia").ToString}'   Pasajeros: {row("Pasajeros")}
Fecha: {row("FechaEvento").ToString}   {row("Evento").ToString} '{row("GeoReferencia").ToString}'   Pasajeros: {PasajerosSalida}
") - - ' Dim ResultadoMail As Integer = 0 - - ' If ObjMail.SendMail(ClsPaginas.EmpresaNotificaciones, DtResultados(0)("Correo").ToString, $"Reporte de pasajeros. Geocerca {DtResultados(0)("GeoReferencia").ToString}", SBuilder.ToString) Then - ' UpdateNotificacionesBitacoraNotifico(CveNotificacionBitacora, 1) - ' End If - ' End If - ' End If - 'Case 9 'Reporte de Rutas - ' If ArmarReporteProgramadoParadas(CveNotificacionBitacora) AndAlso DtResultados.Rows.Count > 0 Then - ' RutaReporte = "Empresas/Grales/ReportesProgramados/RPTParadas.rdlc" - ' Dim ObjEmpresa As New ClsSisEmpresas() - ' Dim ObjGPS As New ClsGPS - ' Try - ' Dim RowParada As DataRow = DtResultados.Rows(0) - - ' Dim RptParametro As List(Of ReportParameter) = New List(Of ReportParameter) - - - ' If ObjGPS.GetRepParadas(RowParada("CveGrupo").ToString.ToEntero, RowParada("FechaInicio").ToString.ToDateTime, RowParada("FechaNotificacion").ToString.ToDateTime, RowParada("CveCliente").ToString.ToEntero) Then - ' If ObjGPS.DtResultados.Rows.Count > 0 Then - - ' RptParametro.Add(New ReportParameter("FechaInicio", RowParada("FechaInicio").ToString)) - ' RptParametro.Add(New ReportParameter("FechaFin", RowParada("FechaNotificacion").ToString)) - ' RptParametro.Add(New ReportParameter("UsuarioImprimio", RowParada("UsuarioImprimio").ToString)) - ' RptParametro.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString)) - ' RptParametro.Add(New ReportParameter("Grupo", RowParada("Grupo").ToString)) - - ' Dim RowRep As DataRow = ObjGPS.DtResultados.FiltroPrimero("TipoColumna=1") - ' Dim MejorC As String = ObjGPS.DtResultados.FiltroPrimeroValor("Conductor", "CveConductor IS NOT NULL AND TotalEventos IS NOT NULL", "TotalEventos ASC") - ' RptParametro.Add(New ReportParameter("TotalGeneral", RowRep("Importe").ToString.ToDecimal)) - ' RptParametro.Add(New ReportParameter("NumEventos", RowRep("TotalEventos").ToString.ToEntero)) - ' RptParametro.Add(New ReportParameter("MejorConductor", MejorC)) - ' retorno = StreamPDF(RutaReporte, ObjGPS.DtResultados, RptParametro, "ReporteProgramado", "PDF", MR:=Nothing, RDSName:="DsOC") - ' End If - - ' End If - - ' Dim ObjMail As New ClsSisMail() - - ' Dim ResultadoMail As Integer = 0 - ' Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail) - ' LSRutasMail.Add(New ClsSisMail.ArchivoMail With {.ArchivoBinario = retorno, .NombreArchivo = "ReporteProgramado.pdf"}) - - ' If ObjMail.SendMail(ClsPaginas.EmpresaNotificaciones, DtResultados(0)("Correos").ToString, $"Reporte Programado {Date.Today.ToShortDateString}", "Se adjunta en pdf el Reporte Programado.", "", LSRutasMail) Then - ' UpdateNotificacionesBitacoraNotifico(CveNotificacionBitacora, 1) - ' End If - - ' Catch ex As Exception - ' GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex)) - ' End Try - ' ObjGPS.Dispose() - ' End If End Select - End Sub - + End Sub + #Region "G E N E R A R - R E P O R T E" Private Function GenerarReporteUltimaPosicion(DataSource As DataTable, Liga As String, FechaI As DateTime, FechaF As DateTime, Correos As String) As Byte() Dim Retorno As Byte() = Nothing @@ -785,10 +921,15 @@ Public Class ClsSisNotificaciones Return Retorno.ToArray() End Function - Private Function GenerarReporteHistorico(DataSource As DataTable, Liga As String, FechaI As DateTime, FechaF As DateTime, Correos As String, NombreReporte As String) As Byte() + Private Function GenerarReporteHistorico(DataSource As DataTable, Liga As String, FechaI As DateTime, FechaF As DateTime, Correos As String, NombreReporte As String, NombreCliente As String, UsuarioActual As Usuario) As Byte() Dim Retorno As Byte() = Nothing Try Dim RptParametro As New List(Of CrystalParametro) + + Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port, UsuarioActual.CveEmpresa) + + Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta)) + RptParametro.Add(New CrystalParametro("FechaInicio", FechaI.ToString)) RptParametro.Add(New CrystalParametro("FechaFin", FechaF.ToString)) RptParametro.Add(New CrystalParametro("UsuarioImprimio", Correos)) @@ -797,7 +938,16 @@ Public Class ClsSisNotificaciones RptParametro.Add(New CrystalParametro("KMRecorridos", $"{DataSource.Rows(0)("KMRecorridos")} KM")) Else RptParametro.Add(New CrystalParametro("KMRecorridos", "0 KM")) + End If + + RptParametro.Add(New CrystalParametro("NombreEmpresa", NombreCliente)) + + If Imagen.Exists Then + RptParametro.Add(New CrystalParametro("LogoPath", logouri)) + Else + RptParametro.Add(New CrystalParametro("LogoPath", "")) End If + Retorno = StreamPDFCrystal(Liga, DataSource, RptParametro, NombreReporte, "PDF") Catch ex As Exception GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex)) @@ -855,7 +1005,82 @@ Public Class ClsSisNotificaciones DataSet.Dispose() End If Return Retorno.ToArray() + End Function + + Private Function GenerarReporteIgnicion(DataSource As DataTable, Liga As String, FechaI As DateTime, FechaF As DateTime, Correos As String, NombreReporte As String) As Byte() + Dim Retorno As Byte() = Nothing + Try + Dim RptParametro As New List(Of ReportParameter) + + RptParametro.Add(New ReportParameter("FechaInicio", FechaI.ToString)) + RptParametro.Add(New ReportParameter("FechaFin", FechaF.ToString)) + RptParametro.Add(New ReportParameter("UsuarioImprimio", Correos)) + RptParametro.Add(New ReportParameter("FechaImpresion", DateTime.Now.ToShortDateString)) + + Retorno = StreamPDF(Liga, DataSource, RptParametro, "ReporteIgnicion", "PDF", MR:=Nothing, RDSName:="DsOC") + Catch ex As Exception + GuardaLog(String.Format("Ocurrio un error al generar el reporte RLDC {0}", ex)) + End Try + Return Retorno End Function + + Private Function GenerarReporteIgnicionExcel(DataSource As DataSet, Liga As String, FechaI As DateTime, FechaF As DateTime, Correos As String, NombreReporte As String) As Byte() + Dim Retorno As New MemoryStream() + SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) + + Dim FileExcel As ExcelFile = New ExcelFile + For Each Dt As DataTable In DataSource.Tables + + Dt.Columns.Remove("CveDispositivo") + Dt.Columns.Remove("CveTramaEncendido") + Dt.Columns.Remove("CveTramaApagado") + + Dt.Columns("Vehiculo").SetOrdinal(0) + Dt.Columns("Vehiculo").ColumnName = "Vehículo" + + Dt.Columns("VMedia").ColumnName = "Velocidad Media" + Dt.Columns("VMax").ColumnName = "Velocidad Maxima" + + Dt.Columns("FechaEncendido").ColumnName = "Fecha Encendido" + Dt.Columns("FechaApagado").ColumnName = "Fecha Apagado" + Dt.Columns("LatitudInicial").ColumnName = "Latitud Inicial" + Dt.Columns("LatitudFinal").ColumnName = "Latitud Final" + + Dt.Columns("LongitudInicial").ColumnName = "Longitud Inicial" + Dt.Columns("LongitudFinal").ColumnName = "Longitud Final" + + Dt.Columns("Duracion").ColumnName = "Duración" + + Dt.Columns("DireccionInical").SetOrdinal(Dt.Columns.Count - 1) + Dt.Columns("DireccionInical").ColumnName = "Dirección Inicial" + + Dt.Columns("DireccionFinal").SetOrdinal(Dt.Columns.Count - 1) + Dt.Columns("DireccionFinal").ColumnName = "Dirección Final" + + Dim item = FileExcel.Worksheets.Add(Dt.TableName) + item.InsertDataTable(Dt, New InsertDataTableOptions() With + { + .ColumnHeaders = True, + .StartRow = 0, + .StartColumn = 0 + }) + item.Rows(0).Style.FillPattern.SetPattern(FillPatternStyle.Solid, SpreadsheetColor.FromArgb(75, 119, 190), SpreadsheetColor.FromArgb(255, 255, 255)) + item.Rows(0).Style.Font.Color = SpreadsheetColor.FromArgb(255, 255, 255) + + Dim columnCount = item.CalculateMaxUsedColumns() + For i = 0 To columnCount + item.Columns(i).AutoFit(1, item.Rows(i), item.Rows(item.Rows.Count - 1)) + Next + + Next + FileExcel.Save(Retorno, SaveOptions.XlsxDefault) + If DataSet IsNot Nothing Then + DataSet.Clear() + DataSet.Dispose() + End If + Return Retorno.ToArray() + End Function + Private Function GenerarReporteTiempoMuerto(DataSource As DataTable, Liga As String, FechaI As DateTime, FechaF As DateTime, Correos As String, NombreReporte As String) As Byte() Dim Retorno As Byte() = Nothing Try @@ -953,7 +1178,7 @@ Public Class ClsSisNotificaciones End Function Private Function GenerarReporteEventos(DataSource As DataTable, Liga As String, FechaI As DateTime, FechaF As DateTime, Correos As String) As Byte() Dim Retorno As Byte() = Nothing - If DataSource IsNot Nothing AndAlso DataSource.Rows.Count > 0 Then + If DataSource IsNot Nothing Then Try Dim RptParametro As New List(Of CrystalParametro) RptParametro.Add(New CrystalParametro("FechaInicio", FechaI.ToString)) @@ -970,15 +1195,16 @@ Public Class ClsSisNotificaciones End If Return Retorno End Function - Private Function GenerarReporteEventosExcel(DataSource As DataTable, FechaI As DateTime, FechaF As DateTime, Correos As String) As Byte() + Private Function GenerarReporteEventosExcel(DtDispositivos As DataTable, DataSource As DataTable, FechaI As DateTime, FechaF As DateTime, Correos As String) As Byte() Dim Retorno As New MemoryStream() SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) Dim FileExcel As ExcelFile = New ExcelFile - Dim DtDispositivos As DataTable = DataSource.FiltraParametros("", "", {"CveDispositivo", "Unidad"}) + 'Dim DtDispositivos As DataTable = DataSource.FiltraParametros("", "", {"CveDispositivo", "Unidad"}) + For Each Dr As DataRow In DtDispositivos.Rows Dim CveDispositivo As Integer = Dr("CveDispositivo").ToString().ToEntero() - Dim NombreVehiculo = Dr("Unidad").ToString() + Dim NombreVehiculo = Dr("NombreVehiculo").ToString() Dim FilterRows = DataSource.FiltraParametros($"CveDispositivo = {CveDispositivo}") Dim Dt = GenerarDTEventos(NombreVehiculo, FilterRows) @@ -1209,18 +1435,21 @@ Public Class ClsSisNotificaciones dt.Columns.Add("Conductor", Type.GetType("System.String")) dt.Columns.Add("Dirección", Type.GetType("System.String")) - For Each Row As DataRow In rows.Rows - Dim dr = dt.NewRow() - dr("Vehículo") = Row("Unidad").ToString() - dr("Fecha") = Row("Fecha").ToString().ToDateTime() - dr("Evento") = Row("Evento").ToString() - dr("Latitud") = Row("Lat").ToString().ToDouble() - dr("Longitud") = Row("Lon").ToString().ToDouble() - dr("Conductor") = Row("Conductor").ToString() - dr("Dirección") = Row("Direccion").ToString() + If rows IsNot Nothing Then + For Each Row As DataRow In rows.Rows + Dim dr = dt.NewRow() + dr("Vehículo") = Row("Unidad").ToString() + dr("Fecha") = Row("Fecha").ToString().ToDateTime() + dr("Evento") = Row("Evento").ToString() + dr("Latitud") = Row("Lat").ToString().ToDouble() + dr("Longitud") = Row("Lon").ToString().ToDouble() + dr("Conductor") = Row("Conductor").ToString() + dr("Dirección") = Row("Direccion").ToString() + + dt.Rows.Add(dr) + Next + End If - dt.Rows.Add(dr) - Next Return dt End Function @@ -2057,10 +2286,45 @@ Public Class ClsSisNotificaciones End Try End Using Return retorno - End Function + End Function + + Public Function ConsultarDireccionesIgnicion(Dt As DataTable, StrCveTrama As String, StrLatitud As String, StrLongitud As String) As JArray + Dim retorno As JArray = Nothing + Dim posicionesArray = New JArray(From Row As DataRow In Dt + Let index = Dt.Rows().IndexOf(Row) + Select New JObject( + New JProperty("indice", index), + New JProperty("cveTrama", Row(StrCveTrama).ToString.ToEntero), + New JProperty("lat", Row(StrLatitud).ToString.ToDouble), + New JProperty("lon", Row(StrLongitud).ToString.ToDouble) + )) + Dim Base64array = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(posicionesArray.ToString())) + + Using wc As New HttpClient() + Try + Dim Url = New Uri(String.Format("{0}nominatim/reverseMultiple.php", ClsPaginas.UrlDirecciones)) + Dim FormStuff = String.Format("formato=json&posiciones={0}", Base64array) + Dim content = New StringContent(FormStuff, Encoding.UTF8, "application/x-www-form-urlencoded") + Dim response = wc.PostAsync(Url, content).Result + Dim result = response.Content.ReadAsStringAsync().Result + retorno = JArray.Parse(result) + response.Dispose() + content = Nothing + Url = Nothing + FormStuff = Nothing + Catch ex As Exception + OnError("Ocurrió un error al obtener las direcciones", ex) + End Try + End Using + Return retorno + End Function + + + + #Region " IDisposable Support " - ' IDisposable + ' IDisposable Protected Overridable Sub Dispose(disposing As Boolean) If Not Me.disposedValue Then If disposing Then