Exemple #1
0
        public MobileSrc.Commuter.Shared.CommuteHistory GetCommuteHistory(Guid deviceId, Guid commuteId)
        {
            LogRequest(deviceId, "GetCommuteHistory");
            MobileSrc.Commuter.Shared.CommuteHistory history = new MobileSrc.Commuter.Shared.CommuteHistory();

            try
            {
                using (SqlConnection connection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';"))
                {
                    connection.Open();

                    SqlCommand command = new SqlCommand("GetCommuteHistory", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("idCommute", commuteId);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        Dictionary <Guid, MobileSrc.Commuter.Shared.RouteHistory> routes = new Dictionary <Guid, MobileSrc.Commuter.Shared.RouteHistory>();

                        while (reader.Read())
                        {
                            Guid idRoute = (Guid)reader["idRoute"];

                            if (!routes.ContainsKey(idRoute))
                            {
                                MobileSrc.Commuter.Shared.RouteHistory routeHistory = new MobileSrc.Commuter.Shared.RouteHistory();
                                routeHistory.RouteId = idRoute;
                                history.Routes.Add(routeHistory);
                                routes.Add(idRoute, routeHistory);
                            }
                            MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay day = new MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay();
                            day.Day     = (DayOfWeek)Convert.ToInt32(reader["Day"]);
                            day.Minutes = Convert.ToDouble(reader["Duration"]);

                            bool isDeparture = Convert.ToBoolean(reader["IsDeparture"]);

                            if (isDeparture)
                            {
                                routes[idRoute].DepartureAverages.Add(day);
                            }
                            else
                            {
                                routes[idRoute].ReturnAverages.Add(day);
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return(history);
        }
Exemple #2
0
        void ProcessHistory(MobileSrc.Commuter.Shared.CommuteHistory commuteHistory)
        {
            departureRouteSeries.Clear();
            returnRouteSeries.Clear();

            foreach (MobileSrc.Commuter.Shared.RouteDefinition route in DataContextManager.SelectedCommute.Routes)
            {
                ObservableCollection <KeyValuePair <string, int> > depSeriesData = new ObservableCollection <KeyValuePair <string, int> >();
                ObservableCollection <KeyValuePair <string, int> > retSeriesData = new ObservableCollection <KeyValuePair <string, int> >();

                BarSeries retSeries = new BarSeries();
                retSeries.Title                   = route.Name;
                retSeries.ItemsSource             = retSeriesData;
                retSeries.IndependentValueBinding = new System.Windows.Data.Binding("Key");
                retSeries.DependentValueBinding   = new System.Windows.Data.Binding("Value");

                BarSeries depSeries = new BarSeries();
                depSeries.Title                   = route.Name;
                depSeries.ItemsSource             = depSeriesData;
                depSeries.IndependentValueBinding = new System.Windows.Data.Binding("Key");
                depSeries.DependentValueBinding   = new System.Windows.Data.Binding("Value");

                departureRouteSeries.Add(route.Id, depSeries);
                returnRouteSeries.Add(route.Id, retSeries);
            }

            foreach (MobileSrc.Commuter.Shared.RouteHistory history in commuteHistory.Routes)
            {
                if (departureRouteSeries.ContainsKey(history.RouteId))
                {
                    ObservableCollection <KeyValuePair <string, int> > depSeriesData = (ObservableCollection <KeyValuePair <string, int> >)departureRouteSeries[history.RouteId].ItemsSource;
                    ObservableCollection <KeyValuePair <string, int> > retSeriesData = (ObservableCollection <KeyValuePair <string, int> >)returnRouteSeries[history.RouteId].ItemsSource;

                    Dictionary <DayOfWeek, double> depDayValues = new Dictionary <DayOfWeek, double>();
                    Dictionary <DayOfWeek, double> retDayValues = new Dictionary <DayOfWeek, double>();

                    foreach (MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay historyDay in history.DepartureAverages)
                    {
                        if (!depDayValues.ContainsKey((DayOfWeek)historyDay.Day))
                        {
                            depDayValues.Add((DayOfWeek)historyDay.Day, historyDay.Minutes);
                        }
                    }
                    foreach (MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay historyDay in history.ReturnAverages)
                    {
                        if (!retDayValues.ContainsKey((DayOfWeek)historyDay.Day))
                        {
                            retDayValues.Add((DayOfWeek)historyDay.Day, historyDay.Minutes);
                        }
                    }
                    Dictionary <DayOfWeek, double> dayValues = new Dictionary <DayOfWeek, double>();

                    for (int i = 0; i <= (int)DayOfWeek.Saturday; ++i)
                    {
                        int value = (int)Math.Pow(2, i);

                        if (0 != ((int)DataContextManager.SelectedCommute.DaysOfWeek & value))
                        {
                            double depTimeValue = 0;
                            double retTimeValue = 0;

                            if (depDayValues.ContainsKey((DayOfWeek)i))
                            {
                                depTimeValue = depDayValues[(DayOfWeek)i];
                            }
                            if (retDayValues.ContainsKey((DayOfWeek)i))
                            {
                                retTimeValue = retDayValues[(DayOfWeek)i];
                            }

                            string dayName = System.Globalization.DateTimeFormatInfo.CurrentInfo.DayNames[i].Substring(0, 3);
                            depSeriesData.Add(new KeyValuePair <string, int>(dayName, (int)depTimeValue));
                            retSeriesData.Add(new KeyValuePair <string, int>(dayName, (int)retTimeValue));
                        }
                    }
                }
            }
            BindRouteData();
        }
        public MobileSrc.Commuter.Shared.CommuteHistory GetCommuteHistory(Guid deviceId, Guid commuteId)
        {
            LogRequest(deviceId, "GetCommuteHistory");
            MobileSrc.Commuter.Shared.CommuteHistory history = new MobileSrc.Commuter.Shared.CommuteHistory();

            try
            {
                using (SqlConnection connection = new SqlConnection(@"Data Source=wpcommuter.db.3448251.hostedresource.com; Initial Catalog=wpcommuter; User ID=wpcommuter; Password='******';"))
                {
                    connection.Open();

                    SqlCommand command = new SqlCommand("GetCommuteHistory", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("idCommute", commuteId);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        Dictionary<Guid, MobileSrc.Commuter.Shared.RouteHistory> routes = new Dictionary<Guid, MobileSrc.Commuter.Shared.RouteHistory>();

                        while (reader.Read())
                        {
                            Guid idRoute = (Guid)reader["idRoute"];

                            if (!routes.ContainsKey(idRoute))
                            {
                                MobileSrc.Commuter.Shared.RouteHistory routeHistory = new MobileSrc.Commuter.Shared.RouteHistory();
                                routeHistory.RouteId = idRoute;
                                history.Routes.Add(routeHistory);
                                routes.Add(idRoute, routeHistory);
                            }
                            MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay day = new MobileSrc.Commuter.Shared.RouteHistory.RouteHistoryDay();
                            day.Day = (DayOfWeek)Convert.ToInt32(reader["Day"]);
                            day.Minutes = Convert.ToDouble(reader["Duration"]);

                            bool isDeparture = Convert.ToBoolean(reader["IsDeparture"]);

                            if (isDeparture)
                            {
                                routes[idRoute].DepartureAverages.Add(day);
                            }
                            else
                            {
                                routes[idRoute].ReturnAverages.Add(day);
                            }
                        }
                    }
                }
            }
            catch
            {
            }

            return history;
        }