Esempio n. 1
0
    private void PerformActionOnCurrentRow()
    {
      if (_bs.Current == null)
      {
        return;
      }

      DataRowView rw = _bs.Current as DataRowView;
      if (rw == null)
        return;

      int objId = (int)rw.Row.ItemArray[0];
      string objType = (string)rw.Row.ItemArray[3];
      string objName = (string)rw.Row.ItemArray[2];

      if (DBConstants.DoesObjectTypeHasScript(objType))
      {
        int type = DBConstants.GetDBObjectType(objType);
        string script = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objId, type);
        frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _connParams.Database);
        ScriptEditorFactory.ShowScriptEditor(editor);
      }
      else if (DBConstants.DoesObjectTypeHoldsData(objType))
      {
        int type = DBConstants.GetDBObjectType(objType);
        string caption = objName + "{" + _connParams.InfoDbServer + "}";
        string script = " select * from [" + objName + "]";
        bool isReadOnly = (type == DBObjectType.View) ? true : false;

        frmDataViewer viewer = DataViewerFactory.CreateDataViewer(_connParams, _connParams.Database, objName, caption, script, isReadOnly, true);
        DataViewerFactory.ShowDataViewer(viewer);
      }

    }
Esempio n. 2
0
        public static frmScriptEditor Create(string caption, string script, NodeData data)
        {
            frmScriptEditor frm = Create(caption, data);

            frm.ScriptText = script;
            return(frm);
        }
Esempio n. 3
0
        private void SwitchToScriptEditor()
        {
            ConnectionParams cp = frmConnectionRepository.SelectSingleConnection(true, true);

            if (cp == null)
            {
                return;
            }

            string content  = this.Content;
            string caption  = this.Caption;
            string filePath = this.FileName;

            frmScriptEditor scriptEditor = ScriptEditorFactory.Create(caption, content, cp, filePath);

            scriptEditor.ContentModified    = base.ContentModified;
            scriptEditor.IsRecoveredContent = base.IsRecoveredContent;
            scriptEditor.ContentPersister   = ContentPersister;
            if (ContentPersister.ContentType == EditorContentType.SharedScript || ContentPersister.ContentType == EditorContentType.SharedSnippet)
            {
                scriptEditor.Icon = this.Icon;
            }

            if (base.ContentModified)
            {
                base.ContentModified = false;
            }

            ScriptEditorFactory.ShowScriptEditor(scriptEditor);
            this.Close();
        }
Esempio n. 4
0
    private void ModifyCurrentObject()
    {
      if (_bs.Current == null)
      {
        return;
      }

      DataRowView rw = _bs.Current as DataRowView;
      if (rw == null)
        return;


      int objId = (int)rw.Row.ItemArray[0];
      string objName = (string)rw.Row.ItemArray[2];
      string objType = (string)rw.Row.ItemArray[3];

      if (DBConstants.DoesObjectTypeHasScript(objType))
      {
        int type = DBConstants.GetDBObjectType(objType);
        string script = ScriptingHelper.GetAlterScript(_connParams.ConnectionString, _connParams.Database, objId, type);
        frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _connParams.Database);
        ScriptEditorFactory.ShowScriptEditor(editor);
      }

    }
Esempio n. 5
0
        public static frmScriptEditor OpenSharedScript(SharedScriptsItemData itemData, ConnectionParams cp)
        {
            string dbName  = String.Empty;
            string caption = String.Empty;
            string script  = String.Empty;

            if (itemData == null)
            {
                throw new NullParameterException("ItemData is null!");
            }


            if (cp != null)
            {
                dbName = cp.Database;
            }



            caption = itemData.Name + "{Shared script}";
            script  = itemData.Script;

            frmScriptEditor frm = new frmScriptEditor();

            frm.Icon = PragmaSQL.Properties.Resources.sharedScript;

            frm.ContentPersister             = new SharedScriptContentPersister();
            frm.ContentPersister.Data        = itemData;
            frm.ContentPersister.Hint        = "This is a shared script: " + itemData.Name;
            frm.ContentInfo                  = frm.ContentPersister.Hint;
            frm.ContentPersister.ContentName = itemData.Name;
            frm.InitializeScriptEditor(caption, script, DBObjectType.None, cp, dbName);

            return(frm);
        }
