private void Initialize(DateTimeModel model) { DateTime time = model.DateTime; while (time.Minute % 5 != 0) { time += TimeSpan.FromMinutes(1); } this.Type = model.Type; setTypeBorders(); isAmPm = time.ToString("t").Contains('M'); SetSize(isAmPm); List <HourWrapper> hourDataSource; var dayDataSource = Enumerable.Range(0, 31).Select(i => DateWrapper.Create(DateTime.Today + TimeSpan.FromDays(i))).ToList(); DaySelector.DataSource = dayDataSource; var minuteDataSource = Enumerable.Range(0, 60 / 5).Select(i => (i * 5).ToString("D2")).Select(x => new MinuteWrapper { Value = x }).ToList(); MinuteSelector.DataSource = minuteDataSource; if (isAmPm) { //AmPmSelector.DataSource = new AmPmDataSource(time.IsPM() ? "PM" : "AM"); var amPmDataSource = new string[] { "AM", "PM" }.Select(x => new AmPmWrapper { Value = x }).ToList(); AmPmSelector.DataSource = amPmDataSource; AmPmSelector.Visibility = Visibility.Visible; AmPmSelector.SelectedItem = time.IsPM() ? amPmDataSource[1] : amPmDataSource[0]; hourDataSource = new int[] { 12 }.Concat(Enumerable.Range(1, 11)).Select(x => new HourWrapper { Value = x }).ToList(); HourSelector.DataSource = hourDataSource; } else { hourDataSource = Enumerable.Range(0, 24).Select(x => new HourWrapper { Value = x }).ToList(); HourSelector.DataSource = hourDataSource; } DaySelector.SelectedItem = dayDataSource.First(x => x.Value.Date == time.Date); MinuteSelector.SelectedItem = minuteDataSource.ElementAt(time.Minute / 5); HourSelector.SelectedItem = hourDataSource.First(h => h.Value.ToString() == time.HourString()); //DaySelector.SelectionChanged += (sender, a) => DaySelector.IsExpanded = false; //HourSelector.SelectionChanged += (sender, a) => HourSelector.IsExpanded = false; //MinuteSelector.SelectionChanged += (sender, a) => MinuteSelector.IsExpanded = false; //if (AmPmSelector.DataSource != null) // AmPmSelector.SelectionChanged += (sender, a) => AmPmSelector.IsExpanded = false; }
private void PlanBtn_Click(object sender, RoutedEventArgs e) { StopGroup source = null, dest = null; var sourceModel = (StopPicker.StopModel)SourceBox.Selected; if (sourceModel != null) { source = sourceModel.Value; } var destModel = (StopPicker.StopModel)DestBox.Selected; if (destModel != null) { dest = destModel.Value; } if (source == null) { new MessageDialog("A kiindulási megálló nem található. Kérem adja meg újra!").ShowAsync(); return; } if (dest == null) { new MessageDialog("A cél megálló nem található. Kérem adja meg újra!").ShowAsync(); return; } DateTime selectedTime = selectedDay + TimeSpan.FromHours((int)HourBox.SelectedItem) + TimeSpan.FromMinutes(int.Parse((string)MinuteBox.SelectedItem)); PlanningTimeType planningType = TypeBox.SelectedIndex == 0 ? PlanningTimeType.Departure : PlanningTimeType.Arrival; Frame.Navigate(typeof(PlanningPage), new PlanningParameter { SourceStop = source, DestStop = dest, DateTime = selectedTime, PlanningType = planningType }); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); string param = ""; NavigationContext.QueryString.TryGetValue("time", out param); DateTime time = DateTime.Parse(param); while (time.Minute % 5 != 0) { time += TimeSpan.FromMinutes(1); } NavigationContext.QueryString.TryGetValue("departure", out param); Type = param == "1" ? PlanningTimeType.Departure : PlanningTimeType.Arrival; setTypeBorders(); isAmPm = time.ToString("t").Contains('M'); DaySelector.DataSource = new NextDatesDataSource(time); HourSelector.DataSource = new HourDataSource(time); MinuteSelector.DataSource = new MinuteDataSource(time.Minute); if (isAmPm) { AmPmSelector.DataSource = new AmPmDataSource(time.IsPM() ? "PM" : "AM"); AmPmSelector.Visibility = Visibility.Visible; } SetSize(isAmPm); DaySelector.DataSource.SelectionChanged += (sender, args) => DaySelector.IsExpanded = false; HourSelector.DataSource.SelectionChanged += (sender, args) => HourSelector.IsExpanded = false; MinuteSelector.DataSource.SelectionChanged += (sender, args) => MinuteSelector.IsExpanded = false; if (AmPmSelector.DataSource != null) { AmPmSelector.DataSource.SelectionChanged += (sender, args) => AmPmSelector.IsExpanded = false; } }
private async Task planAsync(StopGroup source, StopGroup target, DateTime pickedDateTime, PlanningTimeType planningType) { if (source == null) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningSourceEmpty")); return; } if (target == null) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningTargetEmpty")); return; } //var source = SourceText.Selected; //var target = TargetText.Selected; //var pickedDateTime = DateTimePicker.Time; CommonComponent.Current.UB.History.AddPlanningHistory(source, true); CommonComponent.Current.UB.History.AddPlanningHistory(target, false); FoundRoutes.Clear(); ResultBorderHeight = 0; InProgress = true; await CommonComponent.Current.TB.UsingFiles; Stopwatch watch = Stopwatch.StartNew(); await Task.Run(() => { try { CommonComponent.Current.Planner.SetParams(new PlanningArgs { Type = planningType, EnabledTypes = Convert(new bool[] { PlanSettingsModel.TramAllowed, PlanSettingsModel.MetroAllowed, PlanSettingsModel.UrbanTrainAllowed, PlanSettingsModel.BusAllowed, true, true, true, true }), OnlyWheelchairAccessibleTrips = PlanSettingsModel.WheelchairAccessibleTrips, OnlyWheelchairAccessibleStops = PlanSettingsModel.WheelchairAccessibleStops, LatitudeDegreeDistance = CommonComponent.Current.Config.LatitudeDegreeDistance, LongitudeDegreeDistance = CommonComponent.Current.Config.LongitudeDegreeDistance, WalkSpeedRate = PlanSettingsModel.WalkingSpeed / 3.6 * 60 }); } catch (Exception e) { //Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Services.MessageBox.Show(Services.Localization.StringOf("PlanningError"))); } }); IEnumerable <PlanningAspect> aspects = new PlanningAspect[] { PlanningAspect.Time, PlanningAspect.TransferCount, PlanningAspect.WalkDistance }; //aspects = aspects.Take(CommonComponent.Current.Config.PlanningAspectsCount); //aspects = aspects.Take(1); await Task.WhenAll(aspects.Select(async aspect => { PlannerComponent.Interface.Way middleResult = await Task.Run(() => { try { return(CommonComponent.Current.Planner.CalculatePlanning(source, target, pickedDateTime, aspect)); } catch (Exception e) { //Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => Services.MessageBox.Show(Services.Localization.StringOf("PlanningError"))); return(null); } }); if (middleResult != null) { //Services.MessageBox.Show(middleResult.Message); TransitBase.BusinessLogic.Way result = Convert(middleResult, PlanSettingsModel.WalkingSpeedInMps); if (FoundRoutes.All(x => !x.Way.Equals(result))) { int i = 0; while (i < FoundRoutes.Count && FoundRoutes[i].Way < result) { i++; } FoundRoutes.Insert(i, new WayModel(result, source, target, pickedDateTime)); ResultBorderHeight = double.NaN; } } })); InProgress = false; if (FoundRoutes.Count == 0) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningNoResult")); } else { //TimeText.Text = string.Format("{0} ({1:0.##} sec)", Services.Localization.StringOf("PlanningTimeLabel"), watch.ElapsedMilliseconds / 1000.0); //await Task.Delay(3000); //TimeText.Text = ""; } }
public async Task PlanAsync(StopGroup sourceStop, StopGroup targetStop, DateTime pickedDateTime, PlanningTimeType planningType) { if (planningInProgress) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningInProgress")); return; } if (!CommonComponent.Current.OfflinePlanningEnabled) { bool hasConnection = await CheckConnectionProcess.RunAsync(); if (!hasConnection) { Services.MessageBox.Show(Services.Resources.LocalizedStringOf("PlanningNoAccess")); return; } } planningInProgress = true; await planAsync(sourceStop, targetStop, pickedDateTime, planningType); planningInProgress = false; }
private void ArriveBorder_Tap(object sender, System.Windows.Input.GestureEventArgs e) { Type = PlanningTimeType.Arrival; setTypeBorders(); }
private void ArriveBorder_Tap(object sender, TappedRoutedEventArgs e) { LoopingSelector.PerformOtherClick(sender); Type = PlanningTimeType.Arrival; setTypeBorders(); }