// Ability to cancel a selected flight from the datagrid and remove from our Market Manager Queue List // Will auto refresh when we cancel private void CancelProposalBtn_isClicked(object sender, RoutedEventArgs e) { FlightManifestObj selectedFlightManifestObj = (FlightManifestObj)ApprovalQueueGrid.SelectedItem; App.MarketMangerQueue.Remove(selectedFlightManifestObj); populateDataGrid(); }
//If the market manager doesn't like the flight that a load engineer proposed //Remove the flight from the Market Manager Queue and refresh the dataGrid private void RejectFlightBtn_Click(object sender, RoutedEventArgs e) { FlightManifestObj selectedFlightManifestObj = (FlightManifestObj)ApprovalQueueGrid.SelectedItem; App.MarketMangerQueue.Remove(selectedFlightManifestObj); populateLoadEngineerProposaedFlights(); }
//Handles printing the single flight records for the flight manager //Passes in a specific flight for simplicity public static string printFlightManagerSingleRecords(FlightManifestObj flight) { string record = ""; //Prints flight ID record += $"Flight ID: {flight.flightID}\n\t"; //Prints all users of said flight foreach (UserAccountObj user in flight.bookedUsers) { record += $"{user.firstName} {user.lastName}\n\t"; } return(record); }
internal static string printBoardingPass(FlightManifestObj flight) { string boardingPass = ""; boardingPass += $"Flight ID: {flight.flightID}\n\t"; boardingPass += $"Departure City: \t{flight.originCode}\n\t"; boardingPass += $"Layover City 1: \t{flight.layoverCodeA}\n\t"; boardingPass += $"Layover City 2: \t{flight.layoverCodeB}\n\t"; boardingPass += $"Destination Code: \t{flight.destinationCode}\n\t"; boardingPass += $"Departure Time: \t{flight.departTime}\n\t"; boardingPass += $"Arrival Time: \t\t{flight.arrivalTime}\n\t"; boardingPass += $"Point Reward: \t\t{flight.pointReward}\n\t"; return(boardingPass); }
private void promptForRoundtrip(FlightManifestObj flight) { if (MessageBox.Show("Would you like to book a return trip?", "", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { roundTripFlag = true; ComboBoxItem storeArrive = (ComboBoxItem)ArrivalSelectionBox.SelectedItem; ComboBoxItem storeDepart = (ComboBoxItem)DepartureSelectionBox.SelectedItem; ArrivalSelectionBox.Text = flight.originCode; DepartureSelectionBox.Text = flight.destinationCode; ArriveTimePick.Value = null; DepartTimePick.Value = null; SearchRefresh(); } else { roundTripFlag = false; } }
public static FlightManifestObj applyDiscounts(FlightManifestObj flight) { TimeSpan redEyeStart = new TimeSpan(0, 0, 0); TimeSpan redEyeEnd = new TimeSpan(5, 0, 0); TimeSpan offPkStart = new TimeSpan(8, 0, 0); TimeSpan offPkEnd = new TimeSpan(19, 0, 0); if (flight.departTime.TimeOfDay > redEyeStart && flight.departTime.TimeOfDay < redEyeEnd) { flight.ticketPrice = Math.Round(0.8 * flight.ticketPrice, 2); flight.pointReward = Math.Round(0.8 * flight.pointReward, 2); } else if (flight.departTime.TimeOfDay < offPkStart || flight.arrivalTime.TimeOfDay > offPkEnd) { flight.ticketPrice = Math.Round(0.9 * flight.ticketPrice, 2); flight.pointReward = Math.Round(0.9 * flight.pointReward, 2); } return(flight); }
private void FinalizeWindowBtn_Click(object sender, RoutedEventArgs e) { if (PlaneTypeBox.SelectedItem == null) { MessageBox.Show("Please select a plane!", "Alert!", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (ApprovalQueueGrid.SelectedItem == null) { MessageBox.Show("Please select a flight!", "Alert!", MessageBoxButton.OK, MessageBoxImage.Error); return; } FlightManifestObj selected = (FlightManifestObj)ApprovalQueueGrid.SelectedItem; selected.planeAssigned.planeModel = PlaneTypeBox.SelectedValue.ToString(); selected.planeAssigned.numOfSeats = selected.planeAssigned.getNumOfSeats(); App.FlightPlanDict.Add(selected.flightID, selected); App.MarketMangerQueue.Remove(selected); ApprovalQueueGrid.Items.Refresh(); populateLoadEngineerProposaedFlights(); populateFinalizedFlights(); }
// Allows the Market Manager to remove flights from the customer and refund them if necessary // Will update the Posted Flights list and datagrid to see in real time private void CancelFlightBtn_Click(object sender, RoutedEventArgs e) { FlightManifestObj selected = (FlightManifestObj)PostedFlightsGrid.SelectedItem; //Handles no selection null pointer error if (selected == null) { return; } //Checks each user to see if they had that flight and refunds them their money and updates thier upcoming flight list foreach (var user in App.UserAccountDict) { if (user.Value.upcomingFlights.Contains(selected.flightID)) { user.Value.balance += selected.pointReward; user.Value.upcomingFlights.Remove(selected.flightID); } } //Refreshes both datagrids and moves the canceled flight back to the Load Engineer's Proposed Flights List App.MarketMangerQueue.Add(selected); App.FlightPlanDict.Remove(selected.flightID); populateFinalizedFlights(); populateLoadEngineerProposaedFlights(); }
private void PrintBoardingPassBtn_Click(object sender, RoutedEventArgs e) { //Called if user wants to print the Boarding pass of the selected flight. if (UpcomingFlightsGrid.SelectedItem == null) { //No flight selected, so can't print a pass for the null flight. MessageBox.Show("Please Select a Flight", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } FlightManifestObj selected = (FlightManifestObj)UpcomingFlightsGrid.SelectedItem; //Cast selected item to a FlightManifestObj if (DateTime.Now.AddHours(24) < selected.departTime) { //Can't print a boarding pass prior to 24 hrs before boarding, so deny MessageBox.Show("You are unable to print a boarding pass at this time.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning); return; } else { //Write the boarding pass to the proper location, and prompt the user with the location of the printed pass. FileInfo path = new FileInfo(FileIOLoading.printoutDir); //make path if doesn't exist path.Directory.Create(); //File.WriteAllText(FileIOLoading.BoardingPassPath, JsonConvert.SerializeObject(selected, Formatting.Indented)); //write to path File.WriteAllText(FileIOLoading.BoardingPassPath, printBoardingPass(selected)); MessageBox.Show("Boarding Pass Printed To: C:\\temp\\Printouts\\BoardingPass.txt", "Success!", MessageBoxButton.OK, MessageBoxImage.Information); //let user know return; } }
private void CancelFlightBtn_Click(object sender, RoutedEventArgs e) { //User selected Cancel Flight button, so prompt to confirm if (UpcomingFlightsGrid.SelectedItem == null) { //No flight selected to cancel, so ask the user to select a flight before returning. MessageBox.Show("You must select a flight to cancel.", "Error", MessageBoxButton.OK, MessageBoxImage.Warning); return; } FlightManifestObj selected = (FlightManifestObj)UpcomingFlightsGrid.SelectedItem; //Cast selected item to a FlightManifestObj if (DateTime.Now.AddHours(1) >= selected.departTime) { //Flight is within 1 hour of departure and cannot be cancelled. MessageBox.Show("You cannot cancel a flight within 1 hour of departure!", "Warning", MessageBoxButton.OK, MessageBoxImage.Hand); return; } //otherwise, add the flight to canceled list and remove from upcoming. App.LoggedInUser.canceledFlights.Add(selected.flightID); App.LoggedInUser.upcomingFlights.Remove(selected.flightID); App.LoggedInUser.balance += selected.pointReward * 10; //Credit the user for money or points spent on ticket App.FlightPlanDict[selected.flightID].bookedUsers.Remove(App.LoggedInUser); //remove the user from the Flight Manifest MessageBox.Show("Flight Canceled!", "Alert", MessageBoxButton.OK, MessageBoxImage.Information); //Let user know flight was cancelled. UpcomingFlightsGrid.SelectedItem = null; UpcomingFlightsGrid.ItemsSource = LoadUpcomingFlights(); }
//Check and See if Departure Date is before Arrival Date. //Check Locations and Make sure Locations are not the same. //Populate List for Flight Manager Approval //If anything is not correct, highlight the wrong thing and display the correct error text. private void FlightProposeBtn_isClicked(object sender, RoutedEventArgs e) { FlightManifestObj proposedFlightManifestObj = new FlightManifestObj(); DateTime parsedDepartDate, parsedArrivalDate; string departureDateTime; string departureLocation, arrivalLocation; //Set Locations ComboBoxItem comboBoxItem = (ComboBoxItem)DepartureCitiesComboBox.SelectedItem; if (comboBoxItem == null) { //If we have not selected a departed value, highlight the departed box red DepartureCitiesBorderCB.BorderBrush = Brushes.Red; departureLocation = null; return; } else { departureLocation = comboBoxItem.Content.ToString(); } if (ArrivalCitiesComboBox.SelectedItem == null) { //If we have not selected an arrival value, set the arrival box to red. ArrivalCitiesBorderCB.BorderBrush = Brushes.Red; arrivalLocation = null; return; } else { arrivalLocation = ArrivalCitiesComboBox.SelectedItem.ToString(); } //Getting departure date time departureDateTime = DepartureDateTimePicker.Text; if (departureDateTime == null) { //If we have not selected a departure time, highlight the departure timeBox red. DepartureDateTimePicker.BorderBrush = Brushes.Red; parsedDepartDate = DateTime.Today; return; } else { parsedDepartDate = DateTime.Parse(departureDateTime); } //filling in our proposed flight fields and then using our graph to set Layovers proposedFlightManifestObj.originCode = departureLocation; proposedFlightManifestObj.destinationCode = arrivalLocation; int begin = convertLocationsToInt(proposedFlightManifestObj.originCode); int end = convertLocationsToInt(proposedFlightManifestObj.destinationCode); FlightManifestObj planWithLayovers = App.findShortestPath(proposedFlightManifestObj, begin, end); //Setting ArrivalTime based on Departure Time parsedArrivalDate = setArrivalTimeBasedOnDepartureTime(parsedDepartDate, departureLocation, arrivalLocation, planWithLayovers.layoverCodeA, planWithLayovers.layoverCodeB); //Set Arrival Date to 1/1/ThisYear if the previous method failed somehow if (parsedArrivalDate == null) { parsedArrivalDate = DateTime.MinValue; } //If we have a real arrival date, then generate a random 6 digit flight ID. if (!parsedArrivalDate.Equals(DateTime.MinValue)) { Random generator = new Random(); string genNum; genNum = generator.Next(0, 1000000).ToString("000000"); for (int i = 0; i < App.MarketMangerQueue.Count; i++) { if (genNum.Equals(App.MarketMangerQueue.ElementAt(i).flightID)) { genNum = generator.Next(0, 1000000).ToString("000000"); i = 0; } } // Set more fields for the proposed flight proposedFlightManifestObj.flightID = genNum; proposedFlightManifestObj.departTime = parsedDepartDate; proposedFlightManifestObj.arrivalTime = parsedArrivalDate; // Apply red eye and off peak discounts if needed planWithLayovers = App.applyDiscounts(planWithLayovers); // Add our flight to the list of proposed flights App.MarketMangerQueue.Add(planWithLayovers); // Refresh the datagrid which should have our new flight visible now. populateDataGrid(); Console.WriteLine(App.MarketMangerQueue.Count); } else { //If we fail to set a correct arrival time, then send the message box. //We should never reach this point, but if somehow the user manages to get here, this is the failsafe. MessageBox.Show("arrivalTime Did not set correctly."); } }
public static FlightManifestObj findShortestPath(FlightManifestObj flightPlan, int begin, int end) { if (begin > 14 || begin < 0) { return(flightPlan); } if (end > 14 || end < 0) { return(flightPlan); } double miles = 0; double minMiles = 0; //no layovers if (flightGraph[begin, end] != 0) { miles = flightGraph[begin, end]; flightPlan.ticketPrice = Math.Round(50 + (0.12 * miles), 2); flightPlan.pointReward = Math.Round(10 * flightPlan.ticketPrice, 2); flightPlan.layoverCodeA = "N/A"; flightPlan.layoverCodeB = "N/A"; return(flightPlan); } //will go through every possible path and save the shortest one else { for (int i = 0; i < 15; i++) { if (flightGraph[begin, i] != 0) { //1 layover if (flightGraph[i, end] != 0) { miles = (flightGraph[begin, i] + flightGraph[i, end]); if (minMiles > miles || minMiles == 0) { minMiles = miles; flightPlan.ticketPrice = Math.Round((0.12 * miles) + 58, 2); flightPlan.pointReward = Math.Round(10 * flightPlan.ticketPrice, 2); flightPlan.layoverCodeA = intToCode(i); flightPlan.layoverCodeB = "N/A"; } } //2 layovers else { for (int j = 0; j < 15; j++) { if (flightGraph[i, j] != 0) { if (flightGraph[j, end] != 0) { miles = (flightGraph[begin, i] + flightGraph[i, j] + flightGraph[j, end]); if (minMiles > miles || minMiles == 0) { minMiles = miles; flightPlan.ticketPrice = Math.Round((0.12 * miles) + 66, 2); flightPlan.pointReward = Math.Round(10 * flightPlan.ticketPrice, 2); flightPlan.layoverCodeA = intToCode(i); flightPlan.layoverCodeB = intToCode(j); } } } } } } } } return(flightPlan); }
private void BookFlightButton_Click(object sender, RoutedEventArgs e) { //Finalizes booking a user on a flight they've selected from the DataGrid if (FoundFlightsGrid.SelectedItem == null) //They haven't selected a flight, so ask them to do so. { MessageBox.Show("Please select an item.", "Alert", MessageBoxButton.OK, MessageBoxImage.Warning); return; } else { FlightManifestObj selected = (FlightManifestObj)FoundFlightsGrid.SelectedItem; //load selected object into memory as a FlightManifestObj for access if (selected.bookedUsers.Count >= selected.planeAssigned.numOfSeats) //Double check to make sure there isn't any overbooking { MessageBox.Show("There are no seats remaining for this flight", "Alert", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (App.LoggedInUser.upcomingFlights.Contains(selected.flightID))//Double check to make sure the user hasn't already booked this flight. { MessageBox.Show("You've already booked this flight!", "Warning", MessageBoxButton.OK); return; //already booked } //Confirm with the user, then book the flight if (MessageBox.Show("Are you sure you want to book the following flight? \n Flight ID: " + selected.flightID + "\n Departs From: " + selected.originCode + "\n Departure Time: " + selected.departTime.ToLongDateString(), "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //User selected no, so don't book flight Console.WriteLine("Selected \"no\", no flight booked"); return; } else { //User selected yes, so book the flight App.UserAccountDict[App.LoggedInUser.uniqueID].upcomingFlights.Add(selected.flightID.ToString()); //Add the flightID to the logged in user App.FlightPlanDict[selected.flightID].bookedUsers.Add(App.UserAccountDict[App.LoggedInUser.uniqueID]); //Add the user to the selected flight if ((App.LoggedInUser.balance * 100) > selected.ticketPrice) { //User has enough points that they can pay via points, so ask if they want to pay this way. if ((MessageBox.Show("Would you like to use your Points? \n Flight Price: " + selected.ticketPrice + "\n Account Balance: " + App.LoggedInUser.balance, "Question", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)) { //Selected no, so don't use points //Make and add transaction object to show purchase history TransactionObj newTransact = new TransactionObj(); newTransact.FlightUID = selected; newTransact.UserUID = App.LoggedInUser.uniqueID; newTransact.transactionAmt = selected.ticketPrice; App.TransactionHist.Add(newTransact); if (roundTripFlag == false) { promptForRoundtrip(selected); } } else { //Selected yes, so does use points //Make transaction object, use 0 as amount to show they used points TransactionObj newTransact = new TransactionObj(); newTransact.FlightUID = selected; newTransact.UserUID = App.LoggedInUser.uniqueID; newTransact.transactionAmt = 0; App.TransactionHist.Add(newTransact); //Subtract ticket amount from points balance App.UserAccountDict[App.LoggedInUser.uniqueID].balance = App.UserAccountDict[App.LoggedInUser.uniqueID].balance - (selected.ticketPrice * 100); if (roundTripFlag == false) { promptForRoundtrip(selected); } } } else { //Books flight without using points -- because the user doesn't have enough! TransactionObj newTransact = new TransactionObj(); newTransact.FlightUID = selected; newTransact.UserUID = App.LoggedInUser.uniqueID; newTransact.transactionAmt = selected.ticketPrice; App.TransactionHist.Add(newTransact); if (roundTripFlag == false) { promptForRoundtrip(selected); } } m_parent.UpcomingFlightsGrid.ItemsSource = m_parent.LoadUpcomingFlights(); //FoundFlightsGrid.ItemsSource = LoadAllFlights(); if (endPage == true || roundTripFlag == false) { this.Close(); } if (roundTripFlag == true) { endPage = true; } //Put logic here for round trip -------- for each to find a flight with criteria } } }