Example #1
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string output = "Incorrect Password!";
            // Create new Login object
            LoginUser user = new LoginUser();

            // Read input
            user.UserName = txtUserName.Text;
            user.Password = txtPassword.Text;

            // Attempt to Log in
            //string result = DataHandler.SysLogin(userName, password);
            int success = DataHandler.HashLogin(user);

            // RegexCheck
            if (RegexCheck.Password(user.Password) == true)
            {
                if (success == (int)SuccessEnum.Success)
                {
                    currentUser = user.UserName;
                    // Call to method to turn on or off login buttons
                    LoginItems("off");
                    lblWelcome.Text = "Welcome, " + user.UserName + "!";
                    output          = "Welcome, " + user.UserName + "!";
                    tabControl1.Show();
                    // Clear UserName and Password
                    txtUserName.Text = "";
                    txtPassword.Text = "";
                }
            }
            // Display Result
            MessageBox.Show(output, "Login");
            // Reset Password txtBox
            txtPassword.Text = "";
        }
Example #2
0
        private void btnAddEmployee_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Do you wish to add a new employee?", "Add new employee?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                string output = "";
                // Read inputs
                emp.FirstName = txtAddFName.Text;
                emp.LastName  = txtAddLName.Text;
                emp.Email     = txtAddEmail.Text;
                emp.DOB       = Convert.ToDateTime(txtAddDOB.Text);
                emp.Phone     = txtAddPhone.Text;

                // Call to DataHandler, then off to RegexCheck and finally StoredProcedure
                if (RegexCheck.Checker(emp) == "Pass")
                {
                    // Add employee to DB and store the result
                    int success = DataHandler.InsertEmployee(emp);

                    // Display the result
                    if (success == (int)SuccessEnum.Success)
                    {
                        output += "Added Employee to the DataBase!\n";
                        // Reset Fields
                        txtAddFName.Text = "";
                        txtAddLName.Text = "";
                        txtAddEmail.Text = "";
                        txtAddDOB.Text   = "";
                        txtAddPhone.Text = "";
                    }
                    else
                    {
                        output += "Failed to add Employee to the DataBase!\n";
                    }
                }
                // Display Regex fail message
                else
                {
                    output += RegexCheck.Checker(emp) + "\n";
                }

                MessageBox.Show(output, "Result");

                // Update List with new Employee
                FillListEmp();
            }
        }
Example #3
0
        private void btnUpdatePassword_Click(object sender, EventArgs e)
        {
            string output = "";
            // Create new Login object
            LoginUser user = new LoginUser();

            DialogResult result = MessageBox.Show("Do you want to update your password?", "Update password?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // Check passwords are matching

                if (txtNewPassword.Text == txtConfirmNewPassword.Text)
                {
                    // Update password
                    user.UserName    = currentUser;
                    user.Password    = txtOldPassword.Text;
                    user.NewPassword = txtNewPassword.Text;
                    if (RegexCheck.Password(user.NewPassword) == true)
                    {
                        int success = DataHandler.UpdatePassword(user);
                        if (success == (int)SuccessEnum.Success)
                        {
                            output = "Updated Password!";
                        }
                        else
                        {
                            output = "Failed to update Password!";
                        }
                    }
                    else
                    {
                        output += "Incorrect Password Format!";
                    }

                    // Display result
                    MessageBox.Show(output, "Result");
                    // Reset textboxes
                    txtOldPassword.Text        = "";
                    txtNewPassword.Text        = "";
                    txtConfirmNewPassword.Text = "";
                }
                else
                {
                    MessageBox.Show("New passwords don't match!", "Error");
                }
            }
        }
