示例#1
0
        /// <summary>
        /// Get the rules from the form
        /// </summary>
        /// <returns></returns>

        public CondFormatRules GetCondFormatRulesFromDataTable()
        {
            CondFormatRules rules = new CondFormatRules();
            CondFormatRule  rule  = null;

            rules.ColoringStyle = ColoringStyle;

            for (int r = 0; r < DataTable.Rows.Count; r++)
            {
                string           nameText = GetCellText(r, LabelCol);
                string           opText   = GetCellText(r, OpCol);
                CondFormatOpCode opCode   = CondFormatRule.ConvertOpNameToCode(opText);
                string           valText  = GetCellText(r, ValCol);
                string           val2Text = GetCellText(r, ValCol2);

                if (Lex.IsUndefined(nameText))
                {
                    continue;
                }

                bool valueRequired = (ColoringStyle == CondFormatStyle.ColorScale);

                if (valueRequired && Lex.IsUndefined(valText))                 // skip if no value && a value is needed
                {
                    continue;
                }

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

                rule.Name   = nameText;
                rule.Op     = opText;
                rule.OpCode = opCode;

                rule.Value = valText;
                if (!String.IsNullOrEmpty(rule.Value))
                {
                    double.TryParse(rule.Value, out rule.ValueNumber);
                }

                rule.Value2 = val2Text;
                if (!String.IsNullOrEmpty(rule.Value2))
                {
                    double.TryParse(rule.Value2, out rule.Value2Number);
                }

                rule.BackColor1 = GetCellColor(r, BackColorCol1);

                int ii = GetCellInt(r, IconImageCol);
                if (ii >= 0)
                {
                    rule.ImageName = Bitmaps.GetImageNameFromIndex(ColumnImageCollection, ii);
                }
                else
                {
                    rule.ImageName = "";
                }
            }

            return(rules);
        }