コード例 #1
0
        private int GetChildCount(string objType, int?categoryId)
        {
            int count = 0;
            var sql   = string.Empty;

            if (objType != "group")
            {
                if (objType == "table")
                {
                    sql = "select * from sysobjects where xtype='u' ORDER BY name";
                }
                else if (objType == "proc")
                {
                    sql = "select * from sysobjects where xtype='p' ORDER BY name";
                }
                else if (objType == "view")
                {
                    sql = "select * from sysobjects where xtype='v' ORDER BY name";
                }
                else if (objType == "function")
                {
                    sql = "select * from sysobjects where xtype='fn' ORDER BY name";
                }

                ////Framework.Components.DataAccess.StartUp.EntryPoint(path, timeout, ConnectionString);
                var oDT = new Framework.Components.DataAccess.DBDataTable("Get List", sql, DataStoreKey);
                if (oDT.DBTable != null)
                {
                    count = oDT.DBTable.Rows.Count;
                }
                if (count > 0)
                {
                    return(count);
                }
            }

            if (categoryId != null)
            {
                // Get Child Category Count
                var data = new Category.Data();
                data.ParentCategoryId = categoryId;
                var dtCategory = Category.Search(data);
                if (dtCategory != null && dtCategory.Rows.Count > 0)
                {
                    count = dtCategory.Rows.Count;
                    return(count);
                }

                // Get Child Object Items Count
                var dataItem = new CategoryItem.Data();
                dataItem.CategoryId = categoryId;
                var dtCategoryItem = CategoryItem.Search(dataItem);
                if (dtCategoryItem != null && dtCategoryItem.Rows.Count > 0)
                {
                    count = dtCategoryItem.Rows.Count;
                }
            }
            return(count);
        }
コード例 #2
0
        private void RemoveChildNodes(UltraTreeNode parentNode)
        {
            while (parentNode.Nodes.Count > 0)
            {
                var nodeTag = Convert.ToString(parentNode.Nodes[0].Tag);
                if (nodeTag == "group")
                {
                    if (parentNode.Nodes[0].Nodes.Count > 0)
                    {
                        RemoveChildNodes(parentNode.Nodes[0]);
                    }
                    var data = new Category.Data();
                    data.CategoryId = Convert.ToInt32(GetKey(parentNode.Nodes[0].Key));
                    Category.Delete(data);
                    parentNode.Nodes[0].Remove();
                }
                else
                {
                    var data = new CategoryItem.Data();
                    data.CategoryItemId = Convert.ToInt32(GetKey(parentNode.Nodes[0].Key));
                    CategoryItem.Delete(data);

                    //nodeTag
                    //parentNode.Nodes[i].Reposition(

                    for (int j = 0; j < treeViewObjects.Nodes[0].Nodes.Count; j++)
                    {
                        var parentTag = Convert.ToString(treeViewObjects.Nodes[0].Nodes[j].Tag);
                        if (parentTag == nodeTag + "s")
                        {
                            parentNode.Nodes[0].Reposition(treeViewObjects.Nodes[0].Nodes[j].Nodes);
                            break;
                        }
                    }
                }
            }
        }
