예제 #1
0
        private void button2_Click(object sender, EventArgs e) //add guest
        {
            if ((myState == FormState.Add) || ((myState == FormState.WhileBooking) && button2.Text == "Add Guest") ||
                (myState == FormState.Edit))
            {
                Regex validateEmail = new Regex(@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
                                                @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$");


                //https://msdn.microsoft.com/en-us/library/01escwtf(v=vs.110).aspx



                Regex testForNonNumeric = new Regex(@"\D");

                Regex testForLetters = new Regex(@"^[a-zA-Z ]+$"); // @"^[a-zA-Z ]+$" for space character



                if (FirstNameTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter First Name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //https://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxicon(v=vs.110).aspx
                    FirstNameTextBox.Focus(); //focuses on text box with error

                    return;
                }

                else if (LastNameTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter Last Name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    LastNameTextBox.Focus();
                    return;
                }



                else if (TelephoneTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter Your Telephone Number", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (TelephoneTextBox.TextLength < 10)
                {
                    MessageBox.Show("Telephone number must contains 10 digits", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (TelephoneTextBox.TextLength > 10)
                {
                    MessageBox.Show("Telephone number must contains 10 digits", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (testForNonNumeric.IsMatch(TelephoneTextBox.Text))
                {
                    MessageBox.Show("Telephone number must contain digits only", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    TelephoneTextBox.Focus();
                    return;
                }

                else if (EmailTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter An Email Address", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    EmailTextBox.Focus();
                    return;
                }

                else if (!validateEmail.IsMatch(EmailTextBox.Text))
                {
                    MessageBox.Show("Invalid Email Address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    EmailTextBox.Focus();
                    return;
                }


                else
                {
                    //go to next form
                    if (myState == FormState.Add)
                    {
                        guest = PopulateObject();
                        guestController.ADD(guest);
                        MessageBox.Show("Guest successfully added", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ClearAll();
                        this.Hide();
                    }
                    if (myState == FormState.WhileBooking)
                    {
                        guest = PopulateObject();
                        aBooking.DepositPaid = "false";
                        aBooking.GuestID     = guest.GuestID;

                        bookingController.ADD(aBooking);
                        guestController.ADD(guest);
                        MessageBox.Show("Guest successfully added and booking successfully made", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);


                        //would they like to pay now
                        DialogResult result = MessageBox.Show("Would you like to pay now", "Pay now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            PaymentDetailsForm paymentDetailsForm = new PaymentDetailsForm(paymentController,
                                                                                           aBooking, guest, bookingController);
                            paymentDetailsForm.MdiParent     = (Home)this.MdiParent;    // Setting the MDI Parent
                            paymentDetailsForm.StartPosition = FormStartPosition.CenterParent;
                            this.Hide();
                            paymentDetailsForm.Show();
                        }
                        else
                        {
                            //go straight to the email

                            ConfirmationForm cf = new ConfirmationForm(guest, aBooking);

                            cf.StartPosition = FormStartPosition.CenterParent;
                            cf.Show();
                            this.Hide();
                        }
                        ClearAll();
                    }
                    if (myState == FormState.Edit)
                    {
                        Guest g = new Guest();
                        g.GuestID   = textBox1.Text;
                        g.FirstName = FirstNameTextBox.Text;
                        g.Surname   = LastNameTextBox.Text;

                        g.TelephoneNumber = TelephoneTextBox.Text;
                        g.EmailAddress    = EmailTextBox.Text;


                        DialogResult result = MessageBox.Show("Are you sure you want to edit guest", "Edit Guest", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                        //populate the text boxes
                        if (result == DialogResult.Yes)
                        {
                            //we must delete the guest tell them guest has been successfully deleted
                            guestController.Edit(g);
                            MessageBox.Show("Guest successfully editted", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearAll();

                            this.Hide();
                        }
                        else
                        {
                            //reset the controls
                            showRequiredFields(FormState.Edit);
                        }
                    }
                }
            }

            else if (((myState == FormState.WhileBooking) && (button2.Text == "Verify Guest")) || (myState == FormState.Delete))
            {
                if (GuestIDTextBox.Text == "")
                {
                    MessageBox.Show("Please Enter A Guest ID to search for", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    GuestIDTextBox.Focus();
                    return;
                }
                else if (guestController.FindByGuestID(GuestIDTextBox.Text) == null)
                {
                    MessageBox.Show("Guest not found", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    GuestIDTextBox.Focus();
                    return;
                }
                else
                {
                    Guest temp = guestController.FindByGuestID(GuestIDTextBox.Text);
                    FirstNameTextBox.Text = temp.FirstName;
                    LastNameTextBox.Text  = temp.Surname;

                    TelephoneTextBox.Text = temp.TelephoneNumber;

                    EmailTextBox.Text   = temp.EmailAddress;
                    GuestIDTextBox.Text = temp.GuestID;


                    if (myState == FormState.WhileBooking)
                    {
                        MessageBox.Show("Guest has been verified", "Verified", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //add the booking
                        aBooking.GuestID     = temp.GuestID;
                        aBooking.DepositPaid = "false";
                        bookingController.ADD(aBooking);
                        MessageBox.Show("Booking has been successfully made", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);


                        //populate the text boxes
                        DialogResult result = MessageBox.Show("Would you like to pay now", "Pay now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            PaymentDetailsForm paymentDetailsForm = new PaymentDetailsForm(paymentController, aBooking, temp, bookingController);
                            paymentDetailsForm.MdiParent     = (Home)this.MdiParent;        // Setting the MDI Parent
                            paymentDetailsForm.StartPosition = FormStartPosition.CenterParent;
                            this.Hide();
                            paymentDetailsForm.Show();
                        }
                        else
                        {
                            //go straight to the email

                            ConfirmationForm cf = new ConfirmationForm(temp, aBooking);

                            cf.StartPosition = FormStartPosition.CenterParent;
                            cf.Show();
                            this.Hide();
                        }
                    }
                    if (myState == FormState.Delete)
                    {
                        DialogResult result = MessageBox.Show("Are you sure you want to delete guest", "Delete guest", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                        //populate the text boxes
                        if (result == DialogResult.Yes)
                        {
                            //we must delete the guest tell them guest has been successfully deleted
                            guestController.Delete(temp);
                            MessageBox.Show("Guest has been deleted", "Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            this.Hide();
                        }
                        else
                        {
                            //reset the controls
                            showRequiredFields(FormState.Delete);
                        }
                    }
                }
            }
        }
예제 #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            //check if the field is empty
            if (GuestIDTextBox.Text == "")
            {
                MessageBox.Show("Please input a guestID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //https://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxicon(v=vs.110).aspx
                FirstNameTextBox.Focus(); //focuses on text box with error

                return;
            }
            //if the guest doesnt exist
            else if (guestController.FindByGuestID(GuestIDTextBox.Text) == null)
            {
                MessageBox.Show("Guest not found", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                GuestIDTextBox.Focus();
                return;
            }
            //if the guest exists
            else
            {
                Guest temp = guestController.FindByGuestID(GuestIDTextBox.Text);
                label10.Visible = true;
                label11.Visible = true;
                label12.Visible = true;
                label17.Visible = true;
                label18.Visible = true;
                label19.Visible = false;

                FirstNameTextBox.Visible = true;
                LastNameTextBox.Visible  = true;

                TelephoneTextBox.Visible = true;

                EmailTextBox.Visible = true;



                GuestIDTextBox.Visible = false;
                button3.Visible        = false;

                FirstNameTextBox.Text = temp.FirstName;
                LastNameTextBox.Text  = temp.Surname;

                TelephoneTextBox.Text = temp.TelephoneNumber;

                EmailTextBox.Text = temp.EmailAddress;

                if (myState == FormState.Edit)
                {
                    label10.Text             = "Edit Guest with ID:";
                    FirstNameTextBox.Enabled = true;
                    LastNameTextBox.Enabled  = true;

                    TelephoneTextBox.Enabled = true;

                    EmailTextBox.Enabled = true;

                    button2.Text    = "Save Changes";
                    button2.Visible = true;

                    textBox1.Text    = temp.GuestID;
                    textBox1.Enabled = false;
                    textBox1.Visible = true;
                }
                if (myState == FormState.Delete)
                {
                    label10.Text             = "Delete Guest with ID:";
                    FirstNameTextBox.Enabled = false;
                    LastNameTextBox.Enabled  = false;

                    TelephoneTextBox.Enabled = false;

                    EmailTextBox.Enabled = false;
                    button2.Text         = "Delete";
                    button2.Visible      = true;
                    textBox1.Text        = temp.GuestID;
                    textBox1.Enabled     = false;
                    textBox1.Visible     = true;
                }
            }
        }