Example #1
0
 private void GetLoginCredentialsButton_Click(object sender, EventArgs e)
 {
     LoginCTRL loginctrl = new LoginCTRL();
     foreach (Login l in loginctrl.getAllLogins())
     {
         LoginBox.Items.Add(l);
     }
 }
Example #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(txtUsername.Text))
            {
                MessageBox.Show("Please Enter Username");
                return;
            }
            else if (String.IsNullOrEmpty(txtPassword.Text))
            {
                MessageBox.Show("Please Enter Password");
                return;
            }
            bool      notFound  = true;
            UserCTRL  userctrl  = new UserCTRL();
            LoginCTRL loginctrl = new LoginCTRL();

            foreach (Login l in loginctrl.getAllLogins())
            {
                if (l.UserName == txtUsername.Text)
                {
                    if (l.Password == txtPassword.Text)
                    {
                        User user = userctrl.getUserByID(l.ID);
                        UserSingleton.Instance(user);
                        if (user.IsAdmin && SignInAsAdminBox.Checked)
                        {
                            MessageBox.Show("Login Successful");
                            notFound = false;
                            this.Hide();

                            AdminPg.getInstance();
                        }
                        else if (!user.IsAdmin && SignInAsAdminBox.Checked)
                        {
                            MessageBox.Show("User is Not an Admin");
                            notFound = false;
                            this.Hide();

                            HomePage.getInstance();
                        }
                        else
                        {
                            //MessageBox.Show(UserSingleton.GetUser().ToString());
                            MessageBox.Show("Login Successful");
                            notFound = false;
                            this.Hide();

                            HomePage.getInstance();
                        }
                    }
                }
            }
            if (notFound)
            {
                MessageBox.Show("Invalid Username or Password.");
            }
        }
Example #3
0
        private void SaveUserButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(FirstNameBox.Text))
            {
                MessageBox.Show("Please Enter First Name");
                return;
            }
            else if (String.IsNullOrEmpty(LastNameBox.Text))
            {
                MessageBox.Show("Please Enter Last Name");
                return;
            }
            else if (String.IsNullOrEmpty(PhoneNumberBox.Text))
            {
                MessageBox.Show("Please Enter Phone Number");
                return;
            }
            else if (String.IsNullOrEmpty(AddressBox.Text))
            {
                MessageBox.Show("Please Enter Address");
                return;
            }
            if (String.IsNullOrEmpty(EmailBox.Text))
            {
                MessageBox.Show("Please Enter Email");
                return;
            }
            else if (String.IsNullOrEmpty(UsernameBox.Text))
            {
                MessageBox.Show("Please Enter Username");
                return;
            }
            else if (String.IsNullOrEmpty(PasswordBox.Text))
            {
                MessageBox.Show("Please Enter Password");
            }
            LoginCTRL loginctrl = new LoginCTRL();

            foreach (Login l in loginctrl.getAllLogins())
            {
                if (l.UserName == UsernameBox.Text)
                {
                    MessageBox.Show("Username Already Exists");
                    return;
                }
            }
            User user = new User();

            user.FirstName   = FirstNameBox.Text;
            user.LastName    = LastNameBox.Text;
            user.PhoneNumber = PhoneNumberBox.Text;
            user.Address     = AddressBox.Text;
            user.Email       = EmailBox.Text;
            DateTime dateValue;

            if (DateTime.TryParse(DOBBox.Text, out dateValue))
            {
                user.DateOfBirth = dateValue;
            }
            else
            {
                MessageBox.Show("DATE OF BIRTH MUST BE OF TYPE MM/DD/YYYY");
                return;
            }
            if (MaleButton.Checked)
            {
                user.Gender = "male";
            }
            else
            {
                user.Gender = "female";
            }
            user.IsAdmin = false;
            user.ID      = loginctrl.saveLoginInfo(UsernameBox.Text, PasswordBox.Text);
            UserCTRL userctrl = new UserCTRL();

            userctrl.addUser(user, user.ID);
            MessageBox.Show("REGISTRATION COMPLETE, PLEASE LOGIN");
            FirstNameBox.Text   = "";
            LastNameBox.Text    = "";
            PhoneNumberBox.Text = "";
            AddressBox.Text     = "";
            EmailBox.Text       = "";
            UsernameBox.Text    = "";
            PasswordBox.Text    = "";
            this.Hide();

            SignInRegPg.GetInstance();
        }