Пример #1
0
        public UserGroup(Core core, long groupId, UserGroupLoadOptions loadOptions)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(UserGroup_ItemLoad);

            bool containsInfoData = false;
            bool containsIconData = false;

            if (loadOptions == UserGroupLoadOptions.Key)
            {
                try
                {
                    LoadItem(groupId);
                }
                catch (InvalidItemException)
                {
                    throw new InvalidGroupException();
                }
            }
            else
            {
                SelectQuery query = new SelectQuery(UserGroup.GetTable(typeof(UserGroup)));
                query.AddFields(UserGroup.GetFieldsPrefixed(core, typeof(UserGroup)));
                query.AddCondition("`group_keys`.`group_id`", groupId);

                if ((loadOptions & UserGroupLoadOptions.Info) == UserGroupLoadOptions.Info)
                {
                    containsInfoData = true;

                    query.AddJoin(JoinTypes.Inner, UserGroupInfo.GetTable(typeof(UserGroupInfo)), "group_id", "group_id");
                    query.AddFields(UserGroupInfo.GetFieldsPrefixed(core, typeof(UserGroupInfo)));

                    if ((loadOptions & UserGroupLoadOptions.Icon) == UserGroupLoadOptions.Icon)
                    {
                        containsIconData = true;

                        query.AddJoin(JoinTypes.Left, new DataField("group_info", "group_icon"), new DataField("gallery_items", "gallery_item_id"));
                        query.AddField(new DataField("gallery_items", "gallery_item_uri"));
                        query.AddField(new DataField("gallery_items", "gallery_item_parent_path"));
                    }
                }

                DataTable groupTable = db.Query(query);

                if (groupTable.Rows.Count > 0)
                {
                    loadItemInfo(typeof(UserGroup), groupTable.Rows[0]);

                    if (containsInfoData)
                    {
                        groupInfo = new UserGroupInfo(core, groupTable.Rows[0]);
                    }

                    if (containsIconData)
                    {
                        loadUserGroupIcon(groupTable.Rows[0]);
                    }
                }
                else
                {
                    throw new InvalidGroupException();
                }
            }
        }
Пример #2
0
        public UserGroup(Core core, DataRow groupRow)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(UserGroup_ItemLoad);

            if (groupRow != null)
            {
                loadItemInfo(typeof(UserGroup), groupRow);

                groupInfo = new UserGroupInfo(core, groupRow);

                loadUserGroupIcon(groupRow);
            }
            else
            {
                throw new InvalidGroupException();
            }
        }
Пример #3
0
        public UserGroup(Core core, System.Data.Common.DbDataReader groupRow, UserGroupLoadOptions loadOptions)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(UserGroup_ItemLoad);

            if (groupRow != null)
            {
                loadItemInfo(typeof(UserGroup), groupRow);

                if ((loadOptions & UserGroupLoadOptions.Info) == UserGroupLoadOptions.Info)
                {
                    groupInfo = new UserGroupInfo(core, groupRow);
                }

                if ((loadOptions & UserGroupLoadOptions.Icon) == UserGroupLoadOptions.Icon)
                {
                    loadUserGroupIcon(groupRow);
                }
            }
            else
            {
                throw new InvalidGroupException();
            }
        }
Пример #4
0
        public UserGroup(Core core, string groupName, UserGroupLoadOptions loadOptions)
            : base(core)
        {
            ItemLoad += new ItemLoadHandler(UserGroup_ItemLoad);

            bool containsInfoData = false;
            bool containsIconData = false;

            if (loadOptions == UserGroupLoadOptions.Key)
            {
                try
                {
                    LoadItem("group_name", groupName);
                }
                catch (InvalidItemException)
                {
                    throw new InvalidGroupException();
                }
            }
            else
            {
                SelectQuery query = new SelectQuery(UserGroup.GetTable(typeof(UserGroup)));
                query.AddFields(UserGroup.GetFieldsPrefixed(core, typeof(UserGroup)));
                query.AddCondition("`group_keys`.`group_name`", groupName);

                if ((loadOptions & UserGroupLoadOptions.Info) == UserGroupLoadOptions.Info)
                {
                    containsInfoData = true;

                    query.AddJoin(JoinTypes.Inner, UserGroupInfo.GetTable(typeof(UserGroupInfo)), "group_id", "group_id");
                    query.AddFields(UserGroupInfo.GetFieldsPrefixed(core, typeof(UserGroupInfo)));

                    if ((loadOptions & UserGroupLoadOptions.Icon) == UserGroupLoadOptions.Icon)
                    {
                        containsIconData = true;

                        query.AddJoin(JoinTypes.Left, new DataField("group_info", "group_icon"), new DataField("gallery_items", "gallery_item_id"));
                        query.AddField(new DataField("gallery_items", "gallery_item_uri"));
                        query.AddField(new DataField("gallery_items", "gallery_item_parent_path"));
                    }
                }

                System.Data.Common.DbDataReader groupReader = db.ReaderQuery(query);

                if (groupReader.HasRows)
                {
                    groupReader.Read();

                    loadItemInfo(typeof(UserGroup), groupReader);

                    if (containsInfoData)
                    {
                        groupInfo = new UserGroupInfo(core, groupReader);
                    }

                    if (containsIconData)
                    {
                        loadUserGroupIcon(groupReader);
                    }

                    groupReader.Close();
                    groupReader.Dispose();
                }
                else
                {
                    groupReader.Close();
                    groupReader.Dispose();

                    throw new InvalidGroupException();
                }
            }
        }