1

次のシナリオで達成できるかどうか教えてください

したがって、ユーザーがdomain / dan.campbellとしてログインする場合は、RadTreeViewを次のように並べ替える必要があります。

キャンベル、ダン

  • ナイキ
  • プーマ

ANSTON、ERIC

  • アディダス
  • プーマ

ブライアン、エリック

  • アディダス
  • プーマ

次のコードに基づいて、現在のツリーは次のように表示されます。

ANSTON、ERIC

  • アディダス
  • プーマ

ブライアン、エリック

  • アディダス
  • プーマ

キャンベル、ダン

  • ナイキ
  • プーマ

    protected void Page_Load(object sender、EventArgs e){BuildTree(); SortClass(); }

        //Sort all RadTreeNode in Ascending
        public void SortClass()
        {
            SortNodes(treProduct.Nodes);
        }
    

    public void BuildTree(){EntityCollectionコレクション= GetProduct(); treProduct.Nodes.Clear();

        ArrayList pgnodes = new ArrayList();
        RadTreeNode pnode = null;
        RadTreeNode snode = null;
    
        foreach (ProductEntity p in collection)
        {
            pnode = null;
            foreach(RadTreeNode n in pgnodes)
            {
               if(n.Text.Trim() == p.LastName.Trim().ToUpper() + "," +" " + p.FirstName.Trim().ToUpper())
               {
                  pnode = n;
                  break;
               }   
            } 
    
            if(pnode != null)
            {
                RadTreeNode productNode = new RadTreeNode(p.ProductName.toString());  
                pnode.nodes.Add(productNode);  
            }
            else
            {
               RadTreeNode userNode = new RadTreeNode(p.LastName.Trim().ToUpper() + "," +" " + p.FirstName.Trim().ToUpper());
    
               RadTreeNode productNode = new RadTreeNode(p.ProductName.toString()); 
               userNode.Nodes.Add(productNode);
               pgnodes.Add(userNode);   
            }
        }
    
        foreach(RadTreeNode pg in pgnodes)
        {
            treProduct.Nodes.Add(pg);
        }
        treProduct.CollapseAllNode();
    
    }
    
    
    
    
     /// <summary>
        /// The sort node is called for each node level sorting the child node
        /// </summary>
        /// <param name="collection"></param>
    
    public void Sort(RadTreeNodeCollection collection)
    {
            RadTreeNode[] nodes = new RadTreeNode[collection.Count];
            collection.CopyTo(nodes, 0);
            Array.Sort(nodes, new NodeSorter());
            collection.Clear();
            collection.AddRange(nodes);
    }
        /// <summary>
        /// SortNodes is a recursive method enumarating and sorting all area
        /// </summary>
        /// <param name="collection"></param>
    
    private void SortNodes(RadTreeNodeCollection collection)
    {
            Sort(collection);
    
            foreach (RadTreeNode node in collection)
            {
                if (node.Nodes.Count > 0)
                {
                    SortNodes(node.Nodes);
                }
    
            }
     }
        /// <summary>
        /// TreeNodeCOmpare define the sorting criteria
        /// </summary>
     public class NodeSorter : IComparer
     {
            public int Compare(object x, object y)
            {
                RadTreeNode tx = (RadTreeNode)x;
                RadTreeNode ty = (RadTreeNode)y;
    
                //if (tx.Text.Length != ty.Text.Length)
    
                //    return tx.Text.Length - ty.Text.Length;
                return string.Compare(tx.Text, ty.Text);
    
    
            }
    
      }
    
4

1 に答える 1

0
  public String FirstName
    {
        get
        {
            string firstName = null;
            string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(1);
            string[] loginNameParts = userName.Split('\\');
            string loginNameWithoutDomain = loginNameParts[1];


            var names = loginNameWithoutDomain.Split('.');


            firstName = names[0];

            return firstName;

        }
    }
    public String LastName
    {
        get
        {
            string lastName = null;
            string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(1);
            string[] loginNameParts = userName.Split('\\');
            string loginNameWithoutDomain = loginNameParts[1];


            var names = loginNameWithoutDomain.Split('.');

            lastName = names[1];


            return lastName;

        }
    }
    public void SortClass()
    {
        SortNodes(treProduct.Nodes);

        string nameToFind = LastName.Trim().ToUpper() + "," + " " + FirstName.Trim().ToUpper();
        var node = treProduct.FindNodeByText(nameToFind);
        if (node != null)
        {
            node.Remove();
            treProduct.Nodes.Insert(0, node);
            treProduct.Nodes[0].Expanded = true;
            treProduct.Nodes[0].ExpandChildNodes();
        }
    }

  public void Sort(RadTreeNodeCollection collection)
    {
        RadTreeNode[] nodes = new RadTreeNode[collection.Count];
        collection.CopyTo(nodes, 0);
        Array.Sort(nodes, new NodeSorter());
        collection.Clear();
        collection.AddRange(nodes);
    }
    /// <summary>
    /// SortNodes is a recursive method enumarating and sorting all area
    /// </summary>
    /// <param name="collection"></param>

    private void SortNodes(RadTreeNodeCollection collection)
    {
        Sort(collection);

        foreach (RadTreeNode node in collection)
        {
            if (node.Nodes.Count > 0)
            {
                SortNodes(node.Nodes);
            }

        }
    }
    /// <summary>
    /// TreeNodeCOmpare define the sorting criteria
    /// </summary>
    public class NodeSorter : IComparer
    {
        public int Compare(object x, object y)
        {
            RadTreeNode tx = (RadTreeNode)x;
            RadTreeNode ty = (RadTreeNode)y;

            //if (tx.Text.Length != ty.Text.Length)

            //    return tx.Text.Length - ty.Text.Length;
            return string.Compare(tx.Text, ty.Text);


        }

    }
于 2013-03-26T04:24:06.313 に答える