Ejemplo n.º 1
0
        private void Loadbutton1_Click(object sender, EventArgs e)
        {
            string[] words;
            string   fileName = txtFileName2.Text;

            try
            {
                using (StreamReader reader = new StreamReader(fileName))
                {
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        words = line.Split(',');


                        string type = words[0];

                        Person person = null;
                        switch (words[0])
                        {
                        case "Customer":
                            Address    a = new Address(words[4], words[5], words[6], words[7]);
                            CreditCard c = new CreditCard(int.Parse(words[10]), int.Parse(words[11]), DateTime.Parse(words[12]));

                            person = new Customer(words[1], words[2], words[3], a, words[8], int.Parse(words[9]), c);
                            break;

                        case "Passenger":
                            Passport pass = new Passport(int.Parse(words[6]), words[7], words[8]);
                            Address  addr = new Address(words[9], words[10], words[11], words[12]);
                            person = new Passenger(int.Parse(words[1]), words[2], words[3], words[4], words[5], addr, pass);
                            break;

                        case "Travel Agent":
                            Address b = new Address(words[4], words[5], words[6], words[7]);
                            person = new TravelAgent(words[1], words[2], words[3], b, words[8], int.Parse(words[9]), double.Parse(words[10]), words[11]);
                            break;
                        }
                        TravelAgency.people.Add(person);
                    }
                }
                MessageBox.Show("your file has been loaded");
                this.Close();
            }
            catch (Exception w)
            {
                MessageBox.Show("your file could not be read");
                MessageBox.Show(w.Message);
            }
        }
Ejemplo n.º 2
0
 public void BookSeatOnFlightMethod(int flightnum, DateTime dt, int custid, int passengerid, int seatnum, int empid, double price)
 //custid pays for the flight passengerid flighs
 {
     try
     {
         foreach (Person p in TravelAgency.people)
         {
             if (p is Passenger)
             {
                 Passenger ps = p as Passenger;
                 if (ps.Id == passengerid)
                 {
                     foreach (Passenger pas in ScheduledFlight.passengers)
                     {
                         if (pas.Passport == ps.Passport)//if the passenger is already booked with this passport then throw an exception
                         {
                             throw new DuplicateDataExcception("already booked!");
                         }
                     }
                     foreach (ScheduledFlight flight in TravelAgency.scheduledflights)
                     {
                         if (flight.FlightID == flightnum && flight.DepartureDate == dt)
                         {
                             flight.BookSeatFlight(ps, seatnum);
                             foreach (Person per in TravelAgency.people)
                             {
                                 if (per is TravelAgent)
                                 {
                                     TravelAgent ta = per as TravelAgent;
                                     if (ta.EmployeeID == empid)
                                     {
                                         ta.BookTicket(price);
                                         foreach (Person pers in TravelAgency.people)
                                         {
                                             if (pers is Customer)
                                             {
                                                 Customer cust = pers as Customer;
                                                 if (cust.CustomerID == custid)
                                                 {
                                                     cust.ChargeCard(price, cust.CC.expirationDate);
                                                     MessageBox.Show("Passenger " + ps.FirstName + " " + ps.LastName + " was added to flight " + FlightNumbertextBox.Text);
                                                     MessageBox.Show("your balance is now " + cust.CC.Balance);
                                                     MessageBox.Show("Travel Agents Earnings is now: " + ta.Earnings);
                                                 }//charge card
                                                 else
                                                 {
                                                     throw new NotFoundException("not found");
                                                 }
                                             } //if pers is customer
                                         }     //foreach person pers in people
                                     }         //if travel agent ==empid
                                     else
                                     {
                                         throw new NotFoundException("not found");
                                     }
                                 } //if per is travelagent
                             }     //foreach person per in people
                         }         //if flightid and dep date
                         else
                         {
                             TravelAgency.FindFlight(flightnum, dt);
                         } //exception
                     }     //foreach scheduled flight in flights
                 }         //if id==id
                 else
                 {
                     throw new NotFoundException("no such person");
                 } //exception
             }     //if p is passenger
         }         //foreach person p in peopl
     }             //method bookseatonflight
     catch (Exception a)
     {
         MessageBox.Show(a.Message);
     }
 }
Ejemplo n.º 3
0
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            try //throw this exception if this passenger already exists
            {
                string gender;
                if (FemaleradioButton1.Checked)
                {
                    gender = FemaleradioButton1.Text;
                }
                else
                {
                    gender = MaleradioButton2.Text;
                }

                Address     addr  = new Address(StreetTextBox.Text, CityTextBox.Text, StateTextBox.Text, ZipTextBox.Text);
                TravelAgent trav1 = new TravelAgent(FirstNameTextBox.Text, LastNameTextBox.Text, gender, addr, PhoneNumberTextBox.Text, int.Parse(IDNumberTextBox.Text), double.Parse(EarningstextBox1.Text), SsnTextBox.Text);
                trav1.countofEmployees++;
                foreach (Person p in TravelAgency.people)
                {
                    if (trav1.isEqual(p))
                    {
                        throw new DuplicateDataExcception("Sorry! This Passenger already exists!");
                    }
                }
                string s = " ";

                if (FirstNameTextBox.Text == s || LastNameTextBox.Text == s)
                {
                    throw new InvalidName("Invalid Name");
                }

                if (PhoneNumberTextBox.Text == s)
                {
                    throw new InvalidPhoneNumber("Invalid PhoneNumber");
                }

                if (StreetTextBox.Text == s || CityTextBox.Text == s || StateTextBox.Text == s || ZipTextBox.Text == s)
                {
                    throw new InvalidAddress("Invalid Address");
                }

                if (IDNumberTextBox.Text == s)
                {
                    throw new InvalidDataException("Invalid ID");
                }

                if (SsnTextBox.Text == s)
                {
                    throw new InvalidDataException("Invalid Passport Number");
                }

                if (!FemaleradioButton1.Checked && !MaleradioButton2.Checked)
                {
                    throw new InvalidDataException("Invalid Gender");
                }
                TravelAgency.people.Add(trav1);
                MessageBox.Show("Travel Agent " + FirstNameTextBox.Text + " " + LastNameTextBox.Text + " was added");
                FirstNameTextBox.Clear();
                LastNameTextBox.Clear();
                PhoneNumberTextBox.Clear();
                StreetTextBox.Clear();
                SsnTextBox.Clear();
                CityTextBox.Clear();
                StateTextBox.Clear();
                ZipTextBox.Clear();
                FemaleradioButton1.Checked = false;
                MaleradioButton2.Checked   = false;
                IDNumberTextBox.Clear();
                EarningstextBox1.Clear();
            }
            catch (InvalidName)
            {
                MessageBox.Show("Invalid Name");
            }
            catch (InvalidPhoneNumber)
            {
                MessageBox.Show("Invalid phone Number");
            }
            catch (DuplicateDataExcception ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (OverflowException oe)
            {
                MessageBox.Show(oe.Message);
            }
            catch (FormatException f)
            {
                MessageBox.Show(f.Message);
            }
            catch (Exception q)
            {
                MessageBox.Show(q.Message);
            }
        }