Esempio n. 6
0
        internal static frmScriptEditor Create(string caption, string script, int objectType, NodeData data)
        {
            frmScriptEditor frm = Create(caption, script, data);

            frm.ObjectType = objectType;
            return(frm);
        }
Esempio n. 7
0
        private void PerformActionOnFirstSelectedRow( )
        {
            if (grd.SelectedRows.Count == 0)
            {
                return;
            }

            int    objId   = -1;
            string objType = String.Empty;
            string objName = String.Empty;


            DataGridViewRow row = grd.SelectedRows[0];

            DataGridViewCell cellName  = row.Cells[0];
            DataGridViewCell cellType  = row.Cells[1];
            DataGridViewCell cellObjid = row.Cells[2];

            if (cellName.ValueType != typeof(string) || cellName.Value == null)
            {
                return;
            }

            if (cellType.ValueType != typeof(string) || cellType.Value == null)
            {
                return;
            }

            if (cellObjid.ValueType != typeof(int) || cellObjid.Value == null)
            {
                return;
            }

            objId   = (int)cellObjid.Value;
            objType = (string)cellType.Value;
            objName = (string)cellName.Value;

            if (DBConstants.DoesObjectTypeHasScript(objType))
            {
                int    type   = DBConstants.GetDBObjectType(objType);
                string script = String.Empty;
                using (SqlConnection conn = _connParams.CreateSqlConnection(true, false))
                {
                    script = ScriptingHelper.GetAlterScript(conn, objId, type);
                }
                frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _dbName);
                ScriptEditorFactory.ShowScriptEditor(editor);
            }
            else if (DBConstants.DoesObjectTypeHoldsData(objType))
            {
                int    type       = DBConstants.GetDBObjectType(objType);
                string caption    = objName + "{" + _dbName + " on " + _connParams.Server + "}";
                string script     = " select * from [" + objName + "]";
                bool   isReadOnly = (type == DBObjectType.View) ? true : false;

                frmDataViewer viewer = DataViewerFactory.CreateDataViewer(_connParams, _dbName, objName, caption, script, isReadOnly, true);
                DataViewerFactory.ShowDataViewer(viewer);
            }
        }
        private void OnHelpUsedSpaceClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.UsedSpace);
            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_spaceused", "USED_SPACE", true, true);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.UsedSpace);
        }
        private void OnHelpConstraintsClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.Contraints);
            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_helpconstraint", "CONSTRAINTS", true, true);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.Contraints);
        }
Esempio n. 10
0
        private void OnHelpColumnPermissionClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.ColumnPermissions);
            frmScriptEditor editor = CreateScriptEditorForColumnPermissions("COLUMN PERMISSIONS", true);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.ColumnPermissions);
        }
Esempio n. 11
0
        private void OnObjectHelpClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.ObjectHelp);
            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_help", "OBJECT HELP", true, true);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.ObjectHelp);
        }
Esempio n. 12
0
        private void OnHelpObjectPermissionClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.ObjectPermissions);
            frmScriptEditor editor = CreateObjectPermissionsScriptEditor(true);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.ObjectPermissions);
        }
Esempio n. 13
0
        private void OnHelpPermissionClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.Permissions);

            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_table_privileges", "PERMISSIONS", true);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.Permissions);
        }
Esempio n. 14
0
        private void OnHelpDependsClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.Dependencies);

            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_depends", "DEPENDENCIES", true, true);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.Dependencies);
        }
