Exemple #1
0
        protected void AddGroup(UserTreeItemModel parent, List<UserTreeItemModel> list)
        {
            Debug.Assert(parent != null);

            if (_dicGroupByParentID == null || _dicGroupByParentID.Count == 0)
                return;

            if (_dicUserByParentID == null || _dicUserByParentID.Count == 0)
                return;

            if (_dicGroupByParentID.ContainsKey(parent.ID))
            {
                int currentLevel = parent.Level + 1;
                var groups = _dicGroupByParentID[parent.ID];

                foreach (GroupInfo group in groups)
                {
                    int groupID = group.ID;

                    if (!GroupDic.ContainsKey(groupID))
                    {
                        UserTreeItemModel model = new UserTreeItemModel
                        {
                            IsGroup = true,
                            Level = currentLevel,
                            Parent = parent,

                            ID = groupID,
                            Code = group.Code,
                        };

                        GroupDic.Add(groupID, model);
                        list.Add(model);
                    }
                }
            }
        }
Exemple #2
0
        protected void AddUser(UserTreeItemModel parent, List<UserTreeItemModel> list)
        {
            Debug.Assert(parent != null);

            if (_dicUserByParentID == null || _dicUserByParentID.Count == 0)
                return;

            if (_dicUserByParentID.ContainsKey(parent.ID))
            {
                int currentLevel = parent.Level + 1;
                var users = _dicUserByParentID[parent.ID];

                foreach (var user in users)
                {
                    int userID = user.ID;

                    if (!UserDic.ContainsKey(userID))
                    {
                        UserTreeItemModel model = new UserTreeItemModel
                        {
                            Level = currentLevel,
                            Parent = parent,

                            ID = user.ID,
                            Code = user.Code,
                            Name = user.Name,
                        };

                        UserDic.Add(userID, model);
                        list.Add(model);
                    }
                }
            }
        }
Exemple #3
0
        protected void CreateTreeItemModels(UserTreeItemModel parent)
        {
            List<UserTreeItemModel> list = new List<UserTreeItemModel>();

            AddGroup(parent, list);
            AddUser(parent, list);

            parent.Children = list;
            for (int i = 0; i < parent.Children.Count; i++)
            {
                UserTreeItemModel model = parent.Children[i];
                if (model.IsGroup)
                    CreateTreeItemModels(model);
            }
        }
Exemple #4
0
        protected int GetUserCountAndRemoveEmptyGroup(UserTreeItemModel model)
        {
            if (model.Children == null || model.Children.Count == 0)
                return 0;

            List<int> childIDToRemove = new List<int>();

            var children = model.Children;
            for (int i = 0; i < children.Count; i++)
            {
                var child = children[i];
                if (child.IsGroup)
                {
                    if (GetUserCountAndRemoveEmptyGroup(child) == 0)
                        childIDToRemove.Add(i);
                }
                else
                {
                    RemoveChildren(children, childIDToRemove);
                    return int.MaxValue; // Groups, Users順で並び替えたはず; 大量ユーザのため、正確にユーザ数をカウントしない。
                }
            }

            RemoveChildren(children, childIDToRemove);
            return children.Count;
        }
Exemple #5
0
        protected UserTreeItemModel CreateHrchModelRoot(GroupInfo[] groups, UserInfo[] users)
        {
            UserTreeItemModel root = new UserTreeItemModel
            {
                ID = 0,
                Level = 0,
                IsExpanded = true,
                IsGroup = true,
                Code = StrRes.TreeRoot,
            };

            if (groups != null && groups.Length > 0)
                _dicGroupByParentID = (from c in groups
                                       group c by c.ParentID into g
                                       select g).ToDictionary(c => c.Key);

            if (users != null && users.Length > 0)
                _dicUserByParentID = (from c in users
                                      group c by c.ParentID into g
                                      select g).ToDictionary(c => c.Key);

            AddUnidentifiedUser();
            CreateTreeItemModels(root);
            return root;
        }