public FlightQuery(Flight_Schedule flight, String originAirport, String originCountry, String destinationAirport, String destinationCountry) { this.Flight = flight; this.OriginAirport = originAirport; this.OriginCountry = originCountry; this.DestinationAirport = destinationAirport; this.DestinationCountry = destinationCountry; }
private void addFlightToolStripMenuItem1_Click(object sender, EventArgs e) { this.Hide(); int a = 42; int b = 10; Flight_Schedule fl = new Flight_Schedule(a, b); this.Show(); }
public async Task <IActionResult> Create(int FromCityID, int ToCityID) { var flightSchedule = new Flight_Schedule { }; if (await TryUpdateModelAsync <Flight_Schedule>(flightSchedule, "", c => c.Flight_ScheduleID, c => c.RouteID, c => c.DepartDateTime, c => c.ArriveDateTime, c => c.AirCraftID, c => c.Economy, c => c.Business, c => c.PremEconomy, c => c.First)) { //if the route in this schedule does not exist, then reject to create if (!await _context.Routes.AnyAsync(r => r.FromCity.CityID == FromCityID && r.ToCity.CityID == ToCityID)) //get rid of the route that does not exist { ViewBag.ErrorNoRoute = "No such route exists!"; ViewData["FromCityID"] = new SelectList(_context.Cities, "CityID", "Name"); ViewData["ToCityID"] = new SelectList(_context.Cities, "CityID", "Name"); return(View(flightSchedule)); } int RouteID = await _context.Routes.Where(r => r.FromCity.CityID == FromCityID && r.ToCity.CityID == ToCityID).Select(r => r.RouteID).FirstAsync(); //get the ID of route between2 cities flightSchedule.Route = await _context.Routes.Where(r => r.RouteID == RouteID).FirstAsync(); //set the route in the new Flight_Schedule try { _context.Add(flightSchedule); await _context.SaveChangesAsync(); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); } return(RedirectToAction(nameof(Index))); } ViewData["FromCityID"] = new SelectList(_context.Cities, "CityID", "Name"); ViewData["ToCityID"] = new SelectList(_context.Cities, "CityID", "Name"); return(View(flightSchedule)); }
public int InitialBooking(List <int> tripList, string cabin, int passangers, DateTime bookingDateTime) { using (var transaction = new TransactionScope()) { try { int suspendedID; if (_context.BookingTransactions.Any()) { suspendedID = _context.BookingTransactions.OrderByDescending(b => b.SuspendedID).Select(b => b.SuspendedID).FirstOrDefault() + 1; } else { IncrementCounter incrementCounter = new IncrementCounter(); suspendedID = incrementCounter.NextValue(); //生成一个自动递增的数 } //var bookingDateTime = DateTime.Now; foreach (int tripNo in tripList) { Flight_Schedule flight_Schedule = _context.Flight_Schedules.Where(x => x.Flight_ScheduleID == tripNo).FirstOrDefault(); for (int i = 0; i < passangers; i++) { //generate a specific booking transaction(BookingTransaction) for every passanger //每一个passanger都单独生成一比业务记录(BookingTransaction) BookingTransaction bookingTransaction = new BookingTransaction { BookingDateTime = bookingDateTime, DepartDateTime = flight_Schedule.DepartDateTime, Flight_ScheduleID = flight_Schedule.Flight_ScheduleID, PersonalID = "", SuspendedID = suspendedID, CabinType = (CabinType)Enum.Parse(typeof(CabinType), cabin), Suspended = true }; _context.Add(bookingTransaction); } //_context.SaveChanges(); } //change the booked seats number according the cabin and the nuumber of passengers switch (cabin) { case "Economy": foreach (var t in tripList) { _context.Flight_Schedules.Where(f => f.Flight_ScheduleID == t).ToList().ForEach(f => f.Economy = f.Economy - passangers); } break; case "Business": foreach (var t in tripList) { _context.Flight_Schedules.Where(f => f.Flight_ScheduleID == t).ToList().ForEach(f => f.Business = f.Business - passangers); } break; case "PremEconomy": foreach (var t in tripList) { _context.Flight_Schedules.Where(f => f.Flight_ScheduleID == t).ToList().ForEach(f => f.PremEconomy = f.PremEconomy - passangers); } break; case "First": foreach (var t in tripList) { _context.Flight_Schedules.Where(f => f.Flight_ScheduleID == t).ToList().ForEach(f => f.First = f.First - passangers); } break; } //_context.SaveChanges(); transaction.Complete(); return(suspendedID); } catch (Exception ex) { return(0); } } }
public async Task SearchSchedules(int FromCityID, int ToCityID, string trip, int searchCount, DateTime NextEarliestDepartLimit) { if (searchCount != 0) { Flight_Schedule flight_Schedule = flightContext.Where(x => x.Route.FromCityID == FromCityID) .Where(x => x.Route.ToCityID == ToCityID) .Where(x => x.DepartDateTime > NextEarliestDepartLimit) //(filter out the fights that too late to book)确保只获取晚于当前时间的航班 .Where(x => x.DepartDateTime.Date.ToString("d") == NextEarliestDepartLimit.Date.ToString("d")) .OrderBy(x => x.DepartDateTime) //(get the earliest flight from the candidate flights)取起飞时间最早的转机航班 .FirstOrDefault(); //(get the earliest flight from the candidate flights)取起飞时间最早的转机航班 if (flight_Schedule != null) { //trip.Add(route.RouteID); trip = trip + " " + flight_Schedule.Flight_ScheduleID.ToString(); CandidateTrip cR2 = new CandidateTrip { //List<>类型一定要初始化 RouteList = new List <int>(), stopList = new List <string>(), EntertainmentList = new List <bool>(), WiFiList = new List <bool>(), ACPowerList = new List <bool>(), AirCraftModelList = new List <string>(), AirlineCodeList = new List <string>(), }; cR2.DepartTime = departTime; cR2.ArrivetTime = flight_Schedule.ArriveDateTime; cR2.RouteList = trip.Trim(' ').Split(' ').Select(Int32.Parse).ToList(); AddCities(cR2.stopList, cR2.RouteList, cR2.EntertainmentList, cR2.WiFiList, cR2.ACPowerList, cR2.AirCraftModelList, cR2.AirlineCodeList); //将RouteList中一路经过并转机的城市放入stopList中 //cR2.Entertainment = flight_Schedule.AirCraft.Entertainment; //cR2.ACPower = flight_Schedule.AirCraft.ACPower; tripList.Add(cR2); } else if (searchCount < 2) { //”citiesNameInTrip“ prevents the searching route of recursion algorithm from being a dead loop(one route contains 2 identical cities) //”citiesNameInTrip“防止搜索路线成为一个环(同一条路线中包含两个相同的城市) citiesNameInTrip.Add(FromCityID); //iterate all the adjacent cities, using recursion algorithm in each adjacent city //依次遍历当前节点的所有相邻节点,并逐个进行递归(SearchSchedules) foreach (var t in flightContext.Where(x => x.Route.FromCityID == FromCityID) .Where(x => !citiesNameInTrip.Contains(x.Route.ToCityID)) .Where(x => x.DepartDateTime > NextEarliestDepartLimit) .Where(x => x.DepartDateTime.Date.ToString("d") == NextEarliestDepartLimit.Date.ToString("d")) //(ensure all the results are in the same day)保证在同一天 .GroupBy(x => x.Route.FromCity) .Select(x => x.OrderBy(y => y.DepartDateTime)).Select(x => x.First())) //CAUTION: 取起飞时间最早的转机航班 { //List<int> tripTemp = trip; //tripTemp.Add(t.RouteID); string tripTemp = trip + " " + t.Flight_ScheduleID.ToString(); searchCount++; await SearchSchedules(t.Route.ToCityID, ToCityID, tripTemp, searchCount, t.ArriveDateTime.AddHours(1)); //(ensure there is at least 1 hour in a stop)确保转乘航班间有1个小时的间隔 searchCount--; } citiesNameInTrip.Remove(FromCityID); } } else { IEnumerable <Flight_Schedule> flight_Schedules = flightContext.Where(x => x.Route.FromCityID == FromCityID).Where(x => x.Route.ToCityID == ToCityID); if (flight_Schedules != null) { foreach (var flight_Schedule in flight_Schedules) { CandidateTrip cR = new CandidateTrip { RouteList = new List <int>(), stopList = new List <string>(), EntertainmentList = new List <bool>(), WiFiList = new List <bool>(), ACPowerList = new List <bool>(), AirCraftModelList = new List <string>(), AirlineCodeList = new List <string>(), }; cR.RouteList.Add(flight_Schedule.Flight_ScheduleID); AddCities(cR.stopList, cR.RouteList, cR.EntertainmentList, cR.WiFiList, cR.ACPowerList, cR.AirCraftModelList, cR.AirlineCodeList); cR.DepartTime = flight_Schedule.DepartDateTime; cR.ArrivetTime = flight_Schedule.ArriveDateTime; //cR.Entertainment = flight_Schedule.AirCraft.Entertainment; //cR.ACPower = flight_Schedule.AirCraft.ACPower; tripList.Add(cR); } } citiesNameInTrip.Add(FromCityID); //iterate all the adjacent cities, using recursion algorithm in each adjacent city //依次遍历当前节点的所有相邻节点,并逐个进行递归(SearchSchedules) foreach (var t in flightContext.Where(x => x.Route.FromCityID == FromCityID).Where(x => x.Route.ToCityID != ToCityID)) { //store the depart time of the 1st city as the depart time of a trip //保存第一站的出发时间作为最终路线的出发时间 departTime = t.DepartDateTime; string tripTemp = trip + " " + t.Flight_ScheduleID.ToString(); searchCount++; await SearchSchedules(t.Route.ToCityID, ToCityID, tripTemp, searchCount, t.ArriveDateTime.AddHours(1)); searchCount--; } citiesNameInTrip.Remove(FromCityID); } }