/// <summary> /// perfoms comparison operations on expression ie (=, <=, >=, Like, >, <, and <)) returns a boolean /// </summary> /// <returns>object</returns> public override object Execute() { object result = null; if (op == null) { result = this.ConcatExp.Execute(); } else { object LHSO = this.ConcatExp.Execute(); object RHSO; if (this.CompareExp != null) { RHSO = this.CompareExp.Execute(); // this.CompareExp.Execute(); } else { RHSO = this.STRING; } double TryValue = 0.0; int i; if (Util.IsEmpty(LHSO) && Util.IsEmpty(RHSO) && op.Equals("=")) { result = true; } else if (Util.IsEmpty(LHSO) && Util.IsEmpty(RHSO) && op.Equals("<>")) { return(false); } else if ((Util.IsEmpty(LHSO) || Util.IsEmpty(RHSO))) { if (op.Equals("<>")) { return(!(Util.IsEmpty(LHSO) && Util.IsEmpty(RHSO))); } else { result = false; } } else if (op.Equals("LIKE", StringComparison.OrdinalIgnoreCase)) { //string testValue = "^" + RHSO.ToString().Replace("*", "(\\s|\\w)*") + "$"; string testValue = "^" + RHSO.ToString().Replace("*", ".*") + "$"; System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(testValue, System.Text.RegularExpressions.RegexOptions.IgnoreCase); if (re.IsMatch(LHSO.ToString())) { result = true; } else { result = false; } } else { if (this.NumericTypeList.Contains(LHSO.GetType().Name.ToUpperInvariant()) && this.NumericTypeList.Contains(RHSO.GetType().Name.ToUpperInvariant())) { LHSO = Convert.ToDouble(LHSO); RHSO = Convert.ToDouble(RHSO); } if (!LHSO.GetType().Equals(RHSO.GetType())) { if (RHSO is Boolean && op.Equals(StringLiterals.EQUAL)) { result = (RHSO.Equals(!Util.IsEmpty(LHSO))); } else if (LHSO is string && this.NumericTypeList.Contains(RHSO.GetType().Name.ToUpperInvariant()) && double.TryParse(LHSO.ToString(), out TryValue)) { i = TryValue.CompareTo(RHSO); switch (op) { case "=": result = (i == 0); break; case "<>": result = (i != 0); break; case "<": result = (i < 0); break; case ">": result = (i > 0); break; case ">=": result = (i >= 0); break; case "<=": result = (i <= 0); break; } } else if (RHSO is string && this.NumericTypeList.Contains(LHSO.GetType().Name.ToUpperInvariant()) && double.TryParse(RHSO.ToString(), out TryValue)) { i = TryValue.CompareTo(LHSO); switch (op) { case "=": result = (i == 0); break; case "<>": result = (i != 0); break; case "<": result = (i < 0); break; case ">": result = (i > 0); break; case ">=": result = (i >= 0); break; case "<=": result = (i <= 0); break; } } else if (op.Equals(StringLiterals.EQUAL) && (LHSO is Boolean || RHSO is Boolean)) { if (LHSO is Boolean && RHSO is Boolean) { result = LHSO == RHSO; } else if (LHSO is Boolean) { result = (Boolean)LHSO == (Boolean)this.ConvertStringToBoolean(RHSO.ToString()); } else { result = (Boolean)this.ConvertStringToBoolean(LHSO.ToString()) == (Boolean)RHSO; } } else { i = StringComparer.CurrentCultureIgnoreCase.Compare(LHSO.ToString(), RHSO.ToString()); switch (op) { case "=": result = (i == 0); break; case "<>": result = (i != 0); break; case "<": result = (i < 0); break; case ">": result = (i > 0); break; case ">=": result = (i >= 0); break; case "<=": result = (i <= 0); break; } } } else { i = 0; if (LHSO.GetType().Name.ToUpperInvariant() == "STRING" && RHSO.GetType().Name.ToUpperInvariant() == "STRING") { i = StringComparer.CurrentCultureIgnoreCase.Compare(LHSO.ToString().Trim(), RHSO.ToString().Trim()); } else if (LHSO is IComparable && RHSO is IComparable) { i = ((IComparable)LHSO).CompareTo((IComparable)RHSO); } switch (op) { case "=": result = (i == 0); break; case "<>": result = (i != 0); break; case "<": result = (i < 0); break; case ">": result = (i > 0); break; case ">=": result = (i >= 0); break; case "<=": result = (i <= 0); break; } } } } return(result); }
/// <summary> /// checks if a value is within a recode range /// </summary> /// <param name="setValue"></param> /// <returns>bool</returns> public bool ValueIsInRange(object pValue) { bool result = false; bool check1 = false; bool check2 = false; double double_compare; DateTime DateTime_compare; bool bool_compare; int i = 0; object LHSO = null; object RHSO = null; object fromValue = null; if (pValue.ToString().Contains("- ")) { object newval = pValue.ToString().Substring(0, pValue.ToString().IndexOf("-")); pValue = newval; } if (this.fromValue is Rule_Value) { fromValue = ((Rule_Value)this.fromValue).Execute(); } else if (this.fromValue is Rule_NegateExp) { fromValue = ((Rule_NegateExp)this.fromValue).Execute(); } else { fromValue = this.fromValue; } object EqualValue = null; if (this.EqualValue is Rule_Value) { EqualValue = ((Rule_Value)this.EqualValue).Execute(); } else { EqualValue = this.EqualValue; } object rangeEnd = null; if (this.rangeEnd is Rule_Value) { rangeEnd = ((Rule_Value)this.rangeEnd).Execute(); } else if (this.rangeEnd is Rule_NegateExp) { rangeEnd = ((Rule_NegateExp)this.rangeEnd).Execute(); } else { fromValue = this.fromValue; } if (fromValue is string && ((string)fromValue).ToUpperInvariant() == "ELSE") { return(true); } else { if (fromValue.ToString().ToUpperInvariant() == "LOVALUE") { if (double.TryParse(pValue.ToString(), out double_compare)) { LHSO = double.MinValue; } else { if (bool.TryParse(pValue.ToString(), out bool_compare)) { LHSO = bool.FalseString; } else { LHSO = string.Empty; } } } else { if (fromValue is string) { string from = (string)fromValue; if (bool.TryParse(from, out bool_compare)) { LHSO = bool_compare; } else if (fromValue.Equals("(+)") || fromValue.Equals("(-)") || fromValue.Equals("(.)")) { switch (from) { case "(+)": LHSO = true; break; case "(-)": LHSO = false; break; case "(.)": LHSO = null; break; default: break; } } else { LHSO = from.ToUpperInvariant(); } } else { LHSO = fromValue; } } } if (double.TryParse(pValue.ToString(), out double_compare)) { RHSO = double_compare; } else { if (bool.TryParse(pValue.ToString(), out bool_compare)) { RHSO = bool_compare; } else if (pValue.ToString().Equals("(+)") || pValue.ToString().Equals("(-)") || pValue.ToString().Equals("(.)")) { switch (pValue.ToString()) { case "(+)": RHSO = true; break; case "(-)": RHSO = false; break; case "(.)": RHSO = null; break; default: break; } } else { if (pValue != null) { if (pValue is DateTime) { RHSO = pValue; } else { RHSO = pValue.ToString().ToUpperInvariant(); } } } } if (!string.IsNullOrEmpty(RHSO.ToString())) { if (LHSO is IComparable && RHSO is IComparable) { if (LHSO is DateTime && !(RHSO is DateTime)) { DateTime dt; if (DateTime.TryParse(RHSO.ToString(), out dt)) { i = ((IComparable)LHSO).CompareTo((IComparable)dt); } else { i = 0; } } else { i = ((IComparable)LHSO).CompareTo((IComparable)RHSO); } } if (this.recodeType.ToUpperInvariant() == "=") { check1 = i == 0; } else { check1 = i <= 0; } } else if (this.recodeType.ToUpperInvariant() == "RECODEC") { if (Util.IsEmpty(LHSO)) { return(true); } else { return(false); } } if (double.TryParse(pValue.ToString(), out double_compare)) { LHSO = double_compare; } else { if (DateTime.TryParse(pValue.ToString(), out DateTime_compare)) { LHSO = DateTime_compare; } else { if (bool.TryParse(pValue.ToString(), out bool_compare)) { LHSO = bool_compare; } else { if (pValue != null) { LHSO = pValue.ToString().ToUpperInvariant(); } } } } if (rangeEnd.ToString().ToUpperInvariant() == "HIVALUE") { if (double.TryParse(pValue.ToString(), out double_compare)) { RHSO = double.MaxValue; } else { if (DateTime.TryParse(pValue.ToString(), out DateTime_compare)) { RHSO = DateTime.MaxValue; } else { if (bool.TryParse(pValue.ToString(), out bool_compare)) { RHSO = bool.TrueString; } else { RHSO = string.Empty; } } } } else { if (rangeEnd is string) { RHSO = ((string)rangeEnd).ToUpperInvariant(); } else { RHSO = rangeEnd; } } if (!string.IsNullOrEmpty(LHSO.ToString())) { if (LHSO.GetType() == typeof(DateTime) && RHSO.GetType() != typeof(DateTime)) { if (LHSO is IComparable && (Convert.ToDateTime(RHSO) is IComparable)) { i = ((IComparable)LHSO).CompareTo(Convert.ToDateTime(RHSO)); } } else { if (LHSO is IComparable && RHSO is IComparable) { i = ((IComparable)LHSO).CompareTo((IComparable)RHSO); } } if (this.recodeType.ToUpperInvariant() == "=") { check2 = i == 0; } else { check2 = (i <= 0); } } result = check1 && check2; return(result); }