Esempio n. 1
0
        private void ImportMultipleTables(object sender, RoutedEventArgs e)
        {
            try
            {
                var item = ProjectItems.SelectedItem as TreeViewItem;
                if (null == item)
                    return;

                var tag = item.Tag as ScriptNodeTag;

                if (tag == null)
                {
                    return;
                }

                var tableRepository = tag.Tables;

                if (tableRepository == null)
                {
                    MessageBox.Show("Unable to read table repository - try refreshing");
                    return;
                }

                var tables = tableRepository.Get().OrderBy(p => p.Name.GetSchema() + p.Name.GetName());
                var tableList = new List<string>();

                foreach (var table in tables)
                {
                    tableList.Add(string.Format("{0}.{1}", table.Name.GetSchema().Quote(), table.Name.GetName().Quote()));
                }

                var dialog = new ImportMultipleTablesDialog(tableList);
                dialog.ShowDialog();

                foreach (var import in dialog.GetImportedTables())
                {
                    var mergeTable =
                        tables.FirstOrDefault(
                            p => string.Format("{0}.{1}", p.Name.GetSchema().Quote(), p.Name.GetName().Quote()) == import.Name);

                    var merge = new MergeStatementFactory().Build(mergeTable, tag.ScriptPath, import.Data);
                    merge.Data.ExtendedProperties["Changed"] = true;
                    var mergeNode = new TreeViewItem();
                    mergeNode.Header = merge.Name.Value;
                    mergeNode.Tag = merge;
                    mergeNode.ContextMenu = ProjectItems.Resources["TableContext"] as ContextMenu;
                    item.Items.Add(mergeNode);

                    God.MergesToSave.Add(merge);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to import tables: " + ex.Message);
            }
        }
Esempio n. 2
0
        private void MenuItem_AddTableOnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var item = ProjectItems.SelectedItem as TreeViewItem;
                if (null == item)
                    return;

                var tag = item.Tag as ScriptNodeTag;

                if (tag == null)
                {
                    return;
                }


                var tableRepository = tag.Tables;

                if (tableRepository == null)
                {
                    MessageBox.Show("Unable to read table repository - try refreshing");
                    return;
                }

                var tables = tableRepository.Get().OrderBy(p => p.Name.GetSchema() + p.Name.GetName());
                var tableList = new List<string>();

                foreach (var table in tables)
                {
                    tableList.Add(string.Format("{0}.{1}", table.Name.GetSchema().Quote(), table.Name.GetName().Quote()));
                }

                var dialog = new AddTableDialog(tableList);
                dialog.ShowDialog();

                var tableName = dialog.GetSelectedTable();

                if (String.IsNullOrEmpty(tableName))
                    return;

                var mergeTable =
                    tables.FirstOrDefault(
                        p => string.Format("{0}.{1}", p.Name.GetSchema().Quote(), p.Name.GetName().Quote()) == tableName);

                var merge = new MergeStatementFactory().Build(mergeTable, tag.ScriptPath);

                var mergeNode = new TreeViewItem();
                mergeNode.Header = merge.Name.Value;
                mergeNode.Tag = merge;
                mergeNode.ContextMenu = ProjectItems.Resources["TableContext"] as ContextMenu;
                item.Items.Add(mergeNode);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to add new table: " + ex.Message);
            }
        }