Example #4
0
        private void btnNewLogin_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Do you want to create a new login?", "Create new login?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                string output = "";
                // Check passwords are matching
                if (txtNewUserConfirmPassword.Text == txtNewUserPassword.Text)
                {
                    // Create new LoginUser object
                    LoginUser user = new LoginUser();
                    user.UserName = txtNewUser.Text;
                    user.Password = txtNewUserConfirmPassword.Text;
                    // RegexCheck
                    if (RegexCheck.Password(user.Password) == true)
                    {
                        int success = DataHandler.NewLogin(user);

                        if (success == (int)SuccessEnum.Success)
                        {
                            output += "Added new Login User!";
                        }
                        else
                        {
                            output += "Failed to add a new user!";
                        }
                    }
                    else
                    {
                        output += "Incorrect Password Format!\n4-12 characters.\nLetters and numbers only.";
                    }

                    // Reset textboxes
                    txtNewUser.Text = "";
                    txtNewUserConfirmPassword.Text = "";
                    txtNewUserPassword.Text        = "";
                }
                else
                {
                    output += "Passwords don't match!";
                }
                MessageBox.Show(output, "Result");
            }
        }
Example #5
0
        private void btnUpdateHours_Click(object sender, EventArgs e)
        {
            string       output = "";
            DialogResult result = MessageBox.Show("Do you want update employee hours?", "Update hours?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // Read input
                emp.EmpID = int.Parse(lblUpdateEmpIDText.Text);
                // Create new EmpHours object
                EmpHours empHours = new EmpHours(emp);
                empHours.Date  = Convert.ToDateTime(txtUpdateWorkDate.Text);
                empHours.Hours = txtUpdateHours.Text;

                // Call to DataHandler, then off to RegexCheck and finally StoredProcedure
                if (RegexCheck.Checker(empHours) == "Pass")
                {
                    // Add employee to DB and store the result
                    int success = DataHandler.InsertHours(empHours);

                    // Display the result
                    if (success == (int)SuccessEnum.Success)
                    {
                        output += "Added Employee Hours to the DataBase!\n";
                    }
                    else
                    {
                        output += "Failed to add Employee Hours to the DataBase!\n";
                    }
                }
                // Regex fail message
                else
                {
                    output += RegexCheck.Checker(empHours) + "\n";
                }

                MessageBox.Show(output, "Result");

                txtUpdateHours.Text    = "";
                txtUpdateWorkDate.Text = monthCalendar.TodayDate.ToShortDateString();
            }
        }
Example #6
0
        private void btnUpdateEmployee_Click(object sender, EventArgs e)
        {
            string       output = "";
            DialogResult result = MessageBox.Show("Do you want to update employee information?", "Update employee?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // Remember which employee was selected
                int selected = listboxUpdate.SelectedIndex;

                // REALLY horrible solution..
                //-----------------------------------------
                IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
                DateTime        dt2     = new DateTime();
                try
                {
                    dt2 = DateTime.Parse(txtUpdateDOB.Text, culture, System.Globalization.DateTimeStyles.AssumeLocal);
                }
                catch (Exception)
                {
                    dt2 = new DateTime(0001, 01, 01);
                    // Had to change regex dateformat to not accept a year below 1000
                }
                //-----------------------------------------

                // Read inputs
                emp.EmpID     = int.Parse(lblUpdateEmpIDText.Text);
                emp.FirstName = txtUpdateFName.Text;
                emp.LastName  = txtUpdateLName.Text;
                emp.Email     = txtUpdateEmail.Text;
                //emp.DOB = Convert.ToDateTime(txtUpdateDOB.Text);
                emp.DOB   = dt2;
                emp.Phone = txtUpdatePhone.Text;

                // Call to DataHandler, then off to RegexCheck and finally StoredProcedure
                if (RegexCheck.Checker(emp) == "Pass")
                {
                    // Add employee to DB and store the result
                    int success = DataHandler.UpdateEmployee(emp);

                    // Display the result
                    if (success == (int)SuccessEnum.Success)
                    {
                        output += "Updated Employee Information!\n";
                    }
                    else
                    {
                        output += "Failed to update Employee Information!\n";
                    }
                }
                // Display Regex fail message
                else
                {
                    output += RegexCheck.Checker(emp);
                }

                MessageBox.Show(output, "Result");

                // Update List to include new Employee
                FillListEmp();
                // FillList resets the selected Employee
                // So we set it back using the index
                listboxUpdate.SelectedIndex = selected;
            }
        }