Ejemplo n.º 1
0
        /// <summary>
        /// Logs in the user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loginButton_Click(object sender, EventArgs e)
        {
            SimpleAES encrypt = new SimpleAES();
            String name = NameBox.Text;
            String password = PasswordBox.Text;
            password = encrypt.EncryptToString(password);
            try
            {
                Employee employee = _controller.EmployeeLogIn(name, password);

                if (employee == null )
                {
                  MessageBox.Show(@"No valid user found, please try your user name and password again");
                }
                else if (employee.PositionId == 1 && employee.Enabled == 1)
                {
                    MessageBox.Show(@"Valid login. Welcome Nurse " + employee.FirstName + " " + employee.LastName);
                    employeeUser = employee;
                    NorthwindAdmin homeN = new NorthwindAdmin(employee);
                    homeN.Show();
                    this.Hide();
                }
                else if (employee.PositionId == 3 && employee.Enabled == 1)
                {
                    MessageBox.Show(@"Valid login. Welcome Admin " + employee.FirstName + " " + employee.LastName);
                    employeeUser = employee;
                    NorthwindAdmin homeA = new NorthwindAdmin(employee);
                    homeA.Show();
                    this.Hide();

                }
                else if ((employee.PositionId == 3 || employee.PositionId == 1) & employee.Enabled == 0)
                {
                    MessageBox.Show(@"Your account is currently disabled, please contact an admin.");

                }
                else
                {
                     MessageBox.Show(@"Only Nurses Or Administrators May login at this time.");
                }

            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message, ex.GetType().ToString() + "Something happened");
            }
        }
