Exemplo 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);
      }

    }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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);
      }

    }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        private bool EditObjectInScriptEditor()
        {
            if (_objectInfo == null || _cp == null)
            {
                return(false);
            }

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

            ScriptEditorFactory.ShowScriptEditor(editor);
            return(true);
        }
Exemplo n.º 7
0
        private void OnAction_NewScript_Execute(object sender, EventArgs e)
        {
            NodeData data = Program.MainForm.GetCurrentSelectedNodeDataFromObjectExplorer();

            if (data == null)
            {
                return;
            }

            frmScriptEditor editor = ScriptEditorFactory.Create(data);

            ScriptEditorFactory.ShowScriptEditor(editor);
        }
Exemplo n.º 8
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;
            }
        }
Exemplo n.º 9
0
        private void PostAction(DbObjectScripterResult result, bool isCancelled)
        {
            string errors = String.Empty;

            if (result.errors != null && result.errors.Count > 0)
            {
                if (!isCancelled)
                {
                    lblStatus.Text = "Completed with errors!";
                }

                foreach (Exception ex in result.errors)
                {
                    errors += "- " + ex.Message.Replace("\n", " ").Replace("\r", " ") + "\r\n";
                }
            }
            else
            {
                if (!isCancelled)
                {
                    lblStatus.Text = "Completed. Press \"Start\" to script objects.";
                }
            }

            switch (_destination)
            {
            case ScriptDestination.Window:
                string          caption = "Database Objects [" + _connParams.Server + " {" + _connParams.Database + "} ]";
                frmScriptEditor frm     = ScriptEditorFactory.Create(caption, result.script, _connParams);
                ScriptEditorFactory.ShowScriptEditor(frm);
                break;

            case ScriptDestination.File:
                File.AppendAllText(_destPath, result.script);
                break;

            case ScriptDestination.Folder:
                break;
            }

            if (!String.IsNullOrEmpty(errors))
            {
                GenericErrorDialog.ShowError("Error", "Scripting completed with errors! See details below.", errors);
            }
        }
Exemplo n.º 10
0
        public void ModifySelectedObjects( )
        {
            string error = String.Empty;

            IList <frmScriptEditor> editors = new List <frmScriptEditor>();

            foreach (TreeNode node in tv.SelectedNodes)
            {
                ObjectGroupingItemData data = ObjectGroupingItemDataFactory.GetNodeData(node);
                if (data == null)
                {
                    continue;
                }

                ObjectInfo objInfo = ProgrammabilityHelper.GetObjectInfo(_connParams, String.Empty, data.Name);
                if (objInfo == null)
                {
                    error += " - " + data.Name + "\r\n";
                    continue;
                }

                if (!DBConstants.DoesObjectTypeHasScript(data.Type ?? -1))
                {
                    continue;
                }
                string          script = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objInfo.ObjectID, objInfo.ObjectType);
                frmScriptEditor editor = ScriptEditorFactory.Create(objInfo.ObjectName, script, objInfo.ObjectID, objInfo.ObjectType, _connParams, cmbDatabases.Text);
                editors.Add(editor);
            }

            foreach (frmScriptEditor editor in editors)
            {
                ScriptEditorFactory.ShowScriptEditor(editor);
            }

            if (!String.IsNullOrEmpty(error))
            {
                MessageService.ShowError("Objects listed below do not exist in the database!\r\n" + error);
            }
        }