/// <summary> /// Adds the child rep. /// </summary> /// <param name="rep"> /// The rep. /// </param> public void AddChildRep(UPCRMRep rep) { if (this.repChildren != null) { this.repChildren[rep.RepId] = rep; } else { this.repChildren = new Dictionary <string, UPCRMRep> { { rep.RepId, rep } }; } }
/// <summary> /// Changes the rep. /// </summary> /// <param name="_repIdString">The rep identifier string.</param> /// <returns></returns> public bool ChangeRep(string _repIdString) { UPCRMRep rep = UPCRMDataStore.DefaultStore.Reps.RepWithId(_repIdString); if (rep == null) { return(false); } this.RepId = rep.RepId.RepId(); this.RepGroupId = rep.RepOrgGroupId.RepId(); if (!string.IsNullOrEmpty(this._participantString)) { this.UpdateParticipantString(); } return(true); }
/// <summary> /// Childrens the of internal group with type recursive. /// </summary> /// <param name="rep">The rep.</param> /// <param name="repType">Type of the rep.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <returns></returns> public List <UPCRMRep> ChildrenOfInternalGroupWithTypeRecursive(UPCRMRep rep, UPCRMRepType repType, bool recursive) { var repChildren = new List <UPCRMRep>(); foreach (var childrep in rep.RepChildren) { if (childrep.RepType == repType) { repChildren.Add(childrep); } if (recursive) { var childRepArray = this.ChildrenOfInternalGroupWithTypeRecursive(childrep, repType, true); if (childRepArray.Count > 0) { repChildren.AddRange(childRepArray); } } } return(repChildren.Count > 0 ? repChildren : null); }
/// <summary> /// Reads the rep with identifier. /// </summary> /// <param name="repId">The rep identifier.</param> /// <returns></returns> public UPCRMRep ReadRepWithId(string repId) { if (string.IsNullOrEmpty(repId)) { return(null); } if (this.missingRepDictionary == null) { this.missingRepDictionary = new Dictionary <string, UPCRMRep>(); } else { var returnRep = this.missingRepDictionary.ValueOrDefault(repId); if (returnRep != null) { return(returnRep); } if (this.emptyRepDictionary.ValueOrDefault(repId) != null) { return(null); } } var configStore = ConfigurationUnitStore.DefaultStore; var repSearchAndList = configStore.SearchAndListByName("IDSystem"); FieldControl fieldControl = null; if (repSearchAndList != null) { fieldControl = configStore.FieldControlByNameFromGroup("List", "IDSystem"); } if (fieldControl?.Fields == null || fieldControl.Fields.Count == 0) { return(null); } UPCRMField vField = fieldControl.Fields[0].Field; var fromCondition = new UPInfoAreaConditionLeaf(fieldControl.InfoAreaId, vField.FieldId, "=", repId); var metaInfo = new UPContainerMetaInfo(fieldControl); metaInfo.RootInfoAreaMetaInfo.AddCondition(fromCondition); UPCRMResult result = metaInfo.Find(); int count = result.RowCount; if (count > 0) { lock (this.missingRepDictionary) { for (var i = 0; i < count; i++) { var row = result.ResultRowAtIndex(i); var rep = new UPCRMRep( row.RawValueAtIndex(0), row.RawValueAtIndex(2), row.RawValueAtIndex(1), row.RootRecordId, this.RepTypeFromStringRepTypeId(row.RawValueAtIndex(3))); this.missingRepDictionary[rep.RepId] = rep; } foreach (var rep in this.repArray) { if (string.IsNullOrEmpty(rep.RepOrgGroupId)) { continue; } var parentRep = this.missingRepDictionary.ValueOrDefault(rep.RepOrgGroupId); parentRep?.AddChildRep(rep); } } return(this.missingRepDictionary.ValueOrDefault(repId)); } if (this.emptyRepDictionary == null) { this.emptyRepDictionary = new Dictionary <string, string>(); } this.emptyRepDictionary[repId] = repId; return(null); }
/// <summary> /// Childrens the of group with type recursive. /// </summary> /// <param name="rep">The rep.</param> /// <param name="repType">Type of the rep.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <returns></returns> public List <UPCRMRep> ChildrenOfGroupWithTypeRecursive(UPCRMRep rep, UPCRMRepType repType, bool recursive) { return(this.ChildrenOfGroupWithIdWithTypeRecursive(rep.RepId, repType, recursive)); }
/// <summary> /// Reps the group has children of type recursive. /// </summary> /// <param name="rep">The rep.</param> /// <param name="repType">Type of the rep.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <returns></returns> public bool RepGroupHasChildrenOfTypeRecursive(UPCRMRep rep, UPCRMRepType repType, bool recursive) { return(this.RepGroupWithIdHasChildrenOfTypeRecursive(rep.RepId, repType, recursive)); }
/// <summary> /// Internals the rep group has children of type recursive. /// </summary> /// <param name="rep">The rep.</param> /// <param name="repType">Type of the rep.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <returns></returns> public bool InternalRepGroupHasChildrenOfTypeRecursive(UPCRMRep rep, UPCRMRepType repType, bool recursive) { return(rep.RepChildren?.Any(childrep => (repType.HasFlag(childrep.RepType) || repType == UPCRMRepType.All) || (recursive && this.InternalRepGroupHasChildrenOfTypeRecursive(childrep, repType, true))) ?? false); }
/// <summary> /// Loads the reps. /// </summary> public void LoadReps() { lock (this) { if (this.repDictionary != null) { return; } var configStore = ConfigurationUnitStore.DefaultStore; var repSearchAndList = configStore.SearchAndListByName("IDSystem"); FieldControl fieldControl; UPConfigFilter filter = null; if (repSearchAndList != null) { fieldControl = configStore.FieldControlByNameFromGroup("List", "IDSystem"); if (!string.IsNullOrEmpty(repSearchAndList.FilterName)) { filter = configStore.FilterByName(repSearchAndList.FilterName); } } else { fieldControl = configStore.FieldControlByNameFromGroup("List", "IDSystem"); } if (fieldControl == null) { return; } var metaInfo = new UPContainerMetaInfo(fieldControl); if (filter != null) { metaInfo.ApplyFilter(filter); } var result = metaInfo.Find(); var count = result != null ? result.RowCount : 0; if (count <= 0) { return; } var _repDictionary = new Dictionary <string, UPCRMRep>(count); var _repArray = new List <UPCRMRep>(count); for (var i = 0; i < count; i++) { var row = result.ResultRowAtIndex(i); var rep = new UPCRMRep( row.RawValueAtIndex(0), row.RawValueAtIndex(2), row.RawValueAtIndex(1), row.RootRecordId, this.RepTypeFromStringRepTypeId(row.RawValueAtIndex(3))); _repDictionary[rep.RepId] = rep; _repArray.Add(rep); } foreach (var rep in _repArray) { if (string.IsNullOrEmpty(rep.RepOrgGroupId)) { continue; } var parentRep = _repDictionary.ValueOrDefault(rep.RepOrgGroupId); parentRep?.AddChildRep(rep); } this.repDictionary = _repDictionary; this.repArray = _repArray; } }