private void nxtButton_Click(object sender, EventArgs e)
        {
            if (!Regex.IsMatch(firstNametxtbox.Text, @"^[a-zA-Z0 ]+$"))
            {
                MessageBox.Show("First name can not be empty or contains numbers and symbol");
            }

            else if (!Regex.IsMatch(lastNametxtbox.Text, @"^[a-zA-Z0 ]+$"))
            {
                MessageBox.Show("Last name can not be empty or contains numbers and symbol");
            }

            else if (!Regex.IsMatch(gendertxtbox.Text, @"^[a-zA-Z0 ]+$"))
            {
                MessageBox.Show("Gender can not be empty or contains numbers and symbol");
            }

            else if (!Regex.IsMatch(passportNumbtxtbox.Text, @"^[a-zA-Z0-9 ]+$"))
            {
                MessageBox.Show("Passport number can not be empty or contains symbol");
            }

            else if (Nationalitytxtbox.Text == "")
            {
                MessageBox.Show("Nationality can not be empty");
            }

            else if (Addresstxtbox.Text == "")
            {
                MessageBox.Show("Address can not be empty");
            }

            else if (!Regex.IsMatch(postCodetxtbox.Text, @"^[a-zA-Z0-9 ]{7,8}\b+$"))
            {
                MessageBox.Show("Post code can not be empty or contains symbols");
            }

            else if (!Double.TryParse(contactNumbertxtbox.Text, out mynum))
            {
                MessageBox.Show("Contact number can not be empty or it must not contain letters or symbols");
            }

            else if (!Regex.IsMatch(emailtxtbox.Text, @"^[a-zA-Z0-9 ]+$"))
            {
                MessageBox.Show("Must be a valid email address");
            }
            else
            //KEVIN
            {
                MessageBox.Show("Booking Reserved");

                string cString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=PrimaryDB.mdb";
                string save    = "INSERT INTO Customers (CustomerFirstName, CustomerLastName, Gender, PassportNumber, Nationality, Address, PostCode, ContactNumber, EmailAddress) " +
                                 "VALUES (@CustomerFirstName, @CustomerLastName, @Gender, @PassportNumber, @Nationality, @Address, @PostCode, @ContactNumber, @EmailAddress)";


                object[] customers = { "@CustomerFirstName", firstNametxtbox.Text,    "@CustomerLastName",      lastNametxtbox.Text,    "@Gender",  gendertxtbox.Text,
                                       "@PassportNumber",    passportNumbtxtbox.Text, "@Nationality",           Nationalitytxtbox.Text, "@Address", Addresstxtbox.Text,"@PostCode",
                                       postCodetxtbox.Text,  "@ContactNumber",        contactNumbertxtbox.Text, "@EmailAddress",        emailtxtbox.Text };

                var dbFunc = new DatabaseFunctions();
                dbFunc.writeDatabase(save, cString, customers);

                this.Hide();
                Booking_Confirmation b = new Booking_Confirmation();
                b.ShowDialog();
            }
        }
