public int SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
        {
            pbstrMkDocumentNew = null; // _view.Name;
            pfSaveCanceled     = 0;

            if (String.IsNullOrEmpty(_view.OriginalSql) == true)
            {
                using (TableNameDialog dlg = new TableNameDialog("View", _view.Name))
                {
                    if (dlg.ShowDialog(this) == DialogResult.Cancel)
                    {
                        pfSaveCanceled = 1;
                        return(VSConstants.S_OK);
                    }
                    _view.Name = dlg.TableName;
                }
            }

            CommitQueryBuilder();

            string query = _view.GetSqlText();

            if (String.IsNullOrEmpty(query) == false)
            {
                using (DbTransaction trans = _view.GetConnection().BeginTransaction())
                {
                    try
                    {
                        using (DbCommand cmd = _view.GetConnection().CreateCommand())
                        {
                            cmd.CommandText = query;
                            cmd.ExecuteNonQuery();
                        }
                        trans.Commit();
                    }
                    catch (Exception)
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }

            _dirty = false;
            _view.Committed();
            NotifyChanges();

            SQLiteCommandHandler.Refresh(_accessor, _itemId);

            return(VSConstants.S_OK);
        }
        /// <summary>
        /// Rename selected table and refresh treeview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void RenameTableHandler(object sender, TableModel e)
        {
            var originalName = e.Title;
            var dialog       = new TableNameDialog()
            {
                Model = e,
                Owner = this
            };

            dialog.ShowDialog();

            string res = _updater.RenameTable(originalName, e);

            if (res != null)
            {
                await this.ShowMessageAsync("Rename table", res);

                Output.WriteLine(OutputPanelListener.PrepareException(res));
                return;
            }

            await DatabaseConnectionSidebar.RefreshTreeData();
        }
    public int SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
    {
      pbstrMkDocumentNew = null; // _view.Name;
      pfSaveCanceled = 0;

      if (String.IsNullOrEmpty(_view.OriginalSql) == true)
      {
        using (TableNameDialog dlg = new TableNameDialog("View", _view.Name))
        {
          if (dlg.ShowDialog(this) == DialogResult.Cancel)
          {
            pfSaveCanceled = 1;
            return VSConstants.S_OK;
          }
          _view.Name = dlg.TableName;
        }
      }

      CommitQueryBuilder();

      string query = _view.GetSqlText();
      if (String.IsNullOrEmpty(query) == false)
      {
        using (DbTransaction trans = _view.GetConnection().BeginTransaction())
        {
          try
          {
            using (DbCommand cmd = _view.GetConnection().CreateCommand())
            {
              cmd.CommandText = query;
              cmd.ExecuteNonQuery();
            }
            trans.Commit();
          }
          catch (Exception)
          {
            trans.Rollback();
            throw;
          }
        }
      }

      _dirty = false;
      _view.Committed();
      NotifyChanges();

      SQLiteCommandHandler.Refresh(_accessor, _itemId);

      return VSConstants.S_OK;
    }
Example #4
0
    public int SaveDocData(VSSAVEFLAGS dwSave, out string pbstrMkDocumentNew, out int pfSaveCanceled)
    {
      pbstrMkDocumentNew = _table.Name;
      pfSaveCanceled = 0;

      if (String.IsNullOrEmpty(_table.OriginalSql) == true)
      {
        using (TableNameDialog dlg = new TableNameDialog("Table", _table.Name))
        {
          if (dlg.ShowDialog(this) == DialogResult.Cancel)
          {
            pfSaveCanceled = 1;
            return VSConstants.S_OK;
          }
          _table.Name = dlg.TableName;
        }
      }

      string sql = GetChangeScript();

      using (DbTransaction trans = _table.GetConnection().BeginTransaction())
      {
        try
        {
          using (DbCommand cmd = _table.GetConnection().CreateCommand())
          {
            cmd.CommandText = sql;
            cmd.ExecuteNonQuery();
          }
          trans.Commit();
        }
        catch (Exception)
        {
          trans.Rollback();
          throw;
        }
      }

      _dirty = false;
      _table.Committed();
      NotifyChanges();
      _sqlText.Text = _table.OriginalSql;

      NpgsqlCommandHandler.Refresh(_accessor, _itemId);

      _dataGrid_SelectionChanged(this, EventArgs.Empty);

      RefreshToolbars();

      return VSConstants.S_OK;
    }
Example #5
0
        /// <summary>
        /// Mouse clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ModelDesignerCanvasOnMouseDown(object sender, MouseButtonEventArgs e)
        {
            switch (ViewModel.MouseMode)
            {
            case MouseMode.Select:
                ModelDesignerCanvas.DeselectTables();
                ModelDesignerCanvas.DeselectLabels();
                _sourceModel      = null;
                _destinationModel = null;
                DeselectConnections();
                ModelDesignerCanvas.ResetZIndexes();

                //Selection rectangle logic
                _dragSelectionStartPoint = e.GetPosition(ModelDesignerCanvas);
                ModelDesignerCanvas.CaptureMouse();
                break;

            case MouseMode.NewTable:
                var origin = e.GetPosition(ModelDesignerCanvas);
                var table  = new TableViewModel(new TableModel());

                var nameDialog = new TableNameDialog
                {
                    Owner = Window.GetWindow(this), Model = table.Model
                };
                var res = nameDialog.ShowDialog();

                if (res.HasValue)
                {
                    if (res.Value)
                    {
                        MainWindow window = null;
                        try
                        {
                            window = Window.GetWindow(this) as MainWindow;
                            var facade = new DiagramFacade(ViewModel);

                            bool addRes = facade.AddTable(table.Model.Title, (int)origin.X, (int)origin.Y);

                            if (!addRes)
                            {
                                await window.ShowMessageAsync("Add new table", $"Table {table.Model.Title} already exists");
                            }
                            else
                            {
                                OnTableCreated();
                            }
                        }
                        catch (Exception exception) when(exception is SqlException || exception is OracleException)
                        {
                            await window.ShowMessageAsync("Add new table", exception.Message);
                        }
                    }
                }
                ViewModel.MouseMode = MouseMode.Select;
                break;

            case MouseMode.NewLabel:
                var originLabel = e.GetPosition(ModelDesignerCanvas);
                ViewModel.LabelViewModels.Add(new LabelViewModel()
                {
                    Left = originLabel.X,
                    Top  = originLabel.Y
                });
                ViewModel.MouseMode = MouseMode.Select;
                break;
            }
        }