Exemplo n.º 1
0
        public XmlElement ToElement(String fieldId)
        {
            XmlElement rule = XmlUtils.CreateRootElement("rule");

            if (StringUtil.IsEmpty(this.name))
            {
                throw new TopSchemaException(TopSchemaErrorCodeEnum.ERROR_CODE_31001, fieldId);
            }
            if (StringUtil.IsEmpty(this.value))
            {
                throw new TopSchemaException(TopSchemaErrorCodeEnum.ERROR_CODE_31002, fieldId);
            }
            rule.SetAttribute("name", this.name);
            rule.SetAttribute("value", this.value);
            if (!StringUtil.IsEmpty(exProperty))
            {
                rule.SetAttribute("exProperty", this.exProperty);
            }
            //for Special
            if (this.name.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.MAX_TARGET_SIZE_RULE)))
            {
                MaxTargetSizeRule mtsRule = (MaxTargetSizeRule)this;
                if (!StringUtil.IsEmpty(mtsRule.Unit))
                {
                    rule.SetAttribute("unit", mtsRule.Unit);
                }
            }
            if (this.name.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.MIN_TARGET_SIZE_RULE)))
            {
                MinTargetSizeRule misRule = (MinTargetSizeRule)this;
                if (!StringUtil.IsEmpty(misRule.Unit))
                {
                    rule.SetAttribute("unit", misRule.Unit);
                }
            }
            if (this.name.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.TIP_RULE)))
            {
                TipRule tipRule = (TipRule)this;
                if (!StringUtil.IsEmpty(tipRule.Url))
                {
                    rule.SetAttribute("url", tipRule.Url);
                }
            }
            if (this.name.Equals(RuleTypeEnumHelper.ToType(RuleTypeEnum.DEV_TIP_RULE)))
            {
                DevTipRule devTipRule = (DevTipRule)this;
                if (!StringUtil.IsEmpty(devTipRule.Url))
                {
                    rule.SetAttribute("url", devTipRule.Url);
                }
            }
            //depend element
            if (dependGroup != null && !dependGroup.IsEmpty())
            {
                XmlElement depend = dependGroup.ToElement();
                XmlUtils.AppendElement(rule, depend);
            }
            return(rule);
        }
Exemplo n.º 2
0
 public static Rule CreateRule(RuleTypeEnum ruleType)
 {
     Rule rule = null;
     switch (ruleType)
     {
         case RuleTypeEnum.MAX_LENGTH_RULE:
             rule = new MaxLengthRule();
             break;
         case RuleTypeEnum.MIN_LENGTH_RULE:
             rule = new MinLengthRule();
             break;
         case RuleTypeEnum.MAX_VALUE_RULE:
             rule = new MaxValueRule();
             break;
         case RuleTypeEnum.MIN_VALUE_RULE:
             rule = new MinValueRule();
             break;
         case RuleTypeEnum.MAX_INPUT_NUM_RULE:
             rule = new MaxInputNumRule();
             break;
         case RuleTypeEnum.MIN_INPUT_NUM_RULE:
             rule = new MinInputNumRule();
             break;
         case RuleTypeEnum.VALUE_TYPE_RULE:
             rule = new ValueTypeRule();
             break;
         case RuleTypeEnum.REQUIRED_RULE:
             rule = new RequiredRule();
             break;
         case RuleTypeEnum.DISABLE_RULE:
             rule = new DisableRule();
             break;
         case RuleTypeEnum.MAX_DECIMAL_DIGITS_RULE:
             rule = new MaxDecimalDigitsRule();
             break;
         case RuleTypeEnum.MIN_DECIMAL_DIGITS_RULE:
             rule = new MinDecimalDigitsRule();
             break;
         case RuleTypeEnum.REGEX_RULE:
             rule = new RegexRule();
             break;
         case RuleTypeEnum.SET_RULE:
             rule = new SetRule();
             break;
         case RuleTypeEnum.TIP_RULE:
             rule = new TipRule();
             break;
         case RuleTypeEnum.DEV_TIP_RULE:
             rule = new DevTipRule();
             break;
         case RuleTypeEnum.READ_ONLY_RULE:
             rule = new ReadOnlyRule();
             break;
         case RuleTypeEnum.MAX_TARGET_SIZE_RULE:
             rule = new MaxTargetSizeRule();
             break;
         case RuleTypeEnum.MIN_TARGET_SIZE_RULE:
             rule = new MinTargetSizeRule();
             break;
         case RuleTypeEnum.MAX_IMAGE_SIZE_RULE:
             rule = new MaxImageSizeRule();
             break;
         case RuleTypeEnum.MIN_IMAGE_SIZE_RULE:
             rule = new MinImageSizeRule();
             break;
     }
     return rule;
 }