예제 #1
0
        private void LoadList(CustomerEDSC.v_CategoryExplorerDTRow categoryDR)
        {
            if (categoryDR != null)
            {
                //create root
                if (ShowCategoryListingTitle)
                {
                    //string url = "~/Activities/Default.aspx?" + SystemConstants.CategoryID + "=" + categoryDR.ID.ToString();
                    //node = new TreeNode(categoryDR.Name, categoryDR.ID.ToString(), null, null, null);
                    ListItem list1 = new ListItem(categoryDR.Name, categoryDR.ID.ToString());

                    categories.Items.Add(list1);

                    if (categoryDR.ID == Convert.ToInt32(Session[SystemConstants.s_CurrentCategorySelected]))
                    {
                        list1.Selected = true;
                    }
                }
            }
        }
예제 #2
0
        private void LoadTree(TreeNode node, CustomerEDSC.v_CategoryExplorerDTRow categoryDR, CustomerEDSC.v_CategoryExplorerDTDataTable categoryDT)
        {
            IEnumerable <CustomerEDSC.v_CategoryExplorerDTRow> list = null;

            if (node == null && categoryDR != null)
            {
                //create root
                if (ShowCategoryListingTitle)
                {
                    //string url = "~/Activities/Default.aspx?" + SystemConstants.CategoryID + "=" + categoryDR.ID.ToString();
                    node          = new TreeNode(categoryDR.Name, categoryDR.ID.ToString(), null, null, null);
                    node.ImageUrl = "";
                    TreeView1.Nodes.Add(node);

                    if (categoryDR.ID == Convert.ToInt32(Session[SystemConstants.s_CurrentCategorySelected]))
                    {
                        node.Selected = true;
                    }
                    else
                    {
                        if (node.Depth > ShowLevel && !IsPostBack)
                        {
                            node.Collapse();
                        }
                    }
                }
            }

            if (categoryDR == null)
            {
                list = from b in categoryDT
                       where b.Level == 0
                       select b;
            }
            else if (categoryDR.Level == 0)
            {
                list = from b in categoryDT
                       where b.Level == 1 && b.Level1ParentID == categoryDR.ID
                       select b;
            }
            else if (categoryDR.Level == 1)
            {
                list = from b in categoryDT
                       where b.Level == 2 && b.Level1ParentID == categoryDR.Level1ParentID && b.Level2ParentID == categoryDR.ID
                       select b;
            }
            else if (categoryDR.Level == 2)
            {
                list = from b in categoryDT
                       where b.Level == 2 && b.Level1ParentID == categoryDR.Level1ParentID && b.Level2ParentID == categoryDR.ID
                       select b;
            }

            CustomerEDSC.v_CategoryExplorerDTRow drwait = new CustomerEDSC.v_CategoryExplorerDTDataTable().Newv_CategoryExplorerDTRow();
            drwait.Name = "";
            foreach (var dr in list)
            {
                //string url = "~/Activities/Default.aspx?" + SystemConstants.CategoryID + "=" + dr.ID;
                TreeNode childNode;
                if (dr.ID == CategoryID)
                {
                    childNode = new TreeNode("<font color='#17438C'>" + dr.Name + "</font>", dr.ID.ToString(), null, null, null);
                }
                else if (dr.Name == "Other")
                {
                    drwait.ID    = dr.ID;
                    drwait.Name  = dr.Name;
                    drwait.Level = dr.Level;
                    continue;
                }
                else
                {
                    childNode = new TreeNode(dr.Name, dr.ID.ToString(), null, null, null);
                }

                if (dr.Level != 0)
                {
                    childNode.ImageUrl = "~/Content/StyleImages/point.png";
                }
                else
                {
                    childNode.Collapse();
                }

                if (node == null)
                {
                    TreeView1.Nodes.Add(childNode);
                }
                else
                {
                    node.ChildNodes.Add(childNode);
                }

                if (dr.ID == CategoryID)
                {
                    childNode.Selected = true;

                    childNode.Expand();
                    AddToExpandState(childNode.Value);

                    var tempNode = childNode.Parent;
                    int x        = childNode.Depth;
                    for (; x > 0; x--)
                    {
                        if (tempNode != null)
                        {
                            tempNode.Expand();
                            AddToExpandState(tempNode.Value);
                            tempNode = tempNode.Parent;
                        }
                    }
                }
                else
                {
                    if (!CheckIfStateExpanded(childNode.Value))
                    {
                        if (childNode.Depth > ShowLevel && !IsPostBack)
                        {
                            childNode.Collapse();
                            RemoveFromExpandState(childNode.Value);
                        }
                        else
                        {
                            AddToExpandState(childNode.Value);
                        }
                    }
                    else
                    {
                        childNode.Expand();
                        AddToExpandState(childNode.Value);
                    }
                }

                LoadTree(childNode, dr, categoryDT);
            }
            if (!string.IsNullOrEmpty(drwait.Name))
            {
                //string url = "~/Activities/Default.aspx?" + SystemConstants.CategoryID + "=" + dr.ID;
                TreeNode childNode;
                if (drwait.ID == CategoryID)
                {
                    childNode = new TreeNode("<font color='#17438C'>" + drwait.Name + "</font>", drwait.ID.ToString(), null, null, null);
                }

                else
                {
                    childNode = new TreeNode(drwait.Name, drwait.ID.ToString(), null, null, null);
                }

                if (drwait.Level != 0)
                {
                    childNode.ImageUrl = "~/Content/StyleImages/point.png";
                }
                else
                {
                    childNode.Collapse();
                }

                if (node == null)
                {
                    TreeView1.Nodes.Add(childNode);
                }
                else
                {
                    node.ChildNodes.Add(childNode);
                }

                if (drwait.ID == CategoryID)
                {
                    childNode.Selected = true;

                    childNode.Expand();
                    AddToExpandState(childNode.Value);

                    var tempNode = childNode.Parent;
                    int x        = childNode.Depth;
                    for (; x > 0; x--)
                    {
                        if (tempNode != null)
                        {
                            tempNode.Expand();
                            AddToExpandState(tempNode.Value);
                            tempNode = tempNode.Parent;
                        }
                    }
                }
                else
                {
                    if (!CheckIfStateExpanded(childNode.Value))
                    {
                        if (childNode.Depth > ShowLevel && !IsPostBack)
                        {
                            childNode.Collapse();
                            RemoveFromExpandState(childNode.Value);
                        }
                        else
                        {
                            AddToExpandState(childNode.Value);
                        }
                    }
                    else
                    {
                        childNode.Expand();
                        AddToExpandState(childNode.Value);
                    }
                }

                LoadTree(childNode, drwait, categoryDT);
            }
        }