Пример #1
0
        private void btnScan_Click(object sender, EventArgs e)
        {
            try
            {
                CheckInManager cm = new CheckInManager();

                currentFindPassengerResult = cm.FindPassenger(txtBoardingPassString.Text);
                if (currentFindPassengerResult.IsSuccess)
                {
                    UpdatePNROnUI(currentFindPassengerResult);
                }
                else
                {
                    MessageBox.Show(currentFindPassengerResult.Error, "Passenger Service Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                // use online parser if passenger service is down
                // this can be used only to see boarding pass data
                // for operations lile checkin, passenger service must work
                var confirmResult = MessageBox.Show("Passenger service failed to scan the boarding pass due to the error " + ex.Message + Environment.NewLine +
                                                    "Do you want to use the online parser to parse the boarding pass?", "Confirm!",
                                                    MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    currentFindPassengerResult = BoardingPassParsor.ParseBoardingString(txtBoardingPassString.Text);
                    if (currentFindPassengerResult.IsSuccess)
                    {
                        UpdatePNROnUI(currentFindPassengerResult);
                    }
                    else
                    {
                        MessageBox.Show(currentFindPassengerResult.Error, "Parsing Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    currentFindPassengerResult.IsSuccess = false; // set success to false to make sure checkin is not allowed
                }
            }
        }
Пример #2
0
        private void UpdatePNROnUI(FindPassengerResult findPassengerResult)
        {
            // Load Passenger Information
            txtName.Text          = findPassengerResult.PassengerNameRecord.FirstName + " " + findPassengerResult.PassengerNameRecord.LastName;
            txtTravelClass.Text   = findPassengerResult.PassengerNameRecord.TravelClass;
            txtCheckInStatus.Text = findPassengerResult.PassengerNameRecord.CheckedIn ? "Yes" : "No";
            txtAllowance.Text     = findPassengerResult.PassengerNameRecord.Allowance.ToString();
            if (findPassengerResult.PassengerNameRecord.Allowance > 0)
            {
                nmrBags.Value = 1;
            }
            else
            {
                nmrBags.Value = 0;
            }

            // Load flight information
            gvFlights.DataSource = findPassengerResult.PassengerNameRecord.Flights;

            gvFlights.Enabled  = false;
            pnlPNR.Visible     = true;
            pnlFlights.Visible = true;
        }
Пример #3
0
        /// <summary>
        /// Parse boarding pass string and store in FindPassengerResult object
        /// </summary>
        /// <param name="boardingPassStr">Boarding pass string.</param>
        /// <returns></returns>
        public static FindPassengerResult ParseBoardingString(string boardingPassStr)
        {
            FindPassengerResult findPassengerResult = new FindPassengerResult();
            PassengerNameRecord pnr = new PassengerNameRecord();

            try
            {
                using (WebClient wc = new WebClient())
                {
                    var uri = new Uri(ConfigurationManager.AppSettings["BoardingPassParserUrl"] +
                                      boardingPassStr.Replace("/", "%2F"));

                    var     json_data = wc.DownloadString(uri);
                    dynamic jdata     = JObject.Parse(json_data);

                    // loop through unique mandatory to find passenger information
                    foreach (var uniqueMandatory in jdata.unique.mandatory)
                    {
                        foreach (var item in uniqueMandatory)
                        {
                            var description = item.description.Value.ToString();
                            var value       = item.raw.Value;

                            switch (description)
                            {
                            case "Passenger Name":
                                var firstNameWithTitle = value.Split('/')[1].TrimEnd(' ');
                                if (firstNameWithTitle.EndsWith("MR"))
                                {
                                    pnr.FirstName = firstNameWithTitle.Substring(0, firstNameWithTitle.Length - "MR".Length);
                                }
                                if (firstNameWithTitle.EndsWith("MRS"))
                                {
                                    pnr.FirstName = firstNameWithTitle.Substring(0, firstNameWithTitle.Length - "MRS".Length);
                                }
                                pnr.LastName = value.Split('/')[0].TrimEnd(' ');
                                break;

                            default:
                                break;
                            }
                        }

                        List <Flight> flights = new List <Flight>();
                        // loop through reapead mandatory to find flight information
                        foreach (var repeated in jdata.repeated)
                        {
                            Flight f = new Flight();
                            foreach (var repeatedMandatory in repeated.mandatory)
                            {
                                foreach (var item in repeatedMandatory)
                                {
                                    var description = item.description.Value.ToString();
                                    var value       = item.raw.Value;

                                    switch (description)
                                    {
                                    case "Operating Carrier PNR Code":
                                        break;

                                    case "From City Airport Code":
                                        f.Origin = value;
                                        break;

                                    case "To City Airport Code":
                                        f.Destination = value;
                                        break;

                                    case "Operating Carrier Designator":
                                        break;

                                    case "Flight Number":
                                        f.FlightNumber = value.Trim();
                                        break;

                                    case "Date of Flight":
                                        break;

                                    case "Compartment Code":
                                        pnr.TravelClass = value;
                                        break;

                                    case "Seat Number":
                                        break;

                                    case "Check-In Sequence Number":
                                        break;

                                    case "Passenger Status":
                                        pnr.CheckedIn = value.Equals("1") ? true : false;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            flights.Add(f);
                        }
                        pnr.Flights = flights.ToArray();
                    }
                }

                findPassengerResult.PassengerNameRecord = pnr;
                findPassengerResult.IsSuccess           = true;
            }
            catch (Exception ex)
            {
                findPassengerResult.Error     = "No Passenger Found";
                findPassengerResult.IsSuccess = false;
                logger.Error(ex);
            }

            return(findPassengerResult);
        }