Esempio n. 1
0
        public static List <TreeNode> getTree()
        {
            List <TreeNode> nodes = new List <TreeNode>();

            DataTable tb = ConnectionAdmin.getAllConnInfoTable();

            foreach (DataRow row in tb.Rows)
            {
                string conn = row["Name"].ToString();

                TreeNode connNode = new TreeNode()
                {
                    nodeType = (int)DataNodeType.DB,
                    label    = conn,
                    name     = conn,
                    text     = conn,
                    attr     = new Dictionary <string, string>()
                    {
                        { "conn", conn }
                    },
                    id = conn
                };
                nodes.Add(connNode);

                connNode.children = new List <TreeNode>();
                List <TreeNode> subNodes = connNode.children;

                DatabaseAdmin db = null;
                try
                {
                    db = DatabaseAdmin.getInstance(conn);
                }
                catch (Exception e)
                {
                    TreeNode errNode = new TreeNode();
                    errNode.name  = "连接错误:" + e.Message;
                    errNode.label = errNode.name;
                    subNodes.Add(errNode);
                }
                if (db != null)
                {
                    //string connName;
                    List <TreeNode> tbNodes   = new List <TreeNode>();
                    List <TreeNode> viewNodes = new List <TreeNode>();
                    List <TreeNode> spNodes   = new List <TreeNode>();
                    TreeNode        tbNode    = new TreeNode();
                    tbNode.nodeType = (int)DataNodeType.TABLE_FOLDER;
                    tbNode.label    = DataNodeLabel.TABLE_LABEL;
                    tbNode.name     = DataNodeLabel.TABLE_LABEL;
                    tbNode.attr     = new Dictionary <string, string>()
                    {
                        { "conn", conn }
                    };
                    tbNode.id       = "Table";
                    tbNode.text     = DataNodeLabel.TABLE_LABEL;
                    tbNode.children = tbNodes;
                    //Table节点
                    subNodes.Add(tbNode);

                    //获取Table

                    List <string> tbList = null;
                    try
                    {
                        tbList = db.getTableNames();
                    }
                    catch (Exception e)
                    {
                        tbNode.label = e.Message;
                        continue;
                    }

                    if (tbList == null)
                    {
                        continue;
                    }

                    foreach (string t in tbList)
                    {
                        List <TreeNode> tbChildNode   = new List <TreeNode>();
                        List <TreeNode> trigNode      = new List <TreeNode>();
                        List <TreeNode> contriantNode = new List <TreeNode>();

                        //表
                        tbNodes.Add(new TreeNode()
                        {
                            nodeType = (int)DataNodeType.TABLE,
                            label    = t,
                            name     = t,
                            text     = t,
                            attr     = new Dictionary <string, string>()
                            {
                                { "conn", conn }
                            },
                            id       = t,
                            children = tbChildNode
                        });
                    }



                    //存储过程
                    subNodes.Add(new TreeNode()
                    {
                        attr = new Dictionary <string, string>()
                        {
                            { "conn", conn }
                        },
                        nodeType = (int)DataNodeType.SP_FOLDER,
                        label    = DataNodeLabel.SP_LABEL,
                        name     = DataNodeLabel.SP_LABEL,
                        text     = DataNodeLabel.SP_LABEL,
                        id       = "StoreProcess",
                        children = spNodes
                    });

                    //存储过程
                    List <string> spList = db.getProcNames();
                    if (spList != null)
                    {
                        foreach (string sp in spList)
                        {
                            spNodes.Add(new TreeNode()
                            {
                                attr = new Dictionary <string, string>()
                                {
                                    { "conn", conn }
                                },
                                nodeType = (int)DataNodeType.SP,
                                id       = sp,
                                name     = sp,
                                text     = sp,
                                label    = sp
                            });
                        }
                    }

                    //视图
                    subNodes.Add(new TreeNode()
                    {
                        attr = new Dictionary <string, string>()
                        {
                            { "conn", conn }
                        },
                        nodeType = (int)DataNodeType.VIEW_FOLDER,
                        label    = DataNodeLabel.VIEW_LABEL,
                        name     = DataNodeLabel.VIEW_LABEL,
                        id       = "View",
                        text     = DataNodeLabel.VIEW_LABEL,
                        children = viewNodes
                    });

                    //视图
                    List <string> viewList = db.getViewNames();
                    if (viewList != null)
                    {
                        foreach (string view in viewList)
                        {
                            viewNodes.Add(new TreeNode()
                            {
                                attr = new Dictionary <string, string>()
                                {
                                    { "conn", conn }
                                },
                                label    = view,
                                name     = view,
                                id       = view,
                                text     = view,
                                nodeType = (int)DataNodeType.VIEW
                            });
                        }
                    }
                }
            }



            return(nodes);
        }