protected void Page_Load(object sender, EventArgs e) { string cultura = Thread.CurrentThread.CurrentCulture.Name; HttpCookie cookieCultura = Request.Cookies.Get("Cultura"); string metrica= cookieCultura.Values.Get("Metric"); //validamos si hay queryString if (Request.QueryString["sTipoReporte"] != null) { string tipoReporte = Request.QueryString["sTipoReporte"]; //reporte de geocercas #region ReporteGeocerca if (tipoReporte == REPORTE_GEOCERCA) { //Obtenemos valores de la url string fInicial = Request.QueryString["fInicial"]; string fFinal = Request.QueryString["fFinal"]; string aUnidades = Request.QueryString["aUnidades"]; string aGeocercas = Request.QueryString["aGeocercas"]; string sAccion = Request.QueryString["sAccion"]; int zona = Int32.Parse(Request.QueryString["zona"]); //asignamos a las variables indicadas los valores obtenidos Int64 fechaInicial = Int64.Parse(fInicial); Int64 fechaFinal = Int64.Parse(fFinal); int accion = int.Parse(sAccion); List<string> unidades = aUnidades.Split(',').ToList(); List<string> geocercas = aGeocercas.Split(',').ToList(); MemoryStream ms = new MemoryStream(File.ReadAllBytes(HttpContext.Current.Server.MapPath(string.Format("Reportes/{0}/{1}.xlsx", cultura, "ReporteGeocercas")))); //obtener geocercas ... HttpCookie Cookie = HttpContext.Current.Request.Cookies.Get("Usuario"); string cliente = new Codificador().Desencriptar(Cookie.Values.Get("Cliente")); DateTime fi = Util.FromUnixMilis(fechaInicial); DateTime ff = Util.FromUnixMilis(fechaFinal); List<ReporteNotificacionGeocerca> reporte = ReportesBD.ObtenerNotificacionesGeocerca(unidades, geocercas, fi, ff, accion, cliente); reporte.ForEach(b => { b.Fecha = b.Fecha.AddHours(zona);b.Accion = (b.iAccion== ReporteNotificacionGeocerca.AccionDentro)?Resources.Reportes.aspx.Dentro:Resources.Reportes.aspx.Fuera; }); byte[] reporteBytes = ReportesExcel.ReporteNotificacionGeocerca(fi, ff, reporte, ms, metrica); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheEt"; Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xlsx", Resources.Mapa.aspx.ReportesDeGeocercas)); Response.AddHeader("Content-Length", reporteBytes.Length.ToString()); Response.BinaryWrite(reporteBytes); } #endregion #region ReporteDistancia else if (tipoReporte == REPORTE_DISTANCIA) { //Obtenemos los valores del string .. string fInicial = Request.QueryString["fInicial"]; string fFinal = Request.QueryString["fFinal"]; string aUnidades = Request.QueryString["aUnidades"]; string aGeocercas = Request.QueryString["aGeocercas"]; string geocercaBase = Request.QueryString["geocercaBase"]; int zona = Int32.Parse(Request.QueryString["zona"]); //parsear los valores obtenidos con anterioridad Int64 fechaInicial = Int64.Parse(fInicial); Int64 fechaFinal = Int64.Parse(fFinal); List<string> unidades = aUnidades.Split(',').ToList(); List<string> geocercas = aGeocercas.Split(',').ToList(); //obtener las geocercas que visito la unidad, empezando con una salida, luego encontrando una entrada string timezoneBD = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(b => b.BaseUtcOffset.Hours == -10).Id; string timezoneCliente = TimeZoneInfo.GetSystemTimeZones().FirstOrDefault(b => b.BaseUtcOffset.Hours == zona).Id; HttpCookie Cookie = HttpContext.Current.Request.Cookies.Get("Usuario"); string cliente = new Codificador().Desencriptar(Cookie.Values.Get("Cliente")); DateTime fi = Util.FromUnixMilis(fechaInicial); DateTime ff = Util.FromUnixMilis(fechaFinal); int accion = SistemaRastreoWeb.ReporteNotificacionGeocerca.AccionDentroFuera; List<ReporteNotificacionGeocerca> reporte = ReportesBD.ObtenerNotificacionesGeocerca(unidades, geocercas, fi, ff, accion, cliente); List<VehiculoGeocercas> vehiculosConNotificaciones = new List<VehiculoGeocercas>(); List<ReporteViajesEntreGeocerca> viajes = new List<ReporteViajesEntreGeocerca>(); //guardar en lista de vehiculos con notificaciones las unidades que tengan notificaciones de geocercas.. foreach (string unidad in unidades) { //obtenemos reportes de notificaciones de geocercas List<ReporteNotificacionGeocerca> seleccionReportes = reporte.Where(x => x.VehiculoID.Equals(unidad)).ToList(); if (seleccionReportes.Count > 0) { //obtener las fechas correctas de la notificacion de geocerca seleccionReportes.ForEach(b => b.Fecha = b.Fecha.AddHours(zona)); //obtener historico de la unidad Historico historico = RastreoEstaticoBD.Historico(cliente, unidad, fi, ff); historico.Ubicaciones.ForEach(b => b.Fecha = b.Fecha.AddHours(zona)); historico = Historico.CalcularResumenReporte(historico, Util.GetValorCookie(HttpContext.Current, "Cultura", "Metric") != "Km"); historico.Ubicaciones = historico.Resumidas; bool bViajeExistente = false; ReporteViajesEntreGeocerca viaje = new ReporteViajesEntreGeocerca(); foreach (ReporteNotificacionGeocerca reporteNotificacion in seleccionReportes) { if (!bViajeExistente && reporteNotificacion.iAccion == SistemaRastreoWeb.ReporteNotificacionGeocerca.AccionFuera) { viaje.FechaSalida = reporteNotificacion.Fecha; viaje.GeocercaSalidaID = reporteNotificacion.GeocercaID; viaje.GeocercaSalida = reporteNotificacion.Geocerca; bViajeExistente = true; } else if (bViajeExistente && reporteNotificacion.iAccion == SistemaRastreoWeb.ReporteNotificacionGeocerca.AccionDentro) { viaje.FechaEntrada = reporteNotificacion.Fecha; viaje.GeocercaEntradaID = reporteNotificacion.GeocercaID; viaje.Vehiculo = reporteNotificacion.Vehiculo; viaje.GeocercaEntrada = reporteNotificacion.Geocerca; bViajeExistente = false; List<Ubicacion> ubiEntradas = historico.Ubicaciones.Where(x => x.Fecha.Equals(viaje.FechaEntrada)).ToList(); List<Ubicacion> ubiSalidas = historico.Ubicaciones.Where(x => x.Fecha.Equals(viaje.FechaSalida)).ToList(); if (ubiEntradas.Count > 0 && ubiSalidas.Count > 0) { Ubicacion ubiEntrada = ubiEntradas[0]; Ubicacion ubiSalida = ubiSalidas[0]; TimeSpan tiempo = ubiEntrada.Fecha - ubiSalida.Fecha; double distancia = ubiEntrada.DistanciaEntrePuntoInicial - ubiSalida.DistanciaEntrePuntoInicial; viaje.Distancia = Math.Ceiling(distancia); viaje.Tiempo = tiempo; if (geocercaBase != "0") { if (viaje.GeocercaEntradaID == geocercaBase || viaje.GeocercaSalidaID == geocercaBase) { viajes.Add(viaje); } } else { viajes.Add(viaje); } } viaje = new ReporteViajesEntreGeocerca(); } } } } MemoryStream ms = new MemoryStream(File.ReadAllBytes(HttpContext.Current.Server.MapPath(string.Format("Reportes/{0}/{1}.xlsx", cultura, "ReporteGeocercaTrip")))); byte[] reporteBytes = ReportesExcel.ReporteNotificacionGeocercaTrip(fi, ff, viajes, ms, metrica); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheEt"; Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xlsx", Resources.Mapa.aspx.ReporteDistanciaGeocercas)); Response.AddHeader("Content-Length", reporteBytes.Length.ToString()); Response.BinaryWrite(reporteBytes); } #endregion } else { } }
public string ReporteViajeEntreGeocercas(List<string> unidades, List<string> geocercas, long fechaInicial, long fechaFinal, string geocercaBase) { HttpCookie Cookie = HttpContext.Current.Request.Cookies.Get("Usuario"); if (Cookie != null && AutentificacionBD.VerificarToken(Cookie.Values.Get("Token"))) { string cliente = new Codificador().Desencriptar(Cookie.Values.Get("Cliente")); DateTime fInicial = Util.FromUnixMilis(fechaInicial); DateTime fFinal = Util.FromUnixMilis(fechaFinal); int accion = SistemaRastreoWeb.ReporteNotificacionGeocerca.AccionDentroFuera; List<ReporteNotificacionGeocerca> reporte = ReportesBD.ObtenerNotificacionesGeocerca(unidades, geocercas, fInicial, fFinal, accion, cliente); List<VehiculoGeocercas> vehiculosConNotificaciones= new List<VehiculoGeocercas>(); List<ReporteViajesEntreGeocerca> viajes = new List<ReporteViajesEntreGeocerca>(); //guardar en lista de vehiculos con notificaciones las unidades que tengan notificaciones de geocercas.. foreach (string unidad in unidades) { List<ReporteNotificacionGeocerca> seleccionReportes = reporte.Where(x => x.VehiculoID.Equals(unidad)).ToList(); if (seleccionReportes.Count > 0) { //guardar en lista de unidades que si tienen reportes... VehiculoGeocercas notificaciones = new VehiculoGeocercas(unidad, seleccionReportes); vehiculosConNotificaciones.Add(notificaciones); } } //obtener las geocercas que visito la unidad, empezando con una salida, luego encontrando una entrada foreach (VehiculoGeocercas vehiculoNotificaciones in vehiculosConNotificaciones) { bool bViajeExistente = false; ReporteViajesEntreGeocerca viaje = new ReporteViajesEntreGeocerca(); foreach (ReporteNotificacionGeocerca reporteNotificacion in vehiculoNotificaciones.Reportes) { if (!bViajeExistente && reporteNotificacion.iAccion == SistemaRastreoWeb.ReporteNotificacionGeocerca.AccionFuera) { viaje.GeocercaSalida = reporteNotificacion.Geocerca; viaje.FechaSalida = reporteNotificacion.Fecha; bViajeExistente = true; } else if (bViajeExistente && reporteNotificacion.iAccion == SistemaRastreoWeb.ReporteNotificacionGeocerca.AccionDentro) { viaje.GeocercaEntrada = reporteNotificacion.Geocerca; viaje.FechaEntrada = reporteNotificacion.Fecha; bViajeExistente = false; viajes.Add(viaje); viaje = new ReporteViajesEntreGeocerca(); } } } string json = JsonConvert.SerializeObject(viajes, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore }); return json; } else { return "error404"; } }