示例#1
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);
            }
        }