示例#1
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);
            }
        }
        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);
            }
        }