Пример #1
0
        private void CreatChildNodes(UltraTreeNode tNode)
        {
            try
            {
                var sql        = string.Empty;
                var nodeTag    = string.Empty;
                var isRootNode = false;
                var imgIndex   = 0;
                if (tNode.Tag == "tables")
                {
                    //sql = "select name, (SELECT SUM (row_count) FROM sys.dm_db_partition_stats WHERE object_id=s.id) as 'rowcount' from sysobjects s WHERE xtype='u' ORDER BY name";
                    sql        = "SELECT so.name, [RowCount] = MAX(si.rows) FROM sysobjects so, sysindexes si WHERE so.xtype = 'U' AND si.id = OBJECT_ID(so.name) GROUP BY so.name ORDER BY 1";
                    nodeTag    = "table";
                    isRootNode = true;
                    imgIndex   = 2;
                }
                else if (tNode.Tag == "procs")
                {
                    sql        = "select name from sysobjects where xtype='p' ORDER BY name";
                    nodeTag    = "proc";
                    isRootNode = true;
                    imgIndex   = 3;
                }
                else if (tNode.Tag == "views")
                {
                    sql        = "select name from sysobjects where xtype='v' ORDER BY name";
                    nodeTag    = "view";
                    isRootNode = true;
                    imgIndex   = 4;
                }
                else if (tNode.Tag == "functions")
                {
                    sql        = "select name from sysobjects where xtype='fn' ORDER BY name";
                    nodeTag    = "function";
                    isRootNode = true;
                    imgIndex   = 5;
                }
                var isCleared = false;
                var initCount = tNode.Nodes.Count;
                if (isRootNode && tNode.Nodes.Count == 1)
                {
                    tNode.Nodes.Clear();
                    isCleared = true;
                    Framework.Components.DataAccess.StartUp.EntryPoint(path, timeout, Database);
                    var oDT = new Framework.Components.DataAccess.DBDataTable("Get List", sql, Database);
                    if (oDT.DBTable != null && oDT.DBTable.Rows.Count > 0)
                    {
                        var categoryItemList = CategoryItem.GetList();
                        foreach (DataRow dr in oDT.DBTable.Rows)
                        {
                            bool isExist = false;
                            if (categoryItemList != null && categoryItemList.Rows.Count > 0)
                            {
                                var rows = categoryItemList.Select(" Name = '" + Convert.ToString(dr["name"]) + "'");
                                if (rows.Length > 0)
                                {
                                    isExist = true;
                                }
                            }

                            if (!tNode.Nodes.Exists(Convert.ToString(dr["name"])) && !isExist)
                            {
                                var nodeName = Convert.ToString(dr["name"]);
                                if (tNode.Tag == "tables")
                                {
                                    nodeName += "(" + Convert.ToString(dr["rowcount"]) + ")";
                                }
                                var tmpNode = tNode.Nodes.Add(Convert.ToString(dr["name"]), nodeName);
                                tmpNode.Tag           = nodeTag;
                                tmpNode.AllowCellEdit = AllowCellEdit.Disabled;
                                tmpNode.Override.NodeAppearance.Image = GetImageIndex(nodeTag);
                            }
                        }
                    }
                }

                // For Group also and for Root Nodes Also.
                if (initCount == 1)
                {
                    if (!isCleared)
                    {
                        tNode.Nodes.Clear();
                    }

                    // Get Child Category
                    var data = new Category.Data();
                    if (tNode.Tag.ToString() == "group")
                    {
                        var tmpId = GetKey(tNode.Key);
                        data.ParentCategoryId = Convert.ToInt32(tmpId);
                    }
                    else
                    {
                        data.ParentCategoryId = Convert.ToInt32(tNode.Key);
                    }
                    var dtCategory = Category.Search(data);
                    if (dtCategory != null && dtCategory.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtCategory.Rows)
                        {
                            if (!tNode.Nodes.Exists(Convert.ToString(dr["name"])))
                            {
                                var tmpNode = tNode.Nodes.Add(Convert.ToString(dr["CategoryId"]) + "$$group", Convert.ToString(dr["Name"]));
                                tmpNode.Tag = "group";
                                tmpNode.Override.NodeAppearance.Image = GetImageIndex(tmpNode.Tag.ToString());
                                int childCount = GetChildCount("group", Convert.ToInt32(dr["CategoryId"]));
                                if (childCount > 0)
                                {
                                    tmpNode.Nodes.Add("Sample Group" + tmpNode.Key, "Sample Group");
                                }
                            }
                        }
                    }

                    // Get Child Object Items
                    var dataItem = new CategoryItem.Data();
                    if (tNode.Tag.ToString() == "group")
                    {
                        var tmpId = GetKey(tNode.Key);
                        dataItem.CategoryId = Convert.ToInt32(tmpId);
                    }
                    else
                    {
                        dataItem.CategoryId = Convert.ToInt32(tNode.Key);
                    }
                    var dtCategoryItem = CategoryItem.Search(dataItem);
                    if (dtCategoryItem != null && dtCategoryItem.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtCategoryItem.Rows)
                        {
                            var tag  = Convert.ToString(dr["ItemType"]).ToLower();
                            var name = Convert.ToString(dr["Name"]);
                            if (tag == "table")
                            {
                                name = name + "(" + GetTableRowCount(name) + ")";
                            }

                            var tmpNode = tNode.Nodes.Add(Convert.ToString(dr["CategoryItemId"]) + "$$" + tag, name);
                            tmpNode.Tag = tag;
                            tmpNode.Override.NodeAppearance.Image = GetImageIndex(Convert.ToString(dr["ItemType"]).ToLower());
                        }
                    }
                }

                //toolStripStatusLabelExecute.Text = "Objects Listed Successfully";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }