Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (X.IsAjaxRequest)
            {
                return;
            }

            this.lblUser.Text = string.Format("<b>{0}</b>,Today is {1:D}", this.CurrentSecurityPage.CurrentLoginUser.UserLoginID, System.DateTime.Now);


            List <SystemMenuWrapper> list  = SystemMenuWrapper.FindAll();
            List <SystemMenuWrapper> list1 = LinqTree(list, 0);

            for (int i = 0; i < list1.Count; i++)
            {
                Toolbar2.Items.Insert(i + 1, InitButton(list, list1[i].MenuID, list1[i].MenuName));
            }
        }
        private void LinqTree(List <SystemMenuWrapper> list, Ext.Net.TreeNode tnd, int mid)
        {
            if (list == null)
            {
                list = SystemMenuWrapper.FindAll();
            }
            IEnumerable <SystemMenuWrapper> result = null;

            if (mid == 0)
            {
                result = list.Where(menu => menu.ParentMenuID == null);
            }
            else
            {
                result = list.Where(delegate(SystemMenuWrapper menu)
                {
                    if (menu.ParentMenuID == null)
                    {
                        return(false);
                    }
                    else
                    {
                        if (menu.ParentMenuID.MenuID == mid)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                });
            }
            List <string> menuString = SystemMenuWrapper.GetRoleAssignedMenuIDs(SystemRoleWrapper.FindById(RoleID));

            foreach (SystemMenuWrapper m in result)
            {
                Ext.Net.TreeNode tn = new Ext.Net.TreeNode();
                tn.Qtip = m.MenuID.ToString();;
                tn.Text = m.MenuName;

                if (menuString.Count > 0)
                {
                    tn.Checked = (menuString.Exists(id => id.ToString() == tn.Qtip)) ? ThreeStateBool.True : ThreeStateBool.False;
                }
                else
                {
                    tn.Checked = ThreeStateBool.False;
                }
                tnd.Nodes.Add(tn);

                if (list.Exists(delegate(SystemMenuWrapper menu)
                {
                    if (menu.ParentMenuID == null)
                    {
                        return(false);
                    }
                    else
                    {
                        if (menu.ParentMenuID.MenuID == m.MenuID)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }))
                {
                    LinqTree(list, tn, m.MenuID);
                }
            }
        }