Ejemplo n.º 2
0
        private void loadEmployeeData()
        {
            this.Text = String.Concat("Viewing Employee - ", employee.FirstName.Trim(), " ", employee.LastName.Trim());
            firstNameTextBox.Text = employee.FirstName.Trim();
            middleInitialTextBox.Text = employee.MiddleInitial.Trim();
            lastNameTextBox.Text = employee.LastName.Trim();
            if ((employee.Gender == "F"))
            {

                femaleRadioButton.Checked = true;
            }
            else
            {
                maleRadioButton.Checked = true;
            }
            int position = employee.PositionId;
            ssnTextBox.Text = employee.Ssn.ToString().Trim();
            zipTextBox.Text = employee.Zip.ToString().Trim();
            PhoneTextBox.Text = employee.Phone.Trim();
            JobBox.SelectedIndex = employee.PositionId-1;
            dateTimePicker.Text = employee.Dob.ToShortDateString().Trim();
            addressTextBox.Text = employee.Address.Trim();
            cityTextBox.Text = employee.City.Trim();
            StateComboBox.Text = employee.State;
            if (employee.Login != null && employee.Login.Trim() != "")
            {
                loginTextBox.Text = employee.Login;
                SimpleAES encrypt = new SimpleAES();
                passwordTextBox.Text = encrypt.DecryptString(employee.Password.Trim());

            }

            if (employee.Enabled == 1)
            {
                enabledCheckBox.Checked = true;
            }
            else
            {
                enabledCheckBox.Checked = false;
            }

            AddNewButton.Enabled = false;
            UpdateButton.Enabled = true;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Logs a user in
        /// </summary>
        /// <param name="userName">the login name</param>
        /// <param name="password">the person's password</param>
        /// <returns>an employee object for that user if there is one, or null otherwise</returns>
        public static Employee EmployeeLogIn(String userName, String password)
        {
            Employee employeeReturn = null;
            Employee employee = new Employee();
            SimpleAES encrypt = new SimpleAES();

            String selectStatement = "Select employeeID, enabled, first_name, last_name, last_login, password, positionID, login, password from employees "
            +"where login = @username and password = @password";

            try
            {
                using (SqlConnection connection = NorthwindDbConnection.GetConnection())
                {
                    connection.Open();

                    using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                    {
                        selectCommand.Parameters.AddWithValue("@username", userName);
                        selectCommand.Parameters.AddWithValue("@password", password);

                        using (SqlDataReader reader = selectCommand.ExecuteReader())
                        {
                            while (reader.Read())
                            {

                                employee.EmployeeId = (Int32)reader["employeeID"];
                                employee.Enabled = (Byte)reader["enabled"];
                                employee.FirstName = reader["first_name"].ToString().Trim();
                                employee.LastLogin = reader["last_login"].ToString().Trim();
                                employee.LastName = reader["last_name"].ToString().Trim();
                                employee.Login = reader["login"].ToString().Trim();
                                employee.Password = reader["password"].ToString().Trim();
                                employee.PositionId = (Int32)reader["positionID"];

                            }
                        }

                        selectStatement = " Update employees SET last_login = getdate()"
                            + " where employeeID = " + employee.EmployeeId;
                                SqlCommand selectCommand2 = new SqlCommand(selectStatement, connection);
                                selectCommand2.ExecuteNonQuery();

                    }
                }
                if (employee.Login != null && employee.Login != "")
                {
                    employeeReturn = employee;
                } else {
                    return employeeReturn;
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return employeeReturn;
        }
Ejemplo n.º 4
0
        private Employee CreateEmployee()
        {
            if ((femaleRadioButton.Checked == false) & (maleRadioButton.Checked == false))
            {
                MessageBox.Show
                    (
                        @"Please select gender.");
            }
            else
            {

                if ((femaleRadioButton.Checked == true))
                {
                    gender = "F";
                }
                else
                {
                    gender = "M";
                }
                // This is going to check if anything needs to be fixed
                Boolean loginInfoSet = false;
                employee.Enabled = 0;
                if ((loginTextBox.Text.Trim().Length > 0) & (passwordTextBox.Text.Trim().Length > 0))
                {
                    Boolean uniqueLogin = true;

                    if ((employee.Login.Trim() != loginTextBox.Text.Trim()))
                    {
                        uniqueLogin = _controller.VerifyUniqueLogin(loginTextBox.Text);
                    }
                    if (uniqueLogin)
                    {
                        loginInfoSet = true;
                        employee.Login = loginTextBox.Text;
                        SimpleAES encrypt = new SimpleAES();
                        employee.Password = encrypt.EncryptToString(passwordTextBox.Text);
                        employee.Enabled = 1;

                    }
                    else
                    {
                        MessageBox.Show(@"That Login is already in use.");
                    }
                }

                if (loginInfoSet)
                {
                    if ((int.TryParse(ssnTextBox.Text, out ssn)) & (ssnTextBox.Text.Length == 9))
                    {
                        if ((int.TryParse(zipTextBox.Text, out zip)) & (zipTextBox.Text.Length == 5))
                        {
                            long phone;
                            PhoneTextBox.Text = PhoneTextBox.Text.Trim();
                            if ((long.TryParse(PhoneTextBox.Text, out phone)) & (PhoneTextBox.Text.Length >= 10))
                            {

                                if ((firstNameTextBox.Text != "") & (lastNameTextBox.Text != "") & (ssn != 0) & (zip != 0) &
                                    (addressTextBox.Text != "") & (cityTextBox.Text != "") & (StateComboBox.Text != ""))
                                {
                                    //Check Details
                                    employee.FirstName = firstNameTextBox.Text;
                                    employee.MiddleInitial = middleInitialTextBox.Text;
                                    employee.LastName = lastNameTextBox.Text;
                                    employee.Gender = gender;
                                    employee.Ssn = ssn;
                                    employee.Zip = zip;
                                    employee.PositionId = JobBox.SelectedIndex + 1;
                                    employee.Phone = phone.ToString();
                                    employee.Dob = dateTimePicker.Value.Date;
                                    employee.Address = addressTextBox.Text;
                                    employee.City = cityTextBox.Text;
                                    employee.State = StateComboBox.Text;

                                    return employee;
                                }
                                else
                                {
                                    MessageBox.Show(@"Please check all the required fields and make sure you entered the proper information.");

                                }

                            }
                            else
                            {
                                MessageBox.Show(
                                   @"Phone number needs to be numbers only, remove any non digit characters like -'s or ()'s and is at least 10 numbers.");
                            }
                        }
                        else
                        {
                            MessageBox.Show(
                                @"Please enter Zip as a number and that you have entered the right amount of numbers. Please check.");
                        }
                    }
                    else
                    {
                        MessageBox.Show(
                            @"Please enter Social as a number with no dashes, or you may not have entered the right amount of numbers. Please check.");
                    }
                }
                else
                {
                    MessageBox.Show(@"You need to have a login and password.");
                }
            }
            return null;
        }