コード例 #1
0
        private async void btnSearchApply_Click(object sender, EventArgs e)
        {
            var errText      = string.Empty;
            var from         = cmbxSearchFrom.SelectedItem as Airport;
            var to           = cmbxSearchTo.SelectedItem as Airport;
            var cabinType    = cmbxSearchCabinType.SelectedItem as CabinType;
            var isWithReturn = rbntSearchReturn.Checked;
            var outboundDate = dtpSearchOutbound.Value;
            var returnDate   = dtpSearchReturn.Value;
            var nDaysBeforeAndAfterOutbound = cbxIsNDaysBeforeAndAfterOutbound.Checked ? 3 : 0;
            var nDaysBeforeAndAfterReturn   = cbxIsNDaysBeforeAndAfterReturn.Checked ? 3 : 0;

            #region Validation
            if (from == null)
            {
                errText += "From airport is invalid\n";
            }
            if (to == null)
            {
                errText += "To airport is invalid\n";
            }
            if (from != null && to != null && from == to)
            {
                errText += "From and To airport must not be the same\n";
            }
            if (cabinType == null)
            {
                errText += "Cabin type is invalid\n";
            }
            if (returnDate <= outboundDate)
            {
                errText += "Return date must be after outbound\n";
            }

            if (!string.IsNullOrWhiteSpace(errText))
            {
                MessageBox.Show(errText);
                return;
            }
            #endregion

            FlightsSearchOptions = new FlightsSearchOptions()
            {
                From         = from,
                To           = to,
                CabinType    = cabinType,
                IsWithReturn = isWithReturn,
                OutboundDate = outboundDate,
                ReturnDate   = returnDate,
                NDaysBeforeAndAfterOutbound = nDaysBeforeAndAfterOutbound,
                NDaysBeforeAndAfterReturn   = nDaysBeforeAndAfterReturn,
            };
            var searcher     = new FlightsSearcher(FlightsSearchOptions);
            var searchResult = await searcher.Search();

            outboundFlightBindingSource.DataSource = new SortableBindingList <Flight>(searchResult.OutboundFlights);
            returnFlightBindingSource.DataSource   = new SortableBindingList <Flight>(searchResult.ReturnFlights);
        }
コード例 #2
0
 public frmSearchFlights()
 {
     InitializeComponent();
     FlightsSearchOptions = new FlightsSearchOptions();
 }