private void ProcessConfirmacionUbox(string code, Event generico, GPSPoint point) { var extraText = string.Empty; var distribucion = DaoFactory.ViajeDistribucionDAO.FindEnCurso(Coche); if (distribucion != null) { var estado = GeocercaManager.CalcularEstadoVehiculo(Coche, point, DaoFactory); var detalles = distribucion.Detalles.Where(d => estado.GeocercasDentro.Select(g => g.Geocerca.Id).Contains(d.ReferenciaGeografica.Id)); var conEntrada = detalles.Where(d => d.Entrada.HasValue && !d.Manual.HasValue) .OrderBy(d => d.Entrada.Value); detalles = conEntrada.Any() ? conEntrada : detalles.Where(d => !d.Manual.HasValue); var detalle = detalles.Any() ? detalles.First() : null; if (detalle != null) { DaoFactory.Session.Refresh(detalle); extraText = " (" + detalle.Orden + ") -> " + detalle.Viaje.Codigo + " - " + detalle.Descripcion; detalle.Estado = generico.GetData().ToString("#0") == MessageCode.TareaRealizada.GetMessageCode() ? EntregaDistribucion.Estados.Completado : EntregaDistribucion.Estados.NoCompletado; detalle.Manual = generico.GetDateTime(); DaoFactory.EntregaDistribucionDAO.SaveOrUpdate(detalle); } } var textoEvento = ExtraText.GetExtraText(generico, code) + extraText; var chofer = GetChofer(generico.GetRiderId()); MessageSaver.Save(generico, code, Dispositivo, Coche, chofer, generico.GetDateTime(), generico.GeoPoint, textoEvento, ZonaManejo); MessageSaver.Save(MessageCode.EstadoLogisticoCumplidoManual.GetMessageCode(), Coche, chofer, generico.GetDateTime(), generico.GeoPoint, textoEvento); }
protected override void OnRowDataBound(C1GridView grid, C1GridViewRowEventArgs e, TolvaTourVo dataItem) { var vehiculo = DAOFactory.CocheDAO.FindById(dataItem.IdVehiculo); var posInicio = new GPSPoint(dataItem.EntradaHora, (float)dataItem.LatitudInicio, (float)dataItem.LongitudInicio); var posFin = new GPSPoint(dataItem.SalidaHora, (float)dataItem.LatitudFin, (float)dataItem.LongitudFin); var estadoInicio = GeocercaManager.CalcularEstadoVehiculo(vehiculo, posInicio, DAOFactory); var estadoFin = GeocercaManager.CalcularEstadoVehiculo(vehiculo, posFin, DAOFactory); var geocerca = estadoInicio.GeocercasDentro.Intersect(estadoFin.GeocercasDentro).FirstOrDefault(); var text = geocerca != null ? geocerca.Geocerca.Descripcion : GeocoderHelper.GetDescripcionEsquinaMasCercana(dataItem.LatitudInicio, dataItem.LongitudInicio); e.Row.Cells[TolvaTourVo.Index.Ubicacion].Text = text; if (dataItem.Entrada == DateTime.MinValue) { e.Row.Cells[TolvaTourVo.Index.Entrada].Text = ""; e.Row.Cells[TolvaTourVo.Index.EntradaHora].Text = ""; } if (dataItem.Salida == DateTime.MinValue) { e.Row.Cells[TolvaTourVo.Index.Salida].Text = ""; e.Row.Cells[TolvaTourVo.Index.SalidaHora].Text = ""; } }
protected override void OnExecute(Timer timer) { STrace.Trace(GetType().FullName, "Iniciando tarea..."); var te = new TimeElapsed(); try { var empresas = DaoFactory.EmpresaDAO.FindAll().Where(e => e.Baja == false); var lineas = DaoFactory.LineaDAO.FindAll().Where(l => l.Baja == false); foreach (var empresa in empresas) { var lineaEmpresa = lineas.Where(l => l.Empresa.Id == empresa.Id); GeocercaManager.GetQtreeTest(empresa.Id, -1); foreach (var linea in lineaEmpresa) { GeocercaManager.GetQtreeTest(empresa.Id, linea.Id); } } var ts = te.getTimeElapsed().TotalSeconds; STrace.Trace(GetType().FullName, string.Format("Tarea finalizada en {0} segundos", ts)); } catch (Exception ex) { AddError(ex); } finally { ClearData(); } }
private static bool CheckGeofence(Coche vehiculo, Accion accion, DAOFactory daoFactory) { if (!accion.EvaluaGeocerca) { return(true); } var estados = GeocercaManager.GetEstadoVehiculo(vehiculo, daoFactory); var dentroDeAlguna = estados.GeocercasDentro.Any(geo => geo.Geocerca.TipoReferenciaGeograficaId == accion.TipoGeocerca.Id); return((accion.DentroGeocerca && dentroDeAlguna) || (!accion.DentroGeocerca && !dentroDeAlguna)); }
/// <summary> /// Process the givenn message as a VelocidadExcedida event. /// </summary> /// <param name="velocidadExcedida">A message.</param> private HandleResults ProcessVelocidadExcedidaEvent(SpeedingTicket velocidadExcedida) { var inicio = velocidadExcedida.StartPoint ?? velocidadExcedida.TicketPoint; if (IsInvalidVelocidadExcedidaMessage(inicio, velocidadExcedida)) { return(HandleResults.BreakSuccess); } var texto = GetVelocidadExcedidaText(velocidadExcedida); var chofer = GetChofer(velocidadExcedida.GetRiderId()); var velocidadPermitida = Convert.ToInt32(velocidadExcedida.SpeedLimit); var velocidadAlcanzada = Convert.ToInt32(velocidadExcedida.SpeedReached); var estado = GeocercaManager.CalcularEstadoVehiculo(Coche, inicio, DaoFactory); var zona = estado != null && estado.ZonaManejo != null && estado.ZonaManejo.ZonaManejo > 0 ? DaoFactory.ZonaDAO.FindById(estado.ZonaManejo.ZonaManejo) : null; if (Coche.Empresa.AsignoInfraccionPorAgenda) { var reserva = DaoFactory.AgendaVehicularDAO.FindByVehicleAndDate(Coche.Id, inicio.Date); if (reserva != null) { chofer = reserva.Empleado; } } var evento = MessageSaver.Save(velocidadExcedida, MessageCode.SpeedingTicket.GetMessageCode(), Dispositivo, Coche, chofer, inicio.Date, inicio, velocidadExcedida.EndPoint, texto, velocidadPermitida, velocidadAlcanzada, null, zona); var infraccion = new Infraccion { Vehiculo = Coche, Alcanzado = velocidadAlcanzada, CodigoInfraccion = Infraccion.Codigos.ExcesoVelocidad, Empleado = evento.Chofer, Fecha = inicio.Date, Latitud = inicio.Lat, Longitud = inicio.Lon, FechaFin = velocidadExcedida.EndPoint.Date, LatitudFin = velocidadExcedida.EndPoint.Lat, LongitudFin = velocidadExcedida.EndPoint.Lon, Permitido = velocidadPermitida, Zona = zona, FechaAlta = DateTime.UtcNow }; DaoFactory.InfraccionDAO.Save(infraccion); return(HandleResults.Success); }
protected override HandleResults OnDeviceHandleMessage(Event message) { //STrace.Debug(typeof(Events).FullName, message.DeviceId, "OnDeviceHandleMessage (EventsHandler)"); AdjustRfidData(message); var code = GetGenericEventCode(message); STrace.Debug(typeof(Events).FullName, message.DeviceId, String.Format("code:{0} Subcode:{1}", code, message.GetData())); #region protect garmin on/off messages from be banned because of invalid date if ((code == MessageCode.GarminOn.GetMessageCode() || code == MessageCode.GarminOff.GetMessageCode()) && message.GeoPoint != null && FechaInvalida(message.GeoPoint.Date, DeviceParameters)) { message.GeoPoint.Date = DateTime.UtcNow; } #endregion protect garmin on/off messages from be banned because of invalid date //if (IsGarbageMessage(code)) //{ // return HandleResults.BreakSuccess; //} if (IsInvalidMessage(code, message)) { return(HandleResults.BreakSuccess); } ExtraText = new ExtraText(DaoFactory); if (MessageIdentifierX.IsEntityMessage(code)) { ProcessEntityEvent(message, code); } else if (Coche != null) { var estado = GeocercaManager.CalcularEstadoVehiculo(Coche, message.GeoPoint, DaoFactory); ZonaManejo = estado != null && estado.ZonaManejo != null && estado.ZonaManejo.ZonaManejo > 0 ? DaoFactory.ZonaDAO.FindById(estado.ZonaManejo.ZonaManejo) : null; ProcessEvent(code, message); ProcessPosition(message); } return(HandleResults.Success); }
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; }