Beispiel #1
0
        private void AddDatabaseCommand(object parameter)
        {
            if (!(parameter is TreeNodeViewModel treeNode))
            {
                return;
            }
            if (!(treeNode.NodePayload is DatabaseServer server))
            {
                return;
            }

            IMetadataService    metadata  = Services.GetService <IMetadataService>();
            List <DatabaseInfo> databases = metadata.GetDatabases(server);

            if (databases.Count == 0)
            {
                MessageBox.Show("Список выбора баз данных пуст.",
                                "DaJet", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            SelectDatabaseWindow dialog = new SelectDatabaseWindow(databases);

            _ = dialog.ShowDialog();
            if (dialog.Result == null)
            {
                return;
            }

            if (DatabaseNameExists(server, dialog.Result))
            {
                MessageBox.Show("База данных " + dialog.Result.Name + " уже добавлена.",
                                "DaJet", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            DatabaseFormWindow form = new DatabaseFormWindow(dialog.Result);

            _ = form.ShowDialog();

            if (DatabaseNameExists(server, dialog.Result))
            {
                MessageBox.Show("База данных " + dialog.Result.Name + " уже добавлена.",
                                "DaJet", MessageBoxButton.OK, MessageBoxImage.Information);
                return;
            }

            server.Databases.Add(dialog.Result);
            SaveMetadataSettings();

            InitializeMetadata(server, dialog.Result);

            TreeNodeViewModel databaseNode = CreateDatabaseTreeNode(treeNode, dialog.Result);

            treeNode.TreeNodes.Add(databaseNode);
            treeNode.IsExpanded     = true;
            databaseNode.IsSelected = true;

            InitializeDatabaseTreeNodes(databaseNode);
        }