public MainWindow() { InitializeComponent(); #region SetUI Kayak searcher = new Kayak(); foreach (var c in searcher.CountryList) { ListBoxCountries.Items.Add(c.Name); } ListBoxCountries.SelectedValue = "Poland"; CalendarReturn.IsEnabled = false; txtBoxCodeTargetAirport.IsEnabled = true; txtBoxCodeTargetAirport2.IsEnabled = false; txtBoxCodeDepartureAirport.IsEnabled = true; txtBoxCodeDepartureAirport2.IsEnabled = false; chkBoxFlexDepartureDate.IsEnabled = true; chkBoxFlexReturnDate.IsEnabled = false; chkBoxFlexDeparture2.IsEnabled = false; chkBoxFlexTarget2.IsEnabled = false; CalendarDeparture.SelectedDate = DateTime.Today; CalendarReturn.SelectedDate = DateTime.Today.AddDays(7); CalendarDeparture.DisplayDateStart = DateTime.Today; CalendarReturn.DisplayDateStart = DateTime.Today; ListBoxCountries.Focus(); ListBoxCountries.SelectedItem = "Ireland"; #endregion chrome.Source = new Uri("https://www.kayak.de/flights/MLA-GDN,nearby/2015-07-01-flexible"); }
public void CheckFlightsInExternalBrowser(Kayak.FlightTypes flightType) { Kayak searcher = new Kayak(); DateTime DepartureDate = CalendarDeparture.SelectedDate.Value; DateTime ReturnDate = CalendarReturn.SelectedDate.Value; #region Error Check //Error check if (txtBoxCodeDepartureAirport.Text.Length != 3) { MessageBox.Show("Incorrect departure airport code!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); throw new Exception("My error message"); } else if (ListBoxCountries.SelectedItems.Count == 0) { MessageBox.Show("At least one language version must be selected!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if ((txtBoxCodeTargetAirport.Text.Length != 3) || (txtBoxCodeDepartureAirport.Text.Length != 3) || (txtBoxCodeTargetAirport2.Text.Length != 3) || (txtBoxCodeDepartureAirport2.Text.Length != 3)) { MessageBox.Show("Incorrect target airport code!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if (intAdults.Value < 1) { MessageBox.Show("The number of the adults cannot be less than 1!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if (intAdults.Value + intYouth.Value + intChildren.Value + intSeatInfant.Value + intLapInfant.Value > 6) { MessageBox.Show("The number of the passengers cannot exceed 6!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if (chkBoxAllLanguages.IsChecked.Value == true) #endregion { switch (flightType) { case Multisearcher.FlightTypes.OneWay: { for (int i = 0; i < searcher.CountryList.Count; i++) { Process.Start(searcher.OneWayLink(txtBoxCodeDepartureAirport.Text, chkBoxFlexDeparture.IsChecked.Value, txtBoxCodeTargetAirport.Text, chkBoxFlexTarget.IsChecked.Value, Convert.ToInt32(intAdults.Value), Convert.ToInt32(intYouth.Value), Convert.ToInt32(intChildren.Value), Convert.ToInt32(intSeatInfant.Value), Convert.ToInt32(intLapInfant.Value), DepartureDate, chkBoxFlexDepartureDate.IsChecked.Value, searcher.CountryList[i])); } } break; case Multisearcher.FlightTypes.MultiCity: { for (int i = 0; i < searcher.CountryList.Count; i++) { Process.Start(searcher.MultiCityLink(txtBoxCodeDepartureAirport.Text, chkBoxFlexDeparture.IsChecked.Value, txtBoxCodeTargetAirport.Text, chkBoxFlexTarget.IsChecked.Value, txtBoxCodeDepartureAirport2.Text, chkBoxFlexDeparture2.IsChecked.Value, txtBoxCodeTargetAirport2.Text, chkBoxFlexTarget2.IsChecked.Value, Convert.ToInt32(intAdults.Value), Convert.ToInt32(intYouth.Value), Convert.ToInt32(intChildren.Value), Convert.ToInt32(intSeatInfant.Value), Convert.ToInt32(intLapInfant.Value), DepartureDate, ReturnDate, searcher.CountryList[i])); } } break; case Multisearcher.FlightTypes.RoundTrip: { for (int i = 0; i < searcher.CountryList.Count; i++) { Process.Start(searcher.RoundTripLink(txtBoxCodeDepartureAirport.Text, chkBoxFlexDeparture.IsChecked.Value, txtBoxCodeTargetAirport.Text, chkBoxFlexTarget.IsChecked.Value, Convert.ToInt32(intAdults.Value), Convert.ToInt32(intYouth.Value), Convert.ToInt32(intChildren.Value), Convert.ToInt32(intSeatInfant.Value), Convert.ToInt32(intLapInfant.Value), DepartureDate, ReturnDate, chkBoxFlexDepartureDate.IsChecked.Value, chkBoxFlexReturnDate.IsChecked.Value, searcher.CountryList[i])); } } break; } } else { switch (flightType) { case Multisearcher.FlightTypes.OneWay: { foreach (var foo in ListBoxCountries.SelectedItems) { Country result = searcher.CountryList.Find(x => x.Name == foo.ToString()); Process.Start(searcher.OneWayLink(txtBoxCodeDepartureAirport.Text, chkBoxFlexDeparture.IsChecked.Value, txtBoxCodeTargetAirport.Text, chkBoxFlexTarget.IsChecked.Value, Convert.ToInt32(intAdults.Value), Convert.ToInt32(intYouth.Value), Convert.ToInt32(intChildren.Value), Convert.ToInt32(intSeatInfant.Value), Convert.ToInt32(intLapInfant.Value), DepartureDate, chkBoxFlexDepartureDate.IsChecked.Value, result)); } } break; case Multisearcher.FlightTypes.RoundTrip: { foreach (var foo in ListBoxCountries.SelectedItems) { Country result = searcher.CountryList.Find(x => x.Name == foo.ToString()); Process.Start(searcher.RoundTripLink(txtBoxCodeDepartureAirport.Text, chkBoxFlexDeparture.IsChecked.Value, txtBoxCodeTargetAirport.Text, chkBoxFlexTarget.IsChecked.Value, Convert.ToInt32(intAdults.Value), Convert.ToInt32(intYouth.Value), Convert.ToInt32(intChildren.Value), Convert.ToInt32(intSeatInfant.Value), Convert.ToInt32(intLapInfant.Value), DepartureDate, ReturnDate, chkBoxFlexDepartureDate.IsChecked.Value, chkBoxFlexReturnDate.IsChecked.Value, result)); } } break; case Multisearcher.FlightTypes.MultiCity: { foreach (var foo in ListBoxCountries.SelectedItems) { Country result = searcher.CountryList.Find(x => x.Name == foo.ToString()); Process.Start(searcher.MultiCityLink(txtBoxCodeDepartureAirport.Text, chkBoxFlexDeparture.IsChecked.Value, txtBoxCodeTargetAirport.Text, chkBoxFlexTarget.IsChecked.Value, txtBoxCodeDepartureAirport2.Text, chkBoxFlexDeparture2.IsChecked.Value, txtBoxCodeTargetAirport2.Text, chkBoxFlexTarget2.IsChecked.Value, Convert.ToInt32(intAdults.Value), Convert.ToInt32(intYouth.Value), Convert.ToInt32(intChildren.Value), Convert.ToInt32(intSeatInfant.Value), Convert.ToInt32(intLapInfant.Value), DepartureDate, ReturnDate, result)); } } break; } } }