private async Task FillRoleBox() { RoleBox.ClearValue(ItemsControl.ItemsSourceProperty); RoleBox.DisplayMemberPath = "Name"; RoleBox.SelectedValuePath = "RoleId"; RoleBox.ItemsSource = await authCore.GetAllRolesAsync(); }
protected void EditButtonListSelectedIndexChanged(object sender, EventArgs e) { RadioButtonList editButtonList = (RadioButtonList)RoleBox.FindControl("editButtonList"); RoleUsersList.DataSource = Roles.GetUsersInRole(editButtonList.SelectedItem.Text); RoleUsersList.DataBind(); DetermineRemaingUsers(editButtonList); }
protected void RemoveRole_OnClick(object sender, EventArgs e) { RadioButtonList list = (RadioButtonList)RoleBox.FindControl("editButtonList"); ListItem item = list.SelectedItem; if (Roles.GetUsersInRole(item.Text).Length != 0) { Roles.RemoveUsersFromRole(Roles.GetUsersInRole(item.Text), item.Text); } Roles.DeleteRole(item.Text); Response.Redirect("~/Account/RoleEditor.aspx"); }
protected void DeleteFromRole_OnClick(object sender, EventArgs e) { RadioButtonList editButtonList = (RadioButtonList)RoleBox.FindControl("editButtonList"); foreach (ListItem listItem in RoleUsersList.Items) { if (listItem.Selected) { Roles.RemoveUserFromRole(listItem.Text, editButtonList.SelectedItem.Text); } } RoleUsersList.DataSource = Roles.GetUsersInRole(editButtonList.SelectedItem.Text); RoleUsersList.DataBind(); DetermineRemaingUsers(editButtonList); }
} //END OF MAIN WINDOW CONSTRUCTOR //An event handler that handles all of the button clicks on the main application page. private void EnrollButton_ClearButton_SetStaffButton_ClearStaffButton_AddToModuleButton_StudentModRemoveButton_Click(object sender, RoutedEventArgs e) { // STAFF // //Sets the details entered into the text boxes as the current staff members details. if (sender == SetStaffButton) //If the set staff button is clicked. { //A data Range check to make sure correct values hve been entered into each textbox. if (StaffNameBox.Text == "" || StaffEmailBox.Text == "" || StaffAddressBox.Text == "" || DepartmentBox.Text == "" || RoleBox.Text == "" || PayrollNoBox.Text == "") { //Display an error message box. MessageBox.Show("You have left one or more fields blank. Please enter values in all of the fields."); } else { //Range checks payroll number. if (int.Parse(PayrollNoBox.Text) < 9000 || int.Parse(PayrollNoBox.Text) > 9999) { MessageBox.Show("You have entered a payroll number that is not within the range (9000 - 9999). Re-enter."); } else { //Add this newly created staff to the staff list to then be added to the staff data grid. StaffList.Add(new Staff(StaffNameBox.Text, StaffEmailBox.Text, StaffAddressBox.Text, int.Parse(PayrollNoBox.Text), DepartmentBox.Text, RoleBox.Text)); } } } //END OF ADD STAFF BUTTON //Clears the currently entered details in the staaff details boxes. if (sender == ClearStaffButton) { //Clear the contents of the staff detail boxes. StaffNameBox.Clear(); StaffAddressBox.Clear(); StaffEmailBox.Clear(); PayrollNoBox.Clear(); DepartmentBox.Clear(); RoleBox.Clear(); } //END OF CLEAR STAFF BUTTON //STUDENT// //If the Enroll Button is clicked this method is carried out. //This will create a new student object and add it to the student list. //Any details entered into the textboxes will be saved to the current student object. //The students in the student list will be saved to a Student.txt file in the debug folder. if (sender == EnrollButton) { //A range check to make sure non of the fields are blank. if (StudentNameBox.Text == "" || StudentEmailBox.Text == "" || StudentAddressBox.Text == "" || MatricnoBox.Text == "") { MessageBox.Show("You have left one or more of the fields blank. Please enter values."); } else { if (int.Parse(MatricnoBox.Text) >= 1000 && int.Parse(MatricnoBox.Text) <= 9000) { //Add this newly created student to the student list. StudentList.Add(new Student(StudentNameBox.Text, StudentEmailBox.Text, StudentAddressBox.Text, int.Parse(MatricnoBox.Text))); } else { MessageBox.Show("The matriculation number box contains incorrect values. Enter within 1000 and 9000."); } } } //END OF ENROLL STUDENT BUTTON //A clear button to clear the contents in the student detail boxes. if (sender == ClearButton) { //Clear all student details in the text boxes. StudentNameBox.Clear(); StudentEmailBox.Clear(); StudentAddressBox.Clear(); MatricnoBox.Clear(); } //END OF CLEAR STUDENT DETAILS BUTTON //MODULES// //This function is carried out when the add to module button is clicked. //This takes the student selected from the combo box and adds that student to the selected module in the second combo box. if (sender == AddToModuleButton) { //This searches through the student list for a students name that is equal to the student combo box selection. Student search = StudentList.FirstOrDefault(z => z.Name == StudentCNameBox.Text); //If the name typed into the text box (studentCNameBox) is found then this is carried out. if (search != null) //If search is not equal to null. { //If the user selects Database Systems in the combo box when clicking the add button. if (ModuleComboBox.SelectedItem == "Database Systems") { //Add the student from the student list whos name matches the name in the textbox to the selected module. DatabaseList.Add(new Student(search.Name, search.MatricNumber, search.Mark, search.Status)); } //If the user selects Systems and Services in the combo box when clicking the add button. if (ModuleComboBox.SelectedItem == "Systems and Services") { //Add the student from the student list whos name matches the name in the textbox to the selected module. SystemsAndServicesList.Add(new Student(search.Name, search.MatricNumber, search.Mark, search.Status)); } //If the user selects Software Development in the combo box when clicking the add button. if (ModuleComboBox.SelectedItem == "Software Development") { //Add the student from the student list whos name matches the name in the textbox to the selected module. SoftwareDevelopmentList.Add(new Student(search.Name, search.MatricNumber, search.Mark, search.Status)); } } } //END OF ADD STUDENT TO MODULE BUTTON //A button that allows for the removal of a student from a specific module. if (sender == StudentModRemoveButton) //If the Remove Student button is clicked. { //This searches through the student list for a students name that is equal to the string entered into the StudentCNamebox. //Sets this object to look. Student look = StudentList.FirstOrDefault(z => z.Name == StudentCNameBox.Text); //If the name is found then this is carried out. if (look != null) { //If the Database Systems option is selected in the combo box. if (ModuleComboBox.SelectedItem == "Database Systems") { //Remove the student from the database list. //Creates a variable called itemToRemove and sets its values to equal the name entered in the textbox. //For each instance of that item in the list, it is removed from the list. var itemToRemove = DatabaseList.Where(z => z.Name == look.Name).ToList(); foreach (var item in itemToRemove) { DatabaseList.Remove(item); // Removes each instance of that student within the given module list. } } //If the Systems and Services option is selected in the module combo box and the remove student is clicked... if (ModuleComboBox.SelectedItem == "Systems and Services") { //Remove the student from the database list. //Creates a variable called itemToRemove and sets its values to equal the name entered in the textbox. var itemToRemove = SystemsAndServicesList.Where(z => z.Name == look.Name).ToList(); foreach (var item in itemToRemove) { SystemsAndServicesList.Remove(item); // Removes each instance of that student within the given module list. } } //If the Software Development option is selected in the combo box and the remove student button is clicked... if (ModuleComboBox.SelectedItem == "Software Development") { //Remove the student from the software development list. //Creates a variable called itemToRemove and sets its values to equal the name entered in the textbox. var itemToRemove = SoftwareDevelopmentList.Where(z => z.Name == look.Name).ToList(); foreach (var item in itemToRemove) { SoftwareDevelopmentList.Remove(item); // Removes each instance of that student within the given module list. } } } } //END OF STUDENT REMOVE BUTTON } //END OF BUTTON EVENT HANDLER
private void RegisterButton_Click(object sender, EventArgs e) { //sets connection var connectionString = ConfigurationManager.ConnectionStrings["EmployeeManagement"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); //opens connection con.Open(); //Creates a command/sql query to select the userid from the database SqlCommand checkUserName = new SqlCommand("Select * from Employees where UserID=@Username", con); SqlCommand checkEmail = new SqlCommand("Select * from Employees where Email=@Email", con); //Trys to add the current data in the UserID text box to the database checkUserName.Parameters.AddWithValue("@Username", this.Username.Text); // same checks for the user id the only diffrence is its the email checkEmail.Parameters.AddWithValue("@Email", this.EmailBox.Text); var result = checkUserName.ExecuteScalar(); var emailResult = checkEmail.ExecuteScalar(); //checks to see if any textboxes are empty if so then it carrys on if (FirstNameBox.Text == "" || LastNameBox.Text == "" || DOBpicker.Text == "" || JobTitleBox.Text == "" || EmailBox.Text == "" || Username.Text == "" || Password.Text == "") { // if a empty a message box shows to ask to enter all fields MessageBox.Show("Please enter all fields!"); //simple return function as we dont want the rest of the code to continue return; } // if both useername and email are not empty and are equal to values in the database it does the following commands if (result != null || emailResult != null) { //if the user name and email is null then set them to red if (result != null && emailResult != null) { Username.BackColor = Color.LightCoral; EmailBox.BackColor = Color.LightCoral; MessageBox.Show("This Username & Email already exist!"); } //if the username is null set the email to green but the username to red else if (result != null) { EmailBox.BackColor = Color.LightGreen; Username.BackColor = Color.LightCoral; MessageBox.Show("This Username already exist!"); } //if the email is null set the email to red and the username to green else if (emailResult != null) { EmailBox.BackColor = Color.LightCoral; Username.BackColor = Color.LightGreen; MessageBox.Show("This Email already exist!"); } //close connection to database con.Close(); } //if no duplicates are found it will move on to adding the data to the database else { // creates a new connection { //creates the new command to insert values into the database but uses values for neater code Random rnd = new Random(); int ID = rnd.Next(2000, 4000); int Employeeid = ID; //SAME AS REGISTER PAGE SqlCommand EmployeeCheck = new SqlCommand("SELECT * from Employees where EmployeeID='" + Employeeid + "'", con); SqlCommand cmd = new SqlCommand("insert into Employees (EmployeeID, FirstName, LastName, DOB, Address, Salary, Department, JobTitle, Role, Email, UserID, Password) " + " values(@EmployeeID, @FirstName, @LastName, @DOB, @Address, @Salary, @Department, @JobTitle, @Role, @Email, @UserID, @Password)", con); SqlDataAdapter da = new SqlDataAdapter(EmployeeCheck); DataSet ds = new DataSet(); da.Fill(ds); int i = ds.Tables[0].Rows.Count; if (i > 0) { MessageBox.Show(i.ToString()); //create a new id int newID = rnd.Next(2000, 10000); cmd.Parameters.AddWithValue("@EmployeeID", newID); cmd.Parameters.AddWithValue("@FirstName", FirstNameBox.Text); cmd.Parameters.AddWithValue("@LastName", LastNameBox.Text); cmd.Parameters.AddWithValue("@DOB", DOBpicker.Text); cmd.Parameters.AddWithValue("@Address", Address.Text); //sets the salary value to the variable based on which role is selected // CLEAN UP ALL IFS STATEMENTS if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Manager") { cmd.Parameters.AddWithValue("@Salary", Manager); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Engineer") { cmd.Parameters.AddWithValue("@Salary", Engineer); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Team Leader") { cmd.Parameters.AddWithValue("@Salary", TeamLeader); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Engineer Scheduler") { cmd.Parameters.AddWithValue("@Salary", EngineerScheduler); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Senior Developer") { cmd.Parameters.AddWithValue("@Salary", SeniorDevelopment); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Programmer") { cmd.Parameters.AddWithValue("@Salary", Programmer); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Anaylst") { cmd.Parameters.AddWithValue("@Salary", Anaylst); } cmd.Parameters.AddWithValue("@Department", DepartmentBox.GetItemText(DepartmentBox.SelectedItem)); cmd.Parameters.AddWithValue("@JobTitle", JobTitleBox.Text); cmd.Parameters.AddWithValue("@Role", RoleBox.GetItemText(RoleBox.SelectedItem)); cmd.Parameters.AddWithValue("@Email", EmailBox.Text); cmd.Parameters.AddWithValue("@UserID", Username.Text); decryptedPassword = Password.Text; //adds the password as normal but adds it as an encrypted value cmd.Parameters.AddWithValue("@Password", PasswordLogin.encryptPassword(Password.Text.Trim())); //passing id cmd.ExecuteNonQuery(); //shows a succesful message MessageBox.Show("Succesfully Registerd!"); FirstNameBox.Clear(); LastNameBox.Clear(); JobTitleBox.Clear(); EmailBox.Clear(); Username.Clear(); Password.Clear(); Address.Clear(); DOBpicker.ResetText(); RoleBox.ResetText(); DepartmentBox.ResetText(); } else { cmd.Parameters.AddWithValue("@EmployeeID", Employeeid); cmd.Parameters.AddWithValue("@FirstName", FirstNameBox.Text); cmd.Parameters.AddWithValue("@LastName", LastNameBox.Text); cmd.Parameters.AddWithValue("@DOB", DOBpicker.Text); cmd.Parameters.AddWithValue("@Address", Address.Text); //sets the salary value to the variable based on which role is selected // CLEAN UP ALL IFS STATEMENTS if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Manager") { cmd.Parameters.AddWithValue("@Salary", Manager); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Engineer") { cmd.Parameters.AddWithValue("@Salary", Engineer); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Team Leader") { cmd.Parameters.AddWithValue("@Salary", TeamLeader); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Engineer Scheduler") { cmd.Parameters.AddWithValue("@Salary", EngineerScheduler); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Senior Developer") { cmd.Parameters.AddWithValue("@Salary", SeniorDevelopment); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Programmer") { cmd.Parameters.AddWithValue("@Salary", Programmer); } else if (RoleBox.GetItemText(RoleBox.SelectedItem) == "Anaylst") { cmd.Parameters.AddWithValue("@Salary", Anaylst); } cmd.Parameters.AddWithValue("@Department", DepartmentBox.GetItemText(DepartmentBox.SelectedItem)); cmd.Parameters.AddWithValue("@JobTitle", JobTitleBox.Text); cmd.Parameters.AddWithValue("@Role", RoleBox.GetItemText(RoleBox.SelectedItem)); cmd.Parameters.AddWithValue("@Email", EmailBox.Text); cmd.Parameters.AddWithValue("@UserID", Username.Text); decryptedPassword = Password.Text; //adds the password as normal but adds it as an encrypted value cmd.Parameters.AddWithValue("@Password", PasswordLogin.encryptPassword(Password.Text.Trim())); cmd.ExecuteNonQuery(); //closes connection con.Close(); //shows a succesful message MessageBox.Show("Succesfully Registerd!"); FirstNameBox.Clear(); LastNameBox.Clear(); JobTitleBox.Clear(); EmailBox.Clear(); Username.Clear(); Password.Clear(); Address.Clear(); DOBpicker.ResetText(); RoleBox.ResetText(); DepartmentBox.ResetText(); } } } }
protected void Page_Load(object sender, EventArgs e) { RadioButtonList editButtonList = (RadioButtonList)RoleBox.FindControl("editButtonList"); editButtonList.SelectedIndexChanged += EditButtonListSelectedIndexChanged; }