Esempio n. 15
0
        private void ModifySelectedObjects( )
        {
            if (grd.SelectedRows.Count == 0)
            {
                return;
            }

            int    objId   = -1;
            string objType = String.Empty;
            string objName = String.Empty;
            IList <frmScriptEditor> editors = new List <frmScriptEditor>();

            foreach (DataGridViewRow row in grd.SelectedRows)
            {
                DataGridViewCell cellName  = row.Cells[0];
                DataGridViewCell cellType  = row.Cells[1];
                DataGridViewCell cellObjid = row.Cells[2];

                if (cellName.ValueType != typeof(string) || cellName.Value == null)
                {
                    continue;
                }

                if (cellType.ValueType != typeof(string) || cellType.Value == null)
                {
                    continue;
                }

                if (cellObjid.ValueType != typeof(int) || cellObjid.Value == null)
                {
                    continue;
                }

                objId   = (int)cellObjid.Value;
                objType = (string)cellType.Value;
                objName = (string)cellName.Value;

                if (DBConstants.DoesObjectTypeHasScript(objType))
                {
                    int    type   = DBConstants.GetDBObjectType(objType);
                    string script = String.Empty;
                    using (SqlConnection conn = _connParams.CreateSqlConnection(true, false))
                    {
                        script = ScriptingHelper.GetAlterScript(conn, objId, type);
                    }
                    frmScriptEditor editor = ScriptEditorFactory.Create(objName, script, objId, type, _connParams, _dbName);
                    editors.Add(editor);
                }
            }

            foreach (frmScriptEditor editor in editors)
            {
                ScriptEditorFactory.ShowScriptEditor(editor);
            }
        }
Esempio n. 16
0
        public static frmScriptEditor Create(string caption, string script, int objectType, ConnectionParams cp, string dBName)
        {
            if (cp == null)
            {
                throw new NullParameterException("ConnectionParams paremeter is null!");
            }
            frmScriptEditor frm = new frmScriptEditor();

            frm.InitializeScriptEditor(caption, script, objectType, cp, dBName);
            return(frm);
        }
Esempio n. 17
0
        public static frmScriptEditor Create(string caption, string script, ConnectionParams cp)
        {
            if (cp == null)
            {
                throw new NullParameterException("ConnectionParams paremeter is null!");
            }
            frmScriptEditor frm = new frmScriptEditor();

            frm.InitializeScriptEditor(caption, script, DBObjectType.None, cp, cp.Database);
            return(frm);
        }
Esempio n. 18
0
        public static frmScriptEditor Create(string caption, NodeData data)
        {
            if (data == null)
            {
                throw new NullParameterException("NodeData paremeter is null!");
            }
            frmScriptEditor frm = new frmScriptEditor();

            frm.InitializeScriptEditor(caption, String.Empty, DBObjectType.None, data.ConnParams, data.DBName);
            return(frm);
        }
Esempio n. 19
0
        internal static frmScriptEditor CreateNew(string caption, string script, NodeData data)
        {
            if (data == null)
            {
                throw new NullParameterException("NodeData paremeter is null!");
            }

            frmScriptEditor frm = new frmScriptEditor();

            frm.InitializeScriptEditor(caption, script, data.ID, data.Type, data.ConnParams, data.DBName, false);
            return(frm);
        }
Esempio n. 20
0
        private bool EditObjectInScriptEditor()
        {
            if (_objectInfo == null || _cp == null)
            {
                return(false);
            }

            frmScriptEditor editor = ScriptEditorFactory.Create(_objectInfo, _cp, _cp.Database);

            ScriptEditorFactory.ShowScriptEditor(editor);
            return(true);
        }
Esempio n. 21
0
        private void OnAction_OpenFromFile_Execute(object sender, EventArgs e)
        {
            NodeData data = Program.MainForm.GetCurrentSelectedNodeDataFromObjectExplorer();

            if (data == null)
            {
                return;
            }
            frmScriptEditor editor = ScriptEditorFactory.OpenFile(String.Empty, data);

            ScriptEditorFactory.ShowScriptEditor(editor);
        }
