void AddTopBottomFormatCondition() {
     TopBottomRuleFormatCondition condition = new TopBottomRuleFormatCondition();
     condition.FieldName = "Total";
     condition.Threshold = 5;
     condition.Rule = TopBottomRule.TopItems;
     condition.PredefinedFormatName = "YellowFillWithDarkYellowText";
     formats.Add("Top 5 Totals", condition);
 }
Esempio n. 2
0
        void AddTopBottomFormatCondition()
        {
            TopBottomRuleFormatCondition condition = new TopBottomRuleFormatCondition();

            condition.FieldName            = "Total";
            condition.Threshold            = 5;
            condition.Rule                 = TopBottomRule.TopItems;
            condition.PredefinedFormatName = "YellowFillWithDarkYellowText";
            formats.Add("Top 5 Totals", condition);
        }
        static string ToString(TopBottomRuleFormatCondition x)
        {
            switch (x.Rule)
            {
            case TopBottomRule.TopItems: return($"Top {x.Threshold}");

            case TopBottomRule.BottomItems: return($"Bottom {x.Threshold}");

            case TopBottomRule.TopPercent: return($"Top {x.Threshold}%");

            case TopBottomRule.BottomPercent: return($"Bottom {x.Threshold}%");

            case TopBottomRule.AboveAverage: return($"Above Average");

            case TopBottomRule.BelowAverage: return($"Below Average");

            default: throw new NotImplementedException();
            }
        }
        private void CollectionModify(StyleOption styleOption)
        {
            if (styleOption == null)
            {
                return;
            }

            FormatConditionBase formatCondition = null;

            Func <TopBottomRule, FormatConditionBase> createTopBottomRuleFormatConditionHandler = rule =>
            {
                var result = new TopBottomRuleFormatCondition();
                var format = CreateFormat(styleOption);
                if (format != null)
                {
                    result.Format = format;
                }

                result.Rule      = rule;
                result.Threshold = styleOption.Threshold;


                if (styleOption.ApplyToRow)
                {
                    result.Expression = string.Format("[{0}]", styleOption.FieldName);
                }
                else
                {
                    result.FieldName = styleOption.FieldName;
                }

                return(result);
            };

            Action <FormatConditionBase> setAnimatedFormatConditionHandler = fc =>
            {
                formatCondition                      = fc;
                formatCondition.FieldName            = styleOption.FieldName;
                formatCondition.PredefinedFormatName = styleOption.PredefinedFormatName;
            };

            switch (styleOption.FormatConditionType)
            {
            case FormatConditionType.Default:
                var condition = new FormatCondition();
                var format    = CreateFormat(styleOption);
                if (format != null)
                {
                    condition.Format = format;
                }

                formatCondition            = condition;
                formatCondition.FieldName  = styleOption.ApplyToRow ? null : styleOption.FieldName;
                formatCondition.Expression = styleOption.ExpressionString;
                break;

            case FormatConditionType.TopItemsRule:
                formatCondition = createTopBottomRuleFormatConditionHandler(TopBottomRule.TopItems);
                break;

            case FormatConditionType.TopPersentRule:
                formatCondition = createTopBottomRuleFormatConditionHandler(TopBottomRule.TopPercent);
                break;

            case FormatConditionType.BottomItemsRule:
                formatCondition = createTopBottomRuleFormatConditionHandler(TopBottomRule.BottomItems);
                break;

            case FormatConditionType.BottomPercentRule:
                formatCondition = createTopBottomRuleFormatConditionHandler(TopBottomRule.BottomPercent);
                break;

            case FormatConditionType.AboveAverageRule:
                //Не работает
                styleOption.ApplyToRow = false;
                formatCondition        = createTopBottomRuleFormatConditionHandler(TopBottomRule.AboveAverage);
                break;

            case FormatConditionType.BelowAverageRule:
                //Не работает
                styleOption.ApplyToRow = false;
                formatCondition        = createTopBottomRuleFormatConditionHandler(TopBottomRule.BelowAverage);
                break;

            case FormatConditionType.DataBar:
                var dataBarCondition = new DataBarFormatCondition();
                //Необходимо специальное форматирование для этого свойства.
                setAnimatedFormatConditionHandler(dataBarCondition);
                break;

            case FormatConditionType.ColorScale:
                var colorScaleCondition = new ColorScaleFormatCondition();
                //Необходимо специальное форматирование для этого свойства.
                setAnimatedFormatConditionHandler(colorScaleCondition);
                break;

            case FormatConditionType.IconSet:
                var iconSetCondition = new IconSetFormatCondition();
                //Необходимо специальное форматирование для этого свойства.
                setAnimatedFormatConditionHandler(iconSetCondition);
                break;

            default:
                throw new DeveloperException("Undefined FormatConditionType '{0}'.", styleOption.FormatConditionType);
            }

            if (formatCondition != null)
            {
                View.AddFormatCondition(formatCondition);
            }
        }