Ejemplo n.º 1
0
        private async void EditIndex_Click(object sender, RoutedEventArgs e)
        {
            if (ApplicationView.CurrentIndexFile == null)
            {
                return;
            }

            IndexDialog dialog = new IndexDialog
            {
                DataContext = ApplicationView.CurrentIndexFile,
                Owner       = this,
                IsNew       = false,
                ResizeMode  = System.Windows.ResizeMode.NoResize
            };

            if (dialog.ShowDialog() == true)
            {
                ApplicationView.CurrentIndexFile.SaveIndexFile();
                await ApplicationViewService.UpdateIndex();
            }
            else
            {
                await ApplicationViewService.LoadIndex(ApplicationView.CurrentIndexFile.IndexFile);
            }
        }
Ejemplo n.º 2
0
        public void AddIndex(object sender, ExecutedRoutedEventArgs e)
        {
            var menuInfo = ValidateMenuInfo(sender);

            if (menuInfo == null)
            {
                return;
            }
            try
            {
                using (var repository = DataConnectionHelper.CreateRepository(menuInfo.DatabaseInfo))
                {
                    IndexDialog idxDlg = new IndexDialog(menuInfo.Name);
                    idxDlg.Columns = repository.GetAllColumns().Where(c => c.TableName == menuInfo.Name).ToList();
                    if (idxDlg.ShowModal() == true)
                    {
                        //var generator = Helpers.DataConnectionHelper.CreateGenerator(repository, menuInfo.DatabaseInfo.DatabaseType);
                        Index         idx      = idxDlg.NewIndex;
                        StringBuilder sbScript = new StringBuilder();

                        sbScript.Append("CREATE ");
                        if (idx.Unique)
                        {
                            sbScript.Append("UNIQUE ");
                        }
                        sbScript.AppendFormat("INDEX [{0}] ON [{1}] (", idx.IndexName, idx.TableName);
                        sbScript.AppendFormat("[{0}] {1}", idx.ColumnName, idx.SortOrder.ToString());
                        sbScript.AppendLine(");");

                        //foreach (Index col in indexes)
                        //{
                        //    _sbScript.AppendFormat("[{0}] {1},", col.ColumnName, col.SortOrder.ToString());
                        //}
                        //// Remove the last comma
                        //_sbScript.Remove(_sbScript.Length - 1, 1);
                        //_sbScript.AppendLine(");");

                        sbScript.Append("GO" + Environment.NewLine);

                        OpenSqlEditorToolWindow(menuInfo, sbScript.ToString());
                        DataConnectionHelper.LogUsage("TableIndexAdd");
                    }
                }
            }
            catch (Exception ex)
            {
                DataConnectionHelper.SendError(ex, menuInfo.DatabaseInfo.DatabaseType, false);
            }
        }
        protected override void Execute(ApplicationViewModel contextViewModel)
        {
            IndexViewModel dialogModel = new IndexViewModel();
            IndexDialog    dialog      = new IndexDialog
            {
                DataContext = dialogModel,
                Owner       = App.Current.MainWindow,
                IsNew       = true,
                ResizeMode  = System.Windows.ResizeMode.NoResize
            };

            if (dialog.ShowDialog() == true)
            {
                CreateIndex(contextViewModel, dialogModel);
            }
        }