예제 #1
0
 /// <summary>
 /// Обращается к базе данных и находит в ней поезд, соответствующий переданному в параметре, и уменьшает у него количество билетов на 1.
 /// После окончания этой операции вызывает у класса MainWindow метод BookingReady.
 /// </summary>
 /// <param name="CurrentTrain"></param>
 public static void BookTicket(Train CurrentTrain)
 {
     using (ContextForBookingDataBase BookingDBcontext = new ContextForBookingDataBase(NamesOfVariables.ConnectionStringName))
     {
         BookingDBcontext.ListOfTrains.First((res) => res.TrainName == CurrentTrain.TrainName).AmountOfFreeTickets = CurrentTrain.AmountOfFreeTickets;
         BookingDBcontext.SaveChanges();
         Application.Current.Dispatcher.Invoke(new Action(() => ApplicationMainWindow.BookingReady()));
     }
 }
예제 #2
0
        /// <summary>
        /// Возвращает список имен станций из базы данных.
        /// </summary>
        /// <returns></returns>
        public static ObservableCollection<string> GetNamesOfStations()
        {
            ObservableCollection<string> AllStations = new ObservableCollection<string>();
            using (ContextForBookingDataBase BookingDBcontext = new ContextForBookingDataBase(NamesOfVariables.ConnectionStringName))
            {
                foreach (Station CurrentStation in BookingDBcontext.ListOfStations)
                {
                    AllStations.Add(CurrentStation.StationName);
                }
            }

            return AllStations;
        }
예제 #3
0
        /// <summary>
        /// Ищет в базе данных поед, который останавливается на двух указанных станциях
        /// и вызывает у класса MainWindow метод SearchOver с найденным поездом или null в качестве аргумента.
        /// </summary>
        /// <param name="DepartureStationName"></param>
        /// <param name="DestinationStationName"></param>
        /// <returns></returns>
        public static void SearchTrain(string DepartureStationName, string DestinationStationName)
        {
            Train ResultTrain = null;
            int AmountOfFoundStations;
            using (ContextForBookingDataBase BookingDBcontext = new ContextForBookingDataBase(NamesOfVariables.ConnectionStringName))
            {
                bool DepartureStationExist = false;
                bool DestinationStationExist = false;
                if (BookingDBcontext.ListOfStations.Where((res) => res.StationName == DepartureStationName).Count() > 0)
                {
                    DepartureStationExist = true;
                }
                if (BookingDBcontext.ListOfStations.Where((res) => res.StationName == DestinationStationName).Count() > 0)
                {
                    DestinationStationExist = true;
                }
                if (DepartureStationExist && DestinationStationExist)
                {
                    List<Train> AllTrains = new List<Train>();
                    foreach (Train CurrentTrain in BookingDBcontext.ListOfTrains)
                    {
                        AllTrains.Add(CurrentTrain);
                    }

                    bool TrainWasFound = false;

                    foreach (Train CurrentTrain in AllTrains)
                    {
                        AmountOfFoundStations = CurrentTrain.Stations.Where((res) => res.StationName == DepartureStationName || res.StationName == DestinationStationName).Count();
                        if (AmountOfFoundStations == 2)
                        {
                            ResultTrain = CurrentTrain;
                            Application.Current.Dispatcher.Invoke(new Action(() => ApplicationMainWindow.SearchOver(ResultTrain, true, true)));
                            TrainWasFound = true;
                            break;
                        }
                    }
                    if (!TrainWasFound)
                    {
                        Application.Current.Dispatcher.Invoke(new Action(() => ApplicationMainWindow.SearchOver(null, true, true)));
                    }
                }
                else
                {
                    Application.Current.Dispatcher.Invoke(new Action(() => ApplicationMainWindow.SearchOver(null, DepartureStationExist, DestinationStationExist)));
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Возвращает список имен станций из базы данных.
        /// </summary>
        /// <returns></returns>
        public static List<string> GetNamesOfStations(string ConnectionStringName)
        {
            List<string> AllStations = new List<string>();
            using (ContextForBookingDataBase BookingDBcontext = new ContextForBookingDataBase(ConnectionStringName))
            {
                foreach (Station CurrentStation in BookingDBcontext.ListOfStations.OrderBy((res) => res.StationName))
                {
                    AllStations.Add(CurrentStation.StationName);
                }
            }

            return AllStations;
        }