public void ShowInfo() { ClearMimico(); var coches = Enumerable.Where <int>(cbVehiculo.SelectedValues, id => id > 0).Select(id => DAOFactory.CocheDAO.FindById(id)).Where(c => c.Dispositivo != null); var totalCoches = coches.Count(); var conServicio = 0; var sinServicio = 0; var enMantenimiento = 0; var enHora = 0; var adelantados = 0; var demorados = 0; var enBase = 0; var enCliente = 0; var ciclos = new List <Ciclo>(); foreach (var coche in coches) { Ciclo ciclo = null; var idBase = 0; var idCoche = coche.Id; var idClientes = new List <int>(); var ticket = DAOFactory.TicketDAO.FindEnCurso(coche.Dispositivo); if (ticket != null) { ciclo = new Ciclo(ticket, DAOFactory); if (ticket.Linea != null && ticket.Linea.ReferenciaGeografica != null) { idBase = ticket.Linea.ReferenciaGeografica.Id; } idClientes.Add(ticket.PuntoEntrega.ReferenciaGeografica.Id); } if (ciclo == null) { var distribucion = DAOFactory.ViajeDistribucionDAO.FindEnCurso(coche); if (distribucion != null) { ciclo = new Ciclo(distribucion, DAOFactory); if (distribucion.Linea != null && distribucion.Linea.ReferenciaGeografica != null) { idBase = distribucion.Linea.ReferenciaGeografica.Id; } idClientes = distribucion.Detalles.Select(d => d.ReferenciaGeografica.Id).ToList(); } } if (ciclo != null) { conServicio++; var dif = ciclo.Diferencia; if (Math.Abs(dif) <= 5) { enHora++; ciclo.Demorado = false; ciclo.Adelantado = false; } else if (dif > 0) { demorados++; ciclo.Demorado = true; ciclo.Adelantado = false; } else { adelantados++; ciclo.Demorado = false; ciclo.Adelantado = true; } ciclos.Add(ciclo); } else { if (coche.Estado == Coche.Estados.EnMantenimiento) { enMantenimiento++; } else { sinServicio++; } } if (idBase > 0) { var state = GeocercaManager.GetEstadoGeocerca(coche, idBase, DAOFactory); if (state != null && state.Estado == EstadosGeocerca.Dentro) { enBase++; if (ciclo != null) { ciclo.EnPlanta = true; ciclo.EnObra = false; } } } if (idClientes.Count > 0) { var withGeo = idClientes.Select(c => GeocercaManager.GetEstadoGeocerca(coche, c, DAOFactory)) .Where(s => s != null); if (withGeo.Any(st => st != null && st.Estado == EstadosGeocerca.Dentro)) { enCliente++; if (ciclo != null) { ciclo.EnObra = true; ciclo.EnPlanta = false; } } } } var sh = new ScriptHelper(this); foreach (var ciclo in ciclos.OrderByDescending(c => c.Completed)) { if (!chkEnCliente.Checked && ciclo.EnObra) { continue; } if (!chkEnPlanta.Checked && ciclo.EnPlanta) { continue; } if (!chkEnViaje.Checked && (!ciclo.EnObra && !ciclo.EnPlanta)) { continue; } if (!chkDemorados.Checked && ciclo.Demorado) { continue; } if (!chkAdelantados.Checked && ciclo.Adelantado) { continue; } if (!chkEnHora.Checked && (!ciclo.Demorado && !ciclo.Adelantado)) { continue; } sh.RegisterStartupScript(string.Format("init_{0}_{1}", ciclo.Tipo, ciclo.Id), ciclo.Render(), true); } lblTotal.Text = totalCoches.ToString(); lblEnServicio.Text = conServicio.ToString(); lblSinServicio.Text = sinServicio.ToString(); lblEnMantenimiento.Text = enMantenimiento.ToString(); lblEnHora.Text = enHora.ToString(); lblAdelantados.Text = adelantados.ToString(); lblDemorados.Text = demorados.ToString(); lblEnPlanta.Text = enBase.ToString(); lblEnCliente.Text = enCliente.ToString(); lblEnViaje.Text = (conServicio - enBase - enCliente).ToString(); }
private void CalcularEstadisticasHoy(Coche coche, IEnumerable <int> idPoiBase) { if ((coche.Dispositivo != null && DAOFactory.TicketDAO.FindEnCurso(coche.Dispositivo) != null) || DAOFactory.ViajeDistribucionDAO.FindEnCurso(coche) != null) { _movilesActivos++; } var ultimaPos = coche.RetrieveLastPosition(); if (ultimaPos != null && ultimaPos.Velocidad > 0) { _movilesEnMovimiento++; } else { _movilesDetenidos++; //var cercas = GeofenceManager.GetGeocercas(coche); var cercasDentro = GeocercaManager.GetEstadoVehiculo(coche, DAOFactory); //var cercasDentro = GeofenceManager.GetGeocercasInside(coche); var maxMonths = coche.Empresa != null ? coche.Empresa.MesesConsultaPosiciones : 3; var entradaEnCerca = ReportFactory.MobileEventDAO.GetMobilesEvents(new List <int> { coche.Id }, new List <int> { _codigoEntrada }, new List <int> { 0 }, _desdeHoy, _hastaHoy, maxMonths); foreach (var cerca in cercasDentro.GeocercasDentro) { if (idPoiBase.Contains(cerca.Geocerca.Id)) { _movilesEnBase++; _detalleBases[cerca.Geocerca.Id] += 1; var ciclo = CicloLogisticoFactory.GetCiclo(coche, null); if (ciclo != null) { _movilesInactivosBase++; } if (entradaEnCerca.Count > 0 && entradaEnCerca[entradaEnCerca.Count - 1].EventTime < DateTime.UtcNow.AddHours(-1)) { _movilesEnBaseMas1Hora++; } } else { _movilesEnGeocerca++; if (entradaEnCerca.Count > 0 && entradaEnCerca[entradaEnCerca.Count - 1].EventTime < DateTime.UtcNow.AddHours(-1)) { _movilesEnGeocercaMas1Hora++; } } } } ///// TICKETS ///// var enServicio = 0; var tickets = DAOFactory.TicketDAO.FindByCocheYFecha(new[] { coche.Empresa != null ? coche.Empresa.Id : coche.Linea != null ? coche.Linea.Empresa.Id : -1 }, new[] { coche.Linea != null ? coche.Linea.Id : -1 }, new[] { coche.Id }, _desdeHoy, _hastaHoy); foreach (var ticket in tickets) { var diferencia = 0; var ultimoEstado = ticket.Detalles.Cast <DetalleTicket>() .Where(d => d.Automatico.HasValue) .LastOrDefault(); if (ultimoEstado != null) { diferencia = Convert.ToInt32(ultimoEstado.Automatico.Value.Subtract(ultimoEstado.Programado.Value).TotalMinutes); } if (Math.Abs(diferencia) <= 5) { _movilesEnHoraHoy++; } else if (diferencia > 0) { _movilesDemoradosHoy++; } else { _movilesAdelantadosHoy++; } if (ticket.Estado == Ticket.Estados.EnCurso && ticket.FechaTicket < DateTime.UtcNow) { enServicio++; var idBase = 0; var idClientes = new List <int>(); if (ticket.Linea != null && ticket.Linea.ReferenciaGeografica != null) { idBase = ticket.Linea.ReferenciaGeografica.Id; } idClientes.Add(ticket.PuntoEntrega.ReferenciaGeografica.Id); if (idBase > 0) { var state = GeocercaManager.GetEstadoGeocerca(coche, idBase, DAOFactory); if (state != null && state.Estado == EstadosGeocerca.Dentro) { _movilesEnPlanta++; } } if (idClientes.Count > 0) { var withGeo = idClientes.Select(c => GeocercaManager.GetEstadoGeocerca(coche, c, DAOFactory)) .Where(s => s != null); if (withGeo.Any(st => st != null && st.Estado == EstadosGeocerca.Dentro)) { _movilesEnCliente++; } } } } _movilesEnViaje = enServicio - _movilesEnPlanta - _movilesEnCliente; }