Esempio n. 22
0
        public static frmScriptEditor OpenFile(string fileName, NodeData data)
        {
            frmScriptEditor frm = Create(data);

            if (!frm.OpenFile(fileName))
            {
                _instanceCnt--;
                frm.Close();
                frm.Dispose();
                return(null);
            }
            return(frm);
        }
Esempio n. 23
0
        internal static frmScriptEditor OpenFile(string fileName, ConnectionParams cp)
        {
            frmScriptEditor frm = Create(String.Empty, cp);

            if (!frm.OpenFile(fileName))
            {
                frm.Close();
                frm.Dispose();
                return(null);
            }
            frm.ContentPersister.ContentType = EditorContentType.File;
            return(frm);
        }
        private void OnAction_NewScript_Execute(object sender, EventArgs e)
        {
            NodeData data = Program.MainForm.GetCurrentSelectedNodeDataFromObjectExplorer();

            if (data == null)
            {
                return;
            }

            frmScriptEditor editor = ScriptEditorFactory.CreateScriptEditor(data);

            ScriptEditorFactory.ShowScriptEditor(editor);
        }
Esempio n. 25
0
        public static frmScriptEditor OpenFile(string fileName, ConnectionParams cp)
        {
            frmScriptEditor frm = Create(cp);

            if (!frm.OpenFile(fileName))
            {
                _instanceCnt--;
                frm.Close();
                frm.Dispose();
                return(null);
            }
            return(frm);
        }
Esempio n. 26
0
        public static void Remember(string id, frmScriptEditor editor)
        {
            if (String.IsNullOrEmpty(id) || editor == null)
            {
                return;
            }

            if (_editors.ContainsKey(id))
            {
                _editors[id] = editor;
            }
            else
            {
                _editors.Add(id, editor);
            }
        }
Esempio n. 27
0
        public void LoadScriptFile(string fileName, ConnectionParams cp)
        {
            frmScriptEditor frm = null;

            try
            {
                frm = ScriptEditorFactory.OpenFile(fileName, cp);
                ScriptEditorFactory.ShowScriptEditor(frm);
            }
            catch (Exception ex)
            {
                frm.Dispose();
                frm = null;
                throw ex;
            }
        }
Esempio n. 28
0
        public void CreateScriptEditor(string caption, string script, ConnectionParams cp)
        {
            frmScriptEditor frm = null;

            try
            {
                frm = ScriptEditorFactory.Create(caption, script, cp);
                ScriptEditorFactory.ShowScriptEditor(frm);
            }
            catch (Exception ex)
            {
                frm.Dispose();
                frm = null;
                throw ex;
            }
        }
Esempio n. 29
0
        private void OnHelpStatisticsClick(object sender, EventArgs e)
        {
            FireBeforeContextMenuActionExecuted(sender, ObjectExplorerAction.Statistics);

            NodeData data = SelectedNode != null?NodeDataFactory.GetNodeData(SelectedNode.Tag) : null;

            if (data == null)
            {
                return;
            }

            frmScriptEditor editor = CreateScriptEditorForObjectInfo("sp_statistics", "STATISTICS", true, data.Name, data.Owner);

            editor.Icon = global::PragmaSQL.Properties.Resources.Help;
            FireAfterContextMenuActionExecuted(sender, ObjectExplorerAction.Statistics);
        }
Esempio n. 30
0
        internal static frmScriptEditor OpenFile(string fileName, NodeData data)
        {
            ConnectionParams cp = data.ConnParams.CreateCopy();

            cp.Database = data.DBName;
            frmScriptEditor frm = Create(String.Empty, cp);

            if (!frm.OpenFile(fileName))
            {
                frm.Close();
                frm.Dispose();
                return(null);
            }
            frm.ContentPersister.ContentType = EditorContentType.File;
            return(frm);
        }