private void button1_Click(object sender, EventArgs e)
        {
            //get customer registration info and write to database
            string custName    = nameInputBox.Text;
            string telephoneNo = telInputBox.Text;
            string ic          = ICInputBox.Text;
            string email       = emailInputBox.Text;

            if (custName.Equals("") || telephoneNo.Equals("") || ic.Equals("") || email.Equals(""))
            {
                MessageBox.Show("Input must not be empty!");
            }
            else if (!System.Text.RegularExpressions.Regex.Match(ICInputBox.Text, @"^\d{12}$").Success)
            {
                MessageBox.Show("Please input  IC correctly.");
            }
            else if (!System.Text.RegularExpressions.Regex.Match(telInputBox.Text, @"^\d{10}$").Success)
            {
                MessageBox.Show("Please input Phone Number correctly.");
            }
            else
            {
                //connection to database
                string Conn = "datasource=localhost;port=3306;username=root;password=;database=sbc;sslMode=none";

                //insert customer data into database
                string Query = "INSERT INTO customer (PhoneNo, Name, ic, email) " +
                               "VALUES ('" + telephoneNo + "', '" + custName + "', '" + ic + "', '" + email + "');";
                /*string insertLog = "INSERT INTO Log ('EmpID', 'Message') VALUES ('" + Program.admin.getEmpID() + "', 'Added a new customer record');"; */

                MySqlConnection MyConn = new MySqlConnection(Conn);
                MySqlCommand    cmd    = new MySqlCommand(Query, MyConn);

                MySqlDataReader MyReader;
                MyConn.Open();
                MyReader = cmd.ExecuteReader();


                Customer customer = new Customer(telephoneNo, custName, email, ic);


                //Write to log tables here
                ///*********************//
                MyReader.Close();
                cmd.CommandText = "INSERT INTO Log (EmpID, Message) VALUES ('" + Program.admin.getEmpID() + "', 'Added a new customer record');";
                cmd.ExecuteNonQuery();
                MyConn.Close();

                MessageBox.Show("Customer Created!");


                //send customer telephone to bookings2 to identify customer
                createBookings2 bookings2 = new createBookings2(customer);
                bookings2.Show();
                this.Hide();
            }
        }
示例#2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            string custNo = "";

            //get customer value from input box
            try
            {
                custNo = phoneNoInputBox.Text;

                //validate if all character is an integer
                char[] validate = custNo.ToCharArray();

                foreach (char tempChar in validate)
                {
                    int.Parse(tempChar.ToString());
                }
            }
            catch (FormatException ex)
            {
                MessageBox.Show("Invalid format, please enter a valid phone number");
                return;
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            //connection to database
            string Conn = "datasource=localhost;port=3306;username=root;password=;database=sbc;sslMode=none";

            //Select statement to find bus drivers available (phoneNo is unique in the table)
            string          Query  = "SELECT * FROM customer WHERE PhoneNo = '" + custNo + "'";
            MySqlConnection MyConn = new MySqlConnection(Conn);
            MySqlCommand    cmd    = new MySqlCommand(Query, MyConn);

            MySqlDataReader MyReader;

            MyConn.Open();
            MyReader = cmd.ExecuteReader();



            if (MyReader.Read())
            {
                //getting the customer name and phone number
                string customerNumber = MyReader.GetString("PhoneNo");
                string name           = MyReader.GetString("Name");
                string email          = MyReader.GetString("email");
                string ic             = MyReader.GetString("IC");

                Customer customer = new Customer(customerNumber, name, email, ic);

                createBookings2 bookings2 = new createBookings2(customer);
                this.Hide();
                bookings2.ShowDialog();
            }
            else
            {
                //customer not found in database
                MessageBox.Show("Customer not found, please register");

                this.Hide();
                registrationForm register = new registrationForm();
                register.Show();
            }

            MyConn.Close();
        }