private void DeleteFlight() { if (SelectedFlight != null) { string message = "Delete flight" + SelectedFlight.TripNumber + " " + SelectedFlight.TownFrom + "-" + SelectedFlight.TownTo + " on " + SelectedFlight.Date + " without possibility of recovery?"; string caption = "Delete Flight"; DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes && SelectedFlight != null && SelectedFlight.DepOrArrFlag.Equals("departure")) { FlightsViewModel.DeleteFlight(SelectedFlight); Departures.Remove(SelectedFlight); SelectedDepFlight = null; DepFlightDetailsVisibility = "Hidden"; ShowFlightDetails("departure"); } if (result == DialogResult.Yes && SelectedFlight != null && SelectedFlight.DepOrArrFlag.Equals("arrival")) { FlightsViewModel.DeleteFlight(SelectedFlight); Arrivals.Remove(SelectedFlight); SelectedArrFlight = null; ArrFlightDetailsVisibility = "Hidden"; ShowFlightDetails("arrival"); } } }
private void GetUIDataFromDB() { FlightsViewModel.GetAllCities().ForEach(c => CitiesList.Add(c)); CitiesList.Insert(0, "Not selected"); SelectedCity = CitiesList[0]; FlightsViewModel.GetAllCompanies().ForEach(c => CompaniesList.Add(c.name)); CompaniesList.Insert(0, "Not selected"); SelectedCompany = CompaniesList[0]; SelectTrips(); }
private void AddNewFlight() { TripModel newFlight = FlightsViewModel.CreateNewFlight(); if (newFlight != null) { if (newFlight.DepOrArrFlag.Equals("departure")) { Departures.Add(newFlight); SelectedFlight = Departures.Last(); } else if (newFlight.DepOrArrFlag.Equals("arrival")) { Arrivals.Add(newFlight); SelectedFlight = Arrivals.Last(); } } }
private void EditFlight() { TripModel changedFlight = FlightsViewModel.EditFlight(SelectedFlight); if (changedFlight != null) { if (changedFlight.DepOrArrFlag.Equals("departure")) { int n = Departures.IndexOf(SelectedFlight); Departures.Remove(SelectedDepFlight); Departures.Insert(n, changedFlight); SelectedFlight = Departures[n]; } else { int n = Arrivals.IndexOf(SelectedFlight); Arrivals[n] = new TripModel(changedFlight); SelectedFlight = Arrivals[n]; } } }
private void SelectTrips() { List <TripModel> depList = new List <TripModel>(); List <TripModel> arrsList = new List <TripModel>(); if (SelectedCity != "Not selected" && SelectedCompany != "Not selected") { FlightsViewModel.GetFlights(SelectedCity, SelectedCompany, ref depList, ref arrsList); foreach (var t in depList) { Departures.Add(t); } if (Departures.Count == 1) { SelectedFiltersDep = "Found " + Departures.Count + " flight " + " from " + SelectedCity + " by " + SelectedCompany + "."; } else { SelectedFiltersDep = "Found " + Departures.Count + " flights " + " from " + SelectedCity + " by " + SelectedCompany + "."; } foreach (var t in arrsList) { Arrivals.Add(t); } if (Arrivals.Count == 1) { SelectedFiltersArr = "Found " + Arrivals.Count + " flight " + " to " + SelectedCity + " by " + SelectedCompany + "."; } else { SelectedFiltersArr = "Found " + Arrivals.Count + " flights " + " to " + SelectedCity + " by " + SelectedCompany + "."; } SelectedFiltersVisibility = "Visible"; } else if (SelectedCity == "Not selected" && SelectedCompany != "Not selected") { FlightsViewModel.GetFlights(null, SelectedCompany, ref depList, ref arrsList); foreach (var t in depList) { Departures.Add(t); } if (Departures.Count == 1) { SelectedFiltersDep = "Found " + Departures.Count + " departure " + " by " + SelectedCompany + "."; } else { SelectedFiltersDep = "Found " + Departures.Count + " departures " + " by " + SelectedCompany + "."; } foreach (var t in arrsList) { Arrivals.Add(t); } if (Arrivals.Count == 1) { SelectedFiltersArr = "Found " + Arrivals.Count + " arrival " + " by " + SelectedCompany + "."; } else { SelectedFiltersArr = "Found " + Arrivals.Count + " arrivals " + " by " + SelectedCompany + "."; } SelectedFiltersVisibility = "Visible"; } else if (SelectedCity != "Not selected" && SelectedCompany == "Not selected") { FlightsViewModel.GetFlights(SelectedCity, null, ref depList, ref arrsList); foreach (var t in depList) { Departures.Add(t); } if (Departures.Count == 1) { SelectedFiltersDep = "Found " + Departures.Count + " flight " + " from " + SelectedCity + "."; } else { SelectedFiltersDep = "Found " + Departures.Count + " flights " + " from " + SelectedCity + "."; } foreach (var t in arrsList) { Arrivals.Add(t); } SelectedFiltersArr = "Found " + Arrivals.Count + " flights " + " to " + SelectedCity + "."; SelectedFiltersVisibility = "Visible"; } else { FlightsViewModel.GetFlights(null, null, ref depList, ref arrsList); foreach (var t in depList) { Departures.Add(t); } foreach (var t in arrsList) { Arrivals.Add(t); } SelectedFiltersVisibility = "Hidden"; } }