public static IEnumerable <SCSimpleObject> QueryParents(string unitID, bool includingSelf, DateTime timePoint) { if (string.IsNullOrEmpty(unitID) == false) { string timeString = timePoint == DateTime.MinValue ? TSqlBuilder.Instance.DBCurrentTimeFunction : TSqlBuilder.Instance.FormatDateTime(timePoint); WhereSqlClauseBuilder where = new WhereSqlClauseBuilder().AppendCondition("ID", unitID); string sql = string.Format(sqlTemplate, timeString, where.ToSqlString(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, ConnectionName).Tables[0]; DataView view = new DataView(table); view.Sort = "ID"; SCSimpleObjectCollection tempParents = new SCSimpleObjectCollection(); FillAllParents(unitID, view, includingSelf, tempParents); tempParents.Reverse(); return(tempParents); } else { return(emptyResult); } }
/// <summary> /// 初始化祖先的OUs /// </summary> /// <param name="currentObj">当前对象</param> public void InitAncestorOUs(IOguObject currentObj) { IOguPropertyAccessible wrapper = (IOguPropertyAccessible)currentObj; string parentID = (string)currentObj.Properties["ParentID"]; Debug.Assert(string.IsNullOrEmpty(parentID) == false); Dictionary <string, SCSimpleObjectCollection> parentMap = PC.Adapters.SCSnapshotAdapter.Instance.LoadAllParentsInfo(true, parentID); SCSimpleObjectCollection parents = parentMap[parentID]; List <string> idList = new List <string>(parents.ToIDArray()); //idList.Add(parentID); OguObjectCollection <IOrganization> orgs = this.GetObjects <IOrganization>(SearchOUIDType.Guid, idList.ToArray()); ((IOguPropertyAccessible)currentObj).Parent = orgs.Find(obj => obj.ID == parentID); wrapper = (IOguPropertyAccessible)wrapper.Parent; for (int i = parents.Count - 1; i >= 0; i--) { var org = orgs.Find(obj => obj.ID == parents[i].ID); if (org != null && org.DepartmentType != DepartmentTypeDefine.XuNiJiGou) { wrapper.Parent = orgs.Find(obj => obj.ID == parents[i].ID); wrapper = (IOguPropertyAccessible)wrapper.Parent; } } }
public static IEnumerable<SCSimpleObject> QueryParents(string unitID, bool includingSelf, DateTime timePoint) { if (string.IsNullOrEmpty(unitID) == false) { string timeString = timePoint == DateTime.MinValue ? TSqlBuilder.Instance.DBCurrentTimeFunction : TSqlBuilder.Instance.FormatDateTime(timePoint); WhereSqlClauseBuilder where = new WhereSqlClauseBuilder().AppendCondition("ID", unitID); string sql = string.Format(sqlTemplate, timeString, where.ToSqlString(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, ConnectionName).Tables[0]; DataView view = new DataView(table); view.Sort = "ID"; SCSimpleObjectCollection tempParents = new SCSimpleObjectCollection(); FillAllParents(unitID, view, includingSelf, tempParents); tempParents.Reverse(); return tempParents; } else { return emptyResult; } }
protected void Page_Load(object sender, EventArgs e) { if (Page.Request.HttpMethod == "POST") { this.context.Value = HttpContext.Current.Request["context"]; switch (this.context.Value) { case "Users": case "Orgnizations": case "Groups": case "Applications": case "Roles": break; default: throw new ArgumentOutOfRangeException("context"); } string[] keys = HttpContext.Current.Request.Form.GetValues("keys"); if (keys != null) { SCSimpleObjectCollection coll = new SCSimpleObjectCollection(); MCS.Library.Data.Builder.InSqlClauseBuilder inSql = new MCS.Library.Data.Builder.InSqlClauseBuilder("ID"); inSql.AppendItem <string>(keys); var dataItems = SchemaObjectAdapter.Instance.Load(inSql).FilterByStatus(SchemaObjectStatusFilterTypes.Normal); SchemaToSimpleEnumerator bridge = new SchemaToSimpleEnumerator(dataItems); this.mainList.DataSource = bridge; this.mainList.DataBind(); } } }
protected virtual void Fill(IOguObject target, SchemaObjectBase src, SCObjectAndRelation relation, SCSimpleObjectCollection parentsInfo) { Fill(target, src, relation); var wrapper = target as IOguPropertyAccessible; if (parentsInfo != null && parentsInfo.Count > 0) wrapper.FullPath = parentsInfo.JoinNameToFullPath() + "\\" + wrapper.Name; }
/// <summary> /// 根据ID和时间点载入所有父级关系 /// </summary> /// <param name="ids">子级ID</param> /// <param name="includingSelf">结果中是否包含自己</param> /// <param name="timePoint"></param> /// <returns></returns> public Dictionary <string, SCSimpleObjectCollection> LoadAllParentsInfo(string[] ids, bool includingSelf, DateTime timePoint) { ids.NullCheck("ids"); Dictionary <string, SCSimpleObjectCollection> result = new Dictionary <string, SCSimpleObjectCollection>(ids.Length, StringComparer.OrdinalIgnoreCase); if (ids.Length > 0) { string sqlTemplate = ResourceHelper.LoadStringFromResource(Assembly.GetExecutingAssembly(), "MCS.Library.SOA.DataObjects.Security.Adapters.Templates.LoadAllParentInfo.sql"); string timeString = TSqlBuilder.Instance.DBCurrentTimeFunction; if (timePoint != DateTime.MinValue) { timeString = TSqlBuilder.Instance.FormatDateTime(timePoint); } InSqlClauseBuilder inBuilder = new InSqlClauseBuilder("ID"); inBuilder.AppendItem(ids); string sql = string.Format(sqlTemplate, timeString, inBuilder.ToSqlStringWithInOperator(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0]; DataView view = new DataView(table); view.Sort = "ID"; foreach (string id in ids) { if (result.ContainsKey(id) == false) { SCSimpleObjectCollection tempParents = new SCSimpleObjectCollection(); FillAllParents(id, view, includingSelf, tempParents); SCSimpleObjectCollection parents = new SCSimpleObjectCollection(); //转换次序 for (int i = tempParents.Count - 1; i >= 0; i--) { parents.Add(tempParents[i]); } result.Add(id, parents); } } } return(result); }
private static void FillAllParentsRecursively(string id, DataView view, SCSimpleObjectCollection parents) { int index = view.Find(id); if (index >= 0) { DataRow row = view[index].Row; parents.Add(MapDataRowToSimpleObject(row)); FillAllParentsRecursively(row["ParentID"].ToString(), view, parents); } }
private static void FillAllParents(string id, DataView view, bool includingSelf, SCSimpleObjectCollection parents) { int index = view.Find(id); if (index >= 0) { DataRow row = view[index].Row; if (includingSelf) parents.Add(MapDataRowToSimpleObject(row)); FillAllParentsRecursively(row["ParentID"].ToString(), view, parents); } }
private PhantomOguBase FillParents(PhantomOguBase phantom, SCSimpleObjectCollection parents) { PhantomOrganization parent = null, tmpParent = null; string fullPath = ""; for (int i = 0; i < parents.Count; i++) { var simpleObj = parents[i]; tmpParent = new PhantomOrganization() { ID = simpleObj.ID, Name = simpleObj.Name, DisplayName = simpleObj.DisplayName, ObjectType = SchemaType.Organizations, }; if (i > 0) { fullPath += "\\" + tmpParent.Name; } else { fullPath = tmpParent.Name; } tmpParent.Properties["STATUS"] = simpleObj.Status == SchemaObjectStatus.Normal ? 1 : 3; tmpParent.FullPath = fullPath; if (parent != null) { tmpParent.Dummy.Parent = parent; } parent = tmpParent; } phantom.Dummy.Parent = parent; if (fullPath.Length > 0) { phantom.FullPath = fullPath + "\\" + phantom.Name; } else { phantom.FullPath = phantom.Name; } return(phantom); }
/// <summary> /// 根据ID和时间点载入所有父级关系 /// </summary> /// <param name="ids">子级ID</param> /// <param name="includingSelf">结果中是否包含自己</param> /// <param name="timePoint"></param> /// <returns></returns> public Dictionary<string, SCSimpleObjectCollection> LoadAllParentsInfo(string[] ids, bool includingSelf, DateTime timePoint) { ids.NullCheck("ids"); Dictionary<string, SCSimpleObjectCollection> result = new Dictionary<string, SCSimpleObjectCollection>(ids.Length, StringComparer.OrdinalIgnoreCase); if (ids.Length > 0) { string sqlTemplate = ResourceHelper.LoadStringFromResource(Assembly.GetExecutingAssembly(), "MCS.Library.SOA.DataObjects.Security.Adapters.Templates.LoadAllParentInfo.sql"); string timeString = TSqlBuilder.Instance.DBCurrentTimeFunction; if (timePoint != DateTime.MinValue) timeString = TSqlBuilder.Instance.FormatDateTime(timePoint); InSqlClauseBuilder inBuilder = new InSqlClauseBuilder("ID"); inBuilder.AppendItem(ids); string sql = string.Format(sqlTemplate, timeString, inBuilder.ToSqlStringWithInOperator(TSqlBuilder.Instance)); DataTable table = DbHelper.RunSqlReturnDS(sql, this.GetConnectionName()).Tables[0]; DataView view = new DataView(table); view.Sort = "ID"; foreach (string id in ids) { if (result.ContainsKey(id) == false) { SCSimpleObjectCollection tempParents = new SCSimpleObjectCollection(); FillAllParents(id, view, includingSelf, tempParents); SCSimpleObjectCollection parents = new SCSimpleObjectCollection(); //转换次序 for (int i = tempParents.Count - 1; i >= 0; i--) parents.Add(tempParents[i]); result.Add(id, parents); } } } return result; }
public void LoadSimpleObjectTest() { SCOrganization root = SCOrganization.GetRoot(); SCOrganization newOrg = SCObjectGenerator.PrepareOrganizationObject(); SCObjectOperations.Instance.AddOrganization(newOrg, root); root.ClearRelativeData(); SCSimpleObjectCollection simpleChildren = root.CurrentChildren.ToSimpleObjects(); SCSimpleObject simpleObj = simpleChildren.Find(obj => obj.ID == newOrg.ID); Console.WriteLine(simpleObj.DisplayName); Assert.IsNotNull(simpleObj); Assert.AreEqual(simpleObj.Name, simpleObj.DisplayName); }
protected virtual void Fill(IOguObject target, SchemaObjectBase src, SCObjectAndRelation relation, SCSimpleObjectCollection parentsInfo) { Fill(target, src, relation); var wrapper = target as IOguPropertyAccessible; if (parentsInfo != null && parentsInfo.Count > 0) { wrapper.FullPath = parentsInfo.JoinNameToFullPath() + "\\" + wrapper.Name; } }