Ejemplo n.º 2
0
        private void nxtButton_Click(object sender, EventArgs e)
        {
            // Basic validation which will notify the user if they have added invalid characters
            if (!Regex.IsMatch(firstNametxtbox.Text, @"^[a-zA-Z0]+$"))
            {
                MessageBox.Show("First name can not be empty or contains numbers and symbol");
            }

            else if (!Regex.IsMatch(lastNametxtbox.Text, @"^[a-zA-Z0]+$"))
            {
                MessageBox.Show("Last name can not be empty or contains numbers and symbol");
            }

            else if (!Regex.IsMatch(gendertxtbox.Text, @"^[a-zA-Z0]+$"))
            {
                MessageBox.Show("Gender can not be empty or contains numbers and symbol");
            }

            else if (!Regex.IsMatch(passportNumbtxtbox.Text, @"^[a-zA-Z0-9]+$"))
            {
                MessageBox.Show("Passport number can not be empty or contains symbol");
            }

            else if (!Regex.IsMatch(Nationalitytxtbox.Text, @"^[a-zA-Z0-9]+$"))
            {
                MessageBox.Show("Nationality can not be empty or contains symbol");
            }

            else if (!Regex.IsMatch(Addresstxtbox.Text, @"^[A-Za-z0-9'\.\-\s\,]"))
            {
                MessageBox.Show("Must be a valid address");
            }

            else if (!Regex.IsMatch(postCodetxtbox.Text, @"^[a-zA-Z0-9 ]{7,8}\b+$"))
            {
                MessageBox.Show("Post code can not be empty or contains symbols");
            }

            else if (!Regex.IsMatch(contactNumbertxtbox.Text, @"(\+?( |-|\.)?\d{1,2}( |-|\.)?)?(\(?\d{3}\)?|\d{3})( |-|\.)?(\d{3}( |-|\.)?\d{4})"))
            {
                MessageBox.Show("Contact number can not be empty or contain letters or symbols");
            }

            else if (!Regex.IsMatch(emailtxtbox.Text, @"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$"))
            {
                MessageBox.Show("Must be a valid email address");
            }
            else
            {
                // Connects to the database
                string cString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=PrimaryDB.mdb";

                // SQL query that will insert customer details to the database
                string save = "INSERT INTO Customers (CustomerFirstName, CustomerLastName, Gender, PassportNumber, Nationality, Address, PostCode, " +
                              "ContactNumber, EmailAddress) VALUES (@CustomerFirstName, @CustomerLastName, @Gender, @PassportNumber, @Nationality, @Address, " +
                              "@PostCode, @ContactNumber, @EmailAddress)";

                // Objects it requires
                object[] customers = { "@CustomerFirstName", firstNametxtbox.Text,    "@CustomerLastName",      lastNametxtbox.Text,    "@Gender",  gendertxtbox.Text,
                                       "@PassportNumber",    passportNumbtxtbox.Text, "@Nationality",           Nationalitytxtbox.Text, "@Address", Addresstxtbox.Text,"@PostCode",
                                       postCodetxtbox.Text,  "@ContactNumber",        contactNumbertxtbox.Text, "@EmailAddress",        emailtxtbox.Text };
                try
                {
                    // Function to write to database using the variables
                    var dbFunc = new DatabaseFunctions();
                    dbFunc.writeDatabase(save, cString, customers);
                    MessageBox.Show("Booking Reserved");
                    this.Hide();
                    booking.fname           = firstNametxtbox.Text;
                    booking.sname           = lastNametxtbox.Text;
                    booking.customerAddress = Addresstxtbox.Text;
                    booking.customerPhone   = contactNumbertxtbox.Text;
                    booking.gender          = gendertxtbox.Text;
                    booking.passportNum     = passportNumbtxtbox.Text;
                    booking.nationality     = Nationalitytxtbox.Text;
                    booking.postCode        = postCodetxtbox.Text;
                    booking.email           = emailtxtbox.Text;
                    Booking_Confirmation b = new Booking_Confirmation(booking.bookingDate, booking.fname, booking.sname,
                                                                      booking.customerAddress, booking.customerPhone, booking.gender, booking.nationality,
                                                                      booking.passportNum, booking.postCode, booking.email, booking.flightNumber,
                                                                      booking.flightType, booking.Departuretime, booking.arrivalTime, booking.numAdults,
                                                                      booking.numChild, booking.flightDestination, booking.flightTotalPrice, booking.carNumPlate,
                                                                      booking.carSeats, booking.carMake, booking.carModel, booking.carHirePrice, booking.carHireName,
                                                                      booking.hotelStar, booking.hotelCheckin, booking.hotelCheckout, booking.hotelName, booking.hotelTotalPrice, booking.totalPrice);
                    b.ShowDialog();
                }
                catch (Exception)
                {
                    MessageBox.Show("An error occurred. Please contact the system administrator");
                }
            }
        }