コード例 #3
0
        private void treeViewObjects_DragDrop(object sender, DragEventArgs e)
        {
            //A dummy node variable used for various things
            UltraTreeNode aNode;
            //The SelectedNodes which will be dropped
            SelectedNodesCollection SelectedNodes;
            //The Node to Drop On
            UltraTreeNode DropNode;
            //An integer used for loops
            int i;

            //Set the DropNode
            DropNode = UltraTree_DropHightLight_DrawFilter.DropHightLightNode;

            //Get the Data and put it into a SelectedNodes collection,
            //then clone it and work with the clone
            //These are the nodes that are being dragged and dropped
            SelectedNodes = (SelectedNodesCollection)e.Data.GetData(typeof(SelectedNodesCollection));
            SelectedNodes = SelectedNodes.Clone() as SelectedNodesCollection;

            //Sort the selected nodes into their visible position.
            //This is done so that they stay in the same order when
            //they are repositioned.
            SelectedNodes.SortByPosition();

            //Determine where we are dropping based on the current
            //DropLinePosition of the DrawFilter
            switch (UltraTree_DropHightLight_DrawFilter.DropLinePosition)
            {
            case DropLinePositionEnum.OnNode:     //Drop ON the node
            {
                //Loop through the SelectedNodes and reposition
                //them to the node that was dropped on.
                //Note that the DrawFilter keeps track of what
                //node the mouse is over, so we can just use
                //DropHighLightNode as the drop target.
                for (i = 0; i <= (SelectedNodes.Count - 1); i++)
                {
                    try
                    {
                        aNode = SelectedNodes[i];
                        var newParentTagName    = Convert.ToString(DropNode.Tag);
                        var oldParentTagName    = Convert.ToString(aNode.Parent.Tag);
                        var oldParentCategoryId = Convert.ToInt32(GetKey(aNode.Parent.Key));
                        var newParentCategoryId = Convert.ToInt32(GetKey(DropNode.Key));
                        var nodeTagName         = Convert.ToString(aNode.Tag);

                        if (string.IsNullOrEmpty(newParentTagName) || string.IsNullOrEmpty(oldParentTagName))
                        {
                            continue;
                        }

                        if (nodeTagName == "group")
                        {
                            var data = new Category.Data();
                            data.CategoryId       = Convert.ToInt32(GetKey(aNode.Key));
                            data.ParentCategoryId = newParentCategoryId;
                            data.Name             = aNode.Text.Split(new char[] { '(' })[0];
                            data.ConnectionId     = ConnectionId;

                            Category.Update(data);
                        }
                        else
                        {
                            if (newParentTagName == "root")
                            {
                                continue;
                            }
                            List <string> lstRootTags = new List <string>()
                            {
                                "tables", "procs", "views", "functions"
                            };
                            var isUpdate = false; var isInsert = false; var isDelete = false;
                            if (newParentTagName == "group" && oldParentTagName == "group")
                            {
                                isUpdate = true;
                            }
                            else if (newParentTagName == "group" && lstRootTags.Contains(oldParentTagName))
                            {
                                if (nodeTagName + "s" != oldParentTagName)
                                {
                                    isUpdate = true;
                                }
                                else
                                {
                                    isInsert = true;
                                }
                            }
                            else if (oldParentTagName == "group" && lstRootTags.Contains(newParentTagName))
                            {
                                if (nodeTagName + "s" != newParentTagName)
                                {
                                    isUpdate = true;
                                }
                                else
                                {
                                    isDelete = true;
                                }
                            }
                            else if (lstRootTags.Contains(newParentTagName) && lstRootTags.Contains(oldParentTagName))
                            {
                                if (nodeTagName + "s" != newParentTagName && nodeTagName + "s" != oldParentTagName)
                                {
                                    isUpdate = true;
                                }
                                else if (nodeTagName + "s" == oldParentTagName && nodeTagName + "s" != newParentTagName)
                                {
                                    isInsert = true;
                                }
                                else if (nodeTagName + "s" == newParentTagName && nodeTagName + "s" != oldParentTagName)
                                {
                                    isDelete = true;
                                }
                            }

                            var data = new CategoryItem.Data();
                            data.CategoryId = newParentCategoryId;
                            data.ItemType   = nodeTagName;
                            data.Name       = aNode.Text.Split(new char[] { '(' })[0];
                            data.Status     = "new";
                            if (isInsert)
                            {
                                data.CreatedDate = DateTime.Now;
                                var categoryItemId = CategoryItem.Create(data, ApplicationConnectionString);
                                aNode.Key = Convert.ToString(categoryItemId) + "$$" + aNode.Tag;
                            }
                            else if (isUpdate)
                            {
                                data.CategoryItemId = Convert.ToInt32(GetKey(aNode.Key));
                                CategoryItem.Update(data);
                            }
                            else if (isDelete)
                            {
                                data.CategoryItemId = Convert.ToInt32(GetKey(aNode.Key));
                                CategoryItem.Delete(data);
                            }
                        }
                        //MessageBox.Show("aNode: " + aNode.Text);
                        //MessageBox.Show("Drop Node: " + DropNode.Text);

                        aNode.Reposition(DropNode.Nodes);
                    }
                    catch { }
                }
                break;
            }
            }

            //After the drop is complete, erase the current drop
            //highlight.
            UltraTree_DropHightLight_DrawFilter.ClearDropHighlight();
        }
コード例 #4
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);
            }
        }
コード例 #5
0
        private int GetChildCount(string objType, int?categoryId)
        {
            int count = 0;
            var sql   = string.Empty;

            if (objType != "group")
            {
                if (objType == "table")
                {
                    sql = "select * from sysobjects where xtype='u' ORDER BY name";
                }
                else if (objType == "proc")
                {
                    sql = "select * from sysobjects where xtype='p' ORDER BY name";
                }
                else if (objType == "view")
                {
                    sql = "select * from sysobjects where xtype='v' ORDER BY name";
                }
                else if (objType == "function")
                {
                    sql = "select * from sysobjects where xtype='fn' ORDER BY name";
                }


                var localConnectionString = ConfigurationManager.ConnectionStrings[Database];
                if (localConnectionString == null)
                {
                    AddNewConnectionString(Server, Database, User, Password);
                }

                var oDT = new Framework.Components.DataAccess.DBDataTable("Get List", sql, Database);

                if (oDT.DBTable != null)
                {
                    count = oDT.DBTable.Rows.Count;
                }
                if (count > 0)
                {
                    return(count);
                }
            }

            if (categoryId != null)
            {
                // Get Child Category Count
                var data = new Category.Data();
                data.ParentCategoryId = categoryId;
                var dtCategory = Category.Search(data);
                if (dtCategory != null && dtCategory.Rows.Count > 0)
                {
                    count = dtCategory.Rows.Count;
                    return(count);
                }

                // Get Child Object Items Count
                var dataItem = new CategoryItem.Data();
                dataItem.CategoryId = categoryId;
                var dtCategoryItem = CategoryItem.Search(dataItem);
                if (dtCategoryItem != null && dtCategoryItem.Rows.Count > 0)
                {
                    count = dtCategoryItem.Rows.Count;
                }
            }
            return(count);
        }