private void lbPassengers_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { ModelPassenger selPas = (ModelPassenger)lbPassengers.SelectedItem; if (selPas != null) { var data = (from c in lstCst join ps in stkPassengers on c.ID equals ps.customerID join fl in lstFlights on ps.flightID equals fl.ID where ps.ID == selPas.ID select new List <int> { c.ID, fl.ID }).First(); lbCustomers.SelectedValue = data[0]; lbFlights.SelectedValue = data[1]; } } catch { MessageBox.Show("Something went wrong please try again opening Flights Window", "Error code", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { if (Login.isSuperUser == 0) { MessageBox.Show("You are not allowed to perform this operation, Ask SuperUser for help", "Unauthorized access", MessageBoxButton.OK, MessageBoxImage.Hand); return; } ModelPassenger selPass = (ModelPassenger)lbPassengers.SelectedItem; if (selPass == null) { MessageBox.Show("No Flight is selected, please select one from Flights list", "Null reference", MessageBoxButton.OK, MessageBoxImage.Error); return; } var data = (from ps in stkPassengers where ps.ID == selPass.ID && ps.flightID == selPass.flightID select ps).First(); if (data != null) { if (MessageBox.Show("Do you want to DELETE this record?", "Confirm Changes", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { lbPassengers.DataContext = null; Stack <ModelPassenger> temp = new Stack <ModelPassenger>(); while (stkPassengers.Count() > 0) { if (stkPassengers.Peek().ID != data.ID) { temp.Push(stkPassengers.Pop()); } else { stkPassengers.Pop(); break; } } while (temp.Count > 0) { stkPassengers.Push(temp.Pop()); } var newdata = from ps in stkPassengers orderby ps.ID select ps; lbPassengers.DataContext = newdata; } else { return; } } } catch { MessageBox.Show("Unable to delete the record", "Error code", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { try { if (Login.isSuperUser == 0) { MessageBox.Show("You are not allowed to perform this operation, Ask SuperUser for help", "Unauthorized access", MessageBoxButton.OK, MessageBoxImage.Hand); return; } if (lbPassengers.SelectedItem == null || lbFlights.SelectedItem == null || lbCustomers.SelectedItem == null) { MessageBox.Show("No Flights record is selected, please select one from left listboxes", "Attention", MessageBoxButton.OK, MessageBoxImage.Error); return; } ModelPassenger selPass = (ModelPassenger)lbPassengers.SelectedItem; var data = (from ps in stkPassengers where ps.ID == selPass.ID select ps).First(); if (data == null) { MessageBox.Show("Passenger ID is not found please try selecting from left Flights list", "Error code", MessageBoxButton.OK, MessageBoxImage.Error); } else { if (lbPassengers.SelectedItem != null) { if (MessageBox.Show("Do you want to UPDATE this record?", "Confirm Changes", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { lbPassengers.DataContext = null; Stack <ModelPassenger> temp = new Stack <ModelPassenger>(); while (stkPassengers.Count() > 0) { if (stkPassengers.Peek().ID != data.ID) { temp.Push(stkPassengers.Pop()); } else { stkPassengers.Pop(); break; } } stkPassengers.Push(new ModelPassenger(data.ID, (int)lbCustomers.SelectedValue, (int)lbFlights.SelectedValue)); while (temp.Count > 0) { stkPassengers.Push(temp.Pop()); } var newdata = from ps in stkPassengers orderby ps.ID select ps; lbPassengers.DataContext = newdata; } else { MessageBox.Show("No changes made", "Notice", MessageBoxButton.OK, MessageBoxImage.Information); return; } } else { MessageBox.Show("Every field in the form is mandatory, please fill all", "Error code", MessageBoxButton.OK, MessageBoxImage.Error); } } } catch { MessageBox.Show("Something went wrong please try again opening Passengers Window", "Error code", MessageBoxButton.OK, MessageBoxImage.Error); } }