private void ButtonEditChairs_Click(object sender, RoutedEventArgs e)
        {
            if (firebirdClient == null)
            {
                firebirdClient = new Infoscreen.FirebirdClient(
                    configuration.DataBaseAddress,
                    configuration.DataBaseName,
                    configuration.DataBaseUserName,
                    configuration.DataBasePassword);
            }

            if (chairItemsCache.Count == 0)
            {
                GetChairItems();
            }

            if (chairItemsCache.Count == 0)
            {
                return;
            }

            Infoscreen.Configuration.ItemSystem itemSystem =
                (sender as Button).DataContext as Infoscreen.Configuration.ItemSystem;
            string systemName = itemSystem.SystemName;

            WindowEditSystemChairs windowAddOrEditSystem =
                new WindowEditSystemChairs(chairItemsCache, systemName, itemSystem.ChairItems);

            windowAddOrEditSystem.Owner = Window.GetWindow(this);
            windowAddOrEditSystem.ShowDialog();
        }
        private async void UpdateSystemItems()
        {
            if (string.IsNullOrEmpty(configuration.ActiveDirectoryOU))
            {
                MessageBox.Show(Application.Current.MainWindow,
                                "Не выбрано подразделение ActiveDirectory в разделе 'Внутренние настройки'", "Ошибка конфигурации",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            List <Infoscreen.Configuration.ItemSystem> itemSystems = new List <Infoscreen.Configuration.ItemSystem>();
            await Task.Run(() => {
                string searchPath = "LDAP://" + configuration.ActiveDirectoryOU;

                try {
                    using (DirectoryEntry entry = new DirectoryEntry(searchPath)) {
                        using (DirectorySearcher mySearcher = new DirectorySearcher(entry)) {
                            mySearcher.SearchScope = SearchScope.Subtree;
                            mySearcher.Filter      = ("(objectClass=Computer)");
                            mySearcher.SizeLimit   = int.MaxValue;
                            mySearcher.PageSize    = int.MaxValue;

                            foreach (SearchResult resEnt in mySearcher.FindAll())
                            {
                                try {
                                    string name = resEnt.Properties["name"][0].ToString();
                                    string dn   = resEnt.Properties["distinguishedName"][0].ToString();

                                    Infoscreen.Configuration.ItemSystem itemSystem = new Infoscreen.Configuration.ItemSystem()
                                    {
                                        SystemName = name,
                                        SystemUnit = dn.Replace(configuration.ActiveDirectoryOU, "").
                                                     Replace("CN=" + name + ",", "").
                                                     TrimEnd(',').
                                                     TrimStart(new char[] { 'O', 'U', '=' }).
                                                     Replace(",OU=", ", ")
                                    };

                                    try {
                                        IEnumerable <Infoscreen.Configuration.ItemSystem> systemsInConfig =
                                            configuration.SystemItems.Where(
                                                x => x.SystemName.ToUpper().Equals(itemSystem.SystemName.ToUpper()));

                                        if (systemsInConfig.Count() == 1)
                                        {
                                            itemSystem = systemsInConfig.First();
                                        }
                                    } catch (Exception excInner) {
                                        Console.WriteLine(excInner.Message + Environment.NewLine + excInner.StackTrace);
                                    }

                                    itemSystems.Add(itemSystem);
                                } catch (Exception exc) {
                                    Console.WriteLine(exc.Message + Environment.NewLine + exc.StackTrace);
                                }
                            }
                        }
                    }
                } catch (Exception exceptionLdap) {
                    Console.WriteLine(exceptionLdap.Message + Environment.NewLine + exceptionLdap.StackTrace);
                }
            });

            configuration.SystemItems.Clear();
            itemSystems.ForEach(configuration.SystemItems.Add);
        }