/// <summary> /// 返回机构对象的子对象 /// </summary> /// <typeparam name="T">期望返回的结果对象的类型,IOrganization、IUser、IGroup或IOguObject</typeparam> /// <param name="parent">父机构对象</param> /// <param name="includeSideline">对象的类型</param> /// <param name="searchLevel">查询的深度,单级或所有子对象</param> /// <returns></returns> public OguObjectCollection <T> GetChildren <T>(IOrganization parent, bool includeSideline, SearchLevel searchLevel) where T : IOguObject { ExceptionHelper.FalseThrow <ArgumentNullException>(parent != null, "parent"); SchemaType objType = OguObjectHelper.GetSchemaTypeFromInterface <T>(); if (includeSideline) { objType |= SchemaType.Sideline; } DataTable table = OguReaderServiceBroker.Instance.GetOrganizationChildren( parent.ID, (int)SearchOUIDType.Guid, (int)objType, (int)ServiceBrokerContext.Current.ListObjectCondition, (int)searchLevel, string.Empty, string.Empty, string.Empty, Common.DefaultAttrs).Tables[0]; if ((objType & SchemaType.Organizations) == SchemaType.Organizations) { RemoveParentDeptRow(table.Rows, parent); } return(new OguObjectCollection <T>(Common.BuildObjectsFromTable <T>(table, parent))); }
public static List <T> BuildObjectsFromTable <T>(DataTable table, IOrganization parent) where T : IOguObject { List <T> list = new List <T>(); foreach (DataRow row in table.Rows) { SchemaType type; if (row.Table.Columns.Contains("OBJECTCLASS")) { type = (SchemaType)Enum.Parse(typeof(SchemaType), row["OBJECTCLASS"].ToString(), true); if (type == SchemaType.Organizations) { if (row.Table.Columns.Contains("ACCESS_LEVEL") || (parent != null && parent is IOrganizationInRole)) { type = SchemaType.OrganizationsInRole; } } } else { type = OguObjectHelper.GetSchemaTypeFromInterface <T>(); } IOguObject baseObject = OguPermissionSettings.GetConfig().OguObjectFactory.CreateObject(type); if (baseObject is OguBaseImpl) { OguBaseImpl oBase = (OguBaseImpl)baseObject; oBase.InitProperties(row); if (oBase is IOrganizationInRole && (parent != null && parent is IOrganizationInRole)) { ((OguOrganizationInRoleImpl)oBase).AccessLevel = ((IOrganizationInRole)parent).AccessLevel; } } list.Add((T)(baseObject as object)); } return(list); }
/// <summary> /// 在子对象进行查询(所有级别深度) /// </summary> /// <typeparam name="T">期望的类型</typeparam> /// <param name="parent">父机构对象</param> /// <param name="matchString">模糊查询的字符串</param> /// <param name="includeSideLine">是否包含兼职的人员</param> /// <param name="level">查询的深度</param> /// <param name="returnCount">返回的记录数</param> /// <returns>得到查询的子对象</returns> public OguObjectCollection <T> QueryChildren <T>(IOrganization parent, string matchString, bool includeSideLine, SearchLevel level, int returnCount) where T : IOguObject { ExceptionHelper.FalseThrow <ArgumentNullException>(parent != null, "parent"); //ExceptionHelper.CheckStringIsNullOrEmpty(matchString, "matchString"); SchemaType objType = OguObjectHelper.GetSchemaTypeFromInterface <T>(); if (includeSideLine) { objType |= SchemaType.Sideline; } int nDep = 0; if (level == SearchLevel.OneLevel) { nDep = 1; } DataTable table = OguReaderServiceBroker.Instance.QueryOGUByCondition3( parent.ID, (int)SearchOUIDType.Guid, matchString, true, Common.DefaultAttrs, (int)objType, (int)ServiceBrokerContext.Current.ListObjectCondition, nDep, string.Empty, returnCount).Tables[0]; if ((objType & SchemaType.Organizations) == SchemaType.Organizations) { RemoveParentDeptRow(table.Rows, parent); } return(new OguObjectCollection <T>(Common.BuildObjectsFromTable <T>(table, parent))); }
public OguObjectCollection <T> GetObjects <T>(SearchOUIDType idType, params string[] ids) where T : IOguObject { ExceptionHelper.FalseThrow <ArgumentNullException>(ids != null, "ids"); SchemaType objType = OguObjectHelper.GetSchemaTypeFromInterface <T>(); ExceptionHelper.TrueThrow(idType == SearchOUIDType.LogOnName && (objType & ~(SchemaType.Users | SchemaType.Sideline)) != SchemaType.Unspecified, Resource.OnlyUserCanUserLogOnNameQuery); OguObjectCollection <T> result = null; if (ids.Length > 0) { string[] notInCacheIds = null; IList <T> objsInCache = null; if (ServiceBrokerContext.Current.UseLocalCache) { objsInCache = OguObjectCacheBase.GetInstance(idType).GetObjectsInCache <T>(ids, out notInCacheIds); } else { notInCacheIds = ids; objsInCache = new List <T>(); } if (notInCacheIds.Length > 0) { string multiIDString = BuildIDString(notInCacheIds); DataSet ds = OguReaderServiceBroker.Instance.GetObjectsDetail( SchemaTypeToString(objType), multiIDString, (int)idType, string.Empty, 0, Common.DefaultAttrs); //RemoveDeletedObject(ds.Tables[0]); //原来有这句话,现在去掉,可以查询已经逻辑删除的对象 OguObjectCollection <T> queryResult = new OguObjectCollection <T>(Common.BuildObjectsFromTable <T>(ds.Tables[0])); queryResult = queryResult.GetRemovedDuplicateDeletedObjectCollection(); if (ServiceBrokerContext.Current.UseLocalCache) { OguObjectCacheBase.GetInstance(idType).AddObjectsToCache <T>(queryResult); } foreach (T obj in queryResult) { objsInCache.Add(obj); } } result = new OguObjectCollection <T>(objsInCache); result.Sort(OrderByPropertyType.GlobalSortID, SortDirectionType.Ascending); } else { result = new OguObjectCollection <T>(); } return(result); }