Ejemplo n.º 1
0
        private void SignUpButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(FnameTextBox.Text))
            {
                MessageBox.Show("Please enter the First Name");
                return;
            }
            if (String.IsNullOrEmpty(LnameTextBox.Text))
            {
                MessageBox.Show("Please enter the Last Name");
                return;
            }

            if (String.IsNullOrEmpty(UserNameTextBox.Text))
            {
                MessageBox.Show("Please enter a User Name");
                return;
            }
            if (String.IsNullOrEmpty(PasswordTextBox.Text))
            {
                MessageBox.Show("Please enter a Password");
                return;
            }
            if (String.IsNullOrEmpty(EmailTextBox.Text))
            {
                MessageBox.Show("Please enter an Email");
                return;
            }
            if (String.IsNullOrEmpty(CreditCardNumberTextBox.Text))
            {
                MessageBox.Show("Please enter the Credit Card Number");
                return;
            }
            String Fname    = FnameTextBox.Text;
            String Lname    = LnameTextBox.Text;
            String UserName = UserNameTextBox.Text;
            String Password = PasswordTextBox.Text;
            String PhoneNumber;

            PhoneNumber = PhoneNumberTextBox.Text;

            String Email            = EmailTextBox.Text;
            String CreditCardNumber = CreditCardNumberTextBox.Text;

            if (!Validation.IsValidEmail(Email))
            {
                MessageBox.Show("Please enter a valid Email Adress");
                return;
            }
            if (!Validation.IsPasswordValid(Password))
            {
                MessageBox.Show("Please enter a valid Password \n" + "It should contain at least one number,one uppercase letter and 8 letters");
                return;
            }
            if (!String.IsNullOrEmpty(PhoneNumber))
            {
                if (!Validation.IsPhoneNumberVlidate(PhoneNumber))
                {
                    MessageBox.Show("Please enter a valid Phone Number \n");
                    return;
                }
            }
            else
            {
            }
            int T = 0;

            try
            {
                T = controllerObj.GetPersonWithUserName(UserName);
                if (T != 0)
                {
                    MessageBox.Show("Please choose another username.It already exists.");
                    return;
                }
                T = 0;
                T = controllerObj.CheckIfEmailExist(Email);
                if (T != 0)
                {
                    MessageBox.Show("Please choose another Email.It already exists.");
                    return;
                }
                if (PhoneNumber != "")
                {
                    T = 0;
                    T = controllerObj.CheckIfPhoneNumberExist(PhoneNumber);
                    if ((T != 0))
                    {
                        MessageBox.Show("Please choose another Phone Number.It already exists.");
                        return;
                    }
                }
            }
            catch
            { }

            // if (!Validation.IsCardNumberValid(CreditCardNumberTextBox.Text))
            //{
            // MessageBox.Show("Please enter a valid Credit Card Number");
            //  return;
            // }
            int i = -1;

            try
            {
                i = controllerObj.SignUpCustomer(Fname, Lname, UserName, Password, PhoneNumber, Email, CreditCardNumber);
            }
            catch
            {
                MessageBox.Show("Couldn't sign up! Please try again later.");
                return;
            }
            if (i == 0 || i == -1)
            {
                MessageBox.Show("Couldn't sign up! Please try again later.");
                return;
            }
            MessageBox.Show("You have signed up successfully.");
            //Write the code for opening the customer's account form here
            AccountDetailsForm F = new AccountDetailsForm(UserName, this);

            F.Show();
        }
Ejemplo n.º 2
0
        private void SignInButton_Click(object sender, EventArgs e)
        {
            String UserName;
            String Password;

            try
            {
                UserName = UsernameTextBox.Text;
            }
            catch
            {
                MessageBox.Show("Please enter a username");
                return;
            }
            try
            {
                Password = PasswordTextBox.Text;
            }
            catch
            {
                MessageBox.Show("Please enter a password");
                return;
            }
            bool Customer = false;
            bool Staff    = false;
            bool Admin    = false;
            int  i        = 0;

            i = controllerObj.SignInCustomer(UserName, Password);
            if (i != 0)
            {
                Customer = true;
            }
            else
            {
                i = 0;
                i = controllerObj.SignInStaff(UserName, Password);
                if (i != 0)
                {
                    string role = controllerObj.GetStaffWithName(UserName).Rows[0]["Role"].ToString();;
                    if (role == "S")
                    {
                        Staff = true;
                    }
                    else
                    {
                        Admin = true;
                    }
                }
                else
                {
                    MessageBox.Show("Please enter a valid username or password");
                    return;
                }
            }

            if (Customer)
            {
                AccountDetailsForm S = new AccountDetailsForm(UserName, this);
                S.Show();
                this.Hide();
            }
            else if (Staff)
            {
                StaffAccount S = new StaffAccount(this, UserName, i);
                S.Show();
                this.Hide();
            }
            else if (Admin)
            {
                AdminAccount A = new AdminAccount(this, UserName, i);
                A.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("Please enter a valid username or password");
                return;
            }
        }