Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
    private void SendCurrentObjectToTextDiff(bool isSource)
    {
      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);

        frmTextDiff diffForm = frmTextDiff.ActiveTextDiff;
        if (diffForm == null)
        {
          diffForm = TextDiffFactory.CreateDiff();
        }

        if (isSource)
        {
          diffForm.diffControl.SourceText = script;
          diffForm.diffControl.SourceHeaderText = objName;
        }
        else
        {
          diffForm.diffControl.DestText = script;
          diffForm.diffControl.DestHeaderText = objName;
        }
        diffForm.Show();
        diffForm.BringToFront();
      }
    }
Exemplo n.º 6
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);
            }
        }
Exemplo n.º 7
0
        internal static frmScriptEditor Create(ObjectInfo objInfo, ConnectionParams cp, string dBName)
        {
            if (objInfo == null)
            {
                throw new InvalidOperationException("ObjectInfo parameter is null!");
            }

            if (cp == null)
            {
                throw new NullParameterException("ConnectionParams paremeter is null!");
            }


            ConnectionParams tmp = cp.CreateCopy();

            if (!String.IsNullOrEmpty(dBName))
            {
                tmp.Database = dBName;
            }

            string script  = ScriptingHelper.GetAlterScript(tmp, objInfo.ObjectID, objInfo.ObjectType);
            string caption = objInfo.ObjectName;

            frmScriptEditor frm      = null;
            string          windowId = ScriptEditorManager.ProduceWindowId(objInfo.ObjectName, objInfo.ObjectID, objInfo.ObjectType, cp.Server, dBName);

            frm = CheckEditorAlreadyExits(windowId, caption, script);
            if (frm != null)
            {
                return(frm);
            }

            frm = new frmScriptEditor();
            frm.InitializeScriptEditor(caption, script, objInfo.ObjectID, objInfo.ObjectType, cp, String.IsNullOrEmpty(dBName) ? cp.Database : dBName);
            return(frm);
        }
Exemplo n.º 8
0
        public static frmScriptPreview ShowFastPreview(ObjectInfo objInfo, ConnectionParams cp, int posX, int posY)
        {
            if (objInfo == null)
            {
                throw new InvalidOperationException("ObjectInfo parameter is null!");
            }
            if (cp == null)
            {
                throw new InvalidOperationException("Connection params object is null!");
            }

            string script  = ScriptingHelper.GetAlterScript(cp, objInfo.ObjectID, objInfo.ObjectType);
            string caption = "Preview " + objInfo.ObjectName + " {" + cp.InfoDbServer + "}";

            frmScriptPreview frm = new frmScriptPreview();

            frm.Owner = Program.MainForm;
            if (posX > 0 && posY > 0)
            {
                frm.SetLocation(posX, posY);
            }

            frm.ConnParams = cp;
            if (!String.IsNullOrEmpty(caption))
            {
                frm.Text = caption;
            }

            frm._objectInfo      = objInfo;
            frm.Content          = script;
            frm.btnStick.Checked = ConfigHelper.Current != null && ConfigHelper.Current.TextEditorOptions != null && ConfigHelper.Current.TextEditorOptions.ScriptPreviewSticked;

            frm.Show();

            return(frm);
        }
Exemplo n.º 9
0
    private void SendSelectedObjectToTextDiffEx(bool isSource)
    {
      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 cellObjid = row.Cells[0];
        DataGridViewCell cellName = row.Cells[2];
        DataGridViewCell cellType = row.Cells[3];

        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 = ScriptingHelper.GetAlterScript(_connParams, _connParams.Database, objId, type);

          frmTextDiff diffForm = frmTextDiff.ActiveTextDiff;
          if (diffForm == null)
          {
            diffForm = TextDiffFactory.CreateDiff();
          }

          if (isSource)
          {
            diffForm.diffControl.SourceText = script;
            diffForm.diffControl.SourceHeaderText = objName;
          }
          else
          {
            diffForm.diffControl.DestText = script;
            diffForm.diffControl.DestHeaderText = objName;
          }
          diffForm.Show();
          diffForm.BringToFront();
          break;
        }
      }
    }