//Print a selected flight's income, flightID, users on said flight to a text file private void PrintSelectedBtn_Click(object sender, RoutedEventArgs e) { TransactionObj selected = (TransactionObj)AccountingObjDataGrid.SelectedItem; //Handles a no selection null pointer error if (selected == null) { MessageBox.Show("Please select a flight", "Alert!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } //Prints the information needed for a single flight for the accountant MessageBox.Show("Printed: One object to C:\\temp\\Printouts\\SingleSelection.txt"); File.WriteAllText(FileIOLoading.AccountantSinglePath, printAccountantSingleRecords(selected)); selected = null; //will unselect in the datagrid AccountingObjDataGrid.SelectedItem = null; }
//Prints out a single flight's income, percentage of plane filled up, and the flight ID internal static string printAccountantSingleRecords(TransactionObj flight) { string record = ""; double percentOfSeats = 0; double totalBalance = 0; percentOfSeats = (flight.FlightUID.bookedUsers.Count / flight.FlightUID.planeAssigned.numOfSeats) * 100; percentOfSeats = Math.Round(percentOfSeats, 2); totalBalance += flight.transactionAmt; totalBalance = Math.Round(totalBalance, 2); List<FlightManifestObj> flightList = new List<FlightManifestObj>(); flightList.AddRange(App.FlightHistoryDictionary.Values); record += $"Flight ID: {flight.FlightUID.flightID}\n\t"; record += $"Percentage of Seats Taken: {percentOfSeats}\n\t"; record += $"Total Income of Flight: {totalBalance}\n\n"; return record; }
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 } } }