示例#1
0
        private void StartBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DestinationBox.Items.Clear();
            var       item         = sender as ComboBox;
            var       selection    = item.SelectedItem as string;
            ShortName selectedCity = sn.Single(s => s.Name == selection);

            DestId = selectedCity.Id;

            using (var ct = new TimeTable())
            {
                var cityList = ct.Departure
                               .Include(b => b.Connection)
                               .Where(q => q.Connection.StartId == DestId)
                               .Include(c => c.Connection.Destination)
                               .Include(c => c.Connection.Start)
                               .Include(c => c.Connection.Train)
                               .Select(q => new { FROM = q.Connection.Start.Name, TO = q.Connection.Destination.Name, DEPARTURE = q.Time, TRAVEL_TIME = q.TravelTime, TRAIN = q.Connection.Train.Name }).ToList();
                grid.ItemsSource = cityList;
            }

            using (var ct = new TimeTable())
            {
                var cityList = ct.Connection
                               .Include(c => c.Start)
                               .Include(c => c.Destination)
                               .Where(q => q.StartId == DestId)
                               .Select(q => new { q.Id, q.Destination.Name })
                               .ToList();
                foreach (var city in cityList)
                {
                    DestinationBox.Items.Add(city.Name);
                }
            }
        }
示例#2
0
        private void DestinationBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var item      = sender as ComboBox;
            var selection = item.SelectedItem as string;

            if (item.SelectedItem != null)
            {
                ShortName selectedCity = sn.Single(s => s.Name == selection);
                using (var ct = new TimeTable())
                {
                    var cityList = ct.Departure
                                   .Include(b => b.Connection)
                                   .Where(q => q.Connection.StartId == DestId && q.Connection.DestinationId == selectedCity.Id)
                                   .Include(c => c.Connection.Destination)
                                   .Include(c => c.Connection.Start)
                                   .Include(c => c.Connection.Train)
                                   .Select(q => new { FROM = q.Connection.Start.Name, TO = q.Connection.Destination.Name, DEPARTURE = q.Time, TRAVEL_TIME = q.TravelTime, TRAIN = q.Connection.Train.Name }).ToList();
                    grid.ItemsSource = cityList;
                }
            }
        }