示例#1
0
 public void SetAttributeGroupTree(AttributeGroup attributeGroup)
 {
     //Set the AttributeSpec without raising attributechange and keeping HasChanges() on false
     if (attributeGroup == null)
     {
         return;
     }
     if (_attributeSpecId == attributeGroup.Id)
     {
         _attributeSpecs = attributeGroup;
     }
 }
示例#2
0
        public void ApplyRule(IAttributeContainer container, AttributeGroup rootGroup)
        {
            if (Target == null)
            {
                throw new NotSupportedException("Attribute rule has no Target defined.");
            }
            if (ShowAt == null)
            {
                throw new NotSupportedException("Attribute rule has no ShowAt defined.");
            }

            Target.IsVisible = true;
            switch (RuleType)
            {
            case AttributeRuleType.ShowOnAllTrueWithResultCodes:
                Target.IsVisible = ValidateResultCode(container);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnAllTrue;
                }
                break;

            case AttributeRuleType.ShowOnAllTrueWithoutResultCodes:
                Target.IsVisible = string.IsNullOrEmpty(container.FixCode);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnAllTrue;
                }
                break;

            case AttributeRuleType.ShowOnAllTrue:
                foreach (var operand in Operands)
                {
                    var attribute = FindValueWrap(operand, container, rootGroup);
                    if ((!attribute.Value.HasValue) || attribute.Value == false)
                    {
                        Target.IsVisible = false;
                        break;
                    }
                }
                break;

            case AttributeRuleType.ShowOnAllFalseWithResultCodes:
                Target.IsVisible = string.IsNullOrEmpty(container.FixCode);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnAllFalse;
                }
                break;

            case AttributeRuleType.ShowOnAllFalseWithoutResultCodes:
                Target.IsVisible = ValidateResultCode(container);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnAllFalse;
                }
                break;

            case AttributeRuleType.ShowOnAllFalse:
                foreach (var operand in Operands)
                {
                    var attribute = FindValueWrap(operand, container, rootGroup);
                    if (attribute.Value.HasValue && attribute.Value == true)
                    {
                        Target.IsVisible = false;
                        break;
                    }
                }
                break;

            case AttributeRuleType.ShowOnOneTrueWithResultCodes:
                Target.IsVisible = ValidateResultCode(container);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnOneTrue;
                }
                break;

            case AttributeRuleType.ShowOnOneTrueWithoutResultCodes:
                Target.IsVisible = string.IsNullOrEmpty(container.FixCode);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnOneTrue;
                }
                break;

            case AttributeRuleType.ShowOnOneTrue:
                foreach (var operand in Operands)
                {
                    var attribute = FindValueWrap(operand, container, rootGroup);
                    if (attribute.Value.HasValue && attribute.Value == true)
                    {
                        break;
                    }
                }
                Target.IsVisible = false;
                break;

            case AttributeRuleType.ShowOnOneFalseWithResultCodes:
                Target.IsVisible = ValidateResultCode(container);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnOneFalse;
                }
                break;

            case AttributeRuleType.ShowOnOneFalseWithoutResultCodes:
                Target.IsVisible = string.IsNullOrEmpty(container.FixCode);
                if (Target.IsVisible)
                {
                    goto case AttributeRuleType.ShowOnOneFalse;
                }
                break;

            case AttributeRuleType.ShowOnOneFalse:
                foreach (var operand in Operands)
                {
                    var attribute = FindValueWrap(operand, container, rootGroup);
                    if (!attribute.Value.HasValue || attribute.Value == false)
                    {
                        break;
                    }
                }
                Target.IsVisible = false;
                break;

            case AttributeRuleType.Expression:
                Target.IsVisible = true;     //TODO: implement Expression
                break;
            }
            ShowAt.Refresh();
        }
示例#3
0
        private AttributeValueWrapBool FindValueWrap(string code, IAttributeContainer container, AttributeGroup rootGroup)
        {
            //First try to locate the ValueWrap in the container
            var valueWrap = container.Attributes.FirstOrDefault(a => a.Code == code) as AttributeValueWrapBool;

            if (valueWrap == null)
            {
                //Otherwise check the spec's assigend ValueWrap (through Initialize)
                var spec = rootGroup.FindAttributeSpec(code) as AttributeSpecBool;
                if (spec == null || spec.ValueWrap == null)
                {
                    throw new NotSupportedException(string.Format("Attribute rule contains operand {0} but has no Attribute with this code defined.", code));
                }

                valueWrap = spec.ValueWrap as AttributeValueWrapBool;
            }
            return(valueWrap);
        }