Exemplo n.º 1
0
        /// <summary>
        /// Writes the column formats to the specified xml writer.
        /// </summary>
        /// <param name="columnFormats">The column formats to serialize.</param>
        /// <param name="xmlWriter">The writer used to write the xml.</param>
        public static void WriteColumnFormatsXml(IList <ColumnFormatting> columnFormats, XmlWriter xmlWriter)
        {
            if (columnFormats == null)
            {
                throw new ArgumentNullException("columnFormats");
            }

            if (xmlWriter == null)
            {
                throw new ArgumentNullException("xmlWriter");
            }

            if (columnFormats.Count > 0)
            {
                xmlWriter.WriteStartElement("columnFormats");

                foreach (ColumnFormatting columnFormat in columnFormats)
                {
                    xmlWriter.WriteStartElement("columnFormat");
                    xmlWriter.WriteElementString("queryColumnId", columnFormat.QueryColumnId.ToString());
                    xmlWriter.WriteElementString("columnName", columnFormat.ColumnName);
                    columnFormat.ColumnType.ToXml(xmlWriter);

                    xmlWriter.WriteElementString("showText", columnFormat.ShowText.ToString());
                    xmlWriter.WriteElementString("formatString", columnFormat.FormatString);

                    xmlWriter.WriteElementString("decimalPlaces", columnFormat.DecimalPlaces.ToString());
                    xmlWriter.WriteElementString("prefix", columnFormat.Prefix);
                    xmlWriter.WriteElementString("suffix", columnFormat.Suffix);
                    xmlWriter.WriteElementString("lines", columnFormat.Lines.ToString());
                    if (columnFormat.FormattingRule is ColorFormattingRule)
                    {
                        ColorFormattingRule colorRule = columnFormat.FormattingRule as ColorFormattingRule;
                        WriteColorFormattingRuleXml(colorRule, xmlWriter);
                    }
                    else if (columnFormat.FormattingRule is IconFormattingRule)
                    {
                        IconFormattingRule iconRule = columnFormat.FormattingRule as IconFormattingRule;
                        WriteIconFormattingRuleXml(iconRule, xmlWriter);
                    }
                    else if (columnFormat.FormattingRule is BarFormattingRule)
                    {
                        BarFormattingRule barRule = columnFormat.FormattingRule as BarFormattingRule;
                        WriteBarFormattingRuleXml(barRule, xmlWriter);
                    }
                    else if (columnFormat.FormattingRule is ImageFormattingRule)
                    {
                        var imageRule = columnFormat.FormattingRule as ImageFormattingRule;
                        WriteImageFormattingRuleXml(imageRule, xmlWriter);
                    }
                    xmlWriter.WriteEndElement(); //columnFormat
                }

                xmlWriter.WriteEndElement(); //columnFormats
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the bar formatting rule to the specified XML writer.
        /// </summary>
        /// <param name="barFormattingRule">The bar formatting rule to serialize.</param>
        /// <param name="xmlWriter">The XML writer used to write the image to.</param>
        private static void WriteBarFormattingRuleXml(BarFormattingRule barFormattingRule, XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("barFormattingRule");

            ColorInfoHelper.WriteColorInfoXml("color", barFormattingRule.Color, xmlWriter);
            TypedValueHelper.WriteTypedValueXml("minimum", barFormattingRule.Minimum, xmlWriter);
            TypedValueHelper.WriteTypedValueXml("maximum", barFormattingRule.Maximum, xmlWriter);

            xmlWriter.WriteEndElement(); // barFormattingRule
        }
        /// <summary>
        /// </summary>
        /// <param name="index"></param>
        /// <param name="bfr1"></param>
        /// <param name="bfr2"></param>
        private static void CompareBarFormattingRules(int index, BarFormattingRule bfr1, BarFormattingRule bfr2)
        {
            Assert.IsNotNull(bfr1, "Format Index:{0} BarFormattingRule 1 should not be null.", index.ToString(CultureInfo.InvariantCulture));
            Assert.IsNotNull(bfr2, "Format Index:{0} BarFormattingRule 2 should not be null.", index.ToString(CultureInfo.InvariantCulture));

            Assert.AreEqual(bfr1.Color.A, bfr2.Color.A, "Format Index:{0} Color.A is invalid", index.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(bfr1.Color.R, bfr2.Color.R, "Format Index:{0} Color.R is invalid", index.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(bfr1.Color.G, bfr2.Color.G, "Format Index:{0} Color.G is invalid", index.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(bfr1.Color.B, bfr2.Color.B, "Format Index:{0} Color.B is invalid", index.ToString(CultureInfo.InvariantCulture));

            Assert.AreEqual(bfr1.Minimum.Type.GetType( ), bfr2.Minimum.Type.GetType( ), "Format Index:{0} Minimum.Type is invalid", index.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(bfr1.Minimum.Value, bfr2.Minimum.Value, "Format Index:{0} Minimum.Value is invalid", index.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(bfr1.Maximum.Type.GetType( ), bfr2.Maximum.Type.GetType( ), "Format Index:{0} Maximum.Type is invalid", index.ToString(CultureInfo.InvariantCulture));
            Assert.AreEqual(bfr1.Maximum.Value, bfr2.Maximum.Value, "Format Index:{0} Maximum.Value is invalid", index.ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Reconstructs a bar formatting rule from the specified XML image.
        /// </summary>
        /// <param name="node">The node containing the bar formatting rule XML.</param>
        /// <returns>The bar formatting rule.</returns>
        private static BarFormattingRule ReadBarFormattingRuleXml(XmlNode node)
        {
            BarFormattingRule formattingRule = new BarFormattingRule();

            if (XmlHelper.EvaluateSingleNode(node, "barFormattingRule"))
            {
                XmlNode barFormattingRuleNode = XmlHelper.SelectSingleNode(node, "barFormattingRule");
                if (barFormattingRuleNode != null)
                {
                    formattingRule.Color   = ColorInfoHelper.ReadColorInfoXml(barFormattingRuleNode, "color");
                    formattingRule.Minimum = TypedValueHelper.ReadTypedValueXml(barFormattingRuleNode, "minimum");
                    formattingRule.Maximum = TypedValueHelper.ReadTypedValueXml(barFormattingRuleNode, "maximum");
                }
            }

            return(formattingRule);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConditionalFormatter" /> class.
        /// </summary>
        /// <param name="columnFormats">The column formats.</param>
        /// <param name="additionalColumnInfo">The additional column info.</param>
        /// <param name="reportResult">The report result.</param>
        public ConditionalFormatter(IList <ColumnFormatting> columnFormats, IEnumerable <ResultColumn> additionalColumnInfo, ReportResult reportResult)
        {
            _reportResult = reportResult;

            if (columnFormats != null)
            {
                _formatRules = new Dictionary <string, List <ConditionInfo> >(columnFormats.Count);

                // Cache the formatting rules into a dictionary for fast lookup.
                Dictionary <string, ColumnFormatting> formatters = columnFormats.ToDictionary(cf => cf.EntityId.ToString(CultureInfo.InvariantCulture));

                foreach (KeyValuePair <string, ColumnFormatting> keyValuePair in formatters.Where(f => f.Value != null))
                {
                    BarFormattingRule barFormattingRule = keyValuePair.Value.FormattingRule as BarFormattingRule;
                    if (barFormattingRule != null)
                    {
                        ConditionInfo condition = new ConditionInfo
                        {
                            ColorRule = new ColorRule {
                                BackgroundColor = barFormattingRule.Color
                            },
                            Style    = ConditionalFormatStyleEnum.ProgressBar,
                            ShowText = keyValuePair.Value.ShowText
                        };
                        DatabaseType columnForFormatType = additionalColumnInfo.FirstOrDefault(ac => ac.RequestColumn.EntityId.ToString(CultureInfo.InvariantCulture) == keyValuePair.Key).ColumnType;
                        if (columnForFormatType != null)
                        {
                            barFormattingRule.Minimum.Type = columnForFormatType;
                            barFormattingRule.Maximum.Type = columnForFormatType;
                        }

                        DateTime minumumDateTime;
                        if (barFormattingRule.Minimum.Value != null &&
                            (columnForFormatType is DateType || columnForFormatType is TimeType || columnForFormatType is DateTimeType) &&
                            DateTime.TryParse(barFormattingRule.Minimum.Value.ToString(), out minumumDateTime))
                        {
                            condition.LowerBounds = minumumDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
                        }
                        else
                        {
                            float minimum;
                            condition.LowerBounds = float.TryParse(barFormattingRule.Minimum.ValueString, out minimum) ? minimum : 0.0f;
                        }
                        DateTime maximumDateTime;
                        if (barFormattingRule.Maximum.Value != null &&
                            (columnForFormatType is DateType || columnForFormatType is TimeType || columnForFormatType is DateTimeType) &&
                            DateTime.TryParse(barFormattingRule.Maximum.Value.ToString(), out maximumDateTime))
                        {
                            condition.Upperbounds = maximumDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
                        }
                        else
                        {
                            float maximum;
                            if (float.TryParse(barFormattingRule.Maximum.ValueString, out maximum))
                            {
                                condition.Upperbounds = maximum;
                            }
                        }
                        _formatRules.Add(keyValuePair.Key, new List <ConditionInfo>(new[] { condition }));
                    }
                    ColorFormattingRule colorFormattingRule = keyValuePair.Value.FormattingRule as ColorFormattingRule;
                    if (colorFormattingRule != null)
                    {
                        IList <ColorRule>    colorRules = colorFormattingRule.Rules;
                        List <ConditionInfo> predicates = new List <ConditionInfo>(colorRules.Count);
                        foreach (ColorRule colorRule in colorRules)
                        {
                            ResultColumn gridResultColumn = additionalColumnInfo.FirstOrDefault(gu => gu.RequestColumn.EntityId.ToString(CultureInfo.InvariantCulture) == keyValuePair.Key);
                            if (gridResultColumn == null)
                            {
                                continue;
                            }
                            colorRule.Condition.Arguments = TypedValuesForOperatorColumnType(colorRule.Condition.Arguments, colorRule.Condition.Operator, gridResultColumn.ColumnType);
                        }
                        predicates.AddRange(from colorRule in colorRules
                                            let gridResultColumn = additionalColumnInfo.FirstOrDefault(gu => gu.RequestColumn.EntityId.ToString(CultureInfo.InvariantCulture) == keyValuePair.Key)
                                                                   let predicate = PredicateForRule(colorRule.Condition, IsResourceCondition(gridResultColumn), gridResultColumn, this)
                                                                                   where (predicate != null)
                                                                                   select new ConditionInfo
                        {
                            Predicate = predicate,
                            ColorRule = colorRule,
                            Operator  = colorRule.Condition.Operator,
                            Values    = colorRule.Condition.Arguments,
                            Style     = ConditionalFormatStyleEnum.Highlight,
                            ShowText  = keyValuePair.Value.ShowText
                        });
                        _formatRules.Add(keyValuePair.Key, predicates);
                    }
                    IconFormattingRule iconFormattingRule = keyValuePair.Value.FormattingRule as IconFormattingRule;
                    if (iconFormattingRule != null)
                    {
                        IList <IconRule> iconRulesRules = iconFormattingRule.Rules;
                        foreach (IconRule iconRule in iconRulesRules)
                        {
                            ResultColumn gridResultColumn = additionalColumnInfo.FirstOrDefault(gu => gu.RequestColumn.EntityId.ToString(CultureInfo.InvariantCulture) == keyValuePair.Key);
                            if (gridResultColumn == null)
                            {
                                continue;
                            }
                            iconRule.Condition.Arguments = TypedValuesForOperatorColumnType(iconRule.Condition.Arguments, iconRule.Condition.Operator, gridResultColumn.ColumnType);
                        }
                        List <ConditionInfo> predicates = new List <ConditionInfo>(iconRulesRules.Count);
                        predicates.AddRange(from iconRule in iconRulesRules
                                            let gridResultColumn = additionalColumnInfo.FirstOrDefault(gu => gu.RequestColumn.EntityId.ToString(CultureInfo.InvariantCulture) == keyValuePair.Key)
                                                                   let predicate = PredicateForRule(iconRule.Condition, IsResourceCondition(gridResultColumn), gridResultColumn, this)
                                                                                   where (predicate != null)
                                                                                   select new ConditionInfo
                        {
                            Predicate = predicate,
                            IconRule  = iconRule,
                            Operator  = iconRule.Condition.Operator,
                            Values    = iconRule.Condition.Arguments,
                            Style     = ConditionalFormatStyleEnum.Icon,
                            ShowText  = keyValuePair.Value.ShowText
                        });
                        _formatRules.Add(keyValuePair.Key, predicates);
                    }
                }
            }
        }