private void GroupSelection_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { CurrentUsers.ItemsSource = null; CurrentUsers.SelectedItem = null; try { CurrentUsers.ItemsSource = gap.Query(GroupSelection.SelectedItem.ToString()); UsersToAdd.ItemsSource = null; for (int i = 0; i < addList.Count; i++) { if (CurrentUsers.Items.Contains((User)addList[i])) { addList[i] = new UserWithCheck(addList[i], true); } else { addList[i] = new UserWithCheck(addList[i], false); } } UsersToAdd.ItemsSource = addList; } catch (GroupAccessProvider.GroupNotFoundException E) { MessageBox.Show(E.Message); } }
private void SingleAddButton_Click(object sender, RoutedEventArgs e) { if (UserToAdd.Text.Length > 0) { UsersToAdd.ItemsSource = null; Principal user; if (UserToAdd.Text.Contains(" ")) { user = gap.FindByName(UserToAdd.Text); } else { user = gap.FindByAccount(UserToAdd.Text); } if (user != null) { var usr = new User(user.SamAccountName, user.DisplayName); bool isInGroup = CurrentUsers.Items.Contains(usr); var usrWithCheck = new UserWithCheck(usr, isInGroup); if (!addList.Contains(usrWithCheck)) { addList.Add(usrWithCheck); } UserToAdd.Text = ""; } else { using (var sw = new StreamWriter("log.txt", true)) { sw.WriteLine(); sw.WriteLine(DateTime.Now); sw.WriteLine(string.Format("{0} not found", UserToAdd.Text)); MessageBox.Show(string.Format("{0} not found", UserToAdd.Text)); } } UsersToAdd.ItemsSource = addList; } }
private void MultipleAdd_Click(object sender, RoutedEventArgs e) { string filePath; var ofd = new OpenFileDialog(); ofd.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; ofd.FilterIndex = 1; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == true) { filePath = ofd.FileName; } else { return; } var notFound = new List <string>(); UsersToAdd.ItemsSource = null; using (var sr = new StreamReader(filePath)) { while (!sr.EndOfStream) { string accountName = sr.ReadLine(); if (accountName.Length > 0) { Principal user; if (accountName.Contains(" ")) { user = gap.FindByName(accountName); } else { user = gap.FindByAccount(accountName); } if (user != null) { var usr = new User(user.SamAccountName, user.DisplayName); bool isInGroup = CurrentUsers.Items.Contains(usr); var usrWithCheck = new UserWithCheck(usr, isInGroup); if (!addList.Contains(usrWithCheck)) { addList.Add(usrWithCheck); } } else { notFound.Add(accountName); } } } } using (var sw = new StreamWriter("log.txt", true)) { sw.WriteLine(); sw.WriteLine(DateTime.Now); var sb = new StringBuilder(); foreach (var user in notFound) { sw.WriteLine(string.Format("{0} not found", user)); sb.AppendLine(string.Format("{0} not found", user)); } MessageBox.Show(sb.ToString()); } UsersToAdd.ItemsSource = addList; }