Beispiel #1
0
        /// <summary>
        /// Searchs result positions to be displayed.
        /// </summary>

        /*private void SearchPositions()
         * {
         *  var route = DAOFactory.RoutePositionDAO.GetPositions(Mobile, InitialDate.ToDataBaseDateTime(), FinalDate.ToDataBaseDateTime());
         *
         *  if (route.Count == 0)
         *  {
         *      ShowInfo("No se encontraron posiciones para los parametros de busqueda ingresados!");
         *
         *      return;
         *  }
         *
         *  var pos = "[";
         *
         *  for (var i = 0; i < route.Count; i++)
         *  {
         *      var dist = i == route.Count - 1 ? 0 : Distancias.Loxodromica(route[i].Latitude, route[i].Longitude, route[i + 1].Latitude, route[i + 1].Longitude);
         *
         *      var duration = i == route.Count - 1 ? 0 : route[i + 1].Date.Subtract(route[i].Date).TotalSeconds;
         *
         *      if (i > 0) pos = string.Concat(pos, ',');
         *
         *      pos = string.Concat(pos, string.Format("{{lon: {0}, lat: {1}, speed: {2}, distance: {3}, duration: {4}, time: new Date{5}}}",
         *          route[i].Longitude.ToString(CultureInfo.InvariantCulture), route[i].Latitude.ToString(CultureInfo.InvariantCulture), route[i].Speed,
         *          dist.ToString(CultureInfo.InvariantCulture), duration.ToString(CultureInfo.InvariantCulture), route[i].Date.ToString("(yyyy, MM, dd, HH, mm, ss)")));
         *  }
         *
         *  pos = string.Concat(pos, "]");
         *
         *  System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(string), "route", string.Format("simulador.createRoute({0});", pos), true);
         * }
         */
        private void SearchPositions()
        {
            var colorGenerator = new ColorGenerator(new List <Color> {
                Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Violet, Color.Cyan, Color.Purple
            });
            var empresa   = DAOFactory.EmpresaDAO.FindById(ddlDistrito.Selected);
            var maxMonths = empresa != null && empresa.Id > 0 ? empresa.MesesConsultaPosiciones : 3;

            var route = DAOFactory.RoutePositionsDAO.GetPositionsByRoute(Mobile, InitialDate.ToDataBaseDateTime(), FinalDate.ToDataBaseDateTime(), TimeSpan.Zero, maxMonths);

            if (route.Count == 0)
            {
                ShowInfo("No se encontraron posiciones para los parametros de busqueda ingresados!");

                return;
            }

            var pos = "[";

            for (var j = 0; j < route.Count; j++)
            {
                var tramo = route[j];
                var color = HexColorUtil.ColorToHex(colorGenerator.GetNextColor(j)).Substring(1);
                color = color.Substring(4, 2) + color.Substring(2, 2) + color.Substring(0, 2);
                for (var i = 0; i < tramo.Count; i++)
                {
                    var posicion = tramo[i];
                    var next     = i == tramo.Count - 1
                                   ? j == route.Count - 1 ? null : route[j + 1][0]
                                   : tramo[i + 1];
                    var dist = next == null ? 0 : Distancias.Loxodromica(posicion.Latitude, posicion.Longitude, next.Latitude, next.Longitude);

                    var duration = next == null ? 0 : next.Date.Subtract(posicion.Date).TotalSeconds;

                    if (j > 0 || i > 0)
                    {
                        pos = string.Concat(pos, ',');
                    }

                    pos = string.Concat(pos, string.Format("{{lon: {0}, lat: {1}, speed: {2}, distance: {3}, duration: {4}, time: new Date{5}, 'color': '{6}' }}",
                                                           posicion.Longitude.ToString(CultureInfo.InvariantCulture), posicion.Latitude.ToString(CultureInfo.InvariantCulture), posicion.Speed,
                                                           dist.ToString(CultureInfo.InvariantCulture), duration.ToString(CultureInfo.InvariantCulture), posicion.Date.ToDisplayDateTime().ToString("(yyyy, MM, dd, HH, mm, ss)"), color));
                }
            }
            pos = string.Concat(pos, "]");

            var startflag = CreateAbsolutePath("~/images/salida.png");
            var endflag   = CreateAbsolutePath("~/images/llegada.png");

            System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(string), "route", string.Format("simulador.createRoute({0},'{1}','{2}');", pos, startflag, endflag), true);
        }
Beispiel #2
0
        /// <summary>
        /// Transforms the mobile event into a javascript object.
        /// </summary>
        /// <returns></returns>
        private void GetMessages()
        {
            var messages = lbMessages.SelectedStringValues;

            if (MessagesIds.Count == 0 && messages.Count == 0)
            {
                return;
            }

            var empresa   = DAOFactory.EmpresaDAO.FindById(ddlDistrito.Selected);
            var maxMonths = empresa != null && empresa.Id > 0 ? empresa.MesesConsultaPosiciones : 3;
            var events    = (from ev in DAOFactory.LogMensajeDAO.GetByMobilesAndTypes(ddlMovil.SelectedValues, GetSelectedMessagesCodes(messages), InitialDate.ToDataBaseDateTime(), FinalDate.ToDataBaseDateTime(), maxMonths) orderby ev.Fecha select ev).ToList();

            var eventarray = "[";

            for (var i = 0; i < events.Count; i++)
            {
                var evento = events[i];
                if (!evento.HasValidLatitudes())
                {
                    continue;
                }

                var messageIconUrl = evento.GetIconUrl();
                var iconUrl        = CreateAbsolutePath(string.IsNullOrEmpty(messageIconUrl) ? DefaultMessageImgUrl : string.Concat(IconDir, messageIconUrl));

                if (i > 0)
                {
                    eventarray += ",";
                }

                eventarray += string.Format("{{ id: 'ev_{0}', name: '{1}', lat: {2}, lon:{3}, icon:'{4}', time: new Date{5} }}",
                                            evento.Id, evento.Texto, evento.Latitud.ToString(CultureInfo.InvariantCulture), evento.Longitud.ToString(CultureInfo.InvariantCulture),
                                            iconUrl, evento.Fecha.ToDisplayDateTime().ToString("(yyyy, MM, dd, HH, mm, ss)"));

                //Monitor.AddMarkers(MENSAJES, new Marker(i.ToString(), iconUrl, events[i].Latitud, events[i].Longitud,
                //    string.Format("javascript:gMSP({0})", events[i].Id), DrawingFactory.GetSize(24, 24), DrawingFactory.GetOffset(-12, -12)));

                //if (events[i].HasDuration()) AddMessageWithElapsedTime(events[i]);
            }
            eventarray += "]";

            System.Web.UI.ScriptManager.RegisterStartupScript(this, typeof(string), "events", string.Format("simulador.addEvents({0});", eventarray), true);
            //SetMessagesCenterIndex(events);
        }