/// <summary> /// Initialize marker shape rules for newly selected QueryColumn /// </summary> internal void InitializeShapeRules() { CondFormatRule r; ShapeBy.Rules = new CondFormatRules(); if (ShapeBy.QueryColumn == null) { return; } QueryColumn qc = ShapeBy.QueryColumn; ColumnStatistics stats = View.GetStats(qc); for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++) { MobiusDataType mdt = stats.DistinctValueList[i1]; r = new CondFormatRule(); r.Value = View.GetFormattedText(qc, mdt); AddRule(r); if (i1 + 1 >= 25) { break; // limit number of items } } if (stats.NullsExist) { r = new CondFormatRule(); r.Value = "(Blank)"; AddRule(r); } return; }
internal void AddRule(CondFormatRule r) { int max = MaxShapeEnumValue(); if (ShapeBy.Rules.Count <= max) { r.ForeColor = Color.FromArgb(ShapeBy.Rules.Count); } else { r.ForeColor = Color.FromArgb(max); } ShapeBy.Rules.Add(r); return; }
/// <summary> /// Setup color set conditional formatting rules for column /// </summary> /// <param name="setName"></param> /// <returns></returns> private CondFormatRules InitializeColorSetCondFormatRules(string setName) { CondFormatRule rule = null; CondFormatRules rules = GetCondFormatRulesFromDataTable(); bool compatible = (rules.ColoringStyle == CondFormatStyle.ColorSet || rules.ColoringStyle == CondFormatStyle.IconSet); bool setExists = (Bitmaps.ColorSetImageColors.ContainsKey(setName)); if (!compatible || !setExists) // need new rules set? { if (!setExists || Lex.Eq(setName, CondFormat.DefaultColorSet)) { CondFormat cf = CondFormat.BuildDefaultConditionalFormatting(); rules = cf.Rules; return(rules); } rules = new CondFormatRules(CondFormatStyle.ColorSet); } rules.ColoringStyle = CondFormatStyle.ColorSet; Color[] colors = Bitmaps.ColorSetImageColors[setName]; for (int ri = 0; ri < colors.Length; ri++) { if (ri < rules.Count) { rule = rules[ri]; } else { rule = new CondFormatRule(); rule.Name = "Rule " + (ri + 1); rule.Op = "<="; rule.OpCode = CondFormatRule.ConvertOpNameToCode(rule.Op); rules.Add(rule); } rule.BackColor1 = colors[ri]; } return(rules); }
void SetupCondFormatRulesFromColorCodingItems( TrellisCardBarChartControl cc, List <ColorCodingItemMsx> ccl, CondFormatStyle cfStyle) { CondFormatRules rules = new CondFormatRules(cfStyle); foreach (ColorCodingItemMsx i in ccl) { CondFormatRule r = new CondFormatRule(); r.Name = i.ColumnName; string suffix = ""; if (cfStyle == CondFormatStyle.ColorSet) { r.BackColor1 = i.BackColor; } else // Gradient { int ruleCnt = i.SubRules.Count; List <string> subruleText = new List <string>(); foreach (ColorCodingSubRuleMsx ccr in i.SubRules) { string txt = ccr.Value; if (ccr.CalcType != ValueCalcTypeEnumMsx.Value) { txt += " (" + ccr.CalcType + ")"; } subruleText.Add(txt); } List <Color> colors = new List <Color>(); if (ruleCnt > 0) { r.Value = subruleText[0]; colors.Add(i.SubRules[0].Color); } if (ruleCnt > 2) { r.Value2 = subruleText[2]; // max rule text colors.Add(i.SubRules[1].Color); // avg color colors.Add(i.SubRules[2].Color); // max color } else if (ruleCnt > 1) { r.Value2 = subruleText[1]; colors.Add(i.SubRules[1].Color); } string scaleName = Bitmaps.GetColorScaleNameFromColorset(colors.ToArray()); if (Lex.IsUndefined(scaleName)) { scaleName = CondFormat.DefaultColorScale; } r.ImageName = scaleName; } rules.Add(r); } cc.Setup(SVP, rules, EditValueChanged); return; }
/// <summary> /// Initialize coloring rules for newly selected QueryColumn /// </summary> #if false internal CondFormatRules InitializeRulesBasedOnDataValues() { CondFormatRule r; Color[] colors = GetColors(); CondFormatRules rules = new CondFormatRules(); if (ResultsField == null) { return(rules); } QueryColumn qc = ResultsField.QueryColumn; ColumnStatistics stats = ResultsField.GetStats(); if (qc.MetaColumn.DataType == MetaColumnType.Structure) { // setup substructure search rules if structures for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++) { MobiusDataType mdt = stats.DistinctValueList[i1]; r = new CondFormatRule(); r.Op = "SSS"; r.OpCode = CondFormatOpCode.SSS; ChemicalStructureMx cs = mdt as ChemicalStructureMx; if (cs != null) { r.Value = cs.ChimeString; } r.BackColor1 = colors[i1 % colors.Length]; rules.Add(r); } } else // setup equality rules for other types { for (int i1 = 0; i1 < stats.DistinctValueList.Count; i1++) { MobiusDataType mdt = stats.DistinctValueList[i1]; r = new CondFormatRule(); r.Op = "Equal to"; r.OpCode = CondFormatOpCode.Eq; r.Value = mdt.FormattedText; r.BackColor1 = colors[i1 % colors.Length]; rules.Add(r); // if (i1 + 1 >= 25) break; // limit number of items } } if (stats.NullsExist) { r = new CondFormatRule(); r.Name = "Missing Data"; r.Op = "Missing"; r.OpCode = CondFormatOpCode.NotExists; r.BackColor1 = CondFormatMatcher.DefaultMissingValueColor; rules.Add(r); } SetRules(ResultsField, rules); // put into the grid return(rules); }
/// <summary> /// Check for valid format /// </summary> /// <returns></returns> public bool AreValid() { string txt; int count = 0; DataRow dr; for (int r = 0; r < DataTable.Rows.Count; r++) { dr = DataTable.Rows[r]; string label = dr[LabelCol] as string; string op = dr[OpCol] as string; if (op == null) { op = ""; } CondFormatOpCode opCode = CondFormatRule.ConvertOpNameToCode(op); string value = dr[ValCol] as string; string value2 = dr[ValCol2] as string; if (String.IsNullOrEmpty(op) && String.IsNullOrEmpty(value)) { continue; // nothing on line } if (Lex.IsNullOrEmpty(label) && LabelsRequired) { XtraMessageBox.Show("A label must be supplied", UmlautMobius.String); //RulesGrid.EditCell(r, LabelCol); return(false); } if (opCode == CondFormatOpCode.Null || opCode == CondFormatOpCode.NotNull || opCode == CondFormatOpCode.Exists) { continue; // no need to check value } if (op == "") { XtraMessageBox.Show("A comparison type must be supplied", UmlautMobius.String); //RulesGrid.EditCell(r, OpCol); return(false); } if (value == "") { XtraMessageBox.Show("A value must be supplied", UmlautMobius.String); //RulesGrid.EditCell(r, ValCol); return(false); } if (opCode == CondFormatOpCode.Within) // check within date value as integer { if (!IsValidValue(value, MetaColumnType.Integer, r, ValCol)) { return(false); } if (value2 == "") { XtraMessageBox.Show("A date unit must be supplied", UmlautMobius.String); //RulesGrid.EditCell(r, ValCol2); return(false); } } else if (!IsValidValue(value, ColumnType, r, ValCol)) { return(false); } if (opCode == CondFormatOpCode.Between || opCode == CondFormatOpCode.NotBetween) { if (value2 == "") { XtraMessageBox.Show("An \"Between\" high value must be supplied", UmlautMobius.String); //RulesGrid.EditCell(r, ValCol2); return(false); } else if (!IsValidValue(value2, ColumnType, r, ValCol2)) { return(false); } } } return(true); }
/// <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); }
/// <summary> /// Add to the content of the rules control /// </summary> /// <param name="rules"></param> public void LoadDataTableFromCondFormatRules( CondFormatRules rules) { DataTable dt = DataTable; DataRow dr; InSetup = true; //bool saveEnabled = dt.EnableDataChangedEventHandlers(false); // turn off change events while filling // Setup for CF coloring style CondFormatStyle colorStyle = rules.ColoringStyle; if (colorStyle == CondFormatStyle.ColorScale) { //ColorStyleDropDown.Text = "Continuous Colors"; ColumnImageCollection = Bitmaps.I.ColorScaleImages; } else if (colorStyle == CondFormatStyle.DataBar) { //ColorStyleDropDown.Text = "Data Bars"; ColumnImageCollection = Bitmaps.I.DataBarsImages; } else if (colorStyle == CondFormatStyle.IconSet) { //ColorStyleDropDown.Text = "Icon Set"; ColumnImageCollection = Bitmaps.I.IconSetImages; } else { //ColorStyleDropDown.Text = "Discrete Colors"; ColumnImageCollection = null; } // Setup rules for color style if (rules == null) { InSetup = false; return; } for (int ri = 0; ri < rules.Count; ri++) // fill in the grid { CondFormatRule r = rules[ri]; dr = dt.NewRow(); dt.Rows.InsertAt(dr, ri); dr[LabelCol] = r.Name; dr[OpCol] = r.Op; dr[ValCol] = r.Value; dr[ValCol2] = r.Value2; dr[BackColorCol1] = r.BackColor1; if (Lex.IsDefined(r.ImageName)) { dr[IconImageCol] = Bitmaps.GetImageIndexFromName(ColumnImageCollection, r.ImageName); } else { dr[IconImageCol] = DBNull.Value; } } RulesGrid.DataSource = dt; // make the data visible //RulesGrid.AddNewRowAsNeeded(); //dt.EnableDataChangedEventHandlers(saveEnabled); InSetup = false; return; }