Ejemplo n.º 1
0
        // Конструктор
        public SelectGroups(DirectoryEntry entry)
        {
            InitializeComponent();
            _selectedGroups            = new ObservableCollection <Group>();
            _sessionAD                 = entry;
            selectedGroups.ItemsSource = _selectedGroups;
            ReadOnlyCollection <Group> items;

            groupsForSelected.ItemsSource = null;
            string errorMsg = "";
            Thread t        = new Thread(() =>
            {
                items = AsyncDataProvider.GetGroupForSelected(_sessionAD, ref errorMsg);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    groupsForSelected.ItemsSource = items;
                    CollectionView view           = (CollectionView)CollectionViewSource.GetDefaultView(groupsForSelected.ItemsSource);
                    if (view != null)
                    {
                        view.Filter = Groups_Filter;
                        view.SortDescriptions.Clear();
                        view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
                    }
                    if (!string.IsNullOrWhiteSpace(errorMsg))
                    {
                        MessageBox.Show(errorMsg, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }));
            });

            t.IsBackground = true;
            t.Start();
        }
        private string _mode;                                 // Режим работы формы
        #endregion

        #region Конструктор
        public AddUserToGroups(string distinguishedNameUser, DirectoryEntry entry, string mode = "user")
        {
            InitializeComponent();
            _selectedGroups        = new ObservableCollection <Group>();
            _sessionAD             = entry;
            _distinguishedNameUser = distinguishedNameUser;
            _mode = mode;
            selectedGroups.ItemsSource = _selectedGroups;
            ReadOnlyCollection <Group> items;

            groupsForSelected.ItemsSource = null;
            string errorMsg = "";

            if (mode == "comp")
            {
                Title = "Добавление компьютера в группу";
                groupBoxSelectGroup.Header = "Выбор групп для добавления в них компьютера";
            }
            new Thread(() =>
            {
                items = AsyncDataProvider.GetGroupForSelected(_sessionAD, ref errorMsg);
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    groupsForSelected.ItemsSource = items;
                    CollectionView view           = (CollectionView)CollectionViewSource.GetDefaultView(groupsForSelected.ItemsSource);
                    if (view != null)
                    {
                        view.Filter = Groups_Filter;
                        view.SortDescriptions.Clear();
                        view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
                    }
                    if (!string.IsNullOrWhiteSpace(errorMsg))
                    {
                        MessageBox.Show(errorMsg, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }));
            }).Start();
        }