Beispiel #1
0
        private void cmbTables_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_initializing || SelectedKey == null)
            {
                return;
            }

            TableWrapper selTable = cmbTables.SelectedItem as TableWrapper;

            if (selTable == null)
            {
                SelectedKey.Table = selTable;
                return;
            }

            TableWrapper tbl = new TableWrapper();

            tbl.ConnectionParams = _cp;
            tbl.ID = selTable.ID;
            tbl.LoadProperties();
            tbl.LoadColumns();
            SelectedKey.Table = tbl;


            lbPkCols.Items.Clear();
            SelectedKey.Columns.Clear();
            InitializeTableColumns();
        }
Beispiel #2
0
        public override void Run( )
        {
            base.Run();
            IObjectExplorerService srv = HostServicesSingleton.HostServices.ObjectExplorerService;

            if (srv == null)
            {
                MessageService.ShowError("No object explorer available!");
                return;
            }

            if (srv.SelNode == null || srv.SelNode.ConnParams == null || String.IsNullOrEmpty(srv.SelNode.ConnParams.Database))
            {
                MessageService.ShowError("Database data is not available!");
                return;
            }

            if (srv.SelNode.Type != DBObjectType.UserTable)
            {
                MessageService.ShowError("Selected node is not a user defined table!");
                return;
            }


            ConnectionParams cp = srv.SelNode.ConnParams.CreateCopy();

            cp.Database = srv.SelNode.DatabaseName;

            TableWrapper tbl = new TableWrapper(cp);

            tbl.ID = srv.SelNode.id;
            tbl.LoadProperties();
            //tbl.Name = srv.SelNode.Name;

            string newName = srv.SelNode.Name;

            if (InputDialog.ShowDialog("Rename Table", "New Name", ref newName) != DialogResult.OK)
            {
                return;
            }

            if (tbl.Name.ToLowerInvariant() == newName.ToLowerInvariant())
            {
                return;
            }

            try
            {
                tbl.Rename(newName);
                srv.ChangeObjectName(srv.SelNode.Node, newName);
                srv.LoadNodeData(srv.SelNode.Node, true);
            }
            catch (Exception ex)
            {
                MessageService.ShowError(ex.Message);
            }
        }
Beispiel #3
0
        private void ModifySelectedForeignKey( )
        {
            if (grd.CurrentRow == null)
            {
                KeyPanelVisible = false;
                return;
            }

            DataGridViewRow row = grd.CurrentRow;

            long         tableId = (int)row.Cells[1].Value;
            TableWrapper hostTbl = new TableWrapper(tableId);

            hostTbl.ConnectionParams = _cp;
            hostTbl.LoadProperties();
            _foreignKeyEdit.InitializeForeignKeys(TableKeyEditorMode.SingleTable, hostTbl, (int)row.Cells[0].Value);

            UpdateHeaderText();
            KeyPanelVisible = true;
        }
Beispiel #4
0
 private void PopulateTableData( )
 {
     _table.LoadProperties();
     _table.LoadColumns();
     RenderTableProperties();
 }
Beispiel #5
0
        public void GetKey( )
        {
            //Set the key Option
            string cmdText = "declare @cmplevel int select @cmplevel = cmptlevel  from  master..sysdatabases where name = DB_NAME() ";

            cmdText += "SELECT ";
            cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsDisabled') as IsDisabled,";
            cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsNotRepl') as IsNotRepl,";
            cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsUpdateCascade') as IsUpdateCascade,";
            cmdText += " ObjectProperty(" + ID.ToString() + " , 'CnstIsDeleteCascade') as IsDeleteCascade,";
            cmdText += " dbo.sysreferences.constid, CASE WHEN @cmplevel < 90  THEN  USER_NAME(hostTable.uid)  ELSE SCHEMA_NAME(hostTable.uid) END   AS unamehost, hostTable.name AS host, hostTable.id as hostID, refTable.id as refID, CASE WHEN @cmplevel < 90  THEN  USER_NAME(refTable.uid)  ELSE SCHEMA_NAME(refTable.uid) END   AS unameref, refTable.name AS ref";
            cmdText += " FROM dbo.sysreferences INNER JOIN dbo.sysobjects hostTable ON dbo.sysreferences.fkeyid = hostTable.id INNER JOIN dbo.sysobjects refTable ON dbo.sysreferences.rkeyid = refTable.id";
            cmdText += " WHERE (dbo.sysreferences.constid = " + ID.ToString() + ")";

            using (SqlConnection conn = _cp.CreateSqlConnection(true, false))
            {
                SqlDataReader reader = DbCmd.ExecuteReader(cmdText, conn);
                try
                {
                    while (reader.Read())
                    {
                        _notForReplication = Convert.ToBoolean(reader["IsNotRepl"]);
                        _disabled          = Convert.ToBoolean(reader["IsDisabled"]);
                        _cascadeUpdate     = Convert.ToBoolean(reader["IsUpdateCascade"]);
                        _cascadeDelete     = Convert.ToBoolean(reader["IsDeleteCascade"]);

                        _hostTable.ID = Convert.ToInt64(reader["hostID"]);
                        _hostTable.LoadProperties();
                        _hostTable.LoadColumns();

                        _refTable.ID = Convert.ToInt64(reader["refID"]);
                        _refTable.LoadProperties();
                        _refTable.LoadColumns();
                    }
                }
                finally
                {
                    reader.Close();
                    reader.Dispose();
                }

                //Key referenced
                cmdText = "SELECT sysindexes.indid, sysindexes.name as keyName"
                          + " FROM sysindexes, sysreferences "
                          + " WHERE sysreferences.rkeyid=sysindexes.id AND sysreferences.rkeyindid=sysindexes.indid "
                          + " AND sysreferences.rkeyid=" + _refTable.ID
                          + " AND OBJECT_NAME(sysreferences.constid)='" + this.NormalizedName + "'";

                SqlDataReader readerKey = DbCmd.ExecuteReader(cmdText, conn);
                try
                {
                    while (readerKey.Read())
                    {
                        _referencedKey.Id   = (short)readerKey["indid"];
                        _referencedKey.Name = (string)readerKey["keyName"];
                    }
                }
                finally
                {
                    readerKey.Close();
                    readerKey.Dispose();
                }
            }
        }