Example #1
0
        /// <summary>
        /// Build the ConditionalFormatting used for the ActivityClass column
        /// </summary>
        /// <returns></returns>

        public static CondFormat BuildActivityBinCondFormat()
        {
            CondFormatRule rule;
            CondFormat     cf = new CondFormat();

            //cf.ShowInHeaders = false;
            cf.ColumnType = MetaColumnType.Integer;
            cf.Name       = "Activity Bin Conditional Formatting";
            CondFormatRules rules = cf.Rules = new CondFormatRules();

            for (int bin = 1; bin <= 10; bin++)             // create one rule for each value from 1 - 10
            {
                rule        = new CondFormatRule();
                rule.Name   = GetBinLabel(bin);
                rule.Op     = "Equal to";
                rule.OpCode = CondFormatOpCode.Eq;
                rule.Value  = bin.ToString();

                rule.BackColor1 = CalculateBinColor(bin);
                rules.Add(rule);
            }

            //rule = new CondFormatRule("Low", CondFormatOpCode.Lt, "1");
            //rule.BackColor = CalculateBinColor(1);
            //rules.Add(rule);

            //rule = new CondFormatRule("High", CondFormatOpCode.Gt, "10");
            //rule.BackColor = CalculateBinColor(10);
            //rules.Add(rule);

            rule            = new CondFormatRule("Missing", CondFormatOpCode.Null, "");
            rule.BackColor1 = Color.White;
            rules.Add(rule);

            cf.Rules.InitializeInternalMatchValues(cf.ColumnType);

            return(cf);
        }
Example #2
0
        public static CondFormatRules Deserialize(
            XmlTextReader tr)
        {
            string txt;

            CondFormatRules rules = new CondFormatRules();

            if (Lex.Eq(XmlUtil.GetAttribute(tr, "ColorContinuously"), "true"))
            {
                rules.ColoringStyle = CondFormatStyle.ColorScale;
            }

            else if (Lex.Eq(XmlUtil.GetAttribute(tr, "ColorAsDataBar"), "true"))
            {
                rules.ColoringStyle = CondFormatStyle.DataBar;
            }

            else if (Lex.Eq(XmlUtil.GetAttribute(tr, "ColorAsIconSet"), "true"))
            {
                rules.ColoringStyle = CondFormatStyle.IconSet;
            }

            else
            {
                rules.ColoringStyle = CondFormatStyle.ColorSet;
            }

            if (tr.IsEmptyElement)             // all done if no rules
            {
                return(rules);
            }

            while (true)             // loop on list of rules
            {
                tr.Read();           // move to next CondFormatRule
                tr.MoveToContent();

                if (Lex.Eq(tr.Name, "CondFormatRule"))                 // start or end of rule
                {
                    if (tr.NodeType == XmlNodeType.EndElement)
                    {
                        continue;                                                            // end of current rule
                    }
                }

                else if (tr.NodeType == XmlNodeType.EndElement)
                {
                    break;                                                             // done with all rules
                }
                else
                {
                    throw new Exception("CondFormatRules.Deserialize - Unexpected element: " + tr.Name);
                }

                CondFormatRule r = new CondFormatRule();
                rules.Add(r);

                txt = tr.GetAttribute("Name");
                if (txt != null)
                {
                    r.Name = txt;
                }

                txt = tr.GetAttribute("Op");
                if (txt != null)
                {
                    r.Op     = txt;
                    r.OpCode = CondFormatRule.ConvertOpNameToCode(r.Op);
                }

                txt = tr.GetAttribute("Value");
                if (txt != null)
                {
                    r.Value = txt;
                    double.TryParse(txt, out r.ValueNumber);
                }

                txt = tr.GetAttribute("Value2");
                if (txt != null)
                {
                    r.Value2 = txt;
                    double.TryParse(txt, out r.Value2Number);
                }

                string fontName     = tr.GetAttribute("FontName");
                string fontSizeTxt  = tr.GetAttribute("FontSize");
                string fontStyleTxt = tr.GetAttribute("FontStyle");

                float fontsize;
                int   fontStyle;

                if (fontName != null && fontSizeTxt != null && fontStyleTxt != null &&
                    float.TryParse(fontSizeTxt, out fontsize) && int.TryParse(fontStyleTxt, out fontStyle))
                {
                    r.Font = new Font(fontName, fontsize, (FontStyle)fontStyle);
                }

                txt = tr.GetAttribute("ForeColor");
                if (txt != null)
                {
                    r.ForeColor = Color.FromArgb(int.Parse(txt));
                }

                txt = tr.GetAttribute("BackColor");
                if (txt != null)
                {
                    r.BackColor1 = Color.FromArgb(int.Parse(txt));
                }

                txt = tr.GetAttribute("ImageName");
                if (txt != null)
                {
                    r.ImageName = txt;
                }
            }

            return(rules);
        }