/// <summary> /// Construct with basic values /// </summary> public CondFormatRule( string name, CondFormatOpCode opCode, string value) { Name = name; OpCode = opCode; Op = ConvertOpCodeToName(opCode); Value = value; return; }
/// <summary> /// Initialize internal match values for a single rule /// </summary> /// <param name="columnType"></param> public void InitializeInternalMatchValues(MetaColumnType columnType) { OpCode = ConvertOpNameToCode(Op); bool calculateEpsilonFromCfValue = false; // if true use cf value (note: may not be same number of decimals as output format) Epsilon = 0; if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value)) { double.TryParse(Value, out ValueNumber); if (calculateEpsilonFromCfValue) { Epsilon = MobiusDataType.GetEpsilon(Value); } else { int decimals = 10; // use default epsilon value Epsilon = MobiusDataType.GetEpsilon(decimals); } } else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value)) { ValueNormalized = DateTimeMx.Normalize(Value); } if (MetaColumn.IsNumericMetaColumnType(columnType) && !String.IsNullOrEmpty(Value2)) { double.TryParse(Value2, out Value2Number); double e2 = MobiusDataType.GetEpsilon(Value2); if (e2 < Epsilon) { Epsilon = e2; } } else if (columnType == MetaColumnType.Date && !String.IsNullOrEmpty(Value2)) { Value2Normalized = DateTimeMx.Normalize(Value2); } }
/// <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> /// ConvertOpCodeToName /// </summary> /// <param name="opCode"></param> /// <returns></returns> public static string ConvertOpCodeToName( CondFormatOpCode opCode) { if (opCode == CondFormatOpCode.Unknown) { return("Unknown"); } else if (opCode == CondFormatOpCode.Between) { return("Between"); } else if (opCode == CondFormatOpCode.NotBetween) { return("Not Between"); } else if (opCode == CondFormatOpCode.Eq) { return("Equal to"); } else if (opCode == CondFormatOpCode.NotEq) { return("Not Equal to"); } else if (opCode == CondFormatOpCode.Ge) { return(">="); } else if (opCode == CondFormatOpCode.Gt) { return(">"); } else if (opCode == CondFormatOpCode.Le) { return("<="); } else if (opCode == CondFormatOpCode.Lt) { return("<"); } else if (opCode == CondFormatOpCode.Substring) { return("Contains Substring"); } else if (opCode == CondFormatOpCode.Within) { return("Within"); } else if (opCode == CondFormatOpCode.SSS) { return("SSS"); } else if (opCode == CondFormatOpCode.Exists) { return("Exists"); } else if (opCode == CondFormatOpCode.NotExists) { return("Not Exists"); } else if (opCode == CondFormatOpCode.Null) { return("Missing"); } else if (opCode == CondFormatOpCode.NotNull) { return("Not Missing"); } else { throw new Exception("Invalid OpCode: " + opCode); } }
/// <summary> /// Translate op name to code /// </summary> /// <param name="opName"></param> /// <returns></returns> public static CondFormatOpCode ConvertOpNameToCode( string opName) { CondFormatOpCode opCode = CondFormatOpCode.Unknown; if (Lex.StartsWith(opName, "Unknown")) { opCode = CondFormatOpCode.Unknown; } else if (Lex.StartsWith(opName, "Between")) { opCode = CondFormatOpCode.Between; } else if (Lex.StartsWith(opName, "Not Between")) { opCode = CondFormatOpCode.NotBetween; } else if (Lex.StartsWith(opName, "Equal to")) { opCode = CondFormatOpCode.Eq; } else if (Lex.StartsWith(opName, "Not Equal to")) { opCode = CondFormatOpCode.NotEq; } else if (Lex.StartsWith(opName, ">=")) { opCode = CondFormatOpCode.Ge; // check before > } else if (Lex.StartsWith(opName, ">")) { opCode = CondFormatOpCode.Gt; } else if (Lex.StartsWith(opName, "<=")) { opCode = CondFormatOpCode.Le; // check before < } else if (Lex.StartsWith(opName, "<")) { opCode = CondFormatOpCode.Lt; } else if (Lex.StartsWith(opName, "Contains Substring")) { opCode = CondFormatOpCode.Substring; } else if (Lex.StartsWith(opName, "Within")) { opCode = CondFormatOpCode.Within; } else if (Lex.StartsWith(opName, "SSS")) { opCode = CondFormatOpCode.SSS; } else if (Lex.StartsWith(opName, "Exists")) { opCode = CondFormatOpCode.Exists; } else if (Lex.StartsWith(opName, "Not Exists")) { opCode = CondFormatOpCode.NotExists; } else if (Lex.StartsWith(opName, "Missing")) { opCode = CondFormatOpCode.Null; } else if (Lex.StartsWith(opName, "Not Missing") || Lex.StartsWith(opName, "Any other value")) { opCode = CondFormatOpCode.NotNull; } return(opCode); }