private void FlightsList_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ListView listBox = sender as ListView; ScheduleRow selected = listBox.SelectedItem as ScheduleRow; if (selectedItem != null && selected != null) { //change status editMode = true; DateTime selectedHours = Convert.ToDateTime(selected.Time); this.dateControl.SelectedDate = selectedHours.Date; this.minutesBox.Text = selectedHours.Minute.ToString(); this.hoursBox.Text = selectedHours.Hour.ToString(); this.DepartingBox.SelectedIndex = airports.FindIndex(item => item.AirportCode == selected.Departing); this.ArrivingBox.SelectedIndex = airports.FindIndex(item => item.AirportCode == selected.Arriving); this.delete.IsEnabled = true; selectedItem.ID = selected.ID; selectedItem.Departing = selected.Departing; selectedItem.Arriving = selected.Arriving; selectedItem.Time = selected.Time; this.update.IsEnabled = true; this.create.IsEnabled = true; filterRows(); } }
public static List <ScheduleRow> LoadScheduleRows() { using (var conn = new OleDbConnection(ConnectionObject.connectionString)) { List <ScheduleRow> scheduleRows = new List <ScheduleRow>(); conn.Open(); string selectionString = @"SELECT schedule1.* , air2.Descriptions as DepartingName, air3.Descriptions as ArrivingName FROM((CyanairScheduleExtended schedule1 left join CyanairAirports air2 on air2.[Airport Codes] = schedule1.Departing) left join CyanairAirports air3 on air3.[Airport Codes] = schedule1.Arriving)"; OleDbCommand command = new OleDbCommand(selectionString, conn); OleDbDataReader reader = command.ExecuteReader(); while (reader.Read()) { ScheduleRow scheduleRow = new ScheduleRow(); scheduleRow.ID = reader["id"].ToString(); scheduleRow.Departing = (string)reader["Departing"]; scheduleRow.Arriving = (string)reader["Arriving"]; scheduleRow.Date = reader["Date"].ToString(); scheduleRow.Time = reader["Time"].ToString(); scheduleRow.Economy = reader["Economy"].ToString(); scheduleRow.Business = reader["Business"].ToString(); scheduleRow.First = reader["First"].ToString(); scheduleRow.Duration = reader["Duration"].ToString(); scheduleRow.ArrivingName = reader["ArrivingName"].ToString(); scheduleRow.DepartingName = reader["DepartingName"].ToString(); scheduleRows.Add(scheduleRow); } return(scheduleRows); } }
public static ScheduleRow UpdateFlight(ScheduleRow flight) { OleDbCommand command; using (var conn = new OleDbConnection(ConnectionObject.connectionString)) { conn.Open(); try { command = new OleDbCommand("UPDATE CyanairScheduleExtended SET Departing= @departingVar, Arriving = @arrivingVar, [Time] = @timeVar, [Economy] = @economyVar, Business = @businessVar, [First] = @firstVar WHERE ID = @flightNoVar", conn); command.Parameters.AddWithValue("departingVar", flight.Departing); command.Parameters.AddWithValue("arrivingVar", flight.Arriving); command.Parameters.AddWithValue("timeVar", flight.Time); command.Parameters.AddWithValue("economyVar", 80); command.Parameters.AddWithValue("businessVar", 12); command.Parameters.AddWithValue("firstVar", 8); command.Parameters.AddWithValue("flightNoVar", flight.ID); var mario = command.ExecuteNonQuery(); MessageBox.Show(mario.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } return(flight); }
public static void CreateFlight(ScheduleRow newFlight) { OleDbCommand command; using (var conn = new OleDbConnection(ConnectionObject.connectionString)) { conn.Open(); try { command = new OleDbCommand("INSERT INTO CyanairScheduleExtended (Departing, Arriving, [Time], Economy, Business, [First]) " + "VALUES (@Departing, @Arriving, @Time, @Economy, @Business, @First)", conn); command.Parameters.AddWithValue("Departing", newFlight.Departing); command.Parameters.AddWithValue("Arriving", newFlight.Arriving); command.Parameters.AddWithValue("Time", newFlight.Time); command.Parameters.AddWithValue("Economy", "80"); command.Parameters.AddWithValue("Business", "12"); command.Parameters.AddWithValue("First", "8"); int success = command.ExecuteNonQuery(); MessageBox.Show(success.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
public FlightsPage() { InitializeComponent(); this.dateControl.SelectedDate = DateTime.Now.Date; airports = ConnectionObject.LoadAirports(); //airportDictionary = new Dictionary<string, string>(); //foreach (Airport airport in airports) //{ // airportDictionary.Add( airport.AirportCode, airport.Description); //} selectedItem = new ScheduleRow(); scheduleRows = ConnectionObject.LoadScheduleRows(); editMode = false; //rows = from flight in scheduleRows // select flight; arrivalRows = scheduleRows.Distinct(new compareArrivals()); departureRows = scheduleRows.Distinct(new compareDepartures()); listViewRows = from flight in scheduleRows select flight; this.ArrivingBox.ItemsSource = airports; this.ArrivingBox.DisplayMemberPath = "Description"; //this.DepartingBox.ItemsSource = departureRows; //this.DepartingBox.DisplayMemberPath = "Departing"; this.DepartingBox.ItemsSource = airports; this.DepartingBox.DisplayMemberPath = "Description"; GridView flightsGrid = new GridView(); flightsGrid.AllowsColumnReorder = true; flightsGrid.ColumnHeaderToolTip = "flight Data2"; GridViewColumn departuresColumn = new GridViewColumn(); departuresColumn.DisplayMemberBinding = new Binding("DepartingName"); departuresColumn.Header = "Departing"; departuresColumn.Width = 100; flightsGrid.Columns.Add(departuresColumn); GridViewColumn arrivalsColumn = new GridViewColumn(); arrivalsColumn.Header = "Arriving"; arrivalsColumn.Width = 100; arrivalsColumn.DisplayMemberBinding = new Binding("ArrivingName"); flightsGrid.Columns.Add(arrivalsColumn); GridViewColumn timeColumn = new GridViewColumn(); timeColumn.Header = "Time"; //timeColumn.Width = 100; timeColumn.DisplayMemberBinding = new Binding("Time"); flightsGrid.Columns.Add(timeColumn); this.FlightsList.View = flightsGrid; this.FlightsList.ItemsSource = scheduleRows; }
private void Update_Click(object sender, RoutedEventArgs e) { ConnectionObject.UpdateFlight(this.selectedItem); scheduleRows = ConnectionObject.LoadScheduleRows(); selectedItem = new ScheduleRow(); editMode = false; somethingChanged(); }
private void Delete_Click(object sender, RoutedEventArgs e) { ConnectionObject.RemoveFlight(selectedItem); scheduleRows = ConnectionObject.LoadScheduleRows(); selectedItem = new ScheduleRow(); editMode = false; FlightsList.SelectedItem = null; somethingChanged(); }
private void DeparturesBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ScheduleRow selectedItem = (ScheduleRow)this.departuresBox.SelectedItem; //find flights with matching departure field IEnumerable <ScheduleRow> arrivalRows = from flight in scheduleRows where flight.Departing == selectedItem?.Departing select flight; this.arrivingBox.ItemsSource = arrivalRows.Distinct(new compareArrivals()); this.arrivingBox.DisplayMemberPath = "ArrivingName"; newReservation.Departing = selectedItem?.Departing; }
private void ArrivingBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { ScheduleRow selectedItem = (ScheduleRow)this.arrivingBox.SelectedItem; //find flights with matching departure and arrival fields IEnumerable <ScheduleRow> timeRows = new ScheduleRow[] { }; timeRows = from flight in scheduleRows where flight.Departing == selectedItem?.Departing where flight.Arriving == selectedItem?.Arriving select flight; this.timeBox.ItemsSource = timeRows; this.timeBox.DisplayMemberPath = "Date"; newReservation.Arriving = selectedItem?.Arriving; }
private void cancel_Click(object sender, RoutedEventArgs e) { this.dateControl.SelectedDate = DateTime.Now.Date; listViewRows = from flight in scheduleRows select flight; this.selectedItem = new ScheduleRow(); this.FlightsList.SelectedItem = null; this.DepartingBox.SelectedItem = null; this.ArrivingBox.SelectedItem = null; editMode = false; this.create.IsEnabled = false; this.update.IsEnabled = false; this.dateControl.SelectedDate = DateTime.Now.Date; filterRows(); }
private void TimeBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (this.timeBox.SelectedItem != null) { selectedItem = (ScheduleRow)this.timeBox.SelectedItem; //disable radio buttons for seats that are sold out foreach (KeyValuePair <RadioButton, string> item in radioButtons) { //PropertyInfro.GetValue method to access property stored in a variable int seats = Convert.ToInt32(selectedItem.GetType().GetProperty(item.Value).GetValue(selectedItem, null)); item.Key.IsEnabled = seats == 0 ? false : true; } //update the Reservation object with the selected Time and ID newReservation.Time = selectedItem.Time; newReservation.FlightNo = selectedItem.ID; } }
public static ScheduleRow RemoveSeat(string seatClass, ScheduleRow flight) { OleDbCommand command; int economy = Convert.ToInt32(flight.Economy); int business = Convert.ToInt32(flight.Business); int first = Convert.ToInt32(flight.First); switch (seatClass) { case "Economy": flight.Economy = (Convert.ToInt32(flight.Economy) - 1).ToString(); break; case "Business": flight.Business = (Convert.ToInt32(flight.Business) - 1).ToString(); break; case "First": flight.First = (Convert.ToInt32(flight.First) - 1).ToString(); break; } using (var conn = new OleDbConnection(ConnectionObject.connectionString)) { conn.Open(); try { command = new OleDbCommand("UPDATE CyanairScheduleExtended SET [Economy] = @economyVar, Business = @businessVar, [First] = @firstVar WHERE ID = @flightNoVar", conn); command.Parameters.AddWithValue("economyVar", flight.Economy); command.Parameters.AddWithValue("businessVar", flight.Business); command.Parameters.AddWithValue("firstVar", flight.First); command.Parameters.AddWithValue("flightNoVar", flight.ID); var mario = command.ExecuteNonQuery(); MessageBox.Show(mario.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } return(flight); }
public static ScheduleRow RemoveFlight(ScheduleRow flight) { OleDbCommand command; using (var conn = new OleDbConnection(ConnectionObject.connectionString)) { conn.Open(); try { command = new OleDbCommand("DELETE FROM CyanairScheduleExtended WHERE ID = @flightIDVar", conn); command.Parameters.AddWithValue("flightIDVar", flight.ID); var mario = command.ExecuteNonQuery(); MessageBox.Show(mario.ToString()); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } return(flight); }
private void CreateBooking_Click(object sender, RoutedEventArgs e) { // pick the selected flight from the times combo box ScheduleRow flight = this.timeBox.SelectedItem as ScheduleRow; //updates the reservations table ConnectionObject.CreateBooking(newReservation); //updates the sql database and the local variable ConnectionObject.RemoveSeat(newReservation.SeatClass, flight); string successText = $"Success! You've booked {(newReservation.SeatClass == "Economy" ? "an" : "a")} {newReservation.SeatClass} seat on the flight {selectedItem} for {newReservation.PassengerName}" + $"{System.Environment.NewLine}Reference Number: {newReservation.Reference}"; //reset the reservation object newReservation = new Reservation(); //resubscribe to the new reservation object newReservation.changeChecker.changeMadeEvent += disableBookingButton; //reset the text boxes this.passengerName.Text = null; this.passportNo.Text = null; this.passengerName.Text = null; this.departuresBox.SelectedItem = null; //uncheck all seat class controls foreach (KeyValuePair <RadioButton, string> item in radioButtons) { item.Key.IsChecked = false; } //display the success message this.successMessage.Text = successText; MessageBox.Show(this.successBorder.IsVisible.ToString()); this.successBorder.Visibility = Visibility.Visible; this.successMessage.Visibility = Visibility.Visible; this.UpdateLayout(); }