/// <summary> /// Checks if the parent item has a specific code already enabled /// </summary> /// <param name="item">Code item to check parent for</param> /// <returns>True if parent does have the enabled code</returns> private bool ParentHasEnabledCode(IcdCodeItem item) { if (ParentItemVM != null) { if (ParentItemVM.m_Children != null) { if (ParentItemVM.m_Children.Any(vm => vm.IsChosen && (String.Equals(vm.Model.Code.Code, item.Code.Code)))) { return(true); } } return(ParentItemVM.ParentHasEnabledCode(item)); } return(false); }
/// <summary> /// Initiate a new ListItemVM object /// </summary> /// <param name="number">The number to be associated to the item</param> /// <param name="item">The IcdCodeItem object that will serve as the model</param> /// <param name="parentTitle">The object's parent's title</param> public ListItemVM(int number, IcdCodeItem item, IEnumerable <string> parentTitle, bool showCode = false) { SpecificityComplete = false; HasOwnComment = true; m_TrueChildren = new List <ListItemVM>(); Model = item; Comment = CommentStart; Title = new NumberedTitle(number, (showCode) ? (item.Code.CodeType.Equals(IcdCodeStrings.CodeType_Divider)) ? item.Code.Title : String.Format("{0}: {1}", item.Code.Code, item.Code.Title) : item.Code.Title); ParentTitle = parentTitle; m_Comment = item.Comment; m_IsChosen = item.Enabled; CommentCommand = new ActionCommand(ModifyComment); ToggleChosenCmnd = new ActionCommand(() => IsChosen = !IsChosen); }
/// <summary> /// Gets the result string from a specified Code Item /// </summary> /// <param name="item">Item to get the result string from</param> /// <returns>String containing the new Result String for the given option</returns> private string GetResultsStringFrom(IcdCodeItem item) { if (item.Enabled) { var retStr = new StringBuilder(); retStr.AppendStrings(from child in item.Children where child.Code.ChildType.Equals(IcdCodeStrings.ChildType_CodeFirst) select GetResultsStringFrom(child)); var directChildren = (from child in item.Children where child.Code.ChildType.Equals(IcdCodeStrings.ChildType_Direct) select child).ToList(); if (directChildren.Any(i => i.Enabled)) { retStr.AppendStrings(directChildren.Select(i => GetResultsStringFrom(i))); } else { retStr.AppendLine(item.Code.Title); } if (!String.IsNullOrWhiteSpace(item.Comment) && !String.Equals(item.Comment, ListItemVM.CommentStart)) { retStr.AppendLine(item.Comment); } retStr.AppendStrings(from child in item.Children where child.Code.ChildType.Equals(IcdCodeStrings.ChildType_CodeAlso) select GetResultsStringFrom(child)) .AppendStrings(from child in item.Children where child.Code.ChildType.Equals(IcdCodeStrings.ChildType_CodeAdditional) select GetResultsStringFrom(child)); return(retStr.ToString()); } return(String.Empty); }