private void button1_Click(object sender, RoutedEventArgs e) { if (delUNameTxtbox.Text == "") { delUErrorLbl.Content = "Please enter a username"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } else if (findUserList.SelectedItem == null) { delUErrorLbl.Content = "Please select a user to delete"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } else { delUErrorLbl.Visibility = Visibility.Hidden; DbUser selectedUser = (DbUser)findUserList.SelectedItem; string username = selectedUser.Username; if (jobExists(username)) { AssignJobsToAccMan jobs = new AssignJobsToAccMan(sessionId, jobsList); jobs.setUsername(username); jobs.setAdminAppForm(this); this.Hide(); jobs.Show(); } else if (username == adminUsername) { delUErrorLbl.Content = "Sorry you cannot delete yourself. This action is not permitted"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } else { var result = MessageBox.Show("Are you sure you want to delete the selected user?", "Delete User", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { List <DbUser> users = new List <DbUser>(); selectedUser.Username = username; users.Add(selectedUser); if (client.DeleteUser(users)) { _UserCollection.Clear(); autoFillUserName.Remove(username); // delUErrorLbl.Content = tabControl1.SelectedIndex.ToString(); delUErrorLbl.Content = "User " + username + " has been deleted"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Green); delUNameTxtbox.Text = ""; delUErrorLbl.Visibility = Visibility.Visible; } else { delUErrorLbl.Content = "Failed to delete the user with username: " + username; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } } } } }
private void button1_Click(object sender, RoutedEventArgs e) { if (delUNameTxtbox.Text == "") { delUErrorLbl.Content = "Please enter a username"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } else if (findUserList.SelectedItem == null) { delUErrorLbl.Content = "Please select a user to delete"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } else { delUErrorLbl.Visibility = Visibility.Hidden; DbUser selectedUser = (DbUser)findUserList.SelectedItem; string username = selectedUser.Username; if (jobExists(username)) { AssignJobsToAccMan jobs = new AssignJobsToAccMan(sessionId, jobsList); jobs.setUsername(username); jobs.setAdminAppForm(this); this.Hide(); jobs.Show(); } else if (username == adminUsername) { delUErrorLbl.Content = "Sorry you cannot delete yourself. This action is not permitted"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } else { var result = MessageBox.Show("Are you sure you want to delete the selected user?", "Delete User", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { List<DbUser> users = new List<DbUser>(); selectedUser.Username = username; users.Add(selectedUser); if (client.DeleteUser(users)) { _UserCollection.Clear(); autoFillUserName.Remove(username); // delUErrorLbl.Content = tabControl1.SelectedIndex.ToString(); delUErrorLbl.Content = "User " + username + " has been deleted"; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Green); delUNameTxtbox.Text = ""; delUErrorLbl.Visibility = Visibility.Visible; } else { delUErrorLbl.Content = "Failed to delete the user with username: " + username; delUErrorLbl.Foreground = new SolidColorBrush(Colors.Red); delUErrorLbl.Visibility = Visibility.Visible; } } } } }