コード例 #1
0
        private void btnAddGuests_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.btnAddGuests.Content.ToString() == "Update Guest")
                {
                    lstBoxViewGuests.Items.Remove(guest.PassportNo);

                    guest.Name       = txtBoxGuestName.Text;
                    guest.Age        = Convert.ToInt32(txtBoxGuestAge.Text);
                    guest.PassportNo = txtBoxPassportNumber.Text;

                    facade.addGuest(guest);

                    lstBoxViewGuests.Items.Add(guest.PassportNo);

                    this.btnAddGuests.IsEnabled = false;
                    this.clearGuestTxtBoxes();

                    this.btnAddGuests.Content = "Add Guest";
                }
                else
                {
                    if (countGuest > 6)
                    {
                        throw new ArgumentException("There are more than 6 guests!");
                    }

                    guest = new Guest();

                    guest.Name       = txtBoxGuestName.Text;
                    guest.Age        = Convert.ToInt32(txtBoxGuestAge.Text);
                    guest.PassportNo = txtBoxPassportNumber.Text;


                    if (lstBoxViewGuests.Items.Contains(guest.PassportNo))
                    {
                        throw new ArgumentException("Can't have two guests with the same passport number!");
                    }

                    countGuest++;

                    facade.addGuest(guest);


                    lstBoxViewGuests.Items.Add(guest.PassportNo);

                    this.btnAddGuests.IsEnabled = false;
                    this.clearGuestTxtBoxes();
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message, "Add Guest